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;
}
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();
}
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();
}
Aggregations