@Override public List<Usage> apply(final BillingEvent input) { return input.getUsages(); } }));
private List<Usage> findUsageInArrearUsages(final BillingEvent event) { if (event.getUsages().isEmpty()) { return Collections.emptyList(); } final List<Usage> result = Lists.newArrayList(); for (final Usage usage : event.getUsages()) { if (usage.getBillingMode() != BillingMode.IN_ARREAR) { continue; } result.add(usage); } return result; }
private Integer computeAccountBCD(final BillingEventSet result) throws CatalogApiException { BillingEvent oldestAccountAlignedBillingEvent = null; for (final BillingEvent event : result) { if (event.getBillingAlignment() != BillingAlignment.ACCOUNT) { continue; } final BigDecimal recurringPrice = event.getRecurringPrice(event.getEffectiveDate()); final boolean hasRecurringPrice = recurringPrice != null; // Note: could be zero (BCD would still be set, by convention) final boolean hasUsage = event.getUsages() != null && !event.getUsages().isEmpty(); if (!hasRecurringPrice && !hasUsage) { // Nothing to bill, ignored for the purpose of BCD calculation continue; } if (oldestAccountAlignedBillingEvent == null || event.getEffectiveDate().compareTo(oldestAccountAlignedBillingEvent.getEffectiveDate()) < 0 || (event.getEffectiveDate().compareTo(oldestAccountAlignedBillingEvent.getEffectiveDate()) == 0 && event.getTotalOrdering().compareTo(oldestAccountAlignedBillingEvent.getTotalOrdering()) < 0)) { oldestAccountAlignedBillingEvent = event; } } if (oldestAccountAlignedBillingEvent == null) { return null; } // BCD in the account timezone final int accountBCDCandidate = oldestAccountAlignedBillingEvent.getBillCycleDayLocal(); Preconditions.checkState(accountBCDCandidate > 0, "Wrong Account BCD calculation for event: " + oldestAccountAlignedBillingEvent); return accountBCDCandidate; }
protected BillingEvent createMockBillingEvent(final int bcd, final DateTime effectiveDate, final BillingPeriod billingPeriod, final List<Usage> usages) { final BillingEvent result = Mockito.mock(BillingEvent.class); Mockito.when(result.getCurrency()).thenReturn(Currency.BTC); Mockito.when(result.getBillCycleDayLocal()).thenReturn(bcd); Mockito.when(result.getEffectiveDate()).thenReturn(effectiveDate); Mockito.when(result.getBillingPeriod()).thenReturn(billingPeriod); final Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(accountId); final SubscriptionBase subscription = Mockito.mock(SubscriptionBase.class); Mockito.when(subscription.getId()).thenReturn(subscriptionId); Mockito.when(subscription.getBundleId()).thenReturn(bundleId); Mockito.when(result.getSubscription()).thenReturn(subscription); final Product product = Mockito.mock(Product.class); Mockito.when(product.getName()).thenReturn(productName); final Plan plan = Mockito.mock(Plan.class); Mockito.when(plan.getName()).thenReturn(planName); Mockito.when(plan.getProduct()).thenReturn(product); Mockito.when(result.getPlan()).thenReturn(plan); final PlanPhase phase = Mockito.mock(PlanPhase.class); Mockito.when(phase.getName()).thenReturn(phaseName); Mockito.when(result.getPlanPhase()).thenReturn(phase); Mockito.when(result.getUsages()).thenReturn(usages); return result; }
Iterables.any(event.getUsages(), new Predicate<Usage>() { @Override public boolean apply(@Nullable final Usage input) {