Search in sources :

Example 56 with GlobalProperty

use of org.openmrs.GlobalProperty in project openmrs-module-pihcore by PIH.

the class PihCoreActivator method setGlobalProperty.

protected void setGlobalProperty(String propertyName, String propertyValue) {
    AdministrationService administrationService = Context.getAdministrationService();
    GlobalProperty gp = administrationService.getGlobalPropertyObject(propertyName);
    if (gp == null) {
        gp = new GlobalProperty(propertyName);
    }
    gp.setPropertyValue(propertyValue);
    administrationService.saveGlobalProperty(gp);
}
Also used : AdministrationService(org.openmrs.api.AdministrationService) GlobalProperty(org.openmrs.GlobalProperty)

Example 57 with GlobalProperty

use of org.openmrs.GlobalProperty in project openmrs-core by openmrs.

the class AdministrationServiceImpl method setGlobalProperty.

/**
 * @see org.openmrs.api.AdministrationService#setGlobalProperty(java.lang.String,
 *      java.lang.String)
 */
@Override
public void setGlobalProperty(String propertyName, String propertyValue) throws APIException {
    GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject(propertyName);
    if (gp == null) {
        gp = new GlobalProperty();
        gp.setProperty(propertyName);
    }
    gp.setPropertyValue(propertyValue);
    Context.getAdministrationService().saveGlobalProperty(gp);
}
Also used : GlobalProperty(org.openmrs.GlobalProperty)

Example 58 with GlobalProperty

use of org.openmrs.GlobalProperty in project openmrs-core by openmrs.

the class AdministrationServiceImpl method setImplementationId.

/**
 * @see org.openmrs.api.AdministrationService#setImplementationId(org.openmrs.ImplementationId)
 */
@Override
public void setImplementationId(ImplementationId implementationId) throws APIException {
    if (implementationId == null) {
        return;
    }
    // check the validity of this implementation id with the server
    String description = implementationId.getDescription();
    try {
        // check that source id is valid
        description = checkImplementationIdValidity(implementationId.getImplementationId(), description, implementationId.getPassphrase());
        // save the server's description back to this concept source object
        implementationId.setDescription(description);
        boolean foundMatchingSource = false;
        // loop over the concept sources to make sure one exists for this hl7Code/implementationId
        List<ConceptSource> sources = Context.getConceptService().getAllConceptSources(false);
        if (sources != null) {
            for (ConceptSource source : sources) {
                if (implementationId.getImplementationId().equals(source.getHl7Code())) {
                    foundMatchingSource = true;
                }
            }
        }
        // as a new ConceptSource
        if (!foundMatchingSource) {
            ConceptSource newConceptSource = new ConceptSource();
            newConceptSource.setName(implementationId.getName());
            newConceptSource.setDescription(implementationId.getDescription());
            newConceptSource.setHl7Code(implementationId.getImplementationId());
            if (Context.getAuthenticatedUser() == null) {
                // (hackish)
                // fake the user because no one is logged in
                newConceptSource.setCreator(new User(1));
            }
            Context.getConceptService().saveConceptSource(newConceptSource);
        }
        // serialize and save the ImplementationId to the global properties table
        String value = Context.getSerializationService().getDefaultSerializer().serialize(implementationId);
        Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_IMPLEMENTATION_ID, value));
    } catch (APIException e) {
        throw e;
    } catch (Exception e) {
        // pass any other exceptions on up the train
        throw new APIException(e);
    } finally {
    // save an empty concept source to the database when something fails?
    }
}
Also used : User(org.openmrs.User) APIException(org.openmrs.api.APIException) ConceptSource(org.openmrs.ConceptSource) APIException(org.openmrs.api.APIException) UnknownHostException(java.net.UnknownHostException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) GlobalProperty(org.openmrs.GlobalProperty)

Example 59 with GlobalProperty

use of org.openmrs.GlobalProperty in project openmrs-core by openmrs.

the class AdministrationServiceImpl method getAllowedLocales.

/**
 * @see org.openmrs.api.AdministrationService#getAllowedLocales()
 */
@Override
@Transactional(readOnly = true)
public List<Locale> getAllowedLocales() {
    // lazy-load the global locale list and initialize with current global property value
    if (globalLocaleList == null) {
        globalLocaleList = new GlobalLocaleList();
        Context.getAdministrationService().addGlobalPropertyListener(globalLocaleList);
    }
    Set<Locale> allowedLocales = globalLocaleList.getAllowedLocales();
    // update the GlobalLocaleList.allowedLocales by faking a global property change
    if (allowedLocales == null) {
        // use a default language of "english" if they have cleared this GP for some reason
        String currentPropertyValue = Context.getAdministrationService().getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, LocaleUtility.getDefaultLocale().toString());
        GlobalProperty allowedLocalesProperty = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, currentPropertyValue);
        globalLocaleList.globalPropertyChanged(allowedLocalesProperty);
        allowedLocales = globalLocaleList.getAllowedLocales();
    }
    // allowedLocales is guaranteed to not be null at this point
    return new ArrayList<>(allowedLocales);
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) GlobalProperty(org.openmrs.GlobalProperty) Transactional(org.springframework.transaction.annotation.Transactional)

Example 60 with GlobalProperty

use of org.openmrs.GlobalProperty in project openmrs-core by openmrs.

the class EncounterServiceTest method purgeEncounterType_shouldThrowErrorWhenTryingToDeleteEncounterTypeWhenEncounterTypesAreLocked.

/**
 * @see EncounterService#purgeEncounterType(EncounterType)
 */
@Test(expected = EncounterTypeLockedException.class)
public void purgeEncounterType_shouldThrowErrorWhenTryingToDeleteEncounterTypeWhenEncounterTypesAreLocked() {
    EncounterService encounterService = Context.getEncounterService();
    EncounterType encounterType = Context.getEncounterService().getEncounterType(1);
    Assert.assertNotNull(encounterType);
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_ENCOUNTER_TYPES_LOCKED);
    gp.setPropertyValue("true");
    Context.getAdministrationService().saveGlobalProperty(gp);
    encounterService.purgeEncounterType(encounterType);
}
Also used : EncounterType(org.openmrs.EncounterType) GlobalProperty(org.openmrs.GlobalProperty) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

GlobalProperty (org.openmrs.GlobalProperty)110 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 AdministrationService (org.openmrs.api.AdministrationService)10 BindException (org.springframework.validation.BindException)10 DrugOrder (org.openmrs.DrugOrder)9 Errors (org.springframework.validation.Errors)9 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)5 MutableMessageSource (org.openmrs.messagesource.MutableMessageSource)4 MutableResourceBundleMessageSource (org.openmrs.messagesource.impl.MutableResourceBundleMessageSource)4