Search in sources :

Example 1 with GlobalProperty

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();
}
Also used : Locale(java.util.Locale) ConceptSource(org.openmrs.ConceptSource) GlobalProperty(org.openmrs.GlobalProperty) Before(org.junit.Before)

Example 2 with GlobalProperty

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);
        }
    }
}
Also used : AdministrationService(org.openmrs.api.AdministrationService) GlobalProperty(org.openmrs.GlobalProperty)

Example 3 with GlobalProperty

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);
    }
}
Also used : AdministrationService(org.openmrs.api.AdministrationService) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) CycleException(org.openmrs.util.CycleException) InputRequiredException(org.openmrs.util.InputRequiredException) GlobalProperty(org.openmrs.GlobalProperty)

Example 4 with GlobalProperty

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"));
}
Also used : GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 5 with GlobalProperty

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;
}
Also used : APIException(org.openmrs.api.APIException) GlobalProperty(org.openmrs.GlobalProperty)

Aggregations

GlobalProperty (org.openmrs.GlobalProperty)107 Test (org.junit.Test)80 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)77 Locale (java.util.Locale)14 OrderUtilTest (org.openmrs.order.OrderUtilTest)14 Encounter (org.openmrs.Encounter)12 ArrayList (java.util.ArrayList)11 User (org.openmrs.User)11 Patient (org.openmrs.Patient)10 BindException (org.springframework.validation.BindException)10 DrugOrder (org.openmrs.DrugOrder)9 Errors (org.springframework.validation.Errors)9 AdministrationService (org.openmrs.api.AdministrationService)8 CareSetting (org.openmrs.CareSetting)7 OrderType (org.openmrs.OrderType)7 Date (java.util.Date)6 EncounterType (org.openmrs.EncounterType)5 APIException (org.openmrs.api.APIException)4 MutableMessageSource (org.openmrs.messagesource.MutableMessageSource)4 MutableResourceBundleMessageSource (org.openmrs.messagesource.impl.MutableResourceBundleMessageSource)4