protected FormRow getRow( WorkflowAssignment wfAssignment, String multirowBaseObjectName, Integer rowNumber, Object[] fieldMapping, Map object) { FormRow row = new FormRow(); for (Object o : fieldMapping) { Map mapping = (HashMap) o; String fieldName = mapping.get("field").toString(); String jsonObjectName = WorkflowUtil.processVariable( mapping.get("jsonObjectName").toString(), null, wfAssignment, null, null); if (multirowBaseObjectName != null) { jsonObjectName = jsonObjectName.replace( multirowBaseObjectName, multirowBaseObjectName + "[" + rowNumber + "]"); } String value = (String) getObjectFromMap(jsonObjectName, object); if (value == null) { value = jsonObjectName; } if (FormUtil.PROPERTY_ID.equals(fieldName)) { row.setId(value); } else { row.put(fieldName, value); } } if (row.getId() == null || (row.getId() != null && row.getId().trim().length() == 0)) { if (multirowBaseObjectName == null) { row.setId(wfAssignment.getProcessId()); } else { row.setId(UuidGenerator.getInstance().getUuid()); } } Date currentDate = new Date(); row.setDateModified(currentDate); row.setDateCreated(currentDate); return row; }
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); } } } }
@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"; }