Is it possible to create bonita user using script task?
I tried to create a user in bonita portal using a script task.
use the following code and failed without success.
// First of all, let's log in on the engine: org.bonitasoft.engine.api.APIClient apiClient = new APIClient() apiClient.login("install", "install") // create new user, with username john and password bpm IdentityAPI identityAPI = apiClient.getIdentityAPI() final User user = identityAPI.createUser("john", "bpm") System.out.println("New user created: " + user)
Is it possible to create bonita user using script task? If possible what am I got wrong here?
Hi !
When you are executing a script in a process operation or a connector, you are already executing code server side as a technical use, so should not try to call the Login service.
This script should just work fine:
// Use the apiAccessor from a Groovy script to retrieve the Bonita apis
def identityAPI = apiAccessor.getIdentityAPI()
// create complex user
UserCreator creator = new UserCreator("john", "bpm")
creator.setFirstName("Johnny").setLastName("B. Good")
ContactDataCreator proContactDataCreator = new ContactDataCreator().setAddress("32 rueGustave Eiffel").setCity("Grenoble").setPhoneNumber("555 14 12 541")
creator.setProfessionalContactData(proContactDataCreator)
final User user2 = identityAPI.createUser(creator)
HTH
Romain
Comments
Tried this script too..
// Let's set the connection settings to use HTTP on the already running Bonita runtime:
Map settings = new HashMap();
settings.put("server.url", "http://localhost:3381");
settings.put("application.name", "bonita");
APITypeManager.setAPITypeAndParams(ApiAccessType.LOCAL, settings);
final LoginAPI loginAPI = TenantAPIAccessor.getLoginAPI();
APISession session = loginAPI.login("install", "install");
ProcessAPI processAPI = TenantAPIAccessor.getProcessAPI(session);
APIClient apiClient = new APIClient()
// create new user, with username john and password bpm
IdentityAPI identityAPI = apiClient.getIdentityAPI()
// create complex user
UserCreator creator = new UserCreator("john", "bpm")
creator.setFirstName("Johnny").setLastName("B. Good")
ContactDataCreator proContactDataCreator = new ContactDataCreator().setAddress("32 rueGustave Eiffel").setCity("Grenoble").setPhoneNumber("555 14 12 541")
creator.setProfessionalContactData(proContactDataCreator)
final User user2 = identityAPI.createUser(creator)
this is the exception
Caused by: org.bonitasoft.engine.core.operation.exception.SOperationExecutionException: org.bonitasoft.engine.expression.exception.SExpressionEvaluationException: Groovy script throws an exception of type class org.bonitasoft.engine.platform.LoginException with message = org.bonitasoft.engine.transaction.STransactionCreationException: We do not support nested calls to the transaction service. Current state is: 0.
Expression : SExpressionImpl [name=createNewUserScript(), content=import org.bonitasoft.engine.api.APIClient