Search in sources :

Example 21 with TagDefinition

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();
}
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 22 with TagDefinition

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);
}
Also used : TagDefinition(org.killbill.billing.util.tag.TagDefinition) TimedResource(org.killbill.commons.metrics.TimedResource) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 23 with TagDefinition

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())));
}
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) Test(org.testng.annotations.Test)

Example 24 with TagDefinition

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())));
}
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) Test(org.testng.annotations.Test)

Example 25 with TagDefinition

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())));
}
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) Test(org.testng.annotations.Test)

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