private Long getTenantRecordIdSafe(final TenantContext context) { // Default to single default tenant (e.g. single tenant mode) // TODO Extract this convention (e.g. BusinessAnalyticsBase needs to know about it) if (context.getTenantId() == null) { return INTERNAL_TENANT_RECORD_ID; } else { // This is always safe (the tenant context was created from the api key and secret) return getTenantRecordIdUnsafe(context.getTenantId(), ObjectType.TENANT); } }
private Long getAccountRecordIdSafe(final UUID objectId, final ObjectType objectType, final TenantContext context) { if (objectBelongsToTheRightTenant(objectId, objectType, context)) { return getAccountRecordIdUnsafe(objectId, objectType); } else { throw new IllegalStateException(String.format("Object id=%s type=%s doesn't belong to tenant id=%s", objectId, objectType, context.getTenantId())); } }
private boolean objectBelongsToTheRightTenant(final UUID objectId, final ObjectType objectType, final TenantContext context) throws ObjectDoesNotExist { final Long realTenantRecordId = getTenantRecordIdSafe(context); if (realTenantRecordId == null) { throw new ObjectDoesNotExist(String.format("Tenant id=%s doesn't exist!", context.getTenantId())); } return objectBelongsToTheRightTenant(objectId, objectType, realTenantRecordId); }
@Override public UUID getTenantId() { return delegate.getTenantId(); }
@Override public UUID getTenantId() { return delegate.getTenantId(); }
private Long getTenantRecordIdSafe(final TenantContext context) { // Default to single default tenant (e.g. single tenant mode) // TODO Extract this convention (e.g. BusinessAnalyticsBase needs to know about it) if (context.getTenantId() == null) { return INTERNAL_TENANT_RECORD_ID; } else { // This is always safe (the tenant context was created from the api key and secret) return getTenantRecordIdUnsafe(context.getTenantId(), ObjectType.TENANT); } }
protected Long getTenantRecordId(final TenantContext context) throws OSGIServiceNotAvailable { if (context.getTenantId() == null) { return INTERNAL_TENANT_RECORD_ID; } else { final RecordIdApi recordIdUserApi = getRecordIdUserApi(); return recordIdUserApi.getRecordId(context.getTenantId(), ObjectType.TENANT, context); } }
private Long getAccountRecordIdSafe(final UUID objectId, final ObjectType objectType, final TenantContext context) { if (objectBelongsToTheRightTenant(objectId, objectType, context)) { return getAccountRecordIdUnsafe(objectId, objectType); } else { throw new IllegalStateException(String.format("Object id=%s type=%s doesn't belong to tenant id=%s", objectId, objectType, context.getTenantId())); } }
@Override public List<PaymentTransactionInfoPlugin> getPaymentInfo(final UUID kbAccountId, final UUID kbPaymentId, final Iterable<PluginProperty> properties, final TenantContext context) throws PaymentPluginApiException { final List<RESP_R> records; try { records = dao.getResponses(kbPaymentId, context.getTenantId()); } catch (final SQLException e) { throw new PaymentPluginApiException("Unable to retrieve payments for kbPaymentId " + kbPaymentId, e); } return Lists.<RESP_R, PaymentTransactionInfoPlugin>transform(records, new Function<RESP_R, PaymentTransactionInfoPlugin>() { @Override public PaymentTransactionInfoPlugin apply(final RESP_R record) { return buildPaymentTransactionInfoPlugin(record); } }); }
private boolean objectBelongsToTheRightTenant(final UUID objectId, final ObjectType objectType, final TenantContext context) throws ObjectDoesNotExist { final Long realTenantRecordId = getTenantRecordIdSafe(context); if (realTenantRecordId == null) { throw new ObjectDoesNotExist(String.format("Tenant id=%s doesn't exist!", context.getTenantId())); } return objectBelongsToTheRightTenant(objectId, objectType, realTenantRecordId); }
@Override public List<String> answer(final InvocationOnMock invocation) throws Throwable { if (!"PLUGIN_CONFIG_test".equals(invocation.getArguments()[0])) { return ImmutableList.<String>of(); } final TenantContext context = (TenantContext) invocation.getArguments()[1]; if (kbTenantIdA.equals(context.getTenantId())) { return tenantKvsA; } else if (kbTenantIdB.equals(context.getTenantId())) { return tenantKvsB; } else { return ImmutableList.<String>of(); } } });
@Test(groups = "fast") public void testCreateWithTenantId() throws Exception { final UUID kbTenantId = UUID.randomUUID(); final TenantContext context = new PluginTenantContext(null, kbTenantId); Assert.assertEquals(context.getTenantId(), kbTenantId); } }
protected Catalog getCatalog(final TenantContext context) throws OSGIServiceNotAvailable { final CatalogUserApi catalogUserApi = getCatalogUserApi(); try { return catalogUserApi.getCatalog(null, null, context); } catch (final CatalogApiException e) { logService.log(LogService.LOG_INFO, "Unable to retrieve catalog for tenant " + context.getTenantId(), e); return null; } }
@Override public PaymentMethodPlugin getPaymentMethodDetail(final UUID kbAccountId, final UUID kbPaymentMethodId, final Iterable<PluginProperty> properties, final TenantContext context) throws PaymentPluginApiException { final PM_R record; try { record = dao.getPaymentMethod(kbPaymentMethodId, context.getTenantId()); } catch (final SQLException e) { throw new PaymentPluginApiException("Unable to retrieve payment method for kbPaymentMethodId " + kbPaymentMethodId, e); } return buildPaymentMethodPlugin(record); }
@javax.ws.rs.core.Context final HttpServletRequest request) { final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final Long tenantRecordId = recordIdApi.getRecordId(tenantContext.getTenantId(), ObjectType.TENANT, tenantContext); final Long accountRecordId = accountId == null ? null : recordIdApi.getRecordId(accountId, ObjectType.ACCOUNT, tenantContext);
private boolean waitForNotificationToComplete(final ServletRequest request, final Long timeoutSec) { final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final Long tenantRecordId = recordIdApi.getRecordId(tenantContext.getTenantId(), ObjectType.TENANT, tenantContext); int nbTryLeft = timeoutSec != null ? timeoutSec.intValue() : 0; boolean areAllNotificationsProcessed = false; try { while (!areAllNotificationsProcessed && nbTryLeft > 0) { areAllNotificationsProcessed = areAllNotificationsProcessed(tenantRecordId); // Processing of notifications may have triggered bus events, which may trigger other notifications // effective immediately. Hence, we need to make sure all bus events have been processed too. areAllNotificationsProcessed = areAllNotificationsProcessed && areAllBusEventsProcessed(tenantRecordId); // We do a re-check of the notification queues in case of race conditions. areAllNotificationsProcessed = areAllNotificationsProcessed && areAllNotificationsProcessed(tenantRecordId); areAllNotificationsProcessed = areAllNotificationsProcessed && areAllBusEventsProcessed(tenantRecordId); if (!areAllNotificationsProcessed) { Thread.sleep(MILLIS_IN_SEC); nbTryLeft--; } } } catch (final InterruptedException ignore) { } if (!areAllNotificationsProcessed) { log.warn("TestResource: there are more notifications or bus events to process, consider increasing the timeout (currently {}s)", timeoutSec); } return areAllNotificationsProcessed; }
@BeforeMethod(groups = "fast") public void setUp() throws Exception { externalBus = mock(PersistentBus.class); internalCallContextFactory = mock(InternalCallContextFactory.class); beatrixListener = new BeatrixListener(externalBus, internalCallContextFactory); objectMapper = mock(ObjectMapper.class); beatrixListener.objectMapper = objectMapper; InternalCallContext internalContext = new InternalCallContext( TENANT_RECORD_ID, ACCOUNT_RECORD_ID, null, null, USER_TOKEN, null, null, null, null, null, null, null ); when(internalCallContextFactory.createInternalCallContext( SEARCH_KEY_2, SEARCH_KEY_1, "BeatrixListener", CallOrigin.INTERNAL, UserType.SYSTEM, USER_TOKEN)).thenReturn(internalContext); tenantContext = mock(TenantContext.class); when(tenantContext.getTenantId()).thenReturn(TENANT_ID); when(internalCallContextFactory.createTenantContext(internalContext)).thenReturn(tenantContext); }
dryRun, properties, context.getTenantId()); additionalTaxInvoiceItems.addAll(taxInvoiceItems);
final Tenant currentTenant = tenantApi.getTenantById(tenantContext.getTenantId()); final Long tenantRecordId = recordIdApi.getRecordId(tenantContext.getTenantId(), ObjectType.TENANT, tenantContext);
Assert.assertEquals(calculatorNewInvoice.getId(), invoice2.getId()); Assert.assertEquals(calculatorPluginProperties, pluginProperties); Assert.assertEquals(kbTenantId, context.getTenantId());