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.TkConstants;
29 import org.kuali.rice.core.api.util.ConcreteKeyValue;
30 import org.kuali.rice.core.api.util.KeyValue;
31 import org.kuali.rice.kns.web.struts.form.KualiForm;
32 import org.kuali.rice.kns.web.struts.form.KualiTransactionalDocumentFormBase;
33 import org.kuali.rice.krad.keyvalues.KeyValuesBase;
34
35 public class TkClockActionValuesFinder extends KeyValuesBase {
36
37 @Override
38 public List getKeyValues() {
39 List<KeyValue> keyLabels = new LinkedList<KeyValue>();
40
41 String mpDocId = (String)TKContext.getHttpServletRequest().getParameter(TkConstants.DOCUMENT_ID_REQUEST_NAME);
42 if(StringUtils.isBlank(mpDocId)) {
43 mpDocId = (String)TKContext.getHttpServletRequest().getAttribute(TkConstants.DOCUMENT_ID_REQUEST_NAME);
44 if(StringUtils.isBlank(mpDocId)){
45 KualiForm kualiForm = (KualiForm)TKContext.getHttpServletRequest().getAttribute("KualiForm");
46 if(kualiForm instanceof KualiTransactionalDocumentFormBase){
47 mpDocId = ((KualiTransactionalDocumentFormBase)kualiForm).getDocId();
48 }
49 }
50 if(StringUtils.isBlank(mpDocId)){
51 mpDocId = (String)TKContext.getHttpServletRequest().getParameter("docId");
52 }
53 }
54
55 if(!StringUtils.isEmpty(mpDocId)) {
56 MissedPunchDocument mp = TkServiceLocator.getMissedPunchService().getMissedPunchByRouteHeader(mpDocId);
57 if(mp != null) {
58 String clockAction = mp.getClockAction();
59 if(!StringUtils.isEmpty(clockAction)) {
60 Set<String> availableActions = TkConstants.CLOCK_AVAILABLE_ACTION_MAP.get(clockAction);
61 for (String entry : availableActions) {
62 keyLabels.add(new ConcreteKeyValue(entry, TkConstants.CLOCK_ACTION_STRINGS.get(entry)));
63 }
64 }
65 }
66 } else {
67 ClockLog lastClock = TkServiceLocator.getClockLogService().getLastClockLog(TKUser.getCurrentTargetPerson().getPrincipalId());
68 Set<String> validEntries = lastClock != null ?
69 TkConstants.CLOCK_ACTION_TRANSITION_MAP.get(lastClock.getClockAction()) :
70 TkConstants.CLOCK_ACTION_TRANSITION_MAP.get(TkConstants.CLOCK_OUT);
71 for (String entry : validEntries) {
72 keyLabels.add(new ConcreteKeyValue(entry, TkConstants.CLOCK_ACTION_STRINGS.get(entry)));
73 }
74 }
75
76 if(keyLabels.isEmpty()) {
77 for (Map.Entry entry : TkConstants.CLOCK_ACTION_STRINGS.entrySet()) {
78 keyLabels.add(new ConcreteKeyValue((String)entry.getKey(), (String)entry.getValue()));
79 }
80 }
81 return keyLabels;
82 }
83
84 }