@Override public void handleReadyNotification(final NotificationEvent inputKey, final DateTime eventDateTime, final UUID fromNotificationQueueUserToken, final Long accountRecordId, final Long tenantRecordId) { final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(tenantRecordId, accountRecordId, "EntitlementQueue", CallOrigin.INTERNAL, UserType.SYSTEM, fromNotificationQueueUserToken); if (inputKey instanceof EntitlementNotificationKey) { final UUID tenantId = nonEntityDao.retrieveIdFromObject(tenantRecordId, ObjectType.TENANT); processEntitlementNotification((EntitlementNotificationKey) inputKey, tenantId, internalCallContext); } else if (inputKey instanceof BlockingTransitionNotificationKey) { processBlockingNotification((BlockingTransitionNotificationKey) inputKey, internalCallContext); } else if (inputKey != null) { log.error("Entitlement service received an unexpected event type {}" + inputKey.getClass()); } else { log.error("Entitlement service received an unexpected null event"); } } };
@Override public SubscriptionBundle getSubscriptionBundle(final UUID bundleId, final TenantContext context) throws SubscriptionApiException { final Long accountRecordId = nonEntityDao.retrieveAccountRecordIdFromObject(bundleId, ObjectType.BUNDLE, cacheControllerDispatcher.getCacheController(CacheType.ACCOUNT_RECORD_ID)); final UUID accountId = nonEntityDao.retrieveIdFromObject(accountRecordId, ObjectType.ACCOUNT); final Optional<SubscriptionBundle> bundleOptional = Iterables.<SubscriptionBundle>tryFind(getSubscriptionBundlesForAccount(accountId, context), new Predicate<SubscriptionBundle>() { @Override public boolean apply(final SubscriptionBundle bundle) { return bundle.getId().equals(bundleId); } }); if (!bundleOptional.isPresent()) { throw new SubscriptionApiException(ErrorCode.SUB_GET_INVALID_BUNDLE_ID, bundleId); } else { return bundleOptional.get(); } }
@Override public Long getRecordId(final UUID objectId, final ObjectType objectType, final TenantContext tenantContext) { return nonEntityDao.retrieveRecordIdFromObject(objectId, objectType, cacheControllerDispatcher.getCacheController(CacheType.RECORD_ID)); } }
private Long getAccountRecordId(final UUID objectId, final ObjectType objectType) { return nonEntityDao.retrieveAccountRecordIdFromObject(objectId, objectType, cacheControllerDispatcher.getCacheController(CacheType.ACCOUNT_RECORD_ID)); }
@Override public Object load(final Object key, final Object argument) { checkCacheLoaderStatus(); if (!(key instanceof String)) { throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName()); } if (!(argument instanceof CacheLoaderArgument)) { throw new IllegalArgumentException("Unexpected key type of " + argument.getClass().getName()); } final String objectId = (String) key; final ObjectType objectType = ((CacheLoaderArgument) argument).getObjectType(); return nonEntityDao.retrieveTenantRecordIdFromObject(UUID.fromString(objectId), objectType, null); } }
private Long insertHistory(final Long entityRecordId, final M entityModelDao, final ChangeType changeType, final InternalCallContext context) { final EntityHistoryModelDao<M, E> history = new EntityHistoryModelDao<M, E>(entityModelDao, entityRecordId, changeType, clock.getUTCNow()); sqlDao.addHistoryFromTransaction(history, context); final NonEntitySqlDao transactional = sqlDao.become(NonEntitySqlDao.class); /* return transactional.getLastHistoryRecordId(entityRecordId, entityModelDao.getHistoryTableName().getTableName()); */ return nonEntityDao.retrieveLastHistoryRecordIdFromTransaction(entityRecordId, entityModelDao.getHistoryTableName(), transactional); }
@Override public Object load(final Object key, final Object argument) { checkCacheLoaderStatus(); if (!(key instanceof String)) { throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName()); } if (!(argument instanceof CacheLoaderArgument)) { throw new IllegalArgumentException("Unexpected key type of " + argument.getClass().getName()); } final String objectId = (String) key; final ObjectType objectType = ((CacheLoaderArgument) argument).getObjectType(); return nonEntityDao.retrieveAccountRecordIdFromObject(UUID.fromString(objectId), objectType, null); } }
public InternalCallContext createInternalCallContext(final UUID objectId, final ObjectType objectType, final String userName, final CallOrigin callOrigin, final UserType userType, @Nullable final UUID userToken, @Nullable final String reasonCode, @Nullable final String comment, final DateTime createdDate, final DateTime updatedDate) { final Long tenantRecordId = nonEntityDao.retrieveTenantRecordIdFromObject(objectId, objectType, cacheControllerDispatcher.getCacheController(CacheType.TENANT_RECORD_ID)); final Long accountRecordId = getAccountRecordId(objectId, objectType); return createInternalCallContext(tenantRecordId, accountRecordId, userName, callOrigin, userType, userToken, reasonCode, comment, createdDate, updatedDate); }
protected TenantContext buildTenantContext(final InternalTenantContext context) { return context.toTenantContext(nonEntityDao.retrieveIdFromObject(context.getTenantRecordId(), ObjectType.TENANT)); }
@Override public Subscription getSubscriptionForEntitlementId(final UUID entitlementId, final TenantContext context) throws SubscriptionApiException { final Long accountRecordId = nonEntityDao.retrieveAccountRecordIdFromObject(entitlementId, ObjectType.SUBSCRIPTION, cacheControllerDispatcher.getCacheController(CacheType.ACCOUNT_RECORD_ID)); final UUID accountId = nonEntityDao.retrieveIdFromObject(accountRecordId, ObjectType.ACCOUNT); // Retrieve entitlements final AccountEntitlements accountEntitlements; try { accountEntitlements = entitlementInternalApi.getAllEntitlementsForAccountId(accountId, context); } catch (EntitlementApiException e) { throw new SubscriptionApiException(e); } // Build subscriptions final Iterable<Subscription> accountSubscriptions = Iterables.<Subscription>concat(buildSubscriptionsFromEntitlements(accountEntitlements).values()); return Iterables.<Subscription>find(accountSubscriptions, new Predicate<Subscription>() { @Override public boolean apply(final Subscription subscription) { return subscription.getId().equals(entitlementId); } }); }
@Test(groups = "slow") public void testRetrieveAccountRecordIdFromAccountObject() throws IOException { insertAccount(); final Long resultAccountRecordId = nonEntityDao.retrieveAccountRecordIdFromObject(accountId, ObjectType.ACCOUNT, null); Assert.assertEquals(resultAccountRecordId, accountRecordId); }
@Test(groups = "slow") public void testRetrieveTenantRecordIdFromObject() throws IOException { insertAccount(); final Long resultTenantRecordId = nonEntityDao.retrieveTenantRecordIdFromObject(accountId, ObjectType.ACCOUNT, null); Assert.assertEquals(resultTenantRecordId, tenantRecordId); }
@Override public Object load(final Object key, final Object argument) throws CacheException { checkCacheLoaderStatus(); if (!(key instanceof String)) { throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName()); } if (!(argument instanceof CacheLoaderArgument)) { throw new IllegalArgumentException("Unexpected key type of " + argument.getClass().getName()); } final String objectId = (String) key; final ObjectType objectType = ((CacheLoaderArgument) argument).getObjectType(); return nonEntityDao.retrieveRecordIdFromObject(UUID.fromString(objectId), objectType, null); } }
private TenantContext buildTenantContext(final InternalTenantContext context) { return context.toTenantContext(nonEntityDao.retrieveIdFromObject(context.getTenantRecordId(), ObjectType.TENANT)); }
@Test(groups = "slow") public void testRetrieveAccountRecordIdFromTagDefinitionObject() throws IOException { insertTagDefinition(); final Long resultAccountRecordId = nonEntityDao.retrieveAccountRecordIdFromObject(tagDefinitionId, ObjectType.TAG_DEFINITION, null); Assert.assertEquals(resultAccountRecordId, null); }
@Test(groups = "slow") public void testRetrieveTenantRecordIdFromTenantObject() throws IOException { insertTenant(); final Long resultTenantRecordId = nonEntityDao.retrieveTenantRecordIdFromObject(tenantId, ObjectType.TENANT, null); Assert.assertEquals(resultTenantRecordId, tenantRecordId); } private void insertAccount() throws IOException {
@Test(groups = "slow") public void testRetrieveRecordIdFromObject() throws IOException { insertAccount(); final Long resultRecordId = nonEntityDao.retrieveRecordIdFromObject(accountId, ObjectType.ACCOUNT, null); Assert.assertEquals(resultRecordId, accountRecordId); }
private void computeEntitlementsToCancel(final Account account, final List<Entitlement> result, final InternalTenantContext context) throws EntitlementApiException { final UUID tenantId = nonEntityDao.retrieveIdFromObject(context.getTenantRecordId(), ObjectType.TENANT); final List<Entitlement> allEntitlementsForAccountId = entitlementApi.getAllEntitlementsForAccountId(account.getId(), context.toTenantContext(tenantId)); // Entitlement is smart enough and will cancel the associated add-ons. See also discussion in https://github.com/killbill/killbill/issues/94 final Collection<Entitlement> allEntitlementsButAddonsForAccountId = Collections2.<Entitlement>filter(allEntitlementsForAccountId, new Predicate<Entitlement>() { @Override public boolean apply(final Entitlement entitlement) { return !ProductCategory.ADD_ON.equals(entitlement.getLastActiveProductCategory()); } }); result.addAll(allEntitlementsButAddonsForAccountId); }
@Test(groups = "slow") public void testRetrieveAccountRecordIdFromOtherObject() throws IOException { insertTag(); final Long resultAccountRecordId = nonEntityDao.retrieveAccountRecordIdFromObject(tagId, ObjectType.TAG, null); Assert.assertEquals(resultAccountRecordId, accountRecordId); }
private Long getTenantRecordId(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 { return nonEntityDao.retrieveTenantRecordIdFromObject(context.getTenantId(), ObjectType.TENANT, cacheControllerDispatcher.getCacheController(CacheType.TENANT_RECORD_ID)); } } }