use of io.automatiko.engine.workflow.base.core.context.variable.Variable in project automatiko-engine by automatiko-io.
the class AbstractProcessInstanceFactory method createProcessInstance.
public ProcessInstance createProcessInstance(Process process, CorrelationKey correlationKey, InternalProcessRuntime runtime, Map<String, Object> parameters, VariableInitializer variableInitializer) {
ProcessInstance processInstance = createProcessInstance();
processInstance.setProcessRuntime(runtime);
processInstance.setProcess(process);
if (correlationKey != null) {
processInstance.getMetaData().put("CorrelationKey", correlationKey);
}
runtime.getProcessInstanceManager().addProcessInstance(processInstance, correlationKey);
// set variable default values
// TODO: should be part of processInstanceImpl?
VariableScope variableScope = (VariableScope) ((ContextContainer) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
// set input parameters
if (parameters != null) {
if (variableScope != null) {
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
variableScope.validateVariable(process.getName(), entry.getKey(), entry.getValue());
variableScopeInstance.setVariable(entry.getKey(), entry.getValue());
}
} else {
throw new IllegalArgumentException("This process does not support parameters!");
}
}
for (Variable var : variableScope.getVariables()) {
if ((var.hasTag(Variable.AUTO_INITIALIZED_TAG) || var.getMetaData(Variable.DEFAULT_VALUE) != null) && variableScopeInstance.getVariable(var.getName()) == null) {
Object value = variableInitializer.initialize(process, var, variableScopeInstance.getVariables());
variableScope.validateVariable(process.getName(), var.getName(), value);
variableScopeInstance.setVariable(var.getName(), value);
}
}
variableScopeInstance.enforceRequiredVariables();
return processInstance;
}
use of io.automatiko.engine.workflow.base.core.context.variable.Variable in project automatiko-engine by automatiko-io.
the class DefinitionsHandler method postProcessNodes.
protected void postProcessNodes(NodeContainer nodeContainer, List<Variable> parentVariables, ExtensibleXmlParser parser) throws SAXException {
for (Node node : nodeContainer.getNodes()) {
List<Variable> variables = new LinkedList<>(parentVariables);
VariableScope variableScope = (VariableScope) ((ContextContainer) nodeContainer).getDefaultContext(VariableScope.VARIABLE_SCOPE);
if (variableScope != null) {
variables.addAll(variableScope.getVariables());
}
if (node instanceof NodeContainer) {
postProcessNodes((NodeContainer) node, variables, parser);
} else {
if (node instanceof ActionNode) {
ActionNode actionNode = (ActionNode) node;
ProcessAction action = actionNode.getAction();
if (action instanceof ConsequenceAction) {
ConsequenceAction consequenceAction = (ConsequenceAction) action;
switch(consequenceAction.getDialect()) {
case "java":
if (actionNode.getAction().getMetaData("Action") == null) {
actionNode.getAction().setMetaData("Action", new MvelAction(actionNode));
}
break;
case "mvel":
if (actionNode.getAction().getMetaData("Action") == null) {
actionNode.getAction().setMetaData("Action", new MvelAction(actionNode));
}
break;
default:
}
}
}
}
}
}
use of io.automatiko.engine.workflow.base.core.context.variable.Variable in project automatiko-engine by automatiko-io.
the class DocumentationHandler method end.
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
Element element = parser.endElementBuilder();
Object parent = parser.getParent();
if (parent instanceof NodeImpl) {
((NodeImpl) parent).getMetaData().put("Documentation", extractDocumentationText(element));
} else if (parent instanceof io.automatiko.engine.workflow.base.core.Process) {
((io.automatiko.engine.workflow.base.core.Process) parent).getMetaData().put("Documentation", extractDocumentationText(element));
} else if (parent instanceof Variable) {
((Variable) parent).getMetaData().put("Documentation", extractDocumentationText(element));
}
return parser.getCurrent();
}
use of io.automatiko.engine.workflow.base.core.context.variable.Variable in project automatiko-engine by automatiko-io.
the class IntermediateThrowEventHandler method handleMessageNode.
@SuppressWarnings("unchecked")
public void handleMessageNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
ActionNode actionNode = (ActionNode) node;
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("dataInput".equals(nodeName)) {
String id = ((Element) xmlNode).getAttribute("id");
String inputName = ((Element) xmlNode).getAttribute("name");
dataInputs.put(id, inputName);
} else if ("dataInputAssociation".equals(nodeName)) {
readDataInputAssociation(xmlNode, actionNode, 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);
}
String variable = (String) actionNode.getMetaData(MAPPING_VARIABLE_KEY);
Variable v = (Variable) ((ProcessBuildData) parser.getData()).getMetaData("Variable");
if (v != null) {
variable = (String) v.getMetaData(variable);
}
actionNode.setMetaData("MessageType", message.getType());
actionNode.setMetaData("TriggerType", "ProduceMessage");
actionNode.setMetaData("TriggerRef", message.getName());
for (Entry<String, Object> entry : message.getMetaData().entrySet()) {
actionNode.setMetaData(entry.getKey(), entry.getValue());
}
ConsequenceAction action = createJavaAction(new HandleMessageAction(message.getType(), variable, (Transformation) actionNode.getMetaData().get(TRANSFORMATION_KEY)));
actionNode.setAction(action);
}
xmlNode = xmlNode.getNextSibling();
}
}
use of io.automatiko.engine.workflow.base.core.context.variable.Variable in project automatiko-engine by automatiko-io.
the class CompositeContextNodeHandler method writeNode.
public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
CompositeContextNode compositeNode = (CompositeContextNode) node;
String nodeType = "subProcess";
if (node.getMetaData().get("Transaction") != null) {
nodeType = "transaction";
}
writeNode(nodeType, compositeNode, xmlDump, metaDataType);
if (compositeNode instanceof EventSubProcessNode) {
xmlDump.append(" triggeredByEvent=\"true\" ");
}
Object isForCompensationObject = compositeNode.getMetaData("isForCompensation");
if (isForCompensationObject != null && ((Boolean) isForCompensationObject)) {
xmlDump.append("isForCompensation=\"true\" ");
}
xmlDump.append(">" + EOL);
writeExtensionElements(compositeNode, xmlDump);
// variables
VariableScope variableScope = (VariableScope) compositeNode.getDefaultContext(VariableScope.VARIABLE_SCOPE);
if (variableScope != null && !variableScope.getVariables().isEmpty()) {
xmlDump.append(" <!-- variables -->" + EOL);
for (Variable variable : variableScope.getVariables()) {
xmlDump.append(" <property id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(variable.getName()) + "\" ");
if (variable.getType() != null) {
xmlDump.append("itemSubjectRef=\"" + XmlBPMNProcessDumper.getUniqueNodeId(compositeNode) + "-" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(variable.getName()) + "Item\"");
}
// TODO: value
xmlDump.append("/>" + EOL);
}
}
// nodes
List<Node> subNodes = getSubNodes(compositeNode);
XmlBPMNProcessDumper.INSTANCE.visitNodes(subNodes, xmlDump, metaDataType);
// connections
visitConnectionsAndAssociations(compositeNode, xmlDump, metaDataType);
endNode(nodeType, xmlDump);
}
Aggregations