Package com.sparc.knappsack.forms

Examples of com.sparc.knappsack.forms.DomainRequestForm


    private DomainRequestForm form;
    private Errors errors;

    @Before
    public void setup() {
        form = new DomainRequestForm();
        errors = new BeanPropertyBindingResult(form, "domainRegistrationForm");
        ReflectionTestUtils.setField(validator, "emailPattern", EMAIL_PATTERN);
    }
View Full Code Here


        return DomainRequestForm.class.isAssignableFrom(clazz);
    }

    @Override
    public void validate(Object target, Errors errors) {
        DomainRequestForm domainRequestForm = (DomainRequestForm) target;

        Domain domain = domainService.getByUUID(domainRequestForm.getDomainUUID());
        if (!doesBindingErrorExist(errors, DOMAIN_UUID_FIELD) && domain == null) {
            errors.reject(DOMAIN_UUID_FIELD, "domainRequestValidator.domainUUID.invalid");
        }

        if (!doesBindingErrorExist(errors, FIRST_NAME_FIELD) && !StringUtils.hasText(domainRequestForm.getFirstName())) {
            errors.rejectValue(FIRST_NAME_FIELD, "domainRequestValidator.firstName.empty");
        }

        if (!doesBindingErrorExist(errors, LAST_NAME_FIELD) && !StringUtils.hasText(domainRequestForm.getLastName())) {
            errors.rejectValue(LAST_NAME_FIELD, "domainRequestValidator.lastName.empty");
        }

        if (!doesBindingErrorExist(errors, COMPANY_NAME_FIELD) && !StringUtils.hasText(domainRequestForm.getCompanyName())) {
            errors.rejectValue(COMPANY_NAME_FIELD, "domainRequestValidator.companyName.empty");
        }

        if (!doesBindingErrorExist(errors, ADDRESS_FIELD) && !StringUtils.hasText(domainRequestForm.getAddress())) {
            errors.rejectValue(ADDRESS_FIELD, "domainRequestValidator.address.empty");
        }

        if (!doesBindingErrorExist(errors, PHONE_FIELD) && !StringUtils.hasText(domainRequestForm.getPhoneNumber())) {
            errors.rejectValue(PHONE_FIELD, "domainRequestValidator.phoneNumber.empty");
        }

        if (!doesBindingErrorExist(errors, EMAIL_ADDRESS_FIELD) && !StringUtils.hasText(domainRequestForm.getEmailAddress()) || !doesRegexMatch(domainRequestForm.getEmailAddress(), emailPattern)) {
            errors.rejectValue(EMAIL_ADDRESS_FIELD, "domainRequestValidator.emailAddress.invalid");
        }

        if (!doesBindingErrorExist(errors, DEVICE_TYPE_FIELD) && domainRequestForm.getDeviceType() == null) {
            errors.rejectValue(DEVICE_TYPE_FIELD, "domainRequestValidator.deviceType.empty");
        }

        if (!doesBindingErrorExist(errors, REGION_FIELD)) {
            Domain domainForRegion = domainService.getDomainForRegion(domainRequestForm.getRegion());
            if (domainForRegion == null || !domainForRegion.equals(domain)) {
                errors.rejectValue(REGION_FIELD, "domainRequestValidator.region.invalid");
            }
        }

        if (!doesFieldErrorExist(errors, EMAIL_ADDRESS_FIELD) && !doesFieldErrorExist(errors, DOMAIN_UUID_FIELD) && !doesFieldErrorExist(errors, REGION_FIELD) && domainRequestService.doesDomainRequestExist(domain.getId(), domainRequestForm.getEmailAddress())) {
            errors.reject("domainRequestValidator.request.exists");
        }

        if (!doesBindingErrorExist(errors, LANGUAGES_FIELD) && domainRequestForm.getLanguages().size() <= 0) {
            errors.rejectValue(LANGUAGES_FIELD, "domainRequestValidator.languages.empty");
        }

    }
View Full Code Here

    public String showDomainRequestPage(Model model, @PathVariable String domainUUID, @RequestParam(value = "success", required = false) Boolean success) {
        Domain domain = domainService.getByUUID(domainUUID);

        if (domain != null) {
            if (!model.containsAttribute("domainRequestForm")) {
                DomainRequestForm domainRequestForm = new DomainRequestForm();
                domainRequestForm.setDomainUUID(domainUUID);

                model.addAttribute("domainRequestForm", domainRequestForm);
                model.addAttribute("domainName", domain.getName());
            }
View Full Code Here

TOP

Related Classes of com.sparc.knappsack.forms.DomainRequestForm

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.