Search in sources :

Example 1 with ConceptStateConversion

use of org.openmrs.ConceptStateConversion in project openmrs-core by openmrs.

the class HibernateProgramWorkflowDAO method getConceptStateConversion.

/**
 * @see org.openmrs.api.db.ProgramWorkflowDAO#getConceptStateConversion(org.openmrs.ProgramWorkflow,
 *      org.openmrs.Concept)
 */
@Override
public ConceptStateConversion getConceptStateConversion(ProgramWorkflow workflow, Concept trigger) {
    ConceptStateConversion csc = null;
    if (workflow != null && trigger != null) {
        Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ConceptStateConversion.class, "csc");
        criteria.add(Restrictions.eq("csc.programWorkflow", workflow));
        criteria.add(Restrictions.eq("csc.concept", trigger));
        csc = (ConceptStateConversion) criteria.uniqueResult();
    }
    return csc;
}
Also used : ConceptStateConversion(org.openmrs.ConceptStateConversion) Criteria(org.hibernate.Criteria)

Example 2 with ConceptStateConversion

use of org.openmrs.ConceptStateConversion in project openmrs-core by openmrs.

the class StateConversionValidator method validate.

/**
 * Checks the form object for any inconsistencies/errors
 *
 * @see org.springframework.validation.Validator#validate(java.lang.Object,
 *      org.springframework.validation.Errors)
 * @should fail validation if concept is null or empty or whitespace
 * @should fail validation if programWorkflow is null or empty or whitespace
 * @should fail validation if programWorkflowState is null or empty or whitespace
 * @should pass validation if all required fields have proper values
 */
@Override
public void validate(Object obj, Errors errors) {
    ConceptStateConversion c = (ConceptStateConversion) obj;
    if (c == null) {
        log.debug("Rejecting because c is null");
        errors.rejectValue("conceptStateConversion", "error.general");
    } else {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "concept", "error.concept");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "programWorkflow", "error.programWorkflow");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "programWorkflowState", "error.programWorkflowState");
    }
}
Also used : ConceptStateConversion(org.openmrs.ConceptStateConversion)

Example 3 with ConceptStateConversion

use of org.openmrs.ConceptStateConversion in project openmrs-core by openmrs.

the class StateConversionValidatorTest method validate_shouldFailValidationIfProgramWorkflowIsNullOrEmptyOrWhitespace.

/**
 * @see StateConversionValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfProgramWorkflowIsNullOrEmptyOrWhitespace() {
    ConceptStateConversion csc = new ConceptStateConversion();
    csc.setProgramWorkflow(null);
    ProgramWorkflow workflow = Context.getProgramWorkflowService().getProgram(1).getAllWorkflows().iterator().next();
    csc.setConcept(Context.getConceptService().getConcept(3));
    csc.setProgramWorkflowState(workflow.getState(1));
    Errors errors = new BindException(csc, "csc");
    new StateConversionValidator().validate(csc, errors);
    Assert.assertTrue(errors.hasFieldErrors("programWorkflow"));
}
Also used : ProgramWorkflow(org.openmrs.ProgramWorkflow) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) ConceptStateConversion(org.openmrs.ConceptStateConversion) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 4 with ConceptStateConversion

use of org.openmrs.ConceptStateConversion in project openmrs-core by openmrs.

the class StateConversionValidatorTest method validate_shouldFailValidationIfProgramWorkflowStateIsNullOrEmptyOrWhitespace.

/**
 * @see StateConversionValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfProgramWorkflowStateIsNullOrEmptyOrWhitespace() {
    ConceptStateConversion csc = new ConceptStateConversion();
    ProgramWorkflow workflow = Context.getProgramWorkflowService().getProgram(1).getAllWorkflows().iterator().next();
    csc.setConcept(Context.getConceptService().getConcept(3));
    csc.setProgramWorkflow(workflow);
    csc.setProgramWorkflowState(null);
    Errors errors = new BindException(csc, "csc");
    new StateConversionValidator().validate(csc, errors);
    Assert.assertTrue(errors.hasFieldErrors("programWorkflowState"));
}
Also used : ProgramWorkflow(org.openmrs.ProgramWorkflow) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) ConceptStateConversion(org.openmrs.ConceptStateConversion) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 5 with ConceptStateConversion

use of org.openmrs.ConceptStateConversion in project openmrs-core by openmrs.

the class ProgramWorkflowServiceTest method getConceptStateConversionByUuid_shouldFindObjectGivenValidUuid.

/**
 * @see ProgramWorkflowService#getConceptStateConversionByUuid(String)
 */
@Test
public void getConceptStateConversionByUuid_shouldFindObjectGivenValidUuid() {
    String uuid = "6c72b064-506d-11de-80cb-001e378eb67e";
    ConceptStateConversion conceptStateConversion = Context.getProgramWorkflowService().getConceptStateConversionByUuid(uuid);
    Assert.assertEquals(1, (int) conceptStateConversion.getConceptStateConversionId());
}
Also used : ConceptStateConversion(org.openmrs.ConceptStateConversion) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

ConceptStateConversion (org.openmrs.ConceptStateConversion)7 Test (org.junit.Test)5 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)5 ProgramWorkflow (org.openmrs.ProgramWorkflow)4 BindException (org.springframework.validation.BindException)4 Errors (org.springframework.validation.Errors)4 Criteria (org.hibernate.Criteria)1