@TimedResource @GET @Path("/product") @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve product for a given subscription and date", response = ProductJson.class) @ApiResponses(value = {}) public Response getProductForSubscriptionAndDate(@QueryParam("subscriptionId") final UUID subscriptionId, @QueryParam("requestedDate") final String requestedDateString, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException { verifyNonNullOrEmpty(subscriptionId, "Subscription id needs to be specified"); final SubscriptionEvent lastEventBeforeRequestedDate = getLastEventBeforeDate(subscriptionId, requestedDateString, request); if (lastEventBeforeRequestedDate == null) { return Response.status(Status.BAD_REQUEST).entity(String.format("%s is before the subscription start date", requestedDateString)).type("text/plain").build(); } final Product product = lastEventBeforeRequestedDate.getNextProduct(); if (product == null) { // Subscription was cancelled at that point return Response.status(Status.BAD_REQUEST).entity(String.format("%s is after the subscription cancel date", requestedDateString)).type("text/plain").build(); } final ProductJson productJson = new ProductJson(product); return Response.status(Status.OK).entity(productJson).build(); }
public EventSubscriptionJson(final SubscriptionEvent subscriptionEvent, @Nullable final AccountAuditLogs accountAuditLogs) { super(toAuditLogJson(getAuditLogsForSubscriptionEvent(subscriptionEvent, accountAuditLogs))); final BillingPeriod billingPeriod = subscriptionEvent.getNextBillingPeriod() != null ? subscriptionEvent.getNextBillingPeriod() : subscriptionEvent.getPrevBillingPeriod(); final Plan plan = subscriptionEvent.getNextPlan() != null ? subscriptionEvent.getNextPlan() : subscriptionEvent.getPrevPlan(); final Product product = subscriptionEvent.getNextProduct() != null ? subscriptionEvent.getNextProduct() : subscriptionEvent.getPrevProduct(); final PriceList priceList = subscriptionEvent.getNextPriceList() != null ? subscriptionEvent.getNextPriceList() : subscriptionEvent.getPrevPriceList(); final PlanPhase phase = subscriptionEvent.getNextPhase() != null ? subscriptionEvent.getNextPhase() : subscriptionEvent.getPrevPhase(); this.eventId = subscriptionEvent.getId(); this.billingPeriod = billingPeriod; this.effectiveDate = subscriptionEvent.getEffectiveDate(); this.plan = plan != null ? plan.getName() : null; this.product = product != null ? product.getName() : null; this.priceList = priceList != null ? priceList.getName() : null; this.eventType = subscriptionEvent.getSubscriptionEventType(); this.isBlockedBilling = subscriptionEvent.isBlockedBilling(); this.isBlockedEntitlement = subscriptionEvent.isBlockedEntitlement(); this.serviceName = subscriptionEvent.getServiceName(); this.serviceStateName = subscriptionEvent.getServiceStateName(); this.phase = phase != null ? phase.getName() : null; }
final SubscriptionEvent firstEvent = subscriptionEvents.isEmpty() ? null : subscriptionEvents.get(0); if (subscription.getLastActiveProduct() == null) { this.productName = (firstEvent == null || firstEvent.getNextProduct() == null) ? null : firstEvent.getNextProduct().getName(); } else { this.productName = subscription.getLastActiveProduct().getName(); this.productCategory = (firstEvent == null || firstEvent.getNextProduct() == null) ? null : firstEvent.getNextProduct().getCategory(); } else { this.productCategory = subscription.getLastActiveProductCategory();