1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.businessobject.defaultvalue;
17
18 import org.kuali.ole.select.OleSelectConstant;
19 import org.kuali.rice.core.api.membership.MemberType;
20 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
21 import org.kuali.rice.krad.util.GlobalVariables;
22 import org.kuali.rice.krad.valuefinder.ValueFinder;
23
24 import java.util.ArrayList;
25 import java.util.Iterator;
26 import java.util.List;
27
28
29
30 public class DefaultValueLoggedInUser implements ValueFinder {
31
32 @Override
33 public String getValue() {
34
35 boolean flag = false;
36 String role = getRole();
37 String principalName = null;
38 List<String> roleImpl = getRolesForPrincipal(GlobalVariables.getUserSession().getPrincipalId());
39 Iterator itr = roleImpl.iterator();
40 while (itr.hasNext()) {
41 String kimrole = itr.next().toString();
42 if (KimApiServiceLocator.getRoleService().getRole(kimrole) != null) {
43 if (KimApiServiceLocator.getRoleService().getRole(kimrole).getName().equalsIgnoreCase(role)) {
44 flag = true;
45 principalName = null;
46 }
47 }
48 }
49 if (!flag) {
50 principalName = GlobalVariables.getUserSession().getPrincipalId();
51 }
52 return principalName;
53 }
54
55 @SuppressWarnings("unchecked")
56 private List<String> getRolesForPrincipal(String principalId) {
57 if (principalId == null) {
58 return new ArrayList<String>();
59 }
60
61
62
63
64 return (List<String>) KimApiServiceLocator.getRoleService().getMemberParentRoleIds(MemberType.PRINCIPAL.getCode(), principalId);
65 }
66
67 public String getRole() {
68 return OleSelectConstant.SYSTEM_USER_ROLE_NAME;
69 }
70
71 }