@Override public int compare(final StandaloneCatalog c1, final StandaloneCatalog c2) { return c1.getEffectiveDate().compareTo(c2.getEffectiveDate()); } });
private int indexOfVersionForDate(final Date date) throws CatalogApiException { for (int i = versions.size() - 1; i >= 0; i--) { final StandaloneCatalog c = versions.get(i); if (c.getEffectiveDate().getTime() < date.getTime()) { return i; } } throw new CatalogApiException(ErrorCode.CAT_NO_CATALOG_FOR_GIVEN_DATE, date.toString()); }
@Override public ValidationErrors validate(final StandaloneCatalog catalog, final ValidationErrors errors) { if (effectiveDateForExistingSubscriptons != null && catalog.getEffectiveDate().getTime() > effectiveDateForExistingSubscriptons.getTime()) { errors.add(new ValidationError(String.format("Price effective date %s is before catalog effective date '%s'", effectiveDateForExistingSubscriptons, catalog.getEffectiveDate().getTime()), catalog.getCatalogURI(), DefaultInternationalPrice.class, "")); } return errors; }
@Override public Date getEffectiveDate() throws CatalogApiException { return versionForDate(clock.getUTCNow()).getEffectiveDate(); }
@Test(groups = "fast") public void testLoad() throws IOException, SAXException, InvalidConfigException, JAXBException, TransformerException, URISyntaxException, ServiceException { final VersionedCatalog c = loader.load(Resources.getResource("versionedCatalog").toString()); Assert.assertEquals(c.size(), 3); final Iterator<StandaloneCatalog> it = c.iterator(); DateTime dt = new DateTime("2011-01-01T00:00:00+00:00"); Assert.assertEquals(it.next().getEffectiveDate(), dt.toDate()); dt = new DateTime("2011-02-02T00:00:00+00:00"); Assert.assertEquals(it.next().getEffectiveDate(), dt.toDate()); dt = new DateTime("2011-03-03T00:00:00+00:00"); Assert.assertEquals(it.next().getEffectiveDate(), dt.toDate()); } }
final DateTime catalogEffectiveDate = new DateTime(c.getEffectiveDate()); if (subscriptionStartDate.isAfter(catalogEffectiveDate)) { // Its a new subscription this plan always applies return plan;