cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Workflow Code - Check for User present, even if via Group

SteveVinyard
1-Newbie

Workflow Code - Check for User present, even if via Group

Hi guys, this one is giving me trouble. I have some legacy code I'm trying to update and bring forward. Basically the code checks to ensure one of many people are included as Approvers. If they are included directly (user added directly) it works fine. If they are included via a group, it does not work. Used to work in 9.1. Any ideas? I hope I'm missing something simple here. Thanks!


The Problem:

* In the 9.1 system, the system was capable of checking the group to see if one of the users was in the group.

* In the 10.1 system, the system is no longer recognizing that there is one of these "approved" users if they are in a group and not individually selected during the promotion creation request.

o So these are the scenarios:

1. User is member of approver role = Working

2. User is selected individually on promotion request creation wizard = Working

3. User is a member of a group on the approvers role = Not Working

4. Uses is a member of a group selected on the promotion request creation wizard = Not Working

The Setup:

* The Conditional block has code which is meant to determine is one of a few users was selected by the person creating the promotion request.

* If One of the users was not selected, the creator would get a task to assign on of the users

* There is a managers group associated to the approvers role and one of the listed users is a member of the group

[cid:image001.png@01CF684C.E81EF5A0]
boolean provider = false;
java.lang.String userName;
wt.workflow.engine.WfProcess wfprocess = ((wt.workflow.engine.WfProcess)(self.getObject()));
java.util.Enumeration roles = wfprocess.getRoles();
while (roles.hasMoreElements())
{
wt.project.Role role = (wt.project.Role)roles.nextElement();
if (role.getDisplay().equalsIgnoreCase("Approver"))
{
java.util.Enumeration principals= wfprocess.getPrincipals(role);
while (principals.hasMoreElements())
{
System.out.println ("get the first principal");
wt.org.WTPrincipalReference principalref = (wt.org.WTPrincipalReference)principals.nextElement();
System.out.println ("principalref = "+principalref);
userName=principalref.getFullName( );
if (userName.equals("John Doe") || userName.equals("Jane Smith") || userName.equals("John Smith") || userName.equals("Jane Doe")|| userName.equals("Jannet Doe") || userName.equals("Dan Doe") || userName.equals("Matt Smith") || userName.equals("Michael Smith")) \\This<file: \\this="> is the list of approved users, one of these users needs to be selected as an approver for the workflow to continue
{
provider=true;
}
} // end while
} // end if role "approver"
} // end while roles have more elements

if (provider) result="continue";
else
{
result="assignChangeAdmin";
}

7 REPLIES 7

When I run the code it prints out this (the group name) instead of the user obviously.

2014-05-06 12:33:19,454 INFO [WfPropagationQueue.PollingThread] wt.system.out administrator - get the first principal
2014-05-06 12:33:19,454 INFO [WfPropagationQueue.PollingThread] wt.system.out administrator - principal = Engineering Manager Group

Just a guess...
10.x treats the users First, Middle, Last names differently in the WTUser table - and I believe there may a property or preference to display First Last or Last, First such that it may not match LDAP.
Multiple variations with 10.x on this also. As the result of upgrading from 9.1 to 10.1 our WTUser table has "John Smith" in the First field of WTUser for all users.
Maybe this is affecting resolution of "John Smith?"


Steve,

You need to modify the code to validate the result enumeration value is a WTUser or WTGroup,in this case it is wtgroup.

if it is WTUser , the existing code will work fine else look up the user as member on resulted group.

hope this will help you.



Regards
Ramanathan MK
9611 343094

Hi Mike,

i agree on your guess, we had a same issue in displaying name on Info Page, after upgrade from 9.1 m72 to 10.1 m20.

Steve,

you can print the user name.


Regards
Ramanathan MK
9611 343094


Option 1:
Use user id instead of full name. Add code to do the type check and then type cast to WTUser.
String userID = wtUser.getAuthenticationName();

Option 2:
I don't remember exactly, but when principals are calculated from workflow, it automatically get users even groups are assigned to roles.
But this behavior is different when you extract principals from Team object.
I would recommend to rewrite the code to consider principals to take care of WTUser/WTGroup/WTOrganization if option 1 not works, still you need to user userID instead of fullName.
Run the recursive check for groups and group might have groups + users......

Thanks
Ayyappan

You can check if the principal is a group or a wtuser like this:

wt.org.WTPrincipalReference principalref = (wt.org.WTPrincipalReference)principals.nextElement();
if(principalref instanceof wt.org.WTUser)
{
//wtuser
System.out.println("Here at a user: user name = " + principalref.getName());
}
else
{
//group
System.out.println("Here at a group:: group name = " + principalref.getName());
wt.org.WTGroup wtgroup = (wt.org.WTGroup)principalref;
for(java.util.Enumeration en = wtgroup.members(); en.hasMoreElements();)
{
//member of a group
wt.org.WTUser wtuser = (wt.org.WTUser)en.nextElement();
System.out.println("Here at group for loop at a user: user name = " + wtuser.getName());
}
}

Thanks guys, the method below (from a couple of other users too) worked well!
Announcements

Top Tags