public void add(final StandaloneCatalog e) { if (catalogName == null && e.getCatalogName() != null) { catalogName = e.getCatalogName(); } versions.add(e); Collections.sort(versions, new Comparator<StandaloneCatalog>() { @Override public int compare(final StandaloneCatalog c1, final StandaloneCatalog c2) { return c1.getEffectiveDate().compareTo(c2.getEffectiveDate()); } }); }
@Override public ValidationErrors validate(final StandaloneCatalog catalog, final ValidationErrors errors) { if (catalogName == null || !catalogName.equals(catalog.getCatalogName())) { errors.add(new ValidationError(String.format("Invalid catalogName for product '%s'", name), DefaultProduct.class, "")); } //TODO: MDW validation: inclusion and exclusion lists can only contain addon products //TODO: MDW validation: a given product can only be in, at most, one of inclusion and exclusion lists return errors; }
@Override public void initialize(final StandaloneCatalog catalog) { super.initialize(catalog); CatalogSafetyInitializer.initializeNonRequiredNullFieldsWithDefaultValue(this); for (final DefaultLimit cur : limits) { cur.initialize(catalog); } if (prettyName == null) { this.prettyName = name; } catalogName = catalog.getCatalogName(); }
@Override public ValidationErrors validate(final DefaultVersionedCatalog catalog, final ValidationErrors errors) { final Set<Date> effectiveDates = new TreeSet<Date>(); for (final StandaloneCatalog c : versions) { if (effectiveDates.contains(c.getEffectiveDate())) { errors.add(new ValidationError(String.format("Catalog effective date '%s' already exists for a previous version", c.getEffectiveDate()), VersionedCatalog.class, "")); } else { effectiveDates.add(c.getEffectiveDate()); } if (!c.getCatalogName().equals(catalogName)) { errors.add(new ValidationError(String.format("Catalog name '%s' is not consistent across versions ", c.getCatalogName()), VersionedCatalog.class, "")); } errors.addAll(c.validate(c, errors)); } return errors; }
@Test(groups = "fast") public void testMappingFromExistingCatalog() throws Exception { final StandaloneCatalog inputCatalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarAdvanced.xml").toExternalForm(), StandaloneCatalog.class); final StandalonePluginCatalog pluginCatalog = buildStandalonePluginCatalog(inputCatalog); final StandaloneCatalogMapper mapper = new StandaloneCatalogMapper(inputCatalog.getCatalogName()); final StandaloneCatalog output = mapper.toStandaloneCatalog(pluginCatalog); output.setRecurringBillingMode(inputCatalog.getRecurringBillingMode()); Assert.assertEquals(output, inputCatalog); }
public StandaloneCatalogWithPriceOverride(final StandaloneCatalog catalog, final PriceOverride priceOverride, final Long tenantRecordId, final InternalCallContextFactory internalCallContextFactory) { // Initialize from input catalog setCatalogName(catalog.getCatalogName()); setEffectiveDate(catalog.getEffectiveDate()); setProducts(catalog.getCurrentProducts()); setPlans(catalog.getCurrentPlans()); setPriceLists(catalog.getPriceLists()); setPlanRules(catalog.getPlanRules()); setSupportedCurrencies(catalog.getCurrentSupportedCurrencies()); setUnits(catalog.getCurrentUnits()); this.tenantRecordId = tenantRecordId; this.priceOverride = priceOverride; this.internalCallContextFactory = internalCallContextFactory; }
public DefaultMutableStaticCatalog(final StandaloneCatalog input) { this.setCatalogName(input.getCatalogName()) .setRecurringBillingMode(input.getRecurringBillingMode()) .setEffectiveDate(input.getEffectiveDate()) .setSupportedCurrencies(input.getCurrentSupportedCurrencies()) .setUnits(input.getCurrentUnits()) .setProducts(input.getCurrentProducts()) .setPlans(input.getCurrentPlans()) .setPlanRules(input.getPlanRules()) .setPriceLists(input.getPriceLists()); initialize(this); }
public void add(final StandaloneCatalog e) { if (catalogName == null && e.getCatalogName() != null) { catalogName = e.getCatalogName(); } versions.add(e); Collections.sort(versions, new Comparator<StandaloneCatalog>() { @Override public int compare(final StandaloneCatalog c1, final StandaloneCatalog c2) { return c1.getEffectiveDate().compareTo(c2.getEffectiveDate()); } }); }
@Override public ValidationErrors validate(final StandaloneCatalog catalog, final ValidationErrors errors) { if (catalogName == null || !catalogName.equals(catalog.getCatalogName())) { errors.add(new ValidationError(String.format("Invalid catalogName for product '%s'", name), DefaultProduct.class, "")); } //TODO: MDW validation: inclusion and exclusion lists can only contain addon products //TODO: MDW validation: a given product can only be in, at most, one of inclusion and exclusion lists return errors; }
@Override public void initialize(final StandaloneCatalog catalog) { super.initialize(catalog); CatalogSafetyInitializer.initializeNonRequiredNullFieldsWithDefaultValue(this); for (final DefaultLimit cur : limits) { cur.initialize(catalog); } if (prettyName == null) { this.prettyName = name; } catalogName = catalog.getCatalogName(); }
@Override public ValidationErrors validate(final DefaultVersionedCatalog catalog, final ValidationErrors errors) { final Set<Date> effectiveDates = new TreeSet<Date>(); for (final StandaloneCatalog c : versions) { if (effectiveDates.contains(c.getEffectiveDate())) { errors.add(new ValidationError(String.format("Catalog effective date '%s' already exists for a previous version", c.getEffectiveDate()), VersionedCatalog.class, "")); } else { effectiveDates.add(c.getEffectiveDate()); } if (!c.getCatalogName().equals(catalogName)) { errors.add(new ValidationError(String.format("Catalog name '%s' is not consistent across versions ", c.getCatalogName()), VersionedCatalog.class, "")); } errors.addAll(c.validate(c, errors)); } return errors; }
@Test(groups = "fast") public void testMappingFromExistingCatalog() throws Exception { final StandaloneCatalog inputCatalog = XMLLoader.getObjectFromString(Resources.getResource("SpyCarAdvanced.xml").toExternalForm(), StandaloneCatalog.class); final StandalonePluginCatalog pluginCatalog = buildStandalonePluginCatalog(inputCatalog); final StandaloneCatalogMapper mapper = new StandaloneCatalogMapper(inputCatalog.getCatalogName()); final StandaloneCatalog output = mapper.toStandaloneCatalog(pluginCatalog); output.setRecurringBillingMode(inputCatalog.getRecurringBillingMode()); Assert.assertEquals(output, inputCatalog); }
public StandaloneCatalogWithPriceOverride(final StandaloneCatalog catalog, final PriceOverride priceOverride, final Long tenantRecordId, final InternalCallContextFactory internalCallContextFactory) { // Initialize from input catalog setCatalogName(catalog.getCatalogName()); setEffectiveDate(catalog.getEffectiveDate()); setProducts(catalog.getCurrentProducts()); setPlans(catalog.getCurrentPlans()); setPriceLists(catalog.getPriceLists()); setPlanRules(catalog.getPlanRules()); setSupportedCurrencies(catalog.getCurrentSupportedCurrencies()); setUnits(catalog.getCurrentUnits()); this.tenantRecordId = tenantRecordId; this.priceOverride = priceOverride; this.internalCallContextFactory = internalCallContextFactory; }
public DefaultMutableStaticCatalog(final StandaloneCatalog input) { this.setCatalogName(input.getCatalogName()) .setRecurringBillingMode(input.getRecurringBillingMode()) .setEffectiveDate(input.getEffectiveDate()) .setSupportedCurrencies(input.getCurrentSupportedCurrencies()) .setUnits(input.getCurrentUnits()) .setProducts(input.getCurrentProducts()) .setPlans(input.getCurrentPlans()) .setPlanRules(input.getPlanRules()) .setPriceLists(input.getPriceLists()); initialize(this); }