public TenantModelDao(final Tenant tenant) { this(tenant.getId(), tenant.getCreatedDate(), tenant.getUpdatedDate(), tenant.getExternalKey(), tenant.getApiKey(), tenant.getApiSecret(), null); }
@Override public Tenant createTenant(final TenantData data, final CallContext context) throws TenantApiException { final Tenant tenant = new DefaultTenant(data); if (null != tenant.getExternalKey() && tenant.getExternalKey().length() > 255) { throw new TenantApiException(ErrorCode.EXTERNAL_KEY_LIMIT_EXCEEDED); } try { // Not transactional, but there is a db constraint on that column if (data.getApiKey() != null && getTenantByApiKey(data.getApiKey()) != null) { throw new TenantApiException(ErrorCode.TENANT_ALREADY_EXISTS, data.getExternalKey()); } } catch (final RuntimeException e) { if (e.getCause() instanceof IllegalStateException) { // could happen exemption, stating that the key is not found } else { throw e; } } try { tenantDao.create(new TenantModelDao(tenant), internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context)); } catch (final TenantApiException e) { throw new TenantApiException(e, ErrorCode.TENANT_CREATION_FAILED); } return tenant; }
@Test(groups = "slow") public void testTenant() throws Exception { final TenantData tenantdata = new DefaultTenant(UUID.randomUUID(), clock.getUTCNow(), clock.getUTCNow(), "er44TT-yy4r", "TTR445ee2", "dskjhfs^^54R"); tenantUserApi.createTenant(tenantdata, callContext); final Tenant tenant = tenantUserApi.getTenantByApiKey(tenantdata.getApiKey()); Assert.assertEquals(tenant.getApiKey(), tenantdata.getApiKey()); Assert.assertEquals(tenant.getExternalKey(), tenantdata.getExternalKey()); // The second time, the value is already in the cache so the TenantCacheLoader is not invoked final Tenant tenant2 = tenantUserApi.getTenantByApiKey(tenantdata.getApiKey()); Assert.assertEquals(tenant2.getApiKey(), tenantdata.getApiKey()); Assert.assertEquals(tenant2.getExternalKey(), tenantdata.getExternalKey()); }
public TenantJson(final Tenant tenant) { this(tenant.getId(), tenant.getExternalKey(), tenant.getApiKey(), tenant.getApiSecret()); }
public TenantModelDao(final Tenant tenant) { this(tenant.getId(), tenant.getCreatedDate(), tenant.getUpdatedDate(), tenant.getExternalKey(), tenant.getApiKey(), tenant.getApiSecret(), null); }
@Override public Tenant createTenant(final TenantData data, final CallContext context) throws TenantApiException { final Tenant tenant = new DefaultTenant(data); if (null != tenant.getExternalKey() && tenant.getExternalKey().length() > 255) { throw new TenantApiException(ErrorCode.EXTERNAL_KEY_LIMIT_EXCEEDED); } try { // Not transactional, but there is a db constraint on that column if (data.getApiKey() != null && getTenantByApiKey(data.getApiKey()) != null) { throw new TenantApiException(ErrorCode.TENANT_ALREADY_EXISTS, data.getExternalKey()); } } catch (final RuntimeException e) { if (e.getCause() instanceof IllegalStateException) { // could happen exemption, stating that the key is not found } else { throw e; } } try { tenantDao.create(new TenantModelDao(tenant), internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context)); } catch (final TenantApiException e) { throw new TenantApiException(e, ErrorCode.TENANT_CREATION_FAILED); } return tenant; }
@Test(groups = "slow") public void testTenant() throws Exception { final TenantData tenantdata = new DefaultTenant(UUID.randomUUID(), clock.getUTCNow(), clock.getUTCNow(), "er44TT-yy4r", "TTR445ee2", "dskjhfs^^54R"); tenantUserApi.createTenant(tenantdata, callContext); final Tenant tenant = tenantUserApi.getTenantByApiKey(tenantdata.getApiKey()); Assert.assertEquals(tenant.getApiKey(), tenantdata.getApiKey()); Assert.assertEquals(tenant.getExternalKey(), tenantdata.getExternalKey()); // The second time, the value is already in the cache so the TenantCacheLoader is not invoked final Tenant tenant2 = tenantUserApi.getTenantByApiKey(tenantdata.getApiKey()); Assert.assertEquals(tenant2.getApiKey(), tenantdata.getApiKey()); Assert.assertEquals(tenant2.getExternalKey(), tenantdata.getExternalKey()); }