Search in sources :

Example 11 with SubGraph

use of com.centurylink.mdw.designer.display.SubGraph in project mdw-designer by CenturyLinkCloud.

the class DesignerProxy method loadProcessInstance.

public RunTimeDesignerCanvas loadProcessInstance(WorkflowProcess processVersion, ProcessInstancePage processInstancePage) {
    CodeTimer timer = new CodeTimer("loadProcessInstance()");
    ProcessInstanceVO processInstanceInfo = processVersion.getProcessInstance();
    ProcessInstanceLoader instanceLoadThread = new ProcessInstanceLoader(processInstanceInfo, processInstancePage);
    String errorMessage = null;
    try {
        Graph processGraph = dataAccess.getDesignerDataModel().findProcessGraph(processVersion.getId(), null);
        if (processGraph == null)
            processGraph = processInstancePage.loadProcess(processInstanceInfo.getProcessId(), null);
        processVersion.setProcessVO(processGraph.getProcessVO());
        DesignerDataAccess dao = processVersion.getDesignerDataAccess() == null ? processInstancePage.frame.dao : processVersion.getDesignerDataAccess();
        Graph procInstGraph = instanceLoadThread.loadCompletionMap(processGraph.getProcessVO(), processInstanceInfo, dao);
        ProcessInstanceTreeModel model = instanceLoadThread.createOrUpdateModel(null);
        model.getCurrentProcess().setGraph(procInstGraph);
        processInstancePage.setData(model, processInstancePage);
        Map<Long, List<TaskInstanceVO>> taskInstances = new HashMap<>();
        // embedded subprocesses
        List<ProcessInstanceVO> embeddedSubs = new ArrayList<>();
        if (procInstGraph.subgraphs != null) {
            for (SubGraph instSubGraph : procInstGraph.subgraphs) {
                if (instSubGraph.getInstances() != null) {
                    if (instSubGraph.nodes != null) {
                        List<Long> taskActivityIds = new ArrayList<>();
                        for (Node node : instSubGraph.nodes) {
                            if (node.isTaskActivity()) {
                                for (ProcessInstanceVO embeddedProcInst : instSubGraph.getInstances()) {
                                    if (!embeddedProcInst.getActivityInstances(node.getActivityId()).isEmpty())
                                        taskActivityIds.add(node.getActivityId());
                                }
                            }
                        }
                        if (!taskActivityIds.isEmpty()) {
                            for (ProcessInstanceVO embeddedProcInst : instSubGraph.getInstances()) {
                                ProcessVO embeddedProc = instSubGraph.getGraph().getProcessVO();
                                Map<Long, List<TaskInstanceVO>> embeddedTaskInsts = dao.getTaskInstances(embeddedProc, embeddedProcInst, taskActivityIds);
                                for (Map.Entry<Long, List<TaskInstanceVO>> embeddedTaskInst : embeddedTaskInsts.entrySet()) {
                                    if (taskInstances.get(embeddedTaskInst.getKey()) == null)
                                        taskInstances.put(embeddedTaskInst.getKey(), new ArrayList<TaskInstanceVO>());
                                    taskInstances.get(embeddedTaskInst.getKey()).addAll(embeddedTaskInst.getValue());
                                }
                            }
                        }
                    }
                    embeddedSubs.addAll(instSubGraph.getInstances());
                }
            }
        }
        processVersion.setEmbeddedSubProcessInstances(embeddedSubs);
        // manual task instances
        if (processGraph.nodes != null) {
            List<Long> taskActivityIds = new ArrayList<>();
            for (Node node : processGraph.nodes) {
                if (node.isTaskActivity() && !processInstanceInfo.getActivityInstances(node.getActivityId()).isEmpty())
                    taskActivityIds.add(node.getActivityId());
            }
            if (!taskActivityIds.isEmpty()) {
                Map<Long, List<TaskInstanceVO>> taskInsts = dao.getTaskInstances(processVersion.getProcessVO(), processInstanceInfo, taskActivityIds);
                for (Map.Entry<Long, List<TaskInstanceVO>> taskInst : taskInsts.entrySet()) {
                    if (taskInstances.get(taskInst.getKey()) == null)
                        taskInstances.put(taskInst.getKey(), new ArrayList<TaskInstanceVO>());
                    taskInstances.get(taskInst.getKey()).addAll(taskInst.getValue());
                }
            }
        }
        processVersion.setTaskInstances(taskInstances);
    } catch (Exception ex) {
        PluginMessages.log(ex);
        errorMessage = PluginMessages.getUserMessage(ex);
    }
    if (errorMessage == null)
        errorMessage = instanceLoadThread.getErrorMessage();
    if (errorMessage != null) {
        PluginMessages.uiError(errorMessage, "Load Process Instance");
    }
    timer.stopAndLog();
    return processInstancePage.canvas;
}
Also used : HashMap(java.util.HashMap) Node(com.centurylink.mdw.designer.display.Node) ProcessInstanceTreeModel(com.centurylink.mdw.designer.runtime.ProcessInstanceTreeModel) ArrayList(java.util.ArrayList) ProcessInstanceLoader(com.centurylink.mdw.designer.runtime.ProcessInstanceLoader) JSONException(org.json.JSONException) TranslationException(com.centurylink.mdw.common.exception.TranslationException) AuthenticationException(com.centurylink.mdw.auth.AuthenticationException) IOException(java.io.IOException) XmlException(org.apache.xmlbeans.XmlException) ValidationException(com.centurylink.mdw.designer.utils.ValidationException) DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) ZipException(java.util.zip.ZipException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) FileNotFoundException(java.io.FileNotFoundException) RemoteException(java.rmi.RemoteException) Graph(com.centurylink.mdw.designer.display.Graph) SubGraph(com.centurylink.mdw.designer.display.SubGraph) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) ArrayList(java.util.ArrayList) List(java.util.List) ProcessList(com.centurylink.mdw.model.value.process.ProcessList) DesignerDataAccess(com.centurylink.mdw.designer.DesignerDataAccess) CodeTimer(com.centurylink.mdw.plugin.CodeTimer) SubGraph(com.centurylink.mdw.designer.display.SubGraph) Map(java.util.Map) HashMap(java.util.HashMap) ProcessInstanceVO(com.centurylink.mdw.model.value.process.ProcessInstanceVO)

Example 12 with SubGraph

use of com.centurylink.mdw.designer.display.SubGraph in project mdw-designer by CenturyLinkCloud.

the class ProcessCanvasWrapper method handleSelection.

private void handleSelection(MouseEvent mouseEvent) {
    Graph lProcess = null;
    if (isInstance())
        lProcess = getProcessInstancePage().getProcess();
    else
        lProcess = getFlowchartPage().getProcess();
    int mouseX = mouseEvent.getX();
    int mouseY = mouseEvent.getY();
    if (lProcess.zoom != 100) {
        mouseX = mouseX * 100 / lProcess.zoom;
        mouseY = mouseY * 100 / lProcess.zoom;
    }
    Object obj = null;
    if (mouseEvent.getID() == MouseEvent.MOUSE_PRESSED) {
        if (isInstance())
            obj = getProcessInstancePage().canvas.objectAt(lProcess, mouseX, mouseY, getProcessInstancePage().canvas.getGraphics());
        else
            obj = getFlowchartPage().canvas.objectAt(lProcess, mouseX, mouseY, getFlowchartPage().canvas.getGraphics());
    } else {
        obj = lProcess.objectAt(mouseX, mouseY, isInstance() ? getProcessInstancePage().canvas.getGraphics() : getFlowchartPage().canvas.getGraphics());
    }
    if (obj != null) {
        DesignerProxy designerProxy = getProcess().getProject().getDesignerProxy();
        // create the appropriate DesignerCanvasSelection
        if (obj instanceof Node) {
            ActivityImpl actImpl = getProcess().getProject().getActivityImpl(((Node) obj).nodet.getImplementorClassName());
            Activity activity = new Activity((Node) obj, getProcess(), actImpl);
            if (isInstance()) {
                activity.setProcessInstance(getProcess().getProcessInstance());
                List<ActivityInstanceVO> activityInstances = getProcess().getProcessInstance().getActivityInstances(activity.getId());
                if (activityInstances.isEmpty() && getProcess().getEmbeddedSubProcessInstances() != null) {
                    // try embedded subprocess instances
                    for (ProcessInstanceVO embeddedSubProcessInstance : getProcess().getEmbeddedSubProcessInstances()) activityInstances.addAll(embeddedSubProcessInstance.getActivityInstances(activity.getId()));
                }
                activity.setInstances(activityInstances);
                if (activity.isManualTask()) {
                    activity.setTaskInstances(getProcess().getMainTaskInstances(activity.getId()));
                    activity.setSubTaskInstances(getProcess().getSubTaskInstances(activity.getId()));
                }
                if (activity.isSubProcessInvoke()) {
                    // TODO: load subprocess instances when process instance
                    // id loaded (like manual task instances above)
                    List<ProcessInstanceVO> subProcessInstances = designerProxy.getSubProcessInstances(getProcess(), activity);
                    if (subProcessInstances.isEmpty() && getProcess().getEmbeddedSubProcessInstances() != null) {
                        for (ProcessInstanceVO embeddedSubProcessInstance : getProcess().getEmbeddedSubProcessInstances()) subProcessInstances.addAll(designerProxy.getSubProcessInstances(embeddedSubProcessInstance, activity));
                    }
                    activity.setSubProcessInstances(subProcessInstances);
                }
            } else {
                if (activity.getLogicalId() == null)
                    activity.setLogicalId(lProcess.generateLogicalId("A"));
                if (Node.ID_SEQUENCE.equals(getNodeIdType()) && activity.getSequenceId() == 0)
                    lProcess.assignSequenceIds();
            }
            designerCanvasSelection = activity;
        } else if (obj instanceof Link) {
            Transition transition = new Transition((Link) obj, getProcess());
            if (isInstance())
                transition.setInstances(getProcess().getProcessInstance().getTransitionInstances(transition.getId()));
            designerCanvasSelection = transition;
        } else if (obj instanceof SubGraph) {
            EmbeddedSubProcess embeddedSubProcess = new EmbeddedSubProcess((SubGraph) obj, getProcess());
            if (isInstance()) {
                embeddedSubProcess.setSubProcessInstances(((SubGraph) obj).getInstances());
            }
            designerCanvasSelection = embeddedSubProcess;
        } else if (obj instanceof TextNote) {
            TextNote textNote = (TextNote) obj;
            Note note = new Note(textNote, getProcess());
            designerCanvasSelection = note;
        } else {
            designerCanvasSelection = getProcess();
        }
    } else {
        designerCanvasSelection = getProcess();
    }
    designerCanvasSelection.addDirtyStateListener(this);
}
Also used : EmbeddedSubProcess(com.centurylink.mdw.plugin.designer.model.EmbeddedSubProcess) ActivityInstanceVO(com.centurylink.mdw.model.value.work.ActivityInstanceVO) Node(com.centurylink.mdw.designer.display.Node) Activity(com.centurylink.mdw.plugin.designer.model.Activity) Graph(com.centurylink.mdw.designer.display.Graph) SubGraph(com.centurylink.mdw.designer.display.SubGraph) ActivityImpl(com.centurylink.mdw.plugin.designer.model.ActivityImpl) Note(com.centurylink.mdw.plugin.designer.model.Note) TextNote(com.centurylink.mdw.designer.display.TextNote) Transition(com.centurylink.mdw.plugin.designer.model.Transition) JSONObject(org.json.JSONObject) TextNote(com.centurylink.mdw.designer.display.TextNote) SubGraph(com.centurylink.mdw.designer.display.SubGraph) ProcessInstanceVO(com.centurylink.mdw.model.value.process.ProcessInstanceVO) Link(com.centurylink.mdw.designer.display.Link)

Example 13 with SubGraph

use of com.centurylink.mdw.designer.display.SubGraph in project mdw-designer by CenturyLinkCloud.

the class DesignerCanvas method resizeSubGraph.

protected void resizeSubGraph(int x, int y) {
    SubGraph subgraph = (SubGraph) selected_obj;
    Rectangle rect = new Rectangle(subgraph.x, subgraph.y, subgraph.w, subgraph.h);
    resizeRectangle(rect, x, y, 80);
    subgraph.resize(rect);
    if (!page.getProcess().isReadonly())
        page.getProcess().setDirtyLevel(Graph.GEOCHANGE);
}
Also used : Rectangle(java.awt.Rectangle) SubGraph(com.centurylink.mdw.designer.display.SubGraph)

Example 14 with SubGraph

use of com.centurylink.mdw.designer.display.SubGraph in project mdw-designer by CenturyLinkCloud.

the class ExportHelper method printProcessDocx.

private DocxBuilder printProcessDocx(Graph process, DesignerCanvas canvas) throws Exception {
    DocxBuilder builder = new DocxBuilder();
    // title
    String title = "Workflow: \"" + process.getName() + "\"";
    builder.addParagraph("Heading1", title);
    // process image
    int zoomSave = process.zoom;
    process.zoom = 100;
    byte[] imgBytes = printImage(-1f, canvas, process.getGraphSize(), "png");
    process.zoom = zoomSave;
    builder.addImage(imgBytes);
    printProcessBodyDocx(builder, process);
    // embedded subprocesses
    for (SubGraph subprocess : process.getSubgraphs(nodeIdType)) {
        String id = subprocess.getDisplayId(nodeIdType);
        String spTitle = "Embedded Subprocess " + id + ": \"" + subprocess.getName() + "\"";
        builder.addParagraph("Heading1", spTitle);
        printProcessBodyDocx(builder, subprocess);
    }
    // process variables
    if (options.contains(VARIABLES)) {
        List<VariableVO> variables = process.getProcessVO().getVariables();
        if (variables != null && !variables.isEmpty()) {
            builder.addParagraph("Heading2", "Process Variables");
            String[] headers = new String[] { "Name", "Type", "Mode", "Description" };
            String[][] values = new String[4][variables.size()];
            for (int i = 0; i < variables.size(); i++) {
                VariableVO var = variables.get(i);
                values[0][i] = var.getName();
                values[1][i] = var.getVariableType();
                values[2][i] = VariableVO.VariableCategories[var.getVariableCategory()];
                values[3][i] = var.getVariableReferredAs();
            }
            builder.addTable(headers, values, 11, 120);
        }
    }
    return builder;
}
Also used : DocxBuilder(com.centurylink.mdw.designer.utils.DocxBuilder) VariableVO(com.centurylink.mdw.model.value.variable.VariableVO) SubGraph(com.centurylink.mdw.designer.display.SubGraph)

Example 15 with SubGraph

use of com.centurylink.mdw.designer.display.SubGraph in project mdw-designer by CenturyLinkCloud.

the class ExportHelper method printProcessHtml.

private void printProcessHtml(StringBuilder sb, DesignerCanvas canvas, int chapter, Graph process, String filename) throws Exception {
    sb.append("<h1>");
    if (chapter > 0)
        sb.append(Integer.toString(chapter)).append(". ");
    sb.append("Workflow: \"").append(process.getName()).append("\"</h1>\n");
    // print image
    printGraphHtml(sb, canvas, process, filename, chapter);
    // print documentation text
    sb.append(BR);
    printProcessBodyHtml(sb, process);
    for (Node node : process.getNodes(nodeIdType)) {
        printActivityHtml(sb, node);
    }
    for (SubGraph subgraph : process.getSubgraphs(nodeIdType)) {
        printProcessBodyHtml(sb, subgraph);
        for (Node node : subgraph.getNodes(nodeIdType)) {
            printActivityHtml(sb, node);
        }
    }
    if (options.contains(VARIABLES)) {
        List<VariableVO> variables = process.getProcessVO().getVariables();
        if (variables != null && !variables.isEmpty()) {
            sb.append("<h2>Process Variables</h2>\n");
            String[] headers = new String[] { "Name", "Type", "Mode", "Description" };
            String[][] values = new String[4][variables.size()];
            for (int i = 0; i < variables.size(); i++) {
                VariableVO var = variables.get(i);
                values[0][i] = var.getName();
                values[1][i] = var.getVariableType();
                values[2][i] = VariableVO.VariableCategories[var.getVariableCategory()];
                values[3][i] = var.getVariableReferredAs();
            }
            printTableHtml(sb, headers, values);
        }
    }
}
Also used : Node(com.centurylink.mdw.designer.display.Node) VariableVO(com.centurylink.mdw.model.value.variable.VariableVO) SubGraph(com.centurylink.mdw.designer.display.SubGraph)

Aggregations

SubGraph (com.centurylink.mdw.designer.display.SubGraph)25 Node (com.centurylink.mdw.designer.display.Node)17 Graph (com.centurylink.mdw.designer.display.Graph)14 Link (com.centurylink.mdw.designer.display.Link)13 GraphFragment (com.centurylink.mdw.designer.display.GraphFragment)8 TextNote (com.centurylink.mdw.designer.display.TextNote)8 ProcessInstanceVO (com.centurylink.mdw.model.value.process.ProcessInstanceVO)4 Rectangle (java.awt.Rectangle)4 HashMap (java.util.HashMap)3 VariableVO (com.centurylink.mdw.model.value.variable.VariableVO)2 Paragraph (com.lowagie.text.Paragraph)2 Graphics2D (java.awt.Graphics2D)2 AuthenticationException (com.centurylink.mdw.auth.AuthenticationException)1 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)1 TranslationException (com.centurylink.mdw.common.exception.TranslationException)1 DataAccessOfflineException (com.centurylink.mdw.dataaccess.DataAccessOfflineException)1 DesignerDataAccess (com.centurylink.mdw.designer.DesignerDataAccess)1 GraphCommon (com.centurylink.mdw.designer.display.GraphCommon)1 Label (com.centurylink.mdw.designer.display.Label)1 ProcessInstanceLoader (com.centurylink.mdw.designer.runtime.ProcessInstanceLoader)1