0 Replies Latest reply on Dec 4, 2018 6:30 AM by Melvin Moses

    Add new user into user tasks in jBPM7.13

    Melvin Moses Newbie

      Hi,

      I'm new to jBPM process development.i'm using the following codes to start a task

             

               String serverUrl = "http://localhost:8081/kie-server/services/rest/server";

              String user = "wbadmin";

              String password = "wbadmin";

       

              String containerId = "incidentmanagement_1.0.0";

              String processId = "defaultPackage.IncidentManagement-3";

              String name="demo";

              Long taskIdtest=(long) 29;

              KieServicesConfiguration configuration = KieServicesFactory.newRestConfiguration(serverUrl, user, password);

              configuration.setMarshallingFormat(MarshallingFormat.JAXB);

              KieServicesClient kieServicesClient =  KieServicesFactory.newKieServicesClient(configuration);

              boolean deployContainer = true;

              KieContainerResourceList containers = kieServicesClient.listContainers().getResult();

              // check if the container is not yet deployed, if not deploy it

              if (containers != null) {

                  for (KieContainerResource kieContainerResource : containers.getContainers()) {

                      if (kieContainerResource.getContainerId().equals(containerId)) {

                          System.out.println("\t######### Found container " + containerId + " skipping deployment...");

                          deployContainer = false;

                          break;

       

       

                      }

                  }

              }

              // deploy container if not there yet       

              if (deployContainer) {

                  System.out.println("\t######### Deploying container " + containerId);

                  KieContainerResource resource = new KieContainerResource(containerId, new ReleaseId("org.jbpm", "HR", "1.0"));

                  kieServicesClient.createContainer(containerId, resource);

              }

              // query for all available process definitions

              QueryServicesClient queryClient = kieServicesClient.getServicesClient(QueryServicesClient.class);

              List<ProcessDefinition> processes = queryClient.findProcesses(0, 10);

              System.out.println("\t######### Available processes" + processes);

       

              ProcessServicesClient processClient = kieServicesClient.getServicesClient(ProcessServicesClient.class);

              // get details of process definition

              ProcessDefinition definition = processClient.getProcessDefinition(containerId, processId);

              System.out.println("\t######### Definition details: " + definition);

       

              Long processInstanceId = processClient.startProcess(containerId, processId);

              System.out.println("\t######### Process instance id: " + processInstanceId);

             

              List<NodeInstance> completedNodes = queryClient.findCompletedNodeInstances(processInstanceId, 0, 10);

              System.out.println("\t######### Completed nodes: " + completedNodes);

            

            

              UserTaskServicesClient taskClient = kieServicesClient.getServicesClient(UserTaskServicesClient.class);

          

              //Find tasks related to process

              List<TaskSummary> processtasks = taskClient.findTasksByStatusByProcessInstanceId(processInstanceId, null, 0, 1);

              System.out.println("######### All Process Tasks: " +processtasks.size());

              for(int i=0;i<processtasks.size();i++) {

           

              System.out.println("processtasks :"+(i+1)

              +"== id :"+processtasks.get(i).getId()

              +"== Name :"+processtasks.get(i).getName()

              +"== Status :"+processtasks.get(i).getStatus());

              }

            

              //find tasks

            

              List<TaskSummary> Alltasks = taskClient.findTasks(user, 0, 10);

              System.out.println("######### Alltasks: " +Alltasks.size());

              for(int i=0;i<Alltasks.size();i++) {

           

              System.out.println("Task :"+(i+1)

              +"== id :"+Alltasks.get(i).getId()

              +"== Name :"+Alltasks.get(i).getName()

              +"== Status :"+Alltasks.get(i).getStatus());

              }

            

              // find available tasks

              List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(user, 0, 10);

            

              Map<String, Object> performances = new HashMap<String, Object>();

              performances.put("performance", "excellent");

       

       

              taskIdtest=processtasks.get(0).getId();

          

              taskClient.startTask(containerId, taskIdtest, user);

       

       

      I'm using the user here is "wbadmin", which is  a default user in server. What I want is I want to import new users (user in another application) and use that users to start and complete user tasks. I have googled it and can't find any suitable answer. Any help with sample code would be grateful.