private UUID getAccountIdSafe(final InternalTenantContext context) { return context.getAccountRecordId() != null ? nonEntityDao.retrieveIdFromObject(context.getAccountRecordId(), ObjectType.ACCOUNT, objectIdCacheController) : null; }
@Override public int hashCode() { int result = getAccountRecordId() != null ? getAccountRecordId().hashCode() : 0; result = 31 * result + (getTenantRecordId() != null ? getTenantRecordId().hashCode() : 0); return result; } }
@Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("InternalTenantContext"); sb.append("{accountRecordId=").append(getAccountRecordId()); sb.append(", tenantRecordId=").append(getTenantRecordId()); sb.append('}'); return sb.toString(); }
@Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } final InternalTenantContext that = (InternalTenantContext) o; if (getAccountRecordId() != null ? !getAccountRecordId().equals(that.getAccountRecordId()) : that.getAccountRecordId() != null) { return false; } if (getTenantRecordId() != null ? !getTenantRecordId().equals(that.getTenantRecordId()) : that.getTenantRecordId() != null) { return false; } return true; }
@Override public int getBCD(final InternalTenantContext context) throws AccountApiException { final CacheLoaderArgument arg = createBCDCacheLoaderArgument(context); Preconditions.checkNotNull(context.getAccountRecordId(), "Context missing accountRecordId"); final ImmutableAccountData account = immutableAccountInternalApi.getImmutableAccountDataByRecordId(context.getAccountRecordId(), context); final Integer result = bcdCacheController.get(account.getId(), arg); return result != null ? result : DefaultMutableAccountData.DEFAULT_BILLING_CYCLE_DAY_LOCAL; }
public void addAccountRecordIdMapping(final UUID objectId, final InternalTenantContext context) { accountRecordIdMappings.put(objectId, context.getAccountRecordId()); }
@Override @Nullable public EffectiveSubscriptionInternalEvent apply(@Nullable final SubscriptionBaseTransition input) { return new DefaultEffectiveSubscriptionEvent((SubscriptionBaseTransitionData) input, ((DefaultSubscriptionBase) subscription).getAlignStartDate(), null, context.getAccountRecordId(), context.getTenantRecordId()); } }));
@Override public List<TagModelDao> getTagsForAccount(final boolean includedDeleted, final InternalTenantContext internalTenantContext) { if (tagStore.get(getAccountId(internalTenantContext.getAccountRecordId())) == null) { return ImmutableList.<TagModelDao>of(); } return tagStore.get(getAccountId(internalTenantContext.getAccountRecordId())); }
public void exportDataForAccount(final DatabaseExportOutputStream out, final InternalTenantContext context) { if (context.getAccountRecordId() == null || context.getTenantRecordId() == null) { return; } final List<DefaultColumnInfo> columns = databaseSchemaDao.getColumnInfoList(); if (columns.size() == 0) { return; } final List<ColumnInfo> columnsForTable = new ArrayList<ColumnInfo>(); // The list of columns is ordered by table name first String lastSeenTableName = columns.get(0).getTableName(); for (final ColumnInfo column : columns) { if (!column.getTableName().equals(lastSeenTableName)) { exportDataForAccountAndTable(out, columnsForTable, context); lastSeenTableName = column.getTableName(); columnsForTable.clear(); } columnsForTable.add(column); } exportDataForAccountAndTable(out, columnsForTable, context); }
@Override public Void withHandle(final Handle handle) throws Exception { final ResultIterator<Map<String, Object>> iterator = handle.createQuery(queryBuilder.toString()) .bind("accountRecordId", context.getAccountRecordId()) .bind("tenantRecordId", context.getTenantRecordId()) .iterator();
@BeforeMethod(groups = "fast") public void beforeMethod() throws Exception { if (hasFailed()) { return; } super.beforeMethod(); cacheControllerDispatcher.clearAll(); multiTenantContext = Mockito.mock(InternalTenantContext.class); Mockito.when(multiTenantContext.getAccountRecordId()).thenReturn(456L); Mockito.when(multiTenantContext.getTenantRecordId()).thenReturn(99L); otherMultiTenantContext = Mockito.mock(InternalCallContext.class); Mockito.when(otherMultiTenantContext.getAccountRecordId()).thenReturn(123L); Mockito.when(otherMultiTenantContext.getTenantRecordId()).thenReturn(112233L); }
@BeforeMethod(groups = "fast") protected void beforeMethod() throws Exception { if (hasFailed()) { return; } cacheControllerDispatcher.clearAll(); multiTenantContext = Mockito.mock(InternalTenantContext.class); Mockito.when(multiTenantContext.getAccountRecordId()).thenReturn(456L); Mockito.when(multiTenantContext.getTenantRecordId()).thenReturn(99L); otherMultiTenantContext = Mockito.mock(InternalCallContext.class); Mockito.when(otherMultiTenantContext.getAccountRecordId()).thenReturn(123L); Mockito.when(otherMultiTenantContext.getTenantRecordId()).thenReturn(112233L); ((DefaultCatalogCache) catalogCache).setDefaultCatalog(); }
public BillingState billingState(final InternalCallContext context) throws OverdueException { if ((overdueable.getParentAccountId() != null) && (overdueable.isPaymentDelegatedToParent())) { // calculate billing state from parent account final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(overdueable.getParentAccountId(), context); final InternalCallContext parentAccountContext = internalCallContextFactory.createInternalCallContext(internalTenantContext.getAccountRecordId(), context); return billingStateCalcuator.calculateBillingState(overdueable, parentAccountContext); } return billingStateCalcuator.calculateBillingState(overdueable, context); } }
@Override public DefaultAccountAuditLogs getAuditLogsForAccountRecordId(final AuditLevel auditLevel, final InternalTenantContext context) { final UUID accountId = dbRouter.onDemand(true).getIdFromObject(context.getAccountRecordId(), TableName.ACCOUNT.getTableName()); // Lazy evaluate records to minimize the memory footprint (these can yield a lot of results) // We usually always want to wrap our queries in an EntitySqlDaoTransactionWrapper... except here. // Since we want to stream the results out, we don't want to auto-commit when this method returns. final EntitySqlDao auditSqlDao = transactionalSqlDao.onDemandForStreamingResults(EntitySqlDao.class); final Iterator<AuditLogModelDao> auditLogsForAccountRecordId = auditSqlDao.getAuditLogsForAccountRecordId(context); final Iterator<AuditLog> allAuditLogs = buildAuditLogsFromModelDao(auditLogsForAccountRecordId, context); return new DefaultAccountAuditLogs(accountId, auditLevel, allAuditLogs); }
Preconditions.checkState(tenantContext.getAccountRecordId() != null, "Unexpected null accountRecordId in context issued from internal Kill Bill service");
if (account.getParentAccountId() != null && account.isPaymentDelegatedToParent()) { final InternalTenantContext parentAccountInternalTenantContext = internalCallContextFactory.createInternalTenantContext(account.getParentAccountId(), callContext); final InternalCallContext parentAccountContext = internalCallContextFactory.createInternalCallContext(parentAccountInternalTenantContext.getAccountRecordId(), callContext); notificationKey = new OverdueAsyncBusNotificationKey(account.getParentAccountId(), action); asyncPoster.insertOverdueNotification(account.getParentAccountId(), callContext.getCreatedDate(), OverdueAsyncBusNotifier.OVERDUE_ASYNC_BUS_NOTIFIER_QUEUE, notificationKey, parentAccountContext); if (childAccount.isPaymentDelegatedToParent()) { final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(childAccount.getId(), callContext); final InternalCallContext accountContext = internalCallContextFactory.createInternalCallContext(internalTenantContext.getAccountRecordId(), callContext); notificationKey = new OverdueAsyncBusNotificationKey(childAccount.getId(), action); asyncPoster.insertOverdueNotification(childAccount.getId(), callContext.getCreatedDate(), OverdueAsyncBusNotifier.OVERDUE_ASYNC_BUS_NOTIFIER_QUEUE, notificationKey, accountContext);
public static void refreshCallContext(final UUID accountId, final Clock clock, final InternalCallContextFactory internalCallContextFactory, final MutableCallContext callContext, final MutableInternalCallContext internalCallContext) { final InternalTenantContext tmp = internalCallContextFactory.createInternalTenantContext(accountId, callContext); internalCallContext.setAccountRecordId(tmp.getAccountRecordId()); internalCallContext.setFixedOffsetTimeZone(tmp.getFixedOffsetTimeZone()); internalCallContext.setReferenceTime(tmp.getReferenceLocalTime()); internalCallContext.setCreatedDate(clock.getUTCNow()); internalCallContext.setUpdatedDate(clock.getUTCNow()); callContext.setDelegate(accountId, internalCallContext); }
@Override @Nullable public EffectiveSubscriptionInternalEvent apply(@Nullable final SubscriptionBaseTransition input) { return new DefaultEffectiveSubscriptionEvent((SubscriptionBaseTransitionData) input, ((DefaultSubscriptionBase) subscription).getAlignStartDate(), null, context.getAccountRecordId(), context.getTenantRecordId()); } }));
@Override public List<TagModelDao> getTagsForAccount(final boolean includedDeleted, final InternalTenantContext internalTenantContext) { if (tagStore.get(getAccountId(internalTenantContext.getAccountRecordId())) == null) { return ImmutableList.<TagModelDao>of(); } return tagStore.get(getAccountId(internalTenantContext.getAccountRecordId())); }
public BillingState billingState(final InternalCallContext context) throws OverdueException { if ((overdueable.getParentAccountId() != null) && (overdueable.isPaymentDelegatedToParent())) { // calculate billing state from parent account final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(overdueable.getParentAccountId(), context); final InternalCallContext parentAccountContext = internalCallContextFactory.createInternalCallContext(internalTenantContext.getAccountRecordId(), context); return billingStateCalcuator.calculateBillingState(overdueable, parentAccountContext); } return billingStateCalcuator.calculateBillingState(overdueable, context); } }