use of org.kie.kogito.persistence.api.schema.AttributeDescriptor 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.kie.kogito.persistence.api.schema.AttributeDescriptor 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.kie.kogito.persistence.api.schema.AttributeDescriptor in project kogito-apps by kiegroup.
the class TestUtils method getValidEntityIndexDescriptors.
static Map<String, EntityIndexDescriptor> getValidEntityIndexDescriptors(boolean includeUnindexedAttribute) {
AttributeDescriptor flightNumber = new AttributeDescriptor("flightNumber", "string", true);
EntityIndexDescriptor flightEntityIndexDescriptor = new EntityIndexDescriptor("org.acme.travels.travels.Flight", emptyList(), List.of(flightNumber));
AttributeDescriptor hotelName = new AttributeDescriptor("name", "string", true);
AttributeDescriptor hotelRoom = new AttributeDescriptor("room", "string", true);
EntityIndexDescriptor hotelEntityIndexDescriptor = new EntityIndexDescriptor("org.acme.travels.travels.Hotel", emptyList(), includeUnindexedAttribute ? List.of(hotelName, hotelRoom) : List.of(hotelName));
AttributeDescriptor flight = new AttributeDescriptor("flight", "Flight", false);
AttributeDescriptor hotel = new AttributeDescriptor("hotel", "Hotel", false);
AttributeDescriptor id = new AttributeDescriptor("id", "string", true);
AttributeDescriptor metadata = new AttributeDescriptor("metadata", "string", true);
IndexDescriptor idIndex = new IndexDescriptor("id", List.of("id"));
EntityIndexDescriptor travelEntityIndexDescriptor = new EntityIndexDescriptor("org.acme.travels.travels.Travels", List.of(idIndex), List.of(flight, hotel, id, metadata));
Map<String, EntityIndexDescriptor> entityIndexDescriptorMap = new HashMap<>();
entityIndexDescriptorMap.put(flightEntityIndexDescriptor.getName(), flightEntityIndexDescriptor);
entityIndexDescriptorMap.put(hotelEntityIndexDescriptor.getName(), hotelEntityIndexDescriptor);
entityIndexDescriptorMap.put(travelEntityIndexDescriptor.getName(), travelEntityIndexDescriptor);
return entityIndexDescriptorMap;
}
use of org.kie.kogito.persistence.api.schema.AttributeDescriptor in project kogito-apps by kiegroup.
the class IndexManagerIT method setup_all.
@BeforeAll
static void setup_all() {
AttributeDescriptor flightNumber = new AttributeDescriptor("flightNumber", "string", true);
IndexDescriptor flightNumberIndex = new IndexDescriptor("flightNumber", List.of("flightNumber"));
flightEntityIndexDescriptor = new EntityIndexDescriptor("org.acme.travels.travels.Flight", List.of(flightNumberIndex), List.of(flightNumber));
AttributeDescriptor hotelName = new AttributeDescriptor("name", "string", true);
AttributeDescriptor hotelRoom = new AttributeDescriptor("room", "string", true);
IndexDescriptor hotelNameIndex = new IndexDescriptor("name", List.of("name"));
hotelEntityIndexDescriptor = new EntityIndexDescriptor("org.acme.travels.travels.Hotel", List.of(hotelNameIndex), List.of(hotelName, hotelRoom));
AttributeDescriptor flight = new AttributeDescriptor("flight", "Flight", false);
AttributeDescriptor hotel = new AttributeDescriptor("hotel", "org.acme.travels.travels.Hotel", false);
AttributeDescriptor id = new AttributeDescriptor("id", "string", true);
AttributeDescriptor metadata = new AttributeDescriptor("metadata", "string", true);
IndexDescriptor flightIndex = new IndexDescriptor("flight", List.of("flight"));
IndexDescriptor hotelIndex = new IndexDescriptor("hotel", List.of("hotel"));
IndexDescriptor idIndex = new IndexDescriptor("id", List.of("id"));
IndexDescriptor metadataIndex = new IndexDescriptor("metadata", List.of("metadata"));
travelEntityIndexDescriptor = new EntityIndexDescriptor("org.acme.travels.travels.Travels", List.of(flightIndex, hotelIndex, idIndex, metadataIndex), List.of(flight, hotel, id, metadata));
errorEntityIndexDescriptor = mockErrorIndexes();
}
use of org.kie.kogito.persistence.api.schema.AttributeDescriptor in project kogito-apps by kiegroup.
the class ProtoIndexParser method createEntityIndexDescriptors.
static Map<String, EntityIndexDescriptor> createEntityIndexDescriptors(FileDescriptor desc, Map<String, EntityIndexDescriptor> entityIndexes) {
desc.getMessageTypes().forEach(mDesc -> {
String typeName = mDesc.getFullName();
EntityIndexDescriptor entityIndex = entityIndexes.get(typeName);
if (entityIndex != null) {
// Add the fields without index
Set<String> fieldNames = entityIndex.getAttributeDescriptors().stream().map(AttributeDescriptor::getName).collect(toSet());
mDesc.getFields().stream().filter(fDesc -> !fieldNames.contains(fDesc.getName())).forEach(fDesc -> entityIndex.getAttributeDescriptors().add(createAttributeDescriptor(fDesc, null)));
}
});
return entityIndexes;
}
Aggregations