Search in sources :

Example 6 with DocumentReference

use of com.centurylink.mdw.model.value.variable.DocumentReference in project mdw-designer by CenturyLinkCloud.

the class ProcessInstanceListView method createContextMenu.

private Menu createContextMenu(Shell shell) {
    Menu menu = new Menu(shell, SWT.POP_UP);
    final StructuredSelection selection = (StructuredSelection) getTableViewer().getSelection();
    if (selection.size() == 1 && selection.getFirstElement() instanceof ProcessInstanceVO) {
        final ProcessInstanceVO processInstanceInfo = (ProcessInstanceVO) selection.getFirstElement();
        // open instance
        MenuItem openItem = new MenuItem(menu, SWT.PUSH);
        openItem.setText("Open");
        ImageDescriptor openImageDesc = MdwPlugin.getImageDescriptor("icons/process.gif");
        openItem.setImage(openImageDesc.createImage());
        openItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                handleOpen(processInstanceInfo);
            }
        });
        // owning document
        if (OwnerType.DOCUMENT.equals(processInstanceInfo.getOwner()) || OwnerType.TESTER.equals(processInstanceInfo.getOwner())) {
            MenuItem docItem = new MenuItem(menu, SWT.PUSH);
            docItem.setText("View Owning Document");
            ImageDescriptor docImageDesc = MdwPlugin.getImageDescriptor("icons/doc.gif");
            docItem.setImage(docImageDesc.createImage());
            docItem.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    IStorage storage = new DocumentStorage(workflowProject, new DocumentReference(processInstanceInfo.getOwnerId(), null));
                    final IStorageEditorInput input = new StorageEditorInput(storage);
                    final IWorkbenchPage page = MdwPlugin.getActivePage();
                    if (page != null) {
                        BusyIndicator.showWhile(getSite().getShell().getDisplay(), new Runnable() {

                            public void run() {
                                try {
                                    page.openEditor(input, "org.eclipse.ui.DefaultTextEditor");
                                } catch (PartInitException ex) {
                                    PluginMessages.uiError(ex, "View Document", workflowProject);
                                }
                            }
                        });
                    }
                }
            });
        }
        // instance hierarchy
        MenuItem hierarchyItem = new MenuItem(menu, SWT.PUSH);
        hierarchyItem.setText("Instance Hierarchy");
        ImageDescriptor hierarchyImageDesc = MdwPlugin.getImageDescriptor("icons/hierarchy.gif");
        hierarchyItem.setImage(hierarchyImageDesc.createImage());
        hierarchyItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                WorkflowProcess pv = new WorkflowProcess(processVersion);
                pv.setProcessVO(processVersion.getProcessVO());
                pv.setProcessInstance(processInstanceInfo);
                new WorkflowElementActionHandler().showHierarchy(pv);
            }
        });
    }
    // delete
    if (!selection.isEmpty() && !processVersion.getProject().isProduction() && processVersion.isUserAuthorized(UserRoleVO.PROCESS_EXECUTION)) {
        MenuItem deleteItem = new MenuItem(menu, SWT.PUSH);
        deleteItem.setText("Delete...");
        ImageDescriptor deleteImageDesc = MdwPlugin.getImageDescriptor("icons/delete.gif");
        deleteItem.setImage(deleteImageDesc.createImage());
        deleteItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                if (selection.size() == 1 && selection.getFirstElement() instanceof ProcessInstanceVO) {
                    ProcessInstanceVO pii = (ProcessInstanceVO) selection.getFirstElement();
                    if (MessageDialog.openConfirm(getSite().getShell(), "Confirm Delete", "Delete process instance ID: " + pii.getId() + " for workflow project '" + processVersion.getProject().getName() + "'?")) {
                        List<ProcessInstanceVO> instances = new ArrayList<>();
                        instances.add((ProcessInstanceVO) selection.getFirstElement());
                        handleDelete(instances);
                    }
                } else {
                    if (MessageDialog.openConfirm(getSite().getShell(), "Confirm Delete", "Delete selected process instances for workflow project '" + processVersion.getProject().getName() + "'?")) {
                        List<ProcessInstanceVO> instances = new ArrayList<>();
                        for (Object instance : selection.toArray()) {
                            if (instance instanceof ProcessInstanceVO)
                                instances.add((ProcessInstanceVO) instance);
                        }
                        handleDelete(instances);
                    }
                }
            }
        });
    }
    return menu;
}
Also used : DocumentStorage(com.centurylink.mdw.plugin.designer.storage.DocumentStorage) IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) MenuItem(org.eclipse.swt.widgets.MenuItem) IStorage(org.eclipse.core.resources.IStorage) WorkflowElementActionHandler(com.centurylink.mdw.plugin.actions.WorkflowElementActionHandler) StorageEditorInput(com.centurylink.mdw.plugin.designer.storage.StorageEditorInput) IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) List(java.util.List) ArrayList(java.util.ArrayList) Menu(org.eclipse.swt.widgets.Menu) PartInitException(org.eclipse.ui.PartInitException) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) ProcessInstanceVO(com.centurylink.mdw.model.value.process.ProcessInstanceVO) DocumentReference(com.centurylink.mdw.model.value.variable.DocumentReference)

Example 7 with DocumentReference

use of com.centurylink.mdw.model.value.variable.DocumentReference 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)

Example 8 with DocumentReference

use of com.centurylink.mdw.model.value.variable.DocumentReference in project mdw-designer by CenturyLinkCloud.

the class TestCaseRun method translateToLegacyTestFile.

private void translateToLegacyTestFile(String procName, ProcessInstanceVO procInst, int instIndex, Map<Long, String> activityNameMap) throws IOException, DataAccessException {
    TestFile actualFile = new TestFile(null, testcase.getResultDirectory().getPath() + "/R_" + procName + "_I" + instIndex + ".txt");
    TestFile expectedFileToCreate = null;
    if (createReplace) {
        expectedFileToCreate = new TestFile(null, testcase.getCaseDirectory().getPath() + "/E_" + procName + "_I" + instIndex + ".txt");
        log.println("Creating expected results file: " + expectedFileToCreate);
    }
    TestFileLine line = new TestFileLine("PROC");
    line.addWord(Integer.toString(instIndex));
    line.addWord("#");
    line.addWord(procInst.getId().toString());
    actualFile.addLine(line);
    if (expectedFileToCreate != null)
        expectedFileToCreate.addLine(line);
    LinkedList<ActivityInstanceVO> reversedList = new LinkedList<>();
    for (ActivityInstanceVO act : procInst.getActivities()) {
        reversedList.add(0, act);
    }
    for (ActivityInstanceVO act : reversedList) {
        String status = WorkStatuses.getWorkStatuses().get(act.getStatusCode());
        String actName = activityNameMap.get(act.getDefinitionId());
        if (actName == null)
            actName = act.getDefinitionId().toString();
        line = new TestFileLine("ACT");
        line.addWord(actName);
        line.addWord(status);
        line.addWord("#");
        line.addWord(act.getId().toString());
        line.addWord(act.getStartDate());
        actualFile.addLine(line);
        if (expectedFileToCreate != null)
            expectedFileToCreate.addLine(line);
    }
    for (VariableInstanceInfo var : procInst.getVariables()) {
        line = new TestFileLine("VAR");
        line.addWord(var.getName());
        try {
            String value = var.getStringValue();
            if (VariableHelper.isDocumentVariable(var.getType(), value)) {
                DocumentReference docref = new DocumentReference(value);
                String docVal = dao.getDocumentContent(docref, var.getType());
                line.addWord(docVal);
                // pre-populate document values
                procInst.getVariable().put(var.getName(), docVal);
            } else
                line.addWord(var.getStringValue());
        } catch (Throwable e) {
            log.println("Failed to translate variable to string with the following exception");
            e.printStackTrace(log);
            line.addWord(var.getStringValue());
        }
        line.addWord("#");
        line.addWord(var.getInstanceId().toString());
        actualFile.addLine(line);
        if (expectedFileToCreate != null)
            expectedFileToCreate.addLine(line);
    }
    actualFile.save();
    if (expectedFileToCreate != null)
        expectedFileToCreate.save();
}
Also used : ActivityInstanceVO(com.centurylink.mdw.model.value.work.ActivityInstanceVO) VariableInstanceInfo(com.centurylink.mdw.model.value.variable.VariableInstanceInfo) LinkedList(java.util.LinkedList) DocumentReference(com.centurylink.mdw.model.value.variable.DocumentReference)

Aggregations

DocumentReference (com.centurylink.mdw.model.value.variable.DocumentReference)8 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)4 ProcessInstanceVO (com.centurylink.mdw.model.value.process.ProcessInstanceVO)3 ActivityInstanceVO (com.centurylink.mdw.model.value.work.ActivityInstanceVO)3 AuthenticationException (com.centurylink.mdw.auth.AuthenticationException)2 TranslationException (com.centurylink.mdw.common.exception.TranslationException)2 JavaObjectTranslator (com.centurylink.mdw.common.translator.impl.JavaObjectTranslator)2 DataAccessOfflineException (com.centurylink.mdw.dataaccess.DataAccessOfflineException)2 ValidationException (com.centurylink.mdw.designer.utils.ValidationException)2 VariableInstanceInfo (com.centurylink.mdw.model.value.variable.VariableInstanceInfo)2 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)2 DocumentStorage (com.centurylink.mdw.plugin.designer.storage.DocumentStorage)2 StorageEditorInput (com.centurylink.mdw.plugin.designer.storage.StorageEditorInput)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 RemoteException (java.rmi.RemoteException)2 LinkedList (java.util.LinkedList)2 ZipException (java.util.zip.ZipException)2 XmlException (org.apache.xmlbeans.XmlException)2 IStorage (org.eclipse.core.resources.IStorage)2