@Override public String getUserToken() { if (auditLogModelDao.getCallContext().getUserToken() == null) { return null; } else { return auditLogModelDao.getCallContext().getUserToken().toString(); } }
public Response withSynchronization(final EntitlementCallCompletionCallback<T> callback, final long timeoutSec, final boolean callCompletion, final CallContext callContext) throws SubscriptionApiException, AccountApiException, EntitlementApiException { final CompletionUserRequestEntitlement waiter = callCompletion ? new CompletionUserRequestEntitlement(callContext.getUserToken()) : null; try { if (waiter != null) { killbillHandler.registerCompletionUserRequestWaiter(waiter); } final T operationValue = callback.doOperation(callContext); if (waiter != null && callback.isImmOperation()) { waiter.waitForCompletion(timeoutSec * 1000); } return callback.doResponseOk(operationValue); } catch (InterruptedException e) { return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } catch (TimeoutException e) { return Response.status(Status.fromStatusCode(408)).build(); } finally { if (waiter != null) { killbillHandler.unregisterCompletionUserRequestWaiter(waiter); } } } }
/** * Create an internal call callcontext using an existing account to retrieve tenant and account record ids * <p/> * This is used for r/w operations - we need the account id to populate the account_record_id field * * @param accountId account id * @param context original call callcontext * @return internal call callcontext */ public InternalCallContext createInternalCallContext(final UUID accountId, final CallContext context) { return createInternalCallContext(accountId, ObjectType.ACCOUNT, context.getUserName(), context.getCallOrigin(), context.getUserType(), context.getUserToken(), context.getReasonCode(), context.getComments(), context.getCreatedDate(), context.getUpdatedDate()); }
private void verifyInternalCallContext(final InternalCallContext context) { Assert.assertEquals(context.getCallOrigin(), callContext.getCallOrigin()); Assert.assertEquals(context.getComments(), callContext.getComments()); Assert.assertEquals(context.getCreatedDate(), callContext.getCreatedDate()); Assert.assertEquals(context.getReasonCode(), callContext.getReasonCode()); Assert.assertEquals(context.getUpdatedDate(), callContext.getUpdatedDate()); Assert.assertEquals(context.getCreatedBy(), callContext.getUserName()); Assert.assertEquals(context.getUserToken(), callContext.getUserToken()); Assert.assertEquals(context.getContextUserType(), callContext.getUserType()); // Our test callcontext doesn't have a tenant id Assert.assertEquals(context.getTenantRecordId(), (Long) InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID); } }
@Test(groups = "fast") public void testConstructor() throws Exception { final TableName tableName = TableName.ACCOUNT_EMAIL_HISTORY; final long recordId = Long.MAX_VALUE; final ChangeType changeType = ChangeType.DELETE; final EntityAudit entityAudit = new EntityAudit(tableName, recordId, changeType, null); final AuditLog auditLog = new DefaultAuditLog(new AuditLogModelDao(entityAudit, callContext), ObjectType.ACCOUNT_EMAIL, UUID.randomUUID()); final AuditLogJson auditLogJson = new AuditLogJson(auditLog); Assert.assertEquals(auditLogJson.getChangeType(), changeType.toString()); Assert.assertNotNull(auditLogJson.getChangeDate()); Assert.assertEquals(auditLogJson.getChangedBy(), callContext.getUserName()); Assert.assertEquals(auditLogJson.getReasonCode(), callContext.getReasonCode()); Assert.assertEquals(auditLogJson.getComments(), callContext.getComments()); Assert.assertEquals(auditLogJson.getUserToken(), callContext.getUserToken().toString()); } }
/** * 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 = getTenantRecordId(callcontext); //Preconditions.checkState(tenantRecordIdFromContext.equals(tenantRecordIdFromObject), // "tenant of the pointed object (%s) and the callcontext (%s) don't match!", tenantRecordIdFromObject, tenantRecordIdFromContext); return createInternalCallContext(objectId, objectType, context.getUserName(), context.getCallOrigin(), context.getUserType(), context.getUserToken(), context.getReasonCode(), context.getComments(), context.getCreatedDate(), context.getUpdatedDate()); }
@Test(groups = "slow", enabled= false) public void testOriginalAmountCharged() throws Exception { final Invoice initialInvoice = invoiceUserApi.getInvoice(invoiceId, callContext); final BigDecimal originalAmountCharged = initialInvoice.getOriginalChargedAmount(); final BigDecimal amountCharged = initialInvoice.getChargedAmount(); Assert.assertEquals(originalAmountCharged.compareTo(amountCharged), 0); ((ClockMock) clock).addDays(1); // Sleep at least one sec to make sure created_date for the external charge is different than the created date for the invoice itself CallContext newCallContextLater = new DefaultCallContext(callContext.getTenantId(), callContext.getUserName(), callContext.getCallOrigin(), callContext.getUserType(), callContext.getUserToken(), clock); // Post an external charge final BigDecimal externalChargeAmount = BigDecimal.TEN; final InvoiceItem externalChargeInvoiceItem = invoiceUserApi.insertExternalChargeForInvoice(accountId, invoiceId, externalChargeAmount, UUID.randomUUID().toString(), clock.getUTCToday(), accountCurrency, newCallContextLater); final Invoice newInvoice = invoiceUserApi.getInvoice(invoiceId, callContext); final BigDecimal newOriginalAmountCharged = newInvoice.getOriginalChargedAmount(); final BigDecimal newAmountCharged = newInvoice.getChargedAmount(); final BigDecimal expectedChargedAmount = newInvoice.getOriginalChargedAmount().add(externalChargeInvoiceItem.getAmount()); Assert.assertEquals(originalAmountCharged.compareTo(newOriginalAmountCharged), 0); Assert.assertEquals(newAmountCharged.compareTo(expectedChargedAmount), 0); }