/** * 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); } }
@Test public void parse_shouldParseGlobalProperty() throws IOException { GlobalProperty gp1 = new GlobalProperty("report.deleteReportsAgeInHours", "72", "delete reports after hours"); GlobalProperty gp2 = new GlobalProperty("report.validateInput", "2", "to validate input", RegexValidatedTextDatatype.class, "^\\d+$"); Document config = buildOnValidConfigXml() .withGlobalProperty(gp1.getProperty(), gp1.getPropertyValue(), gp1.getDescription(), null, null) .withGlobalProperty(gp2.getProperty(), gp2.getPropertyValue(), gp2.getDescription(), gp2.getDatatypeClassname(), gp2.getDatatypeConfig()) .build(); Module module = parser.parse(writeConfigXmlToFile(config)); assertThat(module.getGlobalProperties().size(), is(2)); assertThat(module.getGlobalProperties().get(0).getProperty(), is(gp1.getProperty())); assertThat(module.getGlobalProperties().get(0).getPropertyValue(), is(gp1.getPropertyValue())); assertThat(module.getGlobalProperties().get(0).getDescription(), is(gp1.getDescription())); assertThat(module.getGlobalProperties().get(0).getDatatypeClassname(), is(gp1.getDatatypeClassname())); assertThat(module.getGlobalProperties().get(0).getDatatypeConfig(), is(gp1.getDatatypeConfig())); assertThat(module.getGlobalProperties().get(1).getProperty(), is(gp2.getProperty())); assertThat(module.getGlobalProperties().get(1).getPropertyValue(), is(gp2.getPropertyValue())); assertThat(module.getGlobalProperties().get(1).getDescription(), is(gp2.getDescription())); assertThat(module.getGlobalProperties().get(1).getDatatypeClassname(), is(gp2.getDatatypeClassname())); assertThat(module.getGlobalProperties().get(1).getDatatypeConfig(), is(gp2.getDatatypeConfig())); }
/** * @see java.lang.Object#toString() */ @Override public String toString() { return "property: " + getProperty() + " value: " + getPropertyValue(); }
/** * @see org.openmrs.api.db.AdministrationDAO#saveGlobalProperty(org.openmrs.GlobalProperty) */ @Override public GlobalProperty saveGlobalProperty(GlobalProperty gp) throws DAOException { GlobalProperty gpObject = getGlobalPropertyObject(gp.getProperty()); if (gpObject != null) { gpObject.setPropertyValue(gp.getPropertyValue()); gpObject.setDescription(gp.getDescription()); sessionFactory.getCurrentSession().update(gpObject); return gpObject; } else { sessionFactory.getCurrentSession().save(gp); return gp; } }
/** * @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); }
@Test public void globalPropertyChanged_shouldSetAllowedLocalesIfGlobalPropertyIsAnEmptyString() { GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, ""); globalLocaleList.globalPropertyChanged(gp); assertThat(globalLocaleList.getAllowedLocales(), contains(Locale.ROOT)); }
@Test public void parse_shouldParseGlobalPropertyContainingElementsNotIncludedInGlobalProperty() throws IOException { GlobalProperty gp1 = new GlobalProperty("report.deleteReportsAgeInHours", "72", "delete reports after"); Document config = buildOnValidConfigXml() .withGlobalProperty(gp1.getProperty(), gp1.getPropertyValue(), gp1.getDescription(), null, null) .build(); config.getElementsByTagName("globalProperty").item(0).appendChild(config.createElement("ignoreMe")); Module module = parser.parse(writeConfigXmlToFile(config)); assertThat(module.getGlobalProperties().size(), is(1)); assertThat(module.getGlobalProperties().get(0).getProperty(), is(gp1.getProperty())); assertThat(module.getGlobalProperties().get(0).getPropertyValue(), is(gp1.getPropertyValue())); assertThat(module.getGlobalProperties().get(0).getDescription(), is(gp1.getDescription())); }
Map<String, GlobalProperty> propsMissingDatatype = new HashMap<>(); for (GlobalProperty prop : Context.getAdministrationService().getAllGlobalProperties()) { currentPropNames.add(prop.getProperty().toUpperCase()); if (prop.getDescription() == null) { propsMissingDescription.put(prop.getProperty().toUpperCase(), prop); if (prop.getDatatypeClassname() == null) { propsMissingDatatype.put(prop.getProperty().toUpperCase(), prop); String corePropName = coreProp.getProperty().toUpperCase(); propToUpdate.setDescription(coreProp.getDescription()); Context.getAdministrationService().saveGlobalProperty(propToUpdate); if (propToUpdate != null && coreProp.getDatatypeClassname() != null) { propToUpdate.setDatatypeClassname(coreProp.getDatatypeClassname()); propToUpdate.setDatatypeConfig(coreProp.getDatatypeConfig()); propToUpdate.setPreferredHandlerClassname(coreProp.getPreferredHandlerClassname()); propToUpdate.setHandlerConfig(coreProp.getHandlerConfig()); Context.getAdministrationService().saveGlobalProperty(propToUpdate);
if (gp != null && StringUtils.hasLength(gp.getPropertyValue())) { String currentDbVersion = gp.getPropertyValue(); if (log.isDebugEnabled()) { log.debug("version:column " + version + ":" + currentDbVersion); 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 {
String gpTextValue = globalProperty.getPropertyValue(); if (StringUtils.isBlank(gpTextValue)) { throw new APIException("GlobalProperty.invalid.value", globalProperty.setPropertyValue(String.valueOf(gpNumericValue + 1));
@Test public void saveGlobalProperty_shouldSaveAGlobalPropertyWhoseTypedValueIsHandledByACustomDatatype() { GlobalProperty gp = new GlobalProperty(); gp.setProperty("What time is it?"); gp.setDatatypeClassname(DateDatatype.class.getName()); gp.setValue(new Date()); adminService.saveGlobalProperty(gp); assertNotNull(gp.getValueReference()); }
@Test public void shouldGetASystemSettingByName() throws Exception { final String name = service.getAllGlobalProperties().get(0).getProperty(); MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/" + name); SimpleObject result = deserialize(handle(req)); GlobalProperty gp = service.getGlobalPropertyObject(name); assertEquals(gp.getUuid(), PropertyUtils.getProperty(result, "uuid")); assertEquals(gp.getProperty(), PropertyUtils.getProperty(result, "property")); assertEquals(gp.getDescription(), PropertyUtils.getProperty(result, "description")); assertEquals(gp.getValue(), PropertyUtils.getProperty(result, "value")); }
/** * @throws HL7Exception * @throws IOException * @see HL7Service#processHL7InQueue(HL7InQueue) */ @Test public void processHL7InQueue_shouldCreateHL7InArchiveAfterSuccessfulParsing() throws HL7Exception, IOException { executeDataSet("org/openmrs/hl7/include/ORUTest-initialData.xml"); File tempDir = new File(System.getProperty("java.io.tmpdir"), HL7Constants.HL7_ARCHIVE_DIRECTORY_NAME); if (tempDir.exists() && tempDir.isDirectory()) Assert.assertEquals(true, OpenmrsUtil.deleteDirectory(tempDir)); //set a global property for the archives directory as a temporary folder GlobalProperty gp = new GlobalProperty(); gp.setProperty(OpenmrsConstants.GLOBAL_PROPERTY_HL7_ARCHIVE_DIRECTORY); gp.setPropertyValue(tempDir.getAbsolutePath()); gp.setDescription("temp test dir"); Context.getAdministrationService().saveGlobalProperty(gp); HL7Service hl7service = Context.getHL7Service(); Assert.assertEquals(0, hl7service.getAllHL7InArchives().size()); HL7InQueue queueItem = hl7service.getHL7InQueue(1); hl7service.processHL7InQueue(queueItem); Assert.assertEquals(1, hl7service.getAllHL7InArchives().size()); }
public GlobalProperty saveGlobalProperty(GlobalProperty gp) throws APIException { if (gp.getProperty() != null && gp.getProperty().length() > 0) { if (gp.getProperty().equals(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST)) { if (gp.getPropertyValue() != null) { List<Locale> localeList = new ArrayList<>(); for (String localeString : gp.getPropertyValue().split(",")) { localeList.add(LocaleUtility.fromSpecification(localeString.trim())); gp.setPropertyValue(StringUtils.join(getAllowedLocales(), ", ")); throw new APIException(Context.getMessageSourceService().getMessage( "general.locale.localeListNotIncludingDefaultLocale", } else if (gp.getProperty().equals(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE) && gp.getPropertyValue() != null) { if (!localeList.contains(LocaleUtility.fromSpecification(gp.getPropertyValue().trim()))) { String value = gp.getPropertyValue(); gp.setPropertyValue(LocaleUtility.getDefaultLocale().toString()); throw new APIException((Context.getMessageSourceService().getMessage( "general.locale.defaultNotInAllowedLocalesList", new Object[] { value }, null)));
/** * @see org.openmrs.api.GlobalPropertyListener#globalPropertyChanged(org.openmrs.GlobalProperty) */ @Override public void globalPropertyChanged(GlobalProperty newValue) { if (newValue.getProperty().equals(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST)) { // reset the calculated locale values presentationLocales = null; } }
/** * Gets the value of the global property delegate * * @param instance the delegate instance to get the value off * @return value object */ @PropertyGetter("value") public static Object getValue(GlobalProperty globalProperty) { if (StringUtils.isNotEmpty(globalProperty.getDatatypeClassname()) && StringUtils.isNotEmpty(globalProperty.getDatatypeConfig())) { return globalProperty.getValue(); } else { return globalProperty.getPropertyValue(); } }
/** * Sets value for given property. * * @param property * @param value */ @PropertySetter("value") public static void setValue(GlobalProperty property, String value) throws Exception { if (StringUtils.isNotEmpty(property.getDatatypeClassname())) { CustomDatatype customDataType = CustomDatatypeUtil.getDatatype(property.getDatatypeClassname(), property.getDatatypeConfig()); if (customDataType != null) { try { property.setValue(customDataType.fromReferenceString(value)); } catch (Exception ex) { throw new APIException("Exception in converting value to custom data type", ex); } } else throw new APIException("Custom data type is null as per provided parameters"); } else { property.setPropertyValue(value); } } }
@Test public void saveGlobalProperties_shouldAssignUuidToAllNewProperties() { // get the current global properties List<GlobalProperty> globalProperties = adminService.getAllGlobalProperties(); // and now add a new one to it and save it globalProperties.add(new GlobalProperty("new prop", "new prop value", "desc")); adminService.saveGlobalProperties(globalProperties); assertNotNull(adminService.getGlobalPropertyObject("new prop").getUuid()); }
/** * @see org.openmrs.customdatatype.SingleCustomValue#setValueReferenceInternal(java.lang.String) * * @since 1.9 */ @Override public void setValueReferenceInternal(String valueToPersist) { setPropertyValue(valueToPersist); }
@Test public void shouldFindASystemSettingWithUUID() throws Exception { SimpleObject property = deserialize(handle(newGetRequest(getURI() + "/" + getUuid()))); GlobalProperty expectedProperty = service.getGlobalPropertyByUuid(getUuid()); assertNotNull(property); assertEquals(expectedProperty.getUuid(), PropertyUtils.getProperty(property, "uuid")); assertEquals(expectedProperty.getProperty(), PropertyUtils.getProperty(property, "property")); assertEquals(expectedProperty.getValue(), PropertyUtils.getProperty(property, "value")); }