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