use of org.killbill.billing.util.tag.Tag in project killbill by killbill.
the class TestInvoiceDaoHelper method testPopulateChildrenWithTrackingIds.
@Test(groups = "slow")
public void testPopulateChildrenWithTrackingIds() throws Exception {
final UUID accountId = account.getId();
final Invoice inputInvoice = new DefaultInvoice(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD);
final InvoiceItem invoiceItem = new RecurringInvoiceItem(inputInvoice.getId(), accountId, UUID.randomUUID(), UUID.randomUUID(), "test", "test-plan", "test-phase", null, today, today, BigDecimal.TEN, BigDecimal.TEN, Currency.USD);
inputInvoice.addInvoiceItem(invoiceItem);
invoiceUtil.createInvoice(inputInvoice, internalAccountContext);
final InvoiceTrackingSqlDao trackingSqlDao = dbi.onDemand(InvoiceTrackingSqlDao.class);
trackingSqlDao.create(ImmutableList.of(new InvoiceTrackingModelDao("12345", inputInvoice.getId(), UUID.randomUUID(), "foo", today)), internalAccountContext);
final List<Tag> tags = ImmutableList.of();
final InvoiceModelDao invoice1 = getRawInvoice(inputInvoice.getId(), internalAccountContext);
populateChildrenByInvoiceId(invoice1, tags);
final InvoiceModelDao invoice2 = getRawInvoice(inputInvoice.getId(), internalAccountContext);
populateChildrenByAccountRecordId(invoice2, tags);
Assert.assertEquals(new DefaultInvoice(invoice1).getTrackingIds().size(), 1);
Assert.assertEquals(new DefaultInvoice(invoice2).getTrackingIds().size(), 1);
Assert.assertEquals(invoice1, invoice2);
}
use of org.killbill.billing.util.tag.Tag 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.Tag in project killbill by killbill.
the class OverdueStateApplicator method isAccountTaggedWith_OVERDUE_ENFORCEMENT_OFF.
//
// Uses callcontext information to retrieve account matching the Overduable object and check whether we should do any overdue processing
//
private boolean isAccountTaggedWith_OVERDUE_ENFORCEMENT_OFF(final InternalCallContext context) throws OverdueException {
try {
final UUID accountId = accountApi.getByRecordId(context.getAccountRecordId(), context);
final List<Tag> accountTags = tagApi.getTags(accountId, ObjectType.ACCOUNT, context);
for (final Tag cur : accountTags) {
if (cur.getTagDefinitionId().equals(ControlTagType.OVERDUE_ENFORCEMENT_OFF.getId())) {
return true;
}
}
return false;
} catch (final AccountApiException e) {
throw new OverdueException(e);
}
}
use of org.killbill.billing.util.tag.Tag in project killbill by killbill.
the class TestDefaultTagUserApi method testSaveTagWithAccountRecordId.
@Test(groups = "slow")
public void testSaveTagWithAccountRecordId() throws Exception {
final UUID accountId = UUID.randomUUID();
final Long accountRecordId = generateAccountRecordId(accountId);
final ImmutableAccountData immutableAccountData = Mockito.mock(ImmutableAccountData.class);
Mockito.when(immutableAccountInternalApi.getImmutableAccountDataByRecordId(Mockito.<Long>eq(accountRecordId), Mockito.<InternalTenantContext>any())).thenReturn(immutableAccountData);
checkPagination(0);
eventsListener.pushExpectedEvent(NextEvent.TAG);
tagUserApi.addTags(accountId, ObjectType.ACCOUNT, ImmutableList.<UUID>of(ControlTagType.AUTO_INVOICING_OFF.getId()), callContext);
assertListenerStatus();
checkPagination(1);
// Verify the tag was saved
final List<Tag> tags = tagUserApi.getTagsForObject(accountId, ObjectType.ACCOUNT, true, callContext);
Assert.assertEquals(tags.size(), 1);
Assert.assertEquals(tags.get(0).getTagDefinitionId(), ControlTagType.AUTO_INVOICING_OFF.getId());
Assert.assertEquals(tags.get(0).getObjectId(), accountId);
Assert.assertEquals(tags.get(0).getObjectType(), ObjectType.ACCOUNT);
// Verify the account_record_id was populated
dbi.withHandle(new HandleCallback<Void>() {
@Override
public Void withHandle(final Handle handle) throws Exception {
final List<Map<String, Object>> values = handle.select("select account_record_id from tags where object_id = ?", accountId.toString());
Assert.assertEquals(values.size(), 1);
Assert.assertEquals(values.get(0).keySet().size(), 1);
Assert.assertEquals(Long.valueOf(values.get(0).get("account_record_id").toString()), accountRecordId);
return null;
}
});
eventsListener.pushExpectedEvent(NextEvent.TAG);
tagUserApi.removeTags(accountId, ObjectType.ACCOUNT, ImmutableList.<UUID>of(ControlTagType.AUTO_INVOICING_OFF.getId()), callContext);
assertListenerStatus();
List<Tag> remainingTags = tagUserApi.getTagsForObject(accountId, ObjectType.ACCOUNT, false, callContext);
Assert.assertEquals(remainingTags.size(), 0);
checkPagination(0);
// Add again the tag
eventsListener.pushExpectedEvent(NextEvent.TAG);
tagUserApi.addTags(accountId, ObjectType.ACCOUNT, ImmutableList.<UUID>of(ControlTagType.AUTO_INVOICING_OFF.getId()), callContext);
assertListenerStatus();
remainingTags = tagUserApi.getTagsForObject(accountId, ObjectType.ACCOUNT, false, callContext);
Assert.assertEquals(remainingTags.size(), 1);
checkPagination(1);
// Delete again
eventsListener.pushExpectedEvent(NextEvent.TAG);
tagUserApi.removeTags(accountId, ObjectType.ACCOUNT, ImmutableList.<UUID>of(ControlTagType.AUTO_INVOICING_OFF.getId()), callContext);
assertListenerStatus();
remainingTags = tagUserApi.getTagsForObject(accountId, ObjectType.ACCOUNT, false, callContext);
Assert.assertEquals(remainingTags.size(), 0);
checkPagination(0);
}
Aggregations