@Override public int hashCode() { int result = getAccountRecordId() != null ? getAccountRecordId().hashCode() : 0; result = 31 * result + (getTenantRecordId() != null ? getTenantRecordId().hashCode() : 0); return result; } }
public static LocalDate alignProposedBillCycleDate(final DateTime proposedDate, final int billingCycleDay, final BillingPeriod billingPeriod, final InternalTenantContext internalTenantContext) { final LocalDate proposedLocalDate = internalTenantContext.toLocalDate(proposedDate); final LocalDate resultingLocalDate = alignProposedBillCycleDate(proposedLocalDate, billingCycleDay, billingPeriod); return resultingLocalDate; }
@Override public Object compute(final String key, final CacheLoaderArgument cacheLoaderArgument) { final String[] parts = key.split(CacheControllerDispatcher.CACHE_KEY_SEPARATOR); final String rawKey = parts[0]; final Matcher matcher = PATTERN.matcher(rawKey); if (!matcher.matches()) { throw new IllegalArgumentException("Unexpected key " + rawKey); } final String pluginName = matcher.group(1); final String tenantRecordId = parts[1]; final LoaderCallback callback = (LoaderCallback) cacheLoaderArgument.getArgs()[0]; final InternalTenantContext internalTenantContext = new InternalTenantContext(Long.valueOf(tenantRecordId)); final String stateMachineConfigXML = tenantApi.getPluginPaymentStateMachineConfig(pluginName, internalTenantContext); if (stateMachineConfigXML == null) { return null; } try { log.info("Loading config state machine cache for pluginName='{}', tenantRecordId='{}'", pluginName, internalTenantContext.getTenantRecordId()); return callback.loadStateMachineConfig(stateMachineConfigXML); } catch (final PaymentApiException e) { throw new IllegalStateException(String.format("Failed to de-serialize state machine config for tenantRecordId='%s'", internalTenantContext.getTenantRecordId()), e); } }
private DateTime getDryRunEffectiveDate(@Nullable final LocalDate inputDate, final SubscriptionBase subscription, final InternalTenantContext context) { if (inputDate == null) { return null; } // We first use context account reference time to get a candidate) final DateTime tmp = context.toUTCDateTime(inputDate); // If we realize that the candidate is on the same LocalDate boundary as the subscription startDate but a bit prior we correct it to avoid weird things down the line if (inputDate.compareTo(context.toLocalDate(subscription.getStartDate())) == 0 && tmp.compareTo(subscription.getStartDate()) < 0) { return subscription.getStartDate(); } else { return tmp; } }
private UUID getAccountIdSafe(final InternalTenantContext context) { return context.getAccountRecordId() != null ? nonEntityDao.retrieveIdFromObject(context.getAccountRecordId(), ObjectType.ACCOUNT, objectIdCacheController) : null; }
@Override public void clearCatalog(final InternalTenantContext tenantContext) { if (!InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID.equals(tenantContext.getTenantRecordId())) { cacheController.remove(tenantContext.getTenantRecordId()); } }
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); }
private ImmutableAccountData getImmutableAccountData(final Long accountRecordId, final Long tenantRecordId) { Preconditions.checkNotNull(accountRecordId, "Missing accountRecordId"); final InternalTenantContext tmp = new InternalTenantContext(tenantRecordId, accountRecordId, null, null); try { final ImmutableAccountData immutableAccountData = accountInternalApi.getImmutableAccountDataByRecordId(accountRecordId, tmp); Preconditions.checkNotNull(immutableAccountData, "Unable to retrieve immutableAccountData"); return immutableAccountData; } catch (final AccountApiException e) { throw new RuntimeException(e); } }
candidateResult = context.toUTCDateTime(resultingLocalDate);
@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; }
@Override public void clearOverdueConfig(final InternalTenantContext tenantContext) { if (!InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID.equals(tenantContext.getTenantRecordId())) { cacheController.remove(tenantContext.getTenantRecordId()); } }
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); }
private DateTime getDryRunEffectiveDate(@Nullable final LocalDate inputDate, final SubscriptionBase subscription, final InternalTenantContext context) { if (inputDate == null) { return null; } // We first use context account reference time to get a candidate) final DateTime tmp = context.toUTCDateTime(inputDate); // If we realize that the candidate is on the same LocalDate boundary as the subscription startDate but a bit prior we correct it to avoid weird things down the line if (inputDate.compareTo(context.toLocalDate(subscription.getStartDate())) == 0 && tmp.compareTo(subscription.getStartDate()) < 0) { return subscription.getStartDate(); } else { return tmp; } }
@Override public String compute(final String key, final CacheLoaderArgument cacheLoaderArgument) { final String[] parts = key.split(CacheControllerDispatcher.CACHE_KEY_SEPARATOR); final String rawKey = parts[0]; final String tenantRecordId = parts[1]; final InternalTenantContext internalTenantContext = new InternalTenantContext(Long.valueOf(tenantRecordId)); final List<String> valuesForKey = tenantApi.getTenantValuesForKey(rawKey, internalTenantContext); if (valuesForKey == null || valuesForKey.isEmpty()) { return EMPTY_VALUE_PLACEHOLDER; } if (valuesForKey.size() > 1) { throw new IllegalStateException("TenantKVCacheLoader expecting no more than one value for key " + key); } return valuesForKey.get(0); } }
case START_BILLING: final SubscriptionBase baseSubscription = dao.getBaseSubscription(bundleId, catalog, context); final DateTime startEffectiveDate = dryRunArguments.getEffectiveDate() != null ? context.toUTCDateTime(dryRunArguments.getEffectiveDate()) : utcNow; final DateTime bundleStartDate = getBundleStartDateWithSanity(bundleId, baseSubscription, plan, startEffectiveDate, addonUtils, context); final UUID subscriptionId = UUIDs.randomUUID();
@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; }
public void addAccountRecordIdMapping(final UUID objectId, final InternalTenantContext context) { accountRecordIdMappings.put(objectId, context.getAccountRecordId()); }
private String getCacheKeyName(final String key, final InternalTenantContext internalContext) { final StringBuilder tenantKey = new StringBuilder(key); tenantKey.append(CacheControllerDispatcher.CACHE_KEY_SEPARATOR); tenantKey.append(internalContext.getTenantRecordId()); return tenantKey.toString(); }
@Override public Catalog compute(final Long key, final CacheLoaderArgument cacheLoaderArgument) { final Long tenantRecordId = key; final InternalTenantContext internalTenantContext = new InternalTenantContext(tenantRecordId); if (cacheLoaderArgument.getArgs() == null || !(cacheLoaderArgument.getArgs()[0] instanceof LoaderCallback)) { throw new IllegalArgumentException("Missing LoaderCallback from the arguments "); } final LoaderCallback callback = (LoaderCallback) cacheLoaderArgument.getArgs()[0]; final List<String> catalogXMLs = tenantApi.getTenantCatalogs(internalTenantContext); if (catalogXMLs.isEmpty()) { return null; } try { log.info("Loading catalog cache for tenantRecordId='{}'", internalTenantContext.getTenantRecordId()); return callback.loadCatalog(catalogXMLs, tenantRecordId); } catch (final CatalogApiException e) { throw new IllegalStateException(String.format("Failed to de-serialize catalog for tenantRecordId='%s'", internalTenantContext.getTenantRecordId()), e); } }
private static int calculateBcdFromSubscription(final SubscriptionBase subscription, final InternalTenantContext internalTenantContext) { final DateTime date = subscription.getDateOfFirstRecurringNonZeroCharge(); final int bcdLocal = internalTenantContext.toLocalDate(date).getDayOfMonth(); log.debug("Calculated BCD: subscriptionId='{}', subscriptionStartDate='{}', bcd='{}'", subscription.getId(), date.toDateTimeISO(), bcdLocal); return bcdLocal; } }