Search in sources :

Example 21 with Descriptor

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

the class Json method buildForKnownTypes.

/**
     * Builds the registry of types known in the application.
     */
private static JsonFormat.TypeRegistry buildForKnownTypes() {
    final JsonFormat.TypeRegistry.Builder builder = JsonFormat.TypeRegistry.newBuilder();
    for (TypeUrl typeUrl : KnownTypes.getAllUrls()) {
        final Descriptors.GenericDescriptor genericDescriptor = typeUrl.getDescriptor();
        if (genericDescriptor instanceof Descriptor) {
            final Descriptor descriptor = (Descriptor) genericDescriptor;
            builder.add(descriptor);
        }
    }
    return builder.build();
}
Also used : Descriptor(com.google.protobuf.Descriptors.Descriptor) TypeUrl(io.spine.type.TypeUrl) Descriptors(com.google.protobuf.Descriptors)

Example 22 with Descriptor

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

the class ReferenceValidator method findSourceFieldByName.

/**
     * Searches for the event/context field with the name retrieved from the
     * enrichment field {@code by} option.
     *
     * @param name            the name of the searched field
     * @param enrichmentField the field of the enrichment targeted onto the searched field
     * @param strict          if {@code true} the field must be found, an exception is thrown
     *                        otherwise.
     *                        <p>If {@code false} {@code null} will be returned upon an
     *                        unsuccessful search
     * @return {@link FieldDescriptor} for the field with the given name or {@code null} if the
     * field is absent and if not in the strict mode
     */
private FieldDescriptor findSourceFieldByName(String name, FieldDescriptor enrichmentField, boolean strict) {
    checkSourceFieldName(name, enrichmentField);
    final Descriptor srcMessage = getSrcMessage(name);
    final FieldDescriptor field = findField(name, srcMessage);
    if (field == null && strict) {
        throw noFieldException(name, srcMessage, enrichmentField);
    }
    return field;
}
Also used : Descriptor(com.google.protobuf.Descriptors.Descriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 23 with Descriptor

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

the class AlternativeFieldValidatorShould method setUp.

@Before
public void setUp() {
    final Descriptor descriptor = PersonName.getDescriptor();
    validator = new AlternativeFieldValidator(descriptor, rootFieldPath);
}
Also used : Descriptor(com.google.protobuf.Descriptors.Descriptor) Before(org.junit.Before)

Example 24 with Descriptor

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

the class MessageValidator method validateFields.

private void validateFields(Message message, ImmutableList.Builder<ConstraintViolation> result) {
    final Descriptor msgDescriptor = message.getDescriptorForType();
    final List<FieldDescriptor> fields = msgDescriptor.getFields();
    for (FieldDescriptor field : fields) {
        final Object value = message.getField(field);
        final FieldValidator<?> fieldValidator = FieldValidatorFactory.create(field, value, rootFieldPath);
        final List<ConstraintViolation> violations = fieldValidator.validate();
        result.addAll(violations);
    }
}
Also used : Descriptor(com.google.protobuf.Descriptors.Descriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 25 with Descriptor

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

the class KnownTypesShould method provide_proto_descriptor_by_type_name.

@Test
public void provide_proto_descriptor_by_type_name() {
    final String typeName = "spine.test.types.Task";
    final Descriptor typeDescriptor = (Descriptor) getDescriptor(typeName);
    assertNotNull(typeDescriptor);
    assertEquals(typeName, typeDescriptor.getFullName());
}
Also used : KnownTypes.getDescriptor(io.spine.type.KnownTypes.getDescriptor) Descriptor(com.google.protobuf.Descriptors.Descriptor) Test(org.junit.Test)

Aggregations

Descriptor (com.google.protobuf.Descriptors.Descriptor)30 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)26 EnumDescriptor (com.google.protobuf.Descriptors.EnumDescriptor)13 EnumValueDescriptor (com.google.protobuf.Descriptors.EnumValueDescriptor)13 ExtensionRegistry (com.google.protobuf.ExtensionRegistry)4 ArrayList (java.util.ArrayList)4 TypicalData (protos.TypicalData)4 Message (com.google.protobuf.Message)3 HashSet (java.util.HashSet)3 TypicalDataMessage (protos.TypicalDataMessage)3 GenericDescriptor (com.google.protobuf.Descriptors.GenericDescriptor)2 GeneratedMessage (com.google.protobuf.GeneratedMessage)2 ConfigNode (com.google.api.codegen.configgen.nodes.ConfigNode)1 FieldConfigNode (com.google.api.codegen.configgen.nodes.FieldConfigNode)1 ListItemConfigNode (com.google.api.codegen.configgen.nodes.ListItemConfigNode)1 NullConfigNode (com.google.api.codegen.configgen.nodes.NullConfigNode)1 ScalarConfigNode (com.google.api.codegen.configgen.nodes.ScalarConfigNode)1 VisitsBefore (com.google.api.tools.framework.util.VisitsBefore)1 ByteString (com.google.protobuf.ByteString)1 Descriptors (com.google.protobuf.Descriptors)1