private Long getTenantRecordIdSafe(final TenantContext context) { // Default to single default tenant (e.g. single tenant mode) // TODO Extract this convention (e.g. BusinessAnalyticsBase needs to know about it) if (context.getTenantId() == null) { return INTERNAL_TENANT_RECORD_ID; } else { // This is always safe (the tenant context was created from the api key and secret) return getTenantRecordIdUnsafe(context.getTenantId(), ObjectType.TENANT); } }
@Override public StaticCatalog getCurrentCatalog(final String catalogName, final TenantContext tenantContext) throws CatalogApiException { final InternalTenantContext internalTenantContext; if (tenantContext.getAccountId() != null) { internalTenantContext = internalCallContextFactory.createInternalTenantContext(tenantContext.getAccountId(), tenantContext); } else { internalTenantContext = createInternalTenantContext(tenantContext); } return catalogService.getFullCatalog(true, true, internalTenantContext); }
private Long getAccountRecordIdSafe(final UUID objectId, final ObjectType objectType, final TenantContext context) { if (objectBelongsToTheRightTenant(objectId, objectType, context)) { return getAccountRecordIdUnsafe(objectId, objectType); } else { throw new IllegalStateException(String.format("Object id=%s type=%s doesn't belong to tenant id=%s", objectId, objectType, context.getTenantId())); } }
@Override public List<AuditLogWithHistory> getEmailAuditLogsWithHistoryForId(final UUID accountEmailId, final AuditLevel auditLevel, final TenantContext tenantContext) throws AccountApiException { return accountDao.getEmailAuditLogsWithHistoryForId(accountEmailId, auditLevel, internalCallContextFactory.createInternalTenantContext(tenantContext.getAccountId(), tenantContext)); } }
private boolean objectBelongsToTheRightTenant(final UUID objectId, final ObjectType objectType, final TenantContext context) throws ObjectDoesNotExist { final Long realTenantRecordId = getTenantRecordIdSafe(context); if (realTenantRecordId == null) { throw new ObjectDoesNotExist(String.format("Tenant id=%s doesn't exist!", context.getTenantId())); } return objectBelongsToTheRightTenant(objectId, objectType, realTenantRecordId); }
@Override public VersionedCatalog<? extends StaticCatalog> getCatalog(final String catalogName, @Nullable final DateTime catalogDateVersion, final TenantContext tenantContext) throws CatalogApiException { final InternalTenantContext internalTenantContext; if (tenantContext.getAccountId() != null) { internalTenantContext = internalCallContextFactory.createInternalTenantContext(tenantContext.getAccountId(), tenantContext); } else { internalTenantContext = createInternalTenantContext(tenantContext); } final DefaultVersionedCatalog fullCatalog = catalogService.getFullCatalog(true, true, internalTenantContext); if (catalogDateVersion == null) { return fullCatalog; } else { final DefaultVersionedCatalog filteredCatalog = new DefaultVersionedCatalog(clock); for (final StandaloneCatalog v : fullCatalog.getVersions()) { if (v.getEffectiveDate().compareTo(catalogDateVersion.toDate()) >= 0) { filteredCatalog.add(v); break; } } return filteredCatalog; } }
@Override public UUID getTenantId() { return delegate.getTenantId(); }
private SubscriptionBaseBundle getBundleWithSanity(final SubscriptionBaseWithAddOnsSpecifier subscriptionBaseWithAddOnsSpecifier, final Catalog catalog, final TenantContext callContext, final InternalCallContext context) throws SubscriptionBaseApiException, CatalogApiException { SubscriptionBaseBundle bundle = null; if (subscriptionBaseWithAddOnsSpecifier.getBundleId() != null) { bundle = dao.getSubscriptionBundleFromId(subscriptionBaseWithAddOnsSpecifier.getBundleId(), context); if (bundle == null || (subscriptionBaseWithAddOnsSpecifier.getBundleExternalKey() != null && !subscriptionBaseWithAddOnsSpecifier.getBundleExternalKey().equals(bundle.getExternalKey()))) { throw new SubscriptionBaseApiException(ErrorCode.SUB_CREATE_INVALID_ENTITLEMENT_SPECIFIER); } } else if (subscriptionBaseWithAddOnsSpecifier.getBundleExternalKey() != null) { final SubscriptionBaseBundle tmp = getActiveBundleForKey(subscriptionBaseWithAddOnsSpecifier.getBundleExternalKey(), catalog, context); if (tmp != null && !tmp.getAccountId().equals(callContext.getAccountId())) { throw new SubscriptionBaseApiException(ErrorCode.SUB_CREATE_ACTIVE_BUNDLE_KEY_EXISTS, subscriptionBaseWithAddOnsSpecifier.getBundleExternalKey()); } else { bundle = tmp; } } return bundle; }
@Override public UUID getTenantId() { return delegate.getTenantId(); }
@Override public UUID getAccountId() { return delegate.getAccountId(); }
private Long getTenantRecordIdSafe(final TenantContext context) { // Default to single default tenant (e.g. single tenant mode) // TODO Extract this convention (e.g. BusinessAnalyticsBase needs to know about it) if (context.getTenantId() == null) { return INTERNAL_TENANT_RECORD_ID; } else { // This is always safe (the tenant context was created from the api key and secret) return getTenantRecordIdUnsafe(context.getTenantId(), ObjectType.TENANT); } }
@Override public UUID getAccountId() { return delegate.getAccountId(); }
protected Long getTenantRecordId(final TenantContext context) throws OSGIServiceNotAvailable { if (context.getTenantId() == null) { return INTERNAL_TENANT_RECORD_ID; } else { final RecordIdApi recordIdUserApi = getRecordIdUserApi(); return recordIdUserApi.getRecordId(context.getTenantId(), ObjectType.TENANT, context); } }
@Override public StaticCatalog getCurrentCatalog(final String catalogName, final TenantContext tenantContext) throws CatalogApiException { final InternalTenantContext internalTenantContext; if (tenantContext.getAccountId() != null) { internalTenantContext = internalCallContextFactory.createInternalTenantContext(tenantContext.getAccountId(), tenantContext); } else { internalTenantContext = createInternalTenantContext(tenantContext); } return catalogService.getFullCatalog(true, true, internalTenantContext); }
private Long getAccountRecordIdSafe(final UUID objectId, final ObjectType objectType, final TenantContext context) { if (objectBelongsToTheRightTenant(objectId, objectType, context)) { return getAccountRecordIdUnsafe(objectId, objectType); } else { throw new IllegalStateException(String.format("Object id=%s type=%s doesn't belong to tenant id=%s", objectId, objectType, context.getTenantId())); } }
@Override public List<AuditLogWithHistory> getEmailAuditLogsWithHistoryForId(final UUID accountEmailId, final AuditLevel auditLevel, final TenantContext tenantContext) throws AccountApiException { return accountDao.getEmailAuditLogsWithHistoryForId(accountEmailId, auditLevel, internalCallContextFactory.createInternalTenantContext(tenantContext.getAccountId(), tenantContext)); } }
@Override public List<PaymentTransactionInfoPlugin> getPaymentInfo(final UUID kbAccountId, final UUID kbPaymentId, final Iterable<PluginProperty> properties, final TenantContext context) throws PaymentPluginApiException { final List<RESP_R> records; try { records = dao.getResponses(kbPaymentId, context.getTenantId()); } catch (final SQLException e) { throw new PaymentPluginApiException("Unable to retrieve payments for kbPaymentId " + kbPaymentId, e); } return Lists.<RESP_R, PaymentTransactionInfoPlugin>transform(records, new Function<RESP_R, PaymentTransactionInfoPlugin>() { @Override public PaymentTransactionInfoPlugin apply(final RESP_R record) { return buildPaymentTransactionInfoPlugin(record); } }); }
@Override public InvoicePayment getInvoicePaymentByCookieId(final String cookieId, final TenantContext context) { final InvoicePaymentModelDao invoicePaymentModelDao = dao.getInvoicePaymentByCookieId(cookieId, internalCallContextFactory.createInternalTenantContext(context.getAccountId(), ObjectType.ACCOUNT, context)); return invoicePaymentModelDao == null ? null : new DefaultInvoicePayment(invoicePaymentModelDao); } }
private boolean objectBelongsToTheRightTenant(final UUID objectId, final ObjectType objectType, final TenantContext context) throws ObjectDoesNotExist { final Long realTenantRecordId = getTenantRecordIdSafe(context); if (realTenantRecordId == null) { throw new ObjectDoesNotExist(String.format("Tenant id=%s doesn't exist!", context.getTenantId())); } return objectBelongsToTheRightTenant(objectId, objectType, realTenantRecordId); }
@Override public VersionedCatalog<? extends StaticCatalog> getCatalog(final String catalogName, @Nullable final DateTime catalogDateVersion, final TenantContext tenantContext) throws CatalogApiException { final InternalTenantContext internalTenantContext; if (tenantContext.getAccountId() != null) { internalTenantContext = internalCallContextFactory.createInternalTenantContext(tenantContext.getAccountId(), tenantContext); } else { internalTenantContext = createInternalTenantContext(tenantContext); } final DefaultVersionedCatalog fullCatalog = catalogService.getFullCatalog(true, true, internalTenantContext); if (catalogDateVersion == null) { return fullCatalog; } else { final DefaultVersionedCatalog filteredCatalog = new DefaultVersionedCatalog(clock); for (final StandaloneCatalog v : fullCatalog.getVersions()) { if (v.getEffectiveDate().compareTo(catalogDateVersion.toDate()) >= 0) { filteredCatalog.add(v); break; } } return filteredCatalog; } }