Search in sources :

Example 16 with QuestionGroupDetail

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");
    }
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SystemException(org.mifos.framework.exceptions.SystemException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 17 with QuestionGroupDetail

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);
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SystemException(org.mifos.framework.exceptions.SystemException) Test(org.junit.Test)

Example 18 with 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;
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) LinkedHashMap(java.util.LinkedHashMap)

Example 19 with QuestionGroupDetail

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";
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SystemException(org.mifos.framework.exceptions.SystemException) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with QuestionGroupDetail

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;
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) HashMap(java.util.HashMap) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) GroupMemberAccountDto(org.mifos.clientportfolio.newloan.applicationservice.GroupMemberAccountDto) CreateLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) LoanCreationResultDto(org.mifos.dto.screen.LoanCreationResultDto) CreateGlimLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateGlimLoanAccount) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) CreationLoanAccountDto(org.mifos.application.servicefacade.CreationLoanAccountDto) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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