on 06-02-2008 10:51 AM
Hi
I started a gp process programmatically like it is described here: http://help.sap.com/saphelp_nw2004s/helpdata/en/43/fcdf77fc6510b3e10000000a11466f/frameset.htm
Creating the Role Assignment List
import com.sap.caf.eu.gp.process.api.GPProcessFactory;
import com.sap.caf.eu.gp.process.api.IGPProcess;
import com.sap.caf.eu.gp.process.rt.api.IGPProcessRoleInstanceList;
import com.sap.caf.eu.gp.process.rt.api.IGPRuntimeManager;
import com.sap.security.api.IUser;
public void startProcess( java.lang.String processId )
{
...
// retrieve the Runtime Manager
IGPRuntimeManager rtm = GPProcessFactory.getRuntimeManager();
// create an empty role assignment list
IGPProcessRoleInstanceList roles = rtm.createProcessRoleInstanceList();
// get the process role number
int rolenum = process.getRoleInfoCount();
// iterate over the required roles
for (int i = 0; i < rolenum; i++) {
// create a new role instance by specifying the role's unique name
IGPProcessRoleInstance roleInstance = roles. createProcessRoleInstance(process.getRoleInfo(i).getRoleName());
// add a user to the role instance
roleInstance.addUser(roleUser);
// add the new role to the assignment list
roles.addProcessRoleInstance(roleInstance);
}
...
}
Instead of assigning a user to the role
// add a user to the role instance
roleInstance.addUser(roleUser);
I would like to assign a group to the user. How can I do this?
Thanks for your help (points will be awarded)
Best regards
Bettina
Bettina,
As I know, the UI provide the search by groups and roles but in background the processor of each action is set by user. In other words, to assign a group as processor you need to read each member from group and set user by user as processor using GP API. The same apply to role.
Reward Points if itu2019s helpful.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Pedro
> In other words, to assign a group as processor you need to read each member from group and set user by user as processor using GP API.
How can I read each member from a group? By using the method Group. getGroupMembers() (https://help.sap.com/javadocs/NW04S/current/se/com/sap/security/api/IGroup.html)?
> Reward Points if itu2019s helpful.
I have rewarded and I will reward more if my problem gets solved.
Kind regards
Bettina
Bettina,
Use this code:
public Collection getGroupMembers(String groupName) throws Exception {
IGroupFactory groupFact = UMFactory.getGroupFactory();
Collection users = new ArrayList();
try {
IGroup group = groupFact.getGroup(groupName);
Iterator itUserMember = group.getUserMembers(true);
while (itUserMember.hasNext()) {
String user = (String)itUserMember.next();
users.add(user);
}
return users;
} catch (UMException umeEx) {
throw umeEx;
}
}
Pass the Unique ID of group like: GRUP.PRIVATE_DATASOURCE.un:Administrators
Reward points if it's helpful.
Hi Pedro
thanks a lot for your help and the code snippet. It was really helpful for me. However, it wasn't working until I converted the String representing the uniqueUserId to an object of type IUser. Here's the code:
IUserFactory userFact = UMFactory.getUserFactory();
IUser iuser= userFact.getUser(user);
users.add(iuser);
By the way - does anyone know whether this is definitely the only way to do assign groups to roles???
Kind regards
Bettina
Hi Bettina,
try this method:
Hint:
It is definitly a better approach to add the role to the group then to directly add the users. Otherwise you lose the flexibility of the group. Or did you always wanted to this?
Best regards,
Stefan Brauneis
Hi Stefan
The "role" a user (or a list of users) is assigned to is of type com.sap.caf.eu.gp.process.api.IGPProcessRoleInstance and serves as an input parameter to the Guided Procedures invocation method:
// initiate the process template by passing the process template
IGPProcessInstance prInstance = rtm.startProcess(process,
// a name,
"My First Process",
// a description,
"This process has been started using the GP public API",
// initiator
user,
// the role assignments,
roles,
// the input parameters
params,
// and the user actually executing this action
user);
These roles are special Guided Procedures roles, not Portal roles. Therefore, I don't think we can apply the method from IGROUP.
Kind regards
Bettina
Hi Bettina,
Follow the code adapted to get IUser object instead of unique ID string:
public Collection getGroupMembers(String groupName) throws Exception {
IGroupFactory groupFact = UMFactory.getGroupFactory();
Collection users = new ArrayList();
try {
IGroup group = groupFact.getGroup(groupName);
Iterator itUserMember = group.getUserMembers(true);
IUserFactory userFact = UMFactory.getUserFactory();
IUser user = null;
while (itUserMember.hasNext()) {
String userID = (String)itUserMember.next();
user = userFact.getUser(userID.trim());
users.add(user);
}
return users;
} catch (UMException umeEx) {
throw umeEx;
}
}
public String[] getGroupMembersArray(String groupName) {
String[] retMembers = null;
try {
Collection users = this.getGroupMembers(groupName);
retMembers = new String[users.size()];
Iterator itResult = users.iterator();
int i = 0;
IUser user = null;
while (itResult.hasNext()) {
user = (IUser)itResult.next();
retMembers<i> = user.getUniqueID();
i++;
}
return retMembers;
} catch (UMException umeEx) {
retMembers = new String[1];
retMembers[1] = umeEx.getMessage();
} catch (Exception ex) {
retMembers = new String[1];
retMembers[1] = ex.getMessage();
}
return retMembers;
}
Note: It's working fine here.
Hi Bettina,
Can you please share your solution?
Thanks and Regards,
Sakshi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bettina,
as far as I understood you want to add your current IUser to a specific group?
Here is the coding:
IGroupFactory groupFactory= UMFactory.getGroupFactory();
groupFactory.addUserToGroup(user.getUniqueID(), group.getUniqueID());
After that the user should be a member of the given group.
Come around if it does not solve your problem
Best regards,
Stefan Brauneis
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Stefan
thanks for helping!
> as far as I understood you want to add your current IUser to a specific group?
No, I would like to read all users from a given group.
Sorry, my mistake: I said, I wanted to assign a group to a user, but what I actually wanted to do was assigning a group to a role !
See you around...
Kind regards
Bettina
Edited by: Bettina Hepp on Jun 3, 2008 9:42 AM
Edited by: Bettina Hepp on Jun 3, 2008 9:44 AM
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.