@Override protected TenantApiException generateAlreadyExistsException(final TenantModelDao entity, final InternalCallContext context) { return new TenantApiException(ErrorCode.TENANT_ALREADY_EXISTS, entity.getExternalKey()); }
@Override public Tenant getTenantByApiKey(final String key) throws TenantApiException { final Tenant tenant = tenantCache.get(key, new CacheLoaderArgument(ObjectType.TENANT)); if (tenant == null) { throw new TenantApiException(ErrorCode.TENANT_DOES_NOT_EXIST_FOR_API_KEY, key); } return tenant; }
@Override public Tenant getTenantByApiKey(final String key) throws TenantApiException { final TenantModelDao tenant = tenantDao.getTenantByApiKey(key); if (tenant == null) { throw new TenantApiException(ErrorCode.TENANT_DOES_NOT_EXIST_FOR_API_KEY, key); } return new DefaultTenant(tenant); }
@Override public Tenant getTenantById(final UUID id) throws TenantApiException { // TODO - API cleanup? final TenantModelDao tenant = tenantDao.getById(id, new InternalTenantContext(null)); if (tenant == null) { throw new TenantApiException(ErrorCode.TENANT_DOES_NOT_EXIST_FOR_ID, id); } return new DefaultTenant(tenant); }
@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; }
@Override protected TenantApiException generateAlreadyExistsException(final TenantModelDao entity, final InternalCallContext context) { return new TenantApiException(ErrorCode.TENANT_ALREADY_EXISTS, entity.getExternalKey()); }
@Override public Tenant getTenantByApiKey(final String key) throws TenantApiException { final Tenant tenant = tenantCache.get(key, new CacheLoaderArgument(ObjectType.TENANT)); if (tenant == null) { throw new TenantApiException(ErrorCode.TENANT_DOES_NOT_EXIST_FOR_API_KEY, key); } return tenant; }
@Override public Tenant getTenantByApiKey(final String key) throws TenantApiException { final TenantModelDao tenant = tenantDao.getTenantByApiKey(key); if (tenant == null) { throw new TenantApiException(ErrorCode.TENANT_DOES_NOT_EXIST_FOR_API_KEY, key); } return new DefaultTenant(tenant); }
@Override public Tenant getTenantById(final UUID id) throws TenantApiException { // TODO - API cleanup? final TenantModelDao tenant = tenantDao.getById(id, new InternalTenantContext(null)); if (tenant == null) { throw new TenantApiException(ErrorCode.TENANT_DOES_NOT_EXIST_FOR_ID, id); } return new DefaultTenant(tenant); }
@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; }