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