cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with date range in Template expression

agey
Champ in-the-making
Champ in-the-making
Hi all,

I have a problem with a Lucene expression to configure a scheduled action. I have created a new action to transform the documents to pdf files. This action should be executed automatically every Saturday on the documents that have been created this week. The configuration in scheduled-action-services-context.xml is:


<bean id="transformPdfOCR" class="org.alfresco.repo.action.scheduled.SimpleTemplateActionDefinition">
        <property name="actionName">
            <value>transformOCR</value>
        </property>
        <property name="parameterTemplates">
            <map>
                <entry>
                    <key>
                        <value>mime-type</value>
                    </key>
                    <value>application/pdf</value>
                </entry>
              
            </map>
        </property>
      
        <property name="templateActionModelFactory">
            <ref bean="templateActionModelFactory"/>
        </property>
        <property name="dictionaryService">
            <ref bean="DictionaryService"/>
        </property>
        <property name="actionService">
            <ref bean="ActionService"/>
        </property>
        <property name="templateService">
            <ref bean="TemplateService"/>
        </property>
    </bean>
  
    <bean id="programTransformOCR" class="org.alfresco.repo.action.scheduled.CronScheduledQueryBasedTemplateActionDefinition">
        <property name="transactionMode">
            <value>UNTIL_FIRST_FAILURE</value>
        </property>
        <property name="compensatingActionMode">
            <value>IGNORE</value>
        </property>
        <property name="searchService">
            <ref bean="SearchService"/>
        </property>
        <property name="templateService">
            <ref bean="TemplateService"/>
        </property>
        <property name="queryLanguage">
            <value>lucene</value>
        </property>
        <property name="stores">
            <list>
                <value>workspace://SpacesStore</value>
            </list>
        </property>
        <!– Find all nodes that do not have the aspect –>
        <property name="queryTemplate">
            <value>+PATH:"/app:company_home/*//*" +TYPE:"{custom.model}Recorte" +@\{http\://www.alfresco.org/model/content/1.0\}content.mimetype:application/pdf +@cm\:created:${luceneDateRange(today, \"-P7D\")</value>
        </property>
        <property name="cronExpression">
            <value>0 */2 * * * ?</value>
        </property>
        <property name="jobName">
            <value>jobA</value>
        </property>
        <property name="jobGroup">
            <value>jobGroup</value>
        </property>
        <property name="triggerName">
            <value>triggerA</value>
        </property>
        <property name="triggerGroup">
            <value>triggerGroup</value>
        </property>
        <!– Inject the scheduler - the trigger will be registered with this scheduler –>
        <property name="scheduler">
            <ref bean="schedulerFactory"/>
        </property>
        <property name="actionService">
            <ref bean="ActionService"/>
        </property>
        <property name="templateActionModelFactory">
            <ref bean="templateActionModelFactory"/>
        </property>
        <property name="templateActionDefinition">
            <ref bean="transformPdfOCR"/>
        </property>
        <property name="transactionService">
            <ref bean="TransactionService"/>
        </property>
        <property name="runAsUser">
            <value>System</value>
        </property>
    </bean>

This action is never executed but if I change the "queryTemplate" in the configuration excluding the search by date range, the action is executed fine.


<property name="queryTemplate">
            <value>+PATH:"/app:company_home/*//*" +TYPE:"{custom.model}Recorte" +@\{http\://www.alfresco.org/model/content/1.0\}content.mimetype:application/pdf</value>
</property>

I use the expression showed on http://wiki.alfresco.com/wiki/Scheduled_Actions#Examples. Can someone point  me how the Template expression must be to limit the date range of creation of the documents?

Thanks a lot in advance.

NOTE: the "cronExpression" is set to run every 2 minutes for testing.
5 REPLIES 5

jayjayecl
Confirmed Champ
Confirmed Champ
Try with :

+@cm\\:created:${luceneDateRange(today, \"-P7D\")}

(escaping the backslash char - and not forgetting the closing bracket)

agey
Champ in-the-making
Champ in-the-making
Hi JayJayECL,

Thank you very much for you reply. I have tried it but returns an error:

ERROR [org.quartz.core.ErrorLogger] Job (jobGroup.jobA threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: org.alfresco.service.cmr.repository.TemplateException: Se ha producido un IO Error al procesar la plantilla '+PATH:"/app:company_home/*//*" +TYPE:"{incis.model}Recorte" +@\{http\://www.alfresco.org/model/content/1.0\}content.mimetype:application/pdf +@cm\\:created:${luceneDateRange(today, \"-P7D\")}'. Por favor contacte con el administrador del sistema.]
   at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
   at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
Caused by: org.alfresco.service.cmr.repository.TemplateException: Se ha producido un IO Error al procesar la plantilla '+PATH:"/app:company_home/*//*" +TYPE:"{incis.model}Recorte" +@\{http\://www.alfresco.org/model/content/1.0\}content.mimetype:application/pdf +@cm\\:created:${luceneDateRange(today, \"-P7D\")}'. Por favor contacte con el administrador del sistema.

jayjayecl
Confirmed Champ
Confirmed Champ
try it with the closing bracket but without the double back-slash

agey
Champ in-the-making
Champ in-the-making
Ok, that was the problem. I tried it and now it works fine.

Thank you very much.

jayjayecl
Confirmed Champ
Confirmed Champ
no problem good luck