public static String phaseName(final String planName, final PhaseType phasetype) { return planName + "-" + phasetype.toString().toLowerCase(); }
@Override public boolean apply(final PlanPhasePriceOverride input) { if (input.getPhaseName() != null) { return input.getPhaseName().equals(curPhase.getName()); } // If the phaseName was not passed, we infer by matching the phaseType. This obviously would not work in a case where // a plan is defined with multiple phases of the same type. final PlanPhaseSpecifier curPlanPhaseSpecifier = input.getPlanPhaseSpecifier(); if (curPlanPhaseSpecifier.getPhaseType().equals(curPhase.getPhaseType())) { return true; } return false; } }).orNull();
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (phaseType != null ? phaseType.hashCode() : 0); return result; }
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 void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { this.prettyName = in.readBoolean() ? in.readUTF() : null; this.type = in.readBoolean() ? PhaseType.valueOf(in.readUTF()) : null; this.duration = (DefaultDuration) in.readObject(); this.fixed = (DefaultFixed) in.readObject(); this.recurring = (DefaultRecurring) in.readObject(); this.usages = (DefaultUsage[]) in.readObject(); this.planName = in.readUTF(); this.product = (Product) in.readObject(); } }
@Override public void writeExternal(final ObjectOutput out) throws IOException { out.writeBoolean(billingPeriod != null); if (billingPeriod != null) { out.writeUTF(billingPeriod.name()); } out.writeObject(recurringPrice); out.writeUTF(planName); out.writeBoolean(phaseType != null); if (phaseType != null) { out.writeUTF(phaseType.name()); } }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { this.billingPeriod = in.readBoolean() ? BillingPeriod.valueOf(in.readUTF()) : null; this.recurringPrice = (DefaultInternationalPrice) in.readObject(); this.planName = in.readUTF(); this.phaseType = in.readBoolean() ? PhaseType.valueOf(in.readUTF()) : null; } }
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 void writeExternal(final ObjectOutput out) throws IOException { super.writeExternal(out); out.writeBoolean(phaseType != null); if (phaseType != null) { out.writeUTF(phaseType.name()); } }
@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 void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); this.phaseType = in.readBoolean() ? PhaseType.valueOf(in.readUTF()) : null; } }
@Override public int hashCode() { int result = type != null ? type.hashCode() : 0; result = 31 * result + (duration != null ? duration.hashCode() : 0); result = 31 * result + (fixed != null ? fixed.hashCode() : 0); result = 31 * result + (recurring != null ? recurring.hashCode() : 0); //result = 31 * result + (usages != null ? Arrays.hashCode(usages) : 0); return result; }
return false; if (phaseType != null ? !phaseType.equals(that.phaseType) : that.phaseType != null) { return false;
@Override public void writeExternal(final ObjectOutput out) throws IOException { out.writeBoolean(prettyName != null); if (prettyName != null) { out.writeUTF(prettyName); } out.writeBoolean(type != null); if (type != null) { out.writeUTF(type.name()); } out.writeObject(duration); out.writeObject(fixed); out.writeObject(recurring); out.writeObject(usages); out.writeUTF(planName); out.writeObject(product); }
@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; }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { this.phaseType = in.readBoolean() ? PhaseType.valueOf(in.readUTF()) : null; this.fromProduct = (DefaultProduct) in.readObject(); this.fromProductCategory = in.readBoolean() ? ProductCategory.valueOf(in.readUTF()) : null; this.fromBillingPeriod = in.readBoolean() ? BillingPeriod.valueOf(in.readUTF()) : null; this.fromPriceList = (DefaultPriceList) in.readObject(); this.toProduct = (DefaultProduct) in.readObject(); this.toProductCategory = in.readBoolean() ? ProductCategory.valueOf(in.readUTF()) : null; this.toBillingPeriod = in.readBoolean() ? BillingPeriod.valueOf(in.readUTF()) : null; this.toPriceList = (DefaultPriceList) in.readObject(); } }
@Override public int hashCode() { int result = phaseType != null ? phaseType.hashCode() : 0; result = 31 * result + (fromProduct != null ? fromProduct.hashCode() : 0); result = 31 * result + (fromProductCategory != null ? fromProductCategory.hashCode() : 0); result = 31 * result + (fromBillingPeriod != null ? fromBillingPeriod.hashCode() : 0); result = 31 * result + (fromPriceList != null ? fromPriceList.hashCode() : 0); result = 31 * result + (toProduct != null ? toProduct.hashCode() : 0); result = 31 * result + (toProductCategory != null ? toProductCategory.hashCode() : 0); result = 31 * result + (toBillingPeriod != null ? toBillingPeriod.hashCode() : 0); result = 31 * result + (toPriceList != null ? toPriceList.hashCode() : 0); return result; }
@Override public boolean apply(final PlanPhasePriceOverride input) { if (input.getPhaseName() != null) { return input.getPhaseName().equals(curPhase.getName()); } // If the phaseName was not passed, we infer by matching the phaseType. This obviously would not work in a case where // a plan is defined with multiple phases of the same type. final PlanPhaseSpecifier curPlanPhaseSpecifier = input.getPlanPhaseSpecifier(); if (curPlanPhaseSpecifier.getPhaseType().equals(curPhase.getPhaseType())) { return true; } return false; } }).orNull();
@Override public void writeExternal(final ObjectOutput out) throws IOException { out.writeBoolean(phaseType != null); if (phaseType != null) { out.writeUTF(phaseType.name()); } out.writeObject(fromProduct); out.writeBoolean(fromProductCategory != null); if (fromProductCategory != null) { out.writeUTF(fromProductCategory.name()); } out.writeBoolean(fromBillingPeriod != null); if (fromBillingPeriod != null) { out.writeUTF(fromBillingPeriod.name()); } out.writeObject(fromPriceList); out.writeObject(toProduct); out.writeBoolean(toProductCategory != null); if (toProductCategory != null) { out.writeUTF(toProductCategory.name()); } out.writeBoolean(toBillingPeriod != null); if (toBillingPeriod != null) { out.writeUTF(toBillingPeriod.name()); } out.writeObject(toPriceList); }
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)); }