Search in sources :

Example 1 with QuestionGroupDetail

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

the class LoanPrdAction method getQuestionGroups.

// Intentionally made public to aid testing !!!
@SuppressWarnings("unchecked")
public Set<QuestionGroupReference> getQuestionGroups(HttpServletRequest request) throws PageExpiredException {
    Set<QuestionGroupReference> questionGroupReferences = null;
    List<QuestionGroupDetail> questionGroups = (List<QuestionGroupDetail>) SessionUtils.getAttribute(ProductDefinitionConstants.SELECTEDQGLIST, request);
    if (CollectionUtils.isNotEmpty(questionGroups)) {
        questionGroupReferences = new LinkedHashSet<QuestionGroupReference>(questionGroups.size());
        for (QuestionGroupDetail questionGroupDetail : questionGroups) {
            QuestionGroupReference questionGroupReference = new QuestionGroupReference();
            questionGroupReference.setQuestionGroupId(questionGroupDetail.getId());
            questionGroupReferences.add(questionGroupReference);
        }
    }
    return questionGroupReferences;
}
Also used : QuestionGroupReference(org.mifos.accounts.productdefinition.business.QuestionGroupReference) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with QuestionGroupDetail

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

the class LoanPrdActionTest method shouldSetQuestionGroupsOnSession.

@Test
public void shouldSetQuestionGroupsOnSession() throws PageExpiredException {
    List<QuestionGroupDetail> questionGroupDetails = asList(getQuestionGroupDetail(1, "QG1", true), getQuestionGroupDetail(2, "QG2", true), getQuestionGroupDetail(3, "QG3", true));
    when(questionnaireServiceFacade.getQuestionGroups("Create", "Loan")).thenReturn(questionGroupDetails);
    when(request.getAttribute(Constants.CURRENTFLOWKEY)).thenReturn(FLOW_KEY);
    when(request.getSession()).thenReturn(session);
    when(session.getAttribute(Constants.FLOWMANAGER)).thenReturn(flowManager);
    Flow flow = new Flow();
    when(flowManager.getFlowWithValidation(FLOW_KEY)).thenReturn(flow);
    loanPrdAction.setQuestionGroupsOnSession(request, questionnaireServiceFacade);
    assertThat((List<QuestionGroupDetail>) flow.getObjectFromSession(ProductDefinitionConstants.SRCQGLIST), is(questionGroupDetails));
    verify(questionnaireServiceFacade, times(1)).getQuestionGroups("Create", "Loan");
    verify(request, times(1)).getAttribute(Constants.CURRENTFLOWKEY);
    verify(request, times(1)).getSession();
    verify(session, times(1)).getAttribute(Constants.FLOWMANAGER);
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) Flow(org.mifos.framework.util.helpers.Flow) Test(org.junit.Test)

Example 3 with QuestionGroupDetail

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

the class LoanPrdActionFormTest method shouldSetSelectedQuestionGroupsOnSession.

@Test
public void shouldSetSelectedQuestionGroupsOnSession() throws PageExpiredException {
    when(request.getAttribute(Constants.CURRENTFLOWKEY)).thenReturn(FLOW_KEY);
    when(request.getSession()).thenReturn(session);
    when(session.getAttribute(Constants.FLOWMANAGER)).thenReturn(flowManager);
    Flow flow = new Flow();
    when(flowManager.getFlowWithValidation(FLOW_KEY)).thenReturn(flow);
    List<QuestionGroupDetail> questionGroupDetails = asList(getQuestionGroupDetail(1, "QG1"), getQuestionGroupDetail(2, "QG2"), getQuestionGroupDetail(3, "QG3"), getQuestionGroupDetail(4, "QG4"));
    when(flowManager.getFromFlow(FLOW_KEY, ProductDefinitionConstants.SRCQGLIST)).thenReturn(questionGroupDetails);
    loanPrdActionForm.setLoanOfferingQGs(new String[] { "1", "4" });
    loanPrdActionForm.setSelectedQuestionGroups(request);
    List<QuestionGroupDetail> selectedQGDetails = (List<QuestionGroupDetail>) flow.getObjectFromSession(ProductDefinitionConstants.SELECTEDQGLIST);
    assertThat(selectedQGDetails, is(notNullValue()));
    assertThat(selectedQGDetails.get(0).getId(), is(1));
    assertThat(selectedQGDetails.get(0).getTitle(), is("QG1"));
    assertThat(selectedQGDetails.get(1).getId(), is(4));
    assertThat(selectedQGDetails.get(1).getTitle(), is("QG4"));
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Flow(org.mifos.framework.util.helpers.Flow) Test(org.junit.Test)

Example 4 with QuestionGroupDetail

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

the class LoanPrdActionFormTest method shouldSetSelectedQuestionGroupsOnSessionForNoQGs.

@Test
public void shouldSetSelectedQuestionGroupsOnSessionForNoQGs() throws PageExpiredException {
    when(request.getAttribute(Constants.CURRENTFLOWKEY)).thenReturn(FLOW_KEY);
    when(request.getSession()).thenReturn(session);
    when(session.getAttribute(Constants.FLOWMANAGER)).thenReturn(flowManager);
    Flow flow = new Flow();
    when(flowManager.getFlowWithValidation(FLOW_KEY)).thenReturn(flow);
    List<QuestionGroupDetail> questionGroupDetails = asList(getQuestionGroupDetail(1, "QG1"), getQuestionGroupDetail(2, "QG2"), getQuestionGroupDetail(3, "QG3"), getQuestionGroupDetail(4, "QG4"));
    when(flowManager.getFromFlow(FLOW_KEY, ProductDefinitionConstants.SRCQGLIST)).thenReturn(questionGroupDetails);
    loanPrdActionForm.setLoanOfferingQGs(null);
    loanPrdActionForm.setSelectedQuestionGroups(request);
    List<QuestionGroupDetail> selectedQGDetails = (List<QuestionGroupDetail>) flow.getObjectFromSession(ProductDefinitionConstants.SELECTEDQGLIST);
    assertThat(selectedQGDetails, is(notNullValue()));
    assertThat(selectedQGDetails.isEmpty(), is(true));
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Flow(org.mifos.framework.util.helpers.Flow) Test(org.junit.Test)

Example 5 with QuestionGroupDetail

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

the class LoanPrdActionForm method setSelectedQuestionGroups.

// Intentionally made public to aid testing !!!
void setSelectedQuestionGroups(HttpServletRequest request) {
    try {
        List<QuestionGroupDetail> questionGroups = new ArrayList<QuestionGroupDetail>();
        if (loanOfferingQGs != null && loanOfferingQGs.length > 0) {
            List<QuestionGroupDetail> srcQGDetails = (List<QuestionGroupDetail>) SessionUtils.getAttribute(ProductDefinitionConstants.SRCQGLIST, request);
            for (String loanOfferingQG : loanOfferingQGs) {
                for (QuestionGroupDetail questionGroupDetail : srcQGDetails) {
                    if (String.valueOf(questionGroupDetail.getId()).equals(loanOfferingQG)) {
                        questionGroups.add(questionGroupDetail);
                        break;
                    }
                }
            }
        }
        SessionUtils.setCollectionAttribute(ProductDefinitionConstants.SELECTEDQGLIST, questionGroups, request);
    } catch (PageExpiredException e) {
        logger.error("An error occurred while setting selected question groups on session", e);
    }
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) ArrayList(java.util.ArrayList) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) ArrayList(java.util.ArrayList) List(java.util.List)

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