Search in sources :

Example 1 with CatalogOverrideUsageDefinitionModelDao

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

the class DefaultOverriddenPlanCache method getUsagePriceOverrides.

List<UsagePriceOverride> getUsagePriceOverrides(PlanPhase curPhase, CatalogOverridePhaseDefinitionModelDao overriddenPhase, final InternalTenantContext context) {
    final List<UsagePriceOverride> usagePriceOverrides = new ArrayList<UsagePriceOverride>();
    final List<CatalogOverrideUsageDefinitionModelDao> usageDefs = overrideDao.getOverriddenPhaseUsages(overriddenPhase.getRecordId(), context);
    for (int i = 0; i < curPhase.getUsages().length; i++) {
        final Usage curUsage = curPhase.getUsages()[i];
        final CatalogOverrideUsageDefinitionModelDao overriddenUsage = Iterables.tryFind(usageDefs, new Predicate<CatalogOverrideUsageDefinitionModelDao>() {

            @Override
            public boolean apply(final CatalogOverrideUsageDefinitionModelDao input) {
                return input.getParentUsageName().equals(curUsage.getName());
            }
        }).orNull();
        if (overriddenUsage != null) {
            List<TierPriceOverride> tierPriceOverrides = getTierPriceOverrides(curUsage, overriddenUsage, context);
            usagePriceOverrides.add(new DefaultUsagePriceOverride(overriddenUsage.getParentUsageName(), curUsage.getUsageType(), tierPriceOverrides));
        }
    }
    return usagePriceOverrides;
}
Also used : CatalogOverrideUsageDefinitionModelDao(org.killbill.billing.catalog.dao.CatalogOverrideUsageDefinitionModelDao) Usage(org.killbill.billing.catalog.api.Usage) DefaultUsagePriceOverride(org.killbill.billing.catalog.DefaultUsagePriceOverride) ArrayList(java.util.ArrayList) UsagePriceOverride(org.killbill.billing.catalog.api.UsagePriceOverride) DefaultUsagePriceOverride(org.killbill.billing.catalog.DefaultUsagePriceOverride) TierPriceOverride(org.killbill.billing.catalog.api.TierPriceOverride) DefaultTierPriceOverride(org.killbill.billing.catalog.DefaultTierPriceOverride) Predicate(com.google.common.base.Predicate)

Aggregations

Predicate (com.google.common.base.Predicate)1 ArrayList (java.util.ArrayList)1 DefaultTierPriceOverride (org.killbill.billing.catalog.DefaultTierPriceOverride)1 DefaultUsagePriceOverride (org.killbill.billing.catalog.DefaultUsagePriceOverride)1 TierPriceOverride (org.killbill.billing.catalog.api.TierPriceOverride)1 Usage (org.killbill.billing.catalog.api.Usage)1 UsagePriceOverride (org.killbill.billing.catalog.api.UsagePriceOverride)1 CatalogOverrideUsageDefinitionModelDao (org.killbill.billing.catalog.dao.CatalogOverrideUsageDefinitionModelDao)1