Search in sources :

Example 1 with AddressVerificationException

use of org.broadleafcommerce.profile.core.service.exception.AddressVerificationException in project BroadleafCommerce by BroadleafCommerce.

the class AddressServiceImpl method verifyAddress.

@Override
public List<Address> verifyAddress(Address address) throws AddressVerificationException {
    if (address.getStandardized() != null && Boolean.TRUE.equals(address.getStandardized())) {
        // If this address is already standardized, don't waste a call.
        ArrayList<Address> out = new ArrayList<Address>();
        out.add(address);
        return out;
    }
    if (providers != null && !providers.isEmpty()) {
        List<ModuleConfiguration> moduleConfigs = moduleConfigService.findActiveConfigurationsByType(ModuleConfigurationType.ADDRESS_VERIFICATION);
        if (moduleConfigs != null && !moduleConfigs.isEmpty()) {
            // Try to find a default configuration
            ModuleConfiguration config = null;
            for (ModuleConfiguration configuration : moduleConfigs) {
                if (configuration.getIsDefault()) {
                    config = configuration;
                    break;
                }
            }
            if (config == null) {
                // if there wasn't a default one, use the first active one...
                config = moduleConfigs.get(0);
            }
            for (AddressVerificationProvider provider : providers) {
                if (provider.canRespond(config)) {
                    return provider.validateAddress(address, config);
                }
            }
        }
    }
    if (mustValidateAddresses) {
        throw new AddressVerificationException("No providers were configured to handle address validation");
    }
    ArrayList<Address> out = new ArrayList<Address>();
    out.add(address);
    return out;
}
Also used : ModuleConfiguration(org.broadleafcommerce.common.config.domain.ModuleConfiguration) Address(org.broadleafcommerce.profile.core.domain.Address) ArrayList(java.util.ArrayList) AddressVerificationException(org.broadleafcommerce.profile.core.service.exception.AddressVerificationException)

Aggregations

ArrayList (java.util.ArrayList)1 ModuleConfiguration (org.broadleafcommerce.common.config.domain.ModuleConfiguration)1 Address (org.broadleafcommerce.profile.core.domain.Address)1 AddressVerificationException (org.broadleafcommerce.profile.core.service.exception.AddressVerificationException)1