Search in sources :

Example 1 with ModuleConfiguration

use of org.broadleafcommerce.common.config.domain.ModuleConfiguration 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)

Example 2 with ModuleConfiguration

use of org.broadleafcommerce.common.config.domain.ModuleConfiguration in project BroadleafCommerce by BroadleafCommerce.

the class SiteMapServiceImpl method findActiveSiteMapConfiguration.

protected SiteMapConfiguration findActiveSiteMapConfiguration() {
    List<ModuleConfiguration> configurations = moduleConfigurationService.findActiveConfigurationsByType(ModuleConfigurationType.SITE_MAP);
    SiteMapConfiguration smc = null;
    if (configurations != null && !configurations.isEmpty()) {
        // Try to find a default configuration
        for (ModuleConfiguration configuration : configurations) {
            if (configuration.getIsDefault()) {
                smc = (SiteMapConfiguration) configuration;
                break;
            }
        }
        if (smc == null) {
            // if there wasn't a default one, use the first active one...
            smc = (SiteMapConfiguration) configurations.get(0);
        }
    }
    return smc;
}
Also used : ModuleConfiguration(org.broadleafcommerce.common.config.domain.ModuleConfiguration) SiteMapConfiguration(org.broadleafcommerce.common.sitemap.domain.SiteMapConfiguration)

Example 3 with ModuleConfiguration

use of org.broadleafcommerce.common.config.domain.ModuleConfiguration in project BroadleafCommerce by BroadleafCommerce.

the class SiteMapGeneratorTest method testGenerator.

protected void testGenerator(List<SiteMapGeneratorConfiguration> smgcList, SiteMapGenerator smg, int maxEntriesPerFile) throws SiteMapException, IOException {
    if (CollectionUtils.isNotEmpty(smgcList)) {
        SiteMapConfiguration smc = new SiteMapConfigurationImpl();
        smc.setMaximumUrlEntriesPerFile(maxEntriesPerFile);
        smc.setSiteMapGeneratorConfigurations(smgcList);
        smc.setIndexedSiteMapFileName("sitemap_index.xml");
        for (SiteMapGeneratorConfiguration smgc : smgcList) {
            smgc.setSiteMapConfiguration(smc);
        }
        List<ModuleConfiguration> mcList = new ArrayList<>();
        mcList.add(smc);
        ModuleConfigurationService mcs = EasyMock.createMock(ModuleConfigurationService.class);
        EasyMock.expect(mcs.findActiveConfigurationsByType(ModuleConfigurationType.SITE_MAP)).andReturn(mcList);
        EasyMock.replay(mcs);
        List<SiteMapGenerator> smgList = new ArrayList<>();
        smgList.add(smg);
        siteMapService.setGzipSiteMapFiles(false);
        siteMapService.setModuleConfigurationService(mcs);
        siteMapService.setSiteMapGenerators(smgList);
        SiteMapGenerationResponse smgr = siteMapService.generateSiteMap();
        Assert.assertFalse(smgr.isHasError());
    }
}
Also used : SiteMapGenerator(org.broadleafcommerce.common.sitemap.service.SiteMapGenerator) ModuleConfiguration(org.broadleafcommerce.common.config.domain.ModuleConfiguration) SiteMapConfigurationImpl(org.broadleafcommerce.common.sitemap.domain.SiteMapConfigurationImpl) ModuleConfigurationService(org.broadleafcommerce.common.config.service.ModuleConfigurationService) SiteMapConfiguration(org.broadleafcommerce.common.sitemap.domain.SiteMapConfiguration) ArrayList(java.util.ArrayList) SiteMapGenerationResponse(org.broadleafcommerce.common.sitemap.service.SiteMapGenerationResponse) SiteMapGeneratorConfiguration(org.broadleafcommerce.common.sitemap.domain.SiteMapGeneratorConfiguration)

Example 4 with ModuleConfiguration

use of org.broadleafcommerce.common.config.domain.ModuleConfiguration in project BroadleafCommerce by BroadleafCommerce.

the class TaxServiceImpl method calculateTaxForOrder.

@Override
public Order calculateTaxForOrder(Order order) throws TaxException {
    List<ModuleConfiguration> configurations = moduleConfigService.findActiveConfigurationsByType(ModuleConfigurationType.TAX_CALCULATION);
    // Try to find a default configuration
    ModuleConfiguration config = null;
    if (configurations != null) {
        for (ModuleConfiguration configuration : configurations) {
            if (configuration.getIsDefault()) {
                config = configuration;
                break;
            }
        }
        if (config == null && CollectionUtils.isNotEmpty(configurations)) {
            // if there wasn't a default one, use the first active one...
            config = configurations.get(0);
        }
    }
    if (CollectionUtils.isNotEmpty(providers)) {
        for (TaxProvider provider : providers) {
            if (provider.canRespond(config)) {
                return provider.calculateTaxForOrder(order, config);
            }
        }
    }
    // haven't returned anything, nothing must have run
    if (!mustCalculate) {
        return order;
    }
    throw new TaxException("No eligible tax providers were configured.");
}
Also used : ModuleConfiguration(org.broadleafcommerce.common.config.domain.ModuleConfiguration) TaxException(org.broadleafcommerce.core.pricing.service.exception.TaxException) TaxProvider(org.broadleafcommerce.core.pricing.service.tax.provider.TaxProvider)

Aggregations

ModuleConfiguration (org.broadleafcommerce.common.config.domain.ModuleConfiguration)4 ArrayList (java.util.ArrayList)2 SiteMapConfiguration (org.broadleafcommerce.common.sitemap.domain.SiteMapConfiguration)2 ModuleConfigurationService (org.broadleafcommerce.common.config.service.ModuleConfigurationService)1 SiteMapConfigurationImpl (org.broadleafcommerce.common.sitemap.domain.SiteMapConfigurationImpl)1 SiteMapGeneratorConfiguration (org.broadleafcommerce.common.sitemap.domain.SiteMapGeneratorConfiguration)1 SiteMapGenerationResponse (org.broadleafcommerce.common.sitemap.service.SiteMapGenerationResponse)1 SiteMapGenerator (org.broadleafcommerce.common.sitemap.service.SiteMapGenerator)1 TaxException (org.broadleafcommerce.core.pricing.service.exception.TaxException)1 TaxProvider (org.broadleafcommerce.core.pricing.service.tax.provider.TaxProvider)1 Address (org.broadleafcommerce.profile.core.domain.Address)1 AddressVerificationException (org.broadleafcommerce.profile.core.service.exception.AddressVerificationException)1