1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.roles.service;
17
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.Properties;
23
24 import org.apache.commons.lang.StringUtils;
25 import org.kuali.hr.time.HrEffectiveDateActiveLookupableHelper;
26 import org.kuali.hr.time.roles.TkRoleGroup;
27 import org.kuali.hr.time.service.base.TkServiceLocator;
28 import org.kuali.hr.time.util.TKContext;
29 import org.kuali.hr.time.util.TKUtils;
30 import org.kuali.rice.kns.lookup.HtmlData;
31 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
32 import org.kuali.rice.krad.bo.BusinessObject;
33 import org.kuali.rice.krad.util.KRADConstants;
34 import org.kuali.rice.krad.util.UrlFactory;
35
36 public class TkRoleLookupableHelper extends HrEffectiveDateActiveLookupableHelper {
37
38 @Override
39 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
40 List<HtmlData> customActionUrls = new ArrayList<HtmlData>();
41
42 List<HtmlData> defaultCustomActionUrls = super.getCustomActionUrls(businessObject, pkNames);
43
44 TkRoleGroup tkRoleGroup = (TkRoleGroup) businessObject;
45 String principalId = tkRoleGroup.getPrincipalId();
46 String location = null;
47 if (StringUtils.isNotBlank(tkRoleGroup.getDepartment())) {
48 location = TkServiceLocator.getDepartmentService().getDepartment(tkRoleGroup.getDepartment(), TKUtils.getCurrentDate()).getLocation();
49 }
50 String department = tkRoleGroup.getDepartment();
51
52 boolean systemAdmin = TKContext.getUser().isSystemAdmin();
53 boolean locationAdmin = TKContext.getUser().getLocationAdminAreas().contains(location);
54 boolean departmentAdmin = TKContext.getUser().getDepartmentAdminAreas().contains(department);
55
56 for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){
57 if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) {
58 if (systemAdmin || locationAdmin || departmentAdmin) {
59 customActionUrls.add(defaultCustomActionUrl);
60 }
61 } else {
62 customActionUrls.add(defaultCustomActionUrl);
63 }
64 }
65
66 Properties params = new Properties();
67 params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
68 params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
69 params.put("principalId", principalId);
70 AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
71 viewUrl.setDisplayText("view");
72 viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
73 customActionUrls.add(viewUrl);
74
75 return customActionUrls;
76 }
77
78 @Override
79 public List<? extends BusinessObject> getSearchResults(
80 Map<String, String> fieldValues) {
81
82 String principalId = fieldValues.get("principalId");
83 String principalName = fieldValues.get("principalName");
84 String workArea = fieldValues.get("workArea");
85 String department = fieldValues.get("department");
86 String roleName = fieldValues.get("roleName");
87
88 List<TkRoleGroup> roleGroupList = TkServiceLocator.getTkRoleGroupService().getRoleGroups(principalId, principalName, workArea, department, roleName);
89
90
91
92 for(TkRoleGroup roleGroup : roleGroupList){
93 TkRoleGroup tkRoleGroup = TkServiceLocator.getTkRoleGroupService().getRoleGroup(roleGroup.getPrincipalId());
94 if(tkRoleGroup == null){
95 tkRoleGroup = new TkRoleGroup();
96 tkRoleGroup.setPrincipalId(roleGroup.getPrincipalId());
97 TkServiceLocator.getTkRoleGroupService().saveOrUpdate(roleGroup);
98 }
99 }
100
101
102 Map<String,TkRoleGroup> mapDistinctPrincipalIdsToRoleGroups = new HashMap<String, TkRoleGroup>();
103 for(TkRoleGroup roleGroup : roleGroupList){
104 mapDistinctPrincipalIdsToRoleGroups.put(roleGroup.getPrincipalId(), roleGroup);
105 }
106 List<TkRoleGroup> distinctRoleGroupPrincipalIds = new ArrayList<TkRoleGroup>();
107 for(String distinctPrincipalId : mapDistinctPrincipalIdsToRoleGroups.keySet()){
108 distinctRoleGroupPrincipalIds.add(mapDistinctPrincipalIdsToRoleGroups.get(distinctPrincipalId));
109 }
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171 return distinctRoleGroupPrincipalIds;
172 }
173 }