1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.web;
17
18 import org.kuali.rice.core.api.CoreApiServiceLocator;
19 import org.kuali.rice.core.api.config.property.ConfigurationService;
20
21 import java.util.HashMap;
22 import java.util.HashSet;
23 import java.util.LinkedList;
24 import java.util.Map;
25 import java.util.Queue;
26 import java.util.Set;
27 import java.util.UUID;
28 import java.util.Collections;
29
30
31
32
33
34
35
36
37
38
39 @Deprecated
40 public class EditablePropertiesHistoryHolder implements java.io.Serializable {
41 private Map<String, Set<String>> editablePropertiesMap;
42 private Integer maxLength = null;
43 private Queue<String> historyOrder;
44 private static final String EDITABLE_PROPERTIES_HISTORY_SIZE_PROPERTY_NAME = "kns.editable.properties.history.size";
45 private transient ConfigurationService configurationService;
46
47
48
49
50
51 public EditablePropertiesHistoryHolder() {
52 editablePropertiesMap = Collections.synchronizedMap(new HashMap<String, Set<String>>());
53 historyOrder = new LinkedList<String>();
54 }
55
56
57
58
59 public int getMaxHistoryLength() {
60 if (maxLength == null) {
61 final String historyLengthAsString = getConfigurationService().getPropertyValueAsString(
62 EditablePropertiesHistoryHolder.EDITABLE_PROPERTIES_HISTORY_SIZE_PROPERTY_NAME);
63 if (historyLengthAsString == null) {
64 maxLength = new Integer(20);
65 } else {
66 try {
67 maxLength = new Integer(historyLengthAsString);
68 } catch (NumberFormatException nfe) {
69 throw new RuntimeException("Cannot convert property "+EditablePropertiesHistoryHolder.EDITABLE_PROPERTIES_HISTORY_SIZE_PROPERTY_NAME+" with value "+historyLengthAsString+" to integer", nfe);
70 }
71 }
72 }
73 return maxLength.intValue();
74 }
75
76
77
78
79
80
81
82 public String addEditablePropertiesToHistory(Set<String> editableProperties) {
83 String guid = generateNewGuid();
84
85 if (getHistoryOrder().size() > getMaxHistoryLength()) {
86 final String guidForRemoval = getHistoryOrder().remove();
87 getEditablePropertiesMap().remove(guidForRemoval);
88 }
89 getHistoryOrder().add(guid);
90 getEditablePropertiesMap().put(guid, editableProperties);
91
92 return guid;
93 }
94
95
96
97
98
99 public String generateNewGuid() {
100 final String guid = UUID.randomUUID().toString();
101 return guid;
102 }
103
104
105
106
107
108
109 public Set<String> getEditableProperties(String guid) {
110 return getEditablePropertiesMap().get(guid);
111 }
112
113
114
115
116
117 public void clearEditableProperties(String guid) {
118 getEditablePropertiesMap().put(guid, createNewEditablePropertiesEntry());
119 }
120
121
122
123
124 protected Queue<String> getHistoryOrder() {
125 return historyOrder;
126 }
127
128
129
130
131 protected Map<String, Set<String>> getEditablePropertiesMap() {
132 return editablePropertiesMap;
133 }
134
135
136
137
138 protected Set<String> createNewEditablePropertiesEntry() {
139 return new HashSet<String>();
140 }
141
142
143
144
145 protected ConfigurationService getConfigurationService() {
146 if (configurationService == null) {
147 configurationService = CoreApiServiceLocator.getKualiConfigurationService();
148 }
149 return configurationService;
150 }
151 }