Refine search
/** * Create an internal call callcontext using an existing account to retrieve tenant and account record ids * <p/> * This is used for r/w operations - we need the account id to populate the account_record_id field * * @param accountId account id * @param context original call callcontext * @return internal call callcontext */ public InternalCallContext createInternalCallContext(final UUID accountId, final CallContext context) { return createInternalCallContext(accountId, ObjectType.ACCOUNT, context); }
private InternalTenantContext createTenantContextFromBundleId(final UUID bundleId, final TenantContext context) { return internalCallContextFactory.createInternalTenantContext(bundleId, ObjectType.BUNDLE, context); } }
@Override public List<AccountEmail> getEmails(final UUID accountId, final TenantContext context) { return ImmutableList.<AccountEmail>copyOf(Collections2.transform(accountDao.getEmailsByAccountId(accountId, internalCallContextFactory.createInternalTenantContextWithoutAccountRecordId(context)), new Function<AccountEmailModelDao, AccountEmail>() { @Override public AccountEmail apply(final AccountEmailModelDao input) { return new DefaultAccountEmail(input); } })); }
public InternalCallContext createInternalCallContext(final UUID objectId, final ObjectType objectType, final String userName, final CallOrigin callOrigin, final UserType userType, @Nullable final UUID userToken, final Long tenantRecordId) { final Long accountRecordId = getAccountRecordIdSafe(objectId, objectType, tenantRecordId); return createInternalCallContext(tenantRecordId, accountRecordId, userName, callOrigin, userType, userToken, null, null, null, null); }
public InternalTenantContext createInternalTenantContext(final UUID accountId, final InternalTenantContext context) { final Long tenantRecordId = context.getTenantRecordId(); final Long accountRecordId = getAccountRecordIdSafe(accountId, ObjectType.ACCOUNT, context.getTenantRecordId()); return createInternalTenantContext(tenantRecordId, accountRecordId); }
@Override public void handleReadyNotification(final NotificationEvent inputKey, final DateTime eventDateTime, final UUID fromNotificationQueueUserToken, final Long accountRecordId, final Long tenantRecordId) { if (!(inputKey instanceof SubscriptionNotificationKey)) { log.error("SubscriptionBase service received an unexpected event className='{}'", inputKey.getClass().getName()); return; } final SubscriptionNotificationKey key = (SubscriptionNotificationKey) inputKey; final SubscriptionBaseEvent event = dao.getEventById(key.getEventId(), internalCallContextFactory.createInternalTenantContext(tenantRecordId, accountRecordId)); if (event == null) { // This can be expected if the event is soft deleted (is_active = 0) log.debug("Failed to extract event for notification key {}", inputKey); return; } final InternalCallContext context = internalCallContextFactory.createInternalCallContext(tenantRecordId, accountRecordId, "SubscriptionEventQueue", CallOrigin.INTERNAL, UserType.SYSTEM, fromNotificationQueueUserToken); processEventReady(event, key.getSeqId(), context); } };
final DateTime init = clock.getUTCNow(); final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(bundle.getAccountId(), ObjectType.ACCOUNT, this.internalCallContext.getUpdatedBy(), this.internalCallContext.getTenantRecordId()); final Iterable<EntitlementSpecifier> specifiers = ImmutableList.<EntitlementSpecifier>of(new DefaultEntitlementSpecifier(new PlanPhaseSpecifier("shotgun-monthly"), 18, null)); final SubscriptionBaseWithAddOnsSpecifier subscriptionBaseWithAddOnsSpecifier = new SubscriptionBaseWithAddOnsSpecifier(bundle.getId(), bundle.getExternalKey(), final List<SubscriptionBaseWithAddOns> subscriptionBaseWithAddOns = subscriptionInternalApi.createBaseSubscriptionsWithAddOns(ImmutableList.<SubscriptionBaseWithAddOnsSpecifier>of(subscriptionBaseWithAddOnsSpecifier), false, internalCallContext);
private void cancelSubscriptionsIfRequired(final DateTime effectiveDate, final ImmutableAccountData account, final OverdueState nextOverdueState, final InternalCallContext context) throws OverdueException { if (nextOverdueState.getOverdueCancellationPolicy() == OverdueCancellationPolicy.NONE) { return; } final CallContext callContext = internalCallContextFactory.createCallContext(context); try { final BillingActionPolicy actionPolicy; switch (nextOverdueState.getOverdueCancellationPolicy()) { case END_OF_TERM: actionPolicy = BillingActionPolicy.END_OF_TERM; break; case IMMEDIATE: actionPolicy = BillingActionPolicy.IMMEDIATE; break; default: throw new IllegalStateException("Unexpected OverdueCancellationPolicy " + nextOverdueState.getOverdueCancellationPolicy()); } final List<Entitlement> toBeCancelled = new LinkedList<Entitlement>(); computeEntitlementsToCancel(account, toBeCancelled, callContext); try { entitlementInternalApi.cancel(toBeCancelled, context.toLocalDate(effectiveDate), actionPolicy, ImmutableList.<PluginProperty>of(), context); } catch (final EntitlementApiException e) { throw new OverdueException(e); } } catch (final EntitlementApiException e) { throw new OverdueException(e); } }
@Override public List<InvoicePayment> getInvoicePayments(final UUID paymentId, final TenantContext context) { return ImmutableList.<InvoicePayment>copyOf(Collections2.transform(dao.getInvoicePaymentsByPaymentId(paymentId, internalCallContextFactory.createInternalTenantContext(paymentId, ObjectType.PAYMENT, context)), new Function<InvoicePaymentModelDao, InvoicePayment>() { @Override public InvoicePayment apply(final InvoicePaymentModelDao input) { return new DefaultInvoicePayment(input); } } )); }
@Override public List<AuditLog> getAuditLogs(final UUID objectId, final ObjectType objectType, final AuditLevel auditLevel, final TenantContext context) { // Optimization - bail early if (AuditLevel.NONE.equals(auditLevel)) { return ImmutableList.<AuditLog>of(); } final TableName tableName = getTableNameFromObjectType(objectType); if (tableName == null) { return ImmutableList.<AuditLog>of(); } return auditDao.getAuditLogsForId(tableName, objectId, auditLevel, internalCallContextFactory.createInternalTenantContextWithoutAccountRecordId(context)); }
private DefaultVersionedCatalog getCatalogFromPlugins(final InternalTenantContext internalTenantContext) throws CatalogApiException { final TenantContext tenantContext = internalCallContextFactory.createTenantContext(internalTenantContext); final Set<String> allServices = pluginRegistry.getAllServices(); for (final String service : allServices) { final DateTime latestCatalogUpdatedDate = plugin.getLatestCatalogVersion(ImmutableList.<PluginProperty>of(), tenantContext); final VersionedPluginCatalog pluginCatalog = plugin.getVersionedPluginCatalog(ImmutableList.<PluginProperty>of(), tenantContext);
@Override public BundleBaseTimeline getBundleTimeline(final SubscriptionBaseBundle bundle, final TenantContext context) throws SubscriptionBaseRepairException { try { final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(bundle.getAccountId(), context); final Catalog fullCatalog = catalogInternalApi.getFullCatalog(true, true, internalTenantContext); final List<DefaultSubscriptionBase> subscriptions = dao.getSubscriptions(bundle.getId(), ImmutableList.<SubscriptionBaseEvent>of(), fullCatalog, internalTenantContext); if (subscriptions.size() == 0) { throw new SubscriptionBaseRepairException(ErrorCode.SUB_NO_ACTIVE_SUBSCRIPTIONS, bundle.getId()); } final String viewId = getViewId(((DefaultSubscriptionBaseBundle) bundle).getLastSysUpdateDate(), subscriptions); final List<SubscriptionBaseTimeline> repairs = createGetSubscriptionRepairList(subscriptions, Collections.<SubscriptionBaseTimeline>emptyList(), fullCatalog, internalTenantContext); return createGetBundleRepair(bundle.getId(), bundle.getExternalKey(), viewId, repairs); } catch (CatalogApiException e) { throw new SubscriptionBaseRepairException(e); } }
@Override public void deleteTagDefinition(final UUID definitionId, final CallContext context) throws TagDefinitionApiException { tagDefinitionDao.deleteById(definitionId, internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context)); }
private InternalTenantContext createInternalTenantContext(final TenantContext tenantContext) { // Only tenantRecordId will be populated -- this is important to always create the (ehcache) key the same way return internalCallContextFactory.createInternalTenantContextWithoutAccountRecordId(tenantContext); } }
@BeforeMethod(groups = "fast") public void setUp() throws Exception { externalBus = mock(PersistentBus.class); internalCallContextFactory = mock(InternalCallContextFactory.class); beatrixListener = new BeatrixListener(externalBus, internalCallContextFactory); objectMapper = mock(ObjectMapper.class); beatrixListener.objectMapper = objectMapper; InternalCallContext internalContext = new InternalCallContext( TENANT_RECORD_ID, ACCOUNT_RECORD_ID, null, null, USER_TOKEN, null, null, null, null, null, null, null ); when(internalCallContextFactory.createInternalCallContext( SEARCH_KEY_2, SEARCH_KEY_1, "BeatrixListener", CallOrigin.INTERNAL, UserType.SYSTEM, USER_TOKEN)).thenReturn(internalContext); tenantContext = mock(TenantContext.class); when(tenantContext.getTenantId()).thenReturn(TENANT_ID); when(internalCallContextFactory.createTenantContext(internalContext)).thenReturn(tenantContext); }
final Long parentAccountRecordId = internalCallContextFactory.getRecordIdFromObject(parentAccountId, ObjectType.ACCOUNT, internalCallContextFactory.createTenantContext(childContext)); final InternalTenantContext parentContext = internalCallContextFactory.createInternalTenantContext(childContext.getTenantRecordId(), parentAccountRecordId);
@Override public DateTime getDryRunChangePlanEffectiveDate(final SubscriptionBase subscription, final EntitlementSpecifier spec, final DateTime requestedDateWithMs, final BillingActionPolicy requestedPolicy, final InternalCallContext context) throws SubscriptionBaseApiException, CatalogApiException { final TenantContext tenantContext = internalCallContextFactory.createTenantContext(context); final CallContext callContext = internalCallContextFactory.createCallContext(context); // verify the number of subscriptions (of the same kind) allowed per bundle final Catalog catalog = catalogInternalApi.getFullCatalog(true, true, context); final DateTime effectiveDate = (requestedDateWithMs != null) ? DefaultClock.truncateMs(requestedDateWithMs) : null; final DateTime effectiveCatalogDate = effectiveDate != null ? effectiveDate : context.getCreatedDate(); final PlanPhasePriceOverridesWithCallContext overridesWithContext = new DefaultPlanPhasePriceOverridesWithCallContext(spec.getOverrides(), callContext); final Plan plan = catalog.createOrFindPlan(spec.getPlanPhaseSpecifier(), overridesWithContext, effectiveCatalogDate, subscription.getStartDate()); if (ProductCategory.ADD_ON.toString().equalsIgnoreCase(plan.getProduct().getCategory().toString())) { if (plan.getPlansAllowedInBundle() != -1 && plan.getPlansAllowedInBundle() > 0 && addonUtils.countExistingAddOnsWithSamePlanName(getSubscriptionsForBundle(subscription.getBundleId(), null, catalog, addonUtils, callContext, context), plan.getName()) >= plan.getPlansAllowedInBundle()) { // the plan can be changed to the new value, because it has reached its limit by bundle throw new SubscriptionBaseApiException(ErrorCode.SUB_CHANGE_AO_MAX_PLAN_ALLOWED_BY_BUNDLE, plan.getName()); } } return apiService.dryRunChangePlan((DefaultSubscriptionBase) subscription, spec, effectiveDate, requestedPolicy, tenantContext); }
@Override public List<SubscriptionBase> getSubscriptionsForBundle(final UUID bundleId, @Nullable final DryRunArguments dryRunArguments, final InternalTenantContext context) throws SubscriptionBaseApiException { try { final Catalog catalog = catalogInternalApi.getFullCatalog(true, true, context); final TenantContext tenantContext = internalCallContextFactory.createTenantContext(context); final List<DefaultSubscriptionBase> subscriptionsForBundle = super.getSubscriptionsForBundle(bundleId, dryRunArguments, catalog, addonUtils, tenantContext, context); return new ArrayList<SubscriptionBase>(subscriptionsForBundle); } catch (final CatalogApiException e) { throw new SubscriptionBaseApiException(e); } }
@Override public List<SubscriptionBaseWithAddOns> createBaseSubscriptionsWithAddOns(final Iterable<SubscriptionBaseWithAddOnsSpecifier> subscriptionWithAddOnsSpecifiers, final boolean renameCancelledBundleIfExist, final InternalCallContext context) throws SubscriptionBaseApiException { try { final Catalog catalog = catalogInternalApi.getFullCatalog(true, true, context); final CallContext callContext = internalCallContextFactory.createCallContext(context); return super.createBaseSubscriptionsWithAddOns(subscriptionWithAddOnsSpecifiers, renameCancelledBundleIfExist, catalog, addonUtils, accountIdCacheController, bundleIdCacheController, callContext, context); } catch (final CatalogApiException e) { throw new SubscriptionBaseApiException(e); } }
final String bundleKey, final DateTime transferDate, final boolean transferAddOn, final boolean cancelImmediately, final CallContext context) throws SubscriptionBaseTransferApiException { final InternalCallContext fromInternalCallContext = internalCallContextFactory.createInternalCallContext(sourceAccountId, context); final InternalCallContext toInternalCallContext = internalCallContextFactory.createInternalCallContext(destAccountId, context); .setBundleStartDate(effectiveTransferDate) .setAlignStartDate(subscriptionAlignStartDate), ImmutableList.<SubscriptionBaseEvent>of(), catalog, fromInternalCallContext);