use of org.kie.kogito.persistence.api.schema.EntityIndexDescriptor 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;
}
use of org.kie.kogito.persistence.api.schema.EntityIndexDescriptor in project kogito-apps by kiegroup.
the class ProtobufService method onStart.
void onStart(@Observes StartupEvent ev) {
kogitoDescriptors.getFileDescriptors().forEach((name, bytes) -> {
LOGGER.info("Registering Kogito ProtoBuffer file: {}", name);
String content = new String(bytes);
try {
SerializationContext ctx = createSerializationContext(FileDescriptorSource.fromString(name, content));
FileDescriptor desc = ctx.getFileDescriptors().get(name);
Map<String, EntityIndexDescriptor> entityIndexes = desc.getMessageTypes().stream().map(t -> t.<EntityIndexDescriptor>getProcessedAnnotation(INDEXED_ANNOTATION)).filter(Objects::nonNull).collect(toMap(EntityIndexDescriptor::getName, Function.identity()));
Map<String, EntityIndexDescriptor> entityIndexDescriptors = createEntityIndexDescriptors(desc, entityIndexes);
schemaEvent.fire(new SchemaRegisteredEvent(new SchemaDescriptor(name, content, entityIndexDescriptors, null), SCHEMA_TYPE));
} catch (ProtobufValidationException e) {
throw new ProtobufFileRegistrationException(e);
}
});
protobufMonitorService.startMonitoring();
}
use of org.kie.kogito.persistence.api.schema.EntityIndexDescriptor in project kogito-apps by kiegroup.
the class ProtobufService method registerProtoBufferType.
public void registerProtoBufferType(String content) throws ProtobufValidationException {
LOGGER.debug("Registering new ProtoBuffer file with content: \n{}", content);
content = content.replaceAll("kogito.Date", "string");
SerializationContext ctx = createSerializationContext(kogitoDescriptors, FileDescriptorSource.fromString(DOMAIN_MODEL_PROTO_NAME, content));
FileDescriptor desc = ctx.getFileDescriptors().get(DOMAIN_MODEL_PROTO_NAME);
Option processIdOption = desc.getOption("kogito_id");
if (processIdOption == null || processIdOption.getValue() == null) {
throw new ProtobufValidationException("Missing marker for process id in proto file, please add option kogito_id=\"processid\"");
}
String processId = (String) processIdOption.getValue();
Option model = desc.getOption("kogito_model");
if (model == null || model.getValue() == null) {
throw new ProtobufValidationException("Missing marker for main message type in proto file, please add option kogito_model=\"messagename\"");
}
String messageName = (String) model.getValue();
String fullTypeName = desc.getPackage() == null ? messageName : desc.getPackage() + "." + messageName;
Descriptor descriptor;
try {
descriptor = ctx.getMessageDescriptor(fullTypeName);
} catch (IllegalArgumentException ex) {
throw new ProtobufValidationException(format("Could not find message with name: %s in proto file, e, please review option kogito_model", fullTypeName));
}
validateDescriptorField(messageName, descriptor, Constants.KOGITO_DOMAIN_ATTRIBUTE);
Map<String, EntityIndexDescriptor> entityIndexes = desc.getMessageTypes().stream().map(t -> t.<EntityIndexDescriptor>getProcessedAnnotation(INDEXED_ANNOTATION)).filter(Objects::nonNull).collect(toMap(EntityIndexDescriptor::getName, Function.identity()));
Map<String, EntityIndexDescriptor> entityIndexedDescriptors = createEntityIndexDescriptors(desc, entityIndexes);
try {
schemaEvent.fire(new SchemaRegisteredEvent(new SchemaDescriptor(processId + ".proto", content, entityIndexedDescriptors, new ProcessDescriptor(processId, fullTypeName)), SCHEMA_TYPE));
} catch (RuntimeException ex) {
throw new ProtobufValidationException(ex.getMessage(), ex);
}
domainModelEvent.fire(new FileDescriptorRegisteredEvent(desc));
}
use of org.kie.kogito.persistence.api.schema.EntityIndexDescriptor in project kogito-apps by kiegroup.
the class ProtoIndexParserTest method testCreateEntityIndexeDescriptors.
@Test
void testCreateEntityIndexeDescriptors() {
FileDescriptor fileDescriptor = createFileDescriptor();
Map<String, EntityIndexDescriptor> entityIndexes = createFileDescriptor().getMessageTypes().stream().map(t -> t.<EntityIndexDescriptor>getProcessedAnnotation(INDEXED_ANNOTATION)).filter(Objects::nonNull).collect(toMap(EntityIndexDescriptor::getName, Function.identity()));
Map<String, EntityIndexDescriptor> indexDescriptor = createEntityIndexDescriptors(fileDescriptor, entityIndexes);
assertEquals(getValidEntityIndexDescriptors(true), indexDescriptor);
}
Aggregations