1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.dto;
17
18 import org.apache.commons.lang.StringEscapeUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.krms.api.repository.proposition.PropositionDefinitionContract;
21 import org.kuali.rice.krms.api.repository.proposition.PropositionParameterContract;
22 import org.kuali.rice.krms.api.repository.term.TermDefinition;
23 import org.kuali.rice.krms.impl.ui.TermParameter;
24
25 import java.io.ByteArrayOutputStream;
26 import java.io.OutputStreamWriter;
27 import java.io.Serializable;
28 import java.nio.charset.Charset;
29 import java.util.ArrayList;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.UUID;
34
35
36
37
38 public class PropositionEditor implements PropositionDefinitionContract, Serializable {
39
40 private static final long serialVersionUID = 1L;
41
42 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PropositionEditor.class);
43
44 private String key;
45
46 private String id;
47 private String description;
48 private String ruleId;
49 private String compoundOpCode;
50 private Integer compoundSequenceNumber;
51 private String typeId;
52 private String propositionTypeCode;
53 private Long versionNumber;
54
55
56 private Map<String, String> naturalLanguage = new HashMap<String, String>();
57
58 private List<PropositionParameterEditor> parameters;
59 private List<PropositionEditor> compoundEditors;
60
61 private TermEditor term;
62 private String termParameter;
63 private List<TermParameter> termParameterList = new ArrayList<TermParameter>();
64 private String type;
65 private boolean editMode = false;
66 private boolean newProp = false;
67
68 private String bindingPath;
69 private String newTermDescription = "new term " + UUID.randomUUID().toString();
70
71 public PropositionEditor() {
72 super();
73 }
74
75
76
77
78
79
80
81 public PropositionEditor(PropositionDefinitionContract definition) {
82 this.id = definition.getId();
83 this.description = definition.getDescription();
84 this.ruleId = definition.getRuleId();
85
86 this.typeId = definition.getTypeId();
87 this.propositionTypeCode = definition.getPropositionTypeCode();
88 this.parameters = new ArrayList<PropositionParameterEditor>();
89 for (PropositionParameterContract parm : definition.getParameters()) {
90 this.parameters.add(new PropositionParameterEditor(parm));
91 }
92 this.compoundOpCode = definition.getCompoundOpCode();
93 this.compoundSequenceNumber = definition.getCompoundSequenceNumber();
94 this.compoundEditors = new ArrayList<PropositionEditor>();
95 for (PropositionDefinitionContract prop : definition.getCompoundComponents()) {
96 this.compoundEditors.add(createPropositionEditor(prop));
97 }
98 this.versionNumber = definition.getVersionNumber();
99 }
100
101 public void clear(){
102 this.description = null;
103 this.term = null;
104 this.termParameter = null;
105 for (PropositionParameterEditor parm : this.getParameters()) {
106 parm.clear();
107 }
108 }
109
110 public String getKey() {
111 return key;
112 }
113
114 public void setKey(String key) {
115 this.key = key;
116 }
117
118 public String getId() {
119 return id;
120 }
121
122 public String getDescription() {
123 return description;
124 }
125
126 public String getCompoundOpCode() {
127 return compoundOpCode;
128 }
129
130 @Override
131 public Integer getCompoundSequenceNumber() {
132 return compoundSequenceNumber;
133 }
134
135 public void setId(String id) {
136 if (!StringUtils.isBlank(id) || id == null) {
137 this.id = id;
138 }
139 }
140
141 public void setDescription(String description) {
142
143 if ((description != null) && (description.length()>100)) {
144 description = description.substring(0,97) + "...";
145 }
146 this.description = description;
147 LOG.info(this.description);
148 }
149
150 public void setRuleId(String ruleId) {
151 this.ruleId = ruleId;
152 }
153
154 public void setCompoundOpCode(String compoundOpCode) {
155 this.compoundOpCode = compoundOpCode;
156 }
157
158 public void setParameters(List<PropositionParameterEditor> parameters) {
159 this.parameters = parameters;
160 }
161
162 public void setCompoundEditors(List<PropositionEditor> compoundEditors) {
163 this.compoundEditors = compoundEditors;
164 }
165
166 public List<PropositionEditor> getCompoundEditors() {
167 return compoundEditors;
168 }
169
170 @Override
171 public List<? extends PropositionDefinitionContract> getCompoundComponents() {
172 return compoundEditors;
173 }
174
175 public void setVersionNumber(Long versionNumber) {
176 this.versionNumber = versionNumber;
177 }
178
179 public List<PropositionParameterEditor> getParameters() {
180 return parameters;
181 }
182
183 public String getTypeId() {
184 return typeId;
185 }
186
187 @Override
188 public String getRuleId() {
189 return this.ruleId;
190 }
191
192 public void setPropositionTypeCode(String propositionTypeCode) {
193 this.propositionTypeCode = propositionTypeCode;
194 }
195
196 @Override
197 public String getPropositionTypeCode() {
198 return propositionTypeCode;
199 }
200
201 public void setTypeId(String typeId) {
202 this.typeId = typeId;
203 }
204
205 public String getType() {
206 return type;
207 }
208
209 public void setType(String type) {
210 this.type = type;
211 }
212
213 public boolean isEditMode() {
214 return editMode;
215 }
216
217 public TermEditor getTerm() {
218 return term;
219 }
220
221 public void setTerm(TermEditor term) {
222 this.term = term;
223 }
224
225 public String getTermParameter() {
226 return termParameter;
227 }
228
229 public void setTermParameter(String termParameter) {
230 this.termParameter = termParameter;
231
232 if(this.termParameter!=null){
233 LOG.info(this.termParameter);
234
235
236 this.termParameter.replaceAll("\\u00a0","");
237 }
238 LOG.info(termParameter);
239 }
240
241 public List<TermParameter> getTermParameterList() {
242 return termParameterList;
243 }
244
245 public void setTermParameterList(List<TermParameter> termParameterList) {
246 this.termParameterList = termParameterList;
247 }
248
249 public void setEditMode(boolean editMode) {
250 this.editMode = editMode;
251 }
252
253 @Override
254 public Long getVersionNumber() {
255 return this.versionNumber;
256 }
257
258 protected PropositionEditor createPropositionEditor(PropositionDefinitionContract definition) {
259 return new PropositionEditor(definition);
260 }
261
262 public String getNewTermDescription() {
263 return newTermDescription;
264 }
265
266 public boolean isNewProp() {
267 return newProp;
268 }
269
270 public void setNewProp(boolean newProp) {
271 this.newProp = newProp;
272 }
273
274 public Map<String, String> getNaturalLanguage() {
275 return naturalLanguage;
276 }
277
278 public void setNaturalLanguage(Map<String, String> naturalLanguage) {
279 this.naturalLanguage = naturalLanguage;
280 }
281
282
283
284
285
286
287
288 public String getNaturalLanguageForUsage(String usage){
289 String description = this.getNaturalLanguage().get(usage);
290
291 if (description == null){
292 return StringUtils.EMPTY;
293 }
294
295 return description;
296 }
297
298
299
300
301
302
303
304
305 public void setNaturalLanguageForUsage(String usage, String nl){
306 this.getNaturalLanguage().put(usage, nl);
307
308 if (usage.equals(this.getDefaultNlKey())){
309 this.setDescription(nl);
310 }
311 }
312
313
314
315
316
317
318
319 public Map<String, String> getNlParameters() {
320 return new HashMap<String, String>();
321 }
322
323 public String getBindingPath() {
324 return bindingPath;
325 }
326
327 public void setBindingPath(String bindingPath) {
328 this.bindingPath = bindingPath;
329 }
330
331 protected String getDefaultNlKey(){
332 return null;
333 }
334 }
335
336