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;
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class ProjectionStorageShould method fillStorage.
// Converter nullability issues
@SuppressWarnings("ConstantConditions")
private List<ProjectId> fillStorage(int count) {
final List<ProjectId> ids = new LinkedList<>();
for (int i = 0; i < count; i++) {
final ProjectId id = newId();
final Project state = Given.project(id, format("project-%d", i));
final Any packedState = AnyPacker.pack(state);
final EntityRecord rawRecord = EntityRecord.newBuilder().setState(packedState).setVersion(GivenVersion.withNumber(1)).build();
final EntityRecordWithColumns record = withLifecycleColumns(rawRecord);
storage.write(id, record);
ids.add(id);
}
return ids;
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class ERepositoryShould method convert_type_query_to_EntityFilters.
@Test
public void convert_type_query_to_EntityFilters() {
final String typeName = " com.example.EventType ";
final EventFilter validFilter = filterForType(typeName);
final EventFilter invalidFilter = filterForType(" ");
final EventStreamQuery query = EventStreamQuery.newBuilder().addFilter(validFilter).addFilter(invalidFilter).build();
final EntityFilters entityFilters = toEntityFilters(query);
assertEquals(1, entityFilters.getFilterCount());
final CompositeColumnFilter compositeFilter = entityFilters.getFilter(0);
final List<ColumnFilter> columnFilters = compositeFilter.getFilterList();
assertEquals(CompositeOperator.EITHER, compositeFilter.getOperator());
assertEquals(1, columnFilters.size());
final Any typeNameAsAny = columnFilters.get(0).getValue();
assertEquals(typeName, toObject(typeNameAsAny, String.class));
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class Stand method update.
/**
* Updates the state of an entity inside of the current instance of {@code Stand}.
*
* <p>In case the entity update represents the new
* {@link io.spine.server.aggregate.Aggregate Aggregate} state,
* store the new value for the {@code Aggregate} to each of the configured instances of
* {@link StandStorage}.
*
* <p>Each {@code Aggregate} state value is stored as one-to-one to its
* {@link TypeUrl TypeUrl} obtained via {@link Any#getTypeUrl()}.
*
* <p>In case {@code Stand} already contains the state for this {@code Aggregate},
* the value will be replaced.
*
* <p>The state updates which are not originated from the {@code Aggregate} are not
* stored in the {@code Stand}.
*
* <p>In any case, the state update is then propagated to the callbacks.
* The set of matched callbacks is determined by filtering all the registered callbacks
* by the entity {@code TypeUrl}.
*
* <p>The matching callbacks are executed with the {@link #callbackExecutor}.
*
* @param envelope the updated entity state,
* packed as {@linkplain EntityStateEnvelope envelope}
*/
void update(final EntityStateEnvelope<?, ?> envelope) {
final EntityUpdateOperation op = new EntityUpdateOperation(envelope) {
@Override
public void run() {
final Object id = envelope.getEntityId();
final Message entityState = envelope.getMessage();
final Any packedState = AnyPacker.pack(entityState);
final TypeUrl entityTypeUrl = TypeUrl.of(entityState);
final boolean aggregateUpdate = typeRegistry.hasAggregateType(entityTypeUrl);
if (aggregateUpdate) {
final Optional<Version> entityVersion = envelope.getEntityVersion();
checkState(entityVersion.isPresent(), "The aggregate version must be set in order to update Stand. " + "Actual envelope: {}", envelope);
// checked above.
@SuppressWarnings("OptionalGetWithoutIsPresent") final Version versionValue = entityVersion.get();
final AggregateStateId aggregateStateId = AggregateStateId.of(id, entityTypeUrl);
final EntityRecord record = EntityRecord.newBuilder().setState(packedState).setVersion(versionValue).build();
getStorage().write(aggregateStateId, record);
}
notifyMatchingSubscriptions(id, packedState, entityTypeUrl);
}
};
op.execute();
}
use of com.google.protobuf.Any in project core-java by SpineEventEngine.
the class SubscriptionRecord method matchByFilters.
private static boolean matchByFilters(Object id, EntityFilters filters) {
final boolean result;
final EntityIdFilter givenIdFilter = filters.getIdFilter();
final boolean idFilterSet = !EntityIdFilter.getDefaultInstance().equals(givenIdFilter);
if (idFilterSet) {
final Any idAsAny = Identifier.pack(id);
final EntityId givenEntityId = EntityId.newBuilder().setId(idAsAny).build();
final List<EntityId> idsList = givenIdFilter.getIdsList();
result = idsList.contains(givenEntityId);
} else {
result = false;
}
return result;
}
Aggregations