Skip to main content
1-Visitor
October 28, 2010
Question

Getting the user assigned to the role and setting an attribute value

  • October 28, 2010
  • 1 reply
  • 1120 views

Hi All,
OK...I've been pouring over the java docs but since I'm still learning this java nonsense, it's quite confusing to me.
In an expression robot, I need a way to extract who the user is assigned to a specified role (AUTHOR for example).
I believe this is what I need but I'm not sure:
wt.team.Team team = (wt.team.Team) ( (wt.workflow.engine.WfProcess) self.getObject() ).getTeamId().getObject();
java.util.Enumeration principal = team.getPrincipalTarget(wt.project.Role.toRole("AUTHOR"));
So in this case, the value of "principal" is the user who is the author in this workflow right?
Mike -

1 reply

1-Visitor
October 28, 2010
Here's what I've got for returning all WTPrincipals in a specific role:

public static Collection getPrincipalsInRole(String role, Team team) throws WTException {
Map rpMap = team.getRolePrincipalMap();
String resultOid = null;
Collection retList = new ArrayList();

Iterator iter = rpMap.keySet().iterator();

while(iter.hasNext()) {
Role nextRole = (Role) iter.next();
String mapRole = nextRole.getStringValue();
int lastPeriodLoc = mapRole.lastIndexOf(".");
if (lastPeriodLoc > -1)
mapRole = mapRole.substring(lastPeriodLoc + 1);

if (mapRole.equalsIgnoreCase(role)) {
Object user = rpMap.get(nextRole);
if (user != null) {
resultOid = GeneralUtility.getLocalOid(user.toString());
ReferenceFactory rf = new ReferenceFactory();
WTReference ref = rf.getReference(resultOid);
retList.add((WTPrincipal) ref.getObject());
}
}
}
return retList;
}

Now, keep in mind that this returns a list that could contain nothing (if the role is empty), or a combination of WTGroup and WTUser objects (since you can assign groups to roles).

-Thomas R. Busch
Sr. Software Developer
Stryker Instruments
(269) 323-7700 x4014
tom.busch@stryker.com<">mailto:tom.busch@stryker.com>