public void testStartProcessWithLinking() { LogUtil.info(getClass().getName(), ">>> testStartProcessWithLinking"); // start and get instant id of 1st process String packageVersion = workflowManager.getCurrentPackageVersion(packageId); WorkflowProcessResult result = workflowManager.processStart(packageId + "#" + packageVersion + "#" + processId); String process1Id = result.getProcess().getInstanceId(); LogUtil.info( getClass().getName(), "------------- process one id : " + process1Id + " -------------"); // start 2nd process with 1st process instant id and get 2nd process instant id WorkflowProcessResult nextResult = workflowManager.processStartWithLinking( packageId + "#" + packageVersion + "#" + processId, null, null, process1Id); String process2Id = nextResult.getProcess().getInstanceId(); LogUtil.info( getClass().getName(), "------------- process two id : " + process2Id + " -------------"); // check process linking data is correct or not WorkflowProcessLink link = workflowManager.getWorkflowProcessLink(process2Id); LogUtil.info( getClass().getName(), "------------- origin process id : " + link.getOriginProcessId() + " -------------"); workflowManager.internalDeleteWorkflowProcessLink(link); Assert.assertNotNull(link); Assert.assertTrue( process1Id.equals(link.getOriginProcessId()) && process1Id.equals(link.getParentProcessId())); }
@Override public FormRowSet store(Element element, FormRowSet rows, FormData formData) { FormRowSet result = rows; if (rows != null && !rows.isEmpty()) { // store form data to DB result = super.store(element, rows, formData); // handle workflow variables if (!rows.isMultiRow()) { String activityId = formData.getActivityId(); String processId = formData.getProcessId(); if (activityId != null || processId != null) { WorkflowManager workflowManager = (WorkflowManager) WorkflowUtil.getApplicationContext().getBean("workflowManager"); // recursively find element(s) mapped to workflow variable FormRow row = rows.iterator().next(); Map<String, String> variableMap = new HashMap<String, String>(); variableMap = storeWorkflowVariables(element, row, variableMap); if (activityId != null) { workflowManager.activityVariables(activityId, variableMap); } else { workflowManager.processVariables(processId, variableMap); } } } } return result; }
public void testStartActivityC() { LogUtil.info(getClass().getName(), ">>> testStartActivityC"); String currentActivityDef = "B"; String desiredActivityDef = "C"; // get process instance Map runningActivities = workflowManager.getActivityInstanceByProcessIdAndStatus(processId, null); String activityId = String.valueOf(runningActivities.get(currentActivityDef)); WorkflowActivity wa = workflowManager.getActivityById(activityId); String processInstanceId = wa.getProcessId(); // abort running activities and start activity C boolean started = workflowManager.activityStart(processInstanceId, desiredActivityDef, true); // check running activities runningActivities = workflowManager.getActivityInstanceByProcessIdAndStatus(processId, null); String abortedActivity = (String) runningActivities.get(currentActivityDef); String runningActivity = (String) runningActivities.get(desiredActivityDef); LogUtil.info( getClass().getName(), "Running activities: " + runningActivities + "; Result: " + started); Assert.assertTrue(abortedActivity == null && runningActivity != null); }
public void testCloseAndRemovePackage() { LogUtil.info(getClass().getName(), ">>> testCloseAndRemovePackage"); Collection<WorkflowProcess> processList = workflowManager.getRunningProcessList(packageId, null, null, null, null, null, 0, 100); for (WorkflowProcess process : processList) workflowManager.removeProcessInstance(process.getInstanceId()); workflowManager.processDeleteAndUnload(packageId); }
public void testAssignment() { LogUtil.info(getClass().getName(), ">>> testAssignment"); Map activityInstance = workflowManager.getActivityInstanceByProcessIdAndStatus(processId, true); String activityId = String.valueOf(activityInstance.get("A")); WorkflowActivity wa = workflowManager.getActivityById(activityId); String processInstanceId = wa.getProcessId(); WorkflowAssignment ass = workflowManager.getAssignmentByProcess(processInstanceId); WorkflowAssignment ass2 = workflowManager.getAssignment(activityId); Assert.assertTrue( ass != null && ass2 != null && ass.getActivityId().equals(ass2.getActivityId())); }
@RequestMapping("/client/app/(~:appId)/(~:version)/assignment/(*:activityId)") public String clientAssignmentView( HttpServletRequest request, ModelMap model, @RequestParam(required = false) String appId, @RequestParam(required = false) String version, @RequestParam("activityId") String activityId) { // check assignment WorkflowAssignment assignment = workflowManager.getAssignment(activityId); if (assignment == null) { return "client/app/assignmentUnavailable"; } try { // get app AppDefinition appDef = null; if (appId != null && !appId.isEmpty()) { appDef = appService.getAppDefinition(appId, version); } else { appDef = appService.getAppDefinitionForWorkflowActivity(activityId); if (appDef != null) { appId = appDef.getId(); } } FormData formData = new FormData(); formData = formService.retrieveFormDataFromRequest(formData, request); // get form Long appVersion = (appDef != null) ? appDef.getVersion() : null; String formUrl = AppUtil.getRequestContextPath() + "/web/client/app/" + appId + "/" + appVersion + "/assignment/" + activityId + "/submit"; PackageActivityForm activityForm = appService.viewAssignmentForm(appId, version, activityId, formData, formUrl); Form form = activityForm.getForm(); // generate form HTML String formHtml = formService.retrieveFormHtml(form, formData); String formJson = formService.generateElementJson(form); model.addAttribute("appDef", appDef); model.addAttribute("assignment", assignment); model.addAttribute("activityForm", activityForm); model.addAttribute("form", form); model.addAttribute("formHtml", formHtml); model.addAttribute("formJson", formJson); } catch (Exception e) { Logger.getLogger(AppWebController.class.getName()).log(Level.SEVERE, null, e); } return "client/app/assignmentView"; }
protected void storeToWorkflowVariable( WorkflowAssignment wfAssignment, Map properties, Map object) { Object[] wfVariableMapping = (Object[]) properties.get("wfVariableMapping"); if (wfVariableMapping != null && wfVariableMapping.length > 0) { ApplicationContext ac = AppUtil.getApplicationContext(); WorkflowManager workflowManager = (WorkflowManager) ac.getBean("workflowManager"); for (Object o : wfVariableMapping) { Map mapping = (HashMap) o; String variable = mapping.get("variable").toString(); String jsonObjectName = mapping.get("jsonObjectName").toString(); String value = (String) getObjectFromMap(jsonObjectName, object); if (value != null) { workflowManager.activityVariable(wfAssignment.getActivityId(), variable, value); } } } }
@Override public FormRowSet load(Element element, String primaryKey, FormData formData) { // load form data from DB FormRowSet rows = super.load(element, primaryKey, formData); if (rows != null) { // handle workflow variables String activityId = formData.getActivityId(); String processId = formData.getProcessId(); WorkflowManager workflowManager = (WorkflowManager) WorkflowUtil.getApplicationContext().getBean("workflowManager"); Collection<WorkflowVariable> variableList = null; if (activityId != null && !activityId.isEmpty()) { variableList = workflowManager.getActivityVariableList(activityId); } else if (processId != null && !processId.isEmpty()) { variableList = workflowManager.getProcessVariableList(processId); } else { variableList = new ArrayList<WorkflowVariable>(); } if (variableList != null && !variableList.isEmpty()) { FormRow row = null; if (rows.isEmpty()) { row = new FormRow(); rows.add(row); } else { row = rows.iterator().next(); } Map<String, String> variableMap = new HashMap<String, String>(); for (WorkflowVariable variable : variableList) { Object val = variable.getVal(); if (val != null) { variableMap.put(variable.getId(), val.toString()); } } loadWorkflowVariables(element, row, variableMap); } } return rows; }
public void testCopyProcess() { LogUtil.info(getClass().getName(), ">>> testCopyProcess"); boolean valid = false; // start and get instance id of the 1st process String packageVersion = workflowManager.getCurrentPackageVersion(packageId); WorkflowProcessResult result = workflowManager.processStart(packageId + "#" + packageVersion + "#" + processId); String processInstanceId = result.getProcess().getInstanceId(); LogUtil.info( getClass().getName(), "------------- process one id : " + processInstanceId + " -------------"); // abort running activities and start activity B String firstActivityDef = "A"; String desiredActivityDef = "B"; boolean started = workflowManager.activityStart(processInstanceId, desiredActivityDef, true); if (started) { // start 2nd process from the 1st process instance id WorkflowProcessResult nextResult = workflowManager.processCopyFromInstanceId( processInstanceId, packageId + "#" + packageVersion + "#" + processId, true); WorkflowProcess processStarted = nextResult.getProcess(); if (processStarted != null) { // check for the aborted and running activities String newProcessId = processStarted.getInstanceId(); Collection<WorkflowActivity> activityList = workflowManager.getActivityList(newProcessId, 0, 1000, null, null); for (WorkflowActivity act : activityList) { if (act.getState().startsWith("open")) { if (firstActivityDef.equals(act.getActivityDefId())) { valid = false; break; } if (desiredActivityDef.equals(act.getActivityDefId())) { valid = true; } } } LogUtil.info( getClass().getName(), "------------- new process id : " + newProcessId + " ------------- " + valid); // cleanup WorkflowProcessLink link = workflowManager.getWorkflowProcessLink(newProcessId); workflowManager.internalDeleteWorkflowProcessLink(link); } } Assert.assertTrue(valid); }
public void testUploadProcess() throws FileNotFoundException, IOException, Exception { LogUtil.info(getClass().getName(), ">>> testUploadProcess"); BufferedReader reader = null; String fileContents = ""; String line; try { reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(xpdl))); while ((line = reader.readLine()) != null) { fileContents += line + "\n"; } } finally { if (reader != null) { reader.close(); } } byte[] processDefinitionData = fileContents.getBytes(); workflowManager.processUpload(null, processDefinitionData); }
@RequestMapping("/client/app/(*:appId)/(~:version)/process/(*:processDefId)") public String clientProcessView( HttpServletRequest request, ModelMap model, @RequestParam("appId") String appId, @RequestParam(required = false) String version, @RequestParam String processDefId, @RequestParam(required = false) String recordId, @RequestParam(required = false) String start) { // clean process def processDefId = WorkflowUtil.getProcessDefIdWithoutVersion(processDefId); AppDefinition appDef = appService.getAppDefinition(appId, version); WorkflowProcess processDef = appService.getWorkflowProcessForApp(appId, appDef.getVersion().toString(), processDefId); // check for permission if (!workflowManager.isUserInWhiteList(processDef.getId())) { return "client/app/processUnauthorized"; } // set app and process details model.addAttribute("appId", appId); model.addAttribute("appVersion", appDef.getVersion()); model.addAttribute("appDefinition", appDef); model.addAttribute("process", processDef); model.addAttribute("queryString", request.getQueryString()); // check for start mapped form FormData formData = new FormData(); formData.setPrimaryKeyValue(recordId); String formUrl = "/web/client/app/" + appId + "/" + appDef.getVersion() + "/process/" + processDefId + "/start"; if (recordId != null) { formUrl += "?recordId=" + recordId; } String formUrlWithContextPath = AppUtil.getRequestContextPath() + formUrl; PackageActivityForm startFormDef = appService.viewStartProcessForm( appId, appDef.getVersion().toString(), processDefId, formData, formUrlWithContextPath); if (startFormDef != null && startFormDef.getForm() != null) { Form startForm = startFormDef.getForm(); // generate form HTML String formHtml = formService.retrieveFormHtml(startForm, formData); String formJson = formService.generateElementJson(startForm); // show form model.addAttribute("form", startForm); model.addAttribute("formJson", formJson); model.addAttribute("formHtml", formHtml); return "client/app/processFormStart"; } else { if (Boolean.valueOf(start).booleanValue()) { // redirect to start URL return "redirect:" + formUrl; } else { // empty start page return "client/app/processStart"; } } }
@RequestMapping("/client/app/(~:appId)/(~:version)/assignment/(*:activityId)/submit") public String clientAssignmentSubmit( HttpServletRequest request, ModelMap model, @RequestParam(required = false) String appId, @RequestParam(required = false) String version, @RequestParam("activityId") String activityId) { // check assignment WorkflowAssignment assignment = workflowManager.getAssignment(activityId); if (assignment == null) { return "client/app/assignmentUnavailable"; } // get app AppDefinition appDef = null; if (appId != null && !appId.isEmpty()) { appDef = appService.getAppDefinition(appId, version); } else { appDef = appService.getAppDefinitionForWorkflowActivity(activityId); } // extract form values from request FormData formData = new FormData(); formData = formService.retrieveFormDataFromRequest(formData, request); // set process instance ID as primary key String processId = assignment.getProcessId(); // load form Long appVersion = (appDef != null) ? appDef.getVersion() : null; String formUrl = AppUtil.getRequestContextPath() + "/web/client/app/" + appId + "/" + appVersion + "/assignment/" + activityId + "/submit"; PackageActivityForm activityForm = appService.viewAssignmentForm(appId, version, activityId, formData, formUrl); Form form = activityForm.getForm(); // submit form FormData formResult = formService.executeFormActions(form, formData); if (formResult.getFormResult(AssignmentWithdrawButton.DEFAULT_ID) != null) { // withdraw assignment workflowManager.assignmentWithdraw(activityId); return "client/app/dialogClose"; } else if (formResult.getFormResult(AssignmentCompleteButton.DEFAULT_ID) != null) { // complete assignment Map<String, String> variableMap = AppUtil.retrieveVariableDataFromRequest(request); formResult = appService.completeAssignmentForm(appId, version, activityId, formData, variableMap); Map<String, String> errors = formResult.getFormErrors(); if (errors.isEmpty() && activityForm.isAutoContinue()) { // redirect to next activity if available WorkflowAssignment nextActivity = workflowManager.getAssignmentByProcess(processId); if (nextActivity != null) { String assignmentUrl = "/web/client/app/" + appId + "/" + appVersion + "/assignment/" + nextActivity.getActivityId(); return "redirect:" + assignmentUrl; } } } String html = null; // check for validation errors Map<String, String> errors = formResult.getFormErrors(); int errorCount = 0; if (errors == null || errors.isEmpty()) { // render normal template html = formService.generateElementHtml(form, formResult); } else { // render error template html = formService.generateElementErrorHtml(form, formResult); errorCount = errors.size(); } String formJson = formService.generateElementJson(form); model.addAttribute("assignment", assignment); model.addAttribute("form", form); model.addAttribute("formHtml", html); model.addAttribute("formJson", formJson); model.addAttribute("formResult", formResult); model.addAttribute("errorCount", errorCount); model.addAttribute("submitted", Boolean.TRUE); model.addAttribute("closeDialog", Boolean.TRUE); return "client/app/assignmentView"; }
@RequestMapping("/client/app/(*:appId)/(~:version)/process/(*:processDefId)/start") public String clientProcessStart( HttpServletRequest request, ModelMap model, @RequestParam("appId") String appId, @RequestParam(required = false) String version, @RequestParam(required = false) String recordId, @RequestParam String processDefId) { // clean process def processDefId = WorkflowUtil.getProcessDefIdWithoutVersion(processDefId); // set app and process details AppDefinition appDef = appService.getAppDefinition(appId, version); WorkflowProcess processDef = appService.getWorkflowProcessForApp(appId, appDef.getVersion().toString(), processDefId); String processDefIdWithVersion = processDef.getId(); model.addAttribute("appId", appId); model.addAttribute("appVersion", appDef.getVersion()); model.addAttribute("appDefinition", appDef); model.addAttribute("process", processDef); // check for permission if (!workflowManager.isUserInWhiteList(processDef.getId())) { return "client/app/processUnauthorized"; } // extract form values from request FormData formData = new FormData(); formData.setPrimaryKeyValue(recordId); formData = formService.retrieveFormDataFromRequest(formData, request); // get workflow variables Map<String, String> variableMap = AppUtil.retrieveVariableDataFromRequest(request); String formUrl = AppUtil.getRequestContextPath() + "/web/client/app/" + appId + "/" + appDef.getVersion() + "/process/" + processDefId + "/start"; if (recordId != null) { formUrl += "?recordId=" + recordId; } PackageActivityForm startFormDef = appService.viewStartProcessForm( appId, appDef.getVersion().toString(), processDefId, formData, formUrl); WorkflowProcessResult result = appService.submitFormToStartProcess( appId, version, processDefId, formData, variableMap, recordId, formUrl); if (startFormDef != null && (startFormDef.getForm() != null || PackageActivityForm.ACTIVITY_FORM_TYPE_EXTERNAL.equals(startFormDef.getType()))) { if (result == null) { // validation error, get form Form startForm = startFormDef.getForm(); // generate form HTML String formHtml = formService.retrieveFormErrorHtml(startForm, formData); String formJson = formService.generateElementJson(startForm); // show form model.addAttribute("form", startForm); model.addAttribute("formJson", formJson); model.addAttribute("formHtml", formHtml); model.addAttribute("activityForm", startFormDef); return "client/app/processFormStart"; } } else { // start process - TODO: handle process linking result = workflowManager.processStart( processDefIdWithVersion, null, variableMap, null, recordId, false); } // set result if (result != null) { WorkflowProcess process = result.getProcess(); model.addAttribute("process", process); // redirect to next activity if available Collection<WorkflowActivity> activities = result.getActivities(); if (activities != null && !activities.isEmpty()) { WorkflowActivity nextActivity = activities.iterator().next(); String assignmentUrl = "/web/client/app/" + appId + "/" + appDef.getVersion() + "/assignment/" + nextActivity.getId() + "?" + request.getQueryString(); return "redirect:" + assignmentUrl; } } return "client/app/processStarted"; }
public void testAcceptedA() { LogUtil.info(getClass().getName(), ">>> testAcceptedA"); Map activityInstance = workflowManager.getActivityInstanceByProcessIdAndStatus(processId, true); workflowManager.assignmentComplete(String.valueOf(activityInstance.get("A"))); }
public void testStartProcess() { LogUtil.info(getClass().getName(), ">>> testStartProcess"); String packageVersion = workflowManager.getCurrentPackageVersion(packageId); workflowManager.processStart(packageId + "#" + packageVersion + "#" + processId); }