use of org.killbill.billing.catalog.dao.CatalogOverridePhaseDefinitionModelDao in project killbill by killbill.
the class EhCacheOverriddenPlanCache method loadOverriddenPlan.
private DefaultPlan loadOverriddenPlan(final String planName, final StaticCatalog catalog, final InternalTenantContext context) throws CatalogApiException {
final Matcher m = DefaultPriceOverride.CUSTOM_PLAN_NAME_PATTERN.matcher(planName);
if (!m.matches()) {
throw new CatalogApiException(ErrorCode.CAT_NO_SUCH_PLAN, planName);
}
final String parentPlanName = m.group(1);
final Long planDefRecordId = Long.parseLong(m.group(2));
final List<CatalogOverridePhaseDefinitionModelDao> phaseDefs = overrideDao.getOverriddenPlanPhases(planDefRecordId, context);
final DefaultPlan defaultPlan = (DefaultPlan) catalog.findCurrentPlan(parentPlanName);
final PlanPhasePriceOverride[] overrides = createOverrides(defaultPlan, phaseDefs);
final DefaultPlan result = new DefaultPlan(planName, defaultPlan, overrides);
result.initialize((StandaloneCatalog) catalog, ((StandaloneCatalog) catalog).getCatalogURI());
return result;
}
use of org.killbill.billing.catalog.dao.CatalogOverridePhaseDefinitionModelDao in project killbill by killbill.
the class DefaultOverriddenPlanCache method createOverrides.
private PlanPhasePriceOverride[] createOverrides(final Plan defaultPlan, final List<CatalogOverridePhaseDefinitionModelDao> phaseDefs, final InternalTenantContext context) {
final PlanPhasePriceOverride[] result = new PlanPhasePriceOverride[defaultPlan.getAllPhases().length];
for (int i = 0; i < defaultPlan.getAllPhases().length; i++) {
final PlanPhase curPhase = defaultPlan.getAllPhases()[i];
final CatalogOverridePhaseDefinitionModelDao overriddenPhase = Iterables.tryFind(phaseDefs, new Predicate<CatalogOverridePhaseDefinitionModelDao>() {
@Override
public boolean apply(final CatalogOverridePhaseDefinitionModelDao input) {
return input.getParentPhaseName().equals(curPhase.getName());
}
}).orNull();
if (overriddenPhase != null) {
List<UsagePriceOverride> usagePriceOverrides = getUsagePriceOverrides(curPhase, overriddenPhase, context);
result[i] = new DefaultPlanPhasePriceOverride(curPhase.getName(), Currency.valueOf(overriddenPhase.getCurrency()), overriddenPhase.getFixedPrice(), overriddenPhase.getRecurringPrice(), usagePriceOverrides);
} else {
result[i] = null;
}
}
return result;
}
use of org.killbill.billing.catalog.dao.CatalogOverridePhaseDefinitionModelDao in project killbill by killbill.
the class EhCacheOverriddenPlanCache method createOverrides.
private PlanPhasePriceOverride[] createOverrides(final Plan defaultPlan, final List<CatalogOverridePhaseDefinitionModelDao> phaseDefs) {
final PlanPhasePriceOverride[] result = new PlanPhasePriceOverride[defaultPlan.getAllPhases().length];
for (int i = 0; i < defaultPlan.getAllPhases().length; i++) {
final PlanPhase curPhase = defaultPlan.getAllPhases()[i];
final CatalogOverridePhaseDefinitionModelDao overriddenPhase = Iterables.tryFind(phaseDefs, new Predicate<CatalogOverridePhaseDefinitionModelDao>() {
@Override
public boolean apply(final CatalogOverridePhaseDefinitionModelDao input) {
return input.getParentPhaseName().equals(curPhase.getName());
}
}).orNull();
result[i] = (overriddenPhase != null) ? new DefaultPlanPhasePriceOverride(curPhase.getName(), Currency.valueOf(overriddenPhase.getCurrency()), overriddenPhase.getFixedPrice(), overriddenPhase.getRecurringPrice()) : null;
}
return result;
}
use of org.killbill.billing.catalog.dao.CatalogOverridePhaseDefinitionModelDao in project killbill by killbill.
the class DefaultOverriddenPlanCache method loadOverriddenPlan.
private DefaultPlan loadOverriddenPlan(final String planName, final StandaloneCatalog catalog, final InternalTenantContext context) throws CatalogApiException {
final String[] parts = priceOverridePattern.getPlanParts(planName);
final String parentPlanName = parts[0];
final Long planDefRecordId = Long.parseLong(parts[1]);
final List<CatalogOverridePhaseDefinitionModelDao> phaseDefs = overrideDao.getOverriddenPlanPhases(planDefRecordId, context);
final DefaultPlan defaultPlan = catalog.findPlan(parentPlanName);
final PlanPhasePriceOverride[] overrides = createOverrides(defaultPlan, phaseDefs, context);
final DefaultPlan result = new DefaultPlan(priceOverridePattern.getPlanName(parts), defaultPlan, overrides);
result.initialize(catalog);
return result;
}
Aggregations