Search in sources :

Example 1 with TagJson

use of org.killbill.billing.jaxrs.json.TagJson in project killbill by killbill.

the class JaxRsResourceBase method createTagResponse.

protected Response createTagResponse(final UUID accountId, final List<Tag> tags, final AuditMode auditMode, final TenantContext context) throws TagDefinitionApiException {
    final AccountAuditLogsForObjectType tagsAuditLogs = auditUserApi.getAccountAuditLogs(accountId, ObjectType.TAG, auditMode.getLevel(), context);
    final Map<UUID, TagDefinition> tagDefinitionsCache = new HashMap<UUID, TagDefinition>();
    final Collection<TagJson> result = new LinkedList<TagJson>();
    for (final Tag tag : tags) {
        if (tagDefinitionsCache.get(tag.getTagDefinitionId()) == null) {
            tagDefinitionsCache.put(tag.getTagDefinitionId(), tagUserApi.getTagDefinition(tag.getTagDefinitionId(), context));
        }
        final TagDefinition tagDefinition = tagDefinitionsCache.get(tag.getTagDefinitionId());
        final List<AuditLog> auditLogs = tagsAuditLogs.getAuditLogs(tag.getId());
        result.add(new TagJson(tag, tagDefinition, auditLogs));
    }
    return Response.status(Response.Status.OK).entity(result).build();
}
Also used : TagDefinition(org.killbill.billing.util.tag.TagDefinition) TagJson(org.killbill.billing.jaxrs.json.TagJson) HashMap(java.util.HashMap) AccountAuditLogsForObjectType(org.killbill.billing.util.audit.AccountAuditLogsForObjectType) Tag(org.killbill.billing.util.tag.Tag) UUID(java.util.UUID) LinkedList(java.util.LinkedList) AuditLog(org.killbill.billing.util.audit.AuditLog)

Example 2 with TagJson

use of org.killbill.billing.jaxrs.json.TagJson in project killbill by killbill.

the class TagResource method searchTags.

@TimedResource
@GET
@Path("/" + SEARCH + "/{searchKey:" + ANYTHING_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Search tags", response = TagJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response searchTags(@PathParam("searchKey") final String searchKey, @QueryParam(QUERY_SEARCH_OFFSET) @DefaultValue("0") final Long offset, @QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws TagApiException {
    final TenantContext tenantContext = context.createContext(request);
    final Pagination<Tag> tags = tagUserApi.searchTags(searchKey, offset, limit, tenantContext);
    final URI nextPageUri = uriBuilder.nextPage(TagResource.class, "searchTags", tags.getNextOffset(), limit, ImmutableMap.<String, String>of("searchKey", searchKey, QUERY_AUDIT, auditMode.getLevel().toString()));
    final Map<UUID, TagDefinition> tagDefinitionsCache = new HashMap<UUID, TagDefinition>();
    for (final TagDefinition tagDefinition : tagUserApi.getTagDefinitions(tenantContext)) {
        tagDefinitionsCache.put(tagDefinition.getId(), tagDefinition);
    }
    return buildStreamingPaginationResponse(tags, new Function<Tag, TagJson>() {

        @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);
        }
    }, nextPageUri);
}
Also used : TagDefinition(org.killbill.billing.util.tag.TagDefinition) TagJson(org.killbill.billing.jaxrs.json.TagJson) HashMap(java.util.HashMap) TenantContext(org.killbill.billing.util.callcontext.TenantContext) List(java.util.List) Tag(org.killbill.billing.util.tag.Tag) UUID(java.util.UUID) URI(java.net.URI) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with TagJson

use of org.killbill.billing.jaxrs.json.TagJson in project killbill by killbill.

the class TagResource method getTags.

@TimedResource
@GET
@Path("/" + PAGINATION)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "List tags", response = TagJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response getTags(@QueryParam(QUERY_SEARCH_OFFSET) @DefaultValue("0") final Long offset, @QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws TagApiException {
    final TenantContext tenantContext = context.createContext(request);
    final Pagination<Tag> tags = tagUserApi.getTags(offset, limit, tenantContext);
    final URI nextPageUri = uriBuilder.nextPage(TagResource.class, "getTags", tags.getNextOffset(), limit, ImmutableMap.<String, String>of(QUERY_AUDIT, auditMode.getLevel().toString()));
    final Map<UUID, TagDefinition> tagDefinitionsCache = new HashMap<UUID, TagDefinition>();
    for (final TagDefinition tagDefinition : tagUserApi.getTagDefinitions(tenantContext)) {
        tagDefinitionsCache.put(tagDefinition.getId(), tagDefinition);
    }
    return buildStreamingPaginationResponse(tags, new Function<Tag, TagJson>() {

        @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);
        }
    }, nextPageUri);
}
Also used : TagDefinition(org.killbill.billing.util.tag.TagDefinition) TagJson(org.killbill.billing.jaxrs.json.TagJson) HashMap(java.util.HashMap) TenantContext(org.killbill.billing.util.callcontext.TenantContext) List(java.util.List) Tag(org.killbill.billing.util.tag.Tag) UUID(java.util.UUID) URI(java.net.URI) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

HashMap (java.util.HashMap)3 UUID (java.util.UUID)3 TagJson (org.killbill.billing.jaxrs.json.TagJson)3 Tag (org.killbill.billing.util.tag.Tag)3 TagDefinition (org.killbill.billing.util.tag.TagDefinition)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 URI (java.net.URI)2 List (java.util.List)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 TenantContext (org.killbill.billing.util.callcontext.TenantContext)2 TimedResource (org.killbill.commons.metrics.TimedResource)2 LinkedList (java.util.LinkedList)1 AccountAuditLogsForObjectType (org.killbill.billing.util.audit.AccountAuditLogsForObjectType)1 AuditLog (org.killbill.billing.util.audit.AuditLog)1