1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krms.impl.repository |
17 | |
|
18 | |
|
19 | |
import org.kuali.rice.krad.bo.PersistableBusinessObjectBase |
20 | |
|
21 | |
import org.kuali.rice.krms.api.repository.proposition.PropositionDefinition; |
22 | |
import org.kuali.rice.krms.api.repository.proposition.PropositionDefinitionContract; |
23 | |
import org.kuali.rice.krad.service.BusinessObjectService; |
24 | |
import org.kuali.rice.krad.service.KRADServiceLocator |
25 | |
import org.kuali.rice.krms.api.repository.proposition.PropositionType |
26 | |
import org.kuali.rice.krms.api.repository.proposition.PropositionParameterType |
27 | |
import org.kuali.rice.krad.service.SequenceAccessorService |
28 | |
import org.kuali.rice.krms.api.repository.LogicalOperator; |
29 | |
|
30 | |
|
31 | |
public class PropositionBo extends PersistableBusinessObjectBase implements PropositionDefinitionContract { |
32 | |
|
33 | |
def String id |
34 | |
def String description |
35 | |
def String ruleId |
36 | |
def String typeId |
37 | |
def String propositionTypeCode |
38 | |
|
39 | |
def List<PropositionParameterBo> parameters |
40 | |
|
41 | |
|
42 | |
def String compoundOpCode |
43 | |
def List<PropositionBo> compoundComponents |
44 | |
|
45 | |
|
46 | |
def String parameterDisplayString |
47 | |
def boolean editMode = false |
48 | |
def String categoryId; |
49 | |
|
50 | |
private SequenceAccessorService sequenceAccessorService; |
51 | |
|
52 | |
private void setupParameterDisplayString(){ |
53 | 0 | if (PropositionType.SIMPLE.getCode().equalsIgnoreCase(getPropositionTypeCode())){ |
54 | |
|
55 | |
|
56 | 0 | List<PropositionParameterBo> parameters = getParameters(); |
57 | 0 | if (parameters != null && parameters.size() == 3){ |
58 | 0 | setParameterDisplayString(getParamValue(parameters.get(0)) |
59 | 0 | + " " + getParamValue(parameters.get(2)) |
60 | 0 | + " " + getParamValue(parameters.get(1))); |
61 | |
} else { |
62 | |
|
63 | |
} |
64 | |
} |
65 | |
} |
66 | |
|
67 | |
private String getParamValue(PropositionParameterBo prop){ |
68 | 0 | if (PropositionParameterType.TERM.getCode().equalsIgnoreCase(prop.getParameterType())){ |
69 | 0 | String termName = ""; |
70 | 0 | String termId = prop.getValue(); |
71 | 0 | if (termId != null && termId.length()>0){ |
72 | |
|
73 | 0 | TermBo term = getBoService().findBySinglePrimaryKey(TermBo.class,termId); |
74 | 0 | termName = term.getSpecification().getName(); |
75 | |
} |
76 | 0 | return termName; |
77 | |
} else { |
78 | 0 | return prop.getValue(); |
79 | |
} |
80 | |
} |
81 | |
|
82 | |
|
83 | |
|
84 | |
public String getParameterDisplayString() { |
85 | 0 | if (parameterDisplayString == null){ |
86 | 0 | setupParameterDisplayString() |
87 | |
} |
88 | 0 | return this.parameterDisplayString; |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public void setParameterDisplayString(String parameterDisplayString) { |
95 | 0 | this.parameterDisplayString = parameterDisplayString; |
96 | |
} |
97 | |
|
98 | |
public boolean getEditMode(){ |
99 | 0 | return this.editMode; |
100 | |
} |
101 | |
|
102 | |
public void setEditMode(boolean editMode){ |
103 | 0 | this.editMode = editMode; |
104 | |
} |
105 | |
|
106 | |
public String getCategoryId(){ |
107 | 0 | return this.categoryId; |
108 | |
} |
109 | |
|
110 | |
public void setCategoryId(String categoryId){ |
111 | 0 | this.categoryId = categoryId; |
112 | |
} |
113 | |
|
114 | |
public BusinessObjectService getBoService() { |
115 | 0 | return KRADServiceLocator.getBusinessObjectService(); |
116 | |
} |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
static PropositionDefinition to(PropositionBo bo) { |
125 | 0 | if (bo == null) { return null } |
126 | 0 | return org.kuali.rice.krms.api.repository.proposition.PropositionDefinition.Builder.create(bo).build() |
127 | |
} |
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
static PropositionBo from(PropositionDefinition im) { |
135 | 0 | if (im == null) { return null } |
136 | |
|
137 | 0 | PropositionBo bo = new PropositionBo() |
138 | 0 | bo.id = im.id |
139 | 0 | bo.description = im.description |
140 | |
|
141 | |
|
142 | 0 | setRuleIdRecursive(im.ruleId, bo) |
143 | |
|
144 | 0 | bo.typeId = im.typeId |
145 | 0 | bo.propositionTypeCode = im.propositionTypeCode |
146 | 0 | bo.parameters = new ArrayList<PropositionParameterBo>() |
147 | 0 | for ( parm in im.parameters){ |
148 | 0 | bo.parameters.add (PropositionParameterBo.from(parm)) |
149 | |
} |
150 | 0 | bo.compoundOpCode = im.compoundOpCode |
151 | 0 | bo.compoundComponents = new ArrayList<PropositionBo>() |
152 | 0 | for (prop in im.compoundComponents){ |
153 | 0 | bo.compoundComponents.add (PropositionBo.from(prop)) |
154 | |
} |
155 | 0 | bo.versionNumber = im.versionNumber |
156 | 0 | return bo |
157 | |
} |
158 | |
|
159 | |
private static void setRuleIdRecursive(String ruleId, PropositionBo prop) { |
160 | 0 | prop.ruleId = ruleId; |
161 | 0 | if (prop.compoundComponents != null) for (PropositionBo child : prop.compoundComponents) if (child != null) { |
162 | 0 | setRuleIdRecursive(ruleId, child); |
163 | |
} |
164 | |
} |
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
public static PropositionBo createSimplePropositionBoStub(PropositionBo sibling, String pType){ |
180 | |
|
181 | 0 | PropositionBo prop = null; |
182 | 0 | if (PropositionType.SIMPLE.getCode().equalsIgnoreCase(pType)){ |
183 | 0 | prop = new PropositionBo(); |
184 | 0 | prop.setId(getNewPropId()); |
185 | 0 | prop.setPropositionTypeCode(pType); |
186 | 0 | prop.setRuleId(sibling.getRuleId()); |
187 | 0 | prop.setTypeId(sibling.getTypeId()); |
188 | 0 | prop.setEditMode(true); |
189 | |
|
190 | |
|
191 | 0 | PropositionParameterBo pTerm = new PropositionParameterBo(); |
192 | 0 | pTerm.setId(getNewPropParameterId()); |
193 | 0 | pTerm.setParameterType("T"); |
194 | 0 | pTerm.setPropId(prop.getId()); |
195 | 0 | pTerm.setSequenceNumber(new Integer("0")); |
196 | 0 | pTerm.setVersionNumber(new Long(1)); |
197 | 0 | pTerm.setValue(""); |
198 | |
|
199 | |
|
200 | 0 | PropositionParameterBo pOp = new PropositionParameterBo(); |
201 | 0 | pOp.setId(getNewPropParameterId()); |
202 | 0 | pOp.setParameterType("F"); |
203 | 0 | pOp.setPropId(prop.getId()); |
204 | 0 | pOp.setSequenceNumber(new Integer("2")); |
205 | 0 | pOp.setVersionNumber(new Long(1)); |
206 | |
|
207 | |
|
208 | 0 | PropositionParameterBo pConst = new PropositionParameterBo(); |
209 | 0 | pConst.setId(getNewPropParameterId()); |
210 | 0 | pConst.setParameterType("C"); |
211 | 0 | pConst.setPropId(prop.getId()); |
212 | 0 | pConst.setSequenceNumber(new Integer("1")); |
213 | 0 | pConst.setVersionNumber(new Long(1)); |
214 | 0 | pConst.setValue(""); |
215 | |
|
216 | 0 | List<PropositionParameterBo> paramList = Arrays.asList(pTerm, pConst, pOp); |
217 | 0 | prop.setParameters(paramList); |
218 | |
} |
219 | 0 | return prop; |
220 | |
} |
221 | |
|
222 | |
public static PropositionBo createCompoundPropositionBoStub(PropositionBo existing){ |
223 | |
|
224 | 0 | PropositionBo prop = new PropositionBo(); |
225 | 0 | prop.setId(getNewPropId()); |
226 | 0 | prop.setPropositionTypeCode(PropositionType.COMPOUND.code); |
227 | 0 | prop.setCompoundOpCode(LogicalOperator.AND.code); |
228 | 0 | prop.setDescription(""); |
229 | 0 | prop.setEditMode(true); |
230 | 0 | if (existing != null){ |
231 | 0 | prop.setRuleId(existing.getRuleId()); |
232 | 0 | prop.setTypeId(existing.getTypeId()); |
233 | |
} |
234 | |
|
235 | 0 | PropositionBo newProp = createSimplePropositionBoStub(existing, PropositionType.SIMPLE.code) |
236 | 0 | List <PropositionBo> components = new ArrayList<PropositionBo>(2); |
237 | 0 | components.add(existing); |
238 | 0 | components.add(newProp); |
239 | 0 | prop.setCompoundComponents(components); |
240 | 0 | return prop; |
241 | |
} |
242 | |
|
243 | |
public static PropositionBo createCompoundPropositionBoStub2(PropositionBo existing){ |
244 | |
|
245 | 0 | PropositionBo prop = new PropositionBo(); |
246 | 0 | prop.setId(getNewPropId()); |
247 | 0 | prop.setPropositionTypeCode(PropositionType.COMPOUND.code); |
248 | 0 | prop.setRuleId(existing.getRuleId()); |
249 | 0 | prop.setTypeId(existing.getTypeId()); |
250 | 0 | prop.setCompoundOpCode(LogicalOperator.AND.code); |
251 | 0 | prop.setDescription(""); |
252 | 0 | prop.setEditMode(true); |
253 | |
|
254 | 0 | List <PropositionBo> components = new ArrayList<PropositionBo>(); |
255 | 0 | components.add(existing); |
256 | 0 | prop.setCompoundComponents(components); |
257 | 0 | return prop; |
258 | |
} |
259 | |
|
260 | |
private static String getNewPropId(){ |
261 | 0 | SequenceAccessorService sas = KRADServiceLocator.getSequenceAccessorService(); |
262 | 0 | Long id = sas.getNextAvailableSequenceNumber("KRMS_PROP_S", |
263 | |
PropositionBo.class); |
264 | 0 | return id.toString(); |
265 | |
} |
266 | |
private static String getNewPropParameterId(){ |
267 | 0 | SequenceAccessorService sas = KRADServiceLocator.getSequenceAccessorService(); |
268 | 0 | Long id = sas.getNextAvailableSequenceNumber("KRMS_PROP_PARM_S", |
269 | |
PropositionParameterBo.class); |
270 | 0 | return id.toString(); |
271 | |
} |
272 | |
} |