use of io.automatiko.engine.workflow.bpmn2.core.Message in project kogito-runtimes by kiegroup.
the class InMessageRefHandler method end.
@SuppressWarnings("unchecked")
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
Element element = parser.endElementBuilder();
String messageId = element.getTextContent();
Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
if (messages == null) {
throw new ProcessParsingValidationException("No messages found");
}
Operation operation = (Operation) parser.getParent();
Message message = messages.get(messageId);
if (message != null) {
operation.setMessage(message);
}
return parser.getCurrent();
}
use of io.automatiko.engine.workflow.bpmn2.core.Message in project kogito-runtimes by kiegroup.
the class BoundaryEventHandler method handleMessageNode.
protected void handleMessageNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser, final String attachedTo, final boolean cancelActivity) throws SAXException {
super.handleNode(node, element, uri, localName, parser);
BoundaryEventNode eventNode = (BoundaryEventNode) node;
eventNode.setMetaData("AttachedTo", attachedTo);
eventNode.setMetaData("CancelActivity", cancelActivity);
eventNode.setAttachedToNodeId(attachedTo);
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("messageEventDefinition".equals(nodeName)) {
String messageRef = ((Element) xmlNode).getAttribute("messageRef");
Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
if (messages == null) {
throw new ProcessParsingValidationException("No messages found");
}
Message message = messages.get(messageRef);
if (message == null) {
throw new ProcessParsingValidationException("Could not find message " + messageRef);
}
eventNode.setMetaData("MessageType", message.getType());
eventNode.setMetaData("TriggerType", "ConsumeMessage");
eventNode.setMetaData("TriggerRef", message.getName());
List<EventFilter> eventFilters = new ArrayList<EventFilter>();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setCorrelationManager(((RuleFlowProcess) parser.getMetaData().get("CurrentProcessDefinition")).getCorrelationManager());
eventFilter.setType("Message-" + message.getName());
eventFilter.setMessageRef(message.getId());
eventFilters.add(eventFilter);
eventNode.setScope("external");
eventNode.setEventFilters(eventFilters);
}
xmlNode = xmlNode.getNextSibling();
}
}
use of io.automatiko.engine.workflow.bpmn2.core.Message in project automatiko-engine by automatiko-io.
the class ProcessCodegen method generate.
public List<GeneratedFile> generate() {
if (processes.isEmpty()) {
return Collections.emptyList();
}
List<ProcessGenerator> ps = new ArrayList<>();
List<ProcessInstanceGenerator> pis = new ArrayList<>();
List<ProcessExecutableModelGenerator> processExecutableModelGenerators = new ArrayList<>();
// REST resources
List<AbstractResourceGenerator> rgs = new ArrayList<>();
// GraphQL resources
List<AbstractResourceGenerator> grapggs = new ArrayList<>();
// Function resources
List<FunctionGenerator> fgs = new ArrayList<>();
// Function flow resources
List<FunctionFlowGenerator> ffgs = new ArrayList<>();
// message data events
List<MessageDataEventGenerator> mdegs = new ArrayList<>();
// message endpoints/consumers
Set<MessageConsumerGenerator> megs = new LinkedHashSet<>();
// message producers
List<MessageProducerGenerator> mpgs = new ArrayList<>();
// OpenAPI clients
Set<OpenAPIClientGenerator> opgs = new LinkedHashSet<>();
List<String> publicProcesses = new ArrayList<>();
Map<String, ModelMetaData> processIdToModel = new HashMap<>();
Map<String, ModelClassGenerator> processIdToModelGenerator = new HashMap<>();
Map<String, InputModelClassGenerator> processIdToInputModelGenerator = new HashMap<>();
Map<String, OutputModelClassGenerator> processIdToOutputModelGenerator = new HashMap<>();
Map<String, List<UserTaskModelMetaData>> processIdToUserTaskModel = new HashMap<>();
Map<String, ProcessMetaData> processIdToMetadata = new HashMap<>();
String workflowType = Process.WORKFLOW_TYPE;
if (isFunctionFlowProject()) {
workflowType = Process.FUNCTION_FLOW_TYPE;
} else if (isFunctionProject()) {
workflowType = Process.FUNCTION_TYPE;
}
// then we can instantiate the exec model generator
// with the data classes that we have already resolved
ProcessToExecModelGenerator execModelGenerator = new ProcessToExecModelGenerator(contextClassLoader, workflowType);
// first we generate all the data classes from variable declarations
for (Entry<String, WorkflowProcess> entry : processes.entrySet()) {
ModelClassGenerator mcg = new ModelClassGenerator(execModelGenerator, context(), entry.getValue());
processIdToModelGenerator.put(entry.getKey(), mcg);
processIdToModel.put(entry.getKey(), mcg.generate());
InputModelClassGenerator imcg = new InputModelClassGenerator(context(), entry.getValue(), workflowType);
processIdToInputModelGenerator.put(entry.getKey(), imcg);
OutputModelClassGenerator omcg = new OutputModelClassGenerator(context(), entry.getValue(), workflowType);
processIdToOutputModelGenerator.put(entry.getKey(), omcg);
context.addGenerator("ModelClassGenerator", entry.getKey(), mcg);
context.addGenerator("InputModelClassGenerator", entry.getKey(), imcg);
context.addGenerator("OutputModelClassGenerator", entry.getKey(), omcg);
}
// then we generate user task inputs and outputs if any
for (Entry<String, WorkflowProcess> entry : processes.entrySet()) {
UserTasksModelClassGenerator utcg = new UserTasksModelClassGenerator(entry.getValue(), context);
processIdToUserTaskModel.put(entry.getKey(), utcg.generate());
}
List<String> functions = context.getBuildContext().classThatImplement(Functions.class.getCanonicalName());
// collect all process descriptors (exec model)
for (Entry<String, WorkflowProcess> entry : processes.entrySet()) {
ProcessExecutableModelGenerator execModelGen = new ProcessExecutableModelGenerator(entry.getValue(), execModelGenerator);
String packageName = entry.getValue().getPackageName();
String id = entry.getKey();
// add extra meta data to indicate if user task mgmt is available
if (context.getBuildContext().isUserTaskMgmtSupported()) {
entry.getValue().getMetaData().put("UserTaskMgmt", "true");
}
Set<String> classImports = ((io.automatiko.engine.workflow.process.core.WorkflowProcess) entry.getValue()).getImports();
if (classImports != null) {
classImports = new HashSet<>();
((io.automatiko.engine.workflow.process.core.WorkflowProcess) entry.getValue()).setImports(classImports);
}
classImports.add(BaseFunctions.class.getCanonicalName());
classImports.addAll(functions);
try {
ProcessMetaData generate = execModelGen.generate();
processIdToMetadata.put(id, generate);
processExecutableModelGenerators.add(execModelGen);
context.addProcess(id, generate);
} catch (RuntimeException e) {
LOGGER.error(e.getMessage());
throw new ProcessCodegenException(id, packageName, e);
}
}
// generate Process, ProcessInstance classes and the REST resource
for (ProcessExecutableModelGenerator execModelGen : processExecutableModelGenerators) {
String classPrefix = StringUtils.capitalize(execModelGen.extractedProcessId());
WorkflowProcess workFlowProcess = execModelGen.process();
ModelClassGenerator modelClassGenerator = processIdToModelGenerator.get(execModelGen.getProcessId());
ProcessGenerator p = new ProcessGenerator(context, workFlowProcess, execModelGen, classPrefix, modelClassGenerator.className(), applicationCanonicalName, processIdToUserTaskModel.get(execModelGen.getProcessId()), processIdToMetadata).withDependencyInjection(annotator).withPersistence(persistence);
ProcessInstanceGenerator pi = new ProcessInstanceGenerator(workflowType, context(), execModelGen, workFlowProcess.getPackageName(), classPrefix, modelClassGenerator.generate());
ProcessMetaData metaData = processIdToMetadata.get(execModelGen.getProcessId());
if (isFunctionFlowProject()) {
ffgs.add(new FunctionFlowGenerator(context(), workFlowProcess, modelClassGenerator.className(), execModelGen.className(), applicationCanonicalName).withDependencyInjection(annotator).withSignals(metaData.getSignals(), metaData.getSignalNodes()).withTriggers(metaData.getTriggers()));
if (metaData.getTriggers() != null) {
for (TriggerMetaData trigger : metaData.getTriggers()) {
if (trigger.getType().equals(TriggerMetaData.TriggerType.ProduceMessage)) {
MessageDataEventGenerator msgDataEventGenerator = new MessageDataEventGenerator(workFlowProcess, trigger).withDependencyInjection(annotator);
mdegs.add(msgDataEventGenerator);
mpgs.add(new MessageProducerGenerator(workflowType, context(), workFlowProcess, modelClassGenerator.className(), execModelGen.className(), msgDataEventGenerator.className(), trigger).withDependencyInjection(annotator));
}
}
}
} else if (isFunctionProject()) {
fgs.add(new FunctionGenerator(context(), workFlowProcess, modelClassGenerator.className(), execModelGen.className(), applicationCanonicalName).withDependencyInjection(annotator));
} else if (isServiceProject()) {
if (isPublic(workFlowProcess)) {
// Creating and adding the ResourceGenerator
resourceGeneratorFactory.create(context(), workFlowProcess, modelClassGenerator.className(), execModelGen.className(), applicationCanonicalName).map(r -> r.withDependencyInjection(annotator).withParentProcess(null).withPersistence(persistence).withUserTasks(processIdToUserTaskModel.get(execModelGen.getProcessId())).withPathPrefix("{id}").withSignals(metaData.getSignals()).withTriggers(metaData.isStartable(), metaData.isDynamic()).withSubProcesses(populateSubprocesses(workFlowProcess, processIdToMetadata.get(execModelGen.getProcessId()), processIdToMetadata, processIdToModelGenerator, processExecutableModelGenerators, processIdToUserTaskModel))).ifPresent(rgs::add);
if (context.getBuildContext().isGraphQLSupported()) {
GraphQLResourceGenerator graphqlGenerator = new GraphQLResourceGenerator(context(), workFlowProcess, modelClassGenerator.className(), execModelGen.className(), applicationCanonicalName);
graphqlGenerator.withDependencyInjection(annotator).withParentProcess(null).withPersistence(persistence).withUserTasks(processIdToUserTaskModel.get(execModelGen.getProcessId())).withPathPrefix(CodegenUtils.version(workFlowProcess.getVersion())).withSignals(metaData.getSignals()).withTriggers(metaData.isStartable(), metaData.isDynamic()).withSubProcesses(populateSubprocessesGraphQL(workFlowProcess, processIdToMetadata.get(execModelGen.getProcessId()), processIdToMetadata, processIdToModelGenerator, processExecutableModelGenerators, processIdToUserTaskModel));
grapggs.add(graphqlGenerator);
}
}
if (metaData.getTriggers() != null) {
for (TriggerMetaData trigger : metaData.getTriggers()) {
// generate message consumers for processes with message events
if (isPublic(workFlowProcess) && trigger.getType().equals(TriggerMetaData.TriggerType.ConsumeMessage)) {
MessageDataEventGenerator msgDataEventGenerator = new MessageDataEventGenerator(workFlowProcess, trigger).withDependencyInjection(annotator);
mdegs.add(msgDataEventGenerator);
megs.add(new MessageConsumerGenerator(context(), workFlowProcess, modelClassGenerator.className(), execModelGen.className(), applicationCanonicalName, msgDataEventGenerator.className(), trigger).withDependencyInjection(annotator).withPersistence(persistence));
} else if (trigger.getType().equals(TriggerMetaData.TriggerType.ProduceMessage)) {
MessageDataEventGenerator msgDataEventGenerator = new MessageDataEventGenerator(workFlowProcess, trigger).withDependencyInjection(annotator);
mdegs.add(msgDataEventGenerator);
mpgs.add(new MessageProducerGenerator(workflowType, context(), workFlowProcess, modelClassGenerator.className(), execModelGen.className(), msgDataEventGenerator.className(), trigger).withDependencyInjection(annotator));
}
}
}
}
if (metaData.getOpenAPIs() != null) {
for (OpenAPIMetaData api : metaData.getOpenAPIs()) {
OpenAPIClientGenerator oagenerator = new OpenAPIClientGenerator(context, workFlowProcess, api).withDependencyInjection(annotator);
opgs.add(oagenerator);
}
}
moduleGenerator.addProcess(p);
ps.add(p);
pis.add(pi);
}
for (ModelClassGenerator modelClassGenerator : processIdToModelGenerator.values()) {
ModelMetaData mmd = modelClassGenerator.generate();
storeFile(Type.MODEL, modelClassGenerator.generatedFilePath(), mmd.generate(annotator != null ? new String[] { "io.quarkus.runtime.annotations.RegisterForReflection" } : new String[0]));
}
for (InputModelClassGenerator modelClassGenerator : processIdToInputModelGenerator.values()) {
ModelMetaData mmd = modelClassGenerator.generate();
storeFile(Type.MODEL, modelClassGenerator.generatedFilePath(), mmd.generate(annotator != null ? new String[] { "io.quarkus.runtime.annotations.RegisterForReflection" } : new String[0]));
}
for (OutputModelClassGenerator modelClassGenerator : processIdToOutputModelGenerator.values()) {
ModelMetaData mmd = modelClassGenerator.generate();
storeFile(Type.MODEL, modelClassGenerator.generatedFilePath(), mmd.generate(annotator != null ? new String[] { "io.quarkus.runtime.annotations.RegisterForReflection" } : new String[0]));
}
for (List<UserTaskModelMetaData> utmd : processIdToUserTaskModel.values()) {
for (UserTaskModelMetaData ut : utmd) {
storeFile(Type.MODEL, UserTasksModelClassGenerator.generatedFilePath(ut.getInputModelClassName()), ut.generateInput());
storeFile(Type.MODEL, UserTasksModelClassGenerator.generatedFilePath(ut.getOutputModelClassName()), ut.generateOutput());
}
}
for (AbstractResourceGenerator resourceGenerator : rgs) {
storeFile(Type.REST, resourceGenerator.generatedFilePath(), resourceGenerator.generate());
}
for (AbstractResourceGenerator resourceGenerator : grapggs) {
storeFile(Type.GRAPHQL, resourceGenerator.generatedFilePath(), resourceGenerator.generate());
}
for (FunctionGenerator functionGenerator : fgs) {
storeFile(Type.FUNCTION, functionGenerator.generatedFilePath(), functionGenerator.generate());
}
for (FunctionFlowGenerator functionFlowGenerator : ffgs) {
storeFile(Type.FUNCTION_FLOW, functionFlowGenerator.generatedFilePath(), functionFlowGenerator.generate());
}
for (MessageDataEventGenerator messageDataEventGenerator : mdegs) {
storeFile(Type.CLASS, messageDataEventGenerator.generatedFilePath(), messageDataEventGenerator.generate());
}
for (MessageConsumerGenerator messageConsumerGenerator : megs) {
storeFile(Type.MESSAGE_CONSUMER, messageConsumerGenerator.generatedFilePath(), messageConsumerGenerator.generate());
}
for (MessageProducerGenerator messageProducerGenerator : mpgs) {
storeFile(Type.MESSAGE_PRODUCER, messageProducerGenerator.generatedFilePath(), messageProducerGenerator.generate());
}
for (OpenAPIClientGenerator openApiClientGenerator : opgs) {
openApiClientGenerator.generate();
Map<String, String> contents = openApiClientGenerator.generatedClasses();
for (Entry<String, String> entry : contents.entrySet()) {
storeFile(Type.CLASS, entry.getKey().replace('.', '/') + ".java", entry.getValue());
}
}
for (ProcessGenerator p : ps) {
storeFile(Type.PROCESS, p.generatedFilePath(), p.generate());
p.getAdditionalClasses().forEach(cp -> {
String packageName = cp.getPackageDeclaration().map(pd -> pd.getName().toString()).orElse("");
String clazzName = cp.findFirst(ClassOrInterfaceDeclaration.class).map(cls -> cls.getName().toString()).get();
String path = (packageName + "." + clazzName).replace('.', '/') + ".java";
storeFile(Type.CLASS, path, cp.toString());
});
}
for (ProcessInstanceGenerator pi : pis) {
storeFile(Type.PROCESS_INSTANCE, pi.generatedFilePath(), pi.generate());
}
for (ProcessExecutableModelGenerator processGenerator : processExecutableModelGenerators) {
if (processGenerator.isPublic()) {
publicProcesses.add(processGenerator.extractedProcessId());
}
}
return generatedFiles;
}
use of io.automatiko.engine.workflow.bpmn2.core.Message in project automatiko-engine by automatiko-io.
the class IntermediateCatchEventHandler method handleMessageNode.
@SuppressWarnings("unchecked")
protected void handleMessageNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
super.handleNode(node, element, uri, localName, parser);
EventNode eventNode = (EventNode) node;
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
String id = ((Element) xmlNode).getAttribute("id");
String name = ((Element) xmlNode).getAttribute("name");
if ("dataOutput".equals(nodeName)) {
dataOutputs.put(id, name);
populateDataOutputs(xmlNode, name, parser);
} else if ("dataOutputAssociation".equals(nodeName)) {
readDataOutputAssociation(xmlNode, eventNode);
} else if ("messageEventDefinition".equals(nodeName)) {
String messageRef = ((Element) xmlNode).getAttribute("messageRef");
Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
if (messages == null) {
throw new IllegalArgumentException("No messages found");
}
Message message = messages.get(messageRef);
if (message == null) {
throw new MalformedNodeException(id, name, MessageFormat.format("Could not find message \"{0}\"", messageRef));
}
eventNode.setMetaData("MessageType", message.getType());
eventNode.setMetaData("TriggerType", "ConsumeMessage");
eventNode.setMetaData("TriggerRef", message.getName());
eventNode.setMetaData("TriggerCorrelation", message.getCorrelation());
eventNode.setMetaData("TriggerCorrelationExpr", message.getCorrelationExpression());
for (Entry<String, Object> entry : message.getMetaData().entrySet()) {
eventNode.setMetaData(entry.getKey(), entry.getValue());
}
List<EventFilter> eventFilters = new ArrayList<EventFilter>();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType("Message-" + message.getName());
eventFilters.add(eventFilter);
eventNode.setEventFilters(eventFilters);
}
xmlNode = xmlNode.getNextSibling();
}
}
use of io.automatiko.engine.workflow.bpmn2.core.Message in project automatiko-engine by automatiko-io.
the class BoundaryEventHandler method handleMessageNode.
protected void handleMessageNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser, final String attachedTo, final boolean cancelActivity) throws SAXException {
super.handleNode(node, element, uri, localName, parser);
BoundaryEventNode eventNode = (BoundaryEventNode) node;
eventNode.setMetaData("AttachedTo", attachedTo);
eventNode.setMetaData("CancelActivity", cancelActivity);
eventNode.setAttachedToNodeId(attachedTo);
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("dataOutput".equals(nodeName)) {
String id = ((Element) xmlNode).getAttribute("id");
String outputName = ((Element) xmlNode).getAttribute("name");
dataOutputs.put(id, outputName);
populateDataOutputs(xmlNode, outputName, parser);
} else if ("dataOutputAssociation".equals(nodeName)) {
readDataOutputAssociation(xmlNode, eventNode, parser);
} else if ("messageEventDefinition".equals(nodeName)) {
String messageRef = ((Element) xmlNode).getAttribute("messageRef");
Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
if (messages == null) {
throw new IllegalArgumentException("No messages found");
}
Message message = messages.get(messageRef);
if (message == null) {
throw new IllegalArgumentException("Could not find message " + messageRef);
}
eventNode.setMetaData("MessageType", message.getType());
eventNode.setMetaData("TriggerType", "ConsumeMessage");
eventNode.setMetaData("TriggerRef", message.getName());
eventNode.setMetaData("TriggerCorrelation", message.getCorrelation());
eventNode.setMetaData("TriggerCorrelationExpr", message.getCorrelationExpression());
eventNode.setMetaData("connector", message.getMetaData().getOrDefault("connector", eventNode.getMetaData("connector")));
eventNode.setMetaData("topic", message.getMetaData().getOrDefault("topic", eventNode.getMetaData("topic")));
List<EventFilter> eventFilters = new ArrayList<EventFilter>();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType("Message-" + message.getName());
eventFilters.add(eventFilter);
eventNode.setScope("external");
eventNode.setEventFilters(eventFilters);
}
xmlNode = xmlNode.getNextSibling();
}
}
Aggregations