use of com.google.protobuf.FieldMask 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();
// Implying AnyPacker.pack to be idempotent
final Set<Any> entityIds = composeIdPredicate();
final Query result = queryFactory.composeQuery(targetType, entityIds, columns, mask);
return result;
}
use of com.google.protobuf.FieldMask in project core-java by SpineEventEngine.
the class QueryFactory method byIdsWithMask.
/**
* Creates a {@link Query} to read certain entity states by IDs with the {@link FieldMask}
* applied to each of the results.
*
* <p>Allows to specify a set of identifiers to be used during the {@code Query} processing.
* The processing results will contain only the entities, which IDs are present among
* the {@code ids}.
*
* <p>Allows to set property paths for a {@link FieldMask}, applied to each of the query
* results. This processing is performed according to the
* <a href="https://goo.gl/tW5wIU">FieldMask specs</a>.
*
* <p>In case the {@code paths} array contains entries inapplicable to the resulting entity
* (e.g. a {@code path} references a missing field),
* such invalid paths are silently ignored.
*
* @param entityClass the class of a target entity
* @param ids the entity IDs of interest
* @param maskPaths the property paths for the {@code FieldMask} applied
* to each of results
* @return an instance of {@code Query} formed according to the passed parameters
*/
public Query byIdsWithMask(Class<? extends Message> entityClass, Set<? extends Message> ids, String... maskPaths) {
checkNotNull(ids);
checkArgument(!ids.isEmpty(), ENTITY_IDS_EMPTY_MSG);
final FieldMask fieldMask = FieldMask.newBuilder().addAllPaths(Arrays.asList(maskPaths)).build();
final Query result = composeQuery(entityClass, ids, null, fieldMask);
return result;
}
use of com.google.protobuf.FieldMask in project core-java by SpineEventEngine.
the class FieldMasksShould method fail_to_mask_message_if_passed_type_does_not_match.
@Test(expected = IllegalArgumentException.class)
public void fail_to_mask_message_if_passed_type_does_not_match() {
final FieldMask mask = Given.fieldMask(Project.ID_FIELD_NUMBER);
final Project origin = Given.newProject("some-string");
FieldMasks.applyMask(mask, origin, Given.OTHER_TYPE);
}
use of com.google.protobuf.FieldMask in project core-java by SpineEventEngine.
the class FieldMasksShould method apply_only_non_empty_mask_to_single_item.
@Test
public void apply_only_non_empty_mask_to_single_item() {
final FieldMask emptyMask = Given.fieldMask();
final Project origin = Given.newProject("read_whole_message");
final Project clone = Project.newBuilder(origin).build();
final Project processed = FieldMasks.applyMask(emptyMask, origin, Given.TYPE);
// Check object itself was returned
assertTrue(processed == origin);
// Check object was not changed
assertTrue(processed.equals(clone));
}
use of com.google.protobuf.FieldMask in project core-java by SpineEventEngine.
the class FieldMasksShould method apply_mask_to_single_message.
@Test
public void apply_mask_to_single_message() {
final FieldMask fieldMask = Given.fieldMask(Project.ID_FIELD_NUMBER, Project.NAME_FIELD_NUMBER);
final Project original = Given.newProject("some-string-id");
final Project masked = FieldMasks.applyMask(fieldMask, original, Given.TYPE);
assertNotEquals(original, masked);
assertMatchesMask(masked, fieldMask);
}
Aggregations