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