Search in sources :

Example 6 with ActivityInstanceVO

use of com.centurylink.mdw.model.value.work.ActivityInstanceVO in project mdw-designer by CenturyLinkCloud.

the class WorkflowImageHelper method generateImage.

/**
 * Generate a process instance image.
 */
private BufferedImage generateImage(DesignerDataAccess dao) throws Exception {
    NodeMetaInfo metainfo = new NodeMetaInfo();
    metainfo.init(dao.getActivityImplementors(), DataAccess.currentSchemaVersion);
    new ProcessWorker().convert_to_designer(process);
    IconFactory iconFactory = new IconFactory();
    iconFactory.setDesignerDataAccess(dao);
    Graph graph = null;
    Node selectedNode = null;
    if (processInstance != null) {
        processInstance.setProcessName(process.getProcessName());
        graph = new Graph(process, processInstance, metainfo, iconFactory);
        graph.setStatus(new StringBuffer());
        if (embeddedInstances != null) {
            for (ProcessInstanceVO embeddedInstance : embeddedInstances) {
                if (embeddedInstance.getStatusCode() == null && embeddedInstance.getStatus() != null)
                    embeddedInstance.setStatusCode(WorkStatuses.getCode(embeddedInstance.getStatus()));
                Long embeddedProcId = new Long(embeddedInstance.getComment());
                SubGraph subgraph = graph.getSubGraph(embeddedProcId);
                if (subgraph != null) {
                    List<ProcessInstanceVO> insts = subgraph.getInstances();
                    if (insts == null) {
                        insts = new ArrayList<ProcessInstanceVO>();
                        subgraph.setInstances(insts);
                    }
                    insts.add(embeddedInstance);
                }
            }
            for (SubGraph subgraph : graph.subgraphs) subgraph.setStatus(new StringBuffer());
        }
        if (selectedActivityInstanceId != null) {
            ActivityInstanceVO selectedInstance = processInstance.getActivity(selectedActivityInstanceId);
            if (selectedInstance == null) {
                for (SubGraph subgraph : graph.subgraphs) {
                    if (subgraph.getInstances() != null) {
                        for (ProcessInstanceVO subinst : subgraph.getInstances()) {
                            selectedInstance = subinst.getActivity(selectedActivityInstanceId);
                            if (selectedInstance != null)
                                break;
                        }
                    }
                    if (selectedInstance != null)
                        break;
                }
            }
            if (selectedInstance != null)
                selectedNode = graph.getNode("A" + selectedInstance.getDefinitionId());
        }
    } else {
        graph = new Graph(process, metainfo, iconFactory);
        if (selectedActivity != null)
            selectedNode = graph.getNode(selectedActivity);
    }
    Dimension graphsize = graph.getGraphSize();
    WorkflowImage canvas = new WorkflowImage(graph, dao);
    if (selectedNode != null)
        canvas.setSelectedObject(selectedNode);
    int h_margin = 72, v_margin = 72;
    BufferedImage image = new BufferedImage(graphsize.width + h_margin, graphsize.height + v_margin, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = image.createGraphics();
    canvas.paintComponent(g2);
    g2.dispose();
    return image;
}
Also used : NodeMetaInfo(com.centurylink.mdw.designer.utils.NodeMetaInfo) ActivityInstanceVO(com.centurylink.mdw.model.value.work.ActivityInstanceVO) Dimension(java.awt.Dimension) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) ProcessWorker(com.centurylink.mdw.designer.utils.ProcessWorker) ProcessInstanceVO(com.centurylink.mdw.model.value.process.ProcessInstanceVO) IconFactory(com.centurylink.mdw.designer.icons.IconFactory)

Example 7 with ActivityInstanceVO

use of com.centurylink.mdw.model.value.work.ActivityInstanceVO in project mdw-designer by CenturyLinkCloud.

the class ProcessInstanceUpdater method updateActivityInstance.

private void updateActivityInstance(ProcessInstancePage procInstPage, Long procId, Long procInstId, String timestr, String id, String msg) {
    ProcessInstanceVO procInst = procInstPage.getProcessInstance();
    if (!isShowingThisInstance(procInst.getId()))
        showInstance(procInstPage);
    int k = id.indexOf('.');
    String actId = id.substring(0, k);
    String actInstId = id.substring(k + 1);
    Node node;
    if (!procInst.getId().equals(procInstId)) {
        // embedded process
        node = this.findNodeInSubgraph(procInstPage.getProcess(), new Long(actId));
        procInst = this.findEmbeddedProcessInstance(procInstPage.getProcess(), procInstId);
    } else {
        node = procInstPage.getProcess().findNode(new Long(actId));
    }
    if (node != null) {
        ActivityInstanceVO actInst = null;
        for (ActivityInstanceVO ai : procInst.getActivities()) {
            if (ai.getId().toString().equals(actInstId)) {
                actInst = ai;
                break;
            }
        }
        if (actInst == null) {
            actInst = new ActivityInstanceVO();
            procInst.getActivities().add(actInst);
            actInst.setId(new Long(actInstId));
            actInst.setDefinitionId(new Long(actId));
            actInst.setOwnerId(procInst.getId());
            actInst.setStartDate(timestr);
            actInst.setStatusCode(WorkStatus.STATUS_IN_PROGRESS);
            node.addInstance(actInst, false);
        }
        if (msg.startsWith(WorkStatus.LOGMSG_COMPLETE)) {
            actInst.setEndDate(timestr);
            actInst.setStatusCode(WorkStatus.STATUS_COMPLETED);
            node.setInstanceStatus(actInst);
        } else if (msg.startsWith(WorkStatus.LOGMSG_START)) {
        // do nothing - already loaded by code above or by full load
        } else if (msg.startsWith(WorkStatus.LOGMSG_FAILED)) {
            actInst.setEndDate(timestr);
            actInst.setStatusCode(WorkStatus.STATUS_FAILED);
            node.setInstanceStatus(actInst);
        } else if (msg.startsWith(WorkStatus.LOGMSG_SUSPEND)) {
            actInst.setStatusCode(WorkStatus.STATUS_WAITING);
            node.setInstanceStatus(actInst);
        } else if (msg.startsWith(WorkStatus.LOGMSG_HOLD)) {
            actInst.setStatusCode(WorkStatus.STATUS_HOLD);
            node.setInstanceStatus(actInst);
        } else {
        // System.out.println("How to handle activity message '" + msg +"'?");
        }
        Rectangle aRect = new java.awt.Rectangle(node.x - 10, node.y - 10, node.w + 20, node.h + 30);
        procInstPage.canvas.scrollRectToVisible(aRect);
    } else {
        System.out.println("Cannot find node with ID " + actId);
    }
    procInstPage.repaint();
}
Also used : ActivityInstanceVO(com.centurylink.mdw.model.value.work.ActivityInstanceVO) Node(com.centurylink.mdw.designer.display.Node) Rectangle(java.awt.Rectangle) ProcessInstanceVO(com.centurylink.mdw.model.value.process.ProcessInstanceVO)

Example 8 with ActivityInstanceVO

use of com.centurylink.mdw.model.value.work.ActivityInstanceVO in project mdw-designer by CenturyLinkCloud.

the class DesignerDataAccess method getTaskInstances.

private List<TaskInstanceVO> getTaskInstances(ProcessVO process, ProcessInstanceVO processInstance, Long activityId, List<TaskInstanceVO> allTaskInstances) throws DataAccessException {
    List<TaskInstanceVO> taskInstances = new ArrayList<>();
    for (TaskInstanceVO taskInstance : allTaskInstances) {
        String secondaryOwner = taskInstance.getSecondaryOwnerType();
        if (OwnerType.DOCUMENT.equals(secondaryOwner) || "EXTERNAL_EVENT_INSTANCE".equals(secondaryOwner)) {
            String formDataString = null;
            if (OwnerType.DOCUMENT.equals(secondaryOwner))
                formDataString = rtinfo.getDocument(taskInstance.getSecondaryOwnerId()).getContent();
            else if ("EXTERNAL_EVENT_INSTANCE".equals(secondaryOwner))
                formDataString = rtinfo.getExternalEventDetails(taskInstance.getSecondaryOwnerId());
            FormDataDocument formDataDoc = new FormDataDocument();
            try {
                formDataDoc.load(formDataString);
                for (ActivityInstanceVO activityInstance : processInstance.getActivityInstances(activityId)) {
                    if (activityInstance.getId().equals(formDataDoc.getActivityInstanceId()))
                        taskInstances.add(taskInstance);
                }
            } catch (MbengException ex) {
                throw new DataAccessException(-1, ex.getMessage(), ex);
            }
        } else {
            // task instance secondary owner is work transition instance
            Long workTransInstId = taskInstance.getSecondaryOwnerId();
            for (WorkTransitionInstanceVO transitionInstance : processInstance.getTransitions()) {
                if (transitionInstance.getTransitionInstanceID().equals(workTransInstId)) {
                    Long transitionId = transitionInstance.getTransitionID();
                    WorkTransitionVO workTrans = process.getWorkTransition(transitionId);
                    if (workTrans == null && process.getSubProcesses() != null) {
                        for (ProcessVO subproc : process.getSubProcesses()) {
                            workTrans = subproc.getWorkTransition(transitionId);
                            if (workTrans != null)
                                break;
                        }
                    }
                    if (workTrans != null && workTrans.getToWorkId().equals(activityId))
                        taskInstances.add(taskInstance);
                }
            }
        }
    }
    return taskInstances;
}
Also used : MbengException(com.qwest.mbeng.MbengException) WorkTransitionInstanceVO(com.centurylink.mdw.model.value.work.WorkTransitionInstanceVO) WorkTransitionVO(com.centurylink.mdw.model.value.work.WorkTransitionVO) ActivityInstanceVO(com.centurylink.mdw.model.value.work.ActivityInstanceVO) TaskInstanceVO(com.centurylink.mdw.model.value.task.TaskInstanceVO) ArrayList(java.util.ArrayList) ProcessVO(com.centurylink.mdw.model.value.process.ProcessVO) FormDataDocument(com.centurylink.mdw.model.FormDataDocument) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Example 9 with ActivityInstanceVO

use of com.centurylink.mdw.model.value.work.ActivityInstanceVO in project mdw-designer by CenturyLinkCloud.

the class RunTimeDesignerCanvas method getToolTipText.

public String getToolTipText(MouseEvent arg0) {
    int x = arg0.getX();
    int y = arg0.getY();
    Graph process = page.getProcess();
    if (process.zoom != 100) {
        x = x * 100 / process.zoom;
        y = y * 100 / process.zoom;
    }
    Object obj = objectAt(process, x, y, getGraphics());
    if (obj != null && obj instanceof Node) {
        Node node = (Node) obj;
        List<ActivityInstanceVO> insts = node.getInstances();
        if (insts != null) {
            StringBuffer sb = new StringBuffer();
            sb.append("<html>");
            int k = 0;
            for (ActivityInstanceVO one : node.getInstances()) {
                sb.append(one.getId()).append(": ").append(one.getStartDate().toString()).append("<p>");
                k++;
                if (k >= 5)
                    break;
            }
            sb.append("</html>");
            return sb.toString();
        } else
            return null;
    } else if (obj != null && obj instanceof Link) {
        Link link = (Link) obj;
        List<WorkTransitionInstanceVO> insts = link.getInstances();
        if (insts != null) {
            StringBuffer sb = new StringBuffer();
            int k = 0;
            sb.append("<html>");
            for (WorkTransitionInstanceVO one : link.getInstances()) {
                sb.append(one.getTransitionInstanceID()).append(": ").append(one.getStartDate().toString()).append("<p>");
                k++;
                if (k >= 5)
                    break;
            }
            sb.append("</html>");
            return sb.toString();
        } else
            return null;
    } else
        return null;
}
Also used : WorkTransitionInstanceVO(com.centurylink.mdw.model.value.work.WorkTransitionInstanceVO) Graph(com.centurylink.mdw.designer.display.Graph) SubGraph(com.centurylink.mdw.designer.display.SubGraph) ActivityInstanceVO(com.centurylink.mdw.model.value.work.ActivityInstanceVO) Node(com.centurylink.mdw.designer.display.Node) ArrayList(java.util.ArrayList) List(java.util.List) Link(com.centurylink.mdw.designer.display.Link)

Example 10 with ActivityInstanceVO

use of com.centurylink.mdw.model.value.work.ActivityInstanceVO in project mdw-designer by CenturyLinkCloud.

the class TestCaseRun method translateToYaml.

private String translateToYaml(Map<String, List<ProcessInstanceVO>> processInstances, Map<String, String> activityNames, boolean orderById, String newLineChars) throws IOException, DataAccessException {
    YamlBuilder yaml = new YamlBuilder(newLineChars);
    for (String procName : processInstances.keySet()) {
        List<ProcessInstanceVO> procInsts = processInstances.get(procName);
        for (int i = 0; i < procInsts.size(); i++) {
            ProcessInstanceVO procInst = procInsts.get(i);
            yaml.append("process: # ").append(procInst.getId()).newLine();
            yaml.append("  name: ").append(procName).newLine();
            yaml.append("  instance: ").append((i + 1)).newLine();
            LinkedList<ActivityInstanceVO> orderedList = new LinkedList<>();
            for (ActivityInstanceVO act : procInst.getActivities()) {
                if (dao.getDatabaseSchemaVersion() < 6000)
                    orderedList.add(0, act);
                else
                    orderedList.add(act);
            }
            if (orderById) {
                Collections.sort(orderedList, new Comparator<ActivityInstanceVO>() {

                    public int compare(ActivityInstanceVO ai1, ActivityInstanceVO ai2) {
                        return (int) (ai1.getDefinitionId() - ai2.getDefinitionId());
                    }
                });
            }
            for (ActivityInstanceVO act : orderedList) {
                yaml.append("  activity: # ").append(act.getDefinitionId()).append(" \"").append(act.getStartDate()).append("\"").newLine();
                String actNameKey = procInst.getProcessId() + "-" + act.getDefinitionId();
                yaml.append("    name: ").appendMulti("      ", activityNames.get(actNameKey)).newLine();
                yaml.append("    status: ").append(WorkStatuses.getWorkStatuses().get(act.getStatusCode())).newLine();
                if (act.getStatusMessage() != null) {
                    String[] msgLines = act.getStatusMessage().split("\\r\\n|\\n|\\r");
                    String result = msgLines[0];
                    if (msgLines.length > 1)
                        result += "...";
                    yaml.append("    result: ").append(result).newLine();
                }
            }
            for (VariableInstanceInfo var : procInst.getVariables()) {
                yaml.append("  variable: # ").append(var.getInstanceId()).newLine();
                yaml.append("    name: ").append(var.getName()).newLine();
                yaml.append("    value: ");
                try {
                    String val = var.getStringValue();
                    if (VariableHelper.isDocumentVariable(var.getType(), val)) {
                        DocumentReference docref = new DocumentReference(val);
                        val = dao.getDocumentContent(docref, var.getType());
                        // pre-populate document values
                        procInst.getVariable().put(var.getName(), val);
                    }
                    yaml.appendMulti("      ", val).newLine();
                } catch (Throwable t) {
                    log.println("Failed to translate variable instance: " + var.getInstanceId() + " to string with the following exception");
                    t.printStackTrace(log);
                    yaml.append(" \"").append(var.getStringValue()).append("\"").newLine();
                }
            }
        }
    }
    return yaml.toString();
}
Also used : YamlBuilder(com.centurylink.mdw.designer.utils.YamlBuilder) ActivityInstanceVO(com.centurylink.mdw.model.value.work.ActivityInstanceVO) LinkedList(java.util.LinkedList) VariableInstanceInfo(com.centurylink.mdw.model.value.variable.VariableInstanceInfo) ProcessInstanceVO(com.centurylink.mdw.model.value.process.ProcessInstanceVO) DocumentReference(com.centurylink.mdw.model.value.variable.DocumentReference)

Aggregations

ActivityInstanceVO (com.centurylink.mdw.model.value.work.ActivityInstanceVO)11 ProcessInstanceVO (com.centurylink.mdw.model.value.process.ProcessInstanceVO)6 Node (com.centurylink.mdw.designer.display.Node)3 DocumentReference (com.centurylink.mdw.model.value.variable.DocumentReference)3 WorkTransitionInstanceVO (com.centurylink.mdw.model.value.work.WorkTransitionInstanceVO)3 Graph (com.centurylink.mdw.designer.display.Graph)2 Link (com.centurylink.mdw.designer.display.Link)2 SubGraph (com.centurylink.mdw.designer.display.SubGraph)2 TaskInstanceVO (com.centurylink.mdw.model.value.task.TaskInstanceVO)2 VariableInstanceInfo (com.centurylink.mdw.model.value.variable.VariableInstanceInfo)2 ActivityInstanceDialog (com.centurylink.mdw.plugin.designer.dialogs.ActivityInstanceDialog)2 Activity (com.centurylink.mdw.plugin.designer.model.Activity)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Menu (org.eclipse.swt.widgets.Menu)2 MenuItem (org.eclipse.swt.widgets.MenuItem)2 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)1