Example usage for org.apache.commons.validator.routines.checkdigit LuhnCheckDigit LUHN_CHECK_DIGIT

List of usage examples for org.apache.commons.validator.routines.checkdigit LuhnCheckDigit LUHN_CHECK_DIGIT

Introduction

In this page you can find the example usage for org.apache.commons.validator.routines.checkdigit LuhnCheckDigit LUHN_CHECK_DIGIT.

Prototype

CheckDigit LUHN_CHECK_DIGIT

To view the source code for org.apache.commons.validator.routines.checkdigit LuhnCheckDigit LUHN_CHECK_DIGIT.

Click Source Link

Document

Singleton Luhn Check Digit instance

Usage

From source file:controllers.LessorController.java

@RequestMapping(value = "/register", method = RequestMethod.POST, params = "save")
public ModelAndView save(@Valid LessorForm lessorForm, BindingResult binding) {
    ModelAndView result = new ModelAndView();
    Lessor lessor;/* ww w. ja  va2  s. co  m*/

    lessor = lessorService.reconstruct(lessorForm, binding);
    if (binding.hasErrors()) {
        result = createEditModelAndView(lessorForm, "lessor.creditCardPosibleBinding");

    } else {
        try {
            if (lessorService.checkCreditCard(lessorForm.getCreditCard())) {
                Boolean var = LuhnCheckDigit.LUHN_CHECK_DIGIT.isValid(lessorForm.getCreditCard().getNumber());
                if (var == false) {
                    throw new IllegalArgumentException("invalid credit card number");
                }

                if (lessorForm.getCreditCard().getNumber().length() < 12) {
                    throw new IllegalArgumentException("invalid credit card number");
                }
            }
            lessorService.save(lessor);
            result = new ModelAndView("redirect:/security/login.do");
        } catch (Throwable oops) {
            result = createEditModelAndView(lessorForm, "lessor.commit.error");
        }
    }

    return result;
}