@Override public BundleJson apply(final SubscriptionBundle input) { return new BundleJson(input, null); } });
@Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } final BundleTimelineJson that = (BundleTimelineJson) o; if (bundle != null ? !bundle.equals(that.bundle) : that.bundle != null) { return false; } if (invoices != null ? !invoices.equals(that.invoices) : that.invoices != null) { return false; } if (payments != null ? !payments.equals(that.payments) : that.payments != null) { return false; } if (reasonForChange != null ? !reasonForChange.equals(that.reasonForChange) : that.reasonForChange != null) { return false; } if (viewId != null ? !viewId.equals(that.viewId) : that.viewId != null) { return false; } return true; }
@Override public int hashCode() { int result = viewId != null ? viewId.hashCode() : 0; result = 31 * result + (bundle != null ? bundle.hashCode() : 0); result = 31 * result + (payments != null ? payments.hashCode() : 0); result = 31 * result + (invoices != null ? invoices.hashCode() : 0); result = 31 * result + (reasonForChange != null ? reasonForChange.hashCode() : 0); return result; } }
@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); } }
@PUT @Path("/{bundleId:" + UUID_PATTERN + "}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) public Response transferBundle(final BundleJson json, @PathParam(ID_PARAM_NAME) final String id, @QueryParam(QUERY_REQUESTED_DT) final String requestedDate, @QueryParam(QUERY_BILLING_POLICY) @DefaultValue("END_OF_TERM") final String policyString, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final UriInfo uriInfo, @javax.ws.rs.core.Context final HttpServletRequest request) throws EntitlementApiException, SubscriptionApiException, AccountApiException { final BillingActionPolicy policy = BillingActionPolicy.valueOf(policyString.toUpperCase()); final CallContext callContext = context.createContext(createdBy, reason, comment, request); final UUID bundleId = UUID.fromString(id); final SubscriptionBundle bundle = subscriptionApi.getSubscriptionBundle(bundleId, callContext); final LocalDate inputLocalDate = toLocalDate(bundle.getAccountId(), requestedDate, callContext); final UUID newBundleId = entitlementApi.transferEntitlementsOverrideBillingPolicy(bundle.getAccountId(), UUID.fromString(json.getAccountId()), bundle.getExternalKey(), inputLocalDate, policy, callContext); return uriBuilder.buildResponse(BundleResource.class, "getBundle", newBundleId, uriInfo.getBaseUri().toString()); }
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)); } }
@GET @Path("/{bundleId:" + UUID_PATTERN + "}") @Produces(APPLICATION_JSON) public Response getBundle(@PathParam("bundleId") final String bundleId, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException { final UUID id = UUID.fromString(bundleId); final SubscriptionBundle bundle = subscriptionApi.getSubscriptionBundle(id, context.createContext(request)); final BundleJson json = new BundleJson(bundle, null); return Response.status(Status.OK).entity(json).build(); }
@GET @Produces(APPLICATION_JSON) public Response getBundleByKey(@QueryParam(QUERY_EXTERNAL_KEY) final String externalKey, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException { final SubscriptionBundle bundle = subscriptionApi.getActiveSubscriptionBundleForExternalKey(externalKey, context.createContext(request)); final BundleJson json = new BundleJson(bundle, null); return Response.status(Status.OK).entity(json).build(); }
@Override public BundleJson apply(final SubscriptionBundle bundle) { // Cache audit logs per account if (accountsAuditLogs.get().get(bundle.getAccountId()) == null) { accountsAuditLogs.get().put(bundle.getAccountId(), auditUserApi.getAccountAuditLogs(bundle.getAccountId(), auditMode.getLevel(), tenantContext)); } return new BundleJson(bundle, accountsAuditLogs.get().get(bundle.getAccountId())); } },
@Override public BundleJson apply(final SubscriptionBundle bundle) { // Cache audit logs per account if (accountsAuditLogs.get().get(bundle.getAccountId()) == null) { accountsAuditLogs.get().put(bundle.getAccountId(), auditUserApi.getAccountAuditLogs(bundle.getAccountId(), auditMode.getLevel(), tenantContext)); } return new BundleJson(bundle, accountsAuditLogs.get().get(bundle.getAccountId())); } },
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); }
for (final SubscriptionBundle bundle : bundles) { final List<AuditLog> bundleAuditLogs = accountAuditLogs.getAuditLogsForBundle(bundle.getId()); final BundleJson jsonWithSubscriptions = new BundleJson(bundle, accountAuditLogs); this.bundles.add(jsonWithSubscriptions);