提交 b4ab7901 编写于 作者: T tombaeyens

ACT-258 form property handling

上级 1abde24c
......@@ -15,8 +15,8 @@ package org.activiti.engine;
import java.util.Map;
import org.activiti.engine.form.StartForm;
import org.activiti.engine.form.TaskForm;
import org.activiti.engine.form.StartFormData;
import org.activiti.engine.form.TaskFormData;
import org.activiti.engine.runtime.ProcessInstance;
......@@ -27,7 +27,7 @@ import org.activiti.engine.runtime.ProcessInstance;
public interface FormService {
/** Retrieves all data necessary for rendering a form to start a new process instance. This can be used to perform rendering of the forms outside of the process engine. */
StartForm getStartForm(String processDefinitionId);
StartFormData getStartFormData(String processDefinitionId);
/** Rendered form generated by the default build-in form engine for starting a new process instance. */
Object getRenderedStartForm(String processDefinitionId);
......@@ -36,10 +36,10 @@ public interface FormService {
Object getRenderedStartForm(String processDefinitionId, String formEngineName);
/** Start a new process instance with the user data that was entered as properties in a start form. */
ProcessInstance submitStartForm(String processDefinitionId, Map<String, Object> properties);
ProcessInstance submitStartFormData(String processDefinitionId, Map<String, String> properties);
/** Retrieves all data necessary for rendering a form to complete a task. This can be used to perform rendering of the forms outside of the process engine. */
TaskForm getTaskForm(String taskId);
TaskFormData getTaskFormData(String taskId);
/** Rendered form generated by the default build-in form engine for completing a task. */
Object getRenderedTaskForm(String taskId);
......@@ -48,6 +48,6 @@ public interface FormService {
Object getRenderedTaskForm(String taskId, String formEngineName);
/** Completes a task with the user data that was entered as properties in a task form. */
void submitTaskForm(String taskId, Map<String, Object> properties);
void submitTaskFormData(String taskId, Map<String, String> properties);
}
......@@ -13,14 +13,15 @@
package org.activiti.engine.form;
import java.util.Map;
import java.util.List;
/** base class for {@link StartForm} and {@link TaskForm}
/** contains all information for diaplaying a form and serves as
* base interface for {@link StartFormData} and {@link TaskFormData}
*
* @author Tom Baeyens
*/
public interface Form {
public interface FormData {
/** user defined reference to a form. In the Explorer app, it is
* assumed that the form key specifies a resource in the deployment
......@@ -28,12 +29,10 @@ public interface Form {
* use this property differently. */
String getFormKey();
/** the deployment id of the process definition to which this form is related */
/** the deployment id of the process definition to which this form is related
* */
String getDeploymentId();
/** properties containing the dynamic information that needs to be displayed in the form. */
Map<String, Object> getProperties();
/** property containing the dynamic information that needs to be displayed in the form. */
Object getProperty(String propertyName);
List<FormProperty> getFormProperties();
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.form;
import org.activiti.engine.FormService;
/**
* @author Tom Baeyens
*/
public interface FormProperty {
/** the key used to submit the property in {@link FormService#submitStartFormData(String, java.util.Map)}
* or {@link FormService#submitTaskFormData(String, java.util.Map)} */
String getId();
/** the display label */
String getName();
/** one of the types defined in this interface like e.g. {@link #TYPE_STRING} */
FormType getType();
/** optional value that should be used to display in this property */
String getValue();
/** is this property read to be displayed in the form and made accessible with the methods
* {@link FormService#getStartFormData(String)} and {@link FormService#getTaskFormData(String)}. */
boolean isReadable();
/** is this property expected when a user submits the form? */
boolean isWritable();
/** is this property a required input field */
boolean isRequired();
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.form;
/**
* @author Tom Baeyens
*/
public interface FormType {
/** name for the form type. */
String getName();
/** retrieve type specific extra information like
* the list of values for enum types or the format
* for date types. Look in the userguide for
* which extra information keys each type provides
* and what return type they give. */
Object getInformation(String key);
}
......@@ -16,11 +16,11 @@ package org.activiti.engine.form;
import org.activiti.engine.repository.ProcessDefinition;
/** Specific {@link Form} for starting a new process instance.
/** Specific {@link FormData} for starting a new process instance.
*
* @author Tom Baeyens
*/
public interface StartForm extends Form {
public interface StartFormData extends FormData {
/** the process definition for which this form is starting a new process instance */
ProcessDefinition getProcessDefinition();
......
......@@ -16,11 +16,11 @@ package org.activiti.engine.form;
import org.activiti.engine.task.Task;
/** Specific {@link Form} for completing a task.
/** Specific {@link FormData} for completing a task.
*
* @author Tom Baeyens
*/
public interface TaskForm extends Form {
public interface TaskFormData extends FormData {
/** the task for which this form is used to complete it. */
Task getTask();
......
......@@ -16,8 +16,8 @@ package org.activiti.engine.impl;
import java.util.Map;
import org.activiti.engine.FormService;
import org.activiti.engine.form.StartForm;
import org.activiti.engine.form.TaskForm;
import org.activiti.engine.form.StartFormData;
import org.activiti.engine.form.TaskFormData;
import org.activiti.engine.impl.cmd.GetRenderedStartFormCmd;
import org.activiti.engine.impl.cmd.GetRenderedTaskFormCmd;
import org.activiti.engine.impl.cmd.GetStartFormCmd;
......@@ -48,19 +48,19 @@ public class FormServiceImpl extends ServiceImpl implements FormService {
return commandExecutor.execute(new GetRenderedTaskFormCmd(taskId, engineName));
}
public StartForm getStartForm(String processDefinitionId) {
public StartFormData getStartFormData(String processDefinitionId) {
return commandExecutor.execute(new GetStartFormCmd(processDefinitionId));
}
public TaskForm getTaskForm(String taskId) {
public TaskFormData getTaskFormData(String taskId) {
return commandExecutor.execute(new GetTaskFormCmd(taskId));
}
public ProcessInstance submitStartForm(String processDefinitionId, Map<String, Object> properties) {
public ProcessInstance submitStartFormData(String processDefinitionId, Map<String, String> properties) {
return commandExecutor.execute(new SubmitStartFormCmd(processDefinitionId, properties));
}
public void submitTaskForm(String taskId, Map<String, Object> properties) {
public void submitTaskFormData(String taskId, Map<String, String> properties) {
commandExecutor.execute(new SubmitTaskFormCmd(taskId, properties));
}
......
......@@ -18,7 +18,7 @@ import java.util.Map;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.form.Form;
import org.activiti.engine.form.FormData;
import org.activiti.engine.impl.cmd.DeleteProcessInstanceCmd;
import org.activiti.engine.impl.cmd.FindActiveActivityIdsCmd;
import org.activiti.engine.impl.cmd.GetStartFormCmd;
......@@ -109,7 +109,7 @@ public class RuntimeServiceImpl extends ServiceImpl implements RuntimeService {
return commandExecutor.execute(new FindActiveActivityIdsCmd(executionId));
}
public Form getFormInstanceById(String processDefinitionId) {
public FormData getFormInstanceById(String processDefinitionId) {
return commandExecutor.execute(new GetStartFormCmd(processDefinitionId));
}
}
......@@ -466,7 +466,7 @@ public class BpmnParse extends Parse {
} else {
startFormHandler = new DefaultStartFormHandler();
}
startFormHandler.parseConfiguration(deployment, startEventElement);
startFormHandler.parseConfiguration(startEventElement, deployment, this);
processDefinition.setStartFormHandler(startFormHandler);
String initiatorVariableName = startEventElement.attributeNS(BpmnParser.BPMN_EXTENSIONS_NS, "initiator");
......@@ -908,7 +908,7 @@ public class BpmnParse extends Parse {
} else {
taskFormHandler = new DefaultTaskFormHandler();
}
taskFormHandler.parseConfiguration(deployment, taskElement);
taskFormHandler.parseConfiguration(taskElement, deployment, this);
TaskDefinition taskDefinition = new TaskDefinition(taskFormHandler);
......@@ -1544,4 +1544,24 @@ public class BpmnParse extends Parse {
public void addOperation(OperationImplementation operationImplementation) {
this.operationImplementations.put(operationImplementation.getName(), operationImplementation);
}
public Boolean parseBooleanAttribute(String booleanText) {
if ("true".equals(booleanText)
|| "enabled".equals(booleanText)
|| "on".equals(booleanText)
|| "active".equals(booleanText)
|| "yes".equals(booleanText)
) {
return Boolean.TRUE;
}
if ("false".equals(booleanText)
|| "disabled".equals(booleanText)
|| "off".equals(booleanText)
|| "inactive".equals(booleanText)
|| "no".equals(booleanText)
) {
return Boolean.FALSE;
}
return null;
}
}
......@@ -53,8 +53,12 @@ import org.activiti.engine.impl.db.DbSqlSession;
import org.activiti.engine.impl.db.DbSqlSessionFactory;
import org.activiti.engine.impl.db.DbTaskSessionFactory;
import org.activiti.engine.impl.el.ExpressionManager;
import org.activiti.engine.impl.form.DateFormType;
import org.activiti.engine.impl.form.FormEngine;
import org.activiti.engine.impl.form.FormTypes;
import org.activiti.engine.impl.form.JuelFormEngine;
import org.activiti.engine.impl.form.LongFormType;
import org.activiti.engine.impl.form.StringFormType;
import org.activiti.engine.impl.history.handler.HistoryTaskAssignmentHandler;
import org.activiti.engine.impl.interceptor.CommandContextFactory;
import org.activiti.engine.impl.interceptor.CommandContextInterceptor;
......@@ -180,7 +184,9 @@ public class ProcessEngineConfiguration {
protected String mailServerDefaultFrom;
protected Map<String, FormEngine> formEngines;
private ClassLoader classLoader;
protected FormTypes formTypes;
protected ClassLoader classLoader;
public ProcessEngineConfiguration() {
processEngineName = ProcessEngines.NAME_DEFAULT;
......@@ -246,6 +252,11 @@ public class ProcessEngineConfiguration {
FormEngine defaultFormEngine = new JuelFormEngine();
formEngines.put(null, defaultFormEngine); // default form engine is looked up with null
formEngines.put("juel", defaultFormEngine);
formTypes = new FormTypes();
formTypes.addFormType(new StringFormType());
formTypes.addFormType(new LongFormType());
formTypes.addFormType(new DateFormType("dd/MM/yyyy"));
}
public ProcessEngine buildProcessEngine() {
......@@ -711,11 +722,19 @@ public class ProcessEngineConfiguration {
this.formService = formService;
}
public void setClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
public FormTypes getFormTypes() {
return formTypes;
}
public void setFormTypes(FormTypes formTypes) {
this.formTypes = formTypes;
}
public ClassLoader getClassLoader() {
return classLoader;
}
public void setClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}
}
......@@ -13,7 +13,7 @@
package org.activiti.engine.impl.cmd;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.form.StartForm;
import org.activiti.engine.form.StartFormData;
import org.activiti.engine.impl.cfg.RepositorySession;
import org.activiti.engine.impl.form.FormEngine;
import org.activiti.engine.impl.form.StartFormHandler;
......@@ -56,7 +56,7 @@ public class GetRenderedStartFormCmd implements Command<Object> {
throw new ActivitiException("No formEngine '" + formEngineName +"' defined process engine configuration");
}
StartForm startForm = startFormHandler.createStartForm(processDefinition);
StartFormData startForm = startFormHandler.createStartFormData(processDefinition);
return formEngine.renderStartForm(startForm);
}
......
......@@ -14,7 +14,7 @@
package org.activiti.engine.impl.cmd;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.form.TaskForm;
import org.activiti.engine.form.TaskFormData;
import org.activiti.engine.impl.cfg.TaskSession;
import org.activiti.engine.impl.form.FormEngine;
import org.activiti.engine.impl.form.TaskFormHandler;
......@@ -57,7 +57,7 @@ public class GetRenderedTaskFormCmd implements Command<Object> {
throw new ActivitiException("No formEngine '" + formEngineName +"' defined process engine configuration");
}
TaskForm taskForm = taskFormHandler.createTaskForm(task);
TaskFormData taskForm = taskFormHandler.createTaskForm(task);
return formEngine.renderTaskForm(taskForm);
}
......
......@@ -14,7 +14,7 @@
package org.activiti.engine.impl.cmd;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.form.StartForm;
import org.activiti.engine.form.StartFormData;
import org.activiti.engine.impl.cfg.RepositorySession;
import org.activiti.engine.impl.form.StartFormHandler;
import org.activiti.engine.impl.interceptor.Command;
......@@ -26,7 +26,7 @@ import org.activiti.engine.impl.repository.ProcessDefinitionEntity;
/**
* @author Tom Baeyens
*/
public class GetStartFormCmd implements Command<StartForm> {
public class GetStartFormCmd implements Command<StartFormData> {
protected String processDefinitionId;
......@@ -34,7 +34,7 @@ public class GetStartFormCmd implements Command<StartForm> {
this.processDefinitionId = processDefinitionId;
}
public StartForm execute(CommandContext commandContext) {
public StartFormData execute(CommandContext commandContext) {
RepositorySession repositorySession = commandContext.getRepositorySession();
ProcessDefinitionEntity processDefinition = repositorySession.findDeployedProcessDefinitionById(processDefinitionId);
if (processDefinition == null) {
......@@ -47,6 +47,6 @@ public class GetStartFormCmd implements Command<StartForm> {
}
return startFormHandler.createStartForm(processDefinition);
return startFormHandler.createStartFormData(processDefinition);
}
}
......@@ -14,7 +14,7 @@
package org.activiti.engine.impl.cmd;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.form.TaskForm;
import org.activiti.engine.form.TaskFormData;
import org.activiti.engine.impl.cfg.TaskSession;
import org.activiti.engine.impl.form.TaskFormHandler;
import org.activiti.engine.impl.interceptor.Command;
......@@ -26,7 +26,7 @@ import org.activiti.engine.impl.task.TaskEntity;
/**
* @author Tom Baeyens
*/
public class GetTaskFormCmd implements Command<TaskForm> {
public class GetTaskFormCmd implements Command<TaskFormData> {
protected String taskId;
......@@ -34,7 +34,7 @@ public class GetTaskFormCmd implements Command<TaskForm> {
this.taskId = taskId;
}
public TaskForm execute(CommandContext commandContext) {
public TaskFormData execute(CommandContext commandContext) {
TaskSession taskSession = commandContext.getTaskSession();
TaskEntity task = taskSession.findTaskById(taskId);
if (task == null) {
......
......@@ -32,9 +32,9 @@ import org.activiti.engine.runtime.ProcessInstance;
public class SubmitStartFormCmd implements Command<ProcessInstance> {
protected String processDefinitionId;
protected Map<String, Object> properties;
protected Map<String, String> properties;
public SubmitStartFormCmd(String processDefinitionId, Map<String, Object> properties) {
public SubmitStartFormCmd(String processDefinitionId, Map<String, String> properties) {
this.processDefinitionId = processDefinitionId;
this.properties = properties;
}
......@@ -51,7 +51,7 @@ public class SubmitStartFormCmd implements Command<ProcessInstance> {
try {
VariableMap.setExternalUpdate(Boolean.TRUE);
processInstance = startFormHandler.submitStartForm(processDefinition, properties);
processInstance = startFormHandler.submitStartFormData(processDefinition, properties);
} finally {
VariableMap.setExternalUpdate(null);
......
......@@ -30,9 +30,9 @@ import org.activiti.engine.impl.task.TaskEntity;
public class SubmitTaskFormCmd implements Command<Object> {
protected String taskId;
protected Map<String, Object> properties;
protected Map<String, String> properties;
public SubmitTaskFormCmd(String taskId, Map<String, Object> properties) {
public SubmitTaskFormCmd(String taskId, Map<String, String> properties) {
this.taskId = taskId;
this.properties = properties;
}
......@@ -54,11 +54,13 @@ public class SubmitTaskFormCmd implements Command<Object> {
try {
VariableMap.setExternalUpdate(Boolean.TRUE);
taskFormHandler.submitTaskForm(task, properties);
taskFormHandler.submitTaskFormData(task, properties);
} finally {
VariableMap.setExternalUpdate(null);
}
task.complete();
return null;
}
......
......@@ -25,8 +25,8 @@ import org.activiti.pvm.impl.runtime.ExecutionImpl;
*/
public class ActivitiValueExpression {
ValueExpression valueExpression;
ExpressionManager expressionManager;
protected ValueExpression valueExpression;
protected ExpressionManager expressionManager;
public ActivitiValueExpression(ValueExpression valueExpression, ExpressionManager expressionManager) {
this.valueExpression = valueExpression;
......
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.impl.form;
import org.activiti.engine.form.FormType;
/**
* @author Tom Baeyens
*/
public abstract class AbstractFormType implements FormType {
public abstract Object convertFormValueToModelValue(String propertyValue);
public abstract String convertModelValueToFormValue(Object modelValue);
public Object getInformation(String key) {
return null;
}
}
......@@ -13,53 +13,52 @@
package org.activiti.engine.impl.form;
import org.activiti.engine.impl.el.ActivitiMethodExpression;
import org.activiti.engine.impl.el.ActivitiValueExpression;
import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.activiti.engine.ActivitiException;
/**
* @author Tom Baeyens
*/
public class FormDisplayProperty {
protected String srcVariable;
protected ActivitiValueExpression srcValueExpression;
protected ActivitiMethodExpression srcMethodExpression;
protected String destProperty;
public String getSrcVariable() {
return srcVariable;
}
public class DateFormType extends AbstractFormType {
public void setSrcVariable(String srcVariable) {
this.srcVariable = srcVariable;
}
public String getDestProperty() {
return destProperty;
}
public void setDestProperty(String destProperty) {
this.destProperty = destProperty;
}
protected String pattern;
protected Format dateFormat;
public DateFormType(String simpleDateFormatPattern) {
this.pattern = simpleDateFormatPattern;
this.dateFormat = new SimpleDateFormat(simpleDateFormatPattern);
}
public ActivitiValueExpression getSrcValueExpression() {
return srcValueExpression;
public String getName() {
return "date";
}
public void setSrcValueExpression(ActivitiValueExpression srcValueExpression) {
this.srcValueExpression = srcValueExpression;
public Object getInformation(String key) {
if ("pattern".equals(key)) {
return pattern;
}
return null;
}
public ActivitiMethodExpression getSrcMethodExpression() {
return srcMethodExpression;
public Object convertFormValueToModelValue(String propertyValue) {
if (propertyValue==null || "".equals(propertyValue)) {
return null;
}
try {
return dateFormat.parseObject(propertyValue);
} catch (ParseException e) {
throw new ActivitiException("invalid date value "+propertyValue);
}
}
public void setSrcMethodExpression(ActivitiMethodExpression srcMethodExpression) {
this.srcMethodExpression = srcMethodExpression;
public String convertModelValueToFormValue(Object modelValue) {
if (modelValue==null) {
return null;
}
return dateFormat.format(modelValue);
}
}
......@@ -13,14 +13,19 @@
package org.activiti.engine.impl.form;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.activiti.engine.form.FormProperty;
import org.activiti.engine.impl.bpmn.parser.BpmnParse;
import org.activiti.engine.impl.bpmn.parser.BpmnParser;
import org.activiti.engine.impl.el.ActivitiMethodExpression;
import org.activiti.engine.impl.el.ActivitiValueExpression;
import org.activiti.engine.impl.el.ExpressionManager;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.repository.DeploymentEntity;
import org.activiti.engine.impl.runtime.ExecutionEntity;
import org.activiti.engine.impl.util.xml.Element;
......@@ -31,44 +36,100 @@ public class DefaultFormHandler {
protected String formKey;
protected String deploymentId;
protected List<FormDisplayProperty> formDisplayProperties;
protected List<FormSubmitProperty> formSubmitProperties;
protected List<FormPropertyHandler> formPropertyHandlers = new ArrayList<FormPropertyHandler>();
public void parseConfiguration(DeploymentEntity deployment, Element activityElement) {
public void parseConfiguration(Element activityElement, DeploymentEntity deployment, BpmnParse bpmnParse) {
this.deploymentId = deployment.getId();
this.formKey = activityElement.attributeNS(BpmnParser.BPMN_EXTENSIONS_NS, "formKey");
Element extensionElement = activityElement.element("extensionElements");
if (extensionElement != null) {
List<Element> formDisplayPropertyElements = extensionElement.elementsNS(BpmnParser.BPMN_EXTENSIONS_NS, "formDisplay");
for (Element formDisplayPropertyElement : formDisplayPropertyElements) {
FormDisplayProperty formDisplayProperty = new FormDisplayProperty();
CommandContext commandContext = CommandContext.getCurrent();
ExpressionManager expressionManager = commandContext
.getProcessEngineConfiguration()
.getExpressionManager();
FormTypes formTypes = commandContext
.getProcessEngineConfiguration()
.getFormTypes();
List<Element> formPropertyElements = extensionElement.elementsNS(BpmnParser.BPMN_EXTENSIONS_NS, "formProperty");
for (Element formPropertyElement : formPropertyElements) {
FormPropertyHandler formProperty = new FormPropertyHandler();
String destProperty = formDisplayPropertyElement.attribute("destProperty");
formDisplayProperty.setDestProperty(destProperty);
String id = formPropertyElement.attribute("http://activiti.org/bpmn-extensions:id");
if (id==null) {
bpmnParse.addError("attribute 'id' is required", formPropertyElement);
}
formProperty.setId(id);
String srcVariable = formDisplayPropertyElement.attribute("srcVar");
formDisplayProperty.setSrcVariable(srcVariable);
String name = formPropertyElement.attribute("http://activiti.org/bpmn-extensions:name");
formProperty.setName(name);
ExpressionManager expressionManager = CommandContext
.getCurrent()
.getProcessEngineConfiguration()
.getExpressionManager();
AbstractFormType type = formTypes.parseFormPropertyType(formPropertyElement, bpmnParse);
formProperty.setType(type);
String requiredText = formPropertyElement.attribute("http://activiti.org/bpmn-extensions:required", "false");
Boolean required = bpmnParse.parseBooleanAttribute(requiredText);
if (required!=null) {
formProperty.setRequired(required);
} else {
bpmnParse.addError("attribute 'required' must be one of {on|yes|true|enabled|active|off|no|false|disabled|inactive}", formPropertyElement);
}
String readableText = formPropertyElement.attribute("readable", "true");
Boolean readable = bpmnParse.parseBooleanAttribute(readableText);
if (readable!=null) {
formProperty.setReadable(readable);
} else {
bpmnParse.addError("attribute 'readable' must be one of {on|yes|true|enabled|active|off|no|false|disabled|inactive}", formPropertyElement);
}
String srcValueExpressionText = formDisplayPropertyElement.attribute("srcValueExpr");
if (srcValueExpressionText!=null) {
ActivitiValueExpression srcValueExpression = expressionManager.createValueExpression(srcValueExpressionText);
formDisplayProperty.setSrcValueExpression(srcValueExpression);
String writableText = formPropertyElement.attribute("http://activiti.org/bpmn-extensions:writable", "true");
Boolean writable = bpmnParse.parseBooleanAttribute(writableText);
if (writable!=null) {
formProperty.setWritable(writable);
} else {
bpmnParse.addError("attribute 'writable' must be one of {on|yes|true|enabled|active|off|no|false|disabled|inactive}", formPropertyElement);
}
String srcMethodExpressionText = formDisplayPropertyElement.attribute("srcMethodExpr");
if (srcMethodExpressionText!=null) {
ActivitiMethodExpression srcMethodExpression = expressionManager.createMethodExpression(srcMethodExpressionText);
formDisplayProperty.setSrcMethodExpression(srcMethodExpression);
String variableName = formPropertyElement.attribute("http://activiti.org/bpmn-extensions:variable");
formProperty.setVariableName(variableName);
String valueExpressionText = formPropertyElement.attribute("http://activiti.org/bpmn-extensions:expression");
if (valueExpressionText!=null) {
ActivitiValueExpression valueExpression = expressionManager.createValueExpression(valueExpressionText);
formProperty.setVariableExpression(valueExpression);
}
formPropertyHandlers.add(formProperty);
}
}
}
protected void initializeFormProperties(FormDataImpl formData, ExecutionEntity execution) {
List<FormProperty> formProperties = new ArrayList<FormProperty>();
for (FormPropertyHandler formPropertyHandler: formPropertyHandlers) {
if (formPropertyHandler.isReadable()) {
FormProperty formProperty = formPropertyHandler.createFormProperty(execution);
formProperties.add(formProperty);
}
}
formData.setFormProperties(formProperties);
}
protected void submitFormProperties(Map<String, String> properties, ExecutionEntity execution) {
Map<String, String> propertiesCopy = new HashMap<String, String>(properties);
for (FormPropertyHandler formPropertyHandler: formPropertyHandlers) {
// submitFormProperty will remove all the keys which it takes care of
formPropertyHandler.submitFormProperty(execution, propertiesCopy);
}
for (String propertyId: propertiesCopy.keySet()) {
execution.setVariable(propertyId, propertiesCopy.get(propertyId));
}
}
// getters and setters //////////////////////////////////////////////////////
public String getFormKey() {
......@@ -87,19 +148,11 @@ public class DefaultFormHandler {
this.deploymentId = deploymentId;
}
public List<FormDisplayProperty> getFormDisplayProperties() {
return formDisplayProperties;
}
public void setFormDisplayProperties(List<FormDisplayProperty> formDisplayProperties) {
this.formDisplayProperties = formDisplayProperties;
}
public List<FormSubmitProperty> getFormSubmitProperties() {
return formSubmitProperties;
public List<FormPropertyHandler> getFormPropertyHandlers() {
return formPropertyHandlers;
}
public void setFormSubmitProperties(List<FormSubmitProperty> formSubmitProperties) {
this.formSubmitProperties = formSubmitProperties;
public void setFormPropertyHandlers(List<FormPropertyHandler> formPropertyHandlers) {
this.formPropertyHandlers = formPropertyHandlers;
}
}
......@@ -13,14 +13,11 @@
package org.activiti.engine.impl.form;
import java.util.List;
import java.util.Map;
import org.activiti.engine.form.StartForm;
import org.activiti.engine.impl.bpmn.parser.BpmnParser;
import org.activiti.engine.form.StartFormData;
import org.activiti.engine.impl.repository.ProcessDefinitionEntity;
import org.activiti.engine.impl.runtime.ExecutionEntity;
import org.activiti.engine.impl.util.xml.Element;
/**
......@@ -28,20 +25,17 @@ import org.activiti.engine.impl.util.xml.Element;
*/
public class DefaultStartFormHandler extends DefaultFormHandler implements StartFormHandler {
public StartForm createStartForm(ProcessDefinitionEntity processDefinition) {
StartFormImpl startForm = new StartFormImpl(formKey, deploymentId, processDefinition);
// TODO resolve display properties
return startForm;
public StartFormData createStartFormData(ProcessDefinitionEntity processDefinition) {
StartFormDataImpl startFormData = new StartFormDataImpl();
startFormData.setFormKey(formKey);
startFormData.setDeploymentId(deploymentId);
startFormData.setProcessDefinition(processDefinition);
return startFormData;
}
public ExecutionEntity submitStartForm(ProcessDefinitionEntity processDefinition, Map<String, Object> properties) {
public ExecutionEntity submitStartFormData(ProcessDefinitionEntity processDefinition, Map<String, String> properties) {
ExecutionEntity processInstance = processDefinition.createProcessInstance();
// TODO process submit properties
processInstance.setVariables(properties);
submitFormProperties(properties, processInstance);
return processInstance;
}
}
......@@ -15,7 +15,7 @@ package org.activiti.engine.impl.form;
import java.util.Map;
import org.activiti.engine.form.TaskForm;
import org.activiti.engine.form.TaskFormData;
import org.activiti.engine.impl.task.TaskEntity;
......@@ -25,12 +25,16 @@ import org.activiti.engine.impl.task.TaskEntity;
*/
public class DefaultTaskFormHandler extends DefaultFormHandler implements TaskFormHandler {
public TaskForm createTaskForm(TaskEntity task) {
return new TaskFormImpl(formKey, deploymentId, task);
public TaskFormData createTaskForm(TaskEntity task) {
TaskFormDataImpl taskFormData = new TaskFormDataImpl();
taskFormData.setFormKey(formKey);
taskFormData.setDeploymentId(deploymentId);
taskFormData.setTask(task);
initializeFormProperties(taskFormData, task.getExecution());
return taskFormData;
}
public void submitTaskForm(TaskEntity task, Map<String, Object> properties) {
task.setExecutionVariables(properties);
task.complete();
public void submitTaskFormData(TaskEntity task, Map<String, String> properties) {
submitFormProperties(properties, task.getExecution());
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.impl.form;
import java.util.List;
import java.util.Map;
/**
* @author Tom Baeyens
*/
public class EnumFormType extends AbstractFormType {
protected Map<String, String> values;
public EnumFormType(Map<String, String> values) {
this.values = values;
}
public String getName() {
return "enum";
}
@Override
public Object getInformation(String key) {
if (key.equals("values")) {
return values;
}
return null;
}
@Override
public Object convertFormValueToModelValue(String propertyValue) {
// TODO
return null;
}
@Override
public String convertModelValueToFormValue(Object modelValue) {
// TODO
return null;
}
}
......@@ -14,48 +14,46 @@
package org.activiti.engine.impl.form;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
import org.activiti.engine.form.Form;
import org.activiti.engine.form.FormData;
import org.activiti.engine.form.FormProperty;
/**
* @author Tom Baeyens
*/
public abstract class FormImpl implements Form, Serializable {
public abstract class FormDataImpl implements FormData, Serializable {
private static final long serialVersionUID = 1L;
protected String formKey;
protected String deploymentId;
protected Map<String, Object> properties = new HashMap<String, Object>();
protected List<FormProperty> formProperties = new ArrayList<FormProperty>();
public FormImpl(String formKey, String deploymentId) {
this.formKey = formKey;
this.deploymentId = deploymentId;
}
public Object getProperty(String propertyName) {
return properties.get(propertyName);
}
public void setProperty(String propertyName, Object propertyValue) {
properties.put(propertyName, propertyValue);
}
// getters and setters //////////////////////////////////////////////////////
public String getFormKey() {
return formKey;
}
public void setProperties(Map<String, Object> properties) {
this.properties = properties;
}
public Map<String, Object> getProperties() {
return properties;
}
public String getDeploymentId() {
return deploymentId;
}
public List<FormProperty> getFormProperties() {
return formProperties;
}
public void setFormKey(String formKey) {
this.formKey = formKey;
}
public void setDeploymentId(String deploymentId) {
this.deploymentId = deploymentId;
}
public void setFormProperties(List<FormProperty> formProperties) {
this.formProperties = formProperties;
}
}
......@@ -12,8 +12,8 @@
*/
package org.activiti.engine.impl.form;
import org.activiti.engine.form.StartForm;
import org.activiti.engine.form.TaskForm;
import org.activiti.engine.form.StartFormData;
import org.activiti.engine.form.TaskFormData;
/**
......@@ -21,7 +21,7 @@ import org.activiti.engine.form.TaskForm;
*/
public interface FormEngine {
Object renderStartForm(StartForm startForm);
Object renderTaskForm(TaskForm taskForm);
Object renderStartForm(StartFormData startForm);
Object renderTaskForm(TaskFormData taskForm);
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.impl.form;
import java.util.Map;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.form.FormProperty;
import org.activiti.engine.impl.el.ActivitiValueExpression;
import org.activiti.engine.impl.runtime.ExecutionEntity;
/**
* @author Tom Baeyens
*/
public class FormPropertyHandler {
protected String id;
protected String name;
protected AbstractFormType type;
protected boolean isReadable;
protected boolean isWritable;
protected boolean isRequired;
protected String variableName;
protected ActivitiValueExpression variableExpression;
public FormProperty createFormProperty(ExecutionEntity execution) {
FormPropertyImpl formProperty = new FormPropertyImpl(this);
Object modelValue = null;
if (variableName!=null) {
modelValue = execution.getVariable(variableName);
} else if (variableExpression!=null) {
modelValue = variableExpression.getValue(execution);
} else {
modelValue = execution.getVariable(id);
}
if (type!=null) {
String formValue = type.convertModelValueToFormValue(modelValue);
formProperty.setValue(formValue);
} else if (modelValue!=null) {
formProperty.setValue(modelValue.toString());
}
return formProperty;
}
public void submitFormProperty(ExecutionEntity execution, Map<String, String> properties) {
if (!isWritable && properties.containsKey(id)) {
throw new ActivitiException("form property '"+id+"' is not writable");
}
if (isRequired && !properties.containsKey(id)) {
throw new ActivitiException("form property '"+id+"' is required");
}
if (properties.containsKey(id)) {
String propertyValue = properties.remove(id);
Object modelValue;
if (type!=null) {
modelValue = type.convertFormValueToModelValue(propertyValue);
} else {
modelValue = propertyValue;
}
if (variableName!=null) {
execution.setVariable(variableName, modelValue);
} else if (variableExpression!=null) {
variableExpression.setValue(modelValue, execution);
} else {
execution.setVariable(id, modelValue);
}
}
}
// getters and setters //////////////////////////////////////////////////////
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public AbstractFormType getType() {
return type;
}
public void setType(AbstractFormType type) {
this.type = type;
}
public boolean isReadable() {
return isReadable;
}
public void setReadable(boolean isReadable) {
this.isReadable = isReadable;
}
public boolean isRequired() {
return isRequired;
}
public void setRequired(boolean isRequired) {
this.isRequired = isRequired;
}
public String getVariableName() {
return variableName;
}
public void setVariableName(String variableName) {
this.variableName = variableName;
}
public ActivitiValueExpression getVariableExpression() {
return variableExpression;
}
public void setVariableExpression(ActivitiValueExpression variableExpression) {
this.variableExpression = variableExpression;
}
public boolean isWritable() {
return isWritable;
}
public void setWritable(boolean isWritable) {
this.isWritable = isWritable;
}
}
......@@ -13,59 +13,62 @@
package org.activiti.engine.impl.form;
import java.util.List;
import org.activiti.engine.form.FormProperty;
import org.activiti.engine.form.FormType;
/**
* @author Tom Baeyens
*/
public class FormSubmitProperty {
protected String srcProperty;
protected String srcExpression;
protected String destVariable;
protected String destExpression;
protected List<String> ignoreProperties;
public String getSrcProperty() {
return srcProperty;
}
public class FormPropertyImpl implements FormProperty {
public void setSrcProperty(String srcProperty) {
this.srcProperty = srcProperty;
protected String id;
protected String name;
protected FormType type;
protected boolean isRequired;
protected boolean isReadable;
protected boolean isWritable;
protected String value;
public FormPropertyImpl(FormPropertyHandler formPropertyHandler) {
this.id = formPropertyHandler.getId();
this.name = formPropertyHandler.getName();
this.type = formPropertyHandler.getType();
this.isRequired = formPropertyHandler.isRequired();
this.isReadable = formPropertyHandler.isReadable();
this.isWritable = formPropertyHandler.isWritable();
}
public String getSrcExpression() {
return srcExpression;
public String getId() {
return id;
}
public void setSrcExpression(String srcExpression) {
this.srcExpression = srcExpression;
public String getName() {
return name;
}
public String getDestVariable() {
return destVariable;
public FormType getType() {
return type;
}
public void setDestVariable(String destVariable) {
this.destVariable = destVariable;
public String getValue() {
return value;
}
public String getDestExpression() {
return destExpression;
public boolean isRequired() {
return isRequired;
}
public void setDestExpression(String destExpression) {
this.destExpression = destExpression;
public boolean isReadable() {
return isReadable;
}
public List<String> getIgnoreProperties() {
return ignoreProperties;
public void setValue(String value) {
this.value = value;
}
public void setIgnoreProperties(List<String> ignoreProperties) {
this.ignoreProperties = ignoreProperties;
public boolean isWritable() {
return isWritable;
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.impl.form;
import java.util.HashMap;
import java.util.Map;
import org.activiti.engine.impl.bpmn.parser.BpmnParse;
import org.activiti.engine.impl.util.xml.Element;
/**
* @author Tom Baeyens
*/
public class FormTypes {
protected Map<String, AbstractFormType> formTypes = new HashMap<String, AbstractFormType>();
public void addFormType(AbstractFormType formType) {
formTypes.put(formType.getName(), formType);
}
public AbstractFormType parseFormPropertyType(Element formPropertyElement, BpmnParse bpmnParse) {
AbstractFormType formType = null;
String typeText = formPropertyElement.attribute("http://activiti.org/bpmn-extensions:type");
if (typeText!=null) {
formType = formTypes.get(typeText);
if (formType==null) {
if ("enum".equals(formType)) {
Map<String, String> values = new HashMap<String, String>();
for (Element valueElement: formPropertyElement.elements("value")) {
String valueId = valueElement.attribute("id");
String valueName = valueElement.attribute("name");
values.put(valueId, valueName);
}
formType = new EnumFormType(values);
} else {
bpmnParse.addError("unknown type '"+typeText+"'", formPropertyElement);
}
}
}
return formType;
}
}
......@@ -12,9 +12,9 @@
*/
package org.activiti.engine.impl.form;
import org.activiti.engine.form.Form;
import org.activiti.engine.form.StartForm;
import org.activiti.engine.form.TaskForm;
import org.activiti.engine.form.FormData;
import org.activiti.engine.form.StartFormData;
import org.activiti.engine.form.TaskFormData;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.repository.ResourceEntity;
import org.activiti.engine.impl.scripting.ScriptingEngines;
......@@ -26,7 +26,7 @@ import org.activiti.engine.impl.task.TaskEntity;
*/
public class JuelFormEngine implements FormEngine {
public Object renderStartForm(StartForm startForm) {
public Object renderStartForm(StartFormData startForm) {
if (startForm.getFormKey()==null) {
return null;
}
......@@ -36,7 +36,7 @@ public class JuelFormEngine implements FormEngine {
return scriptingEngines.evaluate(formTemplateString, ScriptingEngines.DEFAULT_SCRIPTING_LANGUAGE, null);
}
public Object renderTaskForm(TaskForm taskForm) {
public Object renderTaskForm(TaskFormData taskForm) {
if (taskForm.getFormKey()==null) {
return null;
}
......@@ -47,7 +47,7 @@ public class JuelFormEngine implements FormEngine {
return scriptingEngines.evaluate(formTemplateString, ScriptingEngines.DEFAULT_SCRIPTING_LANGUAGE, task.getExecution());
}
private String getFormTemplateString(Form formInstance, CommandContext commandContext) {
private String getFormTemplateString(FormData formInstance, CommandContext commandContext) {
String deploymentId = formInstance.getDeploymentId();
String formKey = formInstance.getFormKey();
......
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.impl.form;
/**
* @author Tom Baeyens
*/
public class LongFormType extends AbstractFormType {
public String getName() {
return "long";
}
public String getMimeType() {
return "plain/text";
}
public Object convertFormValueToModelValue(String propertyValue) {
if (propertyValue==null || "".equals(propertyValue)) {
return null;
}
return new Long(propertyValue);
}
public String convertModelValueToFormValue(Object modelValue) {
if (modelValue==null) {
return null;
}
return modelValue.toString();
}
}
......@@ -13,7 +13,7 @@
package org.activiti.engine.impl.form;
import org.activiti.engine.form.StartForm;
import org.activiti.engine.form.StartFormData;
import org.activiti.engine.impl.repository.ProcessDefinitionEntity;
import org.activiti.engine.repository.ProcessDefinition;
......@@ -21,20 +21,19 @@ import org.activiti.engine.repository.ProcessDefinition;
/**
* @author Tom Baeyens
*/
public class StartFormImpl extends FormImpl implements StartForm {
public class StartFormDataImpl extends FormDataImpl implements StartFormData {
private static final long serialVersionUID = 1L;
protected ProcessDefinition processDefinition;
public StartFormImpl(String formKey, String deploymentId, ProcessDefinitionEntity processDefinition) {
super(formKey, deploymentId);
this.processDefinition = processDefinition;
}
// getters and setters //////////////////////////////////////////////////////
public ProcessDefinition getProcessDefinition() {
return processDefinition;
}
public void setProcessDefinition(ProcessDefinition processDefinition) {
this.processDefinition = processDefinition;
}
}
......@@ -15,7 +15,8 @@ package org.activiti.engine.impl.form;
import java.util.Map;
import org.activiti.engine.form.StartForm;
import org.activiti.engine.form.StartFormData;
import org.activiti.engine.impl.bpmn.parser.BpmnParse;
import org.activiti.engine.impl.repository.DeploymentEntity;
import org.activiti.engine.impl.repository.ProcessDefinitionEntity;
import org.activiti.engine.impl.runtime.ExecutionEntity;
......@@ -27,7 +28,7 @@ import org.activiti.engine.impl.util.xml.Element;
*/
public interface StartFormHandler {
StartForm createStartForm(ProcessDefinitionEntity processDefinition);
ExecutionEntity submitStartForm(ProcessDefinitionEntity processDefinition, Map<String, Object> properties);
void parseConfiguration(DeploymentEntity deploymentEntity, Element startEventElement);
StartFormData createStartFormData(ProcessDefinitionEntity processDefinition);
ExecutionEntity submitStartFormData(ProcessDefinitionEntity processDefinition, Map<String, String> properties);
void parseConfiguration(Element startEventElement, DeploymentEntity deployment, BpmnParse bpmnParse);
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.impl.form;
/**
* @author Tom Baeyens
*/
public class StringFormType extends AbstractFormType {
public String getName() {
return "string";
}
public String getMimeType() {
return "text/plain";
}
public Object convertFormValueToModelValue(String propertyValue) {
return propertyValue;
}
public String convertModelValueToFormValue(Object modelValue) {
return (String) modelValue;
}
}
......@@ -13,26 +13,26 @@
package org.activiti.engine.impl.form;
import org.activiti.engine.form.TaskForm;
import org.activiti.engine.impl.task.TaskEntity;
import org.activiti.engine.form.TaskFormData;
import org.activiti.engine.task.Task;
/**
* @author Tom Baeyens
*/
public class TaskFormImpl extends FormImpl implements TaskForm {
public class TaskFormDataImpl extends FormDataImpl implements TaskFormData {
private static final long serialVersionUID = 1L;
protected Task task;
public TaskFormImpl(String formKey, String deploymentId, TaskEntity task) {
super(formKey, deploymentId);
this.task = task;
}
// getters and setters //////////////////////////////////////////////////////
public Task getTask() {
return task;
}
public void setTask(Task task) {
this.task = task;
}
}
......@@ -15,7 +15,8 @@ package org.activiti.engine.impl.form;
import java.util.Map;
import org.activiti.engine.form.TaskForm;
import org.activiti.engine.form.TaskFormData;
import org.activiti.engine.impl.bpmn.parser.BpmnParse;
import org.activiti.engine.impl.repository.DeploymentEntity;
import org.activiti.engine.impl.task.TaskEntity;
import org.activiti.engine.impl.util.xml.Element;
......@@ -26,8 +27,8 @@ import org.activiti.engine.impl.util.xml.Element;
*/
public interface TaskFormHandler {
TaskForm createTaskForm(TaskEntity task);
void submitTaskForm(TaskEntity task, Map<String, Object> properties);
void parseConfiguration(DeploymentEntity deploymentEntity, Element userTaskElement);
TaskFormData createTaskForm(TaskEntity task);
void submitTaskFormData(TaskEntity task, Map<String, String> properties);
void parseConfiguration(Element userTaskElement, DeploymentEntity deployment, BpmnParse bpmnParse);
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.test.forms;
import java.io.Serializable;
/**
* @author Tom Baeyens
*/
public class Address implements Serializable {
private static final long serialVersionUID = 1L;
private String street;
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
}
......@@ -13,11 +13,15 @@
package org.activiti.engine.test.forms;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.activiti.engine.form.StartForm;
import org.activiti.engine.form.TaskForm;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.form.FormProperty;
import org.activiti.engine.form.StartFormData;
import org.activiti.engine.form.TaskFormData;
import org.activiti.engine.impl.test.ActivitiInternalTestCase;
import org.activiti.engine.task.Task;
import org.activiti.engine.test.Deployment;
......@@ -32,21 +36,21 @@ public class FormsTest extends ActivitiInternalTestCase {
"org/activiti/engine/test/forms/FormsProcess.bpmn20.xml",
"org/activiti/engine/test/forms/start.form",
"org/activiti/engine/test/forms/task.form" })
public void testTaskFormsWithVacationRequestProcess() {
StartForm startForm = formService.getStartForm("FormsProcess:1");
public void testTaskFormPropertyDefaultsAndFormRendering() {
StartFormData startForm = formService.getStartFormData("FormsProcess:1");
assertNotNull(startForm);
assertEquals(deploymentId, startForm.getDeploymentId());
assertEquals("org/activiti/engine/test/forms/start.form", startForm.getFormKey());
assertEquals(new HashMap<String, Object>(), startForm.getProperties());
assertEquals(new ArrayList<FormProperty>(), startForm.getFormProperties());
assertEquals("FormsProcess:1", startForm.getProcessDefinition().getId());
Object renderedStartForm = formService.getRenderedStartForm("FormsProcess:1");
assertEquals("start form content", renderedStartForm);
Map<String, Object> properties = new HashMap<String, Object>();
Map<String, String> properties = new HashMap<String, String>();
properties.put("room", "5b");
properties.put("speaker", "Mike");
String processInstanceId = formService.submitStartForm("FormsProcess:1", properties).getId();
String processInstanceId = formService.submitStartFormData("FormsProcess:1", properties).getId();
Map<String, Object> expectedVariables = new HashMap<String, Object>();
expectedVariables.put("room", "5b");
......@@ -57,12 +61,96 @@ public class FormsTest extends ActivitiInternalTestCase {
Task task = taskService.createTaskQuery().singleResult();
String taskId = task.getId();
TaskForm taskForm = formService.getTaskForm(taskId);
TaskFormData taskForm = formService.getTaskFormData(taskId);
assertEquals(deploymentId, taskForm.getDeploymentId());
assertEquals("org/activiti/engine/test/forms/task.form", taskForm.getFormKey());
assertEquals(new HashMap<String, Object>(), taskForm.getProperties());
assertEquals(new ArrayList<FormProperty>(), taskForm.getFormProperties());
assertEquals(taskId, taskForm.getTask().getId());
assertEquals("Mike is speaking in room 5b", formService.getRenderedTaskForm(taskId));
properties = new HashMap<String, String>();
properties.put("room", "3f");
formService.submitTaskFormData(taskId, properties);
expectedVariables = new HashMap<String, Object>();
expectedVariables.put("room", "3f");
expectedVariables.put("speaker", "Mike");
variables = runtimeService.getVariables(processInstanceId);
assertEquals(expectedVariables, variables);
}
@Deployment
public void testFormPropertyHandling() {
Map<String, String> properties = new HashMap<String, String>();
properties.put("room", "5b"); // default
properties.put("speaker", "Mike"); // variable name mapping
properties.put("duration", "45"); // type conversion
String processInstanceId = formService.submitStartFormData("FormPropertyHandlingProcess:1", properties).getId();
Map<String, Object> expectedVariables = new HashMap<String, Object>();
expectedVariables.put("room", "5b");
expectedVariables.put("SpeakerName", "Mike");
expectedVariables.put("duration", new Long(45));
Map<String, Object> variables = runtimeService.getVariables(processInstanceId);
assertEquals(expectedVariables, variables);
Address address = new Address();
address.setStreet("broadway");
runtimeService.setVariable(processInstanceId, "address", address);
String taskId = taskService.createTaskQuery().singleResult().getId();
TaskFormData taskFormData = formService.getTaskFormData(taskId);
List<FormProperty> formProperties = taskFormData.getFormProperties();
FormProperty propertyRoom = formProperties.get(0);
assertEquals("room", propertyRoom.getId());
assertEquals("5b", propertyRoom.getValue());
FormProperty propertyDuration = formProperties.get(1);
assertEquals("duration", propertyDuration.getId());
assertEquals("45", propertyDuration.getValue());
FormProperty propertySpeaker = formProperties.get(2);
assertEquals("speaker", propertySpeaker.getId());
assertEquals("Mike", propertySpeaker.getValue());
FormProperty propertyStreet = formProperties.get(3);
assertEquals("street", propertyStreet.getId());
assertEquals("broadway", propertyStreet.getValue());
assertEquals(4, formProperties.size());
try {
formService.submitTaskFormData(taskId, new HashMap<String, String>());
fail("expected exception about required form property 'street'");
} catch (ActivitiException e) {
// OK
}
try {
properties = new HashMap<String, String>();
properties.put("speaker", "its not allowed to update speaker!");
formService.submitTaskFormData(taskId, properties);
fail("expected exception about a non writable form property 'speaker'");
} catch (ActivitiException e) {
// OK
}
properties = new HashMap<String, String>();
properties.put("street", "rubensstraat");
formService.submitTaskFormData(taskId, properties);
expectedVariables = new HashMap<String, Object>();
expectedVariables.put("room", "5b");
expectedVariables.put("SpeakerName", "Mike");
expectedVariables.put("duration", new Long(45));
variables = runtimeService.getVariables(processInstanceId);
address = (Address) variables.remove("address");
assertEquals("rubensstraat", address.getStreet());
assertEquals(expectedVariables, variables);
}
}
......@@ -50,14 +50,14 @@ public class TaskFormsTest extends ActivitiInternalTestCase {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
String processDefinitionId = processDefinition.getId();
assertEquals("org/activiti/examples/taskforms/request.form", formService.getStartForm(processDefinitionId).getFormKey());
assertEquals("org/activiti/examples/taskforms/request.form", formService.getStartFormData(processDefinitionId).getFormKey());
// Define variables that would be filled in through the form
Map<String, Object> formProperties = new HashMap<String, Object>();
Map<String, String> formProperties = new HashMap<String, String>();
formProperties.put("employeeName", "kermit");
formProperties.put("numberOfDays", "4");
formProperties.put("vacationMotivation", "I'm tired");
formService.submitStartForm("vacationRequest:1", formProperties);
formService.submitStartFormData("vacationRequest:1", formProperties);
// Management should now have a task assigned to them
Task task = taskService.createTaskQuery().candidateGroup("management").singleResult();
......
<?xml version="1.0" encoding="UTF-8" ?>
<definitions id="definitions"
targetNamespace="http://activiti.org/bpmn20"
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:activiti="http://activiti.org/bpmn-extensions">
<process id="FormPropertyHandlingProcess">
<startEvent id="start">
<extensionElements>
<activiti:formProperty activiti:id="speaker" activiti:variable="SpeakerName"/>
<activiti:formProperty activiti:id="duration" activiti:type="long"/>
</extensionElements>
</startEvent>
<sequenceFlow id="flow1" sourceRef="start" targetRef="task" />
<userTask id="task"
activiti:assignee="kermit">
<extensionElements>
<activiti:formProperty activiti:id="room" />
<activiti:formProperty activiti:id="duration" activiti:type="long"/>
<activiti:formProperty activiti:id="speaker" activiti:variable="SpeakerName" activiti:writable="false" />
<activiti:formProperty activiti:id="street" activiti:expression="#{address.street}" activiti:required="true" />
</extensionElements>
</userTask>
<sequenceFlow id='flow2' sourceRef='task' targetRef='wait' />
<receiveTask id="wait" />
</process>
</definitions>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册