Search in sources :

Example 1 with CountrySubdivision

use of org.broadleafcommerce.profile.core.domain.CountrySubdivision in project BroadleafCommerce by BroadleafCommerce.

the class PaymentResponseDTOToEntityServiceImpl method populateAddressInfo.

@Override
public void populateAddressInfo(AddressDTO<PaymentResponseDTO> dto, Address address) {
    address.setFirstName(dto.getAddressFirstName());
    address.setLastName(dto.getAddressLastName());
    address.setFullName(dto.getAddressFullName());
    address.setAddressLine1(dto.getAddressLine1());
    address.setAddressLine2(dto.getAddressLine2());
    address.setCity(dto.getAddressCityLocality());
    State state = null;
    if (dto.getAddressStateRegion() != null) {
        state = stateService.findStateByAbbreviation(dto.getAddressStateRegion());
    }
    if (state == null) {
        LOG.warn("The given state from the response: " + StringUtil.sanitize(dto.getAddressStateRegion()) + " could not be found" + " as a state abbreviation in BLC_STATE");
    }
    address.setState(state);
    CountrySubdivision isoCountrySub = countrySubdivisionService.findSubdivisionByAbbreviation(dto.getAddressStateRegion());
    if (isoCountrySub != null) {
        address.setIsoCountrySubdivision(isoCountrySub.getAbbreviation());
        address.setStateProvinceRegion(isoCountrySub.getName());
    } else {
        // Integration does not conform to the ISO Code standard - just set the non-referential state province region
        address.setStateProvinceRegion(dto.getAddressStateRegion());
    }
    address.setPostalCode(dto.getAddressPostalCode());
    Country country = null;
    ISOCountry isoCountry = null;
    if (dto.getAddressCountryCode() != null) {
        country = countryService.findCountryByAbbreviation(dto.getAddressCountryCode());
        isoCountry = isoService.findISOCountryByAlpha2Code(dto.getAddressCountryCode());
    }
    if (country == null) {
        LOG.warn("The given country from the response: " + StringUtil.sanitize(dto.getAddressCountryCode()) + " could not be found" + " as a country abbreviation in BLC_COUNTRY");
    } else if (isoCountry == null) {
        LOG.error("The given country from the response: " + StringUtil.sanitize(dto.getAddressCountryCode()) + " could not be found" + " as a country alpha-2 code in BLC_ISO_COUNTRY");
    }
    address.setCountry(country);
    address.setIsoCountryAlpha2(isoCountry);
    if (dto.getAddressPhone() != null) {
        Phone billingPhone = phoneService.create();
        billingPhone.setPhoneNumber(dto.getAddressPhone());
        address.setPhonePrimary(billingPhone);
    }
    if (dto.getAddressEmail() != null) {
        address.setEmailAddress(dto.getAddressEmail());
    }
    if (dto.getAddressCompanyName() != null) {
        address.setCompanyName(dto.getAddressCompanyName());
    }
    addressService.populateAddressISOCountrySub(address);
}
Also used : State(org.broadleafcommerce.profile.core.domain.State) Phone(org.broadleafcommerce.profile.core.domain.Phone) Country(org.broadleafcommerce.profile.core.domain.Country) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry) CountrySubdivision(org.broadleafcommerce.profile.core.domain.CountrySubdivision) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry)

Example 2 with CountrySubdivision

use of org.broadleafcommerce.profile.core.domain.CountrySubdivision in project BroadleafCommerce by BroadleafCommerce.

the class AddressServiceImpl method populateAddressISOCountrySub.

@Override
public void populateAddressISOCountrySub(Address address) {
    if (StringUtils.isBlank(address.getIsoCountrySubdivision()) && address.getIsoCountryAlpha2() != null && StringUtils.isNotBlank(address.getStateProvinceRegion())) {
        String friendlyStateProvRegion = address.getStateProvinceRegion();
        CountrySubdivision isoCountrySub = countrySubdivisionService.findSubdivisionByCountryAndAltAbbreviation(address.getIsoCountryAlpha2().getAlpha2(), friendlyStateProvRegion);
        if (isoCountrySub == null) {
            isoCountrySub = countrySubdivisionService.findSubdivisionByCountryAndName(address.getIsoCountryAlpha2().getAlpha2(), friendlyStateProvRegion);
        }
        if (isoCountrySub != null) {
            address.setIsoCountrySubdivision(isoCountrySub.getAbbreviation());
        }
    }
}
Also used : CountrySubdivision(org.broadleafcommerce.profile.core.domain.CountrySubdivision)

Aggregations

CountrySubdivision (org.broadleafcommerce.profile.core.domain.CountrySubdivision)2 ISOCountry (org.broadleafcommerce.common.i18n.domain.ISOCountry)1 Country (org.broadleafcommerce.profile.core.domain.Country)1 Phone (org.broadleafcommerce.profile.core.domain.Phone)1 State (org.broadleafcommerce.profile.core.domain.State)1