Search in sources :

Example 31 with TaskService

use of org.activiti.engine.TaskService in project midpoint by Evolveum.

the class WorkItemProvider method getWorkItem.

public WorkItemType getWorkItem(String workItemId, OperationResult result) {
    TaskService ts = activitiEngine.getTaskService();
    Task task = ts.createTaskQuery().taskId(workItemId).includeTaskLocalVariables().includeProcessVariables().singleResult();
    return taskToWorkItem(task, null, false, false, false, false, result);
}
Also used : Task(org.activiti.engine.task.Task) TaskService(org.activiti.engine.TaskService)

Example 32 with TaskService

use of org.activiti.engine.TaskService in project midpoint by Evolveum.

the class ProcessInstanceManager method cleanupActivitiProcesses.

public void cleanupActivitiProcesses(OperationResult result) throws SchemaException {
    RuntimeService runtimeService = activitiEngine.getRuntimeService();
    TaskService taskService = activitiEngine.getTaskService();
    LOGGER.info("Starting cleanup of Activiti processes");
    Collection<String> processInstancesToKeep = getProcessInstancesToKeep(result);
    LOGGER.info("Process instances to keep: {}", processInstancesToKeep);
    List<ProcessInstance> instances = runtimeService.createProcessInstanceQuery().list();
    LOGGER.info("Existing process instances in Activiti: {}", instances.size());
    int ok = 0, fail = 0;
    for (ProcessInstance instance : instances) {
        String instanceId = instance.getId();
        if (processInstancesToKeep.contains(instanceId)) {
            continue;
        }
        LOGGER.debug("Deleting process instance {}", instance);
        try {
            runtimeService.setVariable(instanceId, CommonProcessVariableNames.VARIABLE_PROCESS_INSTANCE_IS_STOPPING, Boolean.TRUE);
            runtimeService.deleteProcessInstance(instanceId, "Deleted as part of activiti processes cleanup");
            ok++;
        } catch (Throwable t) {
            LOGGER.info("Couldn't delete process instance {}, retrying with explicit deletion of some variables for its tasks", instanceId);
            List<org.activiti.engine.task.Task> tasks = taskService.createTaskQuery().processInstanceId(instanceId).list();
            LOGGER.debug("Tasks: {}", tasks);
            for (org.activiti.engine.task.Task task : tasks) {
                taskService.removeVariables(task.getId(), Arrays.asList("approvalSchema", "level"));
            }
            try {
                runtimeService.deleteProcessInstance(instanceId, "Deleted as part of activiti processes cleanup");
                ok++;
            } catch (Throwable t2) {
                result.createSubresult(ProcessInstanceManager.class.getName() + ".cleanupActivitiProcess").recordPartialError("Couldn't delete Activiti process instance " + instanceId + ": " + t2.getMessage(), t2);
                fail++;
            }
        }
    }
    String message = "Successfully deleted " + ok + " instances; failed " + fail + " times";
    LOGGER.info(message);
    result.recordStatus(fail > 0 ? OperationResultStatus.PARTIAL_ERROR : OperationResultStatus.SUCCESS, message);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) RuntimeService(org.activiti.engine.RuntimeService) TaskService(org.activiti.engine.TaskService) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) SearchResultList(com.evolveum.midpoint.schema.SearchResultList)

Example 33 with TaskService

use of org.activiti.engine.TaskService in project crnk-framework by crnk-project.

the class ApprovalManagerTest method setup.

@Before
public void setup() {
    runtimeService = Mockito.mock(RuntimeService.class);
    TaskService taskService = Mockito.mock(TaskService.class);
    repositoryFacade = Mockito.mock(ResourceRepositoryV2.class);
    ApprovalMapper approvalMapper = new ApprovalMapper();
    ActivitiResourceMapper resourceMapper = new ActivitiResourceMapper(new TypeParser(), new DefaultDateTimeMapper());
    ResourceInformation information = Mockito.mock(ResourceInformation.class);
    registryEntry = Mockito.mock(RegistryEntry.class);
    ResourceRegistry resourceRegistry = Mockito.mock(ResourceRegistry.class);
    Mockito.when(registryEntry.getResourceInformation()).thenReturn(information);
    Mockito.when(registryEntry.getResourceRepositoryFacade()).thenReturn(repositoryFacade);
    Mockito.when(information.getResourceType()).thenReturn("schedule");
    Mockito.when(information.getId(Mockito.any())).thenReturn(mockId);
    Mockito.when(resourceRegistry.getEntry(Mockito.any(Class.class))).thenReturn(registryEntry);
    Mockito.when(resourceRegistry.getEntry(Mockito.any(String.class))).thenReturn(registryEntry);
    ModuleRegistry moduleRegistry = Mockito.mock(ModuleRegistry.class);
    Mockito.when(moduleRegistry.getResourceRegistry()).thenReturn(resourceRegistry);
    originalResource = new Schedule();
    originalResource.setId(mockId);
    originalResource.setName("Jane");
    Mockito.when(repositoryFacade.findOne(Mockito.any(Long.class), Mockito.any(QuerySpec.class))).thenReturn(originalResource);
    manager = new ApprovalManager();
    manager.init(runtimeService, taskService, resourceMapper, approvalMapper, moduleRegistry);
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) TypeParser(io.crnk.core.engine.parser.TypeParser) RuntimeService(org.activiti.engine.RuntimeService) ActivitiResourceMapper(io.crnk.activiti.mapper.ActivitiResourceMapper) TaskService(org.activiti.engine.TaskService) DefaultDateTimeMapper(io.crnk.activiti.mapper.DefaultDateTimeMapper) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRepositoryV2(io.crnk.core.repository.ResourceRepositoryV2) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) ApprovalManager(io.crnk.activiti.example.approval.ApprovalManager) Schedule(io.crnk.test.mock.models.Schedule) QuerySpec(io.crnk.core.queryspec.QuerySpec) ApprovalMapper(io.crnk.activiti.example.approval.ApprovalMapper) Before(org.junit.Before)

Example 34 with TaskService

use of org.activiti.engine.TaskService in project carbon-business-process by wso2.

the class BPMNHumanTasksService method getTasksOfUser.

public BPMNTask[] getTasksOfUser(String username) throws BPSFault {
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
    TaskService taskService = engine.getTaskService();
    List<Task> tasks = taskService.createTaskQuery().taskTenantId(tenantId.toString()).taskAssignee(username).list();
    BPMNTask[] bpmnTasks = new BPMNTask[tasks.size() + 1];
    int i = 0;
    for (Task t : tasks) {
        BPMNTask bpmnTask = new BPMNTask();
        bpmnTask.setId(t.getId());
        bpmnTask.setName(t.getName());
        bpmnTask.setProcessInstanceId(t.getProcessInstanceId());
        bpmnTasks[i] = bpmnTask;
        i++;
    }
    return bpmnTasks;
}
Also used : Task(org.activiti.engine.task.Task) BPMNTask(org.wso2.carbon.bpmn.core.mgt.model.BPMNTask) TaskService(org.activiti.engine.TaskService) BPMNTask(org.wso2.carbon.bpmn.core.mgt.model.BPMNTask) ProcessEngine(org.activiti.engine.ProcessEngine)

Example 35 with TaskService

use of org.activiti.engine.TaskService in project Activiti by Activiti.

the class ActivitiRuleJunit4Test method ruleUsageExample.

@Test
@Deployment
public void ruleUsageExample() {
    RuntimeService runtimeService = activitiRule.getRuntimeService();
    runtimeService.startProcessInstanceByKey("ruleUsage");
    TaskService taskService = activitiRule.getTaskService();
    Task task = taskService.createTaskQuery().singleResult();
    assertThat(task.getName()).isEqualTo("My Task");
    taskService.complete(task.getId());
    assertThat(runtimeService.createProcessInstanceQuery().count()).isEqualTo(0);
}
Also used : Task(org.activiti.engine.task.Task) RuntimeService(org.activiti.engine.RuntimeService) TaskService(org.activiti.engine.TaskService) Test(org.junit.Test) Deployment(org.activiti.engine.test.Deployment)

Aggregations

TaskService (org.activiti.engine.TaskService)38 Task (org.activiti.engine.task.Task)25 Test (org.junit.Test)15 RuntimeService (org.activiti.engine.RuntimeService)10 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)10 ProcessEngine (org.activiti.engine.ProcessEngine)6 WorkflowDefinition (org.activiti.workflow.simple.definition.WorkflowDefinition)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 HashMap (java.util.HashMap)5 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)4 StandaloneProcessEngineConfiguration (org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration)4 ObjectTypeUtil.toShortString (com.evolveum.midpoint.schema.util.ObjectTypeUtil.toShortString)3 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 ArrayList (java.util.ArrayList)3 RepositoryService (org.activiti.engine.RepositoryService)3 Task (com.evolveum.midpoint.task.api.Task)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 ExternalResource (com.vaadin.terminal.ExternalResource)2