| 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 | 4 | 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 | 37 | PropositionBo bo = new PropositionBo() |
| 138 | 37 | bo.id = im.id |
| 139 | 37 | bo.description = im.description |
| 140 | |
|
| 141 | |
|
| 142 | 37 | setRuleIdRecursive(im.ruleId, bo) |
| 143 | |
|
| 144 | 37 | bo.typeId = im.typeId |
| 145 | 37 | bo.propositionTypeCode = im.propositionTypeCode |
| 146 | 37 | bo.parameters = new ArrayList<PropositionParameterBo>() |
| 147 | 37 | for ( parm in im.parameters){ |
| 148 | 108 | bo.parameters.add (PropositionParameterBo.from(parm)) |
| 149 | |
} |
| 150 | 37 | bo.compoundOpCode = im.compoundOpCode |
| 151 | 37 | bo.compoundComponents = new ArrayList<PropositionBo>() |
| 152 | 37 | for (prop in im.compoundComponents){ |
| 153 | 2 | bo.compoundComponents.add (PropositionBo.from(prop)) |
| 154 | |
} |
| 155 | 37 | bo.versionNumber = im.versionNumber |
| 156 | 37 | return bo |
| 157 | |
} |
| 158 | |
|
| 159 | |
private static void setRuleIdRecursive(String ruleId, PropositionBo prop) { |
| 160 | 37 | prop.ruleId = ruleId; |
| 161 | 37 | 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.setEditMode(true); |
| 187 | 0 | if (sibling != null){ |
| 188 | 0 | prop.setRuleId(sibling.getRuleId()); |
| 189 | 0 | prop.setTypeId(sibling.getTypeId()); |
| 190 | |
} |
| 191 | |
|
| 192 | |
|
| 193 | 0 | PropositionParameterBo pTerm = new PropositionParameterBo(); |
| 194 | 0 | pTerm.setId(getNewPropParameterId()); |
| 195 | 0 | pTerm.setParameterType("T"); |
| 196 | 0 | pTerm.setPropId(prop.getId()); |
| 197 | 0 | pTerm.setSequenceNumber(new Integer("0")); |
| 198 | 0 | pTerm.setVersionNumber(new Long(1)); |
| 199 | 0 | pTerm.setValue(""); |
| 200 | |
|
| 201 | |
|
| 202 | 0 | PropositionParameterBo pOp = new PropositionParameterBo(); |
| 203 | 0 | pOp.setId(getNewPropParameterId()); |
| 204 | 0 | pOp.setParameterType("F"); |
| 205 | 0 | pOp.setPropId(prop.getId()); |
| 206 | 0 | pOp.setSequenceNumber(new Integer("2")); |
| 207 | 0 | pOp.setVersionNumber(new Long(1)); |
| 208 | |
|
| 209 | |
|
| 210 | 0 | PropositionParameterBo pConst = new PropositionParameterBo(); |
| 211 | 0 | pConst.setId(getNewPropParameterId()); |
| 212 | 0 | pConst.setParameterType("C"); |
| 213 | 0 | pConst.setPropId(prop.getId()); |
| 214 | 0 | pConst.setSequenceNumber(new Integer("1")); |
| 215 | 0 | pConst.setVersionNumber(new Long(1)); |
| 216 | 0 | pConst.setValue(""); |
| 217 | |
|
| 218 | 0 | List<PropositionParameterBo> paramList = Arrays.asList(pTerm, pConst, pOp); |
| 219 | 0 | prop.setParameters(paramList); |
| 220 | |
} |
| 221 | 0 | return prop; |
| 222 | |
} |
| 223 | |
|
| 224 | |
public static PropositionBo createCompoundPropositionBoStub(PropositionBo existing){ |
| 225 | |
|
| 226 | 0 | PropositionBo prop = new PropositionBo(); |
| 227 | 0 | prop.setId(getNewPropId()); |
| 228 | 0 | prop.setPropositionTypeCode(PropositionType.COMPOUND.code); |
| 229 | 0 | prop.setCompoundOpCode(LogicalOperator.AND.code); |
| 230 | 0 | prop.setDescription(""); |
| 231 | 0 | prop.setEditMode(true); |
| 232 | 0 | if (existing != null){ |
| 233 | 0 | prop.setRuleId(existing.getRuleId()); |
| 234 | 0 | prop.setTypeId(existing.getTypeId()); |
| 235 | |
} |
| 236 | |
|
| 237 | 0 | PropositionBo newProp = createSimplePropositionBoStub(existing, PropositionType.SIMPLE.code) |
| 238 | 0 | List <PropositionBo> components = new ArrayList<PropositionBo>(2); |
| 239 | 0 | components.add(existing); |
| 240 | 0 | components.add(newProp); |
| 241 | 0 | prop.setCompoundComponents(components); |
| 242 | 0 | return prop; |
| 243 | |
} |
| 244 | |
|
| 245 | |
public static PropositionBo createCompoundPropositionBoStub2(PropositionBo existing){ |
| 246 | |
|
| 247 | 0 | PropositionBo prop = new PropositionBo(); |
| 248 | 0 | prop.setId(getNewPropId()); |
| 249 | 0 | prop.setPropositionTypeCode(PropositionType.COMPOUND.code); |
| 250 | 0 | prop.setRuleId(existing.getRuleId()); |
| 251 | 0 | prop.setTypeId(existing.getTypeId()); |
| 252 | 0 | prop.setCompoundOpCode(LogicalOperator.AND.code); |
| 253 | 0 | prop.setDescription(""); |
| 254 | 0 | prop.setEditMode(true); |
| 255 | |
|
| 256 | 0 | List <PropositionBo> components = new ArrayList<PropositionBo>(); |
| 257 | 0 | components.add(existing); |
| 258 | 0 | prop.setCompoundComponents(components); |
| 259 | 0 | return prop; |
| 260 | |
} |
| 261 | |
|
| 262 | |
private static String getNewPropId(){ |
| 263 | 0 | SequenceAccessorService sas = KRADServiceLocator.getSequenceAccessorService(); |
| 264 | 0 | Long id = sas.getNextAvailableSequenceNumber("KRMS_PROP_S", |
| 265 | |
PropositionBo.class); |
| 266 | 0 | return id.toString(); |
| 267 | |
} |
| 268 | |
private static String getNewPropParameterId(){ |
| 269 | 0 | SequenceAccessorService sas = KRADServiceLocator.getSequenceAccessorService(); |
| 270 | 0 | Long id = sas.getNextAvailableSequenceNumber("KRMS_PROP_PARM_S", |
| 271 | |
PropositionParameterBo.class); |
| 272 | 0 | return id.toString(); |
| 273 | |
} |
| 274 | |
} |