private InternalCallContext createCallContext() { // TODO information about accountRecordId and tenatRecordId return internalCallContextFactory.createInternalCallContext(InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID, null, "ChunkWriter", CallOrigin.INTERNAL, UserType.SYSTEM, null); } }
private InternalCallContext createCallContext() { // TODO add teantRecordId and accountRecordId return internalCallContextFactory.createInternalCallContext(InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID, null, "TimelineAggregator", CallOrigin.INTERNAL, UserType.SYSTEM, null); } }
@Inject public DefaultMeterService(final BackgroundDBChunkWriter backgroundDBChunkWriter, final TimelineEventHandler timelineEventHandler, final InternalCallContextFactory internalCallContextFactory, final TimelineAggregator timelineAggregator, final MeterConfig config) { this.backgroundDBChunkWriter = backgroundDBChunkWriter; this.timelineEventHandler = timelineEventHandler; this.timelineAggregator = timelineAggregator; this.config = config; this.internalCallContext = internalCallContextFactory.createInternalCallContext(InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID, null, "MeterService", CallOrigin.INTERNAL, UserType.SYSTEM, null); }
@Override public void removeTags(final UUID objectId, final ObjectType objectType, final Collection<UUID> tagDefinitionIds, final CallContext context) throws TagApiException { // TODO: consider making this batch for (final UUID tagDefinitionId : tagDefinitionIds) { tagDao.deleteTag(objectId, objectType, tagDefinitionId, internalCallContextFactory.createInternalCallContext(objectId, objectType, context)); } }
@Override public void exportDataForAccount(final UUID accountId, final DatabaseExportOutputStream out, final CallContext context) { final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContext(accountId, context); exportDao.exportDataForAccount(out, internalContext); }
@Override public void updateExternalKey(final UUID uuid, final String newExternalKey, final CallContext callContext) { final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContext(callContext); subscriptionBaseInternalApi.updateExternalKey(uuid, newExternalKey, internalContext); }
@Override public void handleReadyNotification(final NotificationEvent notificationKey, final DateTime eventDateTime, final UUID userToken, final Long accountRecordId, final Long tenantRecordId) { if (!(notificationKey instanceof PaymentRetryNotificationKey)) { log.error("Payment service got an unexpected notification type {}", notificationKey.getClass().getName()); return; } final PaymentRetryNotificationKey key = (PaymentRetryNotificationKey) notificationKey; final InternalCallContext callContext = internalCallContextFactory.createInternalCallContext(tenantRecordId, accountRecordId, PAYMENT_RETRY_SERVICE, CallOrigin.INTERNAL, UserType.SYSTEM, userToken); retry(key.getUuidKey(), callContext); } });
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); }
@Override public InvoiceItem insertInvoiceItemAdjustment(final UUID accountId, final UUID invoiceId, final UUID invoiceItemId, final LocalDate effectiveDate, @Nullable final BigDecimal amount, @Nullable final Currency currency, final CallContext context) throws InvoiceApiException { if (amount != null && amount.compareTo(BigDecimal.ZERO) <= 0) { throw new InvoiceApiException(ErrorCode.INVOICE_ITEM_ADJUSTMENT_AMOUNT_SHOULD_BE_POSITIVE, amount); } final InvoiceItemModelDao adjustment = dao.insertInvoiceItemAdjustment(accountId, invoiceId, invoiceItemId, effectiveDate, amount, currency, internalCallContextFactory.createInternalCallContext(accountId, context)); return InvoiceItemFactory.fromModelDao(adjustment); }
@Override public void notifyPendingRefundOfStateChanged(final Account account, final UUID refundId, final boolean isSuccess, final CallContext context) throws PaymentApiException { refundProcessor.notifyPendingRefundOfStateChanged(account, refundId, isSuccess, internalCallContextFactory.createInternalCallContext(account.getId(), context)); }
@Override public Refund createRefund(final Account account, final UUID paymentId, final BigDecimal refundAmount, final CallContext context) throws PaymentApiException { if (refundAmount == null || refundAmount.compareTo(BigDecimal.ZERO) <= 0) { throw new PaymentApiException(ErrorCode.PAYMENT_REFUND_AMOUNT_NEGATIVE_OR_NULL); } return refundProcessor.createRefund(account, paymentId, refundAmount, false, ImmutableMap.<UUID, BigDecimal>of(), internalCallContextFactory.createInternalCallContext(account.getId(), context)); }
@Override public Refund createRefundWithItemsAdjustments(final Account account, final UUID paymentId, final Map<UUID, BigDecimal> invoiceItemIdsWithAmounts, final CallContext context) throws PaymentApiException { return refundProcessor.createRefund(account, paymentId, null, true, invoiceItemIdsWithAmounts, internalCallContextFactory.createInternalCallContext(account.getId(), context)); }
@Override public List<PaymentMethod> refreshPaymentMethods(final Account account, final CallContext context) throws PaymentApiException { final InternalCallContext callContext = internalCallContextFactory.createInternalCallContext(account.getId(), context); final List<PaymentMethod> paymentMethods = new LinkedList<PaymentMethod>(); for (final String pluginName : methodProcessor.getAvailablePlugins()) { paymentMethods.addAll(methodProcessor.refreshPaymentMethods(pluginName, account, callContext)); } return paymentMethods; } }
@Override public InvoiceItem insertCreditForInvoice(final UUID accountId, final UUID invoiceId, final BigDecimal amount, final LocalDate effectiveDate, final Currency currency, final CallContext context) throws InvoiceApiException { if (amount == null || amount.compareTo(BigDecimal.ZERO) <= 0) { throw new InvoiceApiException(ErrorCode.CREDIT_AMOUNT_INVALID, amount); } final InvoiceItemModelDao credit = dao.insertCredit(accountId, invoiceId, amount, effectiveDate, currency, internalCallContextFactory.createInternalCallContext(accountId, context)); return InvoiceItemFactory.fromModelDao(credit); }
@Override public void removeCustomFields(final List<CustomField> customFields, final CallContext context) throws CustomFieldApiException { // TODO make it transactional for (final CustomField cur : customFields) { customFieldDao.deleteCustomField(cur.getId(), internalCallContextFactory.createInternalCallContext(cur.getObjectId(), cur.getObjectType(), context)); } }
@Subscribe public void handleEntitlementTransition(final EffectiveEntitlementInternalEvent event) { try { final InternalCallContext context = internalCallContextFactory.createInternalCallContext(event.getSearchKey2(), event.getSearchKey1(), "SubscriptionBaseTransition", CallOrigin.INTERNAL, UserType.SYSTEM, event.getUserToken()); dispatcher.processAccount(event.getAccountId(), event.getEffectiveTransitionTime(), false, context); } catch (InvoiceApiException e) { log.error(e.getMessage()); } }
@Override public TagDefinition createTagDefinition(final String definitionName, final String description, final CallContext context) throws TagDefinitionApiException { final TagDefinitionModelDao tagDefinitionModelDao = tagDefinitionDao.create(definitionName, description, internalCallContextFactory.createInternalCallContext(context)); return new DefaultTagDefinition(tagDefinitionModelDao, TagModelDaoHelper.isControlTag(tagDefinitionModelDao.getName())); }
@BeforeMethod(groups = "slow") public void setUp() throws Exception { account = invoiceUtil.createAccount(callContext); context = internalCallContextFactory.createInternalCallContext(account.getId(), callContext); }
@Subscribe public void process_AUTO_INVOICING_OFF_removal(final ControlTagDeletionInternalEvent event) { if (event.getTagDefinition().getName().equals(ControlTagType.AUTO_INVOICING_OFF.toString()) && event.getObjectType() == ObjectType.ACCOUNT) { final UUID accountId = event.getObjectId(); final InternalCallContext context = internalCallContextFactory.createInternalCallContext(event.getSearchKey2(), event.getSearchKey1(), "InvoiceTagHandler", CallOrigin.INTERNAL, UserType.SYSTEM, event.getUserToken()); processUnpaid_AUTO_INVOICING_OFF_invoices(accountId, context); } }
@Override public void tagInvoiceAsNotWrittenOff(final UUID invoiceId, final CallContext context) throws TagApiException, InvoiceApiException { // Note: the tagApi is audited final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContext(invoiceId, ObjectType.INVOICE, context); tagApi.removeTag(invoiceId, ObjectType.INVOICE, ControlTagType.WRITTEN_OFF.getId(), internalContext); // Retrieve the invoice for the account id final Invoice invoice = new DefaultInvoice(dao.getById(invoiceId, internalContext)); // This is for overdue notifyBusOfInvoiceAdjustment(invoiceId, invoice.getAccountId(), internalContext); }