/** * 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); } }
/** * Utility method to add prefix and suffix like expression * * @param identifier * @param adminService */ private Criterion getCriterionForSimpleSearch(String identifier, AdministrationService adminService) { String prefix = adminService.getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_PREFIX, ""); String suffix = adminService.getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SUFFIX, ""); return Restrictions.ilike("ids.identifier", prefix + identifier + suffix); }
@Test public void purgeGlobalProperty_shouldDeleteGlobalPropertyFromDatabase() { executeDataSet(ADMIN_INITIAL_DATA_XML); int allGlobalPropertiesSize = adminService.getAllGlobalProperties().size(); adminService.purgeGlobalProperty(adminService.getGlobalPropertyObject("a_valid_gp_key")); assertEquals(allGlobalPropertiesSize -1, adminService.getAllGlobalProperties().size()); }
public void purgeGlobalProperty(String propertyName) { GlobalProperty globalProperty = administrationService.getGlobalPropertyObject(propertyName); if (globalProperty != null) { administrationService.purgeGlobalProperty(globalProperty); } Assert.assertNull(administrationService.getGlobalProperty(propertyName)); }
/** * @see OrderService#getDrugDispensingUnits() */ @Test public void getDrugDispensingUnits_shouldReturnAnEmptyListIfNothingIsConfigured() { adminService.saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GP_DRUG_DISPENSING_UNITS_CONCEPT_UUID, "")); adminService.saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GP_DRUG_DOSING_UNITS_CONCEPT_UUID, "")); assertThat(orderService.getDrugDispensingUnits(), is(empty())); }
@Test public void saveGlobalProperty_shouldOverwriteGlobalPropertyIfExists() { executeDataSet(ADMIN_INITIAL_DATA_XML); GlobalProperty gp = adminService.getGlobalPropertyObject("a_valid_gp_key"); assertEquals("correct-value", gp.getPropertyValue()); gp.setPropertyValue("new-even-more-correct-value"); adminService.saveGlobalProperty(gp); assertEquals("new-even-more-correct-value", adminService.getGlobalProperty("a_valid_gp_key")); }
Map<String, GlobalProperty> propsMissingDescription = new HashMap<>(); Map<String, GlobalProperty> propsMissingDatatype = new HashMap<>(); for (GlobalProperty prop : Context.getAdministrationService().getAllGlobalProperties()) { currentPropNames.add(prop.getProperty().toUpperCase()); if (prop.getDescription() == null) { Context.getAdministrationService().saveGlobalProperty(coreProp); if (propToUpdate != null) { propToUpdate.setDescription(coreProp.getDescription()); Context.getAdministrationService().saveGlobalProperty(propToUpdate); propToUpdate.setPreferredHandlerClassname(coreProp.getPreferredHandlerClassname()); propToUpdate.setHandlerConfig(coreProp.getHandlerConfig()); Context.getAdministrationService().saveGlobalProperty(propToUpdate); Boolean disableValidation = Boolean.valueOf(as.getGlobalProperty(OpenmrsConstants.GP_DISABLE_VALIDATION, "false")); ValidateUtil.setDisableValidation(disableValidation); PersonName.setFormat(Context.getAdministrationService().getGlobalProperty( OpenmrsConstants.GLOBAL_PROPERTY_LAYOUT_NAME_FORMAT)); Allergen.setOtherNonCodedConceptUuid(Context.getAdministrationService().getGlobalProperty( OpenmrsConstants.GP_ALLERGEN_OTHER_NON_CODED_UUID));
@Test public void updateGlobalProperty_shouldUpdateAGlobalPropertyWhoseTypedvalueIsHandledByACustomDatatype() { GlobalProperty gp = new GlobalProperty(); gp.setProperty("Flag"); gp.setDatatypeClassname(BooleanDatatype.class.getName()); gp.setValue(Boolean.FALSE); adminService.saveGlobalProperty(gp); assertEquals(adminService.getGlobalProperty("Flag"), "false"); adminService.updateGlobalProperty("Flag", Boolean.TRUE.toString()); assertEquals(adminService.getGlobalProperty("Flag"), "true"); }
GlobalProperty gp = as.getGlobalPropertyObject(key); for (String sqlStatement : sqlStatements) { if (sqlStatement.trim().length() > 0) { as.executeSQL(sqlStatement, false); 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");
@Test public void saveGlobalProperty_shouldCreateGlobalPropertyInDatabase() { executeDataSet(ADMIN_INITIAL_DATA_XML); adminService.saveGlobalProperty(new GlobalProperty("detectHiddenSkill", "100")); assertNotNull(adminService.getGlobalProperty("detectHiddenSkill")); }
@Test public void saveGlobalProperties_shouldSaveAllGlobalPropertiesToTheDatabase() { // get the current global properties List<GlobalProperty> globalProperties = adminService.getAllGlobalProperties(); // and now add some new ones to it globalProperties.add(new GlobalProperty("new prop1", "new prop value1", "desc")); globalProperties.add(new GlobalProperty("new prop2", "new prop value2", "desc")); adminService.saveGlobalProperties(globalProperties); assertEquals("new prop value1", adminService.getGlobalProperty("new prop1")); assertEquals("new prop value2", adminService.getGlobalProperty("new prop2")); }
@Test public void saveGlobalProperties_shouldSavePropertiesWithCaseDifferenceOnly() { int originalSize = adminService.getAllGlobalProperties().size(); List<GlobalProperty> props = new ArrayList<>(); props.add(new GlobalProperty("a.property.key", "something")); props.add(new GlobalProperty("a.property.KEY", "somethingelse")); adminService.saveGlobalProperties(props); // make sure that we now have two properties props = adminService.getAllGlobalProperties(); assertEquals(originalSize + 1, props.size()); assertTrue(props.contains(adminService.getGlobalPropertyObject("a.property.KEY"))); }
@Test public void getAllowedLocales_shouldNotReturnDuplicatesEvenIfTheGlobalPropertyHasThem() { adminService.saveGlobalProperty( new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "en_GB,fr,es,en_GB")); assertEquals(3, adminService.getAllowedLocales().size()); }
@Test public void setGlobalProperty_shouldCreateGlobalPropertyInDatabase() { String newKey = "new_gp_key"; String initialValue = adminService.getGlobalProperty(newKey); assertNull(initialValue); // ensure gp doesn't exist before test adminService.setGlobalProperty(newKey, "new_key"); String newValue = adminService.getGlobalProperty(newKey); assertNotNull(newValue); }
@Test public void stopVisits_shouldCloseAllUnvoidedActiveVisitMatchingTheSpecifiedVisitTypes() { executeDataSet("org/openmrs/api/include/VisitServiceTest-includeVisitsAndTypeToAutoClose.xml"); String[] visitTypeNames = StringUtils.split(Context.getAdministrationService().getGlobalProperty( OpenmrsConstants.GP_VISIT_TYPES_TO_AUTO_CLOSE), ","); String openVisitsQuery = "SELECT visit_id FROM visit WHERE voided = 0 AND date_stopped IS NULL AND visit_type_id IN (SELECT visit_type_id FROM visit_type WHERE NAME IN ('" + StringUtils.join(visitTypeNames, "','") + "'))"; int activeVisitCount = Context.getAdministrationService().executeSQL(openVisitsQuery, true).size(); //sanity check assertTrue("There should be some active visits for this test to be valid", activeVisitCount > 0); //close any unvoided open visits visitService.stopVisits(null); activeVisitCount = Context.getAdministrationService().executeSQL(openVisitsQuery, true).size(); //all active unvoided visits should have been closed assertTrue("Not all active unvoided vists were closed", activeVisitCount == 0); }
/** * @see org.openmrs.api.AdministrationService#updateGlobalProperty(java.lang.String, * java.lang.String) */ @Override public void updateGlobalProperty(String propertyName, String propertyValue) throws IllegalStateException { GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject(propertyName); if (gp == null) { throw new IllegalStateException("Global property with the given propertyName does not exist" + propertyName); } gp.setPropertyValue(propertyValue); dao.saveGlobalProperty(gp); }
@Test public void updateGlobalProperty_shouldUpdateGlobalPropertyInDatabase() { executeDataSet("org/openmrs/api/include/AdministrationServiceTest-globalproperties.xml"); String propertyValue = adminService.getGlobalProperty("a_valid_gp_key"); assertEquals("correct-value", propertyValue); adminService.updateGlobalProperty("a_valid_gp_key", "new-value"); String newValue = adminService.getGlobalProperty("a_valid_gp_key"); assertEquals("new-value", newValue); }
@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")); }
/** * Fetches a global property by uuid, if no match is found, it tries to look up one with a * matching name with the assumption that the passed parameter is a global property name * * @see DelegatingCrudResource#getByUniqueId(java.lang.String) */ @Override public GlobalProperty getByUniqueId(String uuid) { GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyByUuid(uuid); if (gp == null) { //We assume the caller is fetching by name gp = Context.getAdministrationService().getGlobalPropertyObject(uuid); } return gp; }
@Test @Ignore public void setImplementationId_shouldSetUuidOnImplementationIdGlobalProperty() { ImplementationId validId = new ImplementationId(); validId.setImplementationId("JUNIT-TEST"); validId.setName("JUNIT-TEST implementation id"); validId.setPassphrase("This is the junit test passphrase"); validId.setDescription("This is the junit impl id used for testing of the openmrs API only."); adminService.setImplementationId(validId); GlobalProperty gp = adminService.getGlobalPropertyObject(OpenmrsConstants.GLOBAL_PROPERTY_IMPLEMENTATION_ID); assertNotNull(gp.getUuid()); }