Search in sources :

Example 1 with Internal

use of io.spine.annotation.Internal in project core-java by SpineEventEngine.

the class Commands method rejectWithCause.

/**
 * Produces a {@link Rejection} for the given {@link Command} based on the given
 * {@linkplain ThrowableMessage cause}.
 *
 * <p>The given {@link Throwable} should be
 * {@linkplain Rejections#causedByRejection caused by a Rejection} or
 * an {@link IllegalArgumentException} is thrown.
 *
 * @param command the command to reject
 * @param cause the rejection cause (may be wrapped into other kinds of {@code Throwable})
 * @return a {@link Rejection} for the given command
 * @throws IllegalArgumentException upon an invalid rejection cause
 */
@Internal
public static Rejection rejectWithCause(Command command, Throwable cause) throws IllegalArgumentException {
    checkNotNull(command);
    checkNotNull(cause);
    final ThrowableMessage rejectionThrowable = Rejections.getCause(cause);
    final Rejection rejection = Rejections.toRejection(rejectionThrowable, command);
    return rejection;
}
Also used : ThrowableMessage(io.spine.base.ThrowableMessage) Internal(io.spine.annotation.Internal)

Example 2 with Internal

use of io.spine.annotation.Internal in project core-java by SpineEventEngine.

the class CommandFactory method createWithContext.

/**
 * Creates a new {@code Command} with the passed {@code message} and {@code context}.
 *
 * @param message the command message
 * @param context the command context
 * @return a new command instance
 * @throws ValidationException if the passed message does not satisfy the constraints
 *                             set for it in its Protobuf definition
 */
@Internal
public Command createWithContext(Message message, CommandContext context) throws ValidationException {
    checkNotNull(message);
    checkNotNull(context);
    checkValid(message);
    final Command result = createCommand(message, context);
    return result;
}
Also used : Command(io.spine.core.Command) Internal(io.spine.annotation.Internal)

Example 3 with Internal

use of io.spine.annotation.Internal in project core-java by SpineEventEngine.

the class CommandFactory method createBasedOnContext.

/**
 * Creates new {@code Command} with the passed message, using the existing context.
 *
 * <p>The produced command is created with a {@code CommandContext} instance, copied from
 * the given one, but with the current time set as a context timestamp.
 *
 * @param message the command message
 * @param context the command context to use as a base for the new command
 * @return new command instance
 * @throws ValidationException if the passed message does not satisfy the constraints
 *                             set for it in its Protobuf definition
 */
@Internal
public Command createBasedOnContext(Message message, CommandContext context) throws ValidationException {
    checkNotNull(message);
    checkNotNull(context);
    checkValid(message);
    final CommandContext newContext = contextBasedOn(context);
    final Command result = createCommand(message, newContext);
    return result;
}
Also used : CommandContext(io.spine.core.CommandContext) Command(io.spine.core.Command) Internal(io.spine.annotation.Internal)

Example 4 with Internal

use of io.spine.annotation.Internal in project core-java by SpineEventEngine.

the class FailureThrowable method toFailure.

/**
     * Converts this {@code FailureThrowable} into {@link Failure}.
     *
     * @param command the command which caused the failure
     */
@Internal
public Failure toFailure(Command command) {
    final Any packedMessage = pack(failureMessage);
    final FailureContext context = createContext(command);
    final FailureId id = Failures.generateId(command.getId());
    return Failure.newBuilder().setId(id).setMessage(packedMessage).setContext(context).build();
}
Also used : Any(com.google.protobuf.Any) Internal(io.spine.annotation.Internal)

Example 5 with Internal

use of io.spine.annotation.Internal in project core-java by SpineEventEngine.

the class RecordStorage method entityLifecycleColumns.

/**
 * Returns a {@code Map} of {@linkplain EntityColumn columns} corresponded to the
 * {@link LifecycleFlagField lifecycle storage fields} of the {@link Entity} class managed by this storage.
 *
 * @return a {@code Map} of managed {@link Entity} lifecycle columns
 * @throws IllegalArgumentException if a lifecycle field is not present in the managed {@link Entity} class
 * @see EntityColumn
 * @see Columns
 * @see LifecycleFlagField
 */
@Internal
public Map<String, EntityColumn> entityLifecycleColumns() {
    final HashMap<String, EntityColumn> lifecycleColumns = new HashMap<>();
    for (LifecycleFlagField field : LifecycleFlagField.values()) {
        final String name = field.name();
        final EntityColumn column = entityColumnCache().findColumn(name);
        lifecycleColumns.put(name, column);
    }
    return lifecycleColumns;
}
Also used : EntityColumn(io.spine.server.entity.storage.EntityColumn) HashMap(java.util.HashMap) Internal(io.spine.annotation.Internal)

Aggregations

Internal (io.spine.annotation.Internal)6 Command (io.spine.core.Command)2 Any (com.google.protobuf.Any)1 ThrowableMessage (io.spine.base.ThrowableMessage)1 CommandContext (io.spine.core.CommandContext)1 EntityColumn (io.spine.server.entity.storage.EntityColumn)1 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)1 HashMap (java.util.HashMap)1 CheckReturnValue (javax.annotation.CheckReturnValue)1