1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.clocklog.service;
17
18 import java.util.ArrayList;
19 import java.util.Iterator;
20 import java.util.List;
21 import java.util.Map;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.kuali.hr.job.Job;
25 import org.kuali.hr.time.clocklog.ClockLog;
26 import org.kuali.hr.time.department.Department;
27 import org.kuali.hr.time.missedpunch.MissedPunchDocument;
28 import org.kuali.hr.time.roles.TkRole;
29 import org.kuali.hr.time.service.base.TkServiceLocator;
30 import org.kuali.hr.time.util.TKContext;
31 import org.kuali.hr.time.util.TKUtils;
32 import org.kuali.hr.time.util.TkConstants;
33 import org.kuali.rice.kns.lookup.HtmlData;
34 import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
35 import org.kuali.rice.krad.bo.BusinessObject;
36
37 public class ClockLogLookupableHelper extends KualiLookupableHelperServiceImpl {
38
39
40
41 private static final long serialVersionUID = 1L;
42
43 @Override
44 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject,
45 List pkNames) {
46 List<HtmlData> customActionUrls = super.getCustomActionUrls(
47 businessObject, pkNames);
48 List<HtmlData> overrideUrls = new ArrayList<HtmlData>();
49
50
51 ClockLog clockLog = (ClockLog)businessObject;
52 MissedPunchDocument mpDoc = TkServiceLocator.getMissedPunchService().getMissedPunchByClockLogId(clockLog.getTkClockLogId());
53 if(mpDoc != null){
54 clockLog.setMissedPunchDocumentId(mpDoc.getDocumentNumber());
55 }
56
57 for(HtmlData actionUrl : customActionUrls){
58 if(!StringUtils.equals(actionUrl.getMethodToCall(), "copy")){
59 overrideUrls.add(actionUrl);
60 }
61 }
62 if (TKContext.getUser().isSystemAdmin() || TKContext.getUser().isGlobalViewOnly()) {
63 clockLog = (ClockLog) businessObject;
64 final String className = this.getBusinessObjectClass().getName();
65 final String tkClockLogId = clockLog.getTkClockLogId();
66 HtmlData htmlData = new HtmlData() {
67
68 @Override
69 public String constructCompleteHtmlTag() {
70 return "<a target=\"_blank\" href=\"inquiry.do?businessObjectClassName="
71 + className
72 + "&methodToCall=start&tkClockLogId="
73 + tkClockLogId + "\">view</a>";
74 }
75 };
76 overrideUrls.add(htmlData);
77 } else if (overrideUrls.size() != 0) {
78 overrideUrls.remove(0);
79 }
80 return overrideUrls;
81 }
82
83 @Override
84 public List<? extends BusinessObject> getSearchResults(
85 Map<String, String> fieldValues) {
86 List<? extends BusinessObject> objectList = super
87 .getSearchResults(fieldValues);
88
89 if (!objectList.isEmpty()) {
90 Iterator itr = objectList.iterator();
91 while (itr.hasNext()) {
92 ClockLog cl = (ClockLog) itr.next();
93 List<TkRole> tkRoles = TkServiceLocator.getTkRoleService()
94 .getRoles(TKContext.getPrincipalId(),
95 TKUtils.getCurrentDate());
96 Job job = TkServiceLocator.getJobService().getJob(
97 cl.getUserPrincipalId(), cl.getJobNumber(),
98 TKUtils.getCurrentDate(), false);
99 boolean valid = false;
100 for (TkRole tkRole : tkRoles) {
101 if (StringUtils.equals(tkRole.getRoleName(),
102 TkConstants.ROLE_TK_SYS_ADMIN)
103 || (StringUtils.equals(tkRole.getRoleName(),
104 TkConstants.ROLE_TK_APPROVER) && cl
105 .getWorkArea().equals(tkRole.getWorkArea()))
106 || (StringUtils.equals(tkRole.getRoleName(),
107 TkConstants.ROLE_TK_DEPT_ADMIN) && (job != null && (job
108 .getDept().equals(tkRole.getDepartment()))))) {
109 valid = true;
110 break;
111 }
112 if(StringUtils.equals(tkRole.getRoleName(), TkConstants.ROLE_TK_LOCATION_ADMIN) && job != null && tkRole.getLocationObj()!=null){
113 List<Department> departments = TkServiceLocator.getDepartmentService().getDepartmentByLocation(tkRole.getLocationObj().getLocation());
114 for(Department department : departments){
115 if(StringUtils.equals(job.getDept(), department.getDept())){
116 valid = true;
117 break;
118 }
119 }
120 if(valid){
121 break;
122 }
123 }
124 }
125 if (!valid) {
126 itr.remove();
127 continue;
128 }
129 }
130 }
131 return objectList;
132 }
133
134
135 }