Package org.aperteworkflow.bpm.graph

Examples of org.aperteworkflow.bpm.graph.StateNode


                        if (firstTransition != null) {
                            res.add(firstTransition);
                        }
                    }
                  
                    StateNode sn = (StateNode) processGraphElements.get(activityName);
                   
                  
                   
                    ArrayList<StateNode> arrayList = new ArrayList<StateNode>();
                    Collection<GraphElement> values = processGraphElements.values();
                    for (GraphElement graphElement : values) {
            if(graphElement instanceof StateNode){
              arrayList.add((StateNode) graphElement);
            }
                     
                     
          }
                    if (sn == null) continue;
                    sn = sn.cloneNode();
                    sn.setUnfinished(activity.getEndTime() == null);
                    sn.setLabel(activityName + ": " + hpi.getDuration() + "ms");
                    res.add(sn);
                    //look for transition
                    TransitionArc ta = (TransitionArc) processGraphElements.get(activityName + "_" + activity.getTransitionName());
                    if (ta == null) { //look for default!
                        ta = (TransitionArc) processGraphElements.get("__AWF__default_transition_" + activityName);
                    }
                    if (ta == null) {
                        continue;
                    }
                   
           
                   
                 
                   
                    res.add(ta.cloneNode());
                } else {
                    loger.severe("Unsupported entry: " + hpi);
                }
            }
           
           addJoinAndForkElements(res,processGraphElements);
           
           
            HistoryProcessInstanceQuery historyProcessInstanceQuery = processEngine.getHistoryService()
                    .createHistoryProcessInstanceQuery().processInstanceId(pi.getInternalId());
            HistoryProcessInstance historyProcessInstance = historyProcessInstanceQuery.uniqueResult();
            if (historyProcessInstance != null && historyProcessInstance.getEndActivityName() != null) {
                StateNode sn = (StateNode) processGraphElements.get(historyProcessInstance.getEndActivityName());
                if (sn != null) {
                    StateNode e = sn.cloneNode();
                    e.setUnfinished(true);
                    res.add(e);
                }
            }
           
           
View Full Code Here


                for (String nodeType : nodeTypes) {
                    NodeList nodes = documentElement.getElementsByTagName(nodeType);
                    for (int i = 0; i < nodes.getLength(); i++) {
                        Element node = (Element) nodes.item(i);
                        try {
                            StateNode sn = new StateNode();
                            String gval = node.getAttribute("g");
                            String[] vals = gval.split(",", 4);
                            int x = Integer.parseInt(vals[0]);
                            int y = Integer.parseInt(vals[1]);
                            int w = Integer.parseInt(vals[2]);
                            int h = Integer.parseInt(vals[3]);
                            sn.setX(x);
                            sn.setY(y);
                            sn.setWidth(w);
                            sn.setHeight(h);
                            sn.setNodeType(nodeType);
                            String name = node.getAttribute("name");
                            sn.setLabel(name);
                            res.put(name, sn);
                            if ("start".equals(nodeType)) {
                                res.put("__AWF__start_node", sn);
                            }
                            loger.fine("Found node" + name + ": " + x + "," + y + "," + w + "," + h);
                        } catch (Exception e) {
                            loger.log(Level.SEVERE, e.getMessage(), e);
                        }
                    }
                }
                    //once again - for transitions
                for (String nodeType : nodeTypes) {
                    NodeList nodes = documentElement.getElementsByTagName(nodeType);
                    for (int i = 0; i < nodes.getLength(); i++) {
                        Element node = (Element) nodes.item(i);
                        try {
                            String startNodeName = node.getAttribute("name");
                            StateNode startNode = (StateNode) res.get(startNodeName);
                            if (startNode == null) {
                                loger.severe("Start node " + startNodeName +
                                        " has not been localized, skipping transition drawing too.");
                                continue;
                            }
                            NodeList transitions = node.getElementsByTagName("transition");
                            for (int j=0; j < transitions.getLength(); j++) {
                                Element transitionEl = (Element) transitions.item(j);
                                String name = transitionEl.getAttribute("name");
                                String to = transitionEl.getAttribute("to") ;
                                StateNode endNode = (StateNode) res.get(to);
                                if (endNode == null) {
                                    loger.severe("End node " + to + " has not been localized for transition " + name +
                                            " of node " + startNodeName + ", skipping transition drawing.");
                                    continue;
                                }
                                String g = transitionEl.getAttribute("g");
                                if (g != null) {
                                    String[] dockersAndDistances = g.split(":");
                                    String[] dockers = new String[0];
                                    if (dockersAndDistances.length == 2) {
                                        dockers = dockersAndDistances[0].split(";");//what the other numbers mean - I have no idea...
                                    }
                                    //calculate line start node which is a center of the start node
                                    int startX = startNode.getX() + startNode.getWidth()/2;
                                    int startY = startNode.getY() + startNode.getHeight()/2;
                                    //and the same for end node
                                    int endX   = endNode.getX() + endNode.getWidth()/2;
                                    int endY   = endNode.getY() + endNode.getHeight()/2;

                                    TransitionArc arc = new TransitionArc();
                                    arc.setName(name);
                                    arc.addPoint(startX, startY);
                                    for (String docker : dockers) {
                                        String[] split = docker.split(",",2);
                                        arc.addPoint(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
                                    }
                                    arc.addPoint(endX, endY);

                                    double a;//remember about vertical line
                                    double b;

                                    endX = arc.getPath().get(1).getX();
                                    endY = arc.getPath().get(1).getY();
                                    if (startX - endX == 0) { //whoa - vertical line - simple case, but requires special approach
                                        if (endY > startNode.getY()+startNode.getHeight()) { //below
                                            startY = startNode.getY()+startNode.getHeight();
                                        } else {
                                            startY = startNode.getY();
                                        }
                                    } else {
                                        a = ((double)(startY-endY))/((double)(startX - endX));
                                        b = (double)startY - (double)startX*a;
                                        for (int x = startX; x <= endX; x++) {
                                            int y = (int) Math.round(a*x+b);
                                            boolean inside = false;
                                            if (x >= startNode.getX() && x <= startNode.getX() + startNode.getWidth()) {
                                                if (y >= startNode.getY() && y <= startNode.getY() + startNode.getHeight()) {
                                                    inside = true;
                                                }
                                            }
                                            if (!inside) {
                                                startX = x;
                                                startY = y;
                                                break;
                                            }
                                        }
                                        for (int x = startX; x > endX; x--) {
                                            int y = (int) Math.round(a*x+b);
                                            boolean inside = false;
                                            if (x >= startNode.getX() && x <= startNode.getX() + startNode.getWidth()) {
                                                if (y >= startNode.getY() && y <= startNode.getY() + startNode.getHeight()) {
                                                    inside = true;
                                                }
                                            }
                                            if (!inside) {
                                                startX = x;
                                                startY = y;
                                                break;
                                            }
                                        }
                                    }
                                    arc.getPath().get(0).setX(startX);
                                    arc.getPath().get(0).setY(startY);

                                    endX = arc.getPath().get(arc.getPath().size()-1).getX();
                                    endY = arc.getPath().get(arc.getPath().size()-1).getY();
                                    startX = arc.getPath().get(arc.getPath().size()-2).getX();
                                    startY = arc.getPath().get(arc.getPath().size()-2).getY();
                                    if (startX - endX == 0) { //whoa - vertical line - simple case, but requires special approach
                                       if (startY > endNode.getY()+endNode.getHeight()) { //below
                                           endY = endNode.getY()+endNode.getHeight();
                                       } else {
                                           endY = endNode.getY();
                                       }
                                    } else {
                                        a = ((double)(startY-endY))/((double)(startX - endX));//remember about vertical line
                                        //startY = startX*a+b
                                        b = (double)startY - (double)startX*a;
                                        for (int x = endX; x <= startX; x++) {
                                            int y = (int) Math.round(a*x+b);
                                            boolean inside = false;
                                            if (x >= endNode.getX() && x <= endNode.getX() + endNode.getWidth()) {
                                                if (y >= endNode.getY() && y <= endNode.getY() + endNode.getHeight()) {
                                                    inside = true;
                                                }
                                            }
                                            if (!inside) {
                                                endX = x;
                                                endY = y;
                                                break;
                                            }
                                        }
                                        for (int x = endX; x > startX; x--) {
                                            int y = (int) Math.round(a*x+b);
                                            boolean inside = false;
                                            if (x >= endNode.getX() && x <= endNode.getX() + endNode.getWidth()) {
                                                if (y >= endNode.getY() && y <= endNode.getY() + endNode.getHeight()) {
                                                    inside = true;
                                                }
                                            }
                                            if (!inside) {
                                                endX = x;
View Full Code Here

//                GraphElement firstTransition = processGraphElements.get("__AWF__start_transition_to_" + activityName);
//                if (firstTransition != null) {
//                    res.add(firstTransition);
//                }
//            }
            StateNode sn = (StateNode) processGraphElements.get(activityName);
            if (sn == null) continue;
            sn = sn.cloneNode();
            sn.setUnfinished(activity.getEndTime() == null);
//            sn.setLabel(activityName + ": " + activity.getDurationInMillis() + "ms");
            res.add(sn);
            //look for transition
        }

        HistoricProcessInstanceQuery historyProcessInstanceQuery = getProcessEngine().getHistoryService()
                .createHistoricProcessInstanceQuery().processInstanceId(pi.getInternalId());
        HistoricProcessInstance historyProcessInstance = historyProcessInstanceQuery.singleResult();
        if (historyProcessInstance != null && historyProcessInstance.getEndActivityId() != null) {
            StateNode sn = (StateNode) processGraphElements.get(historyProcessInstance.getEndActivityId());
            if (sn != null) {
                if (prev != null) {
                    TransitionArc ta = (TransitionArc) processGraphElements.get("__AWF__" + prev.getActivityName() + "_" + sn.getLabel());
                    if (ta == null) { //look for default!
                        ta = (TransitionArc) processGraphElements.get("__AWF__default_transition_" + prev.getActivityName());
                    }
                    if (ta != null) {
                        res.add(ta.cloneNode());

                    }
                }
                StateNode e = sn.cloneNode();
                e.setUnfinished(true);
                res.add(e);
            }
        }
        return res;
    }
View Full Code Here

            for (String nodeType : nodeTypes) {
                NodeList nodes = processElement.getElementsByTagName(nodeType);
                for (int i = 0; i < nodes.getLength(); i++) {
                    Element node = (Element) nodes.item(i);
                    try {
                        StateNode sn = nodeById.get(node.getAttribute("id"));
                        if (sn == null) {
                            continue;
                        }
                        String name = node.getAttribute("name");
                        sn.setLabel(name);
                        res.put(name, sn);
                        res.put(sn.getId(), sn);
                        if ("startEvent".equals(nodeType)) {
                            res.put("__AWF__start_node", sn);
                        }
                        LOGGER.fine("Found node" + name);
                    } catch (Exception e) {
                        LOGGER.log(Level.SEVERE, e.getMessage(), e);
                    }
                }
            }
            /*
<sequenceFlow id="sid-1D101C48-E36A-4A42-8E95-5C83E9A4CE62" name="Continue" sourceRef="sid-7BAAA2C8-B1B8-44C7-8C4F-D3968FBAD1B9" targetRef="sid-9EB37DC6-A17D-4F6B-AD72-64481593034E">
  <conditionExpression id="sid-754c93dd-7b08-4c0b-b858-848069d98e4d" xsi:type="tFormalExpression">${ACTION=='Continue'}</conditionExpression>
</sequenceFlow>
             */
            nodeTypes = new String[]{"sequenceFlow"};
            for (String nodeType : nodeTypes) {
                NodeList nodes = processElement.getElementsByTagName(nodeType);
                for (int i = 0; i < nodes.getLength(); i++) {
                    Element node = (Element) nodes.item(i);
                    try {
                        TransitionArc arc = arcById.get(node.getAttribute("id"));
                        if (arc == null) {
                            continue;
                        }
                        String name = node.getAttribute("name");
                        arc.setName(name);
                        res.put(name, arc);
                        StateNode startNode = nodeById.get(node.getAttribute("sourceRef"));
                        StateNode endNode = nodeById.get(node.getAttribute("targetRef"));
                        if (startNode == null || endNode == null) {
                            continue;
                        }
                                                        //calculate line start node which is a center of the start node
                        int startX = startNode.getX() + startNode.getWidth()/2;
                        int startY = startNode.getY() + startNode.getHeight()/2;
                        //and the same for end node
                        int endX   = endNode.getX() + endNode.getWidth()/2;
                        int endY   = endNode.getY() + endNode.getHeight()/2;

                        arc.getPath().add(0, new TransitionArcPoint(startX, startY));
                        arc.addPoint(endX, endY);

                        double a;//remember about vertical line
                        double b;

                        endX = arc.getPath().get(1).getX();
                        endY = arc.getPath().get(1).getY();
                        if (startX - endX == 0) { //whoa - vertical line - simple case, but requires special approach
                            if (endY > startNode.getY()+startNode.getHeight()) { //below
                                startY = startNode.getY()+startNode.getHeight();
                            } else {
                                startY = startNode.getY();
                            }
                        } else {
                            a = ((double)(startY-endY))/((double)(startX - endX));
                            b = (double)startY - (double)startX*a;
                            for (int x = startX; x <= endX; x++) {
                                int y = (int) Math.round(a*x+b);
                                boolean inside = false;
                                if (x >= startNode.getX() && x <= startNode.getX() + startNode.getWidth()) {
                                    if (y >= startNode.getY() && y <= startNode.getY() + startNode.getHeight()) {
                                        inside = true;
                                    }
                                }
                                if (!inside) {
                                    startX = x;
                                    startY = y;
                                    break;
                                }
                            }
                            for (int x = startX; x > endX; x--) {
                                int y = (int) Math.round(a*x+b);
                                boolean inside = false;
                                if (x >= startNode.getX() && x <= startNode.getX() + startNode.getWidth()) {
                                    if (y >= startNode.getY() && y <= startNode.getY() + startNode.getHeight()) {
                                        inside = true;
                                    }
                                }
                                if (!inside) {
                                    startX = x;
                                    startY = y;
                                    break;
                                }
                            }
                        }
                        arc.getPath().get(0).setX(startX);
                        arc.getPath().get(0).setY(startY);

                        endX = arc.getPath().get(arc.getPath().size()-1).getX();
                        endY = arc.getPath().get(arc.getPath().size()-1).getY();
                        startX = arc.getPath().get(arc.getPath().size()-2).getX();
                        startY = arc.getPath().get(arc.getPath().size()-2).getY();
                        if (startX - endX == 0) { //whoa - vertical line - simple case, but requires special approach
                           if (startY > endNode.getY()+endNode.getHeight()) { //below
                               endY = endNode.getY()+endNode.getHeight();
                           } else {
                               endY = endNode.getY();
                           }
                        } else {
                            a = ((double)(startY-endY))/((double)(startX - endX));//remember about vertical line
                            //startY = startX*a+b
                            b = (double)startY - (double)startX*a;
                            for (int x = endX; x <= startX; x++) {
                                int y = (int) Math.round(a*x+b);
                                boolean inside = false;
                                if (x >= endNode.getX() && x <= endNode.getX() + endNode.getWidth()) {
                                    if (y >= endNode.getY() && y <= endNode.getY() + endNode.getHeight()) {
                                        inside = true;
                                    }
                                }
                                if (!inside) {
                                    endX = x;
                                    endY = y;
                                    break;
                                }
                            }
                            for (int x = endX; x > startX; x--) {
                                int y = (int) Math.round(a*x+b);
                                boolean inside = false;
                                if (x >= endNode.getX() && x <= endNode.getX() + endNode.getWidth()) {
                                    if (y >= endNode.getY() && y <= endNode.getY() + endNode.getHeight()) {
                                        inside = true;
                                    }
                                }
                                if (!inside) {
                                    endX = x;
                                    endY = y;
                                    break;
                                }
                            }
                        }
                        arc.getPath().get(arc.getPath().size()-1).setX(endX);
                        arc.getPath().get(arc.getPath().size()-1).setY(endY);

                        res.put("__AWF__" + startNode.getLabel() + "_" + endNode.getLabel(),
                                arc);
                        res.put("__AWF__default_transition_" + startNode.getLabel(),
                                arc);
                        LOGGER.fine("Found node" + name);
                    } catch (Exception e) {
View Full Code Here

      }

      private void updateNodeList(Map<String, StateNode> nodeList,
          String nodeType, GraphElement originalGraphElement) {

        StateNode stateNode = (StateNode) originalGraphElement;

        if (stateNode.getNodeType() != null
            && (stateNode.getNodeType().equals(nodeType))) {

          nodeList.put(stateNode.getLabel(), stateNode);
        }

      }
View Full Code Here

      private void relateNodesWithTransitionArcs(
          Map<String, StateNode> joinForkList, TransitionArc transitionArc,
          Map<GraphElement, List<TransitionArc>> joinOrForkWithTransitions) {
        if (joinForkList.containsKey(transitionArc.getSource())) {
          StateNode stateNode = joinForkList.get(transitionArc.getSource());
          List<TransitionArc> listOfTransition = null;

          if (joinOrForkWithTransitions.containsKey(stateNode)) {

            listOfTransition = joinOrForkWithTransitions.get(stateNode);
View Full Code Here

          ArrayList<GraphElement> historyGraph) {

        ArrayList<String> newHistoryElement = new ArrayList<String>();
        for (GraphElement historyElement : historyGraph) {
          if (historyElement instanceof StateNode) {
            StateNode historyNode = (StateNode) historyElement;
            String histloryNodeLabel = historyNode.getLabel();
            String[] split = histloryNodeLabel.split(":");

            String taskNameFromHistory = split[0];
            newHistoryElement.add(taskNameFromHistory);
          }
View Full Code Here

                                        String strokeStyle = "stroke:#1B59E0;stroke-width:5;opacity: 1;";

                                        for (GraphElement el : processHistory) {
                                            if (el instanceof StateNode) {
                                                StateNode sn = (StateNode) el;
                                                String fill = sn.isUnfinished() ? "fill:#1B59E0;fill-opacity:0.3" : "fill-opacity:0.0";
                                                svg.append(String.format("<rect x=\"%d\" y=\"%d\" height=\"%d\" width=\"%d\"\n" +
                                                                    " rx=\"5\" ry=\"5\"\n" +
                                                                    " style=\"" + strokeStyle + fill + "\"/>\n",
                                                                    sn.getX(),
                                                                    sn.getY(),
                                                                    sn.getHeight(),
                                                                    sn.getWidth()));
                                            } else if (el instanceof TransitionArc) {
                                                TransitionArc ta = (TransitionArc) el;
                                                TransitionArcPoint prevPoint = null;
                                                for (TransitionArcPoint p : ta.getPath()) {
                                                    if (prevPoint != null) {
View Full Code Here

                /*
                <bpmndi:BPMNShape bpmnElement="sid-0085EC77-5E5A-41F2-AB86-1323CDAA63B9" id="sid-0085EC77-5E5A-41F2-AB86-1323CDAA63B9_gui">
                            <omgdc:Bounds height="30.0" width="30.0" x="21.0" y="89.0"/>
                         </bpmndi:BPMNShape>
                 */
                StateNode sn = new StateNode();
                sn.setId(node.getAttribute("bpmnElement"));
                NodeList boundsList = node.getElementsByTagNameNS(OMG_DC_URI, "Bounds");
                if (boundsList.getLength() == 0) {
                    continue;
                }
                Element boundsEl = (Element) boundsList.item(0);

                int x = new Double(boundsEl.getAttribute("x")).intValue();
                int y = new Double(boundsEl.getAttribute("y")).intValue();
                int w = new Double(boundsEl.getAttribute("width")).intValue();
                int h = new Double(boundsEl.getAttribute("height")).intValue();
                sn.setX(x);
                sn.setY(y);
                sn.setWidth(w);
                sn.setHeight(h);
                nodeById.put(sn.getId(), sn);
                LOGGER.fine("Found node" + sn.getId() + ": " + x + "," + y + "," + w + "," + h);
            } catch (Exception e) {
                LOGGER.log(Level.SEVERE, e.getMessage(), e);
            }
        }
        return nodeById;
View Full Code Here

TOP

Related Classes of org.aperteworkflow.bpm.graph.StateNode

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.