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;
}
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;
}
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;
}
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();
}
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;
}
Aggregations