/** * @see java.lang.Object#toString() */ @Override public String toString() { return "property: " + getProperty() + " value: " + getPropertyValue(); }
/** * @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; } }
/** * @see org.openmrs.api.GlobalPropertyListener#globalPropertyChanged(org.openmrs.GlobalProperty) */ @Override public void globalPropertyChanged(GlobalProperty newValue) { if (!OpenmrsConstants.GLOBAL_PROPERTY_ADDRESS_TEMPLATE.equals(newValue.getProperty())) { return; } try { setAddressTemplate(newValue.getPropertyValue()); } catch (Exception ex) { log.error("Error in new xml global property value", ex); setAddressTemplate(new ArrayList<>()); } }
/** * @see org.openmrs.api.AdministrationService#saveGlobalProperties(java.util.List) */ @Override @CacheEvict(value = "userSearchLocales", allEntries = true) public List<GlobalProperty> saveGlobalProperties(List<GlobalProperty> props) throws APIException { log.debug("saving a list of global properties"); // add all of the new properties for (GlobalProperty prop : props) { if (prop.getProperty() != null && prop.getProperty().length() > 0) { Context.getAdministrationService().saveGlobalProperty(prop); } } return props; }
/** * Returns all modules that are marked as mandatory. Currently this means there is a * <moduleid>.mandatory=true global property. * * @return list of modules ids for mandatory modules * @should return mandatory module ids */ public static List<String> getMandatoryModules() { List<String> mandatoryModuleIds = new ArrayList<>(); try { List<GlobalProperty> props = Context.getAdministrationService().getGlobalPropertiesBySuffix(".mandatory"); for (GlobalProperty prop : props) { if ("true".equalsIgnoreCase(prop.getPropertyValue())) { mandatoryModuleIds.add(prop.getProperty().replace(".mandatory", "")); } } } catch (Exception e) { log.warn("Unable to get the mandatory module list", e); } return mandatoryModuleIds; }
/** * @see org.openmrs.api.AdministrationService#purgeGlobalProperty(org.openmrs.GlobalProperty) */ @Override public void purgeGlobalProperty(GlobalProperty globalProperty) throws APIException { notifyGlobalPropertyDelete(globalProperty.getProperty()); dao.deleteGlobalProperty(globalProperty); }
/** * @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; } }
/** * Calls global property listeners registered for this create/change * * @param gp */ private void notifyGlobalPropertyChange(GlobalProperty gp) { for (GlobalPropertyListener listener : eventListeners.getGlobalPropertyListeners()) { if (listener.supportsPropertyName(gp.getProperty())) { listener.globalPropertyChanged(gp); } } }
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<>(); } else if (gp.getProperty().equals(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE) && gp.getPropertyValue() != null) {
@Test public void parse_shouldParseGlobalPropertyWithoutDescriptionElement() throws IOException { Document config = buildOnValidConfigXml() .withGlobalProperty("report.deleteReportsAgeInHours", "72", null, null, null) .build(); Module module = parser.parse(writeConfigXmlToFile(config)); assertThat(module.getGlobalProperties().size(), is(1)); assertThat(module.getGlobalProperties().get(0).getProperty(), is("report.deleteReportsAgeInHours")); assertThat(module.getGlobalProperties().get(0).getDescription(), is("")); }
@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())); }
@Test public void getGlobalPropertyByUuid_shouldFindObjectGivenValidUuid() { String uuid = "4f55827e-26fe-102b-80cb-0017a47871b3"; GlobalProperty prop = adminService.getGlobalPropertyByUuid(uuid); assertEquals("locale.allowed.list", prop.getProperty()); }
@Test public void getGlobalPropertiesByPrefix_shouldReturnAllRelevantGlobalPropertiesInTheDatabase() { executeDataSet("org/openmrs/api/include/AdministrationServiceTest-globalproperties.xml"); List<GlobalProperty> properties = adminService.getGlobalPropertiesByPrefix("fake.module."); for (GlobalProperty property : properties) { assertTrue(property.getProperty().startsWith("fake.module.")); assertTrue(property.getPropertyValue().startsWith("correct-value")); } }
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); propsMissingDatatype.put(prop.getProperty().toUpperCase(), prop); String corePropName = coreProp.getProperty().toUpperCase();
@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())); }
/** * @return the name */ private static String getName(GlobalProperty globalProperty) { String name = globalProperty.getProperty(); int sectionEnd = globalProperty.getProperty().indexOf("."); if (sectionEnd > 0) { name = globalProperty.getProperty().substring(sectionEnd + 1); } name = beautify(name); return name; }
/** * @return the section */ private static String getSection(GlobalProperty globalProperty) { String section = GENERAL; int sectionEnd = globalProperty.getProperty().indexOf("."); if (sectionEnd > 0) { section = globalProperty.getProperty().substring(0, sectionEnd); section = beautify(section); } return section; }
@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")); }
@Test public void shouldGetASystemSettingWithDotByName() throws Exception { final String name = "concept.defaultConceptMapType"; 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")); } }
@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")); }