Search in sources :

Example 1 with CatalogOverrideTierDefinitionModelDao

use of org.killbill.billing.catalog.dao.CatalogOverrideTierDefinitionModelDao in project killbill by killbill.

the class DefaultOverriddenPlanCache method getTierPriceOverrides.

List<TierPriceOverride> getTierPriceOverrides(Usage curUsage, CatalogOverrideUsageDefinitionModelDao overriddenUsage, final InternalTenantContext context) {
    final List<TierPriceOverride> tierPriceOverrides = new ArrayList<TierPriceOverride>();
    final List<CatalogOverrideTierDefinitionModelDao> tierDefs = overrideDao.getOverriddenUsageTiers(overriddenUsage.getRecordId(), context);
    for (int i = 0; i < curUsage.getTiers().length; i++) {
        final Tier curTier = curUsage.getTiers()[i];
        final TieredBlock[] curTieredBlocks = curTier.getTieredBlocks();
        final CatalogOverrideTierDefinitionModelDao overriddenTier = Iterables.tryFind(tierDefs, new Predicate<CatalogOverrideTierDefinitionModelDao>() {

            @Override
            public boolean apply(final CatalogOverrideTierDefinitionModelDao input) {
                final List<CatalogOverrideBlockDefinitionModelDao> blockDefs = overrideDao.getOverriddenTierBlocks(input.getRecordId(), context);
                for (CatalogOverrideBlockDefinitionModelDao blockDef : blockDefs) {
                    String unitName = blockDef.getParentUnitName();
                    Double max = blockDef.getMax();
                    Double size = blockDef.getSize();
                    for (TieredBlock curTieredBlock : curTieredBlocks) {
                        if (unitName.equals(curTieredBlock.getUnit().getName()) && Double.compare(size, curTieredBlock.getSize()) == 0 && Double.compare(max, curTieredBlock.getMax()) == 0) {
                            return true;
                        }
                    }
                }
                return false;
            }
        }).orNull();
        if (overriddenTier != null) {
            List<TieredBlockPriceOverride> tieredBlockPriceOverrides = getTieredBlockPriceOverrides(curTier, overriddenTier, context);
            tierPriceOverrides.add(new DefaultTierPriceOverride(tieredBlockPriceOverrides));
        }
    }
    return tierPriceOverrides;
}
Also used : TieredBlockPriceOverride(org.killbill.billing.catalog.api.TieredBlockPriceOverride) DefaultTieredBlockPriceOverride(org.killbill.billing.catalog.DefaultTieredBlockPriceOverride) Tier(org.killbill.billing.catalog.api.Tier) ArrayList(java.util.ArrayList) TierPriceOverride(org.killbill.billing.catalog.api.TierPriceOverride) DefaultTierPriceOverride(org.killbill.billing.catalog.DefaultTierPriceOverride) CatalogOverrideTierDefinitionModelDao(org.killbill.billing.catalog.dao.CatalogOverrideTierDefinitionModelDao) Predicate(com.google.common.base.Predicate) TieredBlock(org.killbill.billing.catalog.api.TieredBlock) CatalogOverrideBlockDefinitionModelDao(org.killbill.billing.catalog.dao.CatalogOverrideBlockDefinitionModelDao) DefaultTierPriceOverride(org.killbill.billing.catalog.DefaultTierPriceOverride)

Aggregations

Predicate (com.google.common.base.Predicate)1 ArrayList (java.util.ArrayList)1 DefaultTierPriceOverride (org.killbill.billing.catalog.DefaultTierPriceOverride)1 DefaultTieredBlockPriceOverride (org.killbill.billing.catalog.DefaultTieredBlockPriceOverride)1 Tier (org.killbill.billing.catalog.api.Tier)1 TierPriceOverride (org.killbill.billing.catalog.api.TierPriceOverride)1 TieredBlock (org.killbill.billing.catalog.api.TieredBlock)1 TieredBlockPriceOverride (org.killbill.billing.catalog.api.TieredBlockPriceOverride)1 CatalogOverrideBlockDefinitionModelDao (org.killbill.billing.catalog.dao.CatalogOverrideBlockDefinitionModelDao)1 CatalogOverrideTierDefinitionModelDao (org.killbill.billing.catalog.dao.CatalogOverrideTierDefinitionModelDao)1