use of org.killbill.billing.util.tag.Tag in project killbill by killbill.
the class AccountResource method getAllTags.
@TimedResource
@GET
@Path("/{accountId:" + UUID_PATTERN + "}/" + ALL_TAGS)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve account tags", response = TagJson.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found") })
public Response getAllTags(@PathParam(ID_PARAM_NAME) final String accountIdString, @QueryParam(QUERY_OBJECT_TYPE) final ObjectType objectType, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @QueryParam(QUERY_INCLUDED_DELETED) @DefaultValue("false") final Boolean includedDeleted, @javax.ws.rs.core.Context final HttpServletRequest request) throws TagDefinitionApiException {
final UUID accountId = UUID.fromString(accountIdString);
final TenantContext tenantContext = context.createContext(request);
final List<Tag> tags = objectType != null ? tagUserApi.getTagsForAccountType(accountId, objectType, includedDeleted, tenantContext) : tagUserApi.getTagsForAccount(accountId, includedDeleted, tenantContext);
return createTagResponse(accountId, tags, auditMode, tenantContext);
}
use of org.killbill.billing.util.tag.Tag in project killbill by killbill.
the class DefaultInternalBillingApi method getBillingEventsForAccountAndUpdateAccountBCD.
@Override
public BillingEventSet getBillingEventsForAccountAndUpdateAccountBCD(final UUID accountId, final DryRunArguments dryRunArguments, final InternalCallContext context) throws CatalogApiException, AccountApiException, SubscriptionBaseApiException {
final StaticCatalog currentCatalog = catalogService.getCurrentCatalog(true, true, context);
// Check to see if billing is off for the account
final List<Tag> accountTags = tagApi.getTags(accountId, ObjectType.ACCOUNT, context);
final boolean found_AUTO_INVOICING_OFF = is_AUTO_INVOICING_OFF(accountTags);
final Set<UUID> skippedSubscriptions = new HashSet<UUID>();
final DefaultBillingEventSet result;
if (found_AUTO_INVOICING_OFF) {
// billing is off, we are done
result = new DefaultBillingEventSet(true, currentCatalog.getRecurringBillingMode());
} else {
final List<SubscriptionBaseBundle> bundles = subscriptionApi.getBundlesForAccount(accountId, context);
final ImmutableAccountData account = accountApi.getImmutableAccountDataById(accountId, context);
result = new DefaultBillingEventSet(false, currentCatalog.getRecurringBillingMode());
addBillingEventsForBundles(bundles, account, dryRunArguments, context, result, skippedSubscriptions);
}
if (result.isEmpty()) {
log.info("No billing event for accountId='{}'", accountId);
return result;
}
// Pretty-print the events, before and after the blocking calculator does its magic
final StringBuilder logStringBuilder = new StringBuilder("Computed billing events for accountId='").append(accountId).append("'");
eventsToString(logStringBuilder, result);
if (blockCalculator.insertBlockingEvents(result, skippedSubscriptions, context)) {
logStringBuilder.append("\nBilling Events After Blocking");
eventsToString(logStringBuilder, result);
}
log.info(logStringBuilder.toString());
return result;
}
use of org.killbill.billing.util.tag.Tag in project killbill by killbill.
the class TestInvoiceDaoHelper method testPopulateChildrenWithPayments.
@Test(groups = "slow")
public void testPopulateChildrenWithPayments() 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 InvoicePayment payment = new DefaultInvoicePayment(InvoicePaymentType.ATTEMPT, UUID.randomUUID(), inputInvoice.getId(), new DateTime(), BigDecimal.TEN, Currency.USD, Currency.USD, null, true);
invoiceUtil.createPayment(payment, 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).getBalance().compareTo(BigDecimal.ZERO), 0);
Assert.assertEquals(new DefaultInvoice(invoice1).getPaidAmount().compareTo(BigDecimal.TEN), 0);
Assert.assertEquals(new DefaultInvoice(invoice2).getBalance().compareTo(BigDecimal.ZERO), 0);
Assert.assertEquals(new DefaultInvoice(invoice2).getPaidAmount().compareTo(BigDecimal.TEN), 0);
Assert.assertEquals(invoice1, invoice2);
}
use of org.killbill.billing.util.tag.Tag in project killbill by killbill.
the class TestInvoiceDaoHelper method testPopulateChildrenSimple.
@Test(groups = "slow")
public void testPopulateChildrenSimple() 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 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(invoice1, invoice2);
}
use of org.killbill.billing.util.tag.Tag in project killbill by killbill.
the class TestOverdueHelper method createAccount.
public Account createAccount(final LocalDate dateOfLastUnPaidInvoice) throws SubscriptionBaseApiException, AccountApiException {
final UUID accountId = UUID.randomUUID();
final Account account = Mockito.mock(Account.class);
Mockito.when(account.getId()).thenReturn(accountId);
Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.UTC);
Mockito.when(accountInternalApi.getAccountById(Mockito.eq(account.getId()), Mockito.<InternalTenantContext>any())).thenReturn(account);
final Invoice invoice = Mockito.mock(Invoice.class);
Mockito.when(invoice.getInvoiceDate()).thenReturn(dateOfLastUnPaidInvoice);
Mockito.when(invoice.getBalance()).thenReturn(BigDecimal.TEN);
Mockito.when(invoice.getStatus()).thenReturn(InvoiceStatus.COMMITTED);
Mockito.when(invoice.getId()).thenReturn(UUID.randomUUID());
final InvoiceItem item = Mockito.mock(InvoiceItem.class);
final List<InvoiceItem> items = new ArrayList<InvoiceItem>();
items.add(item);
Mockito.when(invoice.getInvoiceItems()).thenReturn(items);
final List<Invoice> invoices = new ArrayList<Invoice>();
invoices.add(invoice);
Mockito.when(invoiceInternalApi.getUnpaidInvoicesByAccountId(Mockito.<UUID>any(), Mockito.<LocalDate>any(), Mockito.<InternalTenantContext>any())).thenReturn(invoices);
final Tag tag = Mockito.mock(Tag.class);
Mockito.when(tag.getObjectId()).thenReturn(accountId);
Mockito.when(tag.getObjectType()).thenReturn(ObjectType.ACCOUNT);
Mockito.when(tag.getTagDefinitionId()).thenReturn(ControlTagType.TEST.getId());
final List<Tag> tags = new ArrayList<Tag>();
tags.add(tag);
Mockito.when(tagInternalApi.getTags(Mockito.eq(account.getId()), Mockito.eq(ObjectType.ACCOUNT), Mockito.<InternalTenantContext>any())).thenReturn(tags);
return account;
}
Aggregations