Search in sources :

Example 31 with RuntimeManager

use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.

the class UserTaskServiceImpl method execute.

@Override
public <T> T execute(String deploymentId, Command<T> command) {
    Long processInstanceId = CommonUtils.getProcessInstanceId(command);
    RuntimeManager manager = getRuntimeManager(deploymentId, command);
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
    try {
        TaskService taskService = engine.getTaskService();
        // perform actual operation
        return taskService.execute(command);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager)

Example 32 with RuntimeManager

use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.

the class UserTaskServiceImpl method getRuntimeManager.

protected RuntimeManager getRuntimeManager(String deploymentId, Command<?> command) {
    if (deploymentId == null && command instanceof TaskCommand<?>) {
        Long taskId = ((TaskCommand<?>) command).getTaskId();
        if (taskId != null) {
            UserTaskInstanceDesc task = dataService.getTaskById(taskId);
            deploymentId = task.getDeploymentId();
        }
    }
    RuntimeManager manager = deploymentService.getRuntimeManager(deploymentId);
    if (manager == null) {
        InternalTaskService internalTaskService = getInternalTaskService();
        if (internalTaskService != null) {
            manager = new FalbackRuntimeManager(internalTaskService);
        } else {
            logger.warn("Cannot find runtime manager for deployment {}", deploymentId);
            throw new RuntimeException("No runtime manager found for deployment " + deploymentId);
        }
    }
    return manager;
}
Also used : RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) TaskCommand(org.jbpm.services.task.commands.TaskCommand) UpdateTaskCommand(org.jbpm.kie.services.impl.admin.commands.UpdateTaskCommand)

Example 33 with RuntimeManager

use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.

the class UserTaskServiceImpl method getCommentById.

@Override
public Comment getCommentById(String deploymentId, Long taskId, Long commentId) {
    UserTaskInstanceDesc task = dataService.getTaskById(taskId);
    validateTask(deploymentId, taskId, task);
    RuntimeManager manager = getRuntimeManager(task);
    if (manager == null) {
        logger.warn("Cannot find runtime manager for task {}", taskId);
        return null;
    }
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
    try {
        TaskService taskService = engine.getTaskService();
        // perform actual operation
        return ((InternalTaskService) taskService).getCommentById(commentId);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc)

Example 34 with RuntimeManager

use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.

the class UserTaskAdminServiceImpl method acknowledgeError.

@Override
public void acknowledgeError(String... errorId) throws ExecutionErrorNotFoundException {
    for (String error : errorId) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("errorId", error);
        params.put("ack", new Short("0"));
        List<ExecutionError> execErrors = commandService.execute(new QueryNameCommand<List<ExecutionError>>("getErrorById", params));
        if (execErrors.isEmpty()) {
            throw new ExecutionErrorNotFoundException("No execution error found for id " + errorId);
        }
        ExecutionError errorInstance = execErrors.get(0);
        RuntimeManager runtimeManager = RuntimeManagerRegistry.get().getManager(errorInstance.getDeploymentId());
        if (runtimeManager != null) {
            ((AbstractRuntimeManager) runtimeManager).getExecutionErrorManager().getStorage().acknowledge(identityProvider.getName(), errorInstance.getErrorId());
        }
    }
}
Also used : ExecutionError(org.kie.internal.runtime.error.ExecutionError) HashMap(java.util.HashMap) ExecutionErrorNotFoundException(org.jbpm.services.api.admin.ExecutionErrorNotFoundException) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) ArrayList(java.util.ArrayList) List(java.util.List)

Example 35 with RuntimeManager

use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.

the class AsyncWorkItemHandlerCmdCallback method onCommandDone.

@Override
public void onCommandDone(CommandContext ctx, ExecutionResults results) {
    WorkItem workItem = (WorkItem) ctx.getData("workItem");
    logger.debug("About to complete work item {}", workItem);
    // find the right runtime to do the complete
    RuntimeManager manager = getRuntimeManager(ctx);
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get((Long) ctx.getData("processInstanceId")));
    try {
        engine.getKieSession().getWorkItemManager().completeWorkItem(workItem.getId(), results == null ? null : results.getData());
    } finally {
        manager.disposeRuntimeEngine(engine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) WorkItem(org.kie.api.runtime.process.WorkItem)

Aggregations

RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)150 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)116 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)79 KieSession (org.kie.api.runtime.KieSession)55 TaskService (org.kie.api.task.TaskService)53 Test (org.junit.Test)51 HashMap (java.util.HashMap)49 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)46 InternalTaskService (org.kie.internal.task.api.InternalTaskService)44 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)38 UserTaskService (org.jbpm.services.api.UserTaskService)36 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)35 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)23 TaskSummary (org.kie.api.task.model.TaskSummary)21 ArrayList (java.util.ArrayList)19 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)19 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)18 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)15 DeploymentUnit (org.jbpm.services.api.model.DeploymentUnit)15 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)15