Map user to portal

1
0
-1

I create some users by groovy code. And now i want to map them to the portal to let them connect on it.

I dont know what code i have to add in my first code, to get that.

This is my current code to create users :

import org.bonitasoft.engine.identity.UserUpdater;
import java.util.logging.Logger;
import org.bonitasoft.engine.exception.UpdateException;
import org.bonitasoft.engine.identity.UserCreator;
import org.bonitasoft.engine.identity.UserUpdater;
import org.bonitasoft.engine.api.IdentityAPI;
import org.bonitasoft.engine.api.impl.transaction.identity.AddUserMembership;
import org.bonitasoft.engine.identity.User;
import org.bonitasoft.engine.profile.xml.ProfileMappingBinding;

final UserCreator user = new UserCreator (field_login1, field_pw1);
apiAccessor.getIdentityAPI().createUser(user);
return true
9 answers

1
0
-1

Ok.

So no way to do it with groovy code in the process of creation :( ?

Comments

Submitted by haris.subasic on Thu, 06/19/2014 - 17:30

No, groovy is for server-side scripting, it cannot interact with the Studio.

1
0
-1

Ok. So no way to do it by groovy code in the creation process :( ?

1
0
-1

Thank you . Yes it was the solution. :)

And is there some way to create the user also in the studio once created in the portal by my process

Comments

Submitted by haris.subasic on Thu, 06/19/2014 - 17:15

Great ;) You can export the entire Organization from the Portal and import it in the Studio.

1
0
-1

I map them to the role. Because i have 3 groupes G1, G2 and G3. In wich user can be Administrator or Client that's why i create two roles . So i map user like this : G1-Administrator for exemple.

And if it will not create user in the studio, how can i found it after closing the portal. In my cases users wich i add with my process they apear in the portal and once closed i lost them . And in all cases they not apear in my studio ?

Comments

Submitted by haris.subasic on Thu, 06/19/2014 - 16:41

If your task3 is mapped to all users from the role, it is correct that all of them will se it. You can use an additional filter of type 'initiator' that will restrict the task assignment only to the user who initiated the process.

1
0
-1

Hey haris.subasic,

Actualy i have a big problem now. In my process i have 2 profiles Clients and administrators . When i create 2 users with a Client profile. If user1 start his case and ask to some administrator to confirm one tasks in his process, after the confirmation of his tasks it seems that in the portal, user2 get the same information while he never start a case . It should be sent only to user1 who started the case.

Why he send the information to all users with same profile ? I dont know how to manage this big problem !!!!!

Thank you.

Comments

Submitted by haris.subasic on Thu, 06/19/2014 - 15:19

When you say "user2 gets the same information" - what exactly does he get? Is there a task that you designed? Or an email notification? How is the information "sent" to all users of the profile? It might be due to some actor mapping based on the profile

Submitted by rahmi.hichem on Thu, 06/19/2014 - 15:35

He get the tasks (For exemple i have some process with 3 tasks: Taske1 started by user1(client) then user2(administrator) confirm the task2 , after confirmation user1 can execute task3).

The problem is that in the portal when user2 confirm task2 every user who has the profil client will have the possibility to execute task3 !!! what i want is that the continuation will be send only to user1 ?

Submitted by rahmi.hichem on Thu, 06/19/2014 - 15:37

Just for information. I create users with the groovy code that u gave me in my process. After that i map them to profils in the portal. I don't see the new users in my organisation on Studio !!!!

Submitted by rahmi.hichem on Thu, 06/19/2014 - 15:51

With your code

import org.bonitasoft.engine.identity.UserCreator;

final UserCreator user = new UserCreator (field_login2, field_pw2);
user.setFirstName(field_nom1).setLastName(field_prenom1);
apiAccessor.getIdentityAPI().createUser(user);
return true

Once the portal closed the users disapear from the portal whil that they not apear in my studio i think that is the error who to create users in the same time in the portal and studio ?

Submitted by haris.subasic on Thu, 06/19/2014 - 16:00

API will add user on the engine level, that will be visible in the Portal, but it will not create it in the Studio, this is correct behaviour. What kind of actor mapping do you use for your Task3? Did you map it to a group, by any chance? Or a role?

Submitted by rahmi.hichem on Thu, 06/19/2014 - 16:07

I map it to role (in my case Client or Administrator). Because i have 3 groups G1, G2 and G3 and every one in these groupes can be Administrator or Client that's why i create Two roles !

But if he create the user only in the portal, once closed the users will be deleted ? so in the next session t dont found them in the portal.

1
0
-1

Hello Rahmi,

here is a quick script to give you an idea how to do it by code (starting from your code from the question):

import org.bonitasoft.engine.identity.UserCreator;

final identityAPI = apiAccessor.getIdentityAPI();
final profileAPI = apiAccessor.getProfileAPI();
final UserCreator user = new UserCreator (field_login2, field_pw2);
user.setFirstName(field_nom1).setLastName(field_prenom1);

identityAPI.createUser(user);

Long userId = identityAPI.getUserByUserName(field_login2).getId();
Long groupId = identityAPI.getGroupByPath("/acme").getId();

profileAPI.createProfileMember(1, userId, groupId, 1);
 
return true

Note that I used 1 for the profile id (that corresponds to the default User profile) and 1 for the role id (which corresponds to the default member role). You should update it to your needs. After this, your user should be able to connect to the Portal (like all other default users from Acme organization).

Hope this helps, Haris

Comments

Submitted by rahmi.hichem on Mon, 06/16/2014 - 14:53

Thank you for your help,

  1. Actualy i deleted the acme organisation and replace it by an other one with "opt" name. So i think i have just to replace /acme by /opt ?
  2. When you said "toto" do you mean that i have to replace it with "the login" of user (In my case field_login1).

  3. How can i get the right Id for diffirent parameters such (role, group and profil) , while i want to assign all this parameters to my new users !

Thanks

Submitted by haris.subasic on Mon, 06/16/2014 - 14:57
  1. Yes, just provide a correct path to your group.
  2. Yes, sorry, my mistake, you should put in whatever is your username (in your case field_login1)
  3. You should use different methods from IdentityAPI or ProfileAPI (like searchUsers, searchGroups, searchProfiles or searchRoles).
Submitted by rahmi.hichem on Mon, 06/16/2014 - 15:08

Thank you , i will see and if i get some errors i will tell you difficulties :)

1
0
-1

And about the unneeded imports i am not sure about the ones that i should delete ?!

1
0
-1

Thank you enrico.curiotto,

Yeah now i add the other informations such first name and last name , as follow :

final UserCreator user = new UserCreator (field_login2, field_pw2);
user.setFirstName(field_nom1).setLastName(field_prenom1);
apiAccessor.getIdentityAPI().createUser(user);

At this moment i want to map user to some profil (Users or administrators) to be able to connect in portal. I dont want to oblige the administrator to connect every time on the portal to map the new user i want to do all this job in my process.

Do you think it's possible ? and how ?

Thank you again.

1
0
-1

Hi Rahmi, you code works just fine, and you can connect to the portal as and administrator, go to organization and you'll see your new user created. You only set username and password, so in the list you have firstname and lastname as blanks. You can easily put name and lastname with user.setFirstName("...."); and user.setLastName("...."); Be also aware of the unneded imports you have on your script.

Correcting the answer based on your observations: You have two ways to achieve that. 1) Assign manually the profile user to the supergroup of your organization (ACME in the default case) In this way, after you create the user it's sufficient to use the method addUserMembership: org.bonitasoft.engine.api.MembershipAPI.addUserMembership(long userId, long groupId, long roleId) in your code to associate the user created to the supergroup. This automatically will let the user access to the portal with User profile 2) Play with the ProfileAPI methods. You can access them via apiAccessor.getProfileApl()

Cheers

Notifications