Search in sources :

Example 1 with Person

use of org.jbpm.test.entity.Person 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)

Aggregations

HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 EntityManager (javax.persistence.EntityManager)1 SerializablePlaceholderResolverStrategy (org.drools.core.marshalling.impl.SerializablePlaceholderResolverStrategy)1 JPAPlaceholderResolverStrategy (org.drools.persistence.jpa.marshaller.JPAPlaceholderResolverStrategy)1 CommandBasedTaskService (org.jbpm.services.task.impl.command.CommandBasedTaskService)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 TaskService (org.kie.api.task.TaskService)1 Content (org.kie.api.task.model.Content)1 Task (org.kie.api.task.model.Task)1 TaskSummary (org.kie.api.task.model.TaskSummary)1