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