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;
}
Aggregations