Yes, write a Java external that calls the rules engine yourself and then manipulates the returned org.dom4j.Element before returning it in your response document.See RequestContext#executeRules(Element, List)
/* Needs actual exception handling */public Document customRulesExecution(RequestContext context) {String rulenames = context.getParameterString("DatumNameContainingSelectedRules");StringTokenizer tokens = new StringTokenizer(rulenames, ",");List rules = new LinkedList();while (tokens.hasMoreTokens()) { rules.add(new RuleExecDef(tokens.nextToken());}Document doc = Dom4jUtils.newDocument();Element root = doc.addElement("whatever");context.executeRules(root, rules);// manipulate root with whatever you needreturn doc;}
Your rule datum isn't getting executed on its own. You either have an external at the component level, or a controller at the page/site level that's actually executing your rules
Hi Rick,
I am using your code in my external to execute rules, but I am getting below exception :
2014-07-08 05:22:46,791 ERROR [com.interwoven.livesite.rules.engine.RulesEngineRuntimeExecutor] <Error><message>Rules engine error detected when requesting input model values</message><baseUri><![CDATA[http://<lscs-host>:1876/lscs/v1/]]></baseUri><response><root><error><![CDATA[com.interwoven.wcm.iwrr.core.ProjectNotFoundException: No project found with name: '//default/main/<teamsite Branch>'.at com.interwoven.wcm.iwrr.dao.hibernate.AssetDaoHibernateImpl.resolveProjects(AssetDaoHibernateImpl.java:660)at com.interwoven.wcm.iwrr.dao.hibernate.AssetDaoHibernateImpl.getDocumentsByPath(AssetDaoHibernateImpl.java:567)at com.interwoven.wcm.iwrr.dao.hibernate.AssetDaoHibernateImpl.getDocumentByPath(AssetDaoHibernateImpl.java:202)at com.interwoven.wcm.rules.engine.impl.RulesEngineLoaderImplLscs.getRuleCacheKey(RulesEngineLoaderImplLscs.java:195)at com.interwoven.wcm.rules.engine.RulesEngine.getRule(RulesEngine.java:345)at com.interwoven.wcm.iwrr.request.handler.RulesEngineRequestHandler.handlePost(RulesEngineRequestHandler.java:290)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)at $Proxy4.handlePost(Unknown Source)at com.interwoven.wcm.iwrr.core.MainController.handleRequestInternal(MainController.java:208)at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)at sun.reflect.GeneratedMethodAccessor104.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:80)at com.interwoven.wcm.iwrr.diagnostic.DiagnosticLogger.timingAdvice(DiagnosticLogger.java:118)at sun.reflect.GeneratedMethodAccessor103.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)
I have defined a Project name for all LSCS deployments from this Teamsite branch in lscs-authoring.xml , but I am unable to run Rules for this project. Rules execution is taking the teamsite branch as project , which does not exist in LSCS. How do I set LSCS project in RequestContext so that rules are executed correctly for context.executeRules(root, rules); ?
Thanks!
Doesn't look like you can override the logic to use custom project names. It's hardcoded in RulesEngineBaseExecutor#internalExecuteRule(). Is there any reason why you can't use branch paths as your project names? Because just quickly looking at it, rebuilding this piece doesn't look trivial both in effort and maintenance.
Thanks for your reply .
In the content.properties file of LSDS where we define LSCS evironment details , there is one section for Rules Engine :
## LSCS Rules Engine Properties#
# Whether to enable rule execution and rule management featureslscs.rules.enabled=true
But there are no examples of properties that can be defined here, no documentation/post on Support & Devnet site. Anyway I can find that out ?
There's no documentation for what hidden properties may exist, but it wouldn't help you in this case anyway. The code is hardcoded with project = context.getSite().getBranch(). The only way to change that is to build your own connector to the rules engine.
I tried to trick the engine by doing :
context.getSite().setBranch("MyProject");
This resolved the old error of Project not found , but I am getting a different error now. Seems its unable to locate the Rule, Condition & Action , even though files are there.
------------------------------
<Error><message>Rules engine error detected when requesting input model values</message><baseUri><![CDATA[http://<lscs server>:1876/lscs/v1/]]></baseUri><response><root><error><![CDATA[java.lang.RuntimeException: Failed to locate asset document: iwov-resources/rules/ product.rule]RulesEngineConfiguration {BaseRulesDirectory=iwov-resources/rules/BaseConditionsDirectory=iwov-resources/conditions/BaseActionsDirectory=iwov-resources/actions/BaseSegmentRulesDirectory=iwov-resources/actions/}project=MyProjectProject context={
6852837747396cba8678f28259e361b0}available projects={//default/main/aCSPMyProject}
at com.interwoven.wcm.rules.engine.impl.RulesEngineLoaderImplLscs.getRuleCacheKey(RulesEngineLoaderImplLscs.java:224)at com.interwoven.wcm.rules.engine.RulesEngine.getRule(RulesEngine.java:345)at com.interwoven.wcm.iwrr.request.handler.RulesEngineRequestHandler.handlePost(RulesEngineRequestHandler.java:290)at sun.reflect.GeneratedMethodAccessor124.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)at $Proxy4.handlePost(Unknown Source)at com.interwoven.wcm.iwrr.core.MainController.handleRequestInternal(MainController.java:208)at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)at sun.reflect.GeneratedMethodAccessor104.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:80)at com.interwoven.wcm.iwrr.diagnostic.DiagnosticLogger.timingAdvice(DiagnosticLogger.java:118)at sun.reflect.GeneratedMethodAccessor103.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)at $Proxy7.handleRequest(Unknown Source)at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)at com.interwoven.wcm.iwrr.admin.AdminFilter.doFilter(AdminFilter.java:142)at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)at java.lang.Thread.run(Thread.java:662)]]></error></root></response><response_body><![CDATA[<?xml version="1.0" encoding="UTF-8"?><request><rules-to-execute><Rule> product.rule]</Rule></rules-to-execute><EventVisitor>3</EventVisitor></request>]]></response_body><request><rules-to-execute><Rule> product.rule]</Rule></rules-to-execute><EventVisitor>3</EventVisitor></request></Error>
---------------------------------------------------------
I guess this wont work
Thanks for your reply.