Search in sources :

Example 6 with UploadedFileDto

use of org.mifos.dto.screen.UploadedFileDto 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)

Example 7 with UploadedFileDto

use of org.mifos.dto.screen.UploadedFileDto in project head by mifos.

the class PictureFormFile method create.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ClientCustActionForm actionForm = (ClientCustActionForm) form;
    MeetingBO meeting = (MeetingBO) SessionUtils.getAttribute(CustomerConstants.CUSTOMER_MEETING, request);
    List<SavingsDetailDto> allowedSavingProducts = getSavingsOfferingsFromSession(request);
    if (ClientRules.isFamilyDetailsRequired()) {
        actionForm.setFamilyDateOfBirth();
        actionForm.constructFamilyDetails();
    }
    List<Short> selectedSavingProducts = actionForm.getSelectedOfferings();
    String clientName = actionForm.getClientName().getDisplayName();
    Short clientStatus = actionForm.getStatusValue().getValue();
    java.sql.Date mfiJoiningDate = DateUtils.getDateAsSentFromBrowser(actionForm.getMfiJoiningDate());
    String externalId = actionForm.getExternalId();
    AddressDto address = null;
    if (actionForm.getAddress() != null) {
        address = Address.toDto(actionForm.getAddress());
    }
    Short formedBy = actionForm.getFormedByPersonnelValue();
    java.sql.Date dateOfBirth = DateUtils.getDateAsSentFromBrowser(actionForm.getDateOfBirth());
    String governmentId = actionForm.getGovernmentId();
    boolean trained = isTrained(actionForm.getTrainedValue());
    java.sql.Date trainedDate = DateUtils.getDateAsSentFromBrowser(actionForm.getTrainedDate());
    Short groupFlagValue = actionForm.getGroupFlagValue();
    ClientNameDetailDto clientNameDetailDto = actionForm.getClientName();
    ClientPersonalDetailDto clientPersonalDetailDto = actionForm.getClientDetailView();
    ClientNameDetailDto spouseFatherName = actionForm.getSpouseName();
    InputStream picture = actionForm.getCustomerPicture();
    String parentGroupId = actionForm.getParentGroupId();
    List<ClientNameDetailDto> familyNames = actionForm.getFamilyNames();
    List<ClientFamilyDetailDto> familyDetails = actionForm.getFamilyDetails();
    Short loanOfficerId = actionForm.getLoanOfficerIdValue();
    Short officeId = actionForm.getOfficeIdValue();
    // only applies when status is active
    LocalDate activationDateAsToday = new LocalDate();
    ClientCreationDetail clientCreationDetail = new ClientCreationDetail(selectedSavingProducts, clientName, clientStatus, mfiJoiningDate, externalId, address, formedBy, dateOfBirth, governmentId, trained, trainedDate, groupFlagValue, clientNameDetailDto, clientPersonalDetailDto, spouseFatherName, picture, actionForm.getFeesToApply(), parentGroupId, familyNames, familyDetails, loanOfficerId, officeId, activationDateAsToday);
    MeetingDto meetingDto = null;
    if (meeting != null) {
        meetingDto = meeting.toDto();
    }
    CustomerDetailsDto clientDetails = this.clientServiceFacade.createNewClient(clientCreationDetail, meetingDto, allowedSavingProducts);
    List<FormFile> formFiles = actionForm.getFiles();
    List<UploadedFileDto> filesMetadata = actionForm.getFilesMetadata();
    for (int i = 0; i < formFiles.size(); i++) {
        if (formFiles.get(i).getFileSize() != 0) {
            InputStream inputStream = formFiles.get(i).getInputStream();
            UploadedFileDto fileMetadata = filesMetadata.get(i);
            clientServiceFacade.uploadFile(clientDetails.getId(), inputStream, fileMetadata);
        }
    }
    actionForm.setCustomerId(clientDetails.getId().toString());
    actionForm.setGlobalCustNum(clientDetails.getGlobalCustNum());
    actionForm.setEditFamily("notEdit");
    createClientQuestionnaire.saveResponses(request, actionForm, clientDetails.getId());
    return mapping.findForward(ActionForwards.create_success.toString());
}
Also used : MeetingBO(org.mifos.application.meeting.business.MeetingBO) LocalDate(org.joda.time.LocalDate) FormFile(org.apache.struts.upload.FormFile) ClientCreationDetail(org.mifos.dto.domain.ClientCreationDetail) ClientFamilyDetailDto(org.mifos.dto.screen.ClientFamilyDetailDto) ClientNameDetailDto(org.mifos.dto.screen.ClientNameDetailDto) CustomerDetailsDto(org.mifos.dto.domain.CustomerDetailsDto) UploadedFileDto(org.mifos.dto.screen.UploadedFileDto) ClientCustActionForm(org.mifos.customers.client.struts.actionforms.ClientCustActionForm) SavingsDetailDto(org.mifos.dto.domain.SavingsDetailDto) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ClientPersonalDetailDto(org.mifos.dto.screen.ClientPersonalDetailDto) AddressDto(org.mifos.dto.domain.AddressDto) Date(java.sql.Date) MeetingDto(org.mifos.dto.domain.MeetingDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 8 with UploadedFileDto

use of org.mifos.dto.screen.UploadedFileDto in project head by mifos.

the class ViewUploadedFilesController method formSubmit.

@RequestMapping(value = "/uploadNewFilePreview", method = RequestMethod.POST)
public ModelAndView formSubmit(HttpServletRequest request, @ModelAttribute("formBean") UploadedFileFormBean formBean, SessionStatus status) {
    ModelAndView modelAndView = new ModelAndView("redirect:/home.ftl");
    Integer entityId = Integer.parseInt(request.getParameter("entityId"));
    EntityType entityType = EntityType.valueOf(request.getParameter("entityType"));
    String backPageUrl = request.getParameter("backPageUrl");
    setFileService(entityType);
    try {
        if (!StringUtils.isNotBlank(request.getParameter("CANCEL"))) {
            UploadedFileDto uploadedFileDto = new UploadedFileDto(formBean.getFile().getOriginalFilename(), formBean.getFile().getContentType(), (int) formBean.getFile().getSize(), formBean.getDescription());
            fileService.create(entityId, formBean.getFile().getInputStream(), uploadedFileDto);
        }
        String backUrl = REDIRECT_TO_UPLOADED_FILES_LIST + String.format(UPLOADED_FILES_LIST_REQUEST_PARAMETERS, entityId.toString(), entityType.toString(), backPageUrl);
        modelAndView.setViewName(backUrl);
        status.setComplete();
    } catch (IOException e) {
        throw new MifosRuntimeException(e);
    }
    return modelAndView;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) IOException(java.io.IOException) UploadedFileDto(org.mifos.dto.screen.UploadedFileDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with UploadedFileDto

use of org.mifos.dto.screen.UploadedFileDto in project head by mifos.

the class ViewUploadedFilesController method showUploadedFiles.

@RequestMapping(value = "/viewUploadedFiles", method = RequestMethod.GET)
public ModelAndView showUploadedFiles(HttpServletRequest request, HttpServletResponse response) {
    Integer entityId = Integer.parseInt(request.getParameter("entityId"));
    EntityType entityType = EntityType.valueOf(request.getParameter("entityType"));
    String backPageUrl = request.getParameter("backPageUrl");
    setFileService(entityType);
    List<UploadedFileDto> uploadedFiles = null;
    if (StringUtils.isNotBlank(request.getParameter("downloadFileId"))) {
        Long fileId = Long.parseLong(request.getParameter("downloadFileId"));
        UploadedFileDto uploadedFileDto = fileService.read(fileId);
        response.setContentType(uploadedFileDto.getContentType());
        response.setContentLength(uploadedFileDto.getSize());
        response.setHeader("Content-Disposition", "attachment; filename=\"" + uploadedFileDto.getName() + "\"");
        try {
            response.getOutputStream().write(fileService.getData(uploadedFileDto));
        } catch (IOException e) {
            throw new MifosRuntimeException(e);
        }
    } else if (StringUtils.isNotBlank(request.getParameter("deleteFileId"))) {
        Long fileId = Long.parseLong(request.getParameter("deleteFileId"));
        Integer clientId = Integer.parseInt(request.getParameter("entityId"));
        fileService.delete(clientId, fileId);
    }
    uploadedFiles = fileService.readAll(Integer.parseInt(request.getParameter("entityId")));
    for (UploadedFileDto uploadedFileDto : uploadedFiles) {
        if (!fileService.checkIfFileExists(entityId, uploadedFileDto.getName())) {
            uploadedFileDto.setExistOnDisk(false);
        }
    }
    ModelAndView modelAndView = new ModelAndView("viewUploadedFiles");
    modelAndView.addObject("entityId", String.valueOf(entityId));
    modelAndView.addObject("entityType", entityType.toString());
    modelAndView.addObject("backPageUrl", backPageUrl);
    modelAndView.addObject("uploadedFiles", uploadedFiles);
    return modelAndView;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) IOException(java.io.IOException) UploadedFileDto(org.mifos.dto.screen.UploadedFileDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

UploadedFileDto (org.mifos.dto.screen.UploadedFileDto)9 IOException (java.io.IOException)3 FormFile (org.apache.struts.upload.FormFile)3 LocalDate (org.joda.time.LocalDate)3 MifosRuntimeException (org.mifos.core.MifosRuntimeException)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 ClientCustActionForm (org.mifos.customers.client.struts.actionforms.ClientCustActionForm)2 CreateAccountFeeDto (org.mifos.dto.domain.CreateAccountFeeDto)2 CreateAccountPenaltyDto (org.mifos.dto.domain.CreateAccountPenaltyDto)2 ClientFamilyDetailDto (org.mifos.dto.screen.ClientFamilyDetailDto)2 ClientNameDetailDto (org.mifos.dto.screen.ClientNameDetailDto)2 ClientPersonalDetailDto (org.mifos.dto.screen.ClientPersonalDetailDto)2 FileInfoEntity (org.mifos.framework.fileupload.domain.FileInfoEntity)2 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 CommonsMultipartFile (org.springframework.web.multipart.commons.CommonsMultipartFile)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 BigDecimal (java.math.BigDecimal)1