1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.time.util;
17
18 import java.util.List;
19
20 import org.joda.time.DateTime;
21 import org.joda.time.LocalDate;
22 import org.kuali.kpme.core.KPMENamespace;
23 import org.kuali.kpme.core.assignment.Assignment;
24 import org.kuali.kpme.core.role.KPMERole;
25 import org.kuali.kpme.core.service.HrServiceLocator;
26 import org.kuali.kpme.core.util.HrConstants;
27 import org.kuali.kpme.tklm.time.rules.timecollection.TimeCollectionRule;
28 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
29 import org.kuali.rice.krad.util.GlobalVariables;
30
31 public class TkContext {
32
33 public static String getPrincipalId() {
34 return GlobalVariables.getUserSession().getPrincipalId();
35 }
36
37 public static boolean isLocationAdmin() {
38 return HrServiceLocator.getKPMERoleService().principalHasRole(getPrincipalId(), KPMENamespace.KPME_TK.getNamespaceCode(), KPMERole.TIME_LOCATION_ADMINISTRATOR.getRoleName(), LocalDate.now().toDateTimeAtStartOfDay())
39 || HrServiceLocator.getKPMERoleService().principalHasRole(getPrincipalId(), KPMENamespace.KPME_LM.getNamespaceCode(), KPMERole.LEAVE_LOCATION_ADMINISTRATOR.getRoleName(), LocalDate.now().toDateTimeAtStartOfDay());
40 }
41
42 public static boolean isTargetLocationAdmin() {
43 return HrServiceLocator.getKPMERoleService().principalHasRole(getTargetPrincipalId(), KPMENamespace.KPME_TK.getNamespaceCode(), KPMERole.TIME_LOCATION_ADMINISTRATOR.getRoleName(), LocalDate.now().toDateTimeAtStartOfDay())
44 || HrServiceLocator.getKPMERoleService().principalHasRole(getTargetPrincipalId(), KPMENamespace.KPME_LM.getNamespaceCode(), KPMERole.LEAVE_LOCATION_ADMINISTRATOR.getRoleName(), LocalDate.now().toDateTimeAtStartOfDay());
45 }
46
47 public static boolean isLocationViewOnly() {
48 return HrServiceLocator.getKPMERoleService().principalHasRole(getPrincipalId(), KPMENamespace.KPME_TK.getNamespaceCode(), KPMERole.TIME_LOCATION_VIEW_ONLY.getRoleName(), LocalDate.now().toDateTimeAtStartOfDay())
49 || HrServiceLocator.getKPMERoleService().principalHasRole(getPrincipalId(), KPMENamespace.KPME_LM.getNamespaceCode(), KPMERole.LEAVE_LOCATION_VIEW_ONLY.getRoleName(), LocalDate.now().toDateTimeAtStartOfDay());
50 }
51
52 public static boolean isTargetLocationViewOnly() {
53 return HrServiceLocator.getKPMERoleService().principalHasRole(getTargetPrincipalId(), KPMENamespace.KPME_TK.getNamespaceCode(), KPMERole.TIME_LOCATION_VIEW_ONLY.getRoleName(), LocalDate.now().toDateTimeAtStartOfDay())
54 || HrServiceLocator.getKPMERoleService().principalHasRole(getTargetPrincipalId(), KPMENamespace.KPME_LM.getNamespaceCode(), KPMERole.LEAVE_LOCATION_VIEW_ONLY.getRoleName(), LocalDate.now().toDateTimeAtStartOfDay());
55 }
56
57 public static boolean isDepartmentAdmin() {
58 return HrServiceLocator.getKPMERoleService().principalHasRole(getPrincipalId(), KPMENamespace.KPME_TK.getNamespaceCode(), KPMERole.TIME_DEPARTMENT_ADMINISTRATOR.getRoleName(), LocalDate.now().toDateTimeAtStartOfDay())
59 || HrServiceLocator.getKPMERoleService().principalHasRole(getPrincipalId(), KPMENamespace.KPME_LM.getNamespaceCode(), KPMERole.LEAVE_DEPARTMENT_ADMINISTRATOR.getRoleName(), LocalDate.now().toDateTimeAtStartOfDay());
60 }
61
62 public static boolean isTargetDepartmentAdmin() {
63 return HrServiceLocator.getKPMERoleService().principalHasRole(getTargetPrincipalId(), KPMENamespace.KPME_TK.getNamespaceCode(), KPMERole.TIME_DEPARTMENT_ADMINISTRATOR.getRoleName(), LocalDate.now().toDateTimeAtStartOfDay())
64 || HrServiceLocator.getKPMERoleService().principalHasRole(getTargetPrincipalId(), KPMENamespace.KPME_LM.getNamespaceCode(), KPMERole.LEAVE_DEPARTMENT_ADMINISTRATOR.getRoleName(), LocalDate.now().toDateTimeAtStartOfDay());
65 }
66
67 public static boolean isDepartmentViewOnly() {
68 return HrServiceLocator.getKPMERoleService().principalHasRole(getPrincipalId(), KPMENamespace.KPME_TK.getNamespaceCode(), KPMERole.TIME_DEPARTMENT_VIEW_ONLY.getRoleName(), LocalDate.now().toDateTimeAtStartOfDay())
69 || HrServiceLocator.getKPMERoleService().principalHasRole(getPrincipalId(), KPMENamespace.KPME_LM.getNamespaceCode(), KPMERole.LEAVE_DEPARTMENT_VIEW_ONLY.getRoleName(), LocalDate.now().toDateTimeAtStartOfDay());
70 }
71
72 public static boolean isTargetDepartmentViewOnly() {
73 return HrServiceLocator.getKPMERoleService().principalHasRole(getTargetPrincipalId(), KPMENamespace.KPME_TK.getNamespaceCode(), KPMERole.TIME_DEPARTMENT_VIEW_ONLY.getRoleName(), LocalDate.now().toDateTimeAtStartOfDay())
74 || HrServiceLocator.getKPMERoleService().principalHasRole(getTargetPrincipalId(), KPMENamespace.KPME_LM.getNamespaceCode(), KPMERole.LEAVE_DEPARTMENT_VIEW_ONLY.getRoleName(), LocalDate.now().toDateTimeAtStartOfDay());
75 }
76
77 public static String getTargetPrincipalId() {
78 String principalId = (String) GlobalVariables.getUserSession().retrieveObject(HrConstants.TK_TARGET_USER_PERSON);
79 if (principalId == null) {
80 principalId = GlobalVariables.getUserSession().getPerson().getPrincipalId();
81 }
82 return principalId;
83 }
84
85 public static boolean isSynchronous() {
86 boolean isSynchronous = false;
87
88 List<Assignment> assignments = HrServiceLocator.getAssignmentService().getAssignments(getPrincipalId(), LocalDate.now());
89
90 for (Assignment assignment : assignments) {
91 TimeCollectionRule tcr = null;
92 if(assignment.getJob() != null)
93 tcr = TkServiceLocator.getTimeCollectionRuleService().getTimeCollectionRule(assignment.getDept(), assignment.getWorkArea(), assignment.getJob().getHrPayType(), LocalDate.now());
94 if (tcr == null || tcr.isClockUserFl()) {
95 isSynchronous = true;
96 break;
97 }
98 }
99
100 return isSynchronous;
101 }
102
103 public static boolean isTargetSynchronous() {
104 boolean isSynchronous = false;
105
106 List<Assignment> assignments = HrServiceLocator.getAssignmentService().getAssignments(getTargetPrincipalId(), LocalDate.now());
107
108 for (Assignment assignment : assignments) {
109 TimeCollectionRule tcr = null;
110 if(assignment.getJob() != null)
111 tcr = TkServiceLocator.getTimeCollectionRuleService().getTimeCollectionRule(assignment.getDept(), assignment.getWorkArea(), assignment.getJob().getHrPayType(), LocalDate.now());
112 if (tcr == null || tcr.isClockUserFl()) {
113 isSynchronous = true;
114 break;
115 }
116 }
117
118 return isSynchronous;
119 }
120
121 }