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.retrieveAccountRecordIdFromObject(UUID.fromString(objectId), objectType, null); } }
@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(); } }
@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 testRetrieveAccountRecordIdFromTagDefinitionObject() throws IOException { insertTagDefinition(); final Long resultAccountRecordId = nonEntityDao.retrieveAccountRecordIdFromObject(tagDefinitionId, ObjectType.TAG_DEFINITION, null); Assert.assertEquals(resultAccountRecordId, null); }
@Test(groups = "slow") public void testRetrieveAccountRecordIdFromOtherObject() throws IOException { insertTag(); final Long resultAccountRecordId = nonEntityDao.retrieveAccountRecordIdFromObject(tagId, ObjectType.TAG, null); Assert.assertEquals(resultAccountRecordId, accountRecordId); }
@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); } }); }