Search in sources :

Example 11 with Node

use of com.centurylink.mdw.designer.display.Node 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 Node

use of com.centurylink.mdw.designer.display.Node 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 Node

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

the class ArtifactResourceListener method resourceChanged.

public void resourceChanged(IResourceChangeEvent event) {
    if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
        IResourceDelta rootDelta = event.getDelta();
        IResourceDelta artifactDelta = rootDelta.findMember(tempFile.getFullPath());
        if (artifactDelta != null && artifactDelta.getKind() == IResourceDelta.CHANGED && (artifactDelta.getFlags() & IResourceDelta.CONTENT) != 0) {
            // the file has been changed
            final Display display = Display.getCurrent();
            if (display != null) {
                display.syncExec(new Runnable() {

                    public void run() {
                        byte[] newValue = PluginUtil.readFile(tempFile);
                        String attrVal = valueProvider.isBinary() ? encodeBase64(newValue) : new String(newValue);
                        if (getElement() instanceof Activity || getElement() instanceof WorkflowProcess) {
                            WorkflowProcess processVersion = null;
                            if (getElement() instanceof Activity) {
                                Activity activity = (Activity) getElement();
                                activity.setAttribute(valueProvider.getAttributeName(), attrVal);
                                processVersion = activity.getProcess();
                            } else {
                                processVersion = (WorkflowProcess) getElement();
                                processVersion.setAttribute(valueProvider.getAttributeName(), attrVal);
                            }
                            processVersion.fireDirtyStateChanged(true);
                            ProcessEditor processEditor = findProcessEditor(processVersion);
                            if (processEditor == null) {
                                try {
                                    processEditor = openProcessEditor(processVersion);
                                    IEditorPart tempFileEditor = findTempFileEditor(tempFile);
                                    if (tempFileEditor != null)
                                        processEditor.addActiveScriptEditor(tempFileEditor);
                                } catch (PartInitException ex) {
                                    PluginMessages.uiError(display.getActiveShell(), ex, "Open Process", processVersion.getProject());
                                    return;
                                }
                            }
                            processVersion = processEditor.getProcess();
                            if (processVersion.isReadOnly()) {
                                WorkflowProject workflowProject = getElement().getProject();
                                PluginMessages.uiMessage("Process for '" + getElement().getName() + "' in workflow project '" + workflowProject.getName() + "' is Read Only.", "Not Updated", workflowProject, PluginMessages.INFO_MESSAGE);
                                return;
                            }
                            if (getElement() instanceof Activity) {
                                Activity activity = (Activity) getElement();
                                // previously-opened process version
                                for (Node node : processEditor.getProcessCanvasWrapper().getFlowchartPage().getProcess().nodes) {
                                    if (activity.getLogicalId() != null && activity.getLogicalId().equals(node.getAttribute("LOGICAL_ID"))) {
                                        node.setAttribute(valueProvider.getAttributeName(), attrVal);
                                        ActivityImpl actImpl = processVersion.getProject().getActivityImpl(node.nodet.getImplementorClassName());
                                        element = new Activity(node, processVersion, actImpl);
                                    }
                                }
                                activity.fireDirtyStateChanged(true);
                            }
                            processEditor.dirtyStateChanged(true);
                            valueProvider.afterTempFileSaved();
                            // process editor is open
                            String message = valueProvider.getArtifactTypeDescription() + " temporary file has been saved locally; however, you must still save the process for the changes to be persisted.";
                            String toggleMessage = "Don't show me this message again.";
                            IPreferenceStore prefsStore = MdwPlugin.getDefault().getPreferenceStore();
                            String prefsKey = "Mdw" + valueProvider.getArtifactTypeDescription() + "SuppressSaveNag";
                            if (!prefsStore.getBoolean(prefsKey)) {
                                MessageDialogWithToggle dialog = MessageDialogWithToggle.openInformation(display.getActiveShell(), "Artifact Save", message, toggleMessage, false, null, null);
                                prefsStore.setValue(prefsKey, dialog.getToggleState());
                            }
                        }
                    }
                });
            }
        }
    }
}
Also used : Node(com.centurylink.mdw.designer.display.Node) Activity(com.centurylink.mdw.plugin.designer.model.Activity) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) IEditorPart(org.eclipse.ui.IEditorPart) ActivityImpl(com.centurylink.mdw.plugin.designer.model.ActivityImpl) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) PartInitException(org.eclipse.ui.PartInitException) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) ProcessEditor(com.centurylink.mdw.plugin.designer.editors.ProcessEditor) IResourceDelta(org.eclipse.core.resources.IResourceDelta) Display(org.eclipse.swt.widgets.Display)

Example 14 with Node

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

the class ExportHelper method printProcessBodyDocx.

private void printProcessBodyDocx(DocxBuilder builder, GraphCommon process) throws Exception {
    String summary = process.getProcessVO().getProcessDescription();
    if (summary != null && summary.length() > 0) {
        builder.addBoldParagraph(summary);
    }
    if (options.contains(DOCUMENTATION)) {
        String detail = process.getAttribute(WorkAttributeConstant.DOCUMENTATION);
        if (detail != null && detail.length() > 0) {
            if (detail.startsWith(HTMLTAG)) {
                builder.addHtml(detail);
            } else {
                byte[] docBytes = decodeBase64(detail);
                builder.addDoc(docBytes);
            }
        }
    }
    builder.addBreak();
    // activities
    for (Node node : process.getNodes(nodeIdType)) printActivityDocx(builder, node);
}
Also used : Node(com.centurylink.mdw.designer.display.Node)

Example 15 with Node

use of com.centurylink.mdw.designer.display.Node 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

Node (com.centurylink.mdw.designer.display.Node)27 SubGraph (com.centurylink.mdw.designer.display.SubGraph)18 Link (com.centurylink.mdw.designer.display.Link)14 GraphFragment (com.centurylink.mdw.designer.display.GraphFragment)10 Graph (com.centurylink.mdw.designer.display.Graph)9 TextNote (com.centurylink.mdw.designer.display.TextNote)8 Rectangle (java.awt.Rectangle)5 ProcessInstanceVO (com.centurylink.mdw.model.value.process.ProcessInstanceVO)3 ActivityInstanceVO (com.centurylink.mdw.model.value.work.ActivityInstanceVO)3 Activity (com.centurylink.mdw.plugin.designer.model.Activity)2 ActivityImpl (com.centurylink.mdw.plugin.designer.model.ActivityImpl)2 Graphics2D (java.awt.Graphics2D)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)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