Country country = address.getCountry(); if (country.getISO2() == "FR") {
countryCodeRate = lookupCountryRate(itemCountryTaxRateMap, address.getIsoCountryAlpha2()); } else { countryCodeRate = lookupCountryRate(itemCountryTaxRateMap, address.getCountry());
countryCodeRate = lookupCountryRate(fulfillmentGroupCountryTaxRateMap, address.getIsoCountryAlpha2()); } else { countryCodeRate = lookupCountryRate(fulfillmentGroupCountryTaxRateMap, address.getCountry());
public void validate(BroadleafFormType formType, Address address, Errors errors) { if (isCustomValidationEnabled()) { validatorExtensionManager.getProxy().validate(formType, address, errors); return; } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address.addressLine1", "addressLine1.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address.city", "city.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address.stateProvinceRegion", "state.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address.postalCode", "postalCode.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address.phonePrimary.phoneNumber", "phonePrimary.required"); if (isValidateFullNameOnly()) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address.fullName", "fullName.required"); } else { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address.firstName", "firstName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address.lastName", "lastName.required"); } if (address.getIsoCountryAlpha2() == null && address.getCountry() == null) { errors.rejectValue("address.isoCountryAlpha2", "country.required", null, null); } }
} else if (fgAddress.getCountry() != null) { countryAbbr = fgAddress.getCountry().getAbbreviation();
} else if (billAddress.getCountry() != null) { countryAbbr = billAddress.getCountry().getAbbreviation();
dest.setPostalCode(orig.getPostalCode()); dest.setZipFour(orig.getZipFour()); dest.setCountry(orig.getCountry()); dest.setIsoCountryAlpha2(orig.getIsoCountryAlpha2()); dest.setCompanyName(orig.getCompanyName());
public class AddressComparator implements Comparator<Address> { @Override public int compare(Address o1, Address o2) { return o1.getCountry().compareTo(o2.getCountry()); } }
@ApplicationScoped public class CounryZipCodeValidator { @Any @Inject private Instance<ZipCodeChecker> zipCodeCheckers; public void validate(final Address address) { Country country = address.getCountry(); ZipCodeChecker zipCodeChecker = zipCodeCheckers.select(new ZipCodeCheckImpl(country)).get(); //will return null if no zipcoderchecker for the country. checkState(zipCodeChecker.isValid(address.getZipCode()), "Invalid zipcode"); } }
@Override public boolean isValid(Address address, ConstraintValidatorContext constraintContext) { String postalCode = address.getPostalCode(); String country = address.getCountry(); String regex = null; if (null == country || Address.COUNTRY_USA.equals(country)) { regex = "^[0-9]{5}$"; } else if (Address.COUNTRY_CANADA.equals(country)) { regex = "^[A-Za-z][0-9][A-Za-z] [0-9][A-Za-z][0-9]$"; } Pattern postalPattern = Pattern.compile(regex); Matcher matcher = postalPattern.matcher(postalCode); if (matcher.matches()) { return true; } // this will generate a field error for "postalCode" field. constraintContext.disableDefaultConstraintViolation(); constraintContext.buildConstraintViolationWithTemplate("custom_error_code").addNode("postalCode").addConstraintViolation(); return false; }