Search in sources :

Example 16 with TagDefinition

use of org.killbill.billing.util.tag.TagDefinition in project killbill by killbill.

the class TestDefaultControlTagDefinitionCreationEvent method testSerialization.

@Test(groups = "fast")
public void testSerialization() throws Exception {
    final ObjectMapper objectMapper = new ObjectMapper();
    final UUID tagDefinitionId = UUID.randomUUID();
    final String tagDefinitionName = UUID.randomUUID().toString();
    final String tagDefinitionDescription = UUID.randomUUID().toString();
    final boolean controlTag = false;
    final TagDefinition tagDefinition = new DefaultTagDefinition(tagDefinitionId, tagDefinitionName, tagDefinitionDescription, controlTag);
    final UUID userToken = UUID.randomUUID();
    final DefaultControlTagDefinitionCreationEvent event = new DefaultControlTagDefinitionCreationEvent(tagDefinitionId, tagDefinition, 1L, 2L, UUID.randomUUID());
    final String json = objectMapper.writeValueAsString(event);
    final DefaultControlTagDefinitionCreationEvent fromJson = objectMapper.readValue(json, DefaultControlTagDefinitionCreationEvent.class);
    Assert.assertEquals(fromJson, event);
}
Also used : DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) TagDefinition(org.killbill.billing.util.tag.TagDefinition) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) UUID(java.util.UUID) ObjectMapper(org.killbill.billing.util.jackson.ObjectMapper) Test(org.testng.annotations.Test)

Example 17 with TagDefinition

use of org.killbill.billing.util.tag.TagDefinition in project killbill by killbill.

the class TestDefaultControlTagDeletionEvent method testSerialization.

@Test(groups = "fast")
public void testSerialization() throws Exception {
    final ObjectMapper objectMapper = new ObjectMapper();
    final UUID tagId = UUID.randomUUID();
    final UUID objectId = UUID.randomUUID();
    final ObjectType objectType = ObjectType.ACCOUNT_EMAIL;
    final UUID tagDefinitionId = UUID.randomUUID();
    final String tagDefinitionName = UUID.randomUUID().toString();
    final String tagDefinitionDescription = UUID.randomUUID().toString();
    final boolean controlTag = false;
    final TagDefinition tagDefinition = new DefaultTagDefinition(tagDefinitionId, tagDefinitionName, tagDefinitionDescription, controlTag);
    final UUID userToken = UUID.randomUUID();
    final DefaultControlTagDeletionEvent event = new DefaultControlTagDeletionEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID());
    final String json = objectMapper.writeValueAsString(event);
    final DefaultControlTagDeletionEvent fromJson = objectMapper.readValue(json, DefaultControlTagDeletionEvent.class);
    Assert.assertEquals(fromJson, event);
}
Also used : ObjectType(org.killbill.billing.ObjectType) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) TagDefinition(org.killbill.billing.util.tag.TagDefinition) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) UUID(java.util.UUID) ObjectMapper(org.killbill.billing.util.jackson.ObjectMapper) Test(org.testng.annotations.Test)

Example 18 with TagDefinition

use of org.killbill.billing.util.tag.TagDefinition in project killbill by killbill.

the class TestDefaultUserTagDefinitionCreationEvent method testSerialization.

@Test(groups = "fast")
public void testSerialization() throws Exception {
    final ObjectMapper objectMapper = new ObjectMapper();
    final UUID tagDefinitionId = UUID.randomUUID();
    final String tagDefinitionName = UUID.randomUUID().toString();
    final String tagDefinitionDescription = UUID.randomUUID().toString();
    final boolean controlTag = false;
    final TagDefinition tagDefinition = new DefaultTagDefinition(tagDefinitionId, tagDefinitionName, tagDefinitionDescription, controlTag);
    final UUID userToken = UUID.randomUUID();
    final DefaultUserTagDefinitionCreationEvent event = new DefaultUserTagDefinitionCreationEvent(tagDefinitionId, tagDefinition, 1L, 2L, UUID.randomUUID());
    final String json = objectMapper.writeValueAsString(event);
    final DefaultUserTagDefinitionCreationEvent fromJson = objectMapper.readValue(json, DefaultUserTagDefinitionCreationEvent.class);
    Assert.assertEquals(fromJson, event);
}
Also used : DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) TagDefinition(org.killbill.billing.util.tag.TagDefinition) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) UUID(java.util.UUID) ObjectMapper(org.killbill.billing.util.jackson.ObjectMapper) Test(org.testng.annotations.Test)

Example 19 with TagDefinition

use of org.killbill.billing.util.tag.TagDefinition 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.createTenantContextNoAccountId(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()), ImmutableMap.<String, String>of());
    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 20 with TagDefinition

use of org.killbill.billing.util.tag.TagDefinition 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.createTenantContextNoAccountId(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(QUERY_AUDIT, auditMode.getLevel().toString()), ImmutableMap.<String, String>of("searchKey", searchKey));
    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

TagDefinition (org.killbill.billing.util.tag.TagDefinition)33 UUID (java.util.UUID)27 Test (org.testng.annotations.Test)26 DefaultTagDefinition (org.killbill.billing.util.tag.DefaultTagDefinition)24 ObjectType (org.killbill.billing.ObjectType)12 TagDefinitionModelDao (org.killbill.billing.util.tag.dao.TagDefinitionModelDao)9 ObjectMapper (org.killbill.billing.util.jackson.ObjectMapper)8 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 Produces (javax.ws.rs.Produces)6 TimedResource (org.killbill.commons.metrics.TimedResource)6 GET (javax.ws.rs.GET)5 TenantContext (org.killbill.billing.util.callcontext.TenantContext)5 Path (javax.ws.rs.Path)4 TagDefinitionInternalEvent (org.killbill.billing.events.TagDefinitionInternalEvent)4 TagInternalEvent (org.killbill.billing.events.TagInternalEvent)4 AuditLog (org.killbill.billing.util.audit.AuditLog)4 Tag (org.killbill.billing.util.tag.Tag)4 HashMap (java.util.HashMap)3 TagDefinitionJson (org.killbill.billing.jaxrs.json.TagDefinitionJson)3