Search in sources :

Example 1 with CatalogOverridePhaseDefinitionModelDao

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;
}
Also used : Matcher(java.util.regex.Matcher) CatalogOverridePhaseDefinitionModelDao(org.killbill.billing.catalog.dao.CatalogOverridePhaseDefinitionModelDao) DefaultPlan(org.killbill.billing.catalog.DefaultPlan) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride) DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride)

Example 2 with CatalogOverridePhaseDefinitionModelDao

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;
}
Also used : DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride) CatalogOverridePhaseDefinitionModelDao(org.killbill.billing.catalog.dao.CatalogOverridePhaseDefinitionModelDao) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) UsagePriceOverride(org.killbill.billing.catalog.api.UsagePriceOverride) DefaultUsagePriceOverride(org.killbill.billing.catalog.DefaultUsagePriceOverride) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride) DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride) Predicate(com.google.common.base.Predicate)

Example 3 with CatalogOverridePhaseDefinitionModelDao

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;
}
Also used : DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride) CatalogOverridePhaseDefinitionModelDao(org.killbill.billing.catalog.dao.CatalogOverridePhaseDefinitionModelDao) PlanPhase(org.killbill.billing.catalog.api.PlanPhase) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride) DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride) Predicate(com.google.common.base.Predicate)

Example 4 with CatalogOverridePhaseDefinitionModelDao

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;
}
Also used : CatalogOverridePhaseDefinitionModelDao(org.killbill.billing.catalog.dao.CatalogOverridePhaseDefinitionModelDao) DefaultPlan(org.killbill.billing.catalog.DefaultPlan) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride) DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride)

Aggregations

DefaultPlanPhasePriceOverride (org.killbill.billing.catalog.DefaultPlanPhasePriceOverride)4 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)4 CatalogOverridePhaseDefinitionModelDao (org.killbill.billing.catalog.dao.CatalogOverridePhaseDefinitionModelDao)4 Predicate (com.google.common.base.Predicate)2 DefaultPlan (org.killbill.billing.catalog.DefaultPlan)2 PlanPhase (org.killbill.billing.catalog.api.PlanPhase)2 Matcher (java.util.regex.Matcher)1 DefaultUsagePriceOverride (org.killbill.billing.catalog.DefaultUsagePriceOverride)1 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)1 UsagePriceOverride (org.killbill.billing.catalog.api.UsagePriceOverride)1