All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xlrit.gears.engine.flowable.GearsFormHandlerHelper Maven / Gradle / Ivy

package com.xlrit.gears.engine.flowable;

import java.util.List;

import org.flowable.bpmn.model.FlowElement;
import org.flowable.bpmn.model.FormProperty;
import org.flowable.bpmn.model.StartEvent;
import org.flowable.bpmn.model.UserTask;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.impl.form.*;
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;

import com.xlrit.gears.engine.form.GearsFormEngine;
import com.xlrit.gears.engine.form.GearsStartFormHandler;
import com.xlrit.gears.engine.form.GearsTaskFormHandler;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class GearsFormHandlerHelper extends FormHandlerHelper {

	private final GearsFormEngine formEngine;

	@Override
	public StartFormHandler getStartFormHandler(CommandContext commandContext, ProcessDefinition processDefinition) {
		FlowElement initialFlowElement = ProcessDefinitionUtil.getProcess(processDefinition.getId()).getInitialFlowElement();
		if (initialFlowElement instanceof StartEvent) {
			StartEvent startEvent = (StartEvent) initialFlowElement;

			List formProperties = startEvent.getFormProperties();
			String formKey = startEvent.getFormKey();
			DeploymentEntity deploymentEntity = CommandContextUtil.getDeploymentEntityManager(commandContext).findById(processDefinition.getDeploymentId());

			StartFormHandler startFormHandler = createStartFormHandler();
			startFormHandler.parseConfiguration(formProperties, formKey, deploymentEntity, processDefinition);
			return startFormHandler;
		}

		return null;
	}

	@Override
	public TaskFormHandler getTaskFormHandlder(String processDefinitionId, String taskId) {
		FlowElement flowElement = ProcessDefinitionUtil.getProcess(processDefinitionId).getFlowElement(taskId, true);
		if (flowElement instanceof UserTask) {
			UserTask userTask = (UserTask) flowElement;

			ProcessDefinition processDefinitionEntity = ProcessDefinitionUtil.getProcessDefinition(processDefinitionId);
			DeploymentEntity deploymentEntity = CommandContextUtil.getProcessEngineConfiguration()
				.getDeploymentEntityManager().findById(processDefinitionEntity.getDeploymentId());

			TaskFormHandler taskFormHandler = createTaskFormHandler();
			taskFormHandler.parseConfiguration(userTask.getFormProperties(), userTask.getFormKey(), deploymentEntity, processDefinitionEntity);
			return taskFormHandler;
		}

		return null;
	}

	@Override
	public TaskFormHandler getTaskFormHandlder(TaskEntity taskEntity) {
		if (taskEntity.getProcessDefinitionId() != null) {
			return getTaskFormHandlder(taskEntity.getProcessDefinitionId(), taskEntity.getTaskDefinitionKey());
		}
		return null;
	}

	protected StartFormHandler createStartFormHandler() {
		return new GearsStartFormHandler(formEngine);
	}

	protected TaskFormHandler createTaskFormHandler() {
		return new GearsTaskFormHandler(formEngine);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy