use of org.killbill.billing.util.tag.TagDefinition in project killbill by killbill.
the class JaxRsResourceBase method createTagResponse.
protected Response createTagResponse(@Nullable final UUID accountId, final List<Tag> tags, final AuditMode auditMode, final TenantContext context) throws TagDefinitionApiException {
Preconditions.checkState(accountId != null || AuditLevel.NONE.equals(auditMode.getLevel()), "No accountId specified but auditLevel is " + auditMode.getLevel());
final AccountAuditLogsForObjectType tagsAuditLogs = tags.isEmpty() ? null : 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();
}
use of org.killbill.billing.util.tag.TagDefinition in project killbill by killbill.
the class TagDefinitionResource method createTagDefinition.
@TimedResource
@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Create a tag definition", response = TagDefinitionJson.class)
@ApiResponses(value = { @ApiResponse(code = 201, message = "Tag definition created successfully"), @ApiResponse(code = 400, message = "Invalid name or description supplied") })
public Response createTagDefinition(final TagDefinitionJson json, @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 TagDefinitionApiException {
// Checked as the database layer as well, but bail early and return 400 instead of 500
verifyNonNullOrEmpty(json, "TagDefinitionJson body should be specified");
verifyNonNullOrEmpty(json.getName(), "TagDefinition name needs to be set", json.getDescription(), "TagDefinition description needs to be set");
Preconditions.checkArgument(json.getApplicableObjectTypes() != null && !json.getApplicableObjectTypes().isEmpty(), "Applicable object types must be set");
final TagDefinition createdTagDef = tagUserApi.createTagDefinition(json.getName(), json.getDescription(), json.getApplicableObjectTypes(), context.createCallContextNoAccountId(createdBy, reason, comment, request));
return uriBuilder.buildResponse(uriInfo, TagDefinitionResource.class, "getTagDefinition", createdTagDef.getId(), request);
}
use of org.killbill.billing.util.tag.TagDefinition in project killbill by killbill.
the class TestDefaultControlTagDefinitionCreationEvent method testPojo.
@Test(groups = "fast")
public void testPojo() throws Exception {
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());
Assert.assertEquals(event.getBusEventType(), BusInternalEvent.BusInternalEventType.CONTROL_TAGDEFINITION_CREATION);
Assert.assertEquals(event.getTagDefinitionId(), tagDefinitionId);
Assert.assertEquals(event.getTagDefinition(), tagDefinition);
Assert.assertEquals(event.getTagDefinition().getId(), tagDefinitionId);
Assert.assertEquals(event.getTagDefinition().getName(), tagDefinitionName);
Assert.assertEquals(event.getTagDefinition().getDescription(), tagDefinitionDescription);
Assert.assertEquals(event, event);
Assert.assertEquals(event, new DefaultControlTagDefinitionCreationEvent(tagDefinitionId, tagDefinition, 1L, 2L, UUID.randomUUID()));
Assert.assertTrue(event.equals(event));
Assert.assertTrue(event.equals(new DefaultControlTagDefinitionCreationEvent(tagDefinitionId, tagDefinition, 1L, 2L, UUID.randomUUID())));
}
use of org.killbill.billing.util.tag.TagDefinition in project killbill by killbill.
the class TestDefaultControlTagDeletionEvent method testPojo.
@Test(groups = "fast")
public void testPojo() throws Exception {
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());
Assert.assertEquals(event.getBusEventType(), BusInternalEvent.BusInternalEventType.CONTROL_TAG_DELETION);
Assert.assertEquals(event.getTagId(), tagId);
Assert.assertEquals(event.getObjectId(), objectId);
Assert.assertEquals(event.getObjectType(), objectType);
Assert.assertEquals(event.getTagDefinition(), tagDefinition);
Assert.assertEquals(event.getTagDefinition().getId(), tagDefinitionId);
Assert.assertEquals(event.getTagDefinition().getName(), tagDefinitionName);
Assert.assertEquals(event.getTagDefinition().getDescription(), tagDefinitionDescription);
Assert.assertEquals(event, event);
Assert.assertEquals(event, new DefaultControlTagDeletionEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID()));
Assert.assertTrue(event.equals(event));
Assert.assertTrue(event.equals(new DefaultControlTagDeletionEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID())));
}
use of org.killbill.billing.util.tag.TagDefinition in project killbill by killbill.
the class TestDefaultUserTagDefinitionCreationEvent method testPojo.
@Test(groups = "fast")
public void testPojo() throws Exception {
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());
Assert.assertEquals(event.getBusEventType(), BusInternalEvent.BusInternalEventType.USER_TAGDEFINITION_CREATION);
Assert.assertEquals(event.getTagDefinitionId(), tagDefinitionId);
Assert.assertEquals(event.getTagDefinition(), tagDefinition);
Assert.assertEquals(event.getTagDefinition().getId(), tagDefinitionId);
Assert.assertEquals(event.getTagDefinition().getName(), tagDefinitionName);
Assert.assertEquals(event.getTagDefinition().getDescription(), tagDefinitionDescription);
Assert.assertEquals(event, event);
Assert.assertEquals(event, new DefaultUserTagDefinitionCreationEvent(tagDefinitionId, tagDefinition, 1L, 2L, UUID.randomUUID()));
Assert.assertTrue(event.equals(event));
Assert.assertTrue(event.equals(new DefaultUserTagDefinitionCreationEvent(tagDefinitionId, tagDefinition, 1L, 2L, UUID.randomUUID())));
}
Aggregations