Skip to content

Commit

Permalink
Allow to override form handler lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarrez committed Jan 23, 2018
1 parent b5b3c6e commit 8b93c53
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 95 deletions.
Expand Up @@ -173,6 +173,7 @@
import org.flowable.engine.impl.form.DateFormType;
import org.flowable.engine.impl.form.DoubleFormType;
import org.flowable.engine.impl.form.FormEngine;
import org.flowable.engine.impl.form.FormHandlerHelper;
import org.flowable.engine.impl.form.FormTypes;
import org.flowable.engine.impl.form.JuelFormEngine;
import org.flowable.engine.impl.form.LongFormType;
Expand Down Expand Up @@ -469,6 +470,7 @@ public abstract class ProcessEngineConfigurationImpl extends ProcessEngineConfig
// HELPERS //////////////////////////////////////////////////////////////////
protected ProcessInstanceHelper processInstanceHelper;
protected ListenerNotificationHelper listenerNotificationHelper;
protected FormHandlerHelper formHandlerHelper;

// ASYNC EXECUTOR ///////////////////////////////////////////////////////////

Expand Down Expand Up @@ -1834,6 +1836,9 @@ public void initHelpers() {
if (listenerNotificationHelper == null) {
listenerNotificationHelper = new ListenerNotificationHelper();
}
if (formHandlerHelper == null) {
formHandlerHelper = new FormHandlerHelper();
}
}

public void initVariableTypes() {
Expand Down Expand Up @@ -2617,6 +2622,15 @@ public ProcessEngineConfigurationImpl setListenerNotificationHelper(ListenerNoti
this.listenerNotificationHelper = listenerNotificationHelper;
return this;
}

public FormHandlerHelper getFormHandlerHelper() {
return formHandlerHelper;
}

public ProcessEngineConfigurationImpl setFormHandlerHelper(FormHandlerHelper formHandlerHelper) {
this.formHandlerHelper = formHandlerHelper;
return this;
}

@Override
public ProcessEngineConfigurationImpl setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
Expand Down
Expand Up @@ -17,8 +17,9 @@
import org.flowable.engine.common.impl.interceptor.Command;
import org.flowable.engine.common.impl.interceptor.CommandContext;
import org.flowable.engine.impl.form.DefaultFormHandler;
import org.flowable.engine.impl.form.FormHandlerHelper;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.impl.util.Flowable5Util;
import org.flowable.engine.impl.util.FormHandlerUtil;
import org.flowable.engine.impl.util.ProcessDefinitionUtil;
import org.flowable.engine.repository.ProcessDefinition;

Expand Down Expand Up @@ -65,13 +66,14 @@ public String execute(CommandContext commandContext) {
return Flowable5Util.getFlowable5CompatibilityHandler().getFormKey(processDefinitionId, taskDefinitionKey);
}

FormHandlerHelper formHandlerHelper = CommandContextUtil.getProcessEngineConfiguration(commandContext).getFormHandlerHelper();
DefaultFormHandler formHandler;
if (taskDefinitionKey == null) {
// TODO: Maybe add getFormKey() to FormHandler interface to avoid the following cast
formHandler = (DefaultFormHandler) FormHandlerUtil.getStartFormHandler(commandContext, processDefinition);
formHandler = (DefaultFormHandler) formHandlerHelper.getStartFormHandler(commandContext, processDefinition);
} else {
// TODO: Maybe add getFormKey() to FormHandler interface to avoid the following cast
formHandler = (DefaultFormHandler) FormHandlerUtil.getTaskFormHandlder(processDefinitionId, taskDefinitionKey);
formHandler = (DefaultFormHandler) formHandlerHelper.getTaskFormHandlder(processDefinitionId, taskDefinitionKey);
}
String formKey = null;
if (formHandler.getFormKey() != null) {
Expand Down
Expand Up @@ -20,10 +20,10 @@
import org.flowable.engine.common.impl.interceptor.CommandContext;
import org.flowable.engine.form.StartFormData;
import org.flowable.engine.impl.form.FormEngine;
import org.flowable.engine.impl.form.FormHandlerHelper;
import org.flowable.engine.impl.form.StartFormHandler;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.impl.util.Flowable5Util;
import org.flowable.engine.impl.util.FormHandlerUtil;
import org.flowable.engine.repository.ProcessDefinition;

/**
Expand Down Expand Up @@ -53,7 +53,8 @@ public Object execute(CommandContext commandContext) {
return Flowable5Util.getFlowable5CompatibilityHandler().getRenderedStartForm(processDefinitionId, formEngineName);
}

StartFormHandler startFormHandler = FormHandlerUtil.getStartFormHandler(commandContext, processDefinition);
FormHandlerHelper formHandlerHelper = CommandContextUtil.getProcessEngineConfiguration(commandContext).getFormHandlerHelper();
StartFormHandler startFormHandler = formHandlerHelper.getStartFormHandler(commandContext, processDefinition);
if (startFormHandler == null) {
return null;
}
Expand Down
Expand Up @@ -22,9 +22,9 @@
import org.flowable.engine.common.impl.interceptor.CommandContext;
import org.flowable.engine.form.TaskFormData;
import org.flowable.engine.impl.form.FormEngine;
import org.flowable.engine.impl.form.FormHandlerHelper;
import org.flowable.engine.impl.form.TaskFormHandler;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.impl.util.FormHandlerUtil;
import org.flowable.task.api.Task;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;

Expand Down Expand Up @@ -55,7 +55,8 @@ public Object execute(CommandContext commandContext) {
throw new FlowableObjectNotFoundException("Task '" + taskId + "' not found", Task.class);
}

TaskFormHandler taskFormHandler = FormHandlerUtil.getTaskFormHandlder(task);
FormHandlerHelper formHandlerHelper = CommandContextUtil.getProcessEngineConfiguration(commandContext).getFormHandlerHelper();
TaskFormHandler taskFormHandler = formHandlerHelper.getTaskFormHandlder(task);
if (taskFormHandler != null) {

FormEngine formEngine = CommandContextUtil.getProcessEngineConfiguration(commandContext).getFormEngines().get(formEngineName);
Expand Down
Expand Up @@ -20,10 +20,10 @@
import org.flowable.engine.common.impl.interceptor.Command;
import org.flowable.engine.common.impl.interceptor.CommandContext;
import org.flowable.engine.form.StartFormData;
import org.flowable.engine.impl.form.FormHandlerHelper;
import org.flowable.engine.impl.form.StartFormHandler;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.impl.util.Flowable5Util;
import org.flowable.engine.impl.util.FormHandlerUtil;
import org.flowable.engine.repository.ProcessDefinition;

/**
Expand All @@ -49,7 +49,8 @@ public StartFormData execute(CommandContext commandContext) {
return Flowable5Util.getFlowable5CompatibilityHandler().getStartFormData(processDefinitionId);
}

StartFormHandler startFormHandler = FormHandlerUtil.getStartFormHandler(commandContext, processDefinition);
FormHandlerHelper formHandlerHelper = CommandContextUtil.getProcessEngineConfiguration(commandContext).getFormHandlerHelper();
StartFormHandler startFormHandler = formHandlerHelper.getStartFormHandler(commandContext, processDefinition);
if (startFormHandler == null) {
throw new FlowableException("No startFormHandler defined in process '" + processDefinitionId + "'");
}
Expand Down
Expand Up @@ -20,9 +20,9 @@
import org.flowable.engine.common.impl.interceptor.Command;
import org.flowable.engine.common.impl.interceptor.CommandContext;
import org.flowable.engine.form.TaskFormData;
import org.flowable.engine.impl.form.FormHandlerHelper;
import org.flowable.engine.impl.form.TaskFormHandler;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.impl.util.FormHandlerUtil;
import org.flowable.task.api.Task;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;

Expand All @@ -46,7 +46,8 @@ public TaskFormData execute(CommandContext commandContext) {
throw new FlowableObjectNotFoundException("No task found for taskId '" + taskId + "'", Task.class);
}

TaskFormHandler taskFormHandler = FormHandlerUtil.getTaskFormHandlder(task);
FormHandlerHelper formHandlerHelper = CommandContextUtil.getProcessEngineConfiguration(commandContext).getFormHandlerHelper();
TaskFormHandler taskFormHandler = formHandlerHelper.getTaskFormHandlder(task);
if (taskFormHandler == null) {
throw new FlowableException("No taskFormHandler specified for task '" + taskId + "'");
}
Expand Down
Expand Up @@ -18,12 +18,12 @@

import org.flowable.engine.common.impl.interceptor.CommandContext;
import org.flowable.engine.compatibility.Flowable5CompatibilityHandler;
import org.flowable.engine.impl.form.FormHandlerHelper;
import org.flowable.engine.impl.form.StartFormHandler;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.impl.persistence.entity.ProcessDefinitionEntity;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.impl.util.Flowable5Util;
import org.flowable.engine.impl.util.FormHandlerUtil;
import org.flowable.engine.impl.util.ProcessInstanceHelper;
import org.flowable.engine.runtime.ProcessInstance;

Expand Down Expand Up @@ -63,7 +63,8 @@ protected ProcessInstance execute(CommandContext commandContext, ProcessDefiniti

CommandContextUtil.getHistoryManager(commandContext).recordFormPropertiesSubmitted(processInstance.getExecutions().get(0), properties, null);

StartFormHandler startFormHandler = FormHandlerUtil.getStartFormHandler(commandContext, processDefinition);
FormHandlerHelper formHandlerHelper = CommandContextUtil.getProcessEngineConfiguration(commandContext).getFormHandlerHelper();
StartFormHandler startFormHandler = formHandlerHelper.getStartFormHandler(commandContext, processDefinition);
startFormHandler.submitFormProperties(properties, processInstance);

processInstanceHelper.startProcessInstance(processInstance, commandContext, convertPropertiesToVariablesMap());
Expand Down
Expand Up @@ -17,11 +17,11 @@

import org.flowable.engine.common.impl.interceptor.CommandContext;
import org.flowable.engine.compatibility.Flowable5CompatibilityHandler;
import org.flowable.engine.impl.form.FormHandlerHelper;
import org.flowable.engine.impl.form.TaskFormHandler;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.impl.util.Flowable5Util;
import org.flowable.engine.impl.util.FormHandlerUtil;
import org.flowable.engine.impl.util.TaskHelper;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;

Expand Down Expand Up @@ -59,7 +59,8 @@ protected Void execute(CommandContext commandContext, TaskEntity task) {
ExecutionEntity executionEntity = CommandContextUtil.getExecutionEntityManager().findById(task.getExecutionId());
CommandContextUtil.getHistoryManager(commandContext).recordFormPropertiesSubmitted(executionEntity, properties, taskId);

TaskFormHandler taskFormHandler = FormHandlerUtil.getTaskFormHandlder(task);
FormHandlerHelper formHandlerHelper = CommandContextUtil.getProcessEngineConfiguration(commandContext).getFormHandlerHelper();
TaskFormHandler taskFormHandler = formHandlerHelper.getTaskFormHandlder(task);

if (taskFormHandler != null) {
taskFormHandler.submitFormProperties(properties, executionEntity);
Expand Down
Expand Up @@ -10,7 +10,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.flowable.engine.impl.util;
package org.flowable.engine.impl.form;

import java.util.List;

Expand All @@ -19,20 +19,18 @@
import org.flowable.bpmn.model.StartEvent;
import org.flowable.bpmn.model.UserTask;
import org.flowable.engine.common.impl.interceptor.CommandContext;
import org.flowable.engine.impl.form.DefaultStartFormHandler;
import org.flowable.engine.impl.form.DefaultTaskFormHandler;
import org.flowable.engine.impl.form.StartFormHandler;
import org.flowable.engine.impl.form.TaskFormHandler;
import org.flowable.engine.impl.persistence.entity.DeploymentEntity;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.impl.util.ProcessDefinitionUtil;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;

/**
* @author Joram Barrez
*/
public class FormHandlerUtil {
public class FormHandlerHelper {

public static StartFormHandler getStartFormHandler(CommandContext commandContext, ProcessDefinition processDefinition) {
public StartFormHandler getStartFormHandler(CommandContext commandContext, ProcessDefinition processDefinition) {
StartFormHandler startFormHandler = new DefaultStartFormHandler();
org.flowable.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(processDefinition.getId());

Expand All @@ -53,7 +51,7 @@ public static StartFormHandler getStartFormHandler(CommandContext commandContext

}

public static TaskFormHandler getTaskFormHandlder(String processDefinitionId, String taskId) {
public TaskFormHandler getTaskFormHandlder(String processDefinitionId, String taskId) {
org.flowable.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(processDefinitionId);
FlowElement flowElement = process.getFlowElement(taskId, true);
if (flowElement instanceof UserTask) {
Expand All @@ -72,7 +70,7 @@ public static TaskFormHandler getTaskFormHandlder(String processDefinitionId, St
return null;
}

public static TaskFormHandler getTaskFormHandlder(TaskEntity taskEntity) {
public TaskFormHandler getTaskFormHandlder(TaskEntity taskEntity) {
if (taskEntity.getProcessDefinitionId() != null) {
return getTaskFormHandlder(taskEntity.getProcessDefinitionId(), taskEntity.getTaskDefinitionKey());
}
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 8b93c53

Please sign in to comment.