@Override public void setAsText(String text) { if (StringUtils.isNotEmpty(text)) { ISOCountry isoCountry = isoService.findISOCountryByAlpha2Code(text); setValue(isoCountry); }else { setValue(null); } } });
public void createCountry() { Country country = new CountryImpl(); country.setAbbreviation("US"); country.setName("United States"); countryService.save(country); ISOCountry isoCountry = new ISOCountryImpl(); isoCountry.setAlpha2("US"); isoCountry.setName("UNITED STATES"); isoService.save(isoCountry); }
/** * This method only exists because so many other tests depend on it, but should be removed once tests are more isolated * @param customerAddress */ @Deprecated @Test(groups = "createCustomerAddress", dataProvider = "setupCustomerAddress", dataProviderClass = CustomerAddressDataProvider.class, dependsOnGroups = {"readCustomer", "createCountry", "createState"}) @Transactional @Rollback(false) public void createCustomerAddress(CustomerAddress customerAddress) { userName = "customer1"; Customer customer = customerService.readCustomerByUsername(userName); assert customerAddress.getId() == null; customerAddress.setCustomer(customer); State state = stateService.findStateByAbbreviation("KY"); customerAddress.getAddress().setState(state); Country country = countryService.findCountryByAbbreviation("US"); customerAddress.getAddress().setCountry(country); customerAddress.getAddress().setIsoCountrySubdivision("US-KY"); ISOCountry isoCountry = isoService.findISOCountryByAlpha2Code("US"); customerAddress.getAddress().setIsoCountryAlpha2(isoCountry); customerAddress = customerAddressService.saveCustomerAddress(customerAddress); assert customer.equals(customerAddress.getCustomer()); userId = customerAddress.getCustomer().getId(); }
isoCountry.setName("UNITED STATES"); isoService.save(isoCountry);
/** * Saves a customerAddress with state KY and country US. Requires that createCountry() and createState() have been called * @param customerAddress */ public CustomerAddress saveCustomerAddress(CustomerAddress customerAddress) { State state = stateService.findStateByAbbreviation("KY"); customerAddress.getAddress().setState(state); Country country = countryService.findCountryByAbbreviation("US"); customerAddress.getAddress().setCountry(country); customerAddress.getAddress().setIsoCountrySubdivision("US-KY"); ISOCountry isoCountry = isoService.findISOCountryByAlpha2Code("US"); customerAddress.getAddress().setIsoCountryAlpha2(isoCountry); return customerAddressService.saveCustomerAddress(customerAddress); }
isoCountry.setName("UNITED STATES"); isoCountry = isoService.save(isoCountry);
if (dto.getAddressCountryCode() != null) { country = countryService.findCountryByAbbreviation(dto.getAddressCountryCode()); isoCountry = isoService.findISOCountryByAlpha2Code(dto.getAddressCountryCode());
isoCountry.setName("UNITED STATES"); isoCountry = isoService.save(isoCountry);
@Override public boolean isValid(String country, ConstraintValidatorContext context) { return country == null || isoService.findISOCountryByAlpha2Code(country) != null; } }
address.setCountry(countryService.findCountryByAbbreviation("US")); address.setIsoCountrySubdivision("US-KY"); address.setIsoCountryAlpha2(isoService.findISOCountryByAlpha2Code("US"));
@Override public Address updateEntity(final Address address, final AddressDto addressDto) { address.setAddressLine1(Optional.ofNullable(addressDto.getAddressLine1()).orElse("")); address.setAddressLine2(addressDto.getAddressLine2()); address.setAddressLine3(addressDto.getAddressLine3()); address.setFirstName(addressDto.getFirstName()); address.setLastName(addressDto.getLastName()); address.setCity(Optional.ofNullable(addressDto.getCity()).orElse("")); address.setPostalCode(addressDto.getPostalCode()); address.setCompanyName(addressDto.getCompanyName()); address.setCounty(addressDto.getCountrySubdivisionCode()); address.setIsoCountrySubdivision(addressDto.getCountrySubdivisionCode()); Optional.ofNullable(addressDto.getCountryCode()) .ifPresent(countryCode -> address.setIsoCountryAlpha2(isoService.findISOCountryByAlpha2Code(countryCode))); address.setEmailAddress(addressDto.getEmail()); Optional.ofNullable(addressDto.getPhone()).ifPresent(phone -> address.setPhonePrimary(phoneNumberFormat.parseObject(phone, new ParsePosition(0))) ); return address; }