/** * Creates a new result for a status code. * * @param status The status code indicating the outcome of the request. * @param <T> The type of the payload that is conveyed in the result. * @return The result. */ public static <T> CredentialsResult<T> from(final int status) { return new CredentialsResult<>(status, null, CacheDirective.noCacheDirective()); }
/** * Adds a property for the tenant identifier. * <p> * The property will only be added if the AMQP message contains * a non-{@code null} tenant identifier. * * @param msg The AMQP message to retrieve the value from. * @return This message for chaining. */ public EventBusMessage setTenant(final Message msg) { setTenant(MessageHelper.getTenantId(msg)); return this; }
/** * Adds a property for the request/response payload. * <p> * The property will only be added if the AMQP message contains * a JSON payload. * * @param msg The AMQP message to retrieve the payload from. * @return This message for chaining. */ public EventBusMessage setJsonPayload(final Message msg) { setJsonPayload(MessageHelper.getJsonPayload(msg)); return this; }
private static EventBusMessage createRequest(final TenantConstants.TenantAction action, final JsonObject payload) { return EventBusMessage.forOperation(action.toString()) .setTenant(TEST_TENANT) .setJsonPayload(payload); }
private static EventBusMessage createRequestForPayload(final CredentialsConstants.CredentialsAction operation, final JsonObject payload) { return EventBusMessage.forOperation(operation.name()) .setTenant(TEST_TENANT) .setJsonPayload(payload); }
/** * Adds a property for the device identifier. * <p> * The property will only be added if the AMQP message contains * a non-{@code null} device identifier. * * @param msg The AMQP message to retrieve the value from. * @return This message for chaining. */ public EventBusMessage setDeviceId(final Message msg) { setDeviceId(MessageHelper.getDeviceId(msg)); return this; }
/** * Adds a caching directive to an AMQP 1.0 message. * <p> * The directive is put to the message's <em>application-properties</em> under key * {@link #APP_PROPERTY_CACHE_CONTROL}. * * @param msg The message to add the directive to. * @param cacheDirective The cache directive. * @throws NullPointerException if any of the parameters are {@code null}. */ public static void addCacheDirective(final Message msg, final CacheDirective cacheDirective) { addProperty(msg, APP_PROPERTY_CACHE_CONTROL, cacheDirective.toString()); }
/** * Creates a new result for a status code and payload. * * @param status The status code indicating the outcome of the request. * @param payload The payload to convey to the sender of the request. * @param <T> The type of the payload conveyed in the result. * @return The result. */ public static <T> TenantResult<T> from(final int status, final T payload) { return new TenantResult<>(status, payload, null); }
/** * Adds a property for the tenant identifier. * <p> * The property will only be added if the value is not {@code null}. * * @param tenantId The tenant identifier. * @return This message for chaining. */ public EventBusMessage setTenant(final String tenantId) { setProperty(MessageHelper.APP_PROPERTY_TENANT_ID, tenantId); return this; }
/** * Gets the value of the tenant identifier property. * * @return The value or {@code null} if not set. */ public String getTenant() { return getProperty(MessageHelper.APP_PROPERTY_TENANT_ID); }
/** * Checks if this credentials object contains secrets that comply with the Credentials * API specification. * * @throws IllegalStateException if no secrets are set or any of the secrets' not-before * and not-after properties are malformed. */ public void checkSecrets() { checkSecrets((secretType, secret) -> {}); }
/** * Creates an empty execution context. * * @return The new context. */ public static ExecutionContext empty() { return new MapBasedExecutionContext(); }
private static EventBusMessage createRequest(final TenantConstants.TenantAction action, final JsonObject payload) { return EventBusMessage.forOperation(action.toString()) .setTenant(TEST_TENANT) .setJsonPayload(payload); }
private static EventBusMessage createRequestForPayload(final CredentialsConstants.CredentialsAction operation, final JsonObject payload) { return EventBusMessage.forOperation(operation.name()) .setTenant(TEST_TENANT) .setJsonPayload(payload); }
/** * Adds a property for the device identifier. * <p> * The property will only be added if the AMQP message contains * a non-{@code null} device identifier. * * @param msg The AMQP message to retrieve the value from. * @return This message for chaining. */ public EventBusMessage setDeviceId(final Message msg) { setDeviceId(MessageHelper.getDeviceId(msg)); return this; }
/** * Adds a caching directive to an AMQP 1.0 message. * <p> * The directive is put to the message's <em>application-properties</em> under key * {@link #APP_PROPERTY_CACHE_CONTROL}. * * @param msg The message to add the directive to. * @param cacheDirective The cache directive. * @throws NullPointerException if any of the parameters are {@code null}. */ public static void addCacheDirective(final Message msg, final CacheDirective cacheDirective) { addProperty(msg, APP_PROPERTY_CACHE_CONTROL, cacheDirective.toString()); }
/** * Adds a property for the tenant identifier. * <p> * The property will only be added if the AMQP message contains * a non-{@code null} tenant identifier. * * @param msg The AMQP message to retrieve the value from. * @return This message for chaining. */ public EventBusMessage setTenant(final Message msg) { setTenant(MessageHelper.getTenantId(msg)); return this; }
/** * Creates a new result for a status code. * * @param status The status code indicating the outcome of the request. * @param <T> The type of the payload that is conveyed in the result. * @return The result. */ public static <T> CredentialsResult<T> from(final int status) { return new CredentialsResult<>(status, null, CacheDirective.noCacheDirective()); }
/** * Adds a property for the request/response payload. * <p> * The property will only be added if the AMQP message contains * a JSON payload. * * @param msg The AMQP message to retrieve the payload from. * @return This message for chaining. */ public EventBusMessage setJsonPayload(final Message msg) { setJsonPayload(MessageHelper.getJsonPayload(msg)); return this; }
/** * Creates a new result for a status code and payload. * <p> * This method simply invokes {@link #from(int, Object, CacheDirective)} * with {@link CacheDirective#noCacheDirective()}. * * @param status The status code indicating the outcome of the request. * @param payload The payload to convey to the sender of the request. * @param <T> The type of the payload that is conveyed in the result. * @return The result. */ public static <T> CredentialsResult<T> from(final int status, final T payload) { return new CredentialsResult<>(status, payload, CacheDirective.noCacheDirective()); }