1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.clocklog;
17
18 import java.util.LinkedList;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.Set;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.kuali.hr.time.missedpunch.MissedPunchDocument;
25 import org.kuali.hr.time.service.base.TkServiceLocator;
26 import org.kuali.hr.time.util.TKContext;
27 import org.kuali.hr.time.util.TKUser;
28 import org.kuali.hr.time.util.TKUtils;
29 import org.kuali.hr.time.util.TkConstants;
30 import org.kuali.rice.core.api.util.ConcreteKeyValue;
31 import org.kuali.rice.core.api.util.KeyValue;
32 import org.kuali.rice.kns.web.struts.form.KualiForm;
33 import org.kuali.rice.kns.web.struts.form.KualiTransactionalDocumentFormBase;
34 import org.kuali.rice.krad.keyvalues.KeyValuesBase;
35
36 public class TkClockActionValuesFinder extends KeyValuesBase {
37
38 @Override
39 public List<KeyValue> getKeyValues() {
40 List<KeyValue> keyLabels = new LinkedList<KeyValue>();
41
42 String mpDocId = (String)TKContext.getHttpServletRequest().getParameter(TkConstants.DOCUMENT_ID_REQUEST_NAME);
43 if(StringUtils.isBlank(mpDocId)) {
44 mpDocId = (String)TKContext.getHttpServletRequest().getAttribute(TkConstants.DOCUMENT_ID_REQUEST_NAME);
45 if(StringUtils.isBlank(mpDocId)){
46 KualiForm kualiForm = (KualiForm)TKContext.getHttpServletRequest().getAttribute("KualiForm");
47 if(kualiForm instanceof KualiTransactionalDocumentFormBase){
48 mpDocId = ((KualiTransactionalDocumentFormBase)kualiForm).getDocId();
49 }
50 }
51 if(StringUtils.isBlank(mpDocId)){
52 mpDocId = (String)TKContext.getHttpServletRequest().getParameter("docId");
53 }
54 }
55
56 if(!StringUtils.isEmpty(mpDocId)) {
57 MissedPunchDocument mp = TkServiceLocator.getMissedPunchService().getMissedPunchByRouteHeader(mpDocId);
58 if(mp != null) {
59 String clockAction = mp.getClockAction();
60 if(!StringUtils.isEmpty(clockAction)) {
61 Set<String> availableActions = TkConstants.CLOCK_AVAILABLE_ACTION_MAP.get(clockAction);
62 for (String entry : availableActions) {
63 keyLabels.add(new ConcreteKeyValue(entry, TkConstants.CLOCK_ACTION_STRINGS.get(entry)));
64 }
65 }
66 }
67 } else {
68 String targetPerson = TKUser.getCurrentTargetPerson().getPrincipalId();
69 ClockLog lastClock = TkServiceLocator.getClockLogService().getLastClockLog(targetPerson);
70 Set<String> validEntries = lastClock != null ?
71 TkConstants.CLOCK_ACTION_TRANSITION_MAP.get(lastClock.getClockAction()) :
72 TkConstants.CLOCK_ACTION_TRANSITION_MAP.get(TkConstants.CLOCK_OUT);
73 for (String entry : validEntries) {
74 keyLabels.add(new ConcreteKeyValue(entry, TkConstants.CLOCK_ACTION_STRINGS.get(entry)));
75 }
76
77 if(lastClock != null){
78 String dept = TkServiceLocator.getJobService().getJob(targetPerson, lastClock.getJobNumber(), TKUtils.getCurrentDate()).getDept();
79 Long workArea = lastClock.getWorkArea();
80 Long jobNumber = lastClock.getJobNumber();
81
82 if (!TkServiceLocator.getSystemLunchRuleService().getSystemLunchRule(TKUtils.getCurrentDate()).getShowLunchButton()) {
83 keyLabels.remove(new ConcreteKeyValue("LO", "Lunch Out"));
84 keyLabels.remove(new ConcreteKeyValue("LI", "Lunch In"));
85 } else {
86 if (TkServiceLocator.getDepartmentLunchRuleService().getDepartmentLunchRule(dept, workArea, targetPerson, jobNumber,TKUtils.getCurrentDate()) != null) {
87 keyLabels.remove(new ConcreteKeyValue("LO", "Lunch Out"));
88 keyLabels.remove(new ConcreteKeyValue("LI", "Lunch In"));
89 }
90 }
91 }
92
93 }
94
95 if(keyLabels.isEmpty()) {
96 for (Map.Entry entry : TkConstants.CLOCK_ACTION_STRINGS.entrySet()) {
97 keyLabels.add(new ConcreteKeyValue((String)entry.getKey(), (String)entry.getValue()));
98 }
99 }
100 return keyLabels;
101 }
102
103 }