Search in sources :

Example 6 with Tier

use of org.killbill.billing.catalog.api.Tier in project killbill by killbill.

the class UsageUtils method getCapacityInArrearUnitTypes.

public static Set<String> getCapacityInArrearUnitTypes(final Usage usage) {
    Preconditions.checkArgument(usage.getBillingMode() == BillingMode.IN_ARREAR && usage.getUsageType() == UsageType.CAPACITY);
    Preconditions.checkArgument(usage.getTiers().length > 0);
    final Set<String> result = new HashSet<String>();
    for (Tier tier : usage.getTiers()) {
        for (Limit limit : tier.getLimits()) {
            result.add(limit.getUnit().getName());
        }
    }
    return result;
}
Also used : Tier(org.killbill.billing.catalog.api.Tier) Limit(org.killbill.billing.catalog.api.Limit) HashSet(java.util.HashSet)

Example 7 with Tier

use of org.killbill.billing.catalog.api.Tier in project killbill by killbill.

the class DefaultPriceOverride method getResolvedTierOverrides.

public List<TierPriceOverride> getResolvedTierOverrides(Tier[] tiers, List<TierPriceOverride> tierPriceOverrides) throws CatalogApiException {
    List<TierPriceOverride> resolvedTierOverrides = new ArrayList<TierPriceOverride>();
    for (final Tier curTier : tiers) {
        final TierPriceOverride curOverride = Iterables.tryFind(tierPriceOverrides, new Predicate<TierPriceOverride>() {

            @Override
            public boolean apply(final TierPriceOverride input) {
                if (input.getTieredBlockPriceOverrides() != null) {
                    for (TieredBlockPriceOverride blockPriceOverride : input.getTieredBlockPriceOverrides()) {
                        String unitName = blockPriceOverride.getUnitName();
                        Double max = blockPriceOverride.getMax();
                        Double size = blockPriceOverride.getSize();
                        for (int i = 0; i < curTier.getTieredBlocks().length; i++) {
                            TieredBlock curTieredBlock = curTier.getTieredBlocks()[i];
                            if (unitName.equals(curTieredBlock.getUnit().getName()) && Double.compare(size, curTieredBlock.getSize()) == 0 && Double.compare(max, curTieredBlock.getMax()) == 0) {
                                return true;
                            }
                        }
                    }
                }
                return false;
            }
        }).orNull();
        if (curOverride != null) {
            List<TieredBlockPriceOverride> tieredBlockPriceOverrides = getResolvedTieredBlockPriceOverrides(curTier.getTieredBlocks(), curOverride.getTieredBlockPriceOverrides());
            resolvedTierOverrides.add(new DefaultTierPriceOverride(tieredBlockPriceOverrides));
        } else {
            resolvedTierOverrides.add(null);
        }
    }
    return resolvedTierOverrides;
}
Also used : TieredBlockPriceOverride(org.killbill.billing.catalog.api.TieredBlockPriceOverride) DefaultTieredBlockPriceOverride(org.killbill.billing.catalog.DefaultTieredBlockPriceOverride) TieredBlock(org.killbill.billing.catalog.api.TieredBlock) Tier(org.killbill.billing.catalog.api.Tier) DefaultTierPriceOverride(org.killbill.billing.catalog.DefaultTierPriceOverride) ArrayList(java.util.ArrayList) TierPriceOverride(org.killbill.billing.catalog.api.TierPriceOverride) DefaultTierPriceOverride(org.killbill.billing.catalog.DefaultTierPriceOverride) Predicate(com.google.common.base.Predicate)

Example 8 with Tier

use of org.killbill.billing.catalog.api.Tier 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

Tier (org.killbill.billing.catalog.api.Tier)8 TieredBlock (org.killbill.billing.catalog.api.TieredBlock)4 HashSet (java.util.HashSet)3 Limit (org.killbill.billing.catalog.api.Limit)3 TierPriceOverride (org.killbill.billing.catalog.api.TierPriceOverride)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Predicate (com.google.common.base.Predicate)2 ArrayList (java.util.ArrayList)2 DefaultTierPriceOverride (org.killbill.billing.catalog.DefaultTierPriceOverride)2 DefaultTieredBlockPriceOverride (org.killbill.billing.catalog.DefaultTieredBlockPriceOverride)2 TieredBlockPriceOverride (org.killbill.billing.catalog.api.TieredBlockPriceOverride)2 UsageUtils.getCapacityInArrearTier (org.killbill.billing.invoice.usage.UsageUtils.getCapacityInArrearTier)2 RolledUpUnit (org.killbill.billing.usage.api.RolledUpUnit)2 Joiner (com.google.common.base.Joiner)1 BigDecimal (java.math.BigDecimal)1 CatalogOverrideBlockDefinitionModelDao (org.killbill.billing.catalog.dao.CatalogOverrideBlockDefinitionModelDao)1 CatalogOverrideTierDefinitionModelDao (org.killbill.billing.catalog.dao.CatalogOverrideTierDefinitionModelDao)1 UsageCapacityInArrearAggregate (org.killbill.billing.invoice.usage.details.UsageCapacityInArrearAggregate)1 UsageInArrearTierUnitDetail (org.killbill.billing.invoice.usage.details.UsageInArrearTierUnitDetail)1