1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.util;
17
18 import java.util.ArrayList;
19 import java.util.HashSet;
20 import java.util.List;
21 import java.util.Set;
22 import java.util.SortedSet;
23 import java.util.TreeSet;
24
25 import org.kuali.hr.time.roles.TkUserRoles;
26 import org.kuali.hr.time.roles.UserRoles;
27 import org.kuali.hr.time.service.base.TkServiceLocator;
28 import org.kuali.hr.time.workarea.WorkArea;
29 import org.kuali.rice.kim.api.identity.Person;
30 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
31 import org.kuali.rice.krad.util.GlobalVariables;
32
33 import com.google.common.collect.Multimap;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 public class TKUser {
58
59 public static void setTargetPerson(String principalId) {
60 GlobalVariables.getUserSession().addObject(TkConstants.TK_TARGET_USER_PERSON, principalId);
61 }
62
63 public static boolean isTargetInUse() {
64 return GlobalVariables.getUserSession().retrieveObject(TkConstants.TK_TARGET_USER_PERSON) != null;
65 }
66
67 public static void clearTargetUser() {
68 GlobalVariables.getUserSession().removeObject(TkConstants.TK_TARGET_USER_PERSON);
69 }
70
71
72
73
74
75
76
77 public static String getCurrentTargetPersonId() {
78 String p = (String) GlobalVariables.getUserSession().retrieveObject(TkConstants.TK_TARGET_USER_PERSON);
79 if (p == null) {
80 p = GlobalVariables.getUserSession().getPerson().getPrincipalId();
81 }
82 return p;
83 }
84
85
86
87
88
89
90
91 public static Person getCurrentTargetPerson() {
92 Person p;
93 String principalId = (String) GlobalVariables.getUserSession().retrieveObject(TkConstants.TK_TARGET_USER_PERSON);
94 if (principalId == null) {
95 p = GlobalVariables.getUserSession().getPerson();
96 } else {
97 p = KimApiServiceLocator.getPersonService().getPerson(principalId);
98 }
99 return p;
100 }
101
102
103
104
105
106
107
108 public static UserRoles getCurrentTargetRoles() {
109 return TkUserRoles.getUserRoles(getCurrentTargetPersonId());
110 }
111
112
113
114
115
116
117
118 public static boolean isSystemAdmin() {
119 return TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId()).isSystemAdmin();
120 }
121
122 public static boolean isLocationAdmin() {
123 return TKUser.getLocationAdminAreas().size() > 0;
124 }
125
126 public static boolean isDepartmentAdmin() {
127 return TKUser.getDepartmentAdminAreas().size() > 0;
128 }
129
130 public static boolean isGlobalViewOnly() {
131 return TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId()).isGlobalViewOnly();
132 }
133
134 public static boolean isDeptViewOnly() {
135 return TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId()).isDeptViewOnly();
136 }
137
138 public static boolean isActiveEmployee() {
139 return TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId()).isActiveEmployee();
140 }
141
142 public static boolean isSynchronous() {
143 return TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId()).isSynchronous();
144 }
145
146 public static boolean isReviewer() {
147 return TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId()).isReviewer();
148 }
149
150 public static boolean isApprover() {
151 return TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId()).isApprover();
152 }
153
154 public static boolean isTimesheetReviewer() {
155 return TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId()).isTimesheetReviewer();
156 }
157
158 public static boolean isTimesheetApprover() {
159 return TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId()).isTimesheetApprover();
160 }
161
162 public static boolean isAnyApproverActive() {
163 return TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId()).isAnyApproverActive();
164 }
165
166 public static boolean isApproverForTimesheet(String docId) {
167 return TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId()).isApproverForTimesheet(docId);
168 }
169
170 public static boolean isDocumentReadable(String documentId) {
171 return TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId()).isDocumentReadable(documentId);
172 }
173
174 public static boolean isDocumentWritable(String documentId) {
175 return TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId()).isDocumentWritable(documentId);
176 }
177
178 public static Multimap<String, Long> getReportingApprovalDepartments(){
179 UserRoles userRoles = TkUserRoles.getUserRoles(TKContext.getTargetPrincipalId());
180 Set<Long> workAreas = new HashSet<Long>();
181 workAreas.addAll(userRoles.getApproverWorkAreas());
182 workAreas.addAll(userRoles.getReviewerWorkAreas());
183
184 Multimap<String, Long> reportingApprovalDepartments = TkServiceLocator.getTimeApproveService().getDeptWorkAreasByWorkAreas(workAreas);
185
186
187
188
189
190
191
192
193
194 return reportingApprovalDepartments;
195 }
196
197 public static Set<Long> getReportingWorkAreas(){
198 UserRoles userRoles = TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId());
199 Set<Long> reportingWorkAreas = new HashSet<Long>();
200 List<String> depts = new ArrayList<String>();
201
202 reportingWorkAreas.addAll(userRoles.getApproverWorkAreas());
203 for(Long workArea : userRoles.getApproverWorkAreas()){
204 if(!reportingWorkAreas.contains(workArea)){
205 reportingWorkAreas.add(workArea);
206 }
207 }
208
209 for(Long workArea : userRoles.getReviewerWorkAreas()){
210 if(!reportingWorkAreas.contains(workArea)){
211 reportingWorkAreas.add(workArea);
212 }
213 }
214
215 reportingWorkAreas.addAll(userRoles.getReviewerWorkAreas());
216
217 depts.addAll(userRoles.getDepartmentViewOnlyDepartments());
218 depts.addAll(userRoles.getOrgAdminDepartments());
219
220 for(String dept : depts){
221 List<WorkArea> workAreas = TkServiceLocator.getWorkAreaService().getWorkAreas(dept, TKUtils.getCurrentDate());
222 for(WorkArea workArea : workAreas){
223 if(!reportingWorkAreas.contains(workArea.getWorkArea())){
224 reportingWorkAreas.add(workArea.getWorkArea());
225 }
226 }
227 }
228
229
230 return reportingWorkAreas;
231 }
232
233 public static Set<Long> getApproverWorkAreas() {
234 return TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId()).getApproverWorkAreas();
235 }
236
237 public static Set<Long> getReviewerWorkAreas() {
238 return TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId()).getReviewerWorkAreas();
239 }
240
241 public static Set<String> getLocationAdminAreas() {
242 return TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId()).getOrgAdminCharts();
243 }
244
245 public static Set<String> getDepartmentAdminAreas() {
246 return TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId()).getOrgAdminDepartments();
247 }
248
249 public static SortedSet<Long> getWorkAreasFromUserRoles() {
250 UserRoles userRoles = TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId());
251 SortedSet<Long> workAreas = new TreeSet<Long>();
252 workAreas.addAll(userRoles.getApproverWorkAreas());
253 workAreas.addAll(userRoles.getReviewerWorkAreas());
254
255 if(userRoles.isDepartmentAdmin()){
256 Set<String> deptAdminDepts = userRoles.getOrgAdminDepartments();
257 for(String dept : deptAdminDepts){
258 List<WorkArea> was = TkServiceLocator.getWorkAreaService().getWorkAreas(dept, TKUtils.getCurrentDate());
259 for(WorkArea wa : was){
260 workAreas.add(wa.getWorkArea());
261 }
262 }
263 }
264
265 return workAreas;
266 }
267
268 }