Search in sources :

Example 16 with AdministrationService

use of org.openmrs.api.AdministrationService in project openmrs-module-pihcore by PIH.

the class PihCoreActivator method setGlobalProperty.

protected void setGlobalProperty(String propertyName, String propertyValue) {
    AdministrationService administrationService = Context.getAdministrationService();
    GlobalProperty gp = administrationService.getGlobalPropertyObject(propertyName);
    if (gp == null) {
        gp = new GlobalProperty(propertyName);
    }
    gp.setPropertyValue(propertyValue);
    administrationService.saveGlobalProperty(gp);
}
Also used : AdministrationService(org.openmrs.api.AdministrationService) GlobalProperty(org.openmrs.GlobalProperty)

Example 17 with AdministrationService

use of org.openmrs.api.AdministrationService in project openmrs-core by openmrs.

the class ConceptServiceImpl method getConceptClassesOfOrderTypes.

private List<ConceptClass> getConceptClassesOfOrderTypes() {
    List<ConceptClass> mappedClasses = new ArrayList<>();
    AdministrationService administrationService = Context.getAdministrationService();
    List<List<Object>> result = administrationService.executeSQL("SELECT DISTINCT concept_class_id FROM order_type_class_map", true);
    for (List<Object> temp : result) {
        for (Object value : temp) {
            if (value != null) {
                mappedClasses.add(this.getConceptClass((Integer) value));
            }
        }
    }
    return mappedClasses;
}
Also used : ConceptClass(org.openmrs.ConceptClass) AdministrationService(org.openmrs.api.AdministrationService) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 18 with AdministrationService

use of org.openmrs.api.AdministrationService in project openmrs-core by openmrs.

the class PersonServiceImpl method getGlobalProperties.

private List<String> getGlobalProperties(String... properties) {
    List<String> result = new ArrayList<>();
    AdministrationService as = Context.getAdministrationService();
    for (String p : properties) {
        String id = as.getGlobalProperty(p, "");
        if (StringUtils.isNotBlank(id)) {
            result.add(id.trim());
        }
    }
    return result;
}
Also used : AdministrationService(org.openmrs.api.AdministrationService) ArrayList(java.util.ArrayList)

Example 19 with AdministrationService

use of org.openmrs.api.AdministrationService in project openmrs-core by openmrs.

the class UserValidatorTest method validate_shouldFailValidationIfEmailAsUsernameDisabledAndEmailProvided.

/**
 * @see UserValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfEmailAsUsernameDisabledAndEmailProvided() {
    User user = new User();
    user.setUsername("test@example.com");
    AdministrationService as = Context.getAdministrationService();
    as.saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_USER_REQUIRE_EMAIL_AS_USERNAME, "false"));
    Errors errors = new BindException(user, "user");
    validator.validate(user, errors);
    Assert.assertTrue(errors.hasFieldErrors("username"));
}
Also used : Errors(org.springframework.validation.Errors) User(org.openmrs.User) AdministrationService(org.openmrs.api.AdministrationService) BindException(org.springframework.validation.BindException) GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 20 with AdministrationService

use of org.openmrs.api.AdministrationService in project openmrs-core by openmrs.

the class UserValidatorTest method validate_shouldFailValidationIfEmailAsUsernameEnabledAndEmailInvalid.

/**
 * @see UserValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfEmailAsUsernameEnabledAndEmailInvalid() {
    User user = new User();
    user.setUsername("test@example.com");
    AdministrationService as = Context.getAdministrationService();
    as.saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_USER_REQUIRE_EMAIL_AS_USERNAME, "true"));
    Errors errors = new BindException(user, "user");
    validator.validate(user, errors);
    Assert.assertFalse(errors.hasFieldErrors("username"));
}
Also used : Errors(org.springframework.validation.Errors) User(org.openmrs.User) AdministrationService(org.openmrs.api.AdministrationService) BindException(org.springframework.validation.BindException) GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

AdministrationService (org.openmrs.api.AdministrationService)25 GlobalProperty (org.openmrs.GlobalProperty)8 ArrayList (java.util.ArrayList)5 User (org.openmrs.User)4 Test (org.junit.Test)3 IOException (java.io.IOException)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 List (java.util.List)2 EncounterType (org.openmrs.EncounterType)2 APIException (org.openmrs.api.APIException)2 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)2 BindException (org.springframework.validation.BindException)2 Errors (org.springframework.validation.Errors)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1