@TimedResource @GET @Path("/plan") @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve plan for a given subscription and date", response = PlanJson.class) @ApiResponses(value = {}) public Response getPlanForSubscriptionAndDate(@QueryParam("subscriptionId") final UUID subscriptionId, @QueryParam("requestedDate") final String requestedDateString, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException, CurrencyValueNull { 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 Plan plan = lastEventBeforeRequestedDate.getNextPlan(); if (plan == 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 PlanJson planJson = new PlanJson(plan); return Response.status(Status.OK).entity(planJson).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; }
this.billingPeriod = (firstEvent == null || firstEvent.getNextPlan() == null) ? null : firstEvent.getNextPlan().getRecurringBillingPeriod(); } else { this.billingPeriod = subscription.getLastActivePlan().getRecurringBillingPeriod(); this.planName = (firstEvent == null || firstEvent.getNextPlan() == null) ? null : firstEvent.getNextPlan().getName(); } else { this.planName = subscription.getLastActivePlan().getName(); if (currency != null) { final Plan curPlan = subscriptionEvent.getNextPlan(); if (curPlan != null && (currentPlanName == null || !curPlan.getName().equals(currentPlanName))) { currentPlanName = curPlan.getName();