Search in sources :

Example 1 with CommonsMultipartFile

use of org.springframework.web.multipart.commons.CommonsMultipartFile in project head by mifos.

the class ImportClientsController method parseFile.

public ParsedClientsDto parseFile(ImportClientsFormBean importClientsFormBean) {
    ParsedClientsDto result = null;
    CommonsMultipartFile file = importClientsFormBean.getFile();
    InputStream is = null;
    if (file == null) {
        throw new MifosRuntimeException("File cannot be null");
    }
    try {
        is = file.getInputStream();
        result = importClientsServiceFacade.parseImportClients(is);
    } catch (IOException ex) {
        result = importClientsServiceFacade.createDtoFromSingleError(ex.getMessage());
    } finally {
        closeStream(is);
        importClientsFormBean.setFile(null);
    }
    return result;
}
Also used : ParsedClientsDto(org.mifos.dto.domain.ParsedClientsDto) InputStream(java.io.InputStream) IOException(java.io.IOException) CommonsMultipartFile(org.springframework.web.multipart.commons.CommonsMultipartFile) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with CommonsMultipartFile

use of org.springframework.web.multipart.commons.CommonsMultipartFile in project head by mifos.

the class ImportLoansController method parseFile.

/**
     * Parse xls file.
     * @param importLoansFormBean
     * @return
     */
public ParsedLoansDto parseFile(ImportLoansFormBean importLoansFormBean) {
    ParsedLoansDto result = null;
    CommonsMultipartFile file = importLoansFormBean.getFile();
    InputStream is = null;
    if (file == null) {
        throw new MifosRuntimeException("File cannot be null");
    }
    try {
        is = file.getInputStream();
        result = importLSServiceFacade.parseImportLoans(is);
    } catch (IOException ex) {
        result = importLSServiceFacade.createLoansDtoFromSingleError(ex.getMessage());
    } finally {
        closeStream(is);
        importLoansFormBean.setFile(null);
    }
    return result;
}
Also used : InputStream(java.io.InputStream) ParsedLoansDto(org.mifos.dto.domain.ParsedLoansDto) IOException(java.io.IOException) CommonsMultipartFile(org.springframework.web.multipart.commons.CommonsMultipartFile) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 3 with CommonsMultipartFile

use of org.springframework.web.multipart.commons.CommonsMultipartFile in project head by mifos.

the class ImportSavingsController method parseFile.

public ParsedSavingsDto parseFile(ImportSavingsFormBean importSavingsFormBean) {
    ParsedSavingsDto result = null;
    CommonsMultipartFile file = importSavingsFormBean.getFile();
    InputStream is = null;
    if (file == null) {
        throw new MifosRuntimeException("File cannot be null");
    }
    try {
        is = file.getInputStream();
        result = importLoansSavingsFacade.parseImportSavings(is);
    } catch (IOException ex) {
        result = importLoansSavingsFacade.createSavingsDtoFromSingleError(ex.getMessage());
    } finally {
        closeStream(is);
        importSavingsFormBean.setFile(null);
    }
    return result;
}
Also used : InputStream(java.io.InputStream) ParsedSavingsDto(org.mifos.dto.domain.ParsedSavingsDto) IOException(java.io.IOException) CommonsMultipartFile(org.springframework.web.multipart.commons.CommonsMultipartFile) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 4 with CommonsMultipartFile

use of org.springframework.web.multipart.commons.CommonsMultipartFile in project head by mifos.

the class LoanAccountController method submitLoanApplication.

private LoanCreationResultDto submitLoanApplication(Integer accountState, LoanAccountFormBean formBean, LoanAccountQuestionGroupFormBean loanAccountQuestionGroupFormBean, LoanAccountCashFlow loanAccountCashFlow, CashFlowSummaryFormBean cashFlowSummaryFormBean, LoanScheduleFormBean loanScheduleFormBean) {
    LocalDate disbursementDate = LoanCreationHelper.translateDisbursementDateToLocalDate(formBean);
    RecurringSchedule recurringSchedule = LoanCreationHelper.determineRecurringSchedule(formBean);
    List<CreateAccountFeeDto> accountFees = LoanCreationHelper.translateToAccountFeeDtos(formBean);
    List<CreateAccountFeeDto> additionalAccountFees = LoanCreationHelper.translateToAdditionalAccountFeeDtos(formBean);
    List<CreateAccountPenaltyDto> accountPenalties = LoanCreationHelper.translateToAccountPenaltyDtos(formBean);
    accountFees.addAll(additionalAccountFees);
    BigDecimal loanAmount = BigDecimal.valueOf(formBean.getAmount().doubleValue());
    BigDecimal minAllowedLoanAmount = BigDecimal.valueOf(formBean.getMinAllowedAmount().doubleValue());
    BigDecimal maxAllowedLoanAmount = BigDecimal.valueOf(formBean.getMaxAllowedAmount().doubleValue());
    CreateLoanAccount loanAccountDetails = new CreateLoanAccount(formBean.getCustomerId(), formBean.getProductId(), accountState, loanAmount, minAllowedLoanAmount, maxAllowedLoanAmount, formBean.getInterestRate().doubleValue(), disbursementDate, null, formBean.getNumberOfInstallments().intValue(), formBean.getMinNumberOfInstallments().intValue(), formBean.getMaxNumberOfInstallments().intValue(), formBean.getGraceDuration().intValue(), formBean.getFundId(), formBean.getLoanPurposeId(), formBean.getCollateralTypeId(), formBean.getCollateralNotes(), formBean.getExternalId(), formBean.isRepaymentScheduleIndependentOfCustomerMeeting(), recurringSchedule, accountFees, accountPenalties);
    LoanCreationResultDto loanCreationResultDto = null;
    if (formBean.isGlimApplicable()) {
        List<GroupMemberAccountDto> memberAccounts = createGroupMemberAccounts(formBean);
        BigDecimal totalLoanAmount = BigDecimal.valueOf(formBean.getAmount().doubleValue());
        CreateGlimLoanAccount createGroupLoanAccount = new CreateGlimLoanAccount(memberAccounts, totalLoanAmount, loanAccountDetails);
        loanCreationResultDto = loanAccountServiceFacade.createGroupLoanWithIndividualMonitoring(createGroupLoanAccount, loanAccountQuestionGroupFormBean.getQuestionGroups(), loanAccountCashFlow);
    } else {
        if (formBean.isVariableInstallmentsAllowed()) {
            List<DateTime> installmentDates = cashFlowSummaryFormBean.getInstallments();
            List<Number> totalInstallmentAmounts = cashFlowSummaryFormBean.getInstallmentAmounts();
            if (installmentDates.isEmpty()) {
                installmentDates = loanScheduleFormBean.getInstallments();
                totalInstallmentAmounts = loanScheduleFormBean.getInstallmentAmounts();
            }
            // api for creating loan with premade loan schedule
            loanCreationResultDto = loanAccountServiceFacade.createLoan(loanAccountDetails, loanAccountQuestionGroupFormBean.getQuestionGroups(), loanAccountCashFlow, installmentDates, totalInstallmentAmounts);
        } else {
            loanCreationResultDto = loanAccountServiceFacade.createLoan(loanAccountDetails, loanAccountQuestionGroupFormBean.getQuestionGroups(), loanAccountCashFlow);
        }
    }
    List<CommonsMultipartFile> formFiles = formBean.getFiles();
    List<UploadedFileDto> filesMetadata = formBean.getFilesMetadata();
    for (int i = 0; i < formFiles.size(); i++) {
        if (formFiles.get(i).getSize() != 0) {
            InputStream inputStream;
            try {
                inputStream = formFiles.get(i).getInputStream();
            } catch (IOException e) {
                throw new MifosRuntimeException();
            }
            UploadedFileDto fileMetadata = filesMetadata.get(i);
            loanAccountServiceFacade.uploadFile(loanCreationResultDto.getAccountId(), inputStream, fileMetadata);
        }
    }
    return loanCreationResultDto;
}
Also used : InputStream(java.io.InputStream) GroupMemberAccountDto(org.mifos.clientportfolio.newloan.applicationservice.GroupMemberAccountDto) IOException(java.io.IOException) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) DateTime(org.joda.time.DateTime) CommonsMultipartFile(org.springframework.web.multipart.commons.CommonsMultipartFile) RecurringSchedule(org.mifos.clientportfolio.loan.service.RecurringSchedule) CreateLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount) CreateAccountPenaltyDto(org.mifos.dto.domain.CreateAccountPenaltyDto) CreateAccountFeeDto(org.mifos.dto.domain.CreateAccountFeeDto) LoanCreationResultDto(org.mifos.dto.screen.LoanCreationResultDto) CreateGlimLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateGlimLoanAccount) UploadedFileDto(org.mifos.dto.screen.UploadedFileDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 5 with CommonsMultipartFile

use of org.springframework.web.multipart.commons.CommonsMultipartFile in project head by mifos.

the class LoanAccountController method retrieveLoanCreationDetails.

@SuppressWarnings("PMD")
public LoanCreationLoanDetailsDto retrieveLoanCreationDetails(int customerId, int productId, String eventId, String fileToDelete, LoanAccountFormBean formBean) {
    if ("newFileSelected".equals(eventId)) {
        if (formBean.getSelectedFile() != null) {
            CommonsMultipartFile file = formBean.getSelectedFile();
            formBean.getFiles().add(file);
            formBean.getFilesMetadata().add(new UploadedFileDto(file.getOriginalFilename(), file.getContentType(), (int) file.getSize(), formBean.getSelectedFileDescription()));
        }
        return dto;
    } else if ("fileDeleted".equals(eventId)) {
        if (fileToDelete != null) {
            int index = 0;
            for (CommonsMultipartFile formFile : formBean.getFiles()) {
                if (formFile.getOriginalFilename().equals(fileToDelete)) {
                    index = formBean.getFiles().indexOf(formFile);
                    break;
                }
            }
            if (index >= 0) {
                formBean.getFiles().remove(index);
                formBean.getFilesMetadata().remove(index);
            }
        }
        return dto;
    }
    MandatoryHiddenFieldsDto mandatoryHidden = this.adminServiceFacade.retrieveHiddenMandatoryFieldsToRead();
    dto = this.loanAccountServiceFacade.retrieveLoanDetailsForLoanAccountCreation(customerId, Integer.valueOf(productId).shortValue(), formBean.isRedoLoanAccount());
    formBean.setLocale(Locale.getDefault());
    formBean.setDigitsBeforeDecimalForInterest(dto.getAppConfig().getDigitsBeforeDecimalForInterest());
    formBean.setDigitsAfterDecimalForInterest(dto.getAppConfig().getDigitsAfterDecimalForInterest());
    formBean.setDigitsBeforeDecimalForMonetaryAmounts(dto.getAppConfig().getDigitsBeforeDecimalForMonetaryAmounts());
    formBean.setDigitsAfterDecimalForMonetaryAmounts(dto.getAppConfig().getDigitsAfterDecimalForMonetaryAmounts());
    formBean.setProductId(productId);
    formBean.setCustomerId(dto.getCustomerDetailDto().getCustomerId());
    formBean.setRepaymentScheduleIndependentOfCustomerMeeting(dto.isRepaymentIndependentOfMeetingEnabled());
    formBean.setGraceDuration(dto.getGracePeriodInInstallments());
    formBean.setMaxGraceDuration(dto.getGracePeriodInInstallments());
    if (dto.isRepaymentIndependentOfMeetingEnabled()) {
        // use loan product to default meeting details
        Integer recursEvery = dto.getLoanOfferingMeetingDetail().getMeetingDetailsDto().getEvery();
        Integer dayOfMonth = dto.getLoanOfferingMeetingDetail().getMeetingDetailsDto().getRecurrenceDetails().getDayNumber();
        Integer weekOfMonth = dto.getLoanOfferingMeetingDetail().getMeetingDetailsDto().getRecurrenceDetails().getWeekOfMonth();
        Integer dayOfWeek = dto.getLoanOfferingMeetingDetail().getMeetingDetailsDto().getRecurrenceDetails().getDayOfWeek();
        Integer recurrenceType = dto.getLoanOfferingMeetingDetail().getMeetingDetailsDto().getRecurrenceTypeId();
        Integer customerRecurrenceType = dto.getCustomerMeetingDetail().getMeetingDetailsDto().getRecurrenceTypeId();
        if (recurrenceType.equals(customerRecurrenceType)) {
            // if customer and product meeting frequencies are the same e.g. weekly or monthly, then default to customer details except for recurrence details
            dayOfMonth = dto.getCustomerMeetingDetail().getMeetingDetailsDto().getRecurrenceDetails().getDayNumber();
            weekOfMonth = dto.getCustomerMeetingDetail().getMeetingDetailsDto().getRecurrenceDetails().getWeekOfMonth();
            dayOfWeek = dto.getCustomerMeetingDetail().getMeetingDetailsDto().getRecurrenceDetails().getDayOfWeek();
        }
        // sometimes it seems customer meeting information can be setup wrong (i.e. has a day of month even though its weekly)
        if (recurrenceType == 1) {
            if (dateInformationIsAvailable(dayOfWeek)) {
                formBean.setWeeklyDetails(dayOfWeek, recursEvery);
            }
        } else if (recurrenceType == 2) {
            if (dateInformationIsAvailable(weekOfMonth) && dateInformationIsAvailable(dayOfWeek)) {
                formBean.setWeekOfMonthDetails(weekOfMonth, dayOfWeek, recursEvery);
            } else if (dateInformationIsAvailable(dayOfMonth)) {
                formBean.setDayOfMonthDetails(dayOfMonth, recursEvery);
            }
        } else if (recurrenceType == 3) {
            formBean.setRepaymentRecursEvery(recursEvery);
        }
    }
    formBean.setVariableInstallmentsAllowed(dto.isVariableInstallmentsAllowed());
    if (dto.isVariableInstallmentsAllowed()) {
        formBean.setMinGapInDays(dto.getMinGapInDays());
        formBean.setMaxGapInDays(dto.getMaxGapInDays());
        formBean.setMinInstallmentAmount(dto.getMinInstallmentAmount());
    }
    formBean.setGlimApplicable(dto.isGlimApplicable());
    if (dto.isGroup()) {
        formBean.setGroupLoanWithMembersEnabled(dto.isGroupLoanWithMembersEnabled());
    }
    if (dto.isGlimApplicable() || (dto.isGroup() && dto.isGroupLoanWithMembersEnabled())) {
        List<LoanAccountDetailsDto> clientData = dto.getClientDetails();
        String[] clientGlobalIdArray = new String[clientData.size()];
        int index = 0;
        for (LoanAccountDetailsDto loanAccountDetailsDto : clientData) {
            clientGlobalIdArray[index] = loanAccountDetailsDto.getClientId();
            index++;
        }
        formBean.setClientGlobalId(clientGlobalIdArray);
        formBean.setClientSelectForGroup(new Boolean[clientData.size()]);
        formBean.setClientAmount(new Number[clientData.size()]);
        Integer[] loanPurpose = new Integer[clientData.size()];
        formBean.setClientLoanPurposeId(loanPurpose);
        Number[][] selectedFeeIndividualAmounts = new Number[3][clientData.size()];
        formBean.setSelectedFeeIndividualAmounts(selectedFeeIndividualAmounts);
        Number[][] defaultFeeIndividualAmounts = new Number[dto.getDefaultFees().size()][clientData.size()];
        formBean.setDefaultFeeIndividualAmounts(defaultFeeIndividualAmounts);
    } else {
        formBean.setAmount(Double.valueOf(dto.getDefaultLoanAmount().toPlainString()));
    }
    formBean.setMinAllowedAmount(dto.getMinLoanAmount());
    formBean.setMaxAllowedAmount(dto.getMaxLoanAmount());
    formBean.setInterestRate(dto.getDefaultInterestRate());
    formBean.setMinAllowedInterestRate(dto.getMinInterestRate());
    formBean.setMaxAllowedInterestRate(dto.getMaxInterestRate());
    formBean.setNumberOfInstallments(dto.getDefaultNumberOfInstallments());
    formBean.setMinNumberOfInstallments(dto.getMinNumberOfInstallments());
    formBean.setMaxNumberOfInstallments(dto.getMaxNumberOfInstallments());
    formBean.setSourceOfFundsMandatory(mandatoryHidden.isMandatoryLoanSourceOfFund());
    formBean.setPurposeOfLoanMandatory(mandatoryHidden.isMandatoryLoanAccountPurpose());
    formBean.setCollateralTypeAndNotesHidden(mandatoryHidden.isHideSystemCollateralTypeNotes());
    formBean.setExternalIdHidden(mandatoryHidden.isHideSystemExternalId());
    if (!mandatoryHidden.isHideSystemExternalId()) {
        formBean.setExternalIdMandatory(mandatoryHidden.isMandatorySystemExternalId());
    }
    LocalDate possibleDisbursementDate = dto.getNextPossibleDisbursementDate();
    if (possibleDisbursementDate != null) {
        formBean.setDisbursementDateDD(possibleDisbursementDate.getDayOfMonth());
        formBean.setDisbursementDateMM(possibleDisbursementDate.getMonthOfYear());
        formBean.setDisbursementDateYY(possibleDisbursementDate.getYearOfEra());
    }
    formBean.setCollateralNotes("");
    Number[] defaultFeeId = new Number[dto.getDefaultFees().size()];
    Number[] defaultFeeAmountOrRate = new Number[dto.getDefaultFees().size()];
    int index = 0;
    for (FeeDto defaultFee : dto.getDefaultFees()) {
        if (defaultFee.isRateBasedFee()) {
            defaultFeeAmountOrRate[index] = defaultFee.getRate();
        } else {
            defaultFeeAmountOrRate[index] = defaultFee.getAmountAsNumber();
        }
        defaultFeeId[index] = Long.valueOf(defaultFee.getId());
        index++;
    }
    formBean.setDefaultFeeAmountOrRate(defaultFeeAmountOrRate);
    formBean.setDefaultFeeId(defaultFeeId);
    formBean.setDefaultFeeSelected(new Boolean[dto.getDefaultFees().size()]);
    formBean.setDefaultFees(dto.getDefaultFees());
    Number[] defaultPenaltyId = new Number[dto.getDefaultPenalties().size()];
    Number[] defaultPenaltyAmountOrRate = new Number[dto.getDefaultPenalties().size()];
    int idx = 0;
    for (PenaltyDto defaultPenalty : dto.getDefaultPenalties()) {
        if (defaultPenalty.isRateBasedPenalty()) {
            defaultPenaltyAmountOrRate[idx] = defaultPenalty.getRate();
        } else {
            defaultPenaltyAmountOrRate[idx] = defaultPenalty.getAmountAsNumber();
        }
        defaultPenaltyId[idx] = Long.valueOf(defaultPenalty.getPenaltyId());
        idx++;
    }
    formBean.setDefaultPenaltyAmountOrRate(defaultPenaltyAmountOrRate);
    formBean.setDefaultPenaltyId(defaultPenaltyId);
    formBean.setDefaultPenaltySelected(new Boolean[dto.getDefaultPenalties().size()]);
    formBean.setDefaultPenalties(dto.getDefaultPenalties());
    Number[] selectedFeeId = new Number[3];
    formBean.setSelectedFeeId(selectedFeeId);
    Number[] selectedFeeAmount = new Number[3];
    formBean.setSelectedFeeAmount(selectedFeeAmount);
    formBean.setAdditionalFees(dto.getAdditionalFees());
    if (formBean.getFiles() == null) {
        formBean.setFiles(new ArrayList<CommonsMultipartFile>());
        formBean.setFilesMetadata(new ArrayList<UploadedFileDto>());
    }
    formBean.setLoanInformationOrder(informationOrderServiceFacade.getInformationOrder("CreateLoan"));
    return dto;
}
Also used : PenaltyDto(org.mifos.dto.domain.PenaltyDto) CreateAccountPenaltyDto(org.mifos.dto.domain.CreateAccountPenaltyDto) CreateAccountFeeDto(org.mifos.dto.domain.CreateAccountFeeDto) FeeDto(org.mifos.dto.domain.FeeDto) MandatoryHiddenFieldsDto(org.mifos.dto.domain.MandatoryHiddenFieldsDto) LocalDate(org.joda.time.LocalDate) LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto) CommonsMultipartFile(org.springframework.web.multipart.commons.CommonsMultipartFile) UploadedFileDto(org.mifos.dto.screen.UploadedFileDto)

Aggregations

CommonsMultipartFile (org.springframework.web.multipart.commons.CommonsMultipartFile)23 InputStream (java.io.InputStream)9 IOException (java.io.IOException)8 File (java.io.File)7 BaseTest (com.epam.ta.reportportal.BaseTest)5 Test (org.junit.jupiter.api.Test)5 MifosRuntimeException (org.mifos.core.MifosRuntimeException)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 MultipartFile (org.springframework.web.multipart.MultipartFile)4 FileItem (org.apache.commons.fileupload.FileItem)3 BufferedInputStream (java.io.BufferedInputStream)2 FileInputStream (java.io.FileInputStream)2 DiskFileItem (org.apache.commons.fileupload.disk.DiskFileItem)2 Metadata (org.apache.tika.metadata.Metadata)2 MimeTypes (org.apache.tika.mime.MimeTypes)2 LocalDate (org.joda.time.LocalDate)2 CreateAccountFeeDto (org.mifos.dto.domain.CreateAccountFeeDto)2 CreateAccountPenaltyDto (org.mifos.dto.domain.CreateAccountPenaltyDto)2 UploadedFileDto (org.mifos.dto.screen.UploadedFileDto)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2