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