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());
}
}
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;
}
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);
}
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;
}
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);
}
}
}
Aggregations