@Override public String getDefaultLayoutFormat() { String ret = Context.getAdministrationService().getGlobalProperty("layout.name.format"); return (ret != null && ret.length() > 0) ? ret : defaultLayoutFormat; } }
public void purgeGlobalProperty(String propertyName) { GlobalProperty globalProperty = administrationService.getGlobalPropertyObject(propertyName); if (globalProperty != null) { administrationService.purgeGlobalProperty(globalProperty); } Assert.assertNull(administrationService.getGlobalProperty(propertyName)); }
/** * @return the validTime for which the password reset activation key will be valid */ private int getValidTime() { String validTimeGp = Context.getAdministrationService() .getGlobalProperty(OpenmrsConstants.GP_PASSWORD_RESET_VALIDTIME); final int validTime = StringUtils.isBlank(validTimeGp) ? DEFAULT_VALID_TIME : Integer.parseInt(validTimeGp); //if valid time is less that a minute or greater than 12hrs reset valid time to 1 minutes else set it to the required time. return (validTime < MIN_VALID_TIME) || (validTime > MAX_VALID_TIME) ? DEFAULT_VALID_TIME : validTime; }
@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")); }
/** * @see org.openmrs.api.EncounterService#checkIfEncounterTypesAreLocked() */ @Override @Transactional(readOnly = true) public void checkIfEncounterTypesAreLocked() { String locked = Context.getAdministrationService().getGlobalProperty( OpenmrsConstants.GLOBAL_PROPERTY_ENCOUNTER_TYPES_LOCKED, "false"); if (Boolean.valueOf(locked)) { throw new EncounterTypeLockedException(); } }
/** * Returns the location of the OpenMRS log file. * * @return the path to the OpenMRS log file * @since 1.9.2 */ public static String getOpenmrsLogLocation() { String logPathGP = Context.getAdministrationService().getGlobalProperty(OpenmrsConstants.GP_LOG_LOCATION, ""); File logPath = OpenmrsUtil.getDirectoryInApplicationDataDirectory(logPathGP); File logFile = new File(logPath, "openmrs.log"); return logFile.getPath(); }
@Override public void checkIfFormsAreLocked() { String locked = Context.getAdministrationService().getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_FORMS_LOCKED, "false"); if (Boolean.valueOf(locked)) { throw new FormsLockedException(); } }
@Override public void checkIfPersonAttributeTypesAreLocked() { String locked = Context.getAdministrationService() .getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PERSON_ATRIBUTE_TYPES_LOCKED, "false"); if (Boolean.valueOf(locked)) { throw new PersonAttributeTypeLockedException(); } } }
/** * @see org.openmrs.api.ProviderService#getUnknownProvider() */ @Override @Transactional(readOnly = true) public Provider getUnknownProvider() { return getProviderByUuid(Context.getAdministrationService().getGlobalProperty( OpenmrsConstants.GP_UNKNOWN_PROVIDER_UUID)); } }
@Override public Concept getNonCodedDrugConcept() { String conceptUuid = Context.getAdministrationService().getGlobalProperty(OpenmrsConstants.GP_DRUG_ORDER_DRUG_OTHER); if (StringUtils.hasText(conceptUuid)) { return Context.getConceptService().getConceptByUuid(conceptUuid); } return null; }
private List<Concept> getSetMembersOfConceptSetFromGP(String globalProperty) { String conceptUuid = Context.getAdministrationService().getGlobalProperty(globalProperty); Concept concept = Context.getConceptService().getConceptByUuid(conceptUuid); if (concept != null && concept.getSet()) { return concept.getSetMembers(); } return Collections.emptyList(); } }
@Test public void setGlobalProperty_shouldSaveAGlobalPropertyWhoseTypedValueIsHandledByACustomDatatype() { String newKey = "Flag"; String initialValue = adminService.getGlobalProperty(newKey); assertNull(initialValue); adminService.setGlobalProperty(newKey, Boolean.FALSE.toString()); assertEquals(adminService.getGlobalProperty("Flag"), "false"); }
@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 getGlobalProperty_shouldGetPropertyInCaseInsensitiveWay() { executeDataSet("org/openmrs/api/include/AdministrationServiceTest-globalproperties.xml"); // sanity check String orig = adminService.getGlobalProperty("another-global-property"); assertEquals("anothervalue", orig); // try to get a global property with invalid case String noprop = adminService.getGlobalProperty("ANOTher-global-property"); assertEquals(orig, noprop); }
@Before public void initializeContext() throws APIException, IOException { mockStatic(Context.class); when(Context.getAdministrationService()).thenReturn(administrationService); when(administrationService.getGlobalProperty(any())).thenReturn(complexObsTestFolder.newFolder().getAbsolutePath()); }
@Test public void getGlobalProperty_shouldGetPropertyValueGivenValidPropertyName() { // put the global property into the database executeDataSet("org/openmrs/api/include/AdministrationServiceTest-globalproperties.xml"); String propertyValue = adminService.getGlobalProperty("a_valid_gp_key"); assertEquals("correct-value", propertyValue); }
@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"); }
/** * @see LocaleUtility#getDefaultLocale() */ @Test public void getDefaultLocale_shouldNotReturnNullIfGlobalPropertyDoesNotExist() { // sanity check Assert.assertNull(Context.getAdministrationService().getGlobalProperty( OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE)); // check for nonnullness Assert.assertNotNull(LocaleUtility.getDefaultLocale()); }
@Test public void saveGlobalProperty_shouldCreateGlobalPropertyInDatabase() { executeDataSet(ADMIN_INITIAL_DATA_XML); adminService.saveGlobalProperty(new GlobalProperty("detectHiddenSkill", "100")); assertNotNull(adminService.getGlobalProperty("detectHiddenSkill")); }
@Before public void setup() { allergies = new Allergies(); executeDataSet(ALLERGY_OTHER_NONCODED_TEST_DATASET); Allergen.setOtherNonCodedConceptUuid(Context.getAdministrationService().getGlobalProperty( OpenmrsConstants.GP_ALLERGEN_OTHER_NON_CODED_UUID)); }