Search in sources :

Example 11 with ValueListElement

use of org.mifos.dto.domain.ValueListElement in project head by mifos.

the class LoanAccountServiceFacadeWebTier method retrieveLoanAccountDetails.

@Override
public List<LoanAccountDetailsDto> retrieveLoanAccountDetails(LoanInformationDto loanInformationDto) {
    List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(loanInformationDto.getAccountId());
    List<ValueListElement> allLoanPurposes = this.loanProductDao.findAllLoanPurposes();
    List<LoanAccountDetailsDto> loanAccountDetailsViewList = new ArrayList<LoanAccountDetailsDto>();
    for (LoanBO individualLoan : individualLoans) {
        LoanAccountDetailsDto loandetails = new LoanAccountDetailsDto();
        loandetails.setClientId(individualLoan.getCustomer().getGlobalCustNum());
        loandetails.setClientName(individualLoan.getCustomer().getDisplayName());
        loandetails.setLoanAmount(null != individualLoan.getLoanAmount() && !EMPTY.equals(individualLoan.getLoanAmount().toString()) ? individualLoan.getLoanAmount().toString() : "0.0");
        loandetails.setLoanAccountId(individualLoan.getAccountId().toString());
        loandetails.setLoanGlobalAccountNum(individualLoan.getGlobalAccountNum());
        loandetails.setParentLoanGlobalAccountNum(individualLoan.getParentAccount().getGlobalAccountNum());
        loandetails.setParentLoanAccountId(individualLoan.getParentAccount().getAccountId());
        if (null != individualLoan.getBusinessActivityId()) {
            loandetails.setBusinessActivity(individualLoan.getBusinessActivityId().toString());
            for (ValueListElement busact : allLoanPurposes) {
                if (busact.getId().toString().equals(individualLoan.getBusinessActivityId().toString())) {
                    loandetails.setBusinessActivityName(busact.getName());
                }
            }
        }
        ClientBO client = this.customerDao.findClientBySystemId(individualLoan.getCustomer().getGlobalCustNum());
        String governmentId = client.getGovernmentId();
        loandetails.setGovermentId(StringUtils.isNotBlank(governmentId) ? governmentId : "-");
        loanAccountDetailsViewList.add(loandetails);
    }
    return loanAccountDetailsViewList;
}
Also used : LoanBO(org.mifos.accounts.loan.business.LoanBO) ClientBO(org.mifos.customers.client.business.ClientBO) ArrayList(java.util.ArrayList) ValueListElement(org.mifos.dto.domain.ValueListElement) LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto) MultipleLoanAccountDetailsDto(org.mifos.dto.screen.MultipleLoanAccountDetailsDto)

Example 12 with ValueListElement

use of org.mifos.dto.domain.ValueListElement in project head by mifos.

the class LoanAccountServiceFacadeWebTier method retrieveGetProductDetailsForLoanAccountCreation.

@Override
public LoanCreationProductDetailsDto retrieveGetProductDetailsForLoanAccountCreation(final Integer customerId) {
    final CustomerBO customer = this.customerDao.findCustomerById(customerId);
    final CustomerDetailDto customerDetailDto = customer.toCustomerDetailDto();
    // FIXME - keithw - below code is not needed when jsp/struts is removed as this is worked out for enter loan account details step.
    final Date nextMeetingDate = customer.getCustomerAccount().getNextMeetingDate();
    final String recurMonth = customer.getCustomerMeeting().getMeeting().getMeetingDetails().getRecurAfter().toString();
    final boolean isGroup = customer.isGroup();
    final boolean isGlimEnabled = configurationPersistence.isGlimEnabled();
    final boolean isLsimEnabled = configurationPersistence.isRepaymentIndepOfMeetingEnabled();
    final boolean isGroupLoanWithMembersEnabled = AccountingRules.isGroupLoanWithMembers();
    List<PrdOfferingDto> loanProductDtos = retrieveActiveLoanProductsApplicableForCustomer(customer, isLsimEnabled);
    LoanCreationGlimDto loanCreationGlimDto = null;
    List<LoanAccountDetailsDto> clientDetails = new ArrayList<LoanAccountDetailsDto>();
    Errors errors = new Errors();
    List<ErrorEntry> errorEntry = new ArrayList<ErrorEntry>();
    if (isGroup && isGlimEnabled && isGroupLoanWithMembersEnabled) {
        String defaultMessage = "New Group Loan option is enabled in configuration file and also GLIM option is enabled in the database. Loan for Group will be created using new Group Loan approach. Please turn off GLIM option in database. If you want to create Loan for Group using old approach, then please disable AccountingRules.GroupLoanWithMembers option in configuration file and restart Mifos.";
        errorEntry.add(new ErrorEntry("createLoanAccount.glim.and.new.glim.are.enabled", "activeClients2", defaultMessage));
        errors.addErrors(errorEntry);
    }
    if (isGroup && (isGlimEnabled || isGroupLoanWithMembersEnabled)) {
        final List<ValueListElement> loanPurposes = loanProductDao.findAllLoanPurposes();
        final List<ClientBO> activeClientsOfGroup = customerDao.findActiveClientsUnderGroup(customer);
        loanCreationGlimDto = new LoanCreationGlimDto(loanPurposes);
        if (activeClientsOfGroup == null || activeClientsOfGroup.size() < 2) {
            errorEntry.clear();
            String defaultMessage = "Group loan is not allowed as there must be at least two active clients within the group when Group loan with individual monitoring (GLIM) is enabled";
            errorEntry.add(new ErrorEntry("createLoanAccount.glim.invalid.less.than.two.active.clients.in.group", "activeClients", defaultMessage));
            errors.addErrors(errorEntry);
            loanProductDtos = new ArrayList<PrdOfferingDto>();
        } else {
            for (ClientBO client : activeClientsOfGroup) {
                LoanAccountDetailsDto clientDetail = new LoanAccountDetailsDto();
                clientDetail.setClientId(client.getCustomerId().toString());
                clientDetail.setClientName(client.getDisplayName());
                clientDetails.add(clientDetail);
            }
        }
    }
    return new LoanCreationProductDetailsDto(loanProductDtos, customerDetailDto, nextMeetingDate, recurMonth, isGroup, isGlimEnabled, loanCreationGlimDto, clientDetails, errors);
}
Also used : LoanCreationGlimDto(org.mifos.dto.screen.LoanCreationGlimDto) ClientBO(org.mifos.customers.client.business.ClientBO) ArrayList(java.util.ArrayList) ErrorEntry(org.mifos.platform.validations.ErrorEntry) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto) MultipleLoanAccountDetailsDto(org.mifos.dto.screen.MultipleLoanAccountDetailsDto) Errors(org.mifos.platform.validations.Errors) CustomerDetailDto(org.mifos.dto.domain.CustomerDetailDto) CustomerBO(org.mifos.customers.business.CustomerBO) PrdOfferingDto(org.mifos.dto.domain.PrdOfferingDto) LoanCreationProductDetailsDto(org.mifos.dto.screen.LoanCreationProductDetailsDto) ValueListElement(org.mifos.dto.domain.ValueListElement)

Example 13 with ValueListElement

use of org.mifos.dto.domain.ValueListElement in project head by mifos.

the class LoanAccountServiceFacadeWebTier method retrieveLoanDetailsForLoanAccountCreation.

@Override
public LoanCreationLoanDetailsDto retrieveLoanDetailsForLoanAccountCreation(Integer customerId, Short productId, boolean isLoanWithBackdatedPayments) {
    try {
        List<org.mifos.dto.domain.FeeDto> additionalFees = new ArrayList<org.mifos.dto.domain.FeeDto>();
        List<org.mifos.dto.domain.FeeDto> defaultFees = new ArrayList<org.mifos.dto.domain.FeeDto>();
        List<PenaltyDto> defaultPenalties = new ArrayList<PenaltyDto>();
        LoanOfferingBO loanProduct = this.loanProductDao.findById(productId.intValue());
        MeetingBO loanProductMeeting = loanProduct.getLoanOfferingMeetingValue();
        MeetingDto loanOfferingMeetingDto = loanProductMeeting.toDto();
        List<FeeBO> fees = this.feeDao.getAllAppllicableFeeForLoanCreation();
        for (FeeBO fee : fees) {
            if (!fee.isPeriodic() || (MeetingBO.isMeetingMatched(fee.getFeeFrequency().getFeeMeetingFrequency(), loanProductMeeting))) {
                org.mifos.dto.domain.FeeDto feeDto = fee.toDto();
                FeeFrequencyType feeFrequencyType = FeeFrequencyType.getFeeFrequencyType(fee.getFeeFrequency().getFeeFrequencyType().getId());
                FeeFrequencyTypeEntity feeFrequencyEntity = this.loanProductDao.retrieveFeeFrequencyType(feeFrequencyType);
                String feeFrequencyTypeName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(feeFrequencyEntity.getLookUpValue());
                feeDto.setFeeFrequencyType(feeFrequencyTypeName);
                if (feeDto.getFeeFrequency().isOneTime()) {
                    FeePayment feePayment = FeePayment.getFeePayment(fee.getFeeFrequency().getFeePayment().getId());
                    FeePaymentEntity feePaymentEntity = this.loanProductDao.retrieveFeePaymentType(feePayment);
                    String feePaymentName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(feePaymentEntity.getLookUpValue());
                    feeDto.getFeeFrequency().setPayment(feePaymentName);
                }
                if (loanProduct.isFeePresent(fee)) {
                    defaultFees.add(feeDto);
                } else {
                    additionalFees.add(feeDto);
                }
            }
        }
        List<PenaltyBO> penalties = this.penaltyDao.getAllAppllicablePenaltyForLoanCreation();
        for (PenaltyBO penalty : penalties) {
            if (loanProduct.isPenaltyPresent(penalty)) {
                defaultPenalties.add(penalty.toDto());
            }
        }
        if (AccountingRules.isMultiCurrencyEnabled()) {
            defaultFees = getFilteredFeesByCurrency(defaultFees, loanProduct.getCurrency().getCurrencyId());
            additionalFees = getFilteredFeesByCurrency(additionalFees, loanProduct.getCurrency().getCurrencyId());
        }
        Map<String, String> defaultFeeOptions = new LinkedHashMap<String, String>();
        for (org.mifos.dto.domain.FeeDto feeDto : defaultFees) {
            defaultFeeOptions.put(feeDto.getId(), feeDto.getName());
        }
        Map<String, String> additionalFeeOptions = new LinkedHashMap<String, String>();
        for (org.mifos.dto.domain.FeeDto feeDto : additionalFees) {
            additionalFeeOptions.put(feeDto.getId(), feeDto.getName());
        }
        CustomerBO customer = this.customerDao.findCustomerById(customerId);
        boolean isRepaymentIndependentOfMeetingEnabled = new ConfigurationBusinessService().isRepaymentIndepOfMeetingEnabled();
        LoanDisbursementDateFactory loanDisbursementDateFactory = new LoanDisbursmentDateFactoryImpl();
        LoanDisbursementDateFinder loanDisbursementDateFinder = null;
        LocalDate nextPossibleDisbursementDate = null;
        MeetingBO customerMeeting = customer.getCustomerMeetingValue();
        LocalDate dateToStart = new LocalDate();
        if (customerMeeting.isWeekly()) {
            LocalDate meetingStartDate = new LocalDate(customerMeeting.getMeetingStartDate());
            if (dateToStart.isBefore(meetingStartDate)) {
                dateToStart = meetingStartDate;
                loanDisbursementDateFinder = loanDisbursementDateFactory.create(customer, loanProduct, false, isLoanWithBackdatedPayments);
            } else {
                loanDisbursementDateFinder = loanDisbursementDateFactory.create(customer, loanProduct, isRepaymentIndependentOfMeetingEnabled, isLoanWithBackdatedPayments);
            }
            nextPossibleDisbursementDate = loanDisbursementDateFinder.findClosestMatchingDateFromAndInclusiveOf(dateToStart);
        } else {
            loanDisbursementDateFinder = loanDisbursementDateFactory.create(customer, loanProduct, isRepaymentIndependentOfMeetingEnabled, isLoanWithBackdatedPayments);
            nextPossibleDisbursementDate = loanDisbursementDateFinder.findClosestMatchingDateFromAndInclusiveOf(dateToStart);
        }
        LoanAmountOption eligibleLoanAmount = loanProduct.eligibleLoanAmount(customer.getMaxLoanAmount(loanProduct), customer.getMaxLoanCycleForProduct(loanProduct));
        LoanOfferingInstallmentRange eligibleNoOfInstall = loanProduct.eligibleNoOfInstall(customer.getMaxLoanAmount(loanProduct), customer.getMaxLoanCycleForProduct(loanProduct));
        Double defaultInterestRate = loanProduct.getDefInterestRate();
        Double maxInterestRate = loanProduct.getMaxInterestRate();
        Double minInterestRate = loanProduct.getMinInterestRate();
        LinkedHashMap<String, String> collateralOptions = new LinkedHashMap<String, String>();
        LinkedHashMap<String, String> purposeOfLoanOptions = new LinkedHashMap<String, String>();
        CustomValueDto customValueDto = legacyMasterDao.getLookUpEntity(MasterConstants.COLLATERAL_TYPES);
        List<CustomValueListElementDto> collateralTypes = customValueDto.getCustomValueListElements();
        for (CustomValueListElementDto element : collateralTypes) {
            collateralOptions.put(element.getId().toString(), element.getName());
        }
        // Business activities got in getPrdOfferings also but only for glim.
        List<ValueListElement> loanPurposes = legacyMasterDao.findValueListElements(MasterConstants.LOAN_PURPOSES);
        for (ValueListElement element : loanPurposes) {
            purposeOfLoanOptions.put(element.getId().toString(), element.getName());
        }
        List<FundDto> fundDtos = new ArrayList<FundDto>();
        List<FundBO> funds = getFunds(loanProduct);
        for (FundBO fund : funds) {
            FundDto fundDto = new FundDto();
            fundDto.setId(Short.toString(fund.getFundId()));
            fundDto.setCode(translateFundCodeToDto(fund.getFundCode()));
            fundDto.setName(fund.getFundName());
            fundDtos.add(fundDto);
        }
        ProductDetailsDto productDto = loanProduct.toDetailsDto();
        CustomerDetailDto customerDetailDto = customer.toCustomerDetailDto();
        Integer gracePeriodInInstallments = loanProduct.getGracePeriodDuration().intValue();
        final List<PrdOfferingDto> loanProductDtos = retrieveActiveLoanProductsApplicableForCustomer(customer, isRepaymentIndependentOfMeetingEnabled);
        InterestType interestType = InterestType.fromInt(loanProduct.getInterestTypes().getId().intValue());
        InterestTypesEntity productInterestType = this.loanProductDao.findInterestType(interestType);
        String interestTypeName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(productInterestType.getLookUpValue());
        LinkedHashMap<String, String> daysOfTheWeekOptions = new LinkedHashMap<String, String>();
        List<WeekDay> workingDays = new FiscalCalendarRules().getWorkingDays();
        for (WeekDay workDay : workingDays) {
            String weekdayName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(workDay.getPropertiesKey());
            workDay.setWeekdayName(weekdayName);
            daysOfTheWeekOptions.put(workDay.getValue().toString(), weekdayName);
        }
        LinkedHashMap<String, String> weeksOfTheMonthOptions = new LinkedHashMap<String, String>();
        for (RankOfDay weekOfMonth : RankOfDay.values()) {
            String weekOfMonthName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(weekOfMonth.getPropertiesKey());
            weeksOfTheMonthOptions.put(weekOfMonth.getValue().toString(), weekOfMonthName);
        }
        boolean variableInstallmentsAllowed = loanProduct.isVariableInstallmentsAllowed();
        boolean fixedRepaymentSchedule = loanProduct.isFixedRepaymentSchedule();
        Integer minGapInDays = Integer.valueOf(0);
        Integer maxGapInDays = Integer.valueOf(0);
        BigDecimal minInstallmentAmount = BigDecimal.ZERO;
        if (variableInstallmentsAllowed) {
            VariableInstallmentDetailsBO variableInstallmentsDetails = loanProduct.getVariableInstallmentDetails();
            minGapInDays = variableInstallmentsDetails.getMinGapInDays();
            maxGapInDays = variableInstallmentsDetails.getMaxGapInDays();
            minInstallmentAmount = variableInstallmentsDetails.getMinInstallmentAmount().getAmount();
        }
        boolean compareCashflowEnabled = loanProduct.isCashFlowCheckEnabled();
        // GLIM specific
        final boolean isGroup = customer.isGroup();
        final boolean isGlimEnabled = configurationPersistence.isGlimEnabled();
        //Group Loan Account with members specific
        final boolean isGroupLoanWithMembersEnabled = AccountingRules.isGroupLoanWithMembers();
        List<LoanAccountDetailsDto> clientDetails = new ArrayList<LoanAccountDetailsDto>();
        if (isGroup && (isGlimEnabled || isGroupLoanWithMembersEnabled)) {
            final List<ClientBO> activeClientsOfGroup = customerDao.findActiveClientsUnderGroup(customer);
            if (activeClientsOfGroup == null || activeClientsOfGroup.isEmpty()) {
                throw new BusinessRuleException(GroupConstants.IMPOSSIBLE_TO_CREATE_GROUP_LOAN);
            }
            for (ClientBO client : activeClientsOfGroup) {
                LoanAccountDetailsDto clientDetail = new LoanAccountDetailsDto();
                clientDetail.setClientId(client.getGlobalCustNum());
                clientDetail.setClientName(client.getDisplayName());
                clientDetails.add(clientDetail);
            }
        }
        // end of GLIM specific
        int digitsAfterDecimalForInterest = AccountingRules.getDigitsAfterDecimalForInterest().intValue();
        int digitsBeforeDecimalForInterest = AccountingRules.getDigitsBeforeDecimalForInterest().intValue();
        int digitsAfterDecimalForMonetaryAmounts = AccountingRules.getDigitsAfterDecimal().intValue();
        int digitsBeforeDecimalForMonetaryAmounts = AccountingRules.getDigitsBeforeDecimal().intValue();
        ApplicationConfigurationDto appConfig = new ApplicationConfigurationDto(digitsAfterDecimalForInterest, digitsBeforeDecimalForInterest, digitsAfterDecimalForMonetaryAmounts, digitsBeforeDecimalForMonetaryAmounts);
        Map<String, String> disbursalPaymentTypes = new LinkedHashMap<String, String>();
        try {
            for (PaymentTypeDto paymentTypeDto : accountService.getLoanDisbursementTypes()) {
                disbursalPaymentTypes.put(paymentTypeDto.getValue().toString(), paymentTypeDto.getName());
            }
        } catch (Exception e) {
            throw new SystemException(e);
        }
        Map<String, String> repaymentpaymentTypes = new LinkedHashMap<String, String>();
        try {
            for (PaymentTypeDto paymentTypeDto : accountService.getLoanPaymentTypes()) {
                repaymentpaymentTypes.put(paymentTypeDto.getValue().toString(), paymentTypeDto.getName());
            }
        } catch (Exception e) {
            throw new SystemException(e);
        }
        String currency = loanProduct.getCurrency().getCurrencyCode();
        return new LoanCreationLoanDetailsDto(currency, isRepaymentIndependentOfMeetingEnabled, loanOfferingMeetingDto, customer.getCustomerMeetingValue().toDto(), loanPurposes, productDto, gracePeriodInInstallments, customerDetailDto, loanProductDtos, interestTypeName, fundDtos, collateralOptions, purposeOfLoanOptions, defaultFeeOptions, additionalFeeOptions, defaultFees, additionalFees, BigDecimal.valueOf(eligibleLoanAmount.getDefaultLoanAmount()), BigDecimal.valueOf(eligibleLoanAmount.getMaxLoanAmount()), BigDecimal.valueOf(eligibleLoanAmount.getMinLoanAmount()), defaultInterestRate, maxInterestRate, minInterestRate, eligibleNoOfInstall.getDefaultNoOfInstall().intValue(), eligibleNoOfInstall.getMaxNoOfInstall().intValue(), eligibleNoOfInstall.getMinNoOfInstall().intValue(), nextPossibleDisbursementDate, daysOfTheWeekOptions, weeksOfTheMonthOptions, variableInstallmentsAllowed, fixedRepaymentSchedule, minGapInDays, maxGapInDays, minInstallmentAmount, compareCashflowEnabled, isGlimEnabled, isGroup, clientDetails, appConfig, defaultPenalties, disbursalPaymentTypes, repaymentpaymentTypes, isGroupLoanWithMembersEnabled);
    } catch (SystemException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : FeePayment(org.mifos.accounts.fees.util.helpers.FeePayment) LoanDisbursementDateFactory(org.mifos.clientportfolio.newloan.domain.LoanDisbursementDateFactory) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CustomValueListElementDto(org.mifos.application.master.business.CustomValueListElementDto) ClientBO(org.mifos.customers.client.business.ClientBO) ArrayList(java.util.ArrayList) LocalDate(org.joda.time.LocalDate) LinkedHashMap(java.util.LinkedHashMap) RankOfDay(org.mifos.application.meeting.util.helpers.RankOfDay) ApplicationConfigurationDto(org.mifos.dto.domain.ApplicationConfigurationDto) FeeFrequencyTypeEntity(org.mifos.accounts.fees.business.FeeFrequencyTypeEntity) CustomerDetailDto(org.mifos.dto.domain.CustomerDetailDto) LoanDisbursmentDateFactoryImpl(org.mifos.clientportfolio.newloan.domain.LoanDisbursmentDateFactoryImpl) PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) AmountPenaltyBO(org.mifos.accounts.penalties.business.AmountPenaltyBO) FeeFrequencyType(org.mifos.accounts.fees.util.helpers.FeeFrequencyType) CreateAccountFeeDto(org.mifos.dto.domain.CreateAccountFeeDto) FeeDto(org.mifos.dto.domain.FeeDto) WeekDay(org.mifos.application.meeting.util.helpers.WeekDay) InterestType(org.mifos.accounts.productdefinition.util.helpers.InterestType) VariableInstallmentDetailsBO(org.mifos.accounts.productdefinition.business.VariableInstallmentDetailsBO) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) LoanAmountOption(org.mifos.accounts.productdefinition.business.LoanAmountOption) FeeBO(org.mifos.accounts.fees.business.FeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) LoanCreationLoanDetailsDto(org.mifos.dto.screen.LoanCreationLoanDetailsDto) LoanOfferingInstallmentRange(org.mifos.accounts.productdefinition.business.LoanOfferingInstallmentRange) InterestTypesEntity(org.mifos.application.master.business.InterestTypesEntity) LoanCreationProductDetailsDto(org.mifos.dto.screen.LoanCreationProductDetailsDto) ProductDetailsDto(org.mifos.dto.domain.ProductDetailsDto) LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto) MultipleLoanAccountDetailsDto(org.mifos.dto.screen.MultipleLoanAccountDetailsDto) BusinessRuleException(org.mifos.service.BusinessRuleException) SystemException(org.mifos.framework.exceptions.SystemException) MessageLookup(org.mifos.application.master.MessageLookup) ConfigurationBusinessService(org.mifos.config.business.service.ConfigurationBusinessService) CustomerBO(org.mifos.customers.business.CustomerBO) FeeDto(org.mifos.dto.domain.FeeDto) FiscalCalendarRules(org.mifos.config.FiscalCalendarRules) CreateAccountPenaltyDto(org.mifos.dto.domain.CreateAccountPenaltyDto) PenaltyDto(org.mifos.dto.domain.PenaltyDto) LoanDisbursementDateFinder(org.mifos.clientportfolio.newloan.domain.LoanDisbursementDateFinder) FundBO(org.mifos.accounts.fund.business.FundBO) FeePaymentEntity(org.mifos.accounts.fees.business.FeePaymentEntity) PaymentTypeDto(org.mifos.dto.domain.PaymentTypeDto) FundDto(org.mifos.accounts.fund.servicefacade.FundDto) BigDecimal(java.math.BigDecimal) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) BusinessRuleException(org.mifos.service.BusinessRuleException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) AccountException(org.mifos.accounts.exceptions.AccountException) PropertyNotFoundException(org.mifos.framework.exceptions.PropertyNotFoundException) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) MeetingDto(org.mifos.dto.domain.MeetingDto) PrdOfferingDto(org.mifos.dto.domain.PrdOfferingDto) CustomValueDto(org.mifos.application.master.business.CustomValueDto) ValueListElement(org.mifos.dto.domain.ValueListElement) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 14 with ValueListElement

use of org.mifos.dto.domain.ValueListElement in project head by mifos.

the class LoginServiceFacadeWebTier method login.

@Override
public LoginDto login(String username, String password) {
    PersonnelBO user = this.personnelDao.findPersonnelByUsername(username);
    if (user == null) {
        throw new UsernameNotFoundException(LoginConstants.KEYINVALIDUSER);
    }
    MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
    List<ValueListElement> localeList = personnelServiceFacade.getDisplayLocaleList();
    Locale preferredLocale = new Locale(configMgr.getString(LANGUAGE_CODE), configMgr.getString(COUNTRY_CODE));
    String listElement = "[" + preferredLocale.toString() + "]";
    Short localeId = user.getPreferredLocale();
    for (ValueListElement element : localeList) {
        if (element.getName().contains(listElement)) {
            localeId = element.getId().shortValue();
            break;
        }
    }
    user.setPreferredLocale(localeId);
    UserContext userContext = new UserContext();
    userContext.setPreferredLocale(preferredLocale);
    userContext.setLocaleId(localeId);
    userContext.setId(user.getPersonnelId());
    userContext.setName(user.getDisplayName());
    userContext.setLevel(user.getLevelEnum());
    userContext.setRoles(user.getRoles());
    userContext.setLastLogin(user.getLastLogin());
    userContext.setPasswordChanged(user.getPasswordChanged());
    userContext.setBranchId(user.getOffice().getOfficeId());
    userContext.setBranchGlobalNum(user.getOffice().getGlobalOfficeNum());
    userContext.setOfficeLevelId(user.getOffice().getLevel().getId());
    user.updateDetails(userContext);
    try {
        this.transactionHelper.startTransaction();
        this.transactionHelper.beginAuditLoggingFor(user);
        user.login(password);
        this.personnelDao.save(user);
        this.transactionHelper.commitTransaction();
        boolean isPasswordExpired = new LocalDate(user.getPasswordExpirationDate()).isBefore(new LocalDate());
        return new LoginDto(user.getPersonnelId(), user.getOffice().getOfficeId(), user.isPasswordChanged(), isPasswordExpired);
    } catch (ApplicationException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } catch (Exception e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) Locale(java.util.Locale) UserContext(org.mifos.security.util.UserContext) LocalDate(org.joda.time.LocalDate) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersonnelException(org.mifos.customers.personnel.exceptions.PersonnelException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager) BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) LoginDto(org.mifos.dto.domain.LoginDto) ValueListElement(org.mifos.dto.domain.ValueListElement) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 15 with ValueListElement

use of org.mifos.dto.domain.ValueListElement in project head by mifos.

the class PersonnelServiceFacadeWebTier method retrieveUserSettings.

@Override
public UserSettingsDto retrieveUserSettings() {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    PersonnelBO personnel = this.personnelDao.findPersonnelById(userContext.getId());
    String gender = getNameForBusinessActivityEntity(personnel.getPersonnelDetails().getGender());
    String martialStatus = getNameForBusinessActivityEntity(personnel.getPersonnelDetails().getMaritalStatus());
    String language = Localization.getInstance().getDisplayName(personnel.getPreferredLocale());
    String sitePreference = SitePreferenceType.getSitePreference(personnel.getSitePreference()).name();
    List<ValueListElement> genders = this.customerDao.retrieveGenders();
    List<ValueListElement> martialStatuses = this.customerDao.retrieveMaritalStatuses();
    List<ValueListElement> languages = Localization.getInstance().getLocaleForUI();
    List<ValueListElement> sitePreferenceTypes = new ArrayList<ValueListElement>();
    for (short i = 0; i < SitePreferenceType.values().length; i++) {
        SitePreferenceType sitePreferenceType = SitePreferenceType.values()[i];
        ValueListElement valueListElement = new BusinessActivityEntity(sitePreferenceType.getValue().intValue(), sitePreferenceType.name(), sitePreferenceType.name());
        sitePreferenceTypes.add(valueListElement);
    }
    int age = DateUtils.DateDiffInYears(((Date) personnel.getPersonnelDetails().getDob()));
    if (age < 0) {
        age = 0;
    }
    return new UserSettingsDto(gender, martialStatus, language, age, sitePreference, genders, martialStatuses, languages, sitePreferenceTypes);
}
Also used : SitePreferenceType(org.mifos.config.SitePreferenceType) BusinessActivityEntity(org.mifos.application.master.business.BusinessActivityEntity) UserContext(org.mifos.security.util.UserContext) UserSettingsDto(org.mifos.dto.screen.UserSettingsDto) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) Date(java.sql.Date) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) ValueListElement(org.mifos.dto.domain.ValueListElement)

Aggregations

ValueListElement (org.mifos.dto.domain.ValueListElement)32 ArrayList (java.util.ArrayList)25 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)10 UserContext (org.mifos.security.util.UserContext)10 HashMap (java.util.HashMap)8 LoanAccountDetailsDto (org.mifos.dto.domain.LoanAccountDetailsDto)8 CustomerStatusDetailDto (org.mifos.dto.screen.CustomerStatusDetailDto)8 MessageLookup (org.mifos.application.master.MessageLookup)7 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)7 LoanBO (org.mifos.accounts.loan.business.LoanBO)6 MifosRuntimeException (org.mifos.core.MifosRuntimeException)6 ClientBO (org.mifos.customers.client.business.ClientBO)6 LocalDate (org.joda.time.LocalDate)5 CustomFieldDefinitionEntity (org.mifos.application.master.business.CustomFieldDefinitionEntity)5 PersonnelLevelEntity (org.mifos.customers.personnel.business.PersonnelLevelEntity)4 CustSearchActionForm (org.mifos.customers.struts.actionforms.CustSearchActionForm)4 ApplicationException (org.mifos.framework.exceptions.ApplicationException)4 MifosUser (org.mifos.security.MifosUser)4 RoleBO (org.mifos.security.rolesandpermission.business.RoleBO)4 Date (java.util.Date)3