@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)); } try { return new BundleJson(bundle, null, accountsAuditLogs.get().get(bundle.getAccountId())); } catch (final CatalogApiException unused) { // Does not happen because we pass a null Currency throw new RuntimeException(unused); } } },
@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)); } try { return new BundleJson(bundle, null, accountsAuditLogs.get().get(bundle.getAccountId())); } catch (final CatalogApiException unused) { // Does not happen because we pass a null Currency throw new RuntimeException(unused); } } },
@TimedResource @GET @Path("/{bundleId:" + UUID_PATTERN + "}/" + TAGS) @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve bundle tags", response = TagJson.class, responseContainer = "List", nickname = "getBundleTags") @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid bundle id supplied"), @ApiResponse(code = 404, message = "Bundle not found")}) public Response getTags(@PathParam(ID_PARAM_NAME) final UUID bundleId, @QueryParam(QUERY_INCLUDED_DELETED) @DefaultValue("false") final Boolean includedDeleted, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws TagDefinitionApiException, SubscriptionApiException { final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final SubscriptionBundle bundle = subscriptionApi.getSubscriptionBundle(bundleId, tenantContext); return super.getTags(bundle.getAccountId(), bundleId, auditMode, includedDeleted, tenantContext); }
@TimedResource @POST @Path("/{bundleId:" + UUID_PATTERN + "}/" + BLOCK) @Consumes(APPLICATION_JSON) @ApiOperation(value = "Block a bundle", response = BlockingStateJson.class, responseContainer = "List") @ApiResponses(value = {@ApiResponse(code = 201, message = "Blocking state created successfully"), @ApiResponse(code = 400, message = "Invalid bundle id supplied"), @ApiResponse(code = 404, message = "Bundle not found")}) public Response addBundleBlockingState(@PathParam(ID_PARAM_NAME) final UUID id, final BlockingStateJson json, @QueryParam(QUERY_REQUESTED_DT) final String requestedDate, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @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 HttpServletRequest request, @javax.ws.rs.core.Context final UriInfo uriInfo) throws SubscriptionApiException, EntitlementApiException, AccountApiException { final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final SubscriptionBundle bundle = subscriptionApi.getSubscriptionBundle(id, tenantContext); return addBlockingState(json, bundle.getAccountId(), id, BlockingStateType.SUBSCRIPTION_BUNDLE, requestedDate, pluginPropertiesString, createdBy, reason, comment, request, uriInfo); }
@TimedResource @GET @Path("/{bundleId:" + UUID_PATTERN + "}") @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve a bundle by id", response = BundleJson.class) @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid bundle id supplied"), @ApiResponse(code = 404, message = "Bundle not found")}) public Response getBundle(@PathParam("bundleId") final UUID bundleId, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException, AccountApiException, CatalogApiException { final TenantContext tenantContext = this.context.createTenantContextNoAccountId(request); final SubscriptionBundle bundle = subscriptionApi.getSubscriptionBundle(bundleId, tenantContext); final Account account = accountUserApi.getAccountById(bundle.getAccountId(), tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(bundle.getAccountId(), auditMode.getLevel(), tenantContext); final BundleJson json = new BundleJson(bundle, account.getCurrency(), accountAuditLogs); return Response.status(Status.OK).entity(json).build(); }
@TimedResource @GET @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve a bundle by external key", response = BundleJson.class, responseContainer = "List") @ApiResponses(value = {@ApiResponse(code = 404, message = "Bundle not found")}) public Response getBundleByKey(@ApiParam(required=true) @QueryParam(QUERY_EXTERNAL_KEY) final String externalKey, @QueryParam(QUERY_INCLUDED_DELETED) @DefaultValue("false") final Boolean includedDeleted, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException, AccountApiException, CatalogApiException { final TenantContext tenantContext = this.context.createTenantContextNoAccountId(request); final List<SubscriptionBundle> bundles; if (includedDeleted) { bundles = subscriptionApi.getSubscriptionBundlesForExternalKey(externalKey, tenantContext); } else { final SubscriptionBundle activeBundle = subscriptionApi.getActiveSubscriptionBundleForExternalKey(externalKey, tenantContext); bundles = ImmutableList.of(activeBundle); } final List<BundleJson> result = new ArrayList<BundleJson>(bundles.size()); for (final SubscriptionBundle bundle : bundles) { final Account account = accountUserApi.getAccountById(bundle.getAccountId(), tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(bundle.getAccountId(), auditMode.getLevel(), tenantContext); final BundleJson json = new BundleJson(bundle, account.getCurrency(), accountAuditLogs); result.add(json); } return Response.status(Status.OK).entity(result).build(); }
@TimedResource @POST @Path("/{bundleId:" + UUID_PATTERN + "}") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation(value = "Transfer a bundle to another account", response = BundleJson.class) @ApiResponses(value = {@ApiResponse(code = 201, message = "Bundle transferred successfully"), @ApiResponse(code = 400, message = "Invalid bundle id, requested date or policy supplied"), @ApiResponse(code = 404, message = "Bundle not found")}) public Response transferBundle(@PathParam(ID_PARAM_NAME) final UUID bundleId, final BundleJson json, @QueryParam(QUERY_REQUESTED_DT) final String requestedDate, @QueryParam(QUERY_BILLING_POLICY) @DefaultValue("END_OF_TERM") final BillingActionPolicy billingPolicy, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @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 { verifyNonNullOrEmpty(json, "BundleJson body should be specified"); verifyNonNullOrEmpty(json.getAccountId(), "BundleJson accountId needs to be set"); final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString); final CallContext callContext = context.createCallContextNoAccountId(createdBy, reason, comment, request); final SubscriptionBundle bundle = subscriptionApi.getSubscriptionBundle(bundleId, callContext); final LocalDate inputLocalDate = toLocalDate(requestedDate); final UUID newBundleId = entitlementApi.transferEntitlementsOverrideBillingPolicy(bundle.getAccountId(), json.getAccountId(), bundle.getExternalKey(), inputLocalDate, billingPolicy, pluginProperties, callContext); return uriBuilder.buildResponse(uriInfo, BundleResource.class, "getBundle", newBundleId, request); }
public BundleJson(final SubscriptionBundle bundle, @Nullable final Currency currency, @Nullable final AccountAuditLogs accountAuditLogs) throws CatalogApiException { super(toAuditLogJson(accountAuditLogs == null ? null : accountAuditLogs.getAuditLogsForBundle(bundle.getId()))); this.accountId = bundle.getAccountId(); this.bundleId = bundle.getId(); this.externalKey = bundle.getExternalKey(); this.subscriptions = new LinkedList<SubscriptionJson>(); for (final Subscription subscription : bundle.getSubscriptions()) { this.subscriptions.add(new SubscriptionJson(subscription, currency, accountAuditLogs)); } this.timeline = new BundleTimelineJson(bundle.getTimeline(), accountAuditLogs); }
private List<AuditLog> getAuditLogsForSubscription(final UUID bundleId, final UUID subscriptionId, final TenantContext context) { try { final SubscriptionBundle bundle = subscriptionApi.getSubscriptionBundle(bundleId, context); return auditUserApi.getAccountAuditLogs(bundle.getAccountId(), AuditLevel.FULL, context).getAuditLogsForSubscription(subscriptionId); } catch (final SubscriptionApiException e) { Assert.fail(e.toString()); return null; } }
private List<AuditLog> getAuditLogsForSubscriptionEvent(final UUID bundleId, final UUID subscriptionEventId, final TenantContext context) { try { final SubscriptionBundle bundle = subscriptionApi.getSubscriptionBundle(bundleId, context); return auditUserApi.getAccountAuditLogs(bundle.getAccountId(), AuditLevel.FULL, context).getAuditLogsForSubscriptionEvent(subscriptionEventId); } catch (final SubscriptionApiException e) { Assert.fail(e.toString()); return null; } }
private List<AuditLog> getAuditLogsForBundle(final UUID bundleId, final TenantContext context) { try { final SubscriptionBundle bundle = subscriptionApi.getSubscriptionBundle(bundleId, context); return auditUserApi.getAccountAuditLogs(bundle.getAccountId(), AuditLevel.FULL, context).getAuditLogsForBundle(bundle.getId()); } catch (final SubscriptionApiException e) { Assert.fail(e.toString()); return null; } }
private Account getAccountFromSubscriptionJson(final SubscriptionJson entitlementJson, final CallContext callContext) throws SubscriptionApiException, AccountApiException, EntitlementApiException { final UUID accountId; if (entitlementJson.getAccountId() != null) { accountId = entitlementJson.getAccountId(); } else if (entitlementJson.getSubscriptionId() != null) { final Entitlement entitlement = entitlementApi.getEntitlementForId(entitlementJson.getSubscriptionId(), callContext); accountId = entitlement.getAccountId(); } else { final SubscriptionBundle subscriptionBundle = subscriptionApi.getSubscriptionBundle(entitlementJson.getBundleId(), callContext); accountId = subscriptionBundle.getAccountId(); } return accountUserApi.getAccountById(accountId, callContext); } }
assertEquals(initialBundle.getAccountId(), newBundle.getAccountId()); assertEquals(initialBundle.getExternalKey(), newBundle.getExternalKey()); assertEquals(initialBundle.getAccountId(), newerBundle.getAccountId()); assertEquals(initialBundle.getExternalKey(), newerBundle.getExternalKey());