@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); } }
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); }
@Test(groups = "slow") public void testRetrieveTenantRecordIdFromObject() throws IOException { insertAccount(); final Long resultTenantRecordId = nonEntityDao.retrieveTenantRecordIdFromObject(accountId, ObjectType.ACCOUNT, null); Assert.assertEquals(resultTenantRecordId, tenantRecordId); }
@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 {
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)); } } }