use of org.jbpm.workflow.core.Constraint in project jbpm by kiegroup.
the class Split method isDefault.
public boolean isDefault(final Connection connection) {
if (connection == null) {
throw new IllegalArgumentException("connection is null");
}
if (this.type == TYPE_OR || this.type == TYPE_XOR) {
ConnectionRef ref = new ConnectionRef(connection.getTo().getId(), connection.getToType());
Constraint constraint = this.constraints.get(ref);
String defaultConnection = (String) getMetaData().get("Default");
String connectionId = (String) connection.getMetaData().get("UniqueId");
if (constraint != null) {
return constraint.isDefault();
} else if (constraint == null && connectionId.equals(defaultConnection)) {
return true;
} else {
return false;
}
}
throw new UnsupportedOperationException("Constraints are " + "only supported with XOR or OR split types, not with: " + getType());
}
use of org.jbpm.workflow.core.Constraint in project jbpm by kiegroup.
the class ProcessBuilderImpl method generateRules.
private void generateRules(Node[] nodes, Process process, StringBuffer builder) {
for (int i = 0; i < nodes.length; i++) {
if (nodes[i] instanceof Split) {
Split split = (Split) nodes[i];
if (split.getType() == Split.TYPE_XOR || split.getType() == Split.TYPE_OR) {
for (Connection connection : split.getDefaultOutgoingConnections()) {
Constraint constraint = split.getConstraint(connection);
if (constraint != null && "rule".equals(constraint.getType())) {
builder.append(createSplitRule(process, connection, split.getConstraint(connection).getConstraint()));
}
}
}
} else if (nodes[i] instanceof MilestoneNode) {
MilestoneNode milestone = (MilestoneNode) nodes[i];
builder.append(createMilestoneRule(process, milestone));
} else if (nodes[i] instanceof StateNode) {
StateNode state = (StateNode) nodes[i];
builder.append(createStateRules(process, state));
} else if (nodes[i] instanceof StartNode) {
StartNode startNode = (StartNode) nodes[i];
List<Trigger> triggers = startNode.getTriggers();
if (triggers != null) {
for (Trigger trigger : triggers) {
if (trigger instanceof ConstraintTrigger) {
builder.append(createStartConstraintRule(process, startNode.getNodeContainer(), (ConstraintTrigger) trigger));
}
}
}
} else if (nodes[i] instanceof NodeContainer) {
generateRules(((NodeContainer) nodes[i]).getNodes(), process, builder);
if (nodes[i] instanceof DynamicNode && "rule".equals(((DynamicNode) nodes[i]).getLanguage())) {
DynamicNode dynamicNode = (DynamicNode) nodes[i];
if (dynamicNode.getCompletionExpression() != null) {
builder.append(createAdHocCompletionRule(process, dynamicNode));
}
if (dynamicNode.getActivationExpression() != null && !dynamicNode.getActivationExpression().isEmpty()) {
builder.append(createAdHocActivationRule(process, dynamicNode));
}
}
} else if (nodes[i] instanceof EventNode) {
EventNode state = (EventNode) nodes[i];
builder.append(createEventStateRule(process, state));
}
}
}
use of org.jbpm.workflow.core.Constraint in project jbpm by kiegroup.
the class SplitNodeHandler method writeNode.
public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
Split splitNode = (Split) node;
writeNode("split", splitNode, xmlDump, includeMeta);
int type = splitNode.getType();
if (type != 0) {
xmlDump.append("type=\"" + type + "\" ");
}
if (splitNode.getConstraints().isEmpty()) {
endNode(xmlDump);
} else {
xmlDump.append(">" + EOL);
if (includeMeta) {
writeMetaData(splitNode, xmlDump);
}
xmlDump.append(" <constraints>" + EOL);
for (Map.Entry<ConnectionRef, Constraint> entry : splitNode.getConstraints().entrySet()) {
ConnectionRef connection = entry.getKey();
Constraint constraint = entry.getValue();
xmlDump.append(" <constraint " + "toNodeId=\"" + connection.getNodeId() + "\" " + "toType=\"" + connection.getToType() + "\" ");
String name = constraint.getName();
if (name != null && !"".equals(name)) {
xmlDump.append("name=\"" + XmlDumper.replaceIllegalChars(constraint.getName()) + "\" ");
}
int priority = constraint.getPriority();
if (priority != 0) {
xmlDump.append("priority=\"" + constraint.getPriority() + "\" ");
}
xmlDump.append("type=\"" + constraint.getType() + "\" ");
String dialect = constraint.getDialect();
if (dialect != null && !"".equals(dialect)) {
xmlDump.append("dialect=\"" + dialect + "\" ");
}
String constraintString = constraint.getConstraint();
if (constraintString != null) {
xmlDump.append(">" + XmlDumper.replaceIllegalChars(constraintString) + "</constraint>" + EOL);
} else {
xmlDump.append("/>" + EOL);
}
}
xmlDump.append(" </constraints>" + EOL);
endNode("split", xmlDump);
}
}
use of org.jbpm.workflow.core.Constraint in project jbpm by kiegroup.
the class XmlBPMNProcessDumper method visitConnection.
public void visitConnection(Connection connection, StringBuilder xmlDump, int metaDataType) {
// if the connection was generated by a link event, don't dump.
if (isConnectionRepresentingLinkEvent(connection)) {
return;
}
// if the connection is a hidden one (compensations), don't dump
Object hidden = ((ConnectionImpl) connection).getMetaData("hidden");
if (hidden != null && ((Boolean) hidden)) {
return;
}
xmlDump.append(" <sequenceFlow id=\"" + getUniqueNodeId(connection.getFrom()) + "-" + getUniqueNodeId(connection.getTo()) + "\" sourceRef=\"" + getUniqueNodeId(connection.getFrom()) + "\" ");
// TODO fromType, toType
xmlDump.append("targetRef=\"" + getUniqueNodeId(connection.getTo()) + "\" ");
if (metaDataType == META_DATA_AS_NODE_PROPERTY) {
String bendpoints = (String) connection.getMetaData().get("bendpoints");
if (bendpoints != null) {
xmlDump.append("g:bendpoints=\"" + bendpoints + "\" ");
}
}
if (connection.getFrom() instanceof Split) {
Split split = (Split) connection.getFrom();
if (split.getType() == Split.TYPE_XOR || split.getType() == Split.TYPE_OR) {
Constraint constraint = split.getConstraint(connection);
if (constraint == null) {
xmlDump.append(">" + EOL + " <conditionExpression xsi:type=\"tFormalExpression\" />");
} else {
if (constraint.getName() != null && constraint.getName().trim().length() > 0) {
xmlDump.append("name=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(constraint.getName()) + "\" ");
}
if (constraint.getPriority() != 0) {
xmlDump.append("tns:priority=\"" + constraint.getPriority() + "\" ");
}
xmlDump.append(">" + EOL + " <conditionExpression xsi:type=\"tFormalExpression\" ");
if ("code".equals(constraint.getType())) {
if (JavaDialect.ID.equals(constraint.getDialect())) {
xmlDump.append("language=\"" + JAVA_LANGUAGE + "\" ");
} else if ("XPath".equals(constraint.getDialect())) {
xmlDump.append("language=\"" + XPATH_LANGUAGE + "\" ");
} else if ("JavaScript".equals(constraint.getDialect())) {
xmlDump.append("language=\"" + JAVASCRIPT_LANGUAGE + "\" ");
}
} else {
xmlDump.append("language=\"" + RULE_LANGUAGE + "\" ");
}
String constraintString = constraint.getConstraint();
if (constraintString == null) {
constraintString = "";
}
xmlDump.append(">" + XmlDumper.replaceIllegalChars(constraintString) + "</conditionExpression>");
}
xmlDump.append(EOL + " </sequenceFlow>" + EOL);
} else {
xmlDump.append("/>" + EOL);
}
} else {
xmlDump.append("/>" + EOL);
}
}
use of org.jbpm.workflow.core.Constraint in project jbpm by kiegroup.
the class ProcessHandler method postProcessNodes.
private void postProcessNodes(RuleFlowProcess process, NodeContainer container) {
List<String> eventSubProcessHandlers = new ArrayList<String>();
for (Node node : container.getNodes()) {
if (node instanceof StateNode) {
StateNode stateNode = (StateNode) node;
String condition = (String) stateNode.getMetaData("Condition");
Constraint constraint = new ConstraintImpl();
constraint.setConstraint(condition);
constraint.setType("rule");
for (org.kie.api.definition.process.Connection connection : stateNode.getDefaultOutgoingConnections()) {
stateNode.setConstraint(connection, constraint);
}
} else if (node instanceof NodeContainer) {
// prepare event sub process
if (node instanceof EventSubProcessNode) {
EventSubProcessNode eventSubProcessNode = (EventSubProcessNode) node;
Node[] nodes = eventSubProcessNode.getNodes();
for (Node subNode : nodes) {
// avoids cyclomatic complexity
if (subNode == null || !(subNode instanceof StartNode)) {
continue;
}
List<Trigger> triggers = ((StartNode) subNode).getTriggers();
if (triggers == null) {
continue;
}
for (Trigger trigger : triggers) {
if (trigger instanceof EventTrigger) {
final List<EventFilter> filters = ((EventTrigger) trigger).getEventFilters();
for (EventFilter filter : filters) {
if (filter instanceof EventTypeFilter) {
eventSubProcessNode.addEvent((EventTypeFilter) filter);
String type = ((EventTypeFilter) filter).getType();
if (type.startsWith("Error-") || type.startsWith("Escalation")) {
String faultCode = (String) subNode.getMetaData().get("FaultCode");
String replaceRegExp = "Error-|Escalation-";
final String signalType = type;
ExceptionScope exceptionScope = (ExceptionScope) ((ContextContainer) eventSubProcessNode.getNodeContainer()).getDefaultContext(ExceptionScope.EXCEPTION_SCOPE);
if (exceptionScope == null) {
exceptionScope = new ExceptionScope();
((ContextContainer) eventSubProcessNode.getNodeContainer()).addContext(exceptionScope);
((ContextContainer) eventSubProcessNode.getNodeContainer()).setDefaultContext(exceptionScope);
}
String faultVariable = null;
if (trigger.getInAssociations() != null && !trigger.getInAssociations().isEmpty()) {
faultVariable = trigger.getInAssociations().get(0).getTarget();
}
ActionExceptionHandler exceptionHandler = new ActionExceptionHandler();
DroolsConsequenceAction action = new DroolsConsequenceAction("java", PROCESS_INSTANCE_SIGNAL_EVENT + signalType + "\", " + (faultVariable == null ? "null" : "kcontext.getVariable(\"" + faultVariable + "\")") + ");");
exceptionHandler.setAction(action);
exceptionHandler.setFaultVariable(faultVariable);
if (faultCode != null) {
String trimmedType = type.replaceFirst(replaceRegExp, "");
exceptionScope.setExceptionHandler(trimmedType, exceptionHandler);
eventSubProcessHandlers.add(trimmedType);
} else {
exceptionScope.setExceptionHandler(faultCode, exceptionHandler);
}
} else if (type.equals("Compensation")) {
// 1. Find the parent sub-process to this event sub-process
NodeContainer parentSubProcess;
NodeContainer subProcess = eventSubProcessNode.getNodeContainer();
Object isForCompensationObj = eventSubProcessNode.getMetaData("isForCompensation");
if (isForCompensationObj == null) {
eventSubProcessNode.setMetaData("isForCompensation", true);
logger.warn("Overriding empty or false value of \"isForCompensation\" attribute on Event Sub-Process [" + eventSubProcessNode.getMetaData("UniqueId") + "] and setting it to true.");
}
if (subProcess instanceof RuleFlowProcess) {
// ..how do you expect to signal compensation on the completed process (instance)?!?
throw new IllegalArgumentException("Compensation Event Sub-Processes at the process level are not supported.");
}
parentSubProcess = ((Node) subProcess).getNodeContainer();
// 2. The event filter (never fires, purely for dumping purposes) has already been added
// 3. Add compensation scope
String compensationHandlerId = (String) ((CompositeNode) subProcess).getMetaData("UniqueId");
addCompensationScope(process, eventSubProcessNode, parentSubProcess, compensationHandlerId);
}
}
}
} else if (trigger instanceof ConstraintTrigger) {
ConstraintTrigger constraintTrigger = (ConstraintTrigger) trigger;
if (constraintTrigger.getConstraint() != null) {
String processId = ((RuleFlowProcess) container).getId();
String type = "RuleFlowStateEventSubProcess-Event-" + processId + "-" + eventSubProcessNode.getUniqueId();
EventTypeFilter eventTypeFilter = new EventTypeFilter();
eventTypeFilter.setType(type);
eventSubProcessNode.addEvent(eventTypeFilter);
}
}
}
}
// for( Node subNode : nodes)
}
postProcessNodes(process, (NodeContainer) node);
} else if (node instanceof EndNode) {
handleIntermediateOrEndThrowCompensationEvent((EndNode) node);
} else if (node instanceof ActionNode) {
handleIntermediateOrEndThrowCompensationEvent((ActionNode) node);
} else if (node instanceof EventNode) {
final EventNode eventNode = (EventNode) node;
if (!(eventNode instanceof BoundaryEventNode) && eventNode.getDefaultIncomingConnections().size() == 0) {
throw new IllegalArgumentException("Event node '" + node.getName() + "' [" + node.getId() + "] has no incoming connection");
}
}
}
// process fault node to disable termnate parent if there is event subprocess handler
for (Node node : container.getNodes()) {
if (node instanceof FaultNode) {
FaultNode faultNode = (FaultNode) node;
if (eventSubProcessHandlers.contains(faultNode.getFaultName())) {
faultNode.setTerminateParent(false);
}
}
}
}
Aggregations