@Override public void deleteTagDefinition(final UUID definitionId, final CallContext context) throws TagDefinitionApiException { tagDefinitionDao.deleteById(definitionId, internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context)); }
@Override public void deleteTenantKey(final String key, final CallContext context) throws TenantApiException { // Invalidate tenantKVCache after we delete (to avoid race conditions). Multi-node invalidation will follow the TenantBroadcast pattern final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context); final String tenantKey = getCacheKeyName(key, internalContext); tenantDao.deleteTenantKey(key, internalContext); tenantKVCache.remove(tenantKey); }
@Override public void updateTenantKeyValue(final String key, final String value, final CallContext context) throws TenantApiException { // Invalidate tenantKVCache after we store (to avoid race conditions). Multi-node invalidation will follow the TenantBroadcast pattern final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context); final String tenantKey = getCacheKeyName(key, internalContext); tenantDao.updateTenantLastKeyValue(key, value, internalContext); tenantKVCache.remove(tenantKey); }
@Override public TagDefinition createTagDefinition(final String definitionName, final String description, final Set<ObjectType> applicableObjectTypes, final CallContext context) throws TagDefinitionApiException { if (definitionName.matches(".*[A-Z].*")) { throw new TagDefinitionApiException(ErrorCode.TAG_DEFINITION_HAS_UPPERCASE, definitionName); } final TagDefinitionModelDao tagDefinitionModelDao = tagDefinitionDao.create(definitionName, description, JOINER.join(applicableObjectTypes), internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context)); return new DefaultTagDefinition(tagDefinitionModelDao, TagModelDaoHelper.isControlTag(tagDefinitionModelDao.getName())); }
@Override public void addTenantKeyValue(final String key, final String value, final CallContext context) throws TenantApiException { // Invalidate tenantKVCache after we store (to avoid race conditions). Multi-node invalidation will follow the TenantBroadcast pattern final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context); final String tenantKey = getCacheKeyName(key, internalContext); tenantDao.addTenantKeyValue(key, value, isSingleValueKey(key), internalContext); tenantKVCache.remove(tenantKey); }
@Override public Plan createOrFindCurrentPlan(final PlanSpecifier spec, final PlanPhasePriceOverridesWithCallContext overrides) throws CatalogApiException { final Plan defaultPlan = super.createOrFindCurrentPlan(spec, null); if (overrides == null || overrides.getOverrides() == null || overrides.getOverrides().isEmpty()) { return defaultPlan; } final InternalCallContext internalCallContext = overrides.getCallContext() != null ? internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(overrides.getCallContext()) : null; return priceOverride.getOrCreateOverriddenPlan(this, defaultPlan, CatalogDateHelper.toUTCDateTime(getEffectiveDate()), overrides.getOverrides(), internalCallContext); }
@Override public Account createAccount(final AccountData data, final CallContext context) throws AccountApiException { // Not transactional, but there is a db constraint on that column if (data.getExternalKey() != null && getIdFromKey(data.getExternalKey(), context) != null) { throw new AccountApiException(ErrorCode.ACCOUNT_ALREADY_EXISTS, data.getExternalKey()); } final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context); if (data.getParentAccountId() != null) { // verify that parent account exists if parentAccountId is not null final ImmutableAccountData immutableAccountData = immutableAccountInternalApi.getImmutableAccountDataById(data.getParentAccountId(), internalContext); if (immutableAccountData == null) { throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_ID, data.getParentAccountId()); } } final AccountModelDao account = new AccountModelDao(data); if (null != account.getExternalKey() && account.getExternalKey().length() > 255) { throw new AccountApiException(ErrorCode.EXTERNAL_KEY_LIMIT_EXCEEDED); } accountDao.create(account, internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context)); return new DefaultAccount(account); }
@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; }
private void populateMDCContext(final CallContext callContext) { // InternalCallContextFactory will do it for us internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(callContext); }
@Override public void deleteTagDefinition(final UUID definitionId, final CallContext context) throws TagDefinitionApiException { tagDefinitionDao.deleteById(definitionId, internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context)); }
@Override public TagDefinition createTagDefinition(final String definitionName, final String description, final Set<ObjectType> applicableObjectTypes, final CallContext context) throws TagDefinitionApiException { if (definitionName.matches(".*[A-Z].*")) { throw new TagDefinitionApiException(ErrorCode.TAG_DEFINITION_HAS_UPPERCASE, definitionName); } final TagDefinitionModelDao tagDefinitionModelDao = tagDefinitionDao.create(definitionName, description, JOINER.join(applicableObjectTypes), internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context)); return new DefaultTagDefinition(tagDefinitionModelDao, TagModelDaoHelper.isControlTag(tagDefinitionModelDao.getName())); }
@Override public void updateTenantKeyValue(final String key, final String value, final CallContext context) throws TenantApiException { // Invalidate tenantKVCache after we store (to avoid race conditions). Multi-node invalidation will follow the TenantBroadcast pattern final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context); final String tenantKey = getCacheKeyName(key, internalContext); tenantDao.updateTenantLastKeyValue(key, value, internalContext); tenantKVCache.remove(tenantKey); }
@Override public void deleteTenantKey(final String key, final CallContext context) throws TenantApiException { // Invalidate tenantKVCache after we delete (to avoid race conditions). Multi-node invalidation will follow the TenantBroadcast pattern final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context); final String tenantKey = getCacheKeyName(key, internalContext); tenantDao.deleteTenantKey(key, internalContext); tenantKVCache.remove(tenantKey); }
@Override public void addTenantKeyValue(final String key, final String value, final CallContext context) throws TenantApiException { // Invalidate tenantKVCache after we store (to avoid race conditions). Multi-node invalidation will follow the TenantBroadcast pattern final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context); final String tenantKey = getCacheKeyName(key, internalContext); tenantDao.addTenantKeyValue(key, value, isSingleValueKey(key), internalContext); tenantKVCache.remove(tenantKey); }
private <T extends EntitySqlDao<M, E>, M extends EntityModelDao<E>, E extends Entity> M extractEntityModelFromEntityWithTargetRecordId(final UUID entityId, final UUID auditLogId, final Class<T> sqlDao, final CallContext context, final boolean useHistory) { final M modelDaoThatGivesMeTableName = dbi.onDemand(sqlDao).getById(entityId.toString(), callContextFactory.createInternalCallContextWithoutAccountRecordId(context)); Integer targetRecordId = dbi.withHandle(new HandleCallback<Integer>() { @Override public Integer withHandle(final Handle handle) throws Exception { List<Map<String, Object>> res = handle.select("select target_record_id from audit_log where id = '" + auditLogId.toString() + "';"); return Integer.valueOf(res.get(0).get("target_record_id").toString()); } }); if (useHistory) { Long entityRecordId = nonEntityDao.retrieveHistoryTargetRecordId(Long.valueOf(targetRecordId), modelDaoThatGivesMeTableName.getHistoryTableName()); targetRecordId = new Integer(entityRecordId.intValue()); } return dbi.onDemand(sqlDao).getByRecordId(Long.valueOf(targetRecordId), callContextFactory.createInternalCallContextWithoutAccountRecordId(context)); }
@Override public Plan createOrFindCurrentPlan(final PlanSpecifier spec, final PlanPhasePriceOverridesWithCallContext overrides) throws CatalogApiException { final Plan defaultPlan = super.createOrFindCurrentPlan(spec, null); if (overrides == null || overrides.getOverrides() == null || overrides.getOverrides().isEmpty()) { return defaultPlan; } final InternalCallContext internalCallContext = overrides.getCallContext() != null ? internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(overrides.getCallContext()) : null; return priceOverride.getOrCreateOverriddenPlan(this, defaultPlan, CatalogDateHelper.toUTCDateTime(getEffectiveDate()), overrides.getOverrides(), internalCallContext); }
@Override public Account createAccount(final AccountData data, final CallContext context) throws AccountApiException { // Not transactional, but there is a db constraint on that column if (data.getExternalKey() != null && getIdFromKey(data.getExternalKey(), context) != null) { throw new AccountApiException(ErrorCode.ACCOUNT_ALREADY_EXISTS, data.getExternalKey()); } final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context); if (data.getParentAccountId() != null) { // verify that parent account exists if parentAccountId is not null final ImmutableAccountData immutableAccountData = immutableAccountInternalApi.getImmutableAccountDataById(data.getParentAccountId(), internalContext); if (immutableAccountData == null) { throw new AccountApiException(ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_ID, data.getParentAccountId()); } } final AccountModelDao account = new AccountModelDao(data); if (null != account.getExternalKey() && account.getExternalKey().length() > 255) { throw new AccountApiException(ErrorCode.EXTERNAL_KEY_LIMIT_EXCEEDED); } accountDao.create(account, internalCallContextFactory.createInternalCallContextWithoutAccountRecordId(context)); return new DefaultAccount(account); }
@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; }