Package org.drools.definition.process

Examples of org.drools.definition.process.Node


            if (node instanceof EventNode) {
                String attachedTo = (String) node.getMetaData().get("AttachedTo");
                if (attachedTo != null) {
                  String type = ((EventTypeFilter)
                        ((EventNode) node).getEventFilters().get(0)).getType();
                    Node attachedNode = null;
                    try {
                        // remove starting _
                        String attachedToString = attachedTo.substring(1);
                        // remove ids of parent nodes
                        attachedToString = attachedToString.substring(attachedToString.lastIndexOf("-") + 1);
View Full Code Here


            throw new IllegalArgumentException( "Could not read process" );
        }
        log.debug( "Processing " + process.getId() );
        result = new HashMap<String, String[]>();
        StartNode start = process.getStart();
        Node target = start.getTo().getTo();
        if ( target instanceof Split ) {
            Split split = (Split) target;
            for ( Connection connection : split.getDefaultOutgoingConnections() ) {
                Constraint constraint = split.getConstraint( connection );
                if ( constraint != null ) {
View Full Code Here

        if ( process == null ) {
            throw new IllegalArgumentException( "Could not read process" );
        } else {
            log.debug( "Processing " + process.getId() );
            StartNode start = process.getStart();
            Node target = start.getTo().getTo();
            if ( target instanceof Split ) {
                Split split = (Split) target;
                for ( Connection connection : split.getDefaultOutgoingConnections() ) {
                    String s = constraints.get( XmlBPMNProcessDumper.getUniqueNodeId( connection.getTo() ) );
                    if ( s != null ) {
View Full Code Here

            for (String key : incomingConnectionsTypes) {
                Iterator<Connection> itConnections = node.getIncomingConnections(key).iterator();
                long fromNodeId = 0;
                while (itConnections.hasNext()) {
                    Connection connection = itConnections.next();
                    Node fromNode = connection.getFrom();

                    fromNodeId = connection.getTo().getId();
                    if(fromNode instanceof org.drools.jpdl.core.node.State){
                        System.out.println("<!-- Take a look at the State Node that is pointing here, " +
                                "you will need to change the constraint for signal it to the new JoinNode id -->");
                        System.out.println("<!-- in node id: "+fromNode.getId()+ " / name: "+fromNode.getName()+" -->");
                        System.out.println("<!-- you should change the fromId ("+fromNodeId+") attribute to: "+suggestedNodeId+"-->");
                        System.out.println("<!-- you can also change the name for something that reference the JoinNode -->");
                    }
                    fromNode.getOutgoingConnections(key).remove(connection);
                    resultGeneratedConnection += "  <connection from=\"" + fromNode.getId() + "\" to=\"" + suggestedNodeId + "\" />\n";
                }
                resultGeneratedConnection += "  <connection from=\"" + suggestedNodeId + "\" to=\"" + fromNodeId + "\" />\n";
            }
            System.out.println("<!-- END - This is a suggested Join Node -->");
            suggestedNodeId++;
View Full Code Here

            List<Connection> removeConnections = new ArrayList<Connection>();
            for (String key : outgoingConnectionsTypes) {
                Iterator<Connection> itConnections = node.getOutgoingConnections(key).iterator();
                while (itConnections.hasNext()) {
                    Connection connection = itConnections.next();
                    Node toNode = connection.getTo();
                    removeConnections.add(connection);
                    resultGeneratedConnection += "  <connection from=\"" + suggestedNodeId + "\" to=\"" + toNode.getId() + "\" />\n";
                }
               

            }
            resultGeneratedConnection += "  <connection from=\"" + node.getId() + "\" to=\"" + suggestedNodeId + "\" />\n";
View Full Code Here

                "Process has no package name."));
        }

        final Node[] nodes = process.getNodes();
        validateNodes(nodes, errors, process);
        Node startNode = process.getStart();
        if (startNode == null) {
            errors.add(new ProcessValidationErrorImpl(process,
                "Process has no start node."));
        }
        for (final Iterator<Variable> it = process.getVariableScope().getVariables().iterator(); it.hasNext(); ) {
View Full Code Here

        return errors.toArray(new ProcessValidationError[errors.size()]);
    }
   
    private void validateNodes(Node[] nodes, List<ProcessValidationError> errors, JpdlProcess process) {
        for ( int i = 0; i < nodes.length; i++ ) {
            final Node node = nodes[i];
            if (node instanceof StartState) {
                final StartState startState = (StartState) node;
                if (startState.getOutgoingConnections().size() == 0) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "Start state '" + node.getName() + "' [" + node.getId() + "] has no outgoing connections."));
                }
                boolean outgoingConnection = false;
                for (List<Connection> connections: startState.getOutgoingConnections().values()) {
                  if (connections.size() > 0) {
                    outgoingConnection = true;
                    break;
                  }
                }
                if (!outgoingConnection) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "Start state '" + node.getName() + "' [" + node.getId() + "] has no outgoing connections."));
                }
            } else if (node instanceof EndState) {
                final EndState endState = (EndState) node;
                if (endState.getIncomingConnections().size() != 1) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "End state '" + node.getName() + "' [" + node.getId() + "] has more than one type of incoming connections."));
                }
                List<Connection> connections = endState.getIncomingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE)
                if (connections == null || connections.size() == 0) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "End state '" + node.getName() + "' [" + node.getId() + "] has no default incoming connections."));
                }
            } else if (node instanceof RuleSetNode) {
                final RuleSetNode ruleSetNode = (RuleSetNode) node;
                if (ruleSetNode.getFrom() == null) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "RuleSet node '" + node.getName() + "' [" + node.getId() + "] has no incoming connection."));
                }
                if (ruleSetNode.getTo() == null) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "RuleSet node '" + node.getName() + "' [" + node.getId() + "] has no outgoing connection."));
                }
                final String ruleFlowGroup = ruleSetNode.getRuleFlowGroup();
                if (ruleFlowGroup == null || "".equals(ruleFlowGroup)) {
                    errors.add( new ProcessValidationErrorImpl(process,
                        "RuleSet node '" + node.getName() + "' [" + node.getId() + "] has no ruleflow-group."));
                }
            } else if (node instanceof Split) {
                final Split split = (Split) node;
                if (split.getType() == Split.TYPE_UNDEFINED) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "Split node '" + node.getName() + "' [" + node.getId() + "] has no type."));
                }
                if (split.getFrom() == null) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "Split node '" + node.getName() + "' [" + node.getId() + "] has no incoming connection."));
                }
                if (split.getDefaultOutgoingConnections().size() < 2) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "Split node '" + node.getName() + "' [" + node.getId() + "] does not have more than one outgoing connection: " + split.getOutgoingConnections().size() + "."));
                }
                if (split.getType() == Split.TYPE_XOR || split.getType() == Split.TYPE_OR ) {
                    for ( final Iterator<Connection> it = split.getDefaultOutgoingConnections().iterator(); it.hasNext(); ) {
                        final Connection connection = it.next();
                        if (split.getConstraint(connection) == null) {
                            errors.add(new ProcessValidationErrorImpl(process,
                                "Split node '" + node.getName() + "' [" + node.getId() + "] does not have a constraint for " + connection.toString() + "."));
                        }
                    }
                }
            } else if ( node instanceof Join ) {
                final Join join = (Join) node;
                if (join.getType() == Join.TYPE_UNDEFINED) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "Join node '" + node.getName() + "' [" + node.getId() + "] has no type."));
                }
                if (join.getDefaultIncomingConnections().size() < 2) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "Join node '" + node.getName() + "' [" + node.getId() + "] does not have more than one incoming connection: " + join.getIncomingConnections().size() + "."));
                }
                if (join.getTo() == null) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "Join node '" + node.getName() + "' [" + node.getId() + "] has no outgoing connection."));
                }
            } else if (node instanceof MilestoneNode) {
                final MilestoneNode milestone = (MilestoneNode) node;
                if (milestone.getFrom() == null) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "Milestone node '" + node.getName() + "' [" + node.getId() + "] has no incoming connection."));
                }

                if (milestone.getTo() == null) {
                    errors.add( new ProcessValidationErrorImpl(process,
                        "Milestone node '" + node.getName() + "' [" + node.getId() + "] has no outgoing connection."));
                }
                if (milestone.getConstraint() == null) {
                    errors.add( new ProcessValidationErrorImpl(process,
                        "Milestone node '" + node.getName() + "' [" + node.getId() + "] has no constraint."));
                }
            } else if (node instanceof SubProcessNode) {
                final SubProcessNode subProcess = (SubProcessNode) node;
                if (subProcess.getFrom() == null) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "SubProcess node '" + node.getName() + "' [" + node.getId() + "] has no incoming connection."));
                }
                if (subProcess.getTo() == null) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "SubProcess node '" + node.getName() + "' [" + node.getId() + "] has no outgoing connection."));
                }
                if (subProcess.getProcessId() == null) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "SubProcess node '" + node.getName() + "' [" + node.getId() + "] has no process id."));
                }
            } else if (node instanceof ActionNode) {
                final ActionNode actionNode = (ActionNode) node;
                if (actionNode.getFrom() == null) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "Action node '" + node.getName() + "' [" + node.getId() + "] has no incoming connection."));
                }
                if (actionNode.getTo() == null) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "Action node '" + node.getName() + "' [" + node.getId() + "] has no outgoing connection."));
                }
                if (actionNode.getAction() == null) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "Action node '" + node.getName() + "' [" + node.getId() + "] has no action."));
                } else {
                    if (actionNode.getAction() instanceof DroolsConsequenceAction) {
                        DroolsConsequenceAction droolsAction = (DroolsConsequenceAction) actionNode.getAction();
                        String actionString = droolsAction.getConsequence();
                        if (actionString == null) {
                            errors.add(new ProcessValidationErrorImpl(process,
                                "Action node '" + node.getName() + "' [" + node.getId() + "] has empty action."));
                        } else {
                            try {
                                ExpressionCompiler compiler = new ExpressionCompiler(actionString);
                                compiler.setVerifying(true);
                                ParserContext parserContext = new ParserContext();
                                //parserContext.setStrictTypeEnforcement(true);
                                compiler.compile(parserContext);
                                List<ErrorDetail> mvelErrors = parserContext.getErrorList();
                                if (mvelErrors != null) {
                                    for (Iterator<ErrorDetail> iterator = mvelErrors.iterator(); iterator.hasNext(); ) {
                                        ErrorDetail error = iterator.next();
                                        errors.add(new ProcessValidationErrorImpl(process,
                                            "Action node '" + node.getName() + "' [" + node.getId() + "] has invalid action: " + error.getMessage() + "."));
                                    }
                                }
                            } catch (Throwable t) {
                                errors.add(new ProcessValidationErrorImpl(process,
                                    "Action node '" + node.getName() + "' [" + node.getId() + "] has invalid action: " + t.getMessage() + "."));
                            }
                        }
                    }
                }
            } else if (node instanceof WorkItemNode) {
                final WorkItemNode workItemNode = (WorkItemNode) node;
                if (workItemNode.getFrom() == null) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "WorkItem node '" + node.getName() + "' [" + node.getId() + "] has no incoming connection."));
                }
                if (workItemNode.getTo() == null) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "WorkItem node '" + node.getName() + "' [" + node.getId() + "] has no outgoing connection."));
                }
                if (workItemNode.getWork() == null) {
                    errors.add(new ProcessValidationErrorImpl(process,
                        "WorkItem node '" + node.getName() + "' [" + node.getId() + "] has no work specified."));
                } else {
                    Work work = workItemNode.getWork();
                    if (work.getName() == null) {
                        errors.add(new ProcessValidationErrorImpl(process,
                            "WorkItem node '" + node.getName() + "' [" + node.getId() + "] has no work name."));
                    }
                }
            } else if (node instanceof CompositeNode) {
                final CompositeNode compositeNode = (CompositeNode) node;
                for (String inType: compositeNode.getLinkedIncomingNodes().keySet()) {
                    if (compositeNode.getIncomingConnections(inType).size() == 0) {
                        errors.add(new ProcessValidationErrorImpl(process,
                            "Composite node '" + node.getName() + "' [" + node.getId() + "] has no incoming connection for type " + inType));
                    }
                }
                for (String outType: compositeNode.getLinkedOutgoingNodes().keySet()) {
                    if (compositeNode.getOutgoingConnections(outType).size() == 0) {
                        errors.add(new ProcessValidationErrorImpl(process,
                            "Composite node '" + node.getName() + "' [" + node.getId() + "] has no outgoing connection for type " + outType));
                    }
                }
                validateNodes(compositeNode.getNodes(), errors, process);
            }
        }
View Full Code Here

    private void checkAllNodesConnectedToStart(final JpdlProcess process,
                                               final List<ProcessValidationError> errors) {
        final Map<Node, Boolean> processNodes = new HashMap<Node, Boolean>();
        final Node[] nodes = process.getNodes();
        for (int i = 0; i < nodes.length; i++) {
            final Node node = nodes[i];
            processNodes.put(node, Boolean.FALSE);
        }
        Node startNode = process.getStart();
        if (startNode != null) {
            processNode(startNode, processNodes);
        }
        for ( final Iterator<Node> it = processNodes.keySet().iterator(); it.hasNext(); ) {
            final Node node = it.next();
            if (Boolean.FALSE.equals(processNodes.get(node))) {
                errors.add(new ProcessValidationErrorImpl(process,
                    "Node '" + node.getName() + "' [" + node.getId() + "] has no connection to the start node."));
            }
        }
    }
View Full Code Here

    public static void updateProcess(RuleFlowProcess process,
                                     Collection<TransferNode> contentNodes) {

        for ( TransferNode tn : contentNodes ) {

            Node node = process.getNode( tn.getId() );

            updateNode( tn,
                        node );
        }
    }
View Full Code Here

    private static void updateForEach(ElementContainerTransferNode tn,
                                      ForEachNode foreachNode) {

        for ( TransferNode subTn : tn.getContentModel().getNodes() ) {

            Node subNode = foreachNode.getNode( subTn.getId() );

            updateNode( subTn,
                        subNode );
        }
    }
View Full Code Here

TOP

Related Classes of org.drools.definition.process.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.