public PackageActivityForm viewAssignmentForm(AppDefinition appDef, WorkflowAssignment assignment, FormData formData, String formUrl) {
String activityId = assignment.getActivityId();
String processId = assignment.getProcessId();
String processDefId = assignment.getProcessDefId();
String activityDefId = assignment.getActivityDefId();
PackageActivityForm activityForm = retrieveMappedForm(appDef.getAppId(), appDef.getVersion().toString(), processDefId, activityDefId);
// get origin process id
String originProcessId = getOriginProcessId(processId);
// get mapped form
if (formData == null) {
formData = new FormData();
}
formData.setActivityId(activityId);
formData.setProcessId(processId);
formData.setPrimaryKeyValue(originProcessId);
Form form = retrieveForm(appDef, activityForm, formData, assignment);
if (form == null) {
form = createDefaultForm(processId, formData);
}
// set action URL
form.setProperty("url", formUrl);
// decorate form with actions
Collection<FormAction> formActionList = new ArrayList<FormAction>();
if (activityForm != null && activityForm.getFormId() != null && !activityForm.getFormId().isEmpty() && !activityForm.getDisableSaveAsDraft()) {
Element saveButton = (Element) pluginManager.getPlugin(SaveAsDraftButton.class.getName());
saveButton.setProperty(FormUtil.PROPERTY_ID, "saveAsDraft");
saveButton.setProperty("label", ResourceBundleUtil.getMessage("form.button.saveAsDraft"));
formActionList.add((FormAction) saveButton);
}
Element completeButton = (Element) pluginManager.getPlugin(AssignmentCompleteButton.class.getName());
completeButton.setProperty(FormUtil.PROPERTY_ID, AssignmentCompleteButton.DEFAULT_ID);
completeButton.setProperty("label", ResourceBundleUtil.getMessage("form.button.complete"));
formActionList.add((FormAction) completeButton);
FormAction[] formActions = formActionList.toArray(new FormAction[0]);
form = decorateFormActions(form, formActions);
// set to definition
if (activityForm == null) {
activityForm = new PackageActivityForm();
}
activityForm.setForm(form);
if (PackageActivityForm.ACTIVITY_FORM_TYPE_EXTERNAL.equals(activityForm.getType())) {
// set external URL
String externalUrl = AppUtil.processHashVariable(activityForm.getFormUrl(), assignment, null, null);
if (externalUrl.indexOf("?") >= 0) {
if (!externalUrl.endsWith("?") && !externalUrl.endsWith("&")) {
externalUrl += "&";
}
} else {
externalUrl += "?";
}
activityForm.setFormUrl(externalUrl);
}
return activityForm;
}