use of org.mifos.platform.questionnaire.service.QuestionGroupDetail in project head by mifos.
the class QuestionnaireServiceTest method shouldDefineQuestionGroup.
@Test
@Ignore
public void shouldDefineQuestionGroup() throws SystemException {
QuestionGroupDetail questionGroupDefinition = getQuestionGroupDetail(EVENT_CREATE, SOURCE_CLIENT, "S1", "S2");
setUpEventSourceExpectations(EVENT_CREATE, SOURCE_CLIENT);
when(questionDao.getDetails(anyInt())).thenReturn(getQuestion(11), getQuestion(12), getQuestion(11), getQuestion(12));
try {
QuestionGroupDetail questionGroupDetail = questionnaireService.defineQuestionGroup(questionGroupDefinition);
assertQuestionGroupDetail(questionGroupDetail);
verify(questionnaireValidator).validateForDefineQuestionGroup(questionGroupDefinition);
verify(questionGroupDao, times(1)).create(any(QuestionGroup.class));
verify(eventSourceDao, times(1)).retrieveByEventAndSource(anyString(), anyString());
verify(questionDao, times(4)).getDetails(anyInt());
} catch (SystemException e) {
Assert.fail("Should not have thrown the validation exception");
}
}
use of org.mifos.platform.questionnaire.service.QuestionGroupDetail in project head by mifos.
the class QuestionnaireServiceTest method shouldThrowValidationExceptionWhenQuestionGroupTitleIsNull.
@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
@Test(expected = SystemException.class)
public void shouldThrowValidationExceptionWhenQuestionGroupTitleIsNull() throws SystemException {
QuestionGroupDetail questionGroupDetail = new QuestionGroupDetail(0, null, null, asList(getSectionDefinition("S1")), false);
doThrow(new SystemException(QuestionnaireConstants.QUESTION_GROUP_TITLE_NOT_PROVIDED)).when(questionnaireValidator).validateForDefineQuestionGroup(questionGroupDetail);
questionnaireService.defineQuestionGroup(questionGroupDetail);
verify(questionnaireValidator).validateForDefineQuestionGroup(questionGroupDetail);
}
use of org.mifos.platform.questionnaire.service.QuestionGroupDetail in project head by mifos.
the class QuestionGroupController method groupByEventSource.
private Map<String, List<QuestionGroupDetail>> groupByEventSource(List<QuestionGroupDetail> questionGroups) {
Map<String, List<QuestionGroupDetail>> questionGroupsCategoriesSplit = new HashMap<String, List<QuestionGroupDetail>>();
for (QuestionGroupDetail questionGroup : questionGroups) {
for (EventSourceDto eventSourceDto : questionGroup.getEventSources()) {
String eventSource = eventSourceDto.toString();
if (!questionGroupsCategoriesSplit.containsKey(eventSource)) {
questionGroupsCategoriesSplit.put(eventSource, new ArrayList<QuestionGroupDetail>());
}
questionGroupsCategoriesSplit.get(eventSource).add(questionGroup);
}
}
// MIFOS-4164: sort by event source
Map<String, List<QuestionGroupDetail>> orderedQGCategories = new LinkedHashMap<String, List<QuestionGroupDetail>>();
for (EventSourceDto eventSourceDto : questionnaireServiceFacade.getAllEventSources()) {
String eventSource = eventSourceDto.toString();
List<QuestionGroupDetail> questionGroupsList = questionGroupsCategoriesSplit.get(eventSource);
if (questionGroupsList != null) {
orderedQGCategories.put(eventSource, questionGroupsList);
}
}
return orderedQGCategories;
}
use of org.mifos.platform.questionnaire.service.QuestionGroupDetail in project head by mifos.
the class QuestionGroupController method getQuestionGroup.
@RequestMapping("/viewQuestionGroupDetail.ftl")
public String getQuestionGroup(ModelMap model, HttpServletRequest httpServletRequest) {
String questionGroupId = httpServletRequest.getParameter("questionGroupId");
try {
if (isInvalidNumber(questionGroupId)) {
model.addAttribute("error_message_code", QuestionnaireConstants.INVALID_QUESTION_GROUP_ID);
} else {
QuestionGroupDetail questionGroupDetail = questionnaireServiceFacade.getQuestionGroupDetail(Integer.valueOf(questionGroupId));
QuestionGroupForm questionGroupForm = new QuestionGroupForm(questionGroupDetail);
model.addAttribute("questionGroupDetail", questionGroupForm);
model.addAttribute("eventSources", getAllQgEventSources());
}
} catch (SystemException e) {
//TODO: move mifosLogManager to common after dependency resolution
//MifosLogManager.getLogger(LoggerConstants.ROOTLOGGER).error(e.getMessage(), e);
model.addAttribute("error_message_code", QuestionnaireConstants.QUESTION_GROUP_NOT_FOUND);
}
return "viewQuestionGroupDetail";
}
use of org.mifos.platform.questionnaire.service.QuestionGroupDetail in project head by mifos.
the class LoanAccountRESTController method createLoanAccount.
@RequestMapping(value = "/account/loan/create", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> createLoanAccount(@RequestBody String request) throws Throwable {
ObjectMapper om = createLoanAccountMapping();
Map<String, String> map = new HashMap<String, String>();
CreationLoanAccountDto creationDetails = null;
try {
creationDetails = om.readValue(request, CreationLoanAccountDto.class);
} catch (JsonMappingException e) {
e.getCause();
}
loanValidator(creationDetails);
List<QuestionGroupDetail> questionGroups = new ArrayList<QuestionGroupDetail>();
LoanCreationResultDto loanResult = null;
LoanBO loanInfo = null;
CreateLoanAccount loanAccount = createLoan(creationDetails);
if (creationDetails.getGlim()) {
List<GroupMemberAccountDto> memberAccounts = creationDetails.glimsAsGroupMemberAccountDto(creationDetails.getGlimAccounts());
CreateGlimLoanAccount createGroupLoanAccount = new CreateGlimLoanAccount(memberAccounts, creationDetails.getLoanAmount(), loanAccount);
loanResult = loanAccountServiceFacade.createGroupLoanWithIndividualMonitoring(createGroupLoanAccount, questionGroups, null);
List<LoanBO> individuals = loanDao.findIndividualLoans(loanResult.getAccountId());
for (int i = 0; i < individuals.size(); i++) {
map.put("individualCustomer[" + i + "]", individuals.get(i).getCustomer().getDisplayName());
map.put("individualAccount[" + i + "]", individuals.get(i).getGlobalAccountNum());
map.put("individualAmmount[" + i + "]", individuals.get(i).getLoanAmount().toString());
}
} else {
loanResult = loanAccountServiceFacade.createLoan(loanAccount, questionGroups, null);
}
loanInfo = loanDao.findByGlobalAccountNum(loanResult.getGlobalAccountNum());
map.put("status", "success");
map.put("accountNum", loanInfo.getGlobalAccountNum());
map.put("GLIM", creationDetails.getGlim().toString());
map.put("customer", loanInfo.getCustomer().getDisplayName());
map.put("loanAmmount", loanInfo.getLoanAmount().toString());
map.put("noOfInstallments", loanInfo.getNoOfInstallments().toString());
map.put("externalId", loanInfo.getExternalId());
return map;
}
Aggregations