public static String phaseName(final String planName, final PhaseType phasetype) { return planName + "-" + phasetype.toString().toLowerCase(); }
public static String planName(final String phaseName) throws CatalogApiException { for (final PhaseType type : PhaseType.values()) { if (phaseName.endsWith(type.toString().toLowerCase())) { return phaseName.substring(0, phaseName.length() - type.toString().length() - 1); } } throw new CatalogApiException(ErrorCode.CAT_BAD_PHASE_NAME, phaseName); }
@Override public ValidationErrors validate(final StandaloneCatalog catalog, final ValidationErrors errors) { // Validation: check for nulls if (planName == null) { errors.add(new ValidationError("Invalid plan for recurring section", DefaultRecurring.class, "")); } if (phaseType == null) { errors.add(new ValidationError("Invalid phase for recurring section", DefaultPlan.class, planName)); } if (billingPeriod == null) { errors.add(new ValidationError(String.format("Recurring section of Phase %s of plan %s has a recurring price but no billing period", phaseType.toString(), planName), DefaultPlanPhase.class, phaseType.toString())); } // Validation: if there is a recurring price there must be a billing period if ((recurringPrice != null) && (billingPeriod == null || billingPeriod == BillingPeriod.NO_BILLING_PERIOD)) { errors.add(new ValidationError(String.format("Recurring section of Phase %s of plan %s has a recurring price but no billing period", phaseType.toString(), planName), DefaultPlanPhase.class, phaseType.toString())); } // Validation: if there is no recurring price there should be no billing period if ((recurringPrice == null) && billingPeriod != BillingPeriod.NO_BILLING_PERIOD) { errors.add(new ValidationError(String.format("Recurring section of Phase %s of plan %s has no recurring price but does have a billing period. The billing period should be set to '%s'", phaseType.toString(), planName, BillingPeriod.NO_BILLING_PERIOD), DefaultPlanPhase.class, phaseType.toString())); } return errors; }
@Override public ValidationErrors validate(final StandaloneCatalog catalog, final ValidationErrors errors) { if (planName == null) { errors.add(new ValidationError(String.format("Invalid plan for phase '%s'", type), DefaultPlanPhase.class, "")); } if (fixed == null && recurring == null && usages.length == 0) { errors.add(new ValidationError(String.format("Phase %s of plan %s need to define at least either a fixed or recurrring or usage section.", type.toString(), planName), DefaultPlanPhase.class, type.toString())); } if (fixed != null) { fixed.validate(catalog, errors); } if (recurring != null) { recurring.validate(catalog, errors); } duration.validate(catalog, errors); validateCollection(catalog, errors, usages); return errors; }
private SubscriptionBaseEvent createSubscriptionEvent(final DateTime effectiveDate, final String productName, final PhaseType phaseType, final ApiEventType apiEventType) { final ApiEventBuilder eventBuilder = new ApiEventBuilder(); eventBuilder.setEffectiveDate(effectiveDate); eventBuilder.setEventPlan(productName); eventBuilder.setEventPlanPhase(productName + "-" + phaseType.toString().toLowerCase()); eventBuilder.setEventPriceList(priceList); // We don't really use the following but the code path requires it eventBuilder.setFromDisk(true); return new ApiEventBase(eventBuilder.setApiEventType(apiEventType)); }
public static String phaseName(final String planName, final PhaseType phasetype) { return planName + "-" + phasetype.toString().toLowerCase(); }
public static String planName(final String phaseName) throws CatalogApiException { for (final PhaseType type : PhaseType.values()) { if (phaseName.endsWith(type.toString().toLowerCase())) { return phaseName.substring(0, phaseName.length() - type.toString().length() - 1); } } throw new CatalogApiException(ErrorCode.CAT_BAD_PHASE_NAME, phaseName); }
@Override public ValidationErrors validate(final StandaloneCatalog catalog, final ValidationErrors errors) { // Validation: check for nulls if (planName == null) { errors.add(new ValidationError("Invalid plan for recurring section", DefaultRecurring.class, "")); } if (phaseType == null) { errors.add(new ValidationError("Invalid phase for recurring section", DefaultPlan.class, planName)); } if (billingPeriod == null) { errors.add(new ValidationError(String.format("Recurring section of Phase %s of plan %s has a recurring price but no billing period", phaseType.toString(), planName), DefaultPlanPhase.class, phaseType.toString())); } // Validation: if there is a recurring price there must be a billing period if ((recurringPrice != null) && (billingPeriod == null || billingPeriod == BillingPeriod.NO_BILLING_PERIOD)) { errors.add(new ValidationError(String.format("Recurring section of Phase %s of plan %s has a recurring price but no billing period", phaseType.toString(), planName), DefaultPlanPhase.class, phaseType.toString())); } // Validation: if there is no recurring price there should be no billing period if ((recurringPrice == null) && billingPeriod != BillingPeriod.NO_BILLING_PERIOD) { errors.add(new ValidationError(String.format("Recurring section of Phase %s of plan %s has no recurring price but does have a billing period. The billing period should be set to '%s'", phaseType.toString(), planName, BillingPeriod.NO_BILLING_PERIOD), DefaultPlanPhase.class, phaseType.toString())); } return errors; }
@Override public ValidationErrors validate(final StandaloneCatalog catalog, final ValidationErrors errors) { if (planName == null) { errors.add(new ValidationError(String.format("Invalid plan for phase '%s'", type), DefaultPlanPhase.class, "")); } if (fixed == null && recurring == null && usages.length == 0) { errors.add(new ValidationError(String.format("Phase %s of plan %s need to define at least either a fixed or recurrring or usage section.", type.toString(), planName), DefaultPlanPhase.class, type.toString())); } if (fixed != null) { fixed.validate(catalog, errors); } if (recurring != null) { recurring.validate(catalog, errors); } duration.validate(catalog, errors); validateCollection(catalog, errors, usages); return errors; }
public PhaseJson(final PlanPhase phase) throws CurrencyValueNull { final List<PriceJson> prices = new LinkedList<PriceJson>(); if (phase.getRecurring() != null && phase.getRecurring().getRecurringPrice() != null) { for (final Price price : phase.getRecurring().getRecurringPrice().getPrices()) { prices.add(new PriceJson(price)); } } final List<PriceJson> fixedPrices = new LinkedList<PriceJson>(); if (phase.getFixed() != null && phase.getFixed().getPrice() != null) { for (final Price price : phase.getFixed().getPrice().getPrices()) { fixedPrices.add(new PriceJson(price)); } } final DurationJson durationJson = new DurationJson(phase.getDuration().getUnit(), phase.getDuration().getNumber()); final List<UsageJson> usagesJson = buildUsagesJson(phase.getUsages()); this.type = phase.getPhaseType().toString(); this.prices = prices; this.fixedPrices = fixedPrices; this.duration = durationJson; this.usages = usagesJson; }
private SubscriptionBaseEvent createSubscriptionEvent(final DateTime effectiveDate, final String productName, final PhaseType phaseType, final ApiEventType apiEventType) { final ApiEventBuilder eventBuilder = new ApiEventBuilder(); eventBuilder.setEffectiveDate(effectiveDate); eventBuilder.setEventPlan(productName); eventBuilder.setEventPlanPhase(productName + "-" + phaseType.toString().toLowerCase()); eventBuilder.setEventPriceList(priceList); // We don't really use the following but the code path requires it eventBuilder.setFromDisk(true); return new ApiEventBase(eventBuilder.setApiEventType(apiEventType)); }
final PhasePriceJson phase = new PhasePriceJson(currentPlanName, curPlanPhase.getName(), curPlanPhase.getPhaseType().toString(), fixedPrice, recurringPrice, curPlanPhase.getUsages(), currency); prices.add(phase);