use of org.killbill.billing.catalog.dao.CatalogOverrideBlockDefinitionModelDao in project killbill by killbill.
the class DefaultOverriddenPlanCache method getTieredBlockPriceOverrides.
List<TieredBlockPriceOverride> getTieredBlockPriceOverrides(Tier curTier, CatalogOverrideTierDefinitionModelDao overriddenTier, final InternalTenantContext context) {
final List<TieredBlockPriceOverride> blockPriceOverrides = new ArrayList<TieredBlockPriceOverride>();
final List<CatalogOverrideBlockDefinitionModelDao> blockDefs = overrideDao.getOverriddenTierBlocks(overriddenTier.getRecordId(), context);
for (int i = 0; i < curTier.getTieredBlocks().length; i++) {
final TieredBlock curTieredBlock = curTier.getTieredBlocks()[i];
final CatalogOverrideBlockDefinitionModelDao overriddenTierBlock = Iterables.tryFind(blockDefs, new Predicate<CatalogOverrideBlockDefinitionModelDao>() {
@Override
public boolean apply(final CatalogOverrideBlockDefinitionModelDao input) {
return (input.getParentUnitName().equals(curTieredBlock.getUnit().getName()) && Double.compare(input.getSize(), curTieredBlock.getSize()) == 0 && Double.compare(input.getMax(), curTieredBlock.getMax()) == 0);
}
}).orNull();
if (overriddenTierBlock != null) {
blockPriceOverrides.add(new DefaultTieredBlockPriceOverride(overriddenTierBlock.getParentUnitName(), overriddenTierBlock.getSize(), overriddenTierBlock.getPrice(), Currency.valueOf(overriddenTierBlock.getCurrency()), overriddenTierBlock.getMax()));
}
}
return blockPriceOverrides;
}
use of org.killbill.billing.catalog.dao.CatalogOverrideBlockDefinitionModelDao 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;
}
Aggregations