AnsweredAssumed Answered

Script breaking the Content rules

Question asked by ericks on Feb 26, 2011
Hi!!!

I'm running CE 3.4.d on Ubuntu 10.0.4.
I adapted this script so when the total documents inside a folder = X (3 in this example), documents are automatically move to the destination folder.
// ————————————————————
// Name: revisado
// Description: Moves reviewed content to Archived space
// ————————————————————
var activeFolder   = companyhome.childByNamePath("DM/Capture);
var archivedFolder = companyhome.childByNamePath("DM/Ready");

if(activeFolder != null)
{
   var i=0;
   var activeTotal = 0;

   activeChildren  = activeFolder.children;
   activeTotal     = activeChildren.length;
   docs = activeTotal-1;

   if(docs == 3)
   {
     for(i=0; i<activeTotal;i++)
     {
       child = activeChildren[i];
        {
           child.move(archivedFolder);
        }
     }
   }
}

Problem is the script runs only once and after that the rule disappears and if you try to access the Rule Manager this error appears:
A problem has occurred. 
This page could not be rendered:
folder-rules
Please notify your system administrator.

This is the log
15:44:01,859  ERROR [extensions.webscripts.AbstractRuntime] Exception from executeScript - redirecting to status template error: 01260003 Wrapped Exc
ption (with status template): null
org.springframework.extensions.webscripts.WebScriptException: 01260003 Wrapped Exception (with status template): null
        at org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:758)
        at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:171)
        at org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:377)
        at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:381)
        at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:436)
        at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:466)
        at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:304)
        at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:333)
        at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:189)
        at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:118)
        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 org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:58)
        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:127)
        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:298)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
        at org.alfresco.repo.rule.RuleServiceImpl.getLinkedToRuleNode(RuleServiceImpl.java:1472)
        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:307)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:34)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:44)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.audit.AuditMethodInterceptor.proceedWithAudit(AuditMethodInterceptor.java:217)
        at org.alfresco.repo.audit.AuditMethodInterceptor.proceed(AuditMethodInterceptor.java:184)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:137)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at $Proxy52.getLinkedToRuleNode(Unknown Source)
        at org.alfresco.repo.web.scripts.rule.RulesetGet.executeImpl(RulesetGet.java:89)
        at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:64)
        … 24 more
15:44:02,093 http-8080-37 ERROR [freemarker.runtime] Expression ruleset is undefined on line 18, column 12 in org/alfresco/folder-rules.ftl.

Expression ruleset is undefined on line 18, column 12 in org/alfresco/folder-rules.ftl.
The problematic instruction:
———-
==> if-else  [on line 18, column 7 in org/alfresco/folder-rules.ftl]
in user-directive templateBody [on line 7, column 1 in org/alfresco/folder-rules.ftl]
———-

Java backtrace for programmers:
———-
freemarker.core.InvalidReferenceException: Expression ruleset is undefined on line 18, column 12 in org/alfresco/folder-rules.ftl.
        at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)
        at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:134)
        at freemarker.core.Dot._getAsTemplateModel(Dot.java:78)
        at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
        at freemarker.core.ExistsExpression._getAsTemplateModel(ExistsExpression.java:71)
        at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
        at freemarker.core.Expression.isTrue(Expression.java:138)
        at freemarker.core.IfBlock.accept(IfBlock.java:80)
        at freemarker.core.Environment.visit(Environment.java:210)
        at freemarker.core.MixedContent.accept(MixedContent.java:92)
        at freemarker.core.Environment.visit(Environment.java:210)
        at freemarker.core.Environment.visit(Environment.java:395)
        at freemarker.core.BodyInstruction.accept(BodyInstruction.java:93)
        at freemarker.core.Environment.visit(Environment.java:210)
        at freemarker.core.MixedContent.accept(MixedContent.java:92)
        at freemarker.core.Environment.visit(Environment.java:210)
        at freemarker.core.Macro$Context.runMacro(Macro.java:172)
        at freemarker.core.Environment.visit(Environment.java:603)
        at freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)
        at freemarker.core.Environment.visit(Environment.java:210)
        at freemarker.core.MixedContent.accept(MixedContent.java:92)
        at freemarker.core.Environment.visit(Environment.java:210)
        at freemarker.core.Environment.process(Environment.java:190)
        at org.springframework.extensions.webscripts.processor.FTLTemplateProcessor.process(FTLTemplateProcessor.java:171)
        at org.springframework.extensions.webscripts.WebTemplateProcessor.executeBody(WebTemplateProcessor.java:345)
        at org.springframework.extensions.surf.render.AbstractProcessor.execute(AbstractProcessor.java:57)
        at org.springframework.extensions.surf.render.RenderService.processTemplate(RenderService.java:378)
        at org.springframework.extensions.surf.render.bean.TemplateInstanceRenderer.calculateComponentDependencies(TemplateInstanceRenderer.java:61)
        at org.springframework.extensions.surf.render.bean.TemplateInstanceRenderer.body(TemplateInstanceRenderer.java:118)
        at org.springframework.extensions.surf.render.AbstractRenderer.render(AbstractRenderer.java:75)
        at org.springframework.extensions.surf.render.bean.PageRenderer.body(PageRenderer.java:85)
        at org.springframework.extensions.surf.render.AbstractRenderer.render(AbstractRenderer.java:75)
        at org.springframework.extensions.surf.render.RenderService.renderPage(RenderService.java:408)
        at org.springframework.extensions.surf.mvc.PageView.dispatchPage(PageView.java:388)
        at org.springframework.extensions.surf.mvc.PageView.renderView(PageView.java:329)
        at org.springframework.extensions.surf.mvc.AbstractWebFrameworkView.renderMergedOutputModel(AbstractWebFrameworkView.java:285)
        at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
        at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
        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 org.alfresco.web.site.servlet.MTAuthenticationFilter.doFilter(MTAuthenticationFilter.java:74)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.alfresco.web.site.servlet.SSOAuthenticationFilter.doFilter(SSOAuthenticationFilter.java:301)
        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:127)
        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:298)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Thread.java:619)
15:44:02,140 http-8080-37 ERROR [surf.render.RenderService] Unable to process template: folder-rules
15:44:02,140 http-8080-37 ERROR [surf.render.RenderService] An exception occurred while rendering: folder-rules
org.springframework.extensions.surf.exception.RendererExecutionException: WebTemplateProcessor failed to process template uri: org/alfresco/folder-ru
es
        at org.springframework.extensions.webscripts.WebTemplateProcessor.executeBody(WebTemplateProcessor.java:377)
        at org.springframework.extensions.surf.render.AbstractProcessor.execute(AbstractProcessor.java:57)
        at org.springframework.extensions.surf.render.RenderService.processTemplate(RenderService.java:378)
        at org.springframework.extensions.surf.render.bean.TemplateInstanceRenderer.calculateComponentDependencies(TemplateInstanceRenderer.java:61)
        at org.springframework.extensions.surf.render.bean.TemplateInstanceRenderer.body(TemplateInstanceRenderer.java:118)
        at org.springframework.extensions.surf.render.AbstractRenderer.render(AbstractRenderer.java:75)
        at org.springframework.extensions.surf.render.bean.PageRenderer.body(PageRenderer.java:85)
        at org.springframework.extensions.surf.render.AbstractRenderer.render(AbstractRenderer.java:75)
        at org.springframework.extensions.surf.render.RenderService.renderPage(RenderService.java:408)
        at org.springframework.extensions.surf.mvc.PageView.dispatchPage(PageView.java:388)
        at org.springframework.extensions.surf.mvc.PageView.renderView(PageView.java:329)
        at org.springframework.extensions.surf.mvc.AbstractWebFrameworkView.renderMergedOutputModel(AbstractWebFrameworkView.java:285)
        at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
        at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
        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 org.alfresco.web.site.servlet.MTAuthenticationFilter.doFilter(MTAuthenticationFilter.java:74)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.alfresco.web.site.servlet.SSOAuthenticationFilter.doFilter(SSOAuthenticationFilter.java:301)
        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:127)
        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:298)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Thread.java:619)
Caused by: org.springframework.extensions.webscripts.WebScriptException: 01260000 Failed to process template org/alfresco/folder-rules.ftl
        at org.springframework.extensions.webscripts.processor.FTLTemplateProcessor.process(FTLTemplateProcessor.java:175)
        at org.springframework.extensions.webscripts.WebTemplateProcessor.executeBody(WebTemplateProcessor.java:345)
        … 37 more
Caused by: freemarker.core.InvalidReferenceException: Expression ruleset is undefined on line 18, column 12 in org/alfresco/folder-rules.ftl.
        at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)
        at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:134)
        at freemarker.core.Dot._getAsTemplateModel(Dot.java:78)
        at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
        at freemarker.core.ExistsExpression._getAsTemplateModel(ExistsExpression.java:71)
        at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
        at freemarker.core.Expression.isTrue(Expression.java:138)
        at freemarker.core.IfBlock.accept(IfBlock.java:80)
        at freemarker.core.Environment.visit(Environment.java:210)
        at freemarker.core.MixedContent.accept(MixedContent.java:92)
        at freemarker.core.Environment.visit(Environment.java:210)
        at freemarker.core.Environment.visit(Environment.java:395)
        at freemarker.core.BodyInstruction.accept(BodyInstruction.java:93)
        at freemarker.core.Environment.visit(Environment.java:210)
        at freemarker.core.MixedContent.accept(MixedContent.java:92)
        at freemarker.core.Environment.visit(Environment.java:210)
        at freemarker.core.Macro$Context.runMacro(Macro.java:172)
        at freemarker.core.Environment.visit(Environment.java:603)
        at freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)
        at freemarker.core.Environment.visit(Environment.java:210)
        at freemarker.core.MixedContent.accept(MixedContent.java:92)
        at freemarker.core.Environment.visit(Environment.java:210)
        at freemarker.core.Environment.process(Environment.java:190)
        at org.springframework.extensions.webscripts.processor.FTLTemplateProcessor.process(FTLTemplateProcessor.java:171)
        … 38 more

After that, i need to run this script to fix the rules manager
space.removeAspect("rule:rules");
and have to recreate the rule again.

What's wrong with the script that is breaking Alfresco?
Is this the best way to do it?

Thanks
Erick
:)

Outcomes