Search in sources :

Example 6 with FieldMask

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;
}
Also used : Any(com.google.protobuf.Any) FieldMask(com.google.protobuf.FieldMask)

Example 7 with FieldMask

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;
}
Also used : FieldMask(com.google.protobuf.FieldMask)

Example 8 with FieldMask

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);
}
Also used : Project(io.spine.test.aggregate.Project) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 9 with FieldMask

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));
}
Also used : Project(io.spine.test.aggregate.Project) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 10 with FieldMask

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);
}
Also used : Project(io.spine.test.aggregate.Project) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Aggregations

FieldMask (com.google.protobuf.FieldMask)29 Test (org.junit.Test)20 Any (com.google.protobuf.Any)7 EntityRecord (io.spine.server.entity.EntityRecord)6 Descriptors (com.google.protobuf.Descriptors)5 Message (com.google.protobuf.Message)5 Query (io.spine.client.Query)5 Project (io.spine.test.aggregate.Project)5 LinkedList (java.util.LinkedList)4 EntityFilters (io.spine.client.EntityFilters)3 Target (io.spine.client.Target)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 ImmutableList (com.google.common.collect.ImmutableList)2 Version (io.spine.base.Version)2 EntityId (io.spine.client.EntityId)2 EntityIdFilter (io.spine.client.EntityIdFilter)2 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)2 TestEntity (io.spine.test.client.TestEntity)2 Customer (io.spine.test.commandservice.customer.Customer)2 CustomerId (io.spine.test.commandservice.customer.CustomerId)2