AnsweredAssumed Answered

How to add new user to activiti through API

Question asked by vishnukumarnekkanti on Oct 29, 2014
Latest reply on Nov 2, 2014 by vishnukumarnekkanti
I am trrying ti add users to the process engine, but it keeps throwing the java.lang.NullPointerException
Here is my code:

package fluis;

import java.util.List;

import org.activiti.engine.HistoryService;
import org.activiti.engine.IdentityService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.FormService;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.identity.*;
import org.activiti.engine.task.Task;

public class adduser {
   protected transient static ProcessEngine processEngine;
   protected transient static IdentityService identityService;
   protected transient static RepositoryService repositoryService;
   protected transient static RuntimeService runtimeService;
   protected transient static HistoryService historyService;
   protected transient static FormService formService;

   public static void initProcessEngineServices(){
      processEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()
              .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE)
              .setJdbcDriver("org.h2.Driver")
              .setJdbcUrl("jdbc:h2:tcp://localhost/activiti;DB_CLOSE_DELAY=1000")
              .setJobExecutorActivate(true)
              .buildProcessEngine();
       repositoryService = processEngine.getRepositoryService();
       runtimeService = processEngine.getRuntimeService();
       historyService = processEngine.getHistoryService();
   }
   public static void initDeployments(){
       repositoryService.createDeployment()
         .addClasspathResource("processes/createTimersProcess.bpmn20.xml")
         .addClasspathResource("processes/FinancialReportProcess.bpmn20.xml")
         .deploy();
      
   }
   
   public static void newDeployment(String fileName){
      processEngine.getRepositoryService().createDeployment().addClasspathResource("processes/" + fileName).deploy();
   }
   
   public static void createUser(String userId, String firstName, String lastName, String email){
      
       if (identityService.createUserQuery().userId(userId).count() == 0) {
         User user = identityService.newUser(userId);
         user.setFirstName(firstName);
         user.setLastName(lastName);
         user.setPassword("");
         user.setEmail(email);
         identityService.saveUser(user);
       }
      
     }

   public static void main(String[] args) {
      
      initProcessEngineServices();
      initDeployments();
      newDeployment("oneTaskProcess.bpmn20.xml");
      createUser("myid", "hermit", "stone", "kermit@kmail.com");
   //   User x =  identityService.newUser("gty");
    //  System.out.println("asd");
     }
}

Outcomes