Search in sources :

Example 1 with IbanFormatException

use of org.iban4j.IbanFormatException in project axelor-open-suite by axelor.

the class BankDetailsController method validateIban.

public void validateIban(ActionRequest request, ActionResponse response) {
    response.setAttr("invalidIbanText", "hidden", true);
    if (request.getAction().endsWith("onnew")) {
        return;
    }
    BankDetails bankDetails = request.getContext().asType(BankDetails.class);
    Bank bank = bankDetails.getBank();
    if (bankDetails.getIban() != null && bank != null && bank.getBankDetailsTypeSelect() == BankRepository.BANK_IDENTIFIER_TYPE_IBAN) {
        try {
            Beans.get(BankDetailsService.class).validateIban(bankDetails.getIban());
        } catch (IbanFormatException | InvalidCheckDigitException | UnsupportedCountryException e) {
            if (request.getAction().endsWith("onchange")) {
                response.setFlash(I18n.get(IExceptionMessage.BANK_DETAILS_1));
            }
            response.setAttr("invalidIbanText", "hidden", false);
        } finally {
            bankDetails = Beans.get(BankDetailsServiceImpl.class).detailsIban(bankDetails);
            if (bank.getCountry() != null && bank.getCountry().getAlpha2Code().equals("FR")) {
                response.setValue("bankCode", bankDetails.getBankCode());
                response.setValue("sortCode", bankDetails.getSortCode());
                response.setValue("accountNbr", bankDetails.getAccountNbr());
                response.setValue("bbanKey", bankDetails.getBbanKey());
            }
        }
    }
}
Also used : BankDetailsService(com.axelor.apps.base.service.BankDetailsService) InvalidCheckDigitException(org.iban4j.InvalidCheckDigitException) Bank(com.axelor.apps.base.db.Bank) BankDetails(com.axelor.apps.base.db.BankDetails) UnsupportedCountryException(org.iban4j.UnsupportedCountryException) IbanFormatException(org.iban4j.IbanFormatException)

Example 2 with IbanFormatException

use of org.iban4j.IbanFormatException in project axelor-open-suite by axelor.

the class PartnerController method checkIbanValidity.

public void checkIbanValidity(ActionRequest request, ActionResponse response) throws AxelorException {
    List<BankDetails> bankDetailsList = request.getContext().asType(Partner.class).getBankDetailsList();
    List<String> ibanInError = Lists.newArrayList();
    if (bankDetailsList != null && !bankDetailsList.isEmpty()) {
        for (BankDetails bankDetails : bankDetailsList) {
            Bank bank = bankDetails.getBank();
            if (bankDetails.getIban() != null && bank != null && bank.getBankDetailsTypeSelect() == BankRepository.BANK_IDENTIFIER_TYPE_IBAN) {
                LOG.debug("checking iban code : {}", bankDetails.getIban());
                try {
                    Beans.get(BankDetailsService.class).validateIban(bankDetails.getIban());
                } catch (IbanFormatException | InvalidCheckDigitException | UnsupportedCountryException e) {
                    ibanInError.add(bankDetails.getIban());
                }
            }
        }
    }
    if (!ibanInError.isEmpty()) {
        Function<String, String> addLi = new Function<String, String>() {

            @Override
            public String apply(String s) {
                return "<li>".concat(s).concat("</li>").toString();
            }
        };
        response.setAlert(String.format(IExceptionMessage.BANK_DETAILS_2, "<ul>" + Joiner.on("").join(Iterables.transform(ibanInError, addLi)) + "<ul>"));
    }
}
Also used : InvalidCheckDigitException(org.iban4j.InvalidCheckDigitException) Bank(com.axelor.apps.base.db.Bank) BankDetails(com.axelor.apps.base.db.BankDetails) BankDetailsService(com.axelor.apps.base.service.BankDetailsService) Function(com.google.common.base.Function) UnsupportedCountryException(org.iban4j.UnsupportedCountryException) Partner(com.axelor.apps.base.db.Partner) IbanFormatException(org.iban4j.IbanFormatException)

Aggregations

Bank (com.axelor.apps.base.db.Bank)2 BankDetails (com.axelor.apps.base.db.BankDetails)2 BankDetailsService (com.axelor.apps.base.service.BankDetailsService)2 IbanFormatException (org.iban4j.IbanFormatException)2 InvalidCheckDigitException (org.iban4j.InvalidCheckDigitException)2 UnsupportedCountryException (org.iban4j.UnsupportedCountryException)2 Partner (com.axelor.apps.base.db.Partner)1 Function (com.google.common.base.Function)1