use of org.jbpm.workflow.core.impl.MultiInstanceSpecification in project kogito-runtimes by kiegroup.
the class AbstractNodeHandler method decorateMultiInstanceSpecification.
protected ForEachNode decorateMultiInstanceSpecification(NodeImpl nodeTarget, MultiInstanceSpecification multiInstanceSpecification) {
ForEachNode forEachNode = new ForEachNode();
forEachNode.setId(nodeTarget.getId());
forEachNode.setName(nodeTarget.getName());
nodeTarget.setMetaData("hidden", true);
forEachNode.setIoSpecification(nodeTarget.getIoSpecification());
DataDefinition dataInput = multiInstanceSpecification.getInputDataItem();
DataDefinition dataOutput = multiInstanceSpecification.getOutputDataItem();
if (dataInput != null) {
forEachNode.setInputRef(dataInput.getLabel());
forEachNode.addContextVariable(dataInput.getId(), dataInput.getLabel(), fromType(dataInput.getType(), currentThread().getContextClassLoader()));
forEachNode.getIoSpecification().getDataInputAssociation().stream().filter(e -> !e.getSources().isEmpty() && e.getSources().get(0).getId().equals(dataInput.getId())).forEach(da -> {
da.getSources().clear();
da.getSources().add(dataInput);
});
}
if (dataOutput != null) {
forEachNode.setOutputRef(dataOutput.getLabel());
forEachNode.addContextVariable(dataOutput.getId(), dataOutput.getLabel(), fromType(dataOutput.getType(), currentThread().getContextClassLoader()));
forEachNode.getIoSpecification().getDataOutputAssociation().stream().filter(e -> e.getTarget().getId().equals(dataOutput.getId())).forEach(da -> {
da.setTarget(dataOutput);
});
}
if (multiInstanceSpecification.hasLoopDataInputRef()) {
DataDefinition dataInputRef = multiInstanceSpecification.getLoopDataInputRef();
// inputs and outputs are still processes so we need to get rid of the input of belonging to the
// loop
nodeTarget.getMetaData().put("MICollectionInput", dataInputRef.getLabel());
// this is a correction as the input collection is the source of the expr (target)
// so target is the input collection of the node
// so we look in the source of the data input a target is equal to the data input getting the source we get the source
// collection at context level (subprocess or activity)
forEachNode.getIoSpecification().getDataInputAssociation().stream().filter(e -> e.getTarget().getId().equals(dataInputRef.getId())).findAny().ifPresent(pVar -> {
String expr = pVar.getSources().get(0).getLabel();
forEachNode.setCollectionExpression(expr);
});
}
if (multiInstanceSpecification.hasLoopDataOutputRef()) {
// same correction as input
// we determine the output ref and locate the source. if set the target we get the variable at that level.
DataDefinition dataOutputRef = multiInstanceSpecification.getLoopDataOutputRef();
nodeTarget.getMetaData().put("MICollectionOutput", dataOutputRef.getLabel());
forEachNode.getIoSpecification().getDataOutputAssociation().stream().filter(e -> e.getSources().get(0).getId().equals(dataOutputRef.getId())).findAny().ifPresent(e -> {
forEachNode.setOutputCollectionExpression(e.getTarget().getLabel());
});
// another correction colletion output is not being stored in the composite context multiinstance
// we use foreach_output
Iterator<DataAssociation> iterator = forEachNode.getIoSpecification().getDataOutputAssociation().iterator();
while (iterator.hasNext()) {
DataAssociation current = iterator.next();
if (!current.getSources().isEmpty() && current.getSources().get(0).equals(dataOutputRef)) {
iterator.remove();
}
}
}
// this is just an expression
forEachNode.setCompletionConditionExpression(multiInstanceSpecification.getCompletionCondition());
forEachNode.setMultiInstanceSpecification(multiInstanceSpecification);
// This variable is used for adding items computed by each subcontext.
// after foreach is finished it will be moved to the data output ref collection of the multiinstance
// this is the context of each subprocess
VariableScope foreachContext = ((VariableScope) forEachNode.getCompositeNode().getDefaultContext(VariableScope.VARIABLE_SCOPE));
Variable forEach = new Variable();
forEach.setId("foreach_output");
forEach.setName("foreach_output");
forEach.setType(DataTypeResolver.fromType(Collection.class.getCanonicalName(), Thread.currentThread().getContextClassLoader()));
foreachContext.addVariable(forEach);
return forEachNode;
}
use of org.jbpm.workflow.core.impl.MultiInstanceSpecification in project kogito-runtimes by kiegroup.
the class AbstractNodeHandler method readMultiInstanceSpecification.
// this is only for compiling purposes
protected MultiInstanceSpecification readMultiInstanceSpecification(ExtensibleXmlParser parser, org.w3c.dom.Node parent, IOSpecification ioSpecification) {
MultiInstanceSpecification multiInstanceSpecification = new MultiInstanceSpecification();
Optional<Element> multiInstanceParent = readSingleChildElementByTag(parent, "multiInstanceLoopCharacteristics");
if (multiInstanceParent.isEmpty()) {
return multiInstanceSpecification;
}
Element multiInstanceNode = multiInstanceParent.get();
multiInstanceSpecification.setSequential(Boolean.parseBoolean(multiInstanceNode.getAttribute("isSequential")));
readSingleChildElementByTag(multiInstanceNode, "inputDataItem").ifPresent(inputDataItem -> {
String id = inputDataItem.getAttribute("id");
String name = inputDataItem.getAttribute("name");
String itemSubjectRef = inputDataItem.getAttribute("itemSubjectRef");
ItemDefinition itemDefinition = getStructureRef(parser, itemSubjectRef);
String structureRef = itemDefinition != null ? itemDefinition.getStructureRef() : null;
DataDefinition input = new DataDefinition(id, name, structureRef);
multiInstanceSpecification.setInputDataItem(input);
if (!ioSpecification.containsInputLabel(input.getLabel())) {
ioSpecification.getDataInputs().add(input);
}
});
readSingleChildElementByTag(multiInstanceNode, "outputDataItem").ifPresent(outputDataItem -> {
String id = outputDataItem.getAttribute("id");
String name = outputDataItem.getAttribute("name");
String itemSubjectRef = outputDataItem.getAttribute("itemSubjectRef");
ItemDefinition itemDefinition = getStructureRef(parser, itemSubjectRef);
String structureRef = itemDefinition != null ? itemDefinition.getStructureRef() : null;
DataDefinition output = new DataDefinition(id, name, structureRef);
multiInstanceSpecification.setOutputDataItem(output);
if (!ioSpecification.containsOutputLabel(output.getLabel())) {
ioSpecification.getDataOutputs().add(output);
}
});
readSingleChildElementByTag(multiInstanceNode, "loopDataOutputRef").ifPresent(loopDataOutputRef -> {
String expressiontOutput = loopDataOutputRef.getTextContent();
if (expressiontOutput != null && !expressiontOutput.isEmpty()) {
multiInstanceSpecification.setLoopDataOutputRef(ioSpecification.getDataOutput().get(expressiontOutput));
}
});
readSingleChildElementByTag(multiInstanceNode, "loopDataInputRef").ifPresent(loopDataInputRef -> {
String expressionInput = loopDataInputRef.getTextContent();
if (expressionInput != null && !expressionInput.isEmpty()) {
multiInstanceSpecification.setLoopDataInputRef(ioSpecification.getDataInput().get(expressionInput));
}
});
readSingleChildElementByTag(multiInstanceNode, COMPLETION_CONDITION).ifPresent(completeCondition -> {
String completion = completeCondition.getTextContent();
if (completion != null && !completion.isEmpty()) {
multiInstanceSpecification.setCompletionCondition(completion);
}
});
return multiInstanceSpecification;
}
Aggregations