The problem is that we are trying to pass an instance associated with Hibernate to a rules engine (jrules). This will fire rules and add things to the instance that we cannot predict. Perhaps we cannot do it this way but it would be nice if we could!
Thanks, Ann
Code:
TlssrulesResult tlssrulesresult = null;
session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
ContractDao contractDao = new ContractDao();
contract = contractDao.getContract("aston", session);
ContractConstraint cc = new ContractConstraint("cc1", "SOM level", contract, tlss.SOM.CapabilityServiceOnBalanceSheet);
Parameter opConst1 = new Parameter("opConst1","operational_autonomy","yes");
ContractConstraint cc2 = new ContractConstraint("cc2", "support constraint",contract,opConst1);
Parameter opConst2 = new Parameter("opConst2","mission_profile","yes");
ContractConstraint cc3 = new ContractConstraint("cc3", "support constraint",contract,opConst2);
Parameter opConst3 = new Parameter("opConst3","accessibility_in_theatre","yes");
ContractConstraint cc4 = new ContractConstraint("cc4", "support constraint",contract,opConst3);
IlrRuleSessionProvider rsProvider = new IlrRuleSessionProviderFactory.Builder(
IlrRuleSessionProviderFactory.SIMPLE_RULESESSION_PROVIDER).build();
IlrStatelessRuleSession rs = rsProvider .createStatelessRuleSession();
IlrSessionRequest request1 = new IlrSessionRequest(rulesetPath);
IlrSessionExecutionSettings execSettings = request1.getExecutionSettings();
IlrSessionParameters params = execSettings.getInputParameters();
params.setParameter("contract", contract);
// Executes the ruleset
IlrSessionResponse response1 = rs.executeRules(request1);
tlssrulesresult = new TlssrulesResult();
tlssrulesresult.contract = (Contract) response1.getExecutionResult().getOutputParameters().getObjectValue(
"contract");
tlssrulesresult.userdata = (String)response1.getExecutionProperties().getUserData();
tlssrulesresult.outputString = response1.getExecutionResult().getOutputString();
session.saveOrUpdate(contract);
session.getTransaction().commit();