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