Search in sources :

Example 51 with Any

use of com.google.protobuf.Any in project core-java by SpineEventEngine.

the class CommandFactory method createCommand.

/**
 * Creates a command instance with the given {@code message} and {@code context}.
 *
 * <p>If an instance of {@link Any} is passed as the {@code message} parameter, the packed
 * message is used for the command construction.
 *
 * <p>The ID of the new command instance is automatically generated.
 *
 * @param message the command message
 * @param context the context of the command
 * @return a new command
 */
private static Command createCommand(Message message, CommandContext context) {
    final Any packed = AnyPacker.pack(message);
    final Command.Builder result = Command.newBuilder().setId(Commands.generateId()).setMessage(packed).setContext(context);
    return result.build();
}
Also used : Command(io.spine.core.Command) Any(com.google.protobuf.Any)

Example 52 with Any

use of com.google.protobuf.Any in project core-java by SpineEventEngine.

the class QueryBuilder method build.

/**
 * Generates a new instance of {@link Query} regarding all the set parameters.
 *
 * @return the built {@link Query}
 */
public Query build() {
    final FieldMask mask = composeMask();
    final Set<Any> entityIds = composeIdPredicate();
    final Query result = queryFactory.composeQuery(targetType, entityIds, columns, mask);
    return result;
}
Also used : Any(com.google.protobuf.Any) FieldMask(com.google.protobuf.FieldMask)

Example 53 with Any

use of com.google.protobuf.Any in project core-java by SpineEventEngine.

the class Targets method composeTarget.

static Target composeTarget(Class<? extends Message> entityClass, @Nullable Set<? extends Message> ids, @Nullable Set<CompositeColumnFilter> columnFilters) {
    final boolean includeAll = (ids == null && columnFilters == null);
    final Set<? extends Message> entityIds = nullToEmpty(ids);
    final Set<CompositeColumnFilter> entityColumnValues = nullToEmpty(columnFilters);
    final EntityIdFilter.Builder idFilterBuilder = EntityIdFilter.newBuilder();
    if (!includeAll) {
        for (Message rawId : entityIds) {
            final Any packedId = AnyPacker.pack(rawId);
            final EntityId entityId = EntityId.newBuilder().setId(packedId).build();
            idFilterBuilder.addIds(entityId);
        }
    }
    final EntityIdFilter idFilter = idFilterBuilder.build();
    final EntityFilters filters = EntityFilters.newBuilder().setIdFilter(idFilter).addAllFilter(entityColumnValues).build();
    final String typeUrl = TypeUrl.of(entityClass).value();
    final Target.Builder builder = Target.newBuilder().setType(typeUrl);
    if (includeAll) {
        builder.setIncludeAll(true);
    } else {
        builder.setFilters(filters);
    }
    return builder.build();
}
Also used : Message(com.google.protobuf.Message) Any(com.google.protobuf.Any)

Example 54 with Any

use of com.google.protobuf.Any in project core-java by SpineEventEngine.

the class ProcessManagerShould method entityAlreadyArchived.

private static RejectionEnvelope entityAlreadyArchived(Class<? extends Message> commandMessageCls) {
    final Any id = Identifier.pack(ProcessManagerShould.class.getName());
    final EntityAlreadyArchived rejectionMessage = EntityAlreadyArchived.newBuilder().setEntityId(id).build();
    final Command command = ACommand.withMessage(Sample.messageOfType(commandMessageCls));
    final Rejection rejection = Rejections.createRejection(rejectionMessage, command);
    return RejectionEnvelope.of(rejection);
}
Also used : Rejection(io.spine.core.Rejection) Command(io.spine.core.Command) ACommand(io.spine.server.commandbus.Given.ACommand) EntityAlreadyArchived(io.spine.server.entity.rejection.StandardRejections.EntityAlreadyArchived) Any(com.google.protobuf.Any)

Example 55 with Any

use of com.google.protobuf.Any in project core-java by SpineEventEngine.

the class ProjectionStorageShould method checkProjectIdIsInList.

@SuppressWarnings("BreakStatement")
private static Project checkProjectIdIsInList(EntityRecord project, List<ProjectId> ids) {
    final Any packedState = project.getState();
    final Project state = AnyPacker.unpack(packedState);
    final ProjectId id = state.getId();
    boolean isIdPresent = false;
    for (ProjectId genericId : ids) {
        isIdPresent = genericId.equals(id);
        if (isIdPresent) {
            break;
        }
    }
    assertTrue(isIdPresent);
    return state;
}
Also used : Project(io.spine.test.storage.Project) ProjectId(io.spine.test.storage.ProjectId) Any(com.google.protobuf.Any)

Aggregations

Any (com.google.protobuf.Any)155 Test (org.junit.Test)44 Message (com.google.protobuf.Message)30 TypeConverter.toAny (io.spine.protobuf.TypeConverter.toAny)27 EntityRecord (io.spine.server.entity.EntityRecord)24 TypeUrl (io.spine.type.TypeUrl)15 Version (io.spine.core.Version)11 Customer (io.spine.test.commandservice.customer.Customer)11 GivenVersion (io.spine.core.given.GivenVersion)9 EntityRecordWithColumns (io.spine.server.entity.storage.EntityRecordWithColumns)8 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)8 CustomerId (io.spine.test.commandservice.customer.CustomerId)8 FieldMask (com.google.protobuf.FieldMask)7 Query (io.spine.client.Query)7 Project (io.spine.test.storage.Project)7 EntityId (io.spine.client.EntityId)6 QueryResponse (io.spine.client.QueryResponse)6 Ack (io.spine.core.Ack)6 Command (io.spine.core.Command)6 EntityFilters (io.spine.client.EntityFilters)5