Search in sources :

Example 11 with InvalidDateException

use of org.mifos.application.admin.servicefacade.InvalidDateException in project head by mifos.

the class DateComponentValidator method validate.

@Override
public Date validate(Object input) throws ValidationError {
    input = super.validate(input);
    Map inputMap = (Map) input;
    if (inputMap.size() == 0) {
        throw makeError(input, ErrorType.MISSING);
    }
    try {
        String dayValue = (String) inputMap.get("DD");
        String monthValue = (String) inputMap.get("MM");
        String yearValue = (String) inputMap.get("YY");
        return DateUtils.parseBrowserDateFields(yearValue, monthValue, dayValue);
    } catch (InvalidDateException e) {
        throw makeError(input, ErrorType.DATE_FORMAT);
    }
}
Also used : InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) Map(java.util.Map)

Example 12 with InvalidDateException

use of org.mifos.application.admin.servicefacade.InvalidDateException in project head by mifos.

the class DateUtils method convertDbToUserFmt.

public static String convertDbToUserFmt(String dbDate, String userPattern) throws InvalidDateException {
    try {
        SimpleDateFormat databaseFormat = new SimpleDateFormat(dbFormat, dateLocale);
        java.util.Date date = databaseFormat.parse(dbDate);
        SimpleDateFormat userFormat = new SimpleDateFormat(userPattern);
        return userFormat.format(date);
    } catch (ParseException e) {
        throw new InvalidDateException(dbDate, e);
    }
}
Also used : Date(java.util.Date) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 13 with InvalidDateException

use of org.mifos.application.admin.servicefacade.InvalidDateException in project head by mifos.

the class DateUtils method getDateAsSentFromBrowser.

/**
     * "as sent from browser" is a bit of a misnomer; it really is (at least in
     * many cases), as formatted by a routine on the server side like
     * ClientCustActionForm#getDateOfBirth()
     *
     * @throws InvalidDateException
     */
public static java.sql.Date getDateAsSentFromBrowser(String value) throws InvalidDateException {
    if (value == null || value == "") {
        return null;
    }
    try {
        String formatStr = "d" + dateSeparator + "M" + dateSeparator + "yy";
        SimpleDateFormat format = new SimpleDateFormat(formatStr, internalLocale);
        format.setLenient(false);
        return new java.sql.Date(format.parse(value).getTime());
    } catch (ParseException e) {
        throw new InvalidDateException(value);
    }
}
Also used : InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 14 with InvalidDateException

use of org.mifos.application.admin.servicefacade.InvalidDateException in project head by mifos.

the class LoanAccountActionForm method checkValidationForPreviewBefore.

private void checkValidationForPreviewBefore(ActionErrors errors, HttpServletRequest request) throws ApplicationException {
    LoanOfferingBO loanOffering = (LoanOfferingBO) SessionUtils.getAttribute(LoanConstants.LOANOFFERING, request);
    if (!((configService.isNewGlimEnabled() || configService.isGlimEnabled()) && getCustomer(request).isGroup())) {
        checkForMinMax(errors, loanAmount, amountRange, this.getLocalizedMessage("loan.amount"));
    }
    checkForMinMax(errors, interestRate, maxInterestRate, minInterestRate, this.getLocalizedMessage("loan.interestRate"));
    checkForMinMax(errors, noOfInstallments, installmentRange, this.getLocalizedMessage("loan.noOfInstallments"));
    if (StringUtils.isBlank(getDisbursementDate())) {
        addError(errors, "Proposed/Actual disbursal date", "errors.validandmandatory", this.getLocalizedMessage("loan.disbursalDate"));
    }
    // Check for invalid data format
    try {
        DateUtils.getLocaleDate(Locale.ENGLISH, getDisbursementDate());
    } catch (InvalidDateException ide) {
        addError(errors, "Proposed/Actual disbursal date", LoanExceptionConstants.ERROR_INVALID_DISBURSEMENT_DATE_FORMAT, this.getLocalizedMessage("loan.disbursalDate"));
    }
    if (isInterestDedAtDisbValue()) {
        setGracePeriodDuration("0");
    }
    if (((!isInterestDedAtDisbValue()) && StringUtils.isBlank(getGracePeriodDuration())) || (getDoubleValue(getGracePeriodDuration()) != null && getDoubleValue(getNoOfInstallments()) != null && getDoubleValue(getGracePeriodDuration()) >= getDoubleValue(getNoOfInstallments()))) {
        String gracePeriodForRepayments = this.getLocalizedMessage("loan.grace_period");
        String noInst = StringUtils.isBlank(getNoOfInstallments()) ? getStringValue(installmentRange.getMaxNoOfInstall()) : getNoOfInstallments();
        addError(errors, LoanConstants.GRACEPERIODDURATION, LoanConstants.GRACEPERIODERROR, gracePeriodForRepayments, noInst);
    }
}
Also used : InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO)

Example 15 with InvalidDateException

use of org.mifos.application.admin.servicefacade.InvalidDateException in project head by mifos.

the class VoucherBranchMappingActionForm method mandatoryCheck.

private ActionErrors mandatoryCheck(UserContext userContext) {
    Locale locale = userContext.getPreferredLocale();
    ResourceBundle resources = ResourceBundle.getBundle(FilePaths.SIMPLE_ACCOUNTING_RESOURCE, locale);
    ActionErrors errors = new ActionErrors();
    String branchname = resources.getString(SimpleAccountingConstants.BRANCH_NAME);
    String Amount = resources.getString(SimpleAccountingConstants.AMOUNT);
    String trxn_Type = resources.getString(SimpleAccountingConstants.TRXNTYPE);
    String main_Account = resources.getString(SimpleAccountingConstants.MAIN_ACCOUNT);
    String Notes = resources.getString(SimpleAccountingConstants.TRXN_NOTES);
    String trxn_Date = resources.getString(SimpleAccountingConstants.TRXNDATE);
    String[] amts = getAmount();
    String[] trannotes = getTransactionnotes();
    // String[] canames=getCoaname();
    List<CoaNamesDto> coaNamesDtolist = new ArrayList<CoaNamesDto>();
    if (amts.length < 0 || "".equals(amts)) {
        errors.add(SimpleAccountingConstants.MANDATORYENTER, new ActionMessage(SimpleAccountingConstants.MANDATORYENTER, Amount));
    }
    for (int i = 0; i < amts.length; i++) {
        if (amts[i].equalsIgnoreCase("0")) {
            errors.add(SimpleAccountingConstants.MANDATORYENTER, new ActionMessage(SimpleAccountingConstants.MANDATORYENTER, Amount));
        }
    }
    if (trannotes == null || "".equals(trannotes)) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, Notes));
    }
    {
        for (int i = 0; i < getAmount().length; i++) {
            CoaNamesDto coanamesob = new CoaNamesDto();
            coanamesob.setAmount(amts[i]);
            coanamesob.setTrxnnotes(trannotes[i]);
            // coanamesob.setCoaName(canames[i]);
            coaNamesDtolist.add(coanamesob);
        }
    }
    java.sql.Date currentDate = null;
    try {
        currentDate = DateUtils.getLocaleDate(userContext.getPreferredLocale(), DateUtils.getCurrentDate(userContext.getPreferredLocale()));
    } catch (InvalidDateException ide) {
        errors.add(SimpleAccountingConstants.INVALIDDATE, new ActionMessage(SimpleAccountingConstants.INVALIDDATE));
    }
    java.sql.Date trxnDate = null;
    if (getTransactiondate() == null || "".equals(getTransactiondate())) {
        errors.add(SimpleAccountingConstants.MANDATORYENTER, new ActionMessage(SimpleAccountingConstants.MANDATORYENTER, trxn_Date));
    } else if (getTransactiondate() != null && !getTransactiondate().equals("") && !DateUtils.isValidDate(getTransactiondate())) {
        errors = trxnDateValidate(errors, locale);
    } else if (DateUtils.isValidDate(getTransactiondate())) {
        try {
            trxnDate = DateUtils.getDateAsSentFromBrowser(getTransactiondate());
        } catch (InvalidDateException ide) {
            errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.INVALID_TRXN_DATE, trxn_Date));
        }
        if (trxnDate.compareTo(currentDate) > 0) {
            errors.add(SimpleAccountingConstants.INVALID_FUTURE, new ActionMessage(SimpleAccountingConstants.INVALID_FUTURE, trxn_Date));
        }
    }
    if (getBranch() == null || "".equals(getBranch())) {
        errors.add(SimpleAccountingConstants.MANDATORYENTER, new ActionMessage(SimpleAccountingConstants.MANDATORYENTER, branchname));
    }
    if (transactiontype == null || "".equals(transactiontype.trim())) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, trxn_Type));
    }
    if (mainAccount == null || "".equals(mainAccount.trim())) {
        errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, main_Account));
    }
    return errors;
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) ActionErrors(org.apache.struts.action.ActionErrors) CoaNamesDto(org.mifos.dto.domain.CoaNamesDto) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ActionMessage(org.apache.struts.action.ActionMessage) ResourceBundle(java.util.ResourceBundle)

Aggregations

InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)46 ActionMessage (org.apache.struts.action.ActionMessage)22 ActionErrors (org.apache.struts.action.ActionErrors)20 Locale (java.util.Locale)12 Date (java.sql.Date)9 ResourceBundle (java.util.ResourceBundle)9 PersistenceException (org.mifos.framework.exceptions.PersistenceException)6 Date (java.util.Date)5 AccountException (org.mifos.accounts.exceptions.AccountException)5 DoubleConversionResult (org.mifos.framework.util.helpers.DoubleConversionResult)5 SimpleDateFormat (java.text.SimpleDateFormat)4 MifosRuntimeException (org.mifos.core.MifosRuntimeException)4 CustomerException (org.mifos.customers.exceptions.CustomerException)4 ParseException (java.text.ParseException)3 LocalDate (org.joda.time.LocalDate)3 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)3 BusinessRuleException (org.mifos.service.BusinessRuleException)3 ArrayList (java.util.ArrayList)2 DateMidnight (org.joda.time.DateMidnight)2 DateTime (org.joda.time.DateTime)2