Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X
true
if the role has at least one WTPrincipal in it, false
if not.Is there any way to display the alert message on the screen and tell the user that they haave to mandatorily select the participant?
In Reply to Thomas Busch:
Mike, you could try this:
/**
* Determines if a given role is populated for this specific instance of a team.
*
* @param role - the name of the role to check against.
* @param teamOid - the obid of the team instance.
* @returntrue
if the role has at least one WTPrincipal in it,false
if not.
* @throws WTException
*/
public static boolean isRolePopulated(String role, String teamOid) {
String localTeamOid = GeneralUtility.getLocalOid(teamOid);
ReferenceFactory rf = new ReferenceFactory();
WTReference ref;
try {
ref = rf.getReference(localTeamOid);
} catch (WTException e) {
log.error("Could not get team from obid " + teamOid + "(local oid: " + localTeamOid + ")", e);
return false;
}
if (ref == null) {
return false;
}
Team team = (Team) ref.getObject();
if (team == null) {
return false;
}
Map rpMap;
try {
rpMap = team.getRolePrincipalMap();
} catch (WTException e) {
log.error("Could not get RolePrincipalMap from team", e);
return false;
}
String resultOid = null;
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)) {
List users = (ArrayList) rpMap.get(nextRole);
if (users.size() > 0){
// role found & populated with one or more users
return true;
}
}
}
// Role not found or no user in role
return false;
}
FYI, here's GeneralUtility.getLocalOid() (which is kind of sloppy... sorry...):
/**
* Windchill may return an oid which includes the server information. This
* information must not be present when looking up objects based on the oid.
* This method searches for any information after a second colon (the
* extraneous information) and removes it.
*
* @param oid the oid to get a local oid for.
* @return a local oid
*/
public static String getLocalOid(String oid) {
if (oid == null)
return null;
if(oid.indexOf("[") == 0 && oid.lastIndexOf("]") == oid.length()-1) oid = oid.substring(1, oid.length() - 1);
int firstColonLocation = oid.indexOf(':');
int lastColonLocation = oid.lastIndexOf(':');
if (lastColonLocation > 0 && lastColonLocation > firstColonLocation)
return oid.substring(0, lastColonLocation);
else
return oid;
}
-Thomas R. Busch
Sr. Software Developer
Stryker Instruments
(269) 323-7700 x4014
tom.busch@stryker.com<
true
if the role has at least one WTPrincipal in false
if not.