use of org.infinispan.protostream.descriptors.FieldDescriptor in project kogito-apps by kiegroup.
the class ProtoIndexParser method create.
@Override
public EntityIndexDescriptor create(Descriptor annotatedDescriptor, AnnotationElement.Annotation annotation) {
String name = annotatedDescriptor.getFullName();
List<IndexDescriptor> indexes = new ArrayList<>(annotatedDescriptor.getFields().size());
List<AttributeDescriptor> fields = new ArrayList<>(annotatedDescriptor.getFields().size());
for (FieldDescriptor fd : annotatedDescriptor.getFields()) {
AnnotationElement.Annotation fieldAnnotation = fd.getAnnotations().get(FIELD_ANNOTATION);
if (fieldAnnotation != null) {
String fieldName = Optional.ofNullable((String) fieldAnnotation.getAttributeValue(FIELD_NAME_ATTRIBUTE).getValue()).filter(a -> !a.isEmpty()).orElseGet(fd::getName);
boolean isIndexed = INDEX_YES.equals(fieldAnnotation.getAttributeValue(FIELD_INDEX_ATTRIBUTE).getValue());
fields.add(createAttributeDescriptor(fd, fieldName));
if (isIndexed) {
indexes.add(new IndexDescriptor(fieldName, List.of(fieldName)));
}
}
}
return new EntityIndexDescriptor(name, indexes, fields);
}
use of org.infinispan.protostream.descriptors.FieldDescriptor in project kogito-apps by kiegroup.
the class ProtoIndexParserTest method testCreateAttributeDescriptor.
@Test
void testCreateAttributeDescriptor() {
FieldDescriptor roomField = createFileDescriptor().getMessageTypes().stream().filter(descriptor -> "org.acme.travels.travels.Hotel".equals(descriptor.getFullName())).findAny().get().findFieldByName("room");
AttributeDescriptor attributeDescriptor = createAttributeDescriptor(roomField, null);
assertEquals(new AttributeDescriptor("room", "string", true), attributeDescriptor);
}
use of org.infinispan.protostream.descriptors.FieldDescriptor in project infinispan by infinispan.
the class ProtobufMatcherEvalContext method processMissingFields.
private void processMissingFields() {
for (FieldDescriptor fd : messageContext.getMessageDescriptor().getFields()) {
AttributeNode<FieldDescriptor, Integer> attributeNode = currentNode.getChild(fd.getNumber());
boolean fieldSeen = messageContext.isFieldMarked(fd.getNumber());
if (attributeNode != null && (fd.isRepeated() || !fieldSeen)) {
if (fd.isRepeated()) {
// Repeated fields can't have default values but we need to at least take care of IS [NOT] NULL predicates
if (fieldSeen) {
// Here we use a dummy value since it would not matter anyway for IS [NOT] NULL
attributeNode.processValue(AttributeNode.DUMMY_VALUE, this);
} else {
processNullAttribute(attributeNode);
}
} else {
if (fd.getJavaType() == JavaType.MESSAGE) {
processNullAttribute(attributeNode);
} else {
Object defaultValue = fd.hasDefaultValue() ? fd.getDefaultValue() : null;
attributeNode.processValue(defaultValue, this);
}
}
}
}
}
use of org.infinispan.protostream.descriptors.FieldDescriptor in project infinispan by infinispan.
the class ProtobufPropertyHelper method mapPropertyNamePathToFieldIdPath.
@Override
public List<?> mapPropertyNamePathToFieldIdPath(Descriptor messageDescriptor, String[] propertyPath) {
List<Integer> translatedPath = new ArrayList<>(propertyPath.length);
Descriptor md = messageDescriptor;
for (String prop : propertyPath) {
FieldDescriptor fd = md.findFieldByName(prop);
translatedPath.add(fd.getNumber());
if (fd.getJavaType() == JavaType.MESSAGE) {
md = fd.getMessageType();
} else {
// iteration is expected to stop here
md = null;
}
}
return translatedPath;
}
use of org.infinispan.protostream.descriptors.FieldDescriptor in project infinispan by infinispan.
the class ProtobufPropertyHelper method getField.
/**
* @param entityType
* @param propertyPath
* @return the field descriptor or null if not found
*/
private FieldDescriptor getField(Descriptor entityType, String[] propertyPath) {
Descriptor messageDescriptor = entityType;
int i = 0;
for (String p : propertyPath) {
FieldDescriptor field = messageDescriptor.findFieldByName(p);
if (field == null || ++i == propertyPath.length) {
return field;
}
if (field.getJavaType() == JavaType.MESSAGE) {
messageDescriptor = field.getMessageType();
} else {
break;
}
}
return null;
}
Aggregations