View Javadoc

1   package org.kuali.rice.krms.dto;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.kuali.rice.krms.api.repository.proposition.PropositionDefinitionContract;
5   import org.kuali.rice.krms.api.repository.proposition.PropositionParameterContract;
6   import org.kuali.rice.krms.api.repository.term.TermDefinition;
7   import org.kuali.rice.krms.impl.ui.TermParameter;
8   
9   import java.io.Serializable;
10  import java.util.ArrayList;
11  import java.util.HashMap;
12  import java.util.List;
13  import java.util.Map;
14  import java.util.UUID;
15  
16  /**
17   * Created with IntelliJ IDEA.
18   * User: SW
19   * Date: 2012/12/03
20   * Time: 11:41 AM
21   * To change this template use File | Settings | File Templates.
22   */
23  public class PropositionEditor implements PropositionDefinitionContract, Serializable {
24  
25      private static final long serialVersionUID = 1L;
26  
27      private String key;
28  
29      private String id;
30      private String description;
31      private String ruleId;
32      private String compoundOpCode;
33      private String typeId;
34      private String propositionTypeCode;
35      private Long versionNumber;
36  
37      private Map<String, String> naturalLanguage = new HashMap<String, String>();
38  
39      private List<PropositionParameterEditor> parameters;
40      private List<PropositionEditor> compoundEditors;
41  
42      private TermEditor term;
43      private String termParameter;
44      private List<TermParameter> termParameterList = new ArrayList<TermParameter>();
45      private String type;
46      private boolean editMode = false;
47      private boolean newProp = false;
48  
49      private String newTermDescription = "new term " + UUID.randomUUID().toString();
50  
51      public PropositionEditor() {
52          super();
53      }
54  
55      /**
56       * Converts a immutable object to it's mutable bo counterpart
57       *
58       * @param definition immutable object
59       * @return the mutable bo
60       */
61      public PropositionEditor(PropositionDefinitionContract definition) {
62          this.id = definition.getId();
63          this.description = definition.getDescription();
64          this.ruleId = definition.getRuleId();
65  
66          this.typeId = definition.getTypeId();
67          this.propositionTypeCode = definition.getPropositionTypeCode();
68          this.parameters = new ArrayList<PropositionParameterEditor>();
69          for (PropositionParameterContract parm : definition.getParameters()) {
70              this.parameters.add(new PropositionParameterEditor(parm));
71          }
72          this.compoundOpCode = definition.getCompoundOpCode();
73          this.compoundEditors = new ArrayList<PropositionEditor>();
74          for (PropositionDefinitionContract prop : definition.getCompoundComponents()) {
75              this.compoundEditors.add(createPropositionEditor(prop));
76          }
77          this.versionNumber = definition.getVersionNumber();
78      }
79  
80      public String getKey() {
81          return key;
82      }
83  
84      public void setKey(String key) {
85          this.key = key;
86      }
87  
88      public String getId() {
89          return id;
90      }
91  
92      public String getDescription() {
93          return description;
94      }
95  
96      public String getCompoundOpCode() {
97          return compoundOpCode;
98      }
99  
100     public void setId(String id) {
101         if (!StringUtils.isBlank(id)) {
102             this.id = id;
103         }
104     }
105 
106     public void setDescription(String description) {
107         this.description = description;
108     }
109 
110     public void setRuleId(String ruleId) {
111         this.ruleId = ruleId;
112     }
113 
114     public void setCompoundOpCode(String compoundOpCode) {
115         this.compoundOpCode = compoundOpCode;
116     }
117 
118     public void setParameters(List<PropositionParameterEditor> parameters) {
119         this.parameters = parameters;
120     }
121 
122     public void setCompoundEditors(List<PropositionEditor> compoundEditors) {
123         this.compoundEditors = compoundEditors;
124     }
125 
126     public List<PropositionEditor> getCompoundEditors() {
127         return compoundEditors;
128     }
129 
130     @Override
131     public List<? extends PropositionDefinitionContract> getCompoundComponents() {
132         return compoundEditors;
133     }
134 
135     public List<PropositionParameterEditor> getParameters() {
136         return parameters;
137     }
138 
139     public String getTypeId() {
140         return typeId;
141     }
142 
143     @Override
144     public String getRuleId() {
145         return this.ruleId;
146     }
147 
148     public void setPropositionTypeCode(String propositionTypeCode) {
149         this.propositionTypeCode = propositionTypeCode;
150     }
151 
152     @Override
153     public String getPropositionTypeCode() {
154         return propositionTypeCode;
155     }
156 
157     public void setTypeId(String typeId) {
158         this.typeId = typeId;
159     }
160 
161     public String getType() {
162         return type;
163     }
164 
165     public void setType(String type) {
166         this.type = type;
167     }
168 
169     public boolean isEditMode() {
170         return editMode;
171     }
172 
173     public TermEditor getTerm() {
174         return term;
175     }
176 
177     public void setTerm(TermEditor term) {
178         this.term = term;
179     }
180 
181     public String getTermParameter() {
182         return termParameter;
183     }
184 
185     public void setTermParameter(String termParameter) {
186         this.termParameter = termParameter;
187     }
188 
189     public List<TermParameter> getTermParameterList() {
190         return termParameterList;
191     }
192 
193     public void setTermParameterList(List<TermParameter> termParameterList) {
194         this.termParameterList = termParameterList;
195     }
196 
197     public void setEditMode(boolean editMode) {
198         this.editMode = editMode;
199     }
200 
201     @Override
202     public Long getVersionNumber() {
203         return this.versionNumber;
204     }
205 
206     protected PropositionEditor createPropositionEditor(PropositionDefinitionContract definition) {
207         return new PropositionEditor(definition);
208     }
209 
210     public String getNewTermDescription() {
211         return newTermDescription;
212     }
213 
214     public boolean isNewProp() {
215         return newProp;
216     }
217 
218     public void setNewProp(boolean newProp) {
219         this.newProp = newProp;
220     }
221 
222     public Map<String, String> getNaturalLanguage() {
223         return naturalLanguage;
224     }
225 
226     public void setNaturalLanguage(Map<String, String> naturalLanguage) {
227         this.naturalLanguage = naturalLanguage;
228     }
229 
230     public Map<String, String> getNlParameters() {
231         return new HashMap<String, String>();
232     }
233 
234     public String getNaturalLanguageForUsage(String usage){
235         String description = this.getNaturalLanguage().get(usage);
236 
237         if (description == null){
238             return StringUtils.EMPTY;
239         }
240 
241         return description;
242     }
243 }
244 
245