use of org.killbill.billing.account.api.ImmutableAccountData in project killbill by killbill.
the class CompletionTaskBase method tryToDoJanitorOperationWithAccountLock.
protected <T> T tryToDoJanitorOperationWithAccountLock(final JanitorIterationCallback callback, final InternalTenantContext internalTenantContext) throws LockFailedException {
GlobalLock lock = null;
try {
final ImmutableAccountData account = accountInternalApi.getImmutableAccountDataByRecordId(internalTenantContext.getAccountRecordId(), internalTenantContext);
lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), account.getId().toString(), paymentConfig.getMaxGlobalLockRetries());
return callback.doIteration();
} catch (final AccountApiException e) {
log.warn("Error retrieving accountRecordId='{}'", internalTenantContext.getAccountRecordId(), e);
} finally {
if (lock != null) {
lock.release();
}
}
return null;
}
use of org.killbill.billing.account.api.ImmutableAccountData in project killbill by killbill.
the class TestOverdueStateApplicator method testApplicator.
@Test(groups = "slow")
public void testApplicator() throws Exception {
final InputStream is = new ByteArrayInputStream(testOverdueHelper.getConfigXml().getBytes());
final DefaultOverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, DefaultOverdueConfig.class);
final ImmutableAccountData account = Mockito.mock(ImmutableAccountData.class);
Mockito.when(account.getId()).thenReturn(UUID.randomUUID());
final OverdueStateSet overdueStateSet = config.getOverdueStatesAccount();
final OverdueState clearState = config.getOverdueStatesAccount().findState(OverdueWrapper.CLEAR_STATE_NAME);
OverdueState state;
state = config.getOverdueStatesAccount().findState("OD1");
applicator.apply(clock.getUTCNow(), overdueStateSet, null, account, clearState, state, internalCallContext);
testOverdueHelper.checkStateApplied(state);
checkBussEvent("OD1");
state = config.getOverdueStatesAccount().findState("OD2");
applicator.apply(clock.getUTCNow(), overdueStateSet, null, account, clearState, state, internalCallContext);
testOverdueHelper.checkStateApplied(state);
checkBussEvent("OD2");
state = config.getOverdueStatesAccount().findState("OD3");
applicator.apply(clock.getUTCNow(), overdueStateSet, null, account, clearState, state, internalCallContext);
testOverdueHelper.checkStateApplied(state);
checkBussEvent("OD3");
}
use of org.killbill.billing.account.api.ImmutableAccountData in project killbill by killbill.
the class TestBillingStateCalculator method createBSCalc.
public BillingStateCalculator createBSCalc() {
now = new LocalDate();
final Collection<Invoice> invoices = new ArrayList<Invoice>();
invoices.add(createInvoice(now, BigDecimal.ZERO, null));
invoices.add(createInvoice(now.plusDays(1), BigDecimal.TEN, null));
invoices.add(createInvoice(now.plusDays(2), new BigDecimal("100.0"), null));
Mockito.when(invoiceApi.getUnpaidInvoicesByAccountId(Mockito.<UUID>any(), Mockito.<LocalDate>any(), Mockito.<InternalTenantContext>any())).thenReturn(invoices);
return new BillingStateCalculator(invoiceApi, clock, tagInternalApi) {
@Override
public BillingState calculateBillingState(final ImmutableAccountData overdueable, final InternalTenantContext context) {
return null;
}
};
}
use of org.killbill.billing.account.api.ImmutableAccountData in project killbill by killbill.
the class DefaultSubscriptionApi method getBlockingStates.
@Override
public Iterable<BlockingState> getBlockingStates(final UUID accountId, @Nullable final List<BlockingStateType> typeFilter, @Nullable final List<String> svcsFilter, final OrderingType orderingType, final int timeFilter, final TenantContext tenantContext) throws EntitlementApiException {
try {
final InternalTenantContext internalTenantContextWithValidAccountRecordId = internalCallContextFactory.createInternalTenantContext(accountId, tenantContext);
final List<BlockingState> allBlockingStates = blockingStateDao.getBlockingAllForAccountRecordId(internalTenantContextWithValidAccountRecordId);
final ImmutableAccountData account = accountApi.getImmutableAccountDataById(accountId, internalTenantContextWithValidAccountRecordId);
final Iterable<BlockingState> filteredByTypes = typeFilter != null && !typeFilter.isEmpty() ? Iterables.filter(allBlockingStates, new Predicate<BlockingState>() {
@Override
public boolean apply(final BlockingState input) {
return typeFilter.contains(input.getType());
}
}) : allBlockingStates;
final Iterable<BlockingState> filteredByTypesAndSvcs = svcsFilter != null && !svcsFilter.isEmpty() ? Iterables.filter(filteredByTypes, new Predicate<BlockingState>() {
@Override
public boolean apply(final BlockingState input) {
return svcsFilter.contains(input.getService());
}
}) : filteredByTypes;
final LocalDate localDateNowInAccountTimezone = new LocalDate(clock.getUTCNow(), account.getTimeZone());
final List<BlockingState> result = new ArrayList<BlockingState>();
for (final BlockingState cur : filteredByTypesAndSvcs) {
final LocalDate eventDate = new LocalDate(cur.getEffectiveDate(), account.getTimeZone());
final int comp = eventDate.compareTo(localDateNowInAccountTimezone);
if ((comp <= 1 && ((timeFilter & SubscriptionApi.PAST_EVENTS) == SubscriptionApi.PAST_EVENTS)) || (comp == 0 && ((timeFilter & SubscriptionApi.PRESENT_EVENTS) == SubscriptionApi.PRESENT_EVENTS)) || (comp >= 1 && ((timeFilter & SubscriptionApi.FUTURE_EVENTS) == SubscriptionApi.FUTURE_EVENTS))) {
result.add(cur);
}
}
return orderingType == OrderingType.ASCENDING ? result : Lists.reverse(result);
} catch (AccountApiException e) {
throw new EntitlementApiException(e);
}
}
use of org.killbill.billing.account.api.ImmutableAccountData in project killbill by killbill.
the class DefaultSubscriptionApi method updateExternalKey.
@Override
public void updateExternalKey(final UUID bundleId, final String newExternalKey, final CallContext callContext) throws EntitlementApiException {
logUpdateExternalKey(log, bundleId, newExternalKey);
final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(callContext);
final SubscriptionBaseBundle bundle;
final ImmutableAccountData account;
try {
bundle = subscriptionBaseInternalApi.getBundleFromId(bundleId, internalCallContext);
account = accountApi.getImmutableAccountDataById(bundle.getAccountId(), internalCallContext);
} catch (final SubscriptionBaseApiException e) {
throw new EntitlementApiException(e);
} catch (AccountApiException e) {
throw new EntitlementApiException(e);
}
final LocalDate effectiveDate = new LocalDate(clock.getUTCNow(), account.getTimeZone());
final BaseEntitlementWithAddOnsSpecifier baseEntitlementWithAddOnsSpecifier = new DefaultBaseEntitlementWithAddOnsSpecifier(bundleId, newExternalKey, new ArrayList<EntitlementSpecifier>(), effectiveDate, effectiveDate, false);
final List<BaseEntitlementWithAddOnsSpecifier> baseEntitlementWithAddOnsSpecifierList = new ArrayList<BaseEntitlementWithAddOnsSpecifier>();
baseEntitlementWithAddOnsSpecifierList.add(baseEntitlementWithAddOnsSpecifier);
final EntitlementContext pluginContext = new DefaultEntitlementContext(OperationType.UPDATE_BUNDLE_EXTERNAL_KEY, bundle.getAccountId(), null, baseEntitlementWithAddOnsSpecifierList, null, ImmutableList.<PluginProperty>of(), callContext);
final WithEntitlementPlugin<Void> updateExternalKeyWithPlugin = new WithEntitlementPlugin<Void>() {
final InternalCallContext internalCallContextWithValidAccountId = internalCallContextFactory.createInternalCallContext(account.getId(), callContext);
@Override
public Void doCall(final EntitlementApi entitlementApi, final EntitlementContext updatedPluginContext) throws EntitlementApiException {
subscriptionBaseInternalApi.updateExternalKey(bundleId, newExternalKey, internalCallContextWithValidAccountId);
return null;
}
};
pluginExecution.executeWithPlugin(updateExternalKeyWithPlugin, pluginContext);
}
Aggregations