@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(); }
@Override public Entitlement doOperation(final CallContext ctx) throws InterruptedException, TimeoutException, EntitlementApiException { final PlanPhaseSpecifier spec = new PlanPhaseSpecifier(entitlement.getProductName(), ProductCategory.valueOf(entitlement.getProductCategory()), BillingPeriod.valueOf(entitlement.getBillingPeriod()), entitlement.getPriceList(), null); final UUID accountId = entitlement.getAccountId() != null ? UUID.fromString(entitlement.getAccountId()) : null; final LocalDate inputLocalDate = toLocalDate(accountId, requestedDate, callContext); final UUID bundleId = entitlement.getBundleId() != null ? UUID.fromString(entitlement.getBundleId()) : null; return (entitlement.getProductCategory().equals(ProductCategory.ADD_ON.toString())) ? entitlementApi.addEntitlement(bundleId, spec, inputLocalDate, callContext) : entitlementApi.createBaseEntitlement(accountId, spec, entitlement.getExternalKey(), inputLocalDate, callContext); }
@Override public Response doOperation(final CallContext ctx) throws EntitlementApiException, InterruptedException, TimeoutException, AccountApiException { final UUID uuid = UUID.fromString(subscriptionId); final Entitlement current = entitlementApi.getEntitlementForId(uuid, callContext); final LocalDate inputLocalDate = toLocalDate(current.getAccountId(), requestedDate, callContext); final Entitlement newEntitlement; if (requestedDate == null && policyString == null) { newEntitlement = current.changePlan(entitlement.getProductName(), BillingPeriod.valueOf(entitlement.getBillingPeriod()), entitlement.getPriceList(), ctx); } else if (policyString == null) { newEntitlement = current.changePlanWithDate(entitlement.getProductName(), BillingPeriod.valueOf(entitlement.getBillingPeriod()), entitlement.getPriceList(), inputLocalDate, ctx); } else { final BillingActionPolicy policy = BillingActionPolicy.valueOf(policyString.toUpperCase()); newEntitlement = current.changePlanOverrideBillingPolicy(entitlement.getProductName(), BillingPeriod.valueOf(entitlement.getBillingPeriod()), entitlement.getPriceList(), inputLocalDate, policy, ctx); } isImmediateOp = newEntitlement.getLastActiveProduct().getName().equals(entitlement.getProductName()) && newEntitlement.getLastActivePlan().getBillingPeriod() == BillingPeriod.valueOf(entitlement.getBillingPeriod()) && newEntitlement.getLastActivePriceList().getName().equals(entitlement.getPriceList()); return Response.status(Status.OK).build(); }
public SubscriptionJson(final Subscription subscription, final List<SubscriptionEvent> subscriptionEvents, @Nullable final AccountAuditLogs accountAuditLogs) { super(toAuditLogJson(accountAuditLogs == null ? null : accountAuditLogs.getAuditLogsForSubscription(subscription.getId()))); this.startDate = subscription.getEffectiveStartDate(); this.productName = subscription.getLastActiveProduct().getName(); cur.getSubscriptionEventType().toString(), phase != null ? phase.getName() : null, toAuditLogJson(accountAuditLogs == null ? null : accountAuditLogs.getAuditLogsForSubscriptionEvent(cur.getId()))));
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(),