Search in sources :

Example 46 with QuestionGroupDetail

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

the class QuestionnaireMapperImpl method mapToQuestionGroupDetail.

@Override
public QuestionGroupDetail mapToQuestionGroupDetail(QuestionGroup questionGroup) {
    List<SectionDetail> sectionDetails = mapToSectionDetails(questionGroup.getSections());
    List<SectionLink> sectionLinks = new ArrayList<SectionLink>();
    List<SectionQuestionLink> sectionQuestionLinks = new ArrayList<SectionQuestionLink>();
    for (SectionDetail sectionDetail : sectionDetails) {
        for (SectionQuestionDetail sectionQuestionDetail : sectionDetail.getQuestionDetails()) {
            if (!sectionLinkDao.retrieveDependentSectionLinksFromQuestion(sectionQuestionDetail.getId()).isEmpty())
                sectionLinks.addAll(sectionLinkDao.retrieveDependentSectionLinksFromQuestion(sectionQuestionDetail.getId()));
            if (!sectionQuestionLinkDao.retrieveDependentSectionQuestionLinksFromQuestion(sectionQuestionDetail.getId()).isEmpty())
                sectionQuestionLinks.addAll(sectionQuestionLinkDao.retrieveDependentSectionQuestionLinksFromQuestion(sectionQuestionDetail.getId()));
        }
    }
    List<EventSourceDto> eventSourceDtos = mapToEventSource(questionGroup.getEventSources());
    return new QuestionGroupDetail(questionGroup.getId(), questionGroup.getTitle(), eventSourceDtos, sectionDetails, questionGroup.isEditable(), QuestionGroupState.ACTIVE.equals(questionGroup.getState()), questionGroup.isPpi(), mapToQuestionLinkDetails(sectionQuestionLinks), mapToSectionLinkDetails(sectionLinks));
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SectionQuestionLink(org.mifos.platform.questionnaire.domain.SectionQuestionLink) SectionLink(org.mifos.platform.questionnaire.domain.SectionLink) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) ArrayList(java.util.ArrayList) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto)

Example 47 with QuestionGroupDetail

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

the class QuestionGroupController method defineQuestionGroup.

@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
public String defineQuestionGroup(QuestionGroupForm questionGroupForm, RequestContext requestContext, boolean createMode) {
    String result = "success";
    if (!questionGroupHasErrors(questionGroupForm, requestContext)) {
        QuestionGroupDetail questionGroupDetail = null;
        try {
            if (createMode) {
                questionGroupForm.setActive(true);
            }
            if (questionGroupForm.isActive()) {
                questionGroupDetail = questionnaireServiceFacade.createActiveQuestionGroup(questionGroupForm.getQuestionGroupDetail());
            } else {
                questionGroupDetail = questionnaireServiceFacade.createQuestionGroup(questionGroupForm.getQuestionGroupDetail());
            }
            if (containsCreateLoanEventSource(questionGroupForm.getEventSources()) && questionGroupForm.getApplyToAllLoanProducts()) {
                questionnaireServiceFacade.applyToAllLoanProducts(questionGroupDetail.getId());
            }
            List<QuestionLinkDetail> questionLinkDetails = setFilledQuestionDetailForQuestionLinks(questionGroupForm.getQuestionLinks(), questionGroupDetail);
            List<SectionLinkDetail> sectionLinkDetails = setFilledSectionDetailForQuestionLinks(questionGroupForm.getSectionLinks(), questionGroupDetail);
            questionnaireServiceFacade.createQuestionLinks(questionLinkDetails);
            questionnaireServiceFacade.createSectionLinks(sectionLinkDetails);
        } catch (AccessDeniedException e) {
            constructAndLogSystemError(requestContext.getMessageContext(), new SystemException(QuestionnaireConstants.MISSING_PERMISSION_TO_ACTIVATE_QG, e));
            result = "failure";
        } catch (SystemException e) {
            constructAndLogSystemError(requestContext.getMessageContext(), e);
            result = "failure";
        }
    } else {
        result = "failure";
    }
    return result;
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SystemException(org.mifos.framework.exceptions.SystemException) QuestionLinkDetail(org.mifos.platform.questionnaire.service.QuestionLinkDetail) SectionLinkDetail(org.mifos.platform.questionnaire.service.SectionLinkDetail)

Example 48 with QuestionGroupDetail

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

the class QuestionnaireMapperImpl method mapToQuestionGroupInstanceDetail.

@Override
public QuestionGroupInstanceDetail mapToQuestionGroupInstanceDetail(QuestionGroupInstance questionGroupInstance) {
    QuestionGroupDetail questionGroupDetail = mapToQuestionGroupDetail(questionGroupInstance.getQuestionGroup());
    QuestionGroupInstanceDetail questionGroupInstanceDetail = new QuestionGroupInstanceDetail();
    questionGroupInstanceDetail.setId(questionGroupInstance.getId());
    questionGroupInstanceDetail.setDateCompleted(questionGroupInstance.getDateConducted());
    questionGroupInstanceDetail.setQuestionGroupDetail(questionGroupDetail);
    mapQuestionResponses(questionGroupInstance.getQuestionGroupResponses(), questionGroupInstanceDetail.getQuestionGroupDetail());
    return questionGroupInstanceDetail;
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) QuestionGroupInstanceDetail(org.mifos.platform.questionnaire.service.QuestionGroupInstanceDetail)

Example 49 with QuestionGroupDetail

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

the class QuestionnaireFlowAdapterTest method getQuestionGroups.

private List<QuestionGroupDetail> getQuestionGroups() {
    List<QuestionDetail> questions = Arrays.asList(new QuestionDetail(12, "Question1", QuestionType.FREETEXT, true, true));
    List<SectionDetail> section = Arrays.asList(getSectionDetailWithQuestions("Section1", questions, null, true));
    QuestionGroupDetail questionGroup = getQuestionGroupDetail("Group1", "Create", "Loan", section);
    return Arrays.asList(questionGroup);
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail)

Example 50 with QuestionGroupDetail

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

the class CreateSavingsAccountTest method testEnterAccountDetailsStep_DetailsEntered_WithQuestionGroup.

/**
     * Account info entry step is complete. There is a question group defined
     * for "Create Savings" work flow.
     */
@Test
public void testEnterAccountDetailsStep_DetailsEntered_WithQuestionGroup() {
    List<QuestionGroupDetail> groups = new ArrayList<QuestionGroupDetail>();
    groups.add(new QuestionGroupDetail());
    when(formBean.getQuestionGroups()).thenReturn(groups);
    setCurrentState("enterAccountDetailsStep");
    MockExternalContext context = new MockExternalContext();
    context.setEventId("detailsEntered");
    resumeFlow(context);
    assertCurrentStateEquals("answerQuestionGroupStep");
}
Also used : MockExternalContext(org.springframework.webflow.test.MockExternalContext) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)74 Test (org.junit.Test)43 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)25 ArrayList (java.util.ArrayList)23 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)15 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)11 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)11 List (java.util.List)8 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)8 ValidationException (org.mifos.platform.validations.ValidationException)7 LoanOfferingBO (org.mifos.accounts.productdefinition.business.LoanOfferingBO)6 QuestionGroupForm (org.mifos.platform.questionnaire.ui.model.QuestionGroupForm)6 SystemException (org.mifos.framework.exceptions.SystemException)5 Arrays.asList (java.util.Arrays.asList)4 QuestionGroupReference (org.mifos.accounts.productdefinition.business.QuestionGroupReference)4 LoanProductBuilder (org.mifos.domain.builders.LoanProductBuilder)4 EventSourceEntity (org.mifos.platform.questionnaire.domain.EventSourceEntity)4 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)4 Transactional (org.springframework.transaction.annotation.Transactional)4 HashMap (java.util.HashMap)3