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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations