Search in sources :

Example 21 with ProcessDefinition

use of org.jbpm.services.api.model.ProcessDefinition in project jbpm by kiegroup.

the class ClassloaderKModuleDeploymentServiceTest method testDeploymentOfProcesses.

@Test
public void testDeploymentOfProcesses() throws Exception {
    assertNotNull(deploymentService);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION, "defaultKieBase", "defaultKieSession");
    deploymentUnit.setStrategy(RuntimeStrategy.PER_REQUEST);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    DeployedUnit deployed = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
    assertNotNull(deployed);
    assertNotNull(deployed.getDeploymentUnit());
    assertNotNull(deployed.getRuntimeManager());
    assertEquals("org.jbpm.test:jbpm-module:1.0:defaultKieBase:defaultKieSession", deployed.getDeploymentUnit().getIdentifier());
    assertNotNull(runtimeDataService);
    Collection<ProcessDefinition> processes = runtimeDataService.getProcesses(new QueryContext());
    assertNotNull(processes);
    assertEquals(1, processes.size());
    RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnit.getIdentifier());
    assertNotNull(manager);
    RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
    assertNotNull(engine);
    Class<?> clazz = Class.forName("org.jbpm.test.Person", true, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
    Object instance = clazz.newInstance();
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("person", instance);
    ProcessInstance processInstance = engine.getKieSession().startProcess("testkjar.src.main.resources.process", params);
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    List<TaskSummary> tasks = engine.getTaskService().getTasksOwned("salaboy", "en-UK");
    assertEquals(1, tasks.size());
    long taskId = tasks.get(0).getId();
    Map<String, Object> content = ((InternalTaskService) engine.getTaskService()).getTaskContent(taskId);
    assertTrue(content.containsKey("personIn"));
    Object person = content.get("personIn");
    assertEquals(clazz.getName(), person.getClass().getName());
    engine.getTaskService().start(taskId, "salaboy");
    Map<String, Object> data = new HashMap<String, Object>();
    data.put("personOut", instance);
    engine.getTaskService().complete(taskId, "salaboy", data);
    processInstance = engine.getKieSession().getProcessInstance(processInstance.getId());
    assertNull(processInstance);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) HashMap(java.util.HashMap) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) InternalTaskService(org.kie.internal.task.api.InternalTaskService) QueryContext(org.kie.api.runtime.query.QueryContext) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) TaskSummary(org.kie.api.task.model.TaskSummary) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 22 with ProcessDefinition

use of org.jbpm.services.api.model.ProcessDefinition in project jbpm by kiegroup.

the class FormProviderServiceImpl method getFormDisplayProcess.

@Override
public String getFormDisplayProcess(String deploymentId, String processId) {
    ProcessDefinition processDesc = dataService.getProcessesByDeploymentIdProcessId(deploymentId, processId);
    Map<String, String> processData = bpmn2Service.getProcessVariables(deploymentId, processId);
    if (processData == null) {
        processData = new HashMap<String, String>();
    }
    Map<String, Object> renderContext = new HashMap<String, Object>();
    renderContext.put("process", processDesc);
    renderContext.put("outputs", processData);
    renderContext.put("marshallerContext", getMarshallerContext(deploymentId, processId));
    for (FormProvider provider : providers) {
        String template = provider.render(processDesc.getName(), processDesc, renderContext);
        if (!StringUtils.isEmpty(template)) {
            return template;
        }
    }
    logger.warn("Unable to find form to render for process '{}'", processDesc.getName());
    return "";
}
Also used : HashMap(java.util.HashMap) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition)

Example 23 with ProcessDefinition

use of org.jbpm.services.api.model.ProcessDefinition in project jbpm by kiegroup.

the class FormProviderServiceImpl method getFormDisplayTask.

@Override
@SuppressWarnings("unchecked")
public String getFormDisplayTask(long taskId) {
    Task task = taskService.getTaskById(taskId);
    if (task == null) {
        return "";
    }
    String name = task.getName();
    final String deploymentId = task.getTaskData().getDeploymentId();
    final String processId = task.getTaskData().getProcessId();
    ProcessDefinition processDesc = null;
    if (deploymentId != null && processId != null) {
        processDesc = dataService.getProcessesByDeploymentIdProcessId(deploymentId, processId);
    }
    Map<String, Object> renderContext = new HashMap<String, Object>();
    ContentMarshallerContext marshallerContext = getMarshallerContext(task);
    // read task variables
    Object input = null;
    long inputContentId = task.getTaskData().getDocumentContentId();
    if (inputContentId != -1) {
        Content content = taskService.getContentById(inputContentId);
        input = ContentMarshallerHelper.unmarshall(content.getContent(), marshallerContext.getEnvironment(), marshallerContext.getClassloader());
    }
    if (input == null) {
        input = new HashMap<String, Object>();
    }
    Object output = null;
    long outputContentId = task.getTaskData().getOutputContentId();
    if (outputContentId != -1) {
        Content content = taskService.getContentById(outputContentId);
        output = ContentMarshallerHelper.unmarshall(content.getContent(), marshallerContext.getEnvironment(), marshallerContext.getClassloader());
    }
    if (output == null) {
        output = new HashMap<String, Object>();
    }
    // prepare task variables for rendering
    Map<String, Object> finalOutput = new HashMap<String, Object>();
    if (processId != null && !processId.equals("")) {
        // If task has an associated process let's merge the outputs
        Map<String, String> taskOutputMappings = bpmn2Service.getTaskOutputMappings(deploymentId, processId, task.getName());
        if (taskOutputMappings == null) {
            taskOutputMappings = new HashMap<String, String>();
        }
        // process mappings with the value that can be stored in the output Content
        for (String key : taskOutputMappings.keySet()) {
            Object value = ((Map<String, Object>) output).get(key);
            if (value == null) {
                value = "";
            }
            finalOutput.put(key, value);
        }
    } else if (output instanceof Map && !((Map) output).isEmpty()) {
        // If the task doesn't belongs to any project BUT it has outputs let's add them directly to the rendering context.
        finalOutput.putAll((Map<String, Object>) output);
    }
    // merge template with process variables
    renderContext.put("task", task);
    renderContext.put("marshallerContext", marshallerContext);
    // add all inputs as direct entries
    if (input instanceof Map) {
        renderContext.put("inputs", input);
        for (Map.Entry<String, Object> inputVar : ((Map<String, Object>) input).entrySet()) {
            renderContext.put(inputVar.getKey(), inputVar.getValue());
        }
    } else {
        renderContext.put("input", input);
    }
    // add all outputs as direct entries
    renderContext.put("outputs", finalOutput);
    for (Map.Entry<String, Object> outputVar : ((Map<String, Object>) finalOutput).entrySet()) {
        renderContext.put(outputVar.getKey(), outputVar.getValue());
    }
    // find form
    for (FormProvider provider : providers) {
        String template = provider.render(name, task, processDesc, renderContext);
        if (!StringUtils.isEmpty(template)) {
            return template;
        }
    }
    logger.warn("Unable to find form to render for task '{}' on process '{}'", name, processDesc == null ? "" : processDesc.getName());
    return "";
}
Also used : Task(org.kie.api.task.model.Task) HashMap(java.util.HashMap) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) Content(org.kie.api.task.model.Content) HashMap(java.util.HashMap) Map(java.util.Map) ContentMarshallerContext(org.kie.internal.task.api.ContentMarshallerContext)

Example 24 with ProcessDefinition

use of org.jbpm.services.api.model.ProcessDefinition in project jbpm by kiegroup.

the class RuntimeDataServiceEJBIntegrationTest method testGetProcessByDeploymentId.

@Test
public void testGetProcessByDeploymentId() {
    Collection<ProcessDefinition> definitions = runtimeDataService.getProcessesByDeploymentId(deploymentUnit.getIdentifier(), new QueryContext());
    assertNotNull(definitions);
    assertEquals(3, definitions.size());
    List<String> expectedProcessIds = new ArrayList<String>();
    expectedProcessIds.add("org.jbpm.writedocument.empty");
    expectedProcessIds.add("org.jbpm.writedocument");
    expectedProcessIds.add("org.jboss.qa.bpms.HumanTask");
    for (ProcessDefinition def : definitions) {
        assertTrue(expectedProcessIds.contains(def.getId()));
    }
}
Also used : ArrayList(java.util.ArrayList) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) QueryContext(org.kie.api.runtime.query.QueryContext) Test(org.junit.Test)

Example 25 with ProcessDefinition

use of org.jbpm.services.api.model.ProcessDefinition in project jbpm by kiegroup.

the class DeploymentServiceEJBIntegrationTest method testDeploymentOfProcessesVerifyTransientObjectOmitted.

@Test
public void testDeploymentOfProcessesVerifyTransientObjectOmitted() {
    assertNotNull(deploymentService);
    assertNotNull(commandService);
    DeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    DeployedUnit deployed = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
    assertNotNull(deployed);
    assertNotNull(deployed.getDeploymentUnit());
    assertNotNull(deployed.getRuntimeManager());
    assertNotNull(runtimeDataService);
    Collection<ProcessDefinition> processes = runtimeDataService.getProcesses(new QueryContext());
    assertNotNull(processes);
    assertEquals(5, processes.size());
    DeploymentStore store = new DeploymentStore();
    store.setCommandService(commandService);
    Collection<DeploymentUnit> units = store.getEnabledDeploymentUnits();
    assertNotNull(units);
    assertEquals(1, units.size());
    DeploymentUnit enabled = units.iterator().next();
    assertNotNull(enabled);
    assertTrue(enabled instanceof KModuleDeploymentUnit);
    KModuleDeploymentUnit kmoduleEnabled = (KModuleDeploymentUnit) enabled;
    DeploymentDescriptor dd = kmoduleEnabled.getDeploymentDescriptor();
    assertNotNull(dd);
    // ejb deployment service add transitively Async WorkItem handler that should not be stored as part of deployment store
    assertEquals(0, dd.getWorkItemHandlers().size());
}
Also used : DeploymentStore(org.jbpm.kie.services.impl.store.DeploymentStore) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) QueryContext(org.kie.api.runtime.query.QueryContext) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) Test(org.junit.Test)

Aggregations

ProcessDefinition (org.jbpm.services.api.model.ProcessDefinition)50 Test (org.junit.Test)44 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)29 QueryContext (org.kie.api.runtime.query.QueryContext)27 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)22 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)19 DeploymentUnit (org.jbpm.services.api.model.DeploymentUnit)19 HashMap (java.util.HashMap)14 ArrayList (java.util.ArrayList)12 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)12 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)9 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)7 DeployedUnitImpl (org.jbpm.kie.services.impl.DeployedUnitImpl)6 OtherPerson (org.jbpm.kie.test.objects.OtherPerson)6 Person (org.jbpm.kie.test.objects.Person)6 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)6 KieSession (org.kie.api.runtime.KieSession)4 AbstractEJBServicesTest (org.jbpm.test.container.AbstractEJBServicesTest)3 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)3 File (java.io.File)2