AnsweredAssumed Answered

Issues with creating user inside Java task

Question asked by butik on Jul 10, 2014
Latest reply on Jul 22, 2014 by butik
Hello,
I'm implementing "Create user process" - at first step initiator enters some user details and at second stet Java service task is called:

<java>
public class CreateUser implements ActivityBehavior {

  private static final long serialVersionUID = -7993850756520475229L;

  @Override
  public void execute(final ActivityExecution execution) throws Exception {
    System.out.println("Start creating user");
    PvmTransition transition = null;

    try {
      IdentityServiceImpl identityService = (IdentityServiceImpl) execution.getEngineServices().getIdentityService();

      String userId = (String) execution.getVariable("screenName");
      String firstName = (String) execution.getVariable("firstName");
      String lastName = (String) execution.getVariable("lastName");
      String email = (String) execution.getVariable("email");
      String password = (String) execution.getVariable("password");

      User newUser = identityService.newUser(userId);

      newUser.setEmail(email);
      newUser.setFirstName(firstName);
      newUser.setLastName(lastName);
      newUser.setPassword(password);

      identityService.saveUser(newUser);
     
      transition = execution.getActivity().findOutgoingTransition("userStored");

      System.out.println("User:" + userId + "was created");
    } catch (Throwable e) {
      transition = execution.getActivity().findOutgoingTransition("userNotStored");

      System.out.println("User not created: " + e.getMessage());
    }

    execution.take(transition);
  }
}
<java>

I want to handle duplicate id exception  at  identityService.saveUser(newUser); , but the problem is that I'm getting this exception after whole Java service task executed.

How can I force identityService to persist newUser exaclty at a call?

Outcomes