Search in sources :

Example 6 with ActionMessage

use of org.apache.struts.action.ActionMessage in project head by mifos.

the class ClientCustActionForm method validateSpouseNames.

@SuppressWarnings({ "unchecked" })
private void validateSpouseNames(ActionErrors errors, HttpServletRequest request) {
    boolean mandatorySpouseType = false;
    Map<Short, List<FieldConfigurationEntity>> entityMandatoryFieldMap = (Map<Short, List<FieldConfigurationEntity>>) request.getSession().getServletContext().getAttribute(Constants.FIELD_CONFIGURATION);
    List<FieldConfigurationEntity> mandatoryfieldList = entityMandatoryFieldMap.get(EntityType.CLIENT.getValue());
    for (FieldConfigurationEntity fieldConfigurationEntity : mandatoryfieldList) {
        if (HiddenMandatoryFieldNamesConstants.SPOUSE_FATHER_INFORMATION.equals(fieldConfigurationEntity.getFieldName())) {
            if (fieldConfigurationEntity.isMandatory()) {
                mandatorySpouseType = true;
                break;
            }
        }
    }
    // issue 2929: when the spouse/father fields are hidden, then the values are null instead empty string - this need to be fixed here
    if (spouseName.getFirstName() == null) {
        spouseName.setFirstName("");
    }
    if (spouseName.getMiddleName() == null) {
        spouseName.setMiddleName("");
    }
    if (spouseName.getSecondLastName() == null) {
        spouseName.setSecondLastName("");
    }
    if (spouseName.getLastName() == null) {
        spouseName.setLastName("");
    }
    if (spouseName.getNameType() == null && (mandatorySpouseType || !StringUtils.isBlank(spouseName.getFirstName()) || !StringUtils.isBlank(spouseName.getMiddleName()) || !StringUtils.isBlank(spouseName.getSecondLastName()) || !StringUtils.isBlank(spouseName.getLastName()))) {
        errors.add(CustomerConstants.SPOUSE_TYPE, new ActionMessage(CustomerConstants.ERRORS_MANDATORY, getLocalizedMessage("Customer.SpouseType")));
    }
    if (mandatorySpouseType && StringUtils.isBlank(spouseName.getFirstName())) {
        errors.add(CustomerConstants.SPOUSE_FIRST_NAME, new ActionMessage(CustomerConstants.ERRORS_MANDATORY, getLocalizedMessage("Customer.SpouseFirstName")));
    }
    if (mandatorySpouseType && StringUtils.isBlank(spouseName.getLastName())) {
        errors.add(CustomerConstants.SPOUSE_LAST_NAME, new ActionMessage(CustomerConstants.ERRORS_MANDATORY, getLocalizedMessage("Customer.SpouseLastName")));
    }
}
Also used : ActionMessage(org.apache.struts.action.ActionMessage) FieldConfigurationEntity(org.mifos.framework.components.fieldConfiguration.business.FieldConfigurationEntity) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 7 with ActionMessage

use of org.apache.struts.action.ActionMessage in project head by mifos.

the class ClientCustActionForm method validateSelectedOfferings.

@SuppressWarnings("unchecked")
private void validateSelectedOfferings(ActionErrors errors, HttpServletRequest request) {
    boolean duplicateFound = false;
    for (int i = 0; i < selectedOfferings.size() - 1; i++) {
        for (int j = i + 1; j < selectedOfferings.size(); j++) {
            if (selectedOfferings.get(i) != null && selectedOfferings.get(j) != null && selectedOfferings.get(i).equals(selectedOfferings.get(j))) {
                String selectedOffering = "";
                try {
                    List<SavingsDetailDto> offeringsList = (List<SavingsDetailDto>) SessionUtils.getAttribute(ClientConstants.SAVINGS_OFFERING_LIST, request);
                    for (SavingsDetailDto savingsOffering : offeringsList) {
                        if (selectedOfferings.get(i).equals(savingsOffering.getPrdOfferingId())) {
                            selectedOffering = savingsOffering.getPrdOfferingName();
                        }
                        break;
                    }
                } catch (PageExpiredException pee) {
                }
                errors.add(ClientConstants.ERRORS_DUPLICATE_OFFERING_SELECTED, new ActionMessage(ClientConstants.ERRORS_DUPLICATE_OFFERING_SELECTED, selectedOffering));
                duplicateFound = true;
                break;
            }
        }
        if (duplicateFound) {
            break;
        }
    }
}
Also used : SavingsDetailDto(org.mifos.dto.domain.SavingsDetailDto) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) ActionMessage(org.apache.struts.action.ActionMessage) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with ActionMessage

use of org.apache.struts.action.ActionMessage in project head by mifos.

the class CollectionSheetEntryDtoPostPreviewValidator method validatePopulatedData.

private ActionErrors validatePopulatedData(final CollectionSheetEntryDto parent, final ActionErrors errors, final Locale locale) {
    List<CollectionSheetEntryDto> children = parent.getCollectionSheetEntryChildren();
    String acCollections = MessageLookup.getLocalizedMessage(CollectionSheetEntryConstants.AC_COLLECTION);
    if (null != children) {
        for (CollectionSheetEntryDto collectionSheetEntryDto : children) {
            validatePopulatedData(collectionSheetEntryDto, errors, locale);
        }
    }
    for (LoanAccountsProductDto accountView : parent.getLoanAccountDetails()) {
        if (accountView.isDisburseLoanAccountPresent() || accountView.getLoanAccountViews().size() > 1) {
            Money enteredAmount = new Money(Money.getDefaultCurrency(), 0.0);
            if (null != accountView.getEnteredAmount() && accountView.isValidAmountEntered()) {
                enteredAmount = new Money(Money.getDefaultCurrency(), getDoubleValue(accountView.getEnteredAmount()));
            }
            Money enteredDisbursalAmount = new Money(Money.getDefaultCurrency(), 0.0);
            if (null != accountView.getDisBursementAmountEntered() && accountView.isValidDisbursementAmount()) {
                enteredDisbursalAmount = new Money(Money.getDefaultCurrency(), getDoubleValue(accountView.getDisBursementAmountEntered()));
            }
            Money totalDueAmount = new Money(Money.getDefaultCurrency(), accountView.getTotalAmountDue());
            Money totalDisburtialAmount = new Money(Money.getDefaultCurrency(), accountView.getTotalDisburseAmount());
            if (totalDisburtialAmount.isGreaterThanZero()) {
                if ((!accountView.isValidDisbursementAmount() || accountView.getDisBursementAmountEntered() == null || !enteredDisbursalAmount.toString().equals(totalDisburtialAmount.toString())) && !enteredDisbursalAmount.isZero()) {
                    errors.add(CollectionSheetEntryConstants.BULKENTRYINVALIDAMOUNT, new ActionMessage(CollectionSheetEntryConstants.BULKENTRYINVALIDAMOUNT, accountView.getPrdOfferingShortName(), parent.getCustomerDetail().getDisplayName()));
                }
            }
            if (totalDueAmount.isGreaterThanZero()) {
                if ((!accountView.isValidAmountEntered() || accountView.getEnteredAmount() == null || !enteredAmount.toString().equals(totalDueAmount.toString())) && !enteredAmount.isZero()) {
                    errors.add(CollectionSheetEntryConstants.BULKENTRYINVALIDAMOUNT, new ActionMessage(CollectionSheetEntryConstants.BULKENTRYINVALIDAMOUNT, accountView.getPrdOfferingShortName(), parent.getCustomerDetail().getDisplayName()));
                }
            }
            boolean moreThanTwoLoanAccountsToPrepaid = isThereMoreThanTwoLoanAccountsToPrepaid(accountView.getLoanAccountViews());
            if (totalDisburtialAmount.isLessThanOrEqualZero() && totalDueAmount.isLessThanOrEqualZero()) {
                if (!accountView.isValidAmountEntered() || !accountView.isValidDisbursementAmount() || !enteredDisbursalAmount.isZero() || (!moreThanTwoLoanAccountsToPrepaid && !enteredAmount.isZero())) {
                    errors.add(CollectionSheetEntryConstants.BULKENTRYINVALIDAMOUNT, new ActionMessage(CollectionSheetEntryConstants.BULKENTRYINVALIDAMOUNT, accountView.getPrdOfferingShortName(), parent.getCustomerDetail().getDisplayName()));
                } else if (moreThanTwoLoanAccountsToPrepaid && !enteredAmount.isZero()) {
                    errors.add(CollectionSheetEntryConstants.BULKENTRYINVALIDPREPAYAMOUNT, new ActionMessage(CollectionSheetEntryConstants.BULKENTRYINVALIDPREPAYAMOUNT, accountView.getPrdOfferingShortName(), parent.getCustomerDetail().getDisplayName()));
                }
            }
        }
    }
    for (SavingsAccountDto savingsAccountDto : parent.getSavingsAccountDetails()) {
        if (!savingsAccountDto.isValidDepositAmountEntered() || !savingsAccountDto.isValidWithDrawalAmountEntered()) {
            errors.add(CollectionSheetEntryConstants.ERRORINVALIDAMOUNT, new ActionMessage(CollectionSheetEntryConstants.ERRORINVALIDAMOUNT, savingsAccountDto.getSavingsOfferingShortName(), parent.getCustomerDetail().getDisplayName()));
        }
    }
    CustomerAccountDto customerAccountDto = parent.getCustomerAccountDetails();
    Double customerAccountAmountEntered = 0.0;
    if (null != customerAccountDto.getCustomerAccountAmountEntered() && customerAccountDto.isValidCustomerAccountAmountEntered()) {
        customerAccountAmountEntered = getDoubleValue(customerAccountDto.getCustomerAccountAmountEntered());
    }
    if (!customerAccountDto.isValidCustomerAccountAmountEntered() || customerAccountAmountEntered < 0.0) {
        errors.add(CollectionSheetEntryConstants.BULKENTRYINVALIDACCOLLECTIONS, new ActionMessage(CollectionSheetEntryConstants.BULKENTRYINVALIDACCOLLECTIONS, acCollections, parent.getCustomerDetail().getDisplayName()));
    }
    return errors;
}
Also used : Money(org.mifos.framework.util.helpers.Money) CustomerAccountDto(org.mifos.customers.util.helpers.CustomerAccountDto) ActionMessage(org.apache.struts.action.ActionMessage) CollectionSheetEntryDto(org.mifos.application.collectionsheet.business.CollectionSheetEntryDto) LoanAccountsProductDto(org.mifos.accounts.loan.util.helpers.LoanAccountsProductDto) SavingsAccountDto(org.mifos.accounts.savings.util.helpers.SavingsAccountDto)

Example 9 with ActionMessage

use of org.apache.struts.action.ActionMessage in project head by mifos.

the class BulkEntryActionForm method receiptDateValidate.

private ActionErrors receiptDateValidate(ActionErrors errors) {
    if (StringUtils.isNotBlank(getReceiptDate()) && !DateUtils.isValidDate(getReceiptDate())) {
        String rcptdate = getLocalizedMessage(CollectionSheetEntryConstants.RECEIPTDATE);
        errors.add(CollectionSheetEntryConstants.INVALID_RECEIPT_DATE, new ActionMessage(CollectionSheetEntryConstants.INVALID_RECEIPT_DATE, rcptdate));
    }
    return errors;
}
Also used : ActionMessage(org.apache.struts.action.ActionMessage)

Example 10 with ActionMessage

use of org.apache.struts.action.ActionMessage in project head by mifos.

the class BulkEntryActionForm method mandatoryCheck.

private ActionErrors mandatoryCheck(Date meetingDate, UserContext userContext, short isCenterHierarchyExists) {
    String loanOfficer = getLocalizedMessage(CollectionSheetEntryConstants.LOANOFFICERS);
    String modeOfPayment = getLocalizedMessage(CollectionSheetEntryConstants.MODE_OF_PAYMENT);
    String dateOfTransaction = getLocalizedMessage(CollectionSheetEntryConstants.DATEOFTRXN);
    ActionErrors errors = receiptDateValidate(new ActionErrors());
    java.sql.Date currentDate = null;
    try {
        currentDate = DateUtils.getLocaleDate(userContext.getPreferredLocale(), DateUtils.getCurrentDate(userContext.getPreferredLocale()));
    } catch (InvalidDateException ide) {
        errors.add(CollectionSheetEntryConstants.INVALIDDATE, new ActionMessage(CollectionSheetEntryConstants.INVALIDDATE));
    }
    java.sql.Date trxnDate = null;
    String customerLabel = isCenterHierarchyExists == Constants.YES ? ConfigurationConstants.CENTER : ConfigurationConstants.GROUP;
    if (officeId == null || "".equals(officeId.trim())) {
        errors.add(CollectionSheetEntryConstants.MANDATORYFIELDS, new ActionMessage(CollectionSheetEntryConstants.MANDATORYFIELDS, getMessageText(ConfigurationConstants.BRANCHOFFICE)));
    }
    if (loanOfficerId == null || "".equals(loanOfficerId.trim())) {
        errors.add(CollectionSheetEntryConstants.MANDATORYFIELDS, new ActionMessage(CollectionSheetEntryConstants.MANDATORYFIELDS, loanOfficer));
    }
    if (customerId == null || "".equals(customerId.trim())) {
        errors.add(CollectionSheetEntryConstants.MANDATORYFIELDS, new ActionMessage(CollectionSheetEntryConstants.MANDATORYFIELDS, getLabel(customerLabel)));
    }
    if (getTransactionDate() != null && !getTransactionDate().equals("")) {
        try {
            trxnDate = DateUtils.getDateAsSentFromBrowser(getTransactionDate());
        } catch (InvalidDateException ide) {
            errors.add(CollectionSheetEntryConstants.MANDATORYFIELDS, new ActionMessage(AccountConstants.ERROR_INVALID_TRXN));
        }
    } else {
        errors.add(CollectionSheetEntryConstants.MANDATORYFIELDS, new ActionMessage(CollectionSheetEntryConstants.MANDATORYENTER, dateOfTransaction));
    }
    if (currentDate != null && meetingDate != null && trxnDate != null && (meetingDate.compareTo(trxnDate) > 0 || trxnDate.compareTo(currentDate) > 0)) {
        errors.add(CollectionSheetEntryConstants.MANDATORYFIELDS, new ActionMessage(CollectionSheetEntryConstants.INVALIDENDDATE, dateOfTransaction));
    } else if (meetingDate == null && trxnDate != null && trxnDate.compareTo(currentDate) != 0) {
        errors.add(CollectionSheetEntryConstants.MANDATORYFIELDS, new ActionMessage(CollectionSheetEntryConstants.MEETINGDATEEXCEPTION, dateOfTransaction));
    }
    if (paymentId == null || "".equals(paymentId.trim())) {
        errors.add(CollectionSheetEntryConstants.MANDATORYFIELDS, new ActionMessage(CollectionSheetEntryConstants.MANDATORYFIELDS, modeOfPayment));
    }
    return errors;
}
Also used : InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ActionMessage(org.apache.struts.action.ActionMessage) ActionErrors(org.apache.struts.action.ActionErrors) Date(java.sql.Date)

Aggregations

ActionMessage (org.apache.struts.action.ActionMessage)166 ActionErrors (org.apache.struts.action.ActionErrors)70 ActionMessages (org.apache.struts.action.ActionMessages)45 ResourceBundle (java.util.ResourceBundle)29 JspException (javax.servlet.jsp.JspException)22 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)22 Iterator (java.util.Iterator)21 Locale (java.util.Locale)19 List (java.util.List)9 ActionForward (org.apache.struts.action.ActionForward)9 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)8 ArrayList (java.util.ArrayList)8 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)7 DoubleConversionResult (org.mifos.framework.util.helpers.DoubleConversionResult)7 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)6 IOException (java.io.IOException)6 Date (java.sql.Date)6 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)6 ApplicationException (org.mifos.framework.exceptions.ApplicationException)5 UserPersistence (cn.edu.zju.acm.onlinejudge.persistence.UserPersistence)4