@Test(groups = "fast") public void testForObject() throws Exception { for (final ObjectType objectType : ObjectType.values()) { for (final UUID objectId : objectIds) { for (final AuditLevel level : AuditLevel.values()) { if (AuditLevel.NONE.equals(level)) { Assert.assertEquals(auditUserApi.getAuditLogs(objectId, objectType, level, callContext).size(), 0); } else if (AuditLevel.MINIMAL.equals(level)) { Assert.assertEquals(auditUserApi.getAuditLogs(objectId, objectType, level, callContext), ImmutableList.<AuditLog>of(auditLogs.get(0))); } else { Assert.assertEquals(auditUserApi.getAuditLogs(objectId, objectType, level, callContext), auditLogs); } } } } } }
protected AccountAuditLogs getAccountAuditLogs(final UUID accountId, final TenantContext context) throws OSGIServiceNotAvailable { final AuditUserApi auditUserApi = getAuditUserApi(); return auditUserApi.getAccountAuditLogs(accountId, AuditLevel.MINIMAL, context); }
@Override public AccountAuditLogs call() throws Exception { return auditUserApi.getAccountAuditLogs(accountId, auditMode.getLevel(), tenantContext); } };
@TimedResource @GET @Path("/{accountId:" + UUID_PATTERN + "}/" + AUDIT_LOG) @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve audit logs by account id", response = AuditLogJson.class, responseContainer = "List") @ApiResponses(value = {@ApiResponse(code = 404, message = "Account not found")}) public Response getAccountAuditLogs(@PathParam("accountId") final UUID accountId, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException { final TenantContext tenantContext = context.createTenantContextWithAccountId(accountId, request); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(accountId, AuditLevel.FULL, tenantContext); return Response.status(Status.OK).entity(getAuditLogs(accountAuditLogs)).build(); }
protected Response createCustomFieldResponse(final Iterable<CustomField> fields, final AuditMode auditMode, final TenantContext context) { final Collection<CustomFieldJson> result = new LinkedList<CustomFieldJson>(); for (final CustomField cur : fields) { // TODO PIERRE - Bulk API final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(cur.getId(), ObjectType.CUSTOM_FIELD, auditMode.getLevel(), context); result.add(new CustomFieldJson(cur, auditLogs)); } return Response.status(Response.Status.OK).entity(result).build(); }
@Override public AccountJson apply(final Account account) { final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext); return getAccount(account, accountWithBalance, accountWithBalanceAndCBA, accountAuditLogs, tenantContext); } },
@TimedResource @GET @Path("/{tagDefinitionId:" + UUID_PATTERN + "}") @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve a tag definition", response = TagDefinitionJson.class) @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid tagDefinitionId supplied")}) public Response getTagDefinition(@PathParam("tagDefinitionId") final UUID tagDefId, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws TagDefinitionApiException { final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final TagDefinition tagDefinition = tagUserApi.getTagDefinition(tagDefId, tenantContext); final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(tagDefinition.getId(), ObjectType.TAG_DEFINITION, auditMode.getLevel(), tenantContext); final TagDefinitionJson json = new TagDefinitionJson(tagDefinition, auditLogs); return Response.status(Status.OK).entity(json).build(); }
@TimedResource @GET @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve an account by external key", response = AccountJson.class) @ApiResponses(value = {@ApiResponse(code = 404, message = "Account not found")}) public Response getAccountByKey(@ApiParam(required = true) @QueryParam(QUERY_EXTERNAL_KEY) final String externalKey, @QueryParam(QUERY_ACCOUNT_WITH_BALANCE) @DefaultValue("false") final Boolean accountWithBalance, @QueryParam(QUERY_ACCOUNT_WITH_BALANCE_AND_CBA) @DefaultValue("false") final Boolean accountWithBalanceAndCBA, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException { final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final Account account = accountUserApi.getAccountByKey(externalKey, tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext); final AccountJson accountJson = getAccount(account, accountWithBalance, accountWithBalanceAndCBA, accountAuditLogs, tenantContext); return Response.status(Status.OK).entity(accountJson).build(); }
@TimedResource @GET @Produces(APPLICATION_JSON) @ApiOperation(value = "List tag definitions", response = TagDefinitionJson.class, responseContainer = "List") @ApiResponses(value = {}) public Response getTagDefinitions(@javax.ws.rs.core.Context final HttpServletRequest request, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode) { final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final List<TagDefinition> tagDefinitions = tagUserApi.getTagDefinitions(tenantContext); final Collection<TagDefinitionJson> result = new LinkedList<TagDefinitionJson>(); for (final TagDefinition tagDefinition : tagDefinitions) { final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(tagDefinition.getId(), ObjectType.TAG_DEFINITION, auditMode.getLevel(), tenantContext); result.add(new TagDefinitionJson(tagDefinition, auditLogs)); } return Response.status(Status.OK).entity(result).build(); }
@Override public AccountJson apply(final Account account) { final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext); return getAccount(account, accountWithBalance, accountWithBalanceAndCBA, accountAuditLogs, tenantContext); } },
@Override public CustomFieldJson apply(final CustomField customField) { // TODO Really slow - we should instead try to figure out the account id final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(customField.getId(), ObjectType.CUSTOM_FIELD, auditMode.getLevel(), tenantContext); return new CustomFieldJson(customField, auditLogs); } },
@TimedResource @GET @Path("/{accountId:" + UUID_PATTERN + "}") @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve an account by id", response = AccountJson.class) @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found")}) public Response getAccount(@PathParam("accountId") final UUID accountId, @QueryParam(QUERY_ACCOUNT_WITH_BALANCE) @DefaultValue("false") final Boolean accountWithBalance, @QueryParam(QUERY_ACCOUNT_WITH_BALANCE_AND_CBA) @DefaultValue("false") final Boolean accountWithBalanceAndCBA, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException { final TenantContext tenantContext = context.createTenantContextWithAccountId(accountId, request); final Account account = accountUserApi.getAccountById(accountId, tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext); final AccountJson accountJson = getAccount(account, accountWithBalance, accountWithBalanceAndCBA, accountAuditLogs, tenantContext); return Response.status(Status.OK).entity(accountJson).build(); }
@Override public CustomFieldJson apply(final CustomField customField) { // TODO Really slow - we should instead try to figure out the account id final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(customField.getId(), ObjectType.CUSTOM_FIELD, auditMode.getLevel(), tenantContext); return new CustomFieldJson(customField, auditLogs); } },
@TimedResource(name = "getPaymentByTransactionExternalKey") @GET @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve a payment by transaction external key", response = PaymentJson.class) @ApiResponses(value = {@ApiResponse(code = 404, message = "Payment not found")}) public Response getPaymentByTransactionExternalKey(@ApiParam(required = true) @QueryParam(QUERY_TRANSACTION_EXTERNAL_KEY) final String paymentTransactionExternalKey, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @QueryParam(QUERY_WITH_ATTEMPTS) @DefaultValue("false") final Boolean withAttempts, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException { final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString); final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final Payment payment = paymentApi.getPaymentByTransactionExternalKey(paymentTransactionExternalKey, withPluginInfo, withAttempts, pluginProperties, tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(payment.getAccountId(), auditMode.getLevel(), tenantContext); final PaymentJson result = new PaymentJson(payment, accountAuditLogs); return Response.status(Response.Status.OK).entity(result).build(); }
@Override public TagJson apply(final Tag tag) { final TagDefinition tagDefinition = tagDefinitionsCache.get(tag.getTagDefinitionId()); // TODO Really slow - we should instead try to figure out the account id final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(tag.getId(), ObjectType.TAG, auditMode.getLevel(), tenantContext); return new TagJson(tag, tagDefinition, auditLogs); } },
@TimedResource @GET @Path("/{accountId:" + UUID_PATTERN + "}/" + PAYMENTS) @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve account payments", response = PaymentJson.class, responseContainer = "List") @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid account id supplied")}) public Response getPaymentsForAccount(@PathParam("accountId") final UUID accountId, @QueryParam(QUERY_WITH_ATTEMPTS) @DefaultValue("false") final Boolean withAttempts, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException { final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString); final TenantContext tenantContext = context.createTenantContextWithAccountId(accountId, request); final List<Payment> payments = paymentApi.getAccountPayments(accountId, withPluginInfo, withAttempts, pluginProperties, tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(accountId, auditMode.getLevel(), tenantContext); final List<PaymentJson> result = ImmutableList.copyOf(Iterables.transform(payments, new Function<Payment, PaymentJson>() { @Override public PaymentJson apply(final Payment payment) { return new PaymentJson(payment, accountAuditLogs); } })); return Response.status(Response.Status.OK).entity(result).build(); }
@Override public TagJson apply(final Tag tag) { final TagDefinition tagDefinition = tagDefinitionsCache.get(tag.getTagDefinitionId()); // TODO Really slow - we should instead try to figure out the account id final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(tag.getId(), ObjectType.TAG, auditMode.getLevel(), tenantContext); return new TagJson(tag, tagDefinition, auditLogs); } },
@TimedResource(name = "getPaymentByTransactionId") @GET @Path("/{transactionId:" + UUID_PATTERN + "}/") @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve a payment by transaction id", response = PaymentJson.class) @ApiResponses(value = {@ApiResponse(code = 404, message = "Payment not found")}) public Response getPaymentByTransactionId(@PathParam("transactionId") final UUID transactionId, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @QueryParam(QUERY_WITH_ATTEMPTS) @DefaultValue("false") final Boolean withAttempts, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException { final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString); final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final Payment payment = paymentApi.getPaymentByTransactionId(transactionId, withPluginInfo, withAttempts, pluginProperties, tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(payment.getAccountId(), auditMode.getLevel(), tenantContext); final PaymentJson result = new PaymentJson(payment, accountAuditLogs); return Response.status(Response.Status.OK).entity(result).build(); }
@Test(groups = "fast") public void testForObject() throws Exception { for (final ObjectType objectType : ObjectType.values()) { for (final UUID objectId : objectIds) { for (final AuditLevel level : AuditLevel.values()) { if (AuditLevel.NONE.equals(level)) { Assert.assertEquals(auditUserApi.getAuditLogs(objectId, objectType, level, callContext).size(), 0); } else if (AuditLevel.MINIMAL.equals(level)) { Assert.assertEquals(auditUserApi.getAuditLogs(objectId, objectType, level, callContext), ImmutableList.<AuditLog>of(auditLogs.get(0))); } else { Assert.assertEquals(auditUserApi.getAuditLogs(objectId, objectType, level, callContext), auditLogs); } } } } } }
@TimedResource(name = "getPayment") @GET @Path("/{paymentId:" + UUID_PATTERN + "}/") @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve a payment by id", response = PaymentJson.class) @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid paymentId supplied"), @ApiResponse(code = 404, message = "Payment not found")}) public Response getPayment(@PathParam("paymentId") final UUID paymentId, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @QueryParam(QUERY_WITH_ATTEMPTS) @DefaultValue("false") final Boolean withAttempts, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException { final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString); final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final Payment payment = paymentApi.getPayment(paymentId, withPluginInfo, withAttempts, pluginProperties, tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(payment.getAccountId(), auditMode.getLevel(), tenantContext); final PaymentJson result = new PaymentJson(payment, accountAuditLogs); return Response.status(Response.Status.OK).entity(result).build(); }