org.openmrs.module.ipd.api.events.ConfigLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bahmni-ipd-api Show documentation
Show all versions of bahmni-ipd-api Show documentation
Bahmni IPD API contains all backend APIs for IPD
package org.openmrs.module.ipd.api.events;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
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.util.ArrayList;
import java.util.List;
@Component
@Slf4j
public class ConfigLoader {
private List configs = new ArrayList<>();
private ObjectMapper objectMapper = new ObjectMapper();
@Value("${ipd.events_config.file_path:/etc/bahmni_config/openmrs/apps/ipdDashboard/eventsConfig.json}")
private String eventsConfigurationFileLocation;
public List getConfigs() {
if (configs.isEmpty()) {
loadConfiguration();
}
return this.configs;
}
private void loadConfiguration() {
try {
File routeConfigurationFile = new FileSystemResource(eventsConfigurationFileLocation).getFile();
this.configs = objectMapper.readValue(routeConfigurationFile, new TypeReference>() {});
} catch (IOException exception) {
log.error("Failed to load configuration for file : " + eventsConfigurationFileLocation, exception);
}
}
}