use of org.openmrs.GlobalProperty in project openmrs-module-pihcore by PIH.
the class CauseOfDeathListTagHandlerComponentTest method setUp.
@Before
public void setUp() throws Exception {
ConceptSource ciel = conceptSource("CIEL", "Columbia International eHealth Laboratory concept ID", null, CoreConceptMetadataBundle.ConceptSources.CIEL);
conceptService.saveConceptSource(ciel);
// for some reason, one of the other tests leaves the context dirty, and the locale set to "fr", which causes the tests to fail when matching obs
Context.setLocale(new Locale("en"));
unknownConcept = testData.concept().datatype("N/A").conceptClass("Misc").name("Unknown Concept").save();
administrationService.saveGlobalProperty(new GlobalProperty(HtmlFormEntryConstants.GP_UNKNOWN_CONCEPT, unknownConcept.getUuid()));
codedCauseConcept = testData.concept().datatype("Coded").conceptClass("Misc").name("CAUSE OF DEATH FROM DEATH CERTIFICATE").mapping("SAME-AS", "CIEL:1814").save();
nonCodedCauseConcept = testData.concept().datatype("Text").conceptClass("Misc").name("Probable cause of death (text)").mapping("SAME-AS", "CIEL:160218").save();
sequenceConcept = testData.conceptNumeric().datatype("Numeric").conceptClass("Misc").name("DIAGNOSIS SEQUENCE NUMBER").mapping("SAME-AS", "CIEL:1815").save();
groupingConcept = testData.concept().datatype("N/A").conceptClass("Misc").name("CAUSES OF DEATH FROM DEATH CERTIFICATE").mapping("SAME-AS", "CIEL:1816").setMembers(codedCauseConcept, nonCodedCauseConcept, sequenceConcept).save();
HtmlFormSetup.setupHtmlFormEntryTagHandlers();
}
use of org.openmrs.GlobalProperty in project openmrs-core by openmrs.
the class ModuleFactory method runDiff.
/**
* Execute the given sql diff section for the given module
*
* @param module the module being executed on
* @param version the version of this sql diff
* @param sql the actual sql statements to run (separated by semi colons)
*/
private static void runDiff(Module module, String version, String sql) {
AdministrationService as = Context.getAdministrationService();
String key = module.getModuleId() + ".database_version";
GlobalProperty gp = as.getGlobalPropertyObject(key);
boolean executeSQL = false;
// check given version against current version
if (gp != null && StringUtils.hasLength(gp.getPropertyValue())) {
String currentDbVersion = gp.getPropertyValue();
if (log.isDebugEnabled()) {
log.debug("version:column " + version + ":" + currentDbVersion);
log.debug("compare: " + ModuleUtil.compareVersion(version, currentDbVersion));
}
if (ModuleUtil.compareVersion(version, currentDbVersion) > 0) {
executeSQL = true;
}
} else {
executeSQL = true;
}
// version is greater than the currently installed version. execute this update.
if (executeSQL) {
try {
Context.addProxyPrivilege(PrivilegeConstants.SQL_LEVEL_ACCESS);
log.debug("Executing sql: " + sql);
String[] sqlStatements = sql.split(";");
for (String sqlStatement : sqlStatements) {
if (sqlStatement.trim().length() > 0) {
as.executeSQL(sqlStatement, false);
}
}
} finally {
Context.removeProxyPrivilege(PrivilegeConstants.SQL_LEVEL_ACCESS);
}
// save the global property
try {
Context.addProxyPrivilege(PrivilegeConstants.MANAGE_GLOBAL_PROPERTIES);
String description = "DO NOT MODIFY. Current database version number for the " + module.getModuleId() + " module.";
if (gp == null) {
log.info("Global property " + key + " was not found. Creating one now.");
gp = new GlobalProperty(key, version, description);
as.saveGlobalProperty(gp);
} else if (!gp.getPropertyValue().equals(version)) {
log.info("Updating global property " + key + " to version: " + version);
gp.setDescription(description);
gp.setPropertyValue(version);
as.saveGlobalProperty(gp);
} else {
log.error("Should not be here. GP property value and sqldiff version should not be equal");
}
} finally {
Context.removeProxyPrivilege(PrivilegeConstants.MANAGE_GLOBAL_PROPERTIES);
}
}
}
use of org.openmrs.GlobalProperty in project openmrs-core by openmrs.
the class ModuleFactory method saveGlobalProperty.
/**
* Convenience method to save a global property with the given value. Proxy privileges are added
* so that this can occur at startup.
*
* @param key the property for this global property
* @param value the value for this global property
* @param desc the description
* @see AdministrationService#saveGlobalProperty(GlobalProperty)
*/
private static void saveGlobalProperty(String key, String value, String desc) {
try {
AdministrationService as = Context.getAdministrationService();
GlobalProperty gp = as.getGlobalPropertyObject(key);
if (gp == null) {
gp = new GlobalProperty(key, value, desc);
} else {
gp.setPropertyValue(value);
}
as.saveGlobalProperty(gp);
} catch (Exception e) {
log.warn("Unable to save the global property", e);
}
}
use of org.openmrs.GlobalProperty in project openmrs-core by openmrs.
the class ModuleUtilTest method getMandatoryModules_shouldReturnMandatoryModuleIds.
/**
* @see org.openmrs.module.ModuleUtil#getMandatoryModules()
*/
@Test
public void getMandatoryModules_shouldReturnMandatoryModuleIds() {
// given
GlobalProperty gp1 = new GlobalProperty("firstmodule.mandatory", "true");
GlobalProperty gp2 = new GlobalProperty("secondmodule.mandatory", "false");
Context.getAdministrationService().saveGlobalProperty(gp1);
Context.getAdministrationService().saveGlobalProperty(gp2);
// when
// then
assertThat(ModuleUtil.getMandatoryModules(), contains("firstmodule"));
}
use of org.openmrs.GlobalProperty in project openmrs-core by openmrs.
the class HibernateOrderDAO method getNextOrderNumberSeedSequenceValue.
/**
* @see org.openmrs.api.db.OrderDAO#getNextOrderNumberSeedSequenceValue()
*/
@Override
public Long getNextOrderNumberSeedSequenceValue() {
GlobalProperty globalProperty = (GlobalProperty) sessionFactory.getCurrentSession().get(GlobalProperty.class, OpenmrsConstants.GP_NEXT_ORDER_NUMBER_SEED, LockOptions.UPGRADE);
if (globalProperty == null) {
throw new APIException("GlobalProperty.missing", new Object[] { OpenmrsConstants.GP_NEXT_ORDER_NUMBER_SEED });
}
String gpTextValue = globalProperty.getPropertyValue();
if (StringUtils.isBlank(gpTextValue)) {
throw new APIException("GlobalProperty.invalid.value", new Object[] { OpenmrsConstants.GP_NEXT_ORDER_NUMBER_SEED });
}
Long gpNumericValue;
try {
gpNumericValue = Long.parseLong(gpTextValue);
} catch (NumberFormatException ex) {
throw new APIException("GlobalProperty.invalid.value", new Object[] { OpenmrsConstants.GP_NEXT_ORDER_NUMBER_SEED });
}
globalProperty.setPropertyValue(String.valueOf(gpNumericValue + 1));
sessionFactory.getCurrentSession().save(globalProperty);
return gpNumericValue;
}
Aggregations