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);
}
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);
}
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?
}
}
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);
}
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);
}
Aggregations