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

com.github.egatlovs.variablemanager.managers.TaskManager Maven / Gradle / Ivy

package com.github.egatlovs.variablemanager.managers;

import com.github.egatlovs.variablemanager.processing.FieldNames;
import com.github.egatlovs.variablemanager.processing.ProcessingUnit;
import com.github.egatlovs.variablemanager.processing.ResultObject;
import com.github.egatlovs.variablemanager.validation.VariableValidator;
import org.camunda.bpm.engine.TaskService;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * TaskManager
*
* TaskManager wraps a TaskService and offers methods to set, get and remove * variables based of an ExecutionEntity.
* The Manager itself uses BeanValidation on each given Object, so you can * simply annotate your ExecutionEntities with the well known BeanValidation * annotations.
*
* The TaskManager is injectable. If you inject it in your bean it will * initialize itself with the TaskManager provided in the environment. * * @author egatlovs */ @SuppressWarnings("CdiInjectionPointsInspection") @RequestScoped public class TaskManager implements TaskVariableManager { @Inject private TaskService taskService; /** * Constructor defining the taskService to be used. * * @param taskService - The taskService to be used */ public TaskManager(TaskService taskService) { this.taskService = taskService; } public TaskManager() { } @Override public void setVariable(Object value, String taskid) { VariableValidator.validate(value); ProcessingUnit punit = new ProcessingUnit(); Map variables = punit.getVariables(value); this.taskService.setVariables(taskid, variables); } @Override public void setVariableLocal(Object value, String taskid) { VariableValidator.validate(value); ProcessingUnit punit = new ProcessingUnit(); Map variables = punit.getVariables(value); this.taskService.setVariables(taskid, variables); } @Override public T getVariable(Class clazz, String taskid) { Set variableNames = new FieldNames().getNames(clazz); Map variables = new HashMap<>(); for (String name : variableNames) { variables.put(name, this.taskService.getVariable(taskid, name)); } return new ResultObject().getValue(clazz, variables); } @Override public T getVariableLocal(Class clazz, String taskid) { Set variableNames = new FieldNames().getNames(clazz); Map variables = new HashMap<>(); for (String name : variableNames) { variables.put(name, this.taskService.getVariableLocal(taskid, name)); } return new ResultObject().getValue(clazz, variables); } @Override public void removeVariables(Class clazz, String taskid) { Set variableNames = new FieldNames().getNames(clazz); this.taskService.removeVariables(taskid, variableNames); } @Override public void removeVariablesLocal(Class clazz, String taskid) { Set variableNames = new FieldNames().getNames(clazz); this.taskService.removeVariablesLocal(taskid, variableNames); } @Override public TaskService getExecutionService() { return taskService; } @Override public void setExecutionService(TaskService taskService) { this.taskService = taskService; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy