AddUserMembership/ ProfileMemberCreator.setGroupId/.setRoleId Problem

1
0
-1

I have a problem with setting UserMembership on a "Blank" User, created on Anonymous User, with his Form Inputs.
The user and his profile is created, but not his Usermembership on his UserDetails in Portal Bonita.
This is the Groovy code:

UserCreator creator = new UserCreator(tsk2_emailStudent, tsk2_CodeStudent);
creator.setFirstName(tsk2_nameStudent).setLastName(tsk2_StudentLastname);
ContactDataCreator proContactDataCreator = new ContactDataCreator().setFaxNumber(tsk2_codeStudent);
creator.setProfessionalContactData(proContactDataCreator);
final IdentityAPI identityAPI = apiAccessor.getIdentityAPI();
final User user = identityAPI.createUser(creator);
ProfileAPI orgProfileAPI = apiAccessor.getProfileAPI();
SearchOptionsBuilder searchOptionsBuilder = new SearchOptionsBuilder(0,10);
searchOptionsBuilder.filter(ProfileSearchDescriptor.NAME, tsk2_emailStudent);
SearchResult<Profile> searchResultProfile = orgProfileAPI.searchProfiles(searchOptionsBuilder.done());
if (searchResultProfile.getResult().size()!=1)
                { return; }
Profile profile = searchResultProfile.getResult().get(0);
ProfileMemberCreator profileMemberCreator = new ProfileMemberCreator( profile.getId());
profileMemberCreator.setUserId(creator.getId());
Group stugroup = apiAccessor.identityAPI.getGroupByPath["plataform","Students"];
Role sturole = apiAccessor.identityAPI.getRoleByName("Group");
/*
profileMemberCreator.setGroupId(stugroup.getId());
profileMemberCreator.setRoleId(sturole.getId());
*/

//This is using ProfileMemberCreator, setting role.id() group.id().
orgProfileAPI.createProfileMember(profileMemberCreator);
apiAccessor.identityAPI.addUserMembership(tsk1_studentID, stugroup.getId(), sturole.getId());
//using UserMemberShip.

Both them are not working, anyone know how to fix this problem, help me, please.
Regards, Peter Grant

Comments

Submitted by phenant on Tue, 08/23/2016 - 21:45

Im using BonitaBPM 6.5.4. i can't migrate yet...

Submitted by Sean McP on Wed, 08/24/2016 - 00:08

To Show Code correctly use

< code >
your code
< /code >

removing the spaces to show code correctly as here:

your code

Thanks and regards
Seán

Submitted by phenant on Wed, 08/24/2016 - 18:08

Thanks sean, i hope someone knows the answer, i think is because getId() from both below are wrong.

Group stugroup = apiAccessor.identityAPI.getGroupByPath["plataform","Students"];
Role sturole = apiAccessor.identityAPI.getRoleByName("Group");

But if its the case, i dont know how get ids from Organization created in BonitaStudio. not in a Groovy code. Funny thing is BonitaBPM Engine not accusing error about erroneous parameter in setting ids() in that both methods.

1 answer

1
+1
-1
This one is the BEST answer!

We don't use getGroupByPath that way,

we do it like this and it works:

String fullOrganizationPath = "/acme/groupname/groupname";
Group groupSelected=apiAccessor.getIdentityAPI().getGroupByPath(fullOrganizationPath);

regarding the Role - I take it you mean Role Name not Group :)

I would also write it as:

Role sturole = apiAccessor.getIdentityAPI().getRoleByName("member");

Note - these commands are case sensitive so Member is not the same as member and getting it wrong will lead to notFound errors.

Hope that helps,

regards
Seán

PS: If this answers your question, please mark as resolved by ticking the tick mark on the left of this reply.

Notifications