private DateTime getSafeFirstCatalogEffectiveDate(@Nullable final DateTime input, final CallContext callContext) { // The effectiveDate for the initial version does not matter too much // Because of #760, we want to make that client passing a approximate date (e.g today.toDateTimeAtStartOfDay()) will find the version final DateTime catalogEffectiveDate = callContext.getCreatedDate().minusDays(1); return (input == null || input.isAfter(catalogEffectiveDate)) ? catalogEffectiveDate : input; }
@Override public DateTime getCreatedDate() { return auditLogModelDao.getCallContext().getCreatedDate(); }
public MutableCallContext(final MutableInternalCallContext internalCallContext) { this.delegate = internalCallContext.toCallContext(null, null); this.createdDate = delegate.getCreatedDate(); }
@Override public CustomFieldModelDao apply(final CustomField input) { // Respect user-specified ID // TODO See https://github.com/killbill/killbill/issues/35 if (input.getId() != null) { return new CustomFieldModelDao(input.getId(), context.getCreatedDate(), context.getCreatedDate(), input.getFieldName(), input.getFieldValue(), input.getObjectId(), input.getObjectType()); } else { return new CustomFieldModelDao(context.getCreatedDate(), input.getFieldName(), input.getFieldValue(), input.getObjectId(), input.getObjectType()); } } });
@Override public void addTag(final UUID objectId, final ObjectType objectType, final UUID tagDefinitionId, final CallContext context) throws TagApiException { if (SystemTags.isSystemTag(tagDefinitionId)) { // TODO Create a proper ErrorCode instaed throw new IllegalStateException(String.format("Failed to add tag for tagDefinitionId='%s': System tags are reserved for the system.", tagDefinitionId)); } final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContext(objectId, objectType, context); final TagModelDao tag = new TagModelDao(context.getCreatedDate(), tagDefinitionId, objectId, objectType); try { tagDao.create(tag, internalContext); } catch (TagApiException e) { // Be lenient here and make the addTag method idempotent if (ErrorCode.TAG_ALREADY_EXISTS.getCode() != e.getCode()) { throw e; } } }
/** * Create an internal call callcontext without populating the account record id * <p/> * This is used for update/delete operations - we don't need the account id in that case - and * also when we don't have an account_record_id column (e.g. tenants, tag_definitions) * * @param context original call callcontext * @return internal call callcontext */ public InternalCallContext createInternalCallContextWithoutAccountRecordId(final CallContext context) { // If tenant id is null, this will default to the default tenant record id (multi-tenancy disabled) final Long tenantRecordId = getTenantRecordIdSafe(context); populateMDCContext(context.getUserToken(), null, tenantRecordId); return new InternalCallContext(tenantRecordId, context, context.getCreatedDate()); }
@Override public void deleteCatalog(final CallContext callContext) throws CatalogApiException { final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContextWithoutAccountRecordId(callContext); try { tenantApi.deleteTenantKey(TenantKey.CATALOG.toString(), callContext); catalogCache.clearCatalog(internalTenantContext); createDefaultEmptyCatalog(callContext.getCreatedDate(), callContext); } catch (final TenantApiException e) { throw new CatalogApiException(e); } }
@Override public boolean cancelWithRequestedDate(final DefaultSubscriptionBase subscription, final DateTime requestedDateWithMs, final CallContext context) throws SubscriptionBaseApiException { final EntitlementState currentState = subscription.getState(); if (currentState == EntitlementState.CANCELLED) { throw new SubscriptionBaseApiException(ErrorCode.SUB_CANCEL_BAD_STATE, subscription.getId(), currentState); } final InternalCallContext internalCallContext = createCallContextFromBundleId(subscription.getBundleId(), context); final Catalog fullCatalog; try { fullCatalog = catalogInternalApi.getFullCatalog(true, true, internalCallContext); final DateTime effectiveDate = (requestedDateWithMs != null) ? DefaultClock.truncateMs(requestedDateWithMs) : context.getCreatedDate(); return doCancelPlan(ImmutableMap.<DefaultSubscriptionBase, DateTime>of(subscription, effectiveDate), fullCatalog, internalCallContext); } catch (final CatalogApiException e) { throw new SubscriptionBaseApiException(e); } }
@Override public DateTime changePlan(final DefaultSubscriptionBase subscription, final EntitlementSpecifier spec, final CallContext context) throws SubscriptionBaseApiException { validateSubscriptionStateForChangePlan(subscription, null); final PlanChangeResult planChangeResult = getPlanChangeResult(subscription, spec.getPlanPhaseSpecifier(), context.getCreatedDate(), context); final DateTime effectiveDate = dryRunChangePlan(subscription, spec, null, planChangeResult.getPolicy(), context); validateEffectiveDate(subscription, effectiveDate); try { doChangePlan(subscription, spec, effectiveDate, context); } catch (final CatalogApiException e) { throw new SubscriptionBaseApiException(e); } return effectiveDate; }
public DefaultCallContext(final CallContext callContext) { super(callContext.getAccountId(), callContext.getTenantId(), callContext.getUserName(), callContext.getCallOrigin(), callContext.getUserType(), callContext.getReasonCode(), callContext.getComments(), callContext.getUserToken()); this.createdDate = callContext.getCreatedDate(); this.updateDate = callContext.getUpdatedDate(); }
.setEffectiveDate(context.getCreatedDate()) .setFromDisk(true)); final DateTime planAlignerEffectiveDate = subscription.getState() == EntitlementState.PENDING ? subscription.getStartDate() : context.getCreatedDate();
.setEffectiveDate(context.getCreatedDate()) .setFromDisk(true)); final DateTime planAlignerEffectiveDate = subscription.getState() == EntitlementState.PENDING ? subscription.getStartDate() : context.getCreatedDate();
/** * Create an internal call callcontext from a call callcontext, and retrieving the account_record_id from another table * * @param objectId the id of the row in the table pointed by object type where to look for account_record_id * @param objectType the object type pointed by this objectId * @param context original call callcontext * @return internal call callcontext from callcontext, with a non null account_record_id (if found) */ public InternalCallContext createInternalCallContext(final UUID objectId, final ObjectType objectType, final CallContext context) { // The callcontext may come from a user API - for security, check we're not doing cross-tenants operations //final Long tenantRecordIdFromObject = retrieveTenantRecordIdFromObject(objectId, objectType); //final Long tenantRecordIdFromContext = getTenantRecordIdSafe(callcontext); //Preconditions.checkState(tenantRecordIdFromContext.equals(tenantRecordIdFromObject), // "tenant of the pointed object (%s) and the callcontext (%s) don't match!", tenantRecordIdFromObject, tenantRecordIdFromContext); final Long tenantRecordId = getTenantRecordIdSafe(context); final Long accountRecordId = getAccountRecordIdSafe(objectId, objectType, context); return createInternalCallContext(tenantRecordId, accountRecordId, context.getUserName(), context.getCallOrigin(), context.getUserType(), context.getUserToken(), context.getReasonCode(), context.getComments(), context.getCreatedDate(), context.getUpdatedDate()); }
final DateTime effectiveTransferDate = transferDate == null ? context.getCreatedDate() : transferDate; if (effectiveTransferDate.isAfter(context.getCreatedDate())) { bundle.getOriginalCreatedDate(), context.getCreatedDate(), context.getCreatedDate()); final List<SubscriptionTransferData> subscriptionTransferDataList = new LinkedList<SubscriptionTransferData>();
private DateTime getSafeFirstCatalogEffectiveDate(@Nullable final DateTime input, final CallContext callContext) { // The effectiveDate for the initial version does not matter too much // Because of #760, we want to make that client passing a approximate date (e.g today.toDateTimeAtStartOfDay()) will find the version final DateTime catalogEffectiveDate = callContext.getCreatedDate().minusDays(1); return (input == null || input.isAfter(catalogEffectiveDate)) ? catalogEffectiveDate : input; }
public MutableCallContext(final MutableInternalCallContext internalCallContext) { this.delegate = internalCallContext.toCallContext(null, null); this.createdDate = delegate.getCreatedDate(); }
protected Response modifyCustomFields(final UUID id, final List<CustomFieldJson> customFields, final CallContext context) throws CustomFieldApiException { final LinkedList<CustomField> input = new LinkedList<CustomField>(); for (final CustomFieldJson cur : customFields) { verifyNonNullOrEmpty(cur.getCustomFieldId(), "CustomFieldJson id needs to be set"); verifyNonNullOrEmpty(cur.getValue(), "CustomFieldJson value needs to be set"); input.add(new StringCustomField(cur.getCustomFieldId(), cur.getName(), cur.getValue(), getObjectType(), id, context.getCreatedDate())); } customFieldUserApi.updateCustomFields(input, context); return Response.status(Status.NO_CONTENT).build(); }
@Override public CustomFieldModelDao apply(final CustomField input) { // Respect user-specified ID // TODO See https://github.com/killbill/killbill/issues/35 if (input.getId() != null) { return new CustomFieldModelDao(input.getId(), context.getCreatedDate(), context.getCreatedDate(), input.getFieldName(), input.getFieldValue(), input.getObjectId(), input.getObjectType()); } else { return new CustomFieldModelDao(context.getCreatedDate(), input.getFieldName(), input.getFieldValue(), input.getObjectId(), input.getObjectType()); } } });
@Override public void deleteCatalog(final CallContext callContext) throws CatalogApiException { final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContextWithoutAccountRecordId(callContext); try { tenantApi.deleteTenantKey(TenantKey.CATALOG.toString(), callContext); catalogCache.clearCatalog(internalTenantContext); createDefaultEmptyCatalog(callContext.getCreatedDate(), callContext); } catch (final TenantApiException e) { throw new CatalogApiException(e); } }
@Override public DateTime changePlan(final DefaultSubscriptionBase subscription, final EntitlementSpecifier spec, final CallContext context) throws SubscriptionBaseApiException { validateSubscriptionStateForChangePlan(subscription, null); final PlanChangeResult planChangeResult = getPlanChangeResult(subscription, spec.getPlanPhaseSpecifier(), context.getCreatedDate(), context); final DateTime effectiveDate = dryRunChangePlan(subscription, spec, null, planChangeResult.getPolicy(), context); validateEffectiveDate(subscription, effectiveDate); try { doChangePlan(subscription, spec, effectiveDate, context); } catch (final CatalogApiException e) { throw new SubscriptionBaseApiException(e); } return effectiveDate; }