* @param formUrl
* @return
*/
@Override
public WorkflowProcessResult submitFormToStartProcess(String appId, String version, String processDefId, FormData formData, Map<String, String> workflowVariableMap, String originProcessId, String formUrl) {
WorkflowProcessResult result = null;
if (formData == null) {
formData = new FormData();
}
AppDefinition appDef = getAppDefinition(appId, version);
PackageDefinition packageDef = appDef.getPackageDefinition();
String processDefIdWithVersion = AppUtil.getProcessDefIdWithVersion(packageDef.getId(), packageDef.getVersion().toString(), processDefId);
// get form
PackageActivityForm startFormDef = viewStartProcessForm(appId, appDef.getVersion().toString(), processDefId, formData, formUrl);
if (startFormDef != null && startFormDef.getForm() != null) {
Form startForm = startFormDef.getForm();
FormData formResult = formService.executeFormActions(startForm, formData);
if (formResult.getFormResult(AssignmentCompleteButton.DEFAULT_ID) != null) {
// validate form
formData = FormUtil.executeElementFormatDataForValidation(startForm, formData);
formResult = formService.validateFormData(startForm, formData);
Map<String, String> errors = formResult.getFormErrors();
if (!formResult.getStay() && (errors == null || errors.isEmpty())) {
if (originProcessId == null && formResult.getRequestParameter(FormUtil.FORM_META_ORIGINAL_ID) != null && !formResult.getRequestParameter(FormUtil.FORM_META_ORIGINAL_ID).isEmpty()) {
originProcessId = formResult.getRequestParameter(FormUtil.FORM_META_ORIGINAL_ID);
} else if (startForm.getPrimaryKeyValue(formResult) != null) {
originProcessId = startForm.getPrimaryKeyValue(formResult);
}
// start process
result = workflowManager.processStart(processDefIdWithVersion, null, workflowVariableMap, null, originProcessId, true);
String processId = result.getProcess().getInstanceId();
String originId = (originProcessId != null && originProcessId.trim().length() > 0) ? originProcessId : processId;
originId = getOriginProcessId(originId);
// set primary key
formResult.setPrimaryKeyValue(originId);
formResult.setProcessId(processId);
// submit form
formResult = formService.submitForm(startForm, formResult, true);
errors = formResult.getFormErrors();
if (!formResult.getStay() && (errors == null || errors.isEmpty())) {
result = workflowManager.processStartWithInstanceId(processDefIdWithVersion, processId, workflowVariableMap);
// set next activity if configured
boolean autoContinue = (startFormDef != null) && startFormDef.isAutoContinue();
if (!autoContinue) {
// clear next activities
result.setActivities(new ArrayList<WorkflowActivity>());
}
} else {
workflowManager.removeProcessInstance(processId);
result = null;
}