Search in sources :

Example 21 with SectionDetail

use of org.mifos.platform.questionnaire.service.SectionDetail in project head by mifos.

the class QuestionnaireValidatorTest method shouldThrowExceptionWhenANumericQuestionHasInvalidAnswer.

@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" })
@Test
public void shouldThrowExceptionWhenANumericQuestionHasInvalidAnswer() {
    QuestionDetail questionDetail = getNumericQuestionDetail("Numeric Question", 10, 100);
    SectionDetail sectionWithOneQuestion = getSectionWithOneQuestion("Sec1", questionDetail, "123ab");
    QuestionGroupDetail questionGroupDetail = getQuestionGroupDetail(0, "Title", "Create", "Client", asList(sectionWithOneQuestion));
    try {
        questionnaireValidator.validateForQuestionGroupResponses(asList(questionGroupDetail));
        fail("Should have thrown the validation exception");
    } catch (ValidationException e) {
        assertEquals(GENERIC_VALIDATION, e.getKey());
        assertEquals(true, e.hasChildExceptions());
        assertEquals(1, e.getChildExceptions().size());
        ValidationException childException = e.getChildExceptions().get(0);
        assertTrue(childException instanceof BadNumericResponseException);
        assertEquals("Numeric Question", childException.getIdentifier());
        assertEquals(Integer.valueOf(10), ((BadNumericResponseException) childException).getAllowedMinValue());
        assertEquals(Integer.valueOf(100), ((BadNumericResponseException) childException).getAllowedMaxValue());
    }
}
Also used : BadNumericResponseException(org.mifos.platform.questionnaire.exceptions.BadNumericResponseException) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) ValidationException(org.mifos.platform.validations.ValidationException) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) Test(org.junit.Test)

Example 22 with SectionDetail

use of org.mifos.platform.questionnaire.service.SectionDetail in project head by mifos.

the class QuestionGroupControllerTest method getQuestionGroupDetail.

private QuestionGroupDetail getQuestionGroupDetail(String title, String event, String source, String... sectionNames) {
    QuestionGroupDetail questionGroupDetail = new QuestionGroupDetail();
    questionGroupDetail.setTitle(title);
    questionGroupDetail.setEventSources(Arrays.asList(new EventSourceDto(event, source, null)));
    List<SectionDetail> sectionDetails = new ArrayList<SectionDetail>();
    for (String sectionName : sectionNames) {
        SectionDetail sectionDetail = new SectionDetail();
        sectionDetail.setName(sectionName);
        sectionDetails.add(sectionDetail);
    }
    questionGroupDetail.setSectionDetails(sectionDetails);
    return questionGroupDetail;
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) ArrayList(java.util.ArrayList) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto)

Example 23 with SectionDetail

use of org.mifos.platform.questionnaire.service.SectionDetail in project head by mifos.

the class QuestionGroupControllerTest method getQuestionGroupDetail.

private QuestionGroupDetail getQuestionGroupDetail(int questionGroupId, String title, String event, String source, boolean active, boolean editable, String... sectionNames) {
    List<SectionDetail> sectionDetails = new ArrayList<SectionDetail>();
    for (String sectionName : sectionNames) {
        SectionDetail sectionDetail = new SectionDetail();
        sectionDetail.setName(sectionName);
        sectionDetails.add(sectionDetail);
    }
    return new QuestionGroupDetail(questionGroupId, title, Arrays.asList(new EventSourceDto(event, source, null)), sectionDetails, editable, active);
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) ArrayList(java.util.ArrayList) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto)

Example 24 with SectionDetail

use of org.mifos.platform.questionnaire.service.SectionDetail in project head by mifos.

the class QuestionGroupControllerTest method getQuestionGroupFormWithOneSectionQuestion.

private QuestionGroupForm getQuestionGroupFormWithOneSectionQuestion(String qgTitle, int questionId) {
    QuestionGroupForm questionGroupForm = getQuestionGroupForm(qgTitle, "Create.Client");
    SectionDetail sectionDetail = new SectionDetail();
    sectionDetail.setName("Sec1");
    sectionDetail.setQuestionDetails(asList(new SectionQuestionDetail(getQuestionDetail(questionId, "Q3", QuestionType.FREETEXT), true)));
    questionGroupForm.getQuestionGroupDetail().getSectionDetails().add(sectionDetail);
    return questionGroupForm;
}
Also used : SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail)

Example 25 with SectionDetail

use of org.mifos.platform.questionnaire.service.SectionDetail in project head by mifos.

the class AuditLogServiceImpl method addAuditLogRegistry.

@Override
public void addAuditLogRegistry(QuestionGroupDetail questionGroupDetail, QuestionGroupDetail oldQuestionGroupDetail, int creatorId, int entityId, String source, String event) {
    PersonnelBusinessService pbs = new PersonnelBusinessService();
    String modifierName;
    if (oldQuestionGroupDetail != null && event.toLowerCase().equals(CREATE)) {
        String questionGroupName;
        String sectionName;
        String fieldName;
        String fieldValue;
        try {
            modifierName = pbs.getPersonnel((short) creatorId).getDisplayName();
        } catch (ServiceException e) {
            modifierName = "";
        }
        questionGroupName = questionGroupDetail.getTitle();
        AuditLog auditLog = new AuditLog(entityId, EntityType.getEntityValue(source.toUpperCase()), modifierName, new DateTimeService().getCurrentJavaSqlDate(), (short) creatorId);
        Set<AuditLogRecord> auditLogRecords = new HashSet<AuditLogRecord>();
        for (int sectionPosition = 0; sectionPosition < questionGroupDetail.getSectionDetails().size(); sectionPosition++) {
            SectionDetail sectionDetail = questionGroupDetail.getSectionDetails().get(sectionPosition);
            sectionName = sectionDetail.getName();
            for (int questionPosition = 0; questionPosition < sectionDetail.getQuestions().size(); questionPosition++) {
                SectionQuestionDetail sectionQuestionDetail = sectionDetail.getQuestions().get(questionPosition);
                fieldName = sectionQuestionDetail.getText();
                fieldValue = sectionQuestionDetail.getAnswer();
                String oldFieldValue = null;
                for (SectionDetail oldSectionDetail : oldQuestionGroupDetail.getSectionDetails()) {
                    if (oldSectionDetail.getName().equals(sectionName)) {
                        for (SectionQuestionDetail oldSectionQuestionDetail : oldSectionDetail.getQuestions()) {
                            if (oldSectionQuestionDetail.getText().equals(fieldName)) {
                                oldFieldValue = oldSectionQuestionDetail.getAnswer();
                                break;
                            }
                        }
                        break;
                    }
                }
                if (!fieldValue.equals("")) {
                    if (oldFieldValue != null && !oldFieldValue.equals("")) {
                        if (!oldFieldValue.equals(fieldValue)) {
                            auditLogRecords.add(new AuditLogRecord(trimField(questionGroupName + "/" + sectionName + "/" + fieldName, 100), trimField(oldFieldValue, 200), trimField(fieldValue, 200), auditLog));
                        }
                    } else {
                        auditLogRecords.add(new AuditLogRecord(trimField(questionGroupName + "/" + sectionName + "/" + fieldName, 100), "-", trimField(fieldValue, 200), auditLog));
                    }
                }
            }
        }
        if (!auditLogRecords.isEmpty()) {
            auditLog.addAuditLogRecords(auditLogRecords);
            legacyAuditDao.save(auditLog);
        }
    }
}
Also used : AuditLogRecord(org.mifos.framework.components.audit.business.AuditLogRecord) PersonnelBusinessService(org.mifos.customers.personnel.business.service.PersonnelBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) DateTimeService(org.mifos.framework.util.DateTimeService) AuditLog(org.mifos.framework.components.audit.business.AuditLog) HashSet(java.util.HashSet)

Aggregations

SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)56 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)34 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)25 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)24 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)20 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)13 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)12 Transactional (org.springframework.transaction.annotation.Transactional)7 QuestionGroupInstance (org.mifos.platform.questionnaire.domain.QuestionGroupInstance)5 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)5 ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)5 ValidationException (org.mifos.platform.validations.ValidationException)5 EventSourceEntity (org.mifos.platform.questionnaire.domain.EventSourceEntity)4 QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)3 Section (org.mifos.platform.questionnaire.domain.Section)3 BadNumericResponseException (org.mifos.platform.questionnaire.exceptions.BadNumericResponseException)3 QuestionGroupForm (org.mifos.platform.questionnaire.ui.model.QuestionGroupForm)3 QuestionGroupResponse (org.mifos.platform.questionnaire.domain.QuestionGroupResponse)2 QuestionGroupDetails (org.mifos.platform.questionnaire.service.QuestionGroupDetails)2