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);
}
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);
}
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);
}
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;
}
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);
}
Aggregations