1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.web.form;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.uif.UifConstants;
20 import org.kuali.rice.krad.uif.UifParameters;
21
22 import java.io.Serializable;
23 import java.util.HashMap;
24 import java.util.Map;
25 import java.util.UUID;
26
27
28
29
30
31
32 public class HistoryManager implements Serializable {
33 private static final long serialVersionUID = 7612500634309569727L;
34
35 private Map<String, HistoryFlow> historyFlowMap = new HashMap<String, HistoryFlow>();
36 private Map<String, HistoryFlow> recentFlows = new HashMap<String, HistoryFlow>();
37
38
39
40
41
42
43
44
45
46
47
48
49
50 public HistoryFlow process(String flowKey, String formKey, String currentUrl) {
51 if (StringUtils.isBlank(flowKey) || flowKey.equalsIgnoreCase(UifConstants.HistoryFlow.START)) {
52 flowKey = UUID.randomUUID().toString();
53 }
54
55 HistoryFlow newFlow = new HistoryFlow(flowKey);
56
57 if (currentUrl.contains("?") && !currentUrl.contains(UifParameters.FORM_KEY) && StringUtils.isNotBlank(formKey)){
58 currentUrl = currentUrl + "&" + UifParameters.FORM_KEY + "=" + formKey;
59 }
60
61 if (getMostRecentFlowByFormKey(flowKey, formKey) != null) {
62 newFlow = getMostRecentFlowByFormKey(flowKey, formKey);
63 newFlow.update(currentUrl);
64 } else if (StringUtils.isNotBlank(flowKey)) {
65 HistoryFlow recentFlow = recentFlows.get(flowKey);
66 newFlow.continueFlow(recentFlow);
67 newFlow.push(currentUrl);
68 }
69
70 recentFlows.put(flowKey, newFlow);
71 historyFlowMap.put(flowKey + UifConstants.HistoryFlow.SEPARATOR + formKey, newFlow);
72
73 return newFlow;
74 }
75
76
77
78
79
80
81
82 public HistoryFlow getMostRecentFlowByKey(String key) {
83 if (StringUtils.isBlank(key)) {
84 return null;
85 }
86
87 return recentFlows.get(key);
88 }
89
90
91
92
93
94
95
96
97 public HistoryFlow getMostRecentFlowByFormKey(String key, String formKey) {
98 if (StringUtils.isBlank(key) || StringUtils.isBlank(formKey)) {
99 return null;
100 }
101
102 return historyFlowMap.get(key + UifConstants.HistoryFlow.SEPARATOR + formKey);
103 }
104 }