@GET @Path("/{subscriptionId:" + UUID_PATTERN + "}") @Produces(APPLICATION_JSON) public Response getEntitlement(@PathParam("subscriptionId") final String subscriptionId, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException { final UUID uuid = UUID.fromString(subscriptionId); final Subscription subscription = subscriptionApi.getSubscriptionForEntitlementId(uuid, context.createContext(request)); final SubscriptionJson json = new SubscriptionJson(subscription, null, null); return Response.status(Status.OK).entity(json).build(); }
private BundleJson createBundleWithSubscriptions() { final String someUUID = UUID.randomUUID().toString(); final UUID accountId = UUID.randomUUID(); final UUID bundleId = UUID.randomUUID(); final UUID subscriptionId = UUID.randomUUID(); final String externalKey = UUID.randomUUID().toString(); final SubscriptionJson entitlementJsonWithEvents = new SubscriptionJson(accountId.toString(), bundleId.toString(), subscriptionId.toString(), externalKey, new LocalDate(), someUUID, someUUID, someUUID, someUUID, new LocalDate(), new LocalDate(), new LocalDate(), new LocalDate(), null, null, null, null); return new BundleJson(accountId.toString(), bundleId.toString(), externalKey, ImmutableList.<SubscriptionJson>of(entitlementJsonWithEvents), null); }
public BundleJson(final SubscriptionBundle bundle, @Nullable final AccountAuditLogs accountAuditLogs) { super(toAuditLogJson(accountAuditLogs == null ? null : accountAuditLogs.getAuditLogsForBundle(bundle.getId()))); this.accountId = bundle.getAccountId().toString(); this.bundleId = bundle.getId().toString(); this.externalKey = bundle.getExternalKey(); this.subscriptions = new LinkedList<SubscriptionJson>(); for (final Subscription cur : bundle.getSubscriptions()) { final ImmutableList<SubscriptionEvent> events = ImmutableList.<SubscriptionEvent>copyOf(Collections2.filter(bundle.getTimeline().getSubscriptionEvents(), new Predicate<SubscriptionEvent>() { @Override public boolean apply(@Nullable final SubscriptionEvent input) { return input.getEntitlementId().equals(cur.getId()); } })); this.subscriptions.add(new SubscriptionJson(cur, events, accountAuditLogs)); } }
@Test(groups = "fast") public void testJson() throws Exception { final String someUUID = UUID.randomUUID().toString(); final UUID bundleId = UUID.randomUUID(); final String externalKey = UUID.randomUUID().toString(); final List<AuditLogJson> auditLogs = createAuditLogsJson(clock.getUTCNow()); EventSubscriptionJson event = new EventSubscriptionJson(someUUID, BillingPeriod.NO_BILLING_PERIOD.toString(), new LocalDate(), new LocalDate(), "product", "priceList", "eventType", "phase", null); final SubscriptionJson subscription = new SubscriptionJson(someUUID, someUUID, someUUID, externalKey, new LocalDate(), someUUID, someUUID, someUUID, someUUID, new LocalDate(), new LocalDate(), new LocalDate(), new LocalDate(), ImmutableList.<EventSubscriptionJson>of(event), null, null, auditLogs); final BundleJson bundleJson = new BundleJson(someUUID, bundleId.toString(), externalKey, ImmutableList.<SubscriptionJson>of(subscription), auditLogs); Assert.assertEquals(bundleJson.getBundleId(), bundleId.toString()); Assert.assertEquals(bundleJson.getExternalKey(), externalKey); Assert.assertEquals(bundleJson.getSubscriptions().size(), 1); Assert.assertEquals(bundleJson.getAuditLogs(), auditLogs); final String asJson = mapper.writeValueAsString(bundleJson); final BundleJson fromJson = mapper.readValue(asJson, BundleJson.class); Assert.assertEquals(fromJson, bundleJson); } }
PhaseType.DISCOUNT.toString(), auditLogs); final SubscriptionJson entitlementJsonWithEvents = new SubscriptionJson(accountId, bundleId, subscriptionId, externalKey, new LocalDate(), someUUID, someUUID, someUUID, someUUID, new LocalDate(), new LocalDate(), new LocalDate(), new LocalDate(),