Search in sources :

Example 1 with CommandBasedTaskService

use of org.jbpm.services.task.impl.command.CommandBasedTaskService in project jbpm by kiegroup.

the class AbstractRuntimeManager method newTaskService.

protected InternalTaskService newTaskService(TaskServiceFactory factory) {
    InternalTaskService internalTaskService = (InternalTaskService) factory.newTaskService();
    if (internalTaskService instanceof CommandBasedTaskService) {
        ((CommandBasedTaskService) internalTaskService).getEnvironment().set(EnvironmentName.DEPLOYMENT_ID, this.getIdentifier());
        ((CommandBasedTaskService) internalTaskService).getEnvironment().set(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, ((SimpleRuntimeEnvironment) environment).getEnvironmentTemplate().get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES));
    }
    return internalTaskService;
}
Also used : InternalTaskService(org.kie.internal.task.api.InternalTaskService) CommandBasedTaskService(org.jbpm.services.task.impl.command.CommandBasedTaskService)

Example 2 with CommandBasedTaskService

use of org.jbpm.services.task.impl.command.CommandBasedTaskService in project jbpm by kiegroup.

the class ParentChildMarshallingJpaTest method testProcess.

@Test
public void testProcess() throws Exception {
    emfDomain = Persistence.createEntityManagerFactory("org.jbpm.persistence.parent-child");
    addEnvironmentEntry(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, new ObjectMarshallingStrategy[] { new JPAPlaceholderResolverStrategy(emfDomain), new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT) });
    RuntimeManager manager = createRuntimeManager(Strategy.PROCESS_INSTANCE, "manager", "org/jbpm/test/functional/jpa/parent-child.bpmn");
    RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession = runtime.getKieSession();
    // start a new process instance
    Map<String, Object> params = new HashMap<String, Object>();
    Application application = new Application();
    application.setType("A");
    params.put("application", application);
    ProcessInstance pi = ksession.startProcess("com.sample.bpmn.hello", params);
    System.out.println("A process instance started : pid = " + pi.getId());
    TaskService taskService = runtime.getTaskService();
    assertTrue(taskService instanceof CommandBasedTaskService);
    assertTrue(((CommandBasedTaskService) taskService).getEnvironment().get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES) != null);
    List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    for (TaskSummary taskSummary : list) {
        System.out.println("john starts a task : taskId = " + taskSummary.getId());
        Task task = taskService.getTaskById(taskSummary.getId());
        long documentContentId = task.getTaskData().getDocumentContentId();
        Content content = taskService.getContentById(documentContentId);
        HashMap<String, Object> contents = (HashMap<String, Object>) ContentMarshallerHelper.unmarshall(content.getContent(), ksession.getEnvironment());
        Application outputApplication = (Application) contents.get("input1_application");
        Person person = new Person();
        person.setFullName("John Doe");
        outputApplication.setPerson(person);
        Map<String, Object> results = new LinkedHashMap<String, Object>();
        results.put("output1_application", outputApplication);
        taskService.start(taskSummary.getId(), "john");
        taskService.complete(taskSummary.getId(), "john", results);
    }
    list = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
    for (TaskSummary taskSummary : list) {
        System.out.println("mary starts a task : taskId = " + taskSummary.getId());
        taskService.start(taskSummary.getId(), "mary");
        taskService.complete(taskSummary.getId(), "mary", null);
    }
    manager.disposeRuntimeEngine(runtime);
    // Check!
    EntityManager em = emfDomain.createEntityManager();
    int size = em.createQuery("select i from Person i").getResultList().size();
    assertEquals(1, size);
}
Also used : SerializablePlaceholderResolverStrategy(org.drools.core.marshalling.impl.SerializablePlaceholderResolverStrategy) JPAPlaceholderResolverStrategy(org.drools.persistence.jpa.marshaller.JPAPlaceholderResolverStrategy) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) Task(org.kie.api.task.model.Task) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TaskService(org.kie.api.task.TaskService) CommandBasedTaskService(org.jbpm.services.task.impl.command.CommandBasedTaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) CommandBasedTaskService(org.jbpm.services.task.impl.command.CommandBasedTaskService) LinkedHashMap(java.util.LinkedHashMap) EntityManager(javax.persistence.EntityManager) Content(org.kie.api.task.model.Content) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Application(org.jbpm.test.entity.Application) Person(org.jbpm.test.entity.Person) Test(org.junit.Test)

Example 3 with CommandBasedTaskService

use of org.jbpm.services.task.impl.command.CommandBasedTaskService in project jbpm by kiegroup.

the class HumanTaskConfigurator method getTaskService.

@SuppressWarnings("unchecked")
public TaskService getTaskService() {
    if (service == null) {
        TaskEventSupport taskEventSupport = new TaskEventSupport();
        this.commandExecutor = new TaskCommandExecutorImpl(this.environment, taskEventSupport);
        if (userGroupCallback == null) {
            userGroupCallback = new MvelUserGroupCallbackImpl(true);
        }
        environment.set(EnvironmentName.TASK_USER_GROUP_CALLBACK, userGroupCallback);
        if (userInfo == null) {
            userInfo = new DefaultUserInfo(true);
        }
        environment.set(EnvironmentName.TASK_USER_INFO, userInfo);
        addDefaultInterceptor();
        addTransactionLockInterceptor();
        addOptimisticLockInterceptor();
        addErrorHandlingInterceptor();
        for (PriorityInterceptor pInterceptor : interceptors) {
            this.commandExecutor.addInterceptor(pInterceptor.getInterceptor());
        }
        service = new CommandBasedTaskService(this.commandExecutor, taskEventSupport, this.environment);
        // register listeners
        for (TaskLifeCycleEventListener listener : listeners) {
            ((EventService<TaskLifeCycleEventListener>) service).registerTaskEventListener(listener);
        }
        if (AssignmentServiceProvider.get().isEnabled()) {
            ((EventService<TaskLifeCycleEventListener>) service).registerTaskEventListener(new AssignmentTaskEventListener());
        }
        // initialize deadline service with command executor for processing
        if (TaskDeadlinesServiceImpl.getInstance() == null) {
            TaskDeadlinesServiceImpl.initialize(commandExecutor);
        }
    }
    return service;
}
Also used : AssignmentTaskEventListener(org.jbpm.services.task.assignment.impl.AssignmentTaskEventListener) TaskCommandExecutorImpl(org.jbpm.services.task.commands.TaskCommandExecutorImpl) EventService(org.kie.internal.task.api.EventService) MvelUserGroupCallbackImpl(org.jbpm.services.task.identity.MvelUserGroupCallbackImpl) TaskEventSupport(org.jbpm.services.task.events.TaskEventSupport) CommandBasedTaskService(org.jbpm.services.task.impl.command.CommandBasedTaskService) DefaultUserInfo(org.jbpm.services.task.identity.DefaultUserInfo) TaskLifeCycleEventListener(org.kie.api.task.TaskLifeCycleEventListener)

Example 4 with CommandBasedTaskService

use of org.jbpm.services.task.impl.command.CommandBasedTaskService in project jbpm by kiegroup.

the class CustomHumanTaskServiceProducer method produceTaskService.

@Produces
@CustomHumanTaskService
@Override
public CommandBasedTaskService produceTaskService() {
    CommandBasedTaskService taskServiceMock = Mockito.mock(CommandBasedTaskService.class);
    Mockito.when(taskServiceMock.execute(Mockito.any())).thenAnswer((InvocationOnMock invocation) -> {
        throw new CustomTaskServiceInUse();
    });
    return taskServiceMock;
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) CommandBasedTaskService(org.jbpm.services.task.impl.command.CommandBasedTaskService) Produces(javax.enterprise.inject.Produces)

Aggregations

CommandBasedTaskService (org.jbpm.services.task.impl.command.CommandBasedTaskService)4 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Produces (javax.enterprise.inject.Produces)1 EntityManager (javax.persistence.EntityManager)1 SerializablePlaceholderResolverStrategy (org.drools.core.marshalling.impl.SerializablePlaceholderResolverStrategy)1 JPAPlaceholderResolverStrategy (org.drools.persistence.jpa.marshaller.JPAPlaceholderResolverStrategy)1 AssignmentTaskEventListener (org.jbpm.services.task.assignment.impl.AssignmentTaskEventListener)1 TaskCommandExecutorImpl (org.jbpm.services.task.commands.TaskCommandExecutorImpl)1 TaskEventSupport (org.jbpm.services.task.events.TaskEventSupport)1 DefaultUserInfo (org.jbpm.services.task.identity.DefaultUserInfo)1 MvelUserGroupCallbackImpl (org.jbpm.services.task.identity.MvelUserGroupCallbackImpl)1 Application (org.jbpm.test.entity.Application)1 Person (org.jbpm.test.entity.Person)1 Test (org.junit.Test)1 KieSession (org.kie.api.runtime.KieSession)1 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)1 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)1 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)1 TaskLifeCycleEventListener (org.kie.api.task.TaskLifeCycleEventListener)1