Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BAH-3842|refactor events config to be read from global property #59

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.openmrs.api.context.Context;
import org.openmrs.module.ipd.api.events.model.ConfigDetail;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.FileSystemResource;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -20,8 +22,7 @@ public class ConfigLoader {

private ObjectMapper objectMapper = new ObjectMapper();

@Value("${config-file.path}")
private String routeConfigurationFileLocation;
private static final String CONFIG_FILE_NAME = "eventsConfig.json";

public List<ConfigDetail> getConfigs() {
if (configs.isEmpty()) {
Expand All @@ -31,11 +32,20 @@ public List<ConfigDetail> getConfigs() {
}

private void loadConfiguration() {
String routeConfigurationFileLocation = Context.getAdministrationService().getGlobalProperty("ipd.eventsConfig.filepath");
try {
if (StringUtils.isBlank(routeConfigurationFileLocation)) {
File file = new File(this.getClass().getClassLoader().getResource(CONFIG_FILE_NAME).toURI());
routeConfigurationFileLocation = file.getAbsolutePath();
}

File routeConfigurationFile = new FileSystemResource(routeConfigurationFileLocation).getFile();
this.configs = objectMapper.readValue(routeConfigurationFile, new TypeReference<List<ConfigDetail>>() {});
} catch (IOException exception) {
log.error("Failed to load configuration for file : " + routeConfigurationFileLocation, exception);
}
catch (URISyntaxException exception) {
log.error("Failed to find file : " + CONFIG_FILE_NAME, exception);
}
}
}
14 changes: 14 additions & 0 deletions api/src/main/resources/eventsConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"type": "PATIENT_ADMIT",
"tasks": []
},
{
"type": "SHIFT_START_TASK",
"tasks": []
},
{
"type": "ROLLOVER_TASK",
"tasks": []
}
]
14 changes: 14 additions & 0 deletions api/src/main/resources/liquibase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -527,4 +527,18 @@
<column name="uuid" valueComputed="uuid()"/>
</insert>
</changeSet>

<changeSet id="ipd-events-config-filepath-202405311510" author="Kavitha">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">
select count(*) from global_property where property = 'ipd.eventsConfig.filepath';
</sqlCheck>
</preConditions>
<comment>Add global property to add filepath for the events config json file</comment>
<sql>
INSERT INTO global_property (property, property_value, description, uuid)
VALUES ('ipd.eventsConfig.filepath', '',
'File path of the events configuration json file', uuid())
</sql>
</changeSet>
</databaseChangeLog>
Loading