Search in sources :

Example 31 with InternalTaskService

use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.

the class HumanTaskResolver method populateOrgEntity.

@Before
public void populateOrgEntity() {
    TaskService taskService = HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(getEmf()).getTaskService();
    ((InternalTaskService) taskService).addUser(TaskModelProvider.getFactory().newUser("krisv"));
    ((InternalTaskService) taskService).addUser(TaskModelProvider.getFactory().newUser("sales-rep"));
    ((InternalTaskService) taskService).addUser(TaskModelProvider.getFactory().newUser("john"));
    ((InternalTaskService) taskService).addUser(TaskModelProvider.getFactory().newUser("Administrator"));
    ((InternalTaskService) taskService).addGroup(TaskModelProvider.getFactory().newGroup("sales"));
    ((InternalTaskService) taskService).addGroup(TaskModelProvider.getFactory().newGroup("PM"));
    ((InternalTaskService) taskService).addGroup(TaskModelProvider.getFactory().newGroup("Administrators"));
}
Also used : InternalTaskService(org.kie.internal.task.api.InternalTaskService) TaskService(org.kie.api.task.TaskService) InternalTaskService(org.kie.internal.task.api.InternalTaskService) Before(org.junit.Before)

Example 32 with InternalTaskService

use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.

the class PerCaseRuntimeManager method getRuntimeEngine.

@SuppressWarnings("unchecked")
@Override
public RuntimeEngine getRuntimeEngine(Context<?> context) {
    if (isClosed()) {
        throw new IllegalStateException("Runtime manager " + identifier + " is already closed");
    }
    checkPermission();
    RuntimeEngine runtime = null;
    Object contextId = context.getContextId();
    if (!(context instanceof ProcessInstanceIdContext || context instanceof CaseContext)) {
        logger.warn("ProcessInstanceIdContext or CaseContext shall be used when interacting with PerCase runtime manager");
    }
    if (engineInitEager) {
        KieSession ksession = null;
        Long ksessionId = null;
        RuntimeEngine localRuntime = findLocalRuntime(contextId);
        if (localRuntime != null) {
            return localRuntime;
        }
        synchronized (this) {
            ksessionId = mapper.findMapping(context, this.identifier);
            if (ksessionId == null) {
                ksession = factory.newKieSession();
                ksessionId = ksession.getIdentifier();
                if (context instanceof CaseContext) {
                    ksession.execute(new SaveMappingCommand(mapper, context, ksessionId, getIdentifier()));
                }
            } else {
                ksession = factory.findKieSessionById(ksessionId);
            }
        }
        InternalTaskService internalTaskService = newTaskService(taskServiceFactory);
        runtime = new RuntimeEngineImpl(ksession, internalTaskService);
        ((RuntimeEngineImpl) runtime).setManager(this);
        ((RuntimeEngineImpl) runtime).setContext(context);
        configureRuntimeOnTaskService(internalTaskService, runtime);
        registerDisposeCallback(runtime, new DisposeSessionTransactionSynchronization(this, runtime), ksession.getEnvironment());
        registerItems(runtime);
        attachManager(runtime);
        ksession.addEventListener(new MaintainMappingListener(ksessionId, runtime, this.identifier, (String) contextId));
        if (context instanceof CaseContext) {
            ksession.getEnvironment().set("CaseId", context.getContextId());
        } else {
            Object contexts = mapper.findContextId(ksession.getIdentifier(), this.identifier);
            if (contexts instanceof Collection) {
                RuntimeEngine finalRuntimeEngnie = runtime;
                KieSession finalKieSession = ksession;
                ((Collection<Object>) contexts).forEach(o -> {
                    try {
                        saveLocalRuntime(null, Long.parseLong(o.toString()), finalRuntimeEngnie);
                    } catch (NumberFormatException e) {
                        saveLocalRuntime(o.toString(), null, finalRuntimeEngnie);
                        finalKieSession.getEnvironment().set("CaseId", o.toString());
                    }
                });
            }
        }
    } else {
        RuntimeEngine localRuntime = findLocalRuntime(contextId);
        if (localRuntime != null) {
            return localRuntime;
        }
        // lazy initialization of ksession and task service
        runtime = new RuntimeEngineImpl(context, new PerCaseInitializer());
        ((RuntimeEngineImpl) runtime).setManager(this);
    }
    String caseId = null;
    Long processInstanceId = null;
    if (context instanceof CaseContext) {
        caseId = (String) contextId;
    } else if (context instanceof ProcessInstanceIdContext) {
        processInstanceId = (Long) contextId;
    }
    Long ksessionId = mapper.findMapping(context, this.identifier);
    createLockOnGetEngine(ksessionId, runtime);
    saveLocalRuntime(caseId, processInstanceId, runtime);
    return runtime;
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalTaskService(org.kie.internal.task.api.InternalTaskService) CaseContext(org.kie.internal.runtime.manager.context.CaseContext) ProcessInstanceIdContext(org.kie.internal.runtime.manager.context.ProcessInstanceIdContext) DisposeSessionTransactionSynchronization(org.jbpm.runtime.manager.impl.tx.DisposeSessionTransactionSynchronization) Collection(java.util.Collection) KieSession(org.kie.api.runtime.KieSession)

Example 33 with InternalTaskService

use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.

the class SupportProcessBaseTest method testSupportProcess.

@Test
public void testSupportProcess() {
    DeploymentUnit deploymentUnitSupport = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnitSupport);
    units.add(deploymentUnitSupport);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("customer", "polymita");
    RuntimeManager managerSupport = deploymentService.getRuntimeManager(deploymentUnitSupport.getIdentifier());
    assertNotNull(managerSupport);
    int currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
    assertEquals(0, currentNumberOfEvents);
    RuntimeEngine engine = managerSupport.getRuntimeEngine(EmptyContext.get());
    assertNotNull(engine);
    ProcessInstance pI = engine.getKieSession().startProcess("support.process", params);
    assertNotNull(pI);
    TaskService taskService = engine.getTaskService();
    currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
    assertEquals(2, currentNumberOfEvents);
    // Configure Release
    List<TaskSummary> tasksAssignedToSalaboy = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    assertEquals(1, tasksAssignedToSalaboy.size());
    assertEquals("Create Support", tasksAssignedToSalaboy.get(0).getName());
    TaskSummary createSupportTask = tasksAssignedToSalaboy.get(0);
    taskService.start(createSupportTask.getId(), "salaboy");
    currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
    assertEquals(4, currentNumberOfEvents);
    Map<String, Object> taskContent = ((InternalTaskService) taskService).getTaskContent(createSupportTask.getId());
    assertEquals("polymita", taskContent.get("input_customer"));
    Map<String, String> taskOutputMappings = bpmn2Service.getTaskOutputMappings(deploymentUnitSupport.getIdentifier(), "support.process", createSupportTask.getName());
    assertEquals(1, taskOutputMappings.size());
    assertEquals("output_customer", taskOutputMappings.keySet().iterator().next());
    Map<String, Object> output = new HashMap<String, Object>();
    output.put("output_customer", "polymita/redhat");
    taskService.complete(createSupportTask.getId(), "salaboy", output);
    currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
    assertEquals(8, currentNumberOfEvents);
    tasksAssignedToSalaboy = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    assertEquals(1, tasksAssignedToSalaboy.size());
    assertEquals("Resolve Support", tasksAssignedToSalaboy.get(0).getName());
    TaskSummary resolveSupportTask = tasksAssignedToSalaboy.get(0);
    taskService.start(resolveSupportTask.getId(), "salaboy");
    currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
    assertEquals(10, currentNumberOfEvents);
    taskService.complete(resolveSupportTask.getId(), "salaboy", null);
    currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
    assertEquals(14, currentNumberOfEvents);
    tasksAssignedToSalaboy = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    assertEquals(1, tasksAssignedToSalaboy.size());
    assertEquals("Notify Customer", tasksAssignedToSalaboy.get(0).getName());
    TaskSummary notifySupportTask = tasksAssignedToSalaboy.get(0);
    taskService.start(notifySupportTask.getId(), "salaboy");
    currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
    assertEquals(16, currentNumberOfEvents);
    output = new HashMap<String, Object>();
    output.put("output_solution", "solved today");
    taskService.complete(notifySupportTask.getId(), "salaboy", output);
    currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
    assertEquals(18, currentNumberOfEvents);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) InternalTaskService(org.kie.internal.task.api.InternalTaskService) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalTaskService(org.kie.internal.task.api.InternalTaskService) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) TaskSummary(org.kie.api.task.model.TaskSummary) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 34 with InternalTaskService

use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.

the class UserTaskServiceImpl method getAttachmentsByTaskId.

@Override
public List<Attachment> getAttachmentsByTaskId(String deploymentId, Long taskId) {
    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 Collections.emptyList();
    }
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
    try {
        TaskService taskService = engine.getTaskService();
        // perform actual operation
        return ((InternalTaskService) taskService).getAllAttachmentsByTaskId(taskId);
    } 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 35 with InternalTaskService

use of org.kie.internal.task.api.InternalTaskService in project jbpm by kiegroup.

the class UserTaskServiceImpl method deleteAttachment.

@Override
public void deleteAttachment(String deploymentId, Long taskId, Long attachmentId) {
    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;
    }
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
    try {
        TaskService taskService = engine.getTaskService();
        // perform actual operation
        ((InternalTaskService) taskService).deleteAttachment(taskId, attachmentId);
    } 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)

Aggregations

InternalTaskService (org.kie.internal.task.api.InternalTaskService)44 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)35 TaskService (org.kie.api.task.TaskService)27 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)25 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)20 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)18 UserTaskService (org.jbpm.services.api.UserTaskService)17 TaskSummary (org.kie.api.task.model.TaskSummary)13 Test (org.junit.Test)12 KieSession (org.kie.api.runtime.KieSession)11 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)9 Task (org.kie.api.task.model.Task)5 TaskCleanUpProcessEventListener (org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener)4 AuditService (org.kie.api.runtime.manager.audit.AuditService)4 I18NText (org.kie.api.task.model.I18NText)4 Date (java.util.Date)3 EntityManager (javax.persistence.EntityManager)3 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)3