/** * @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); }
/** * @see ContextDAO#updateSearchIndex() */ @Override public void updateSearchIndex() { try { log.info("Updating the search index... It may take a few minutes."); Search.getFullTextSession(sessionFactory.getCurrentSession()).createIndexer().startAndWait(); GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject( OpenmrsConstants.GP_SEARCH_INDEX_VERSION); if (gp == null) { gp = new GlobalProperty(OpenmrsConstants.GP_SEARCH_INDEX_VERSION); } gp.setPropertyValue(OpenmrsConstants.SEARCH_INDEX_VERSION.toString()); Context.getAdministrationService().saveGlobalProperty(gp); log.info("Finished updating the search index"); } catch (Exception e) { throw new RuntimeException("Failed to update the search index", e); } }
/** * 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 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 getGlobalPropertyObject_shouldReturnNullWhenNoGlobalPropertyMatchGivenPropertyName() { executeDataSet(ADMIN_INITIAL_DATA_XML); assertNull(adminService.getGlobalPropertyObject("magicResistSkill")); }
/** * @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); }
GlobalProperty gp = as.getGlobalPropertyObject(key);
public void purgeGlobalProperty(String propertyName) { GlobalProperty globalProperty = administrationService.getGlobalPropertyObject(propertyName); if (globalProperty != null) { administrationService.purgeGlobalProperty(globalProperty); } Assert.assertNull(administrationService.getGlobalProperty(propertyName)); }
props.add(as.getGlobalPropertyObject(propName));
@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()); }
@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()); }
/** * Utility method that allows tests to easily configure and save a global property * @param string the name of the property to save * @param value the value of the property to save */ public static void saveGlobalProperty(String name, String value) { GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject(name); if (gp == null) { gp = new GlobalProperty(name); } gp.setPropertyValue(value); Context.getAdministrationService().saveGlobalProperty(gp); }
@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")); }
@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()); }
GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject( OpenmrsConstants.GP_VISIT_ASSIGNMENT_HANDLER); gp.setPropertyValue("org.openmrs.api.handler.ExistingOrNewVisitAssignmentHandler");
/** * @see EncounterService#saveEncounter(Encounter) */ @Test public void saveEncounter_shouldNotAssignEncounterToVisitIfTheNoAssignHandlerIsRegistered() { Encounter encounter = buildEncounter(); //We should have no visit assertNull(encounter.getVisit()); GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject( OpenmrsConstants.GP_VISIT_ASSIGNMENT_HANDLER); gp.setPropertyValue("org.openmrs.api.handler.NoVisitAssignmentHandler"); Context.getAdministrationService().saveGlobalProperty(gp); Context.getEncounterService().saveEncounter(encounter); //We should have no visit. assertNull(encounter.getVisit()); }
/** * @see EncounterService#saveEncounter(Encounter) */ @Test public void saveEncounter_shouldAssignEncounterToVisitIfTheAssignToExistingHandlerIsRegistered() { Encounter encounter = buildEncounter(); //We should have no visit assertNull(encounter.getVisit()); GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject( OpenmrsConstants.GP_VISIT_ASSIGNMENT_HANDLER); gp.setPropertyValue("org.openmrs.api.handler.ExistingVisitAssignmentHandler"); Context.getAdministrationService().saveGlobalProperty(gp); Context.getEncounterService().saveEncounter(encounter); //We should have a visit. assertNotNull(encounter.getVisit()); assertNotNull(encounter.getVisit().getVisitId()); }
/** * @see ConceptService#saveConcept(Concept) */ @Test public void saveConcept_shouldSetAPreferredNameForEachLocaleIfNoneIsMarked() { //add some other locales to locale.allowed.list for testing purposes GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject( OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST); gp.setPropertyValue(gp.getPropertyValue().concat(",fr,ja,en_GB")); Context.getAdministrationService().saveGlobalProperty(gp); Concept concept = new Concept(); concept.addName(new ConceptName("name1", Locale.ENGLISH)); concept.addName(new ConceptName("name2", Locale.ENGLISH)); concept.addName(new ConceptName("name3", Locale.FRENCH)); concept.addName(new ConceptName("name4", Locale.FRENCH)); concept.addName(new ConceptName("name5", Locale.JAPANESE)); concept.addName(new ConceptName("name6", Locale.JAPANESE)); concept.addDescription(new ConceptDescription("some description",null)); concept.setDatatype(new ConceptDatatype(1)); concept.setConceptClass(new ConceptClass(1)); concept = Context.getConceptService().saveConcept(concept); Assert.assertNotNull(concept.getPreferredName(Locale.ENGLISH)); Assert.assertNotNull(concept.getPreferredName(Locale.FRENCH)); Assert.assertNotNull(concept.getPreferredName(Locale.JAPANESE)); }
CareSetting careSetting = Context.getOrderService().getCareSetting(2); OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order"); assertNull(Context.getAdministrationService().getGlobalPropertyObject( OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG));
@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")); } }