cancel
Showing results for 
Search instead for 
Did you mean: 

scheduled job admin

xerox
Champ in-the-making
Champ in-the-making
I've wrote a JavaScript that browses trough spaces and do something with the files within it. When I execute the script in the web client, everything works fine.

When I'm running it as a scheduled job(as an admin user), it seems alfresco don't recognize the admin user, because the script only runs trough public folders.

Is this a bug?

friendly regards,
Nick
8 REPLIES 8

xerox
Champ in-the-making
Champ in-the-making
we're using alfresco 1.4.3 enterprise

xerox
Champ in-the-making
Champ in-the-making
*bump*

andy
Champ on-the-rise
Champ on-the-rise
Hi

Can you post the config for the scheduled job?

Andy

xerox
Champ in-the-making
Champ in-the-making
I've replaced our admin user with YYYY, so there I write our adminuser.

<bean id="archiveJob" 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>
      <property name="queryTemplate">
         <value>
            +PATH:"/app:company_home"      
         </value>
      </property>
   <property name="jobName">
         <value>archiveExpirationChecker</value>
      </property>
      <property name="jobGroup">
         <value>archiveJobGroup</value>
      </property>
      <property name="triggerName">
         <value>archiveTriggerEC</value>
      </property>
      <property name="triggerGroup">
         <value>archiveTriggerGroup</value>
      </property>
       <property name="cronExpression">
       <value>0 0 1 * * ? </value>
      </property>
      <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="javaArchive"/>
      </property>
      <property name="transactionService">
         <ref bean="TransactionService"/>
      </property>
      <property name="runAsUser">
         <value>YYYY</value>
      </property>
   </bean>

<bean id="javaArchive" class="org.alfresco.repo.action.scheduled.SimpleTemplateActionDefinition">
   <property name="actionName">
      <value>script</value>
   </property>
   <property name="parameterTemplates">
      <map>
         <entry>
            <key><value>script-ref</value></key>   
            <value>${selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:"/app:company_home/app:dictionary/app:scripts/cm:xxxx/cm:archive.js"' )}</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>

var topSpace = companyhome.childByNamePath("Extranet");
//template that returns the archiving period in months.
var archivetemplate = companyhome .childByNamePath("Data Dictionary/Presentation Templates/xxxx/archive.ftl");
//default archivingmonths
var archivingMonths = 12;
var dateHelp = new Date();
var now = new Date();
var archiveSpace = "" ;
setArchive(topSpace, archiveSpace);

function setArchive(curNode,arcSpace)
{
   if (curNode.isDocument)
   {
      if (isNaN(curNode.name.substring(0,6)))
   {
   logger.log(curNode.name + " has no date prefix");
   }
   else
   {
       dateHelp.setFullYear(curNode.name.substring(0,4),curNode.name.substring(4,6) - 1 + archivingMonths);
       if ( dateHelp < now && (!curNode.properties["imec:isArchived"] == true))
       {
          curNode.addAspect("xxxx:archive");
          curNode.properties["xxxx:isArchived"] = true;
          curNode.properties["xxxx:archivedDate"] =  new Date();
          logger.log(curNode.name + " ( " + curNode.nodeRef + " ) has been archived");
          curNode.save();
      
          arcSpace.properties["imec:hasArchivedDocs"] = true;
          arcSpace.save();
        }               
    }
   }
   else if (curNode.isContainer)
  
   {   var help = trim(String(curNode.processTemplate(archivetemplate)))
      logger.log(curNode.name);
      if (curNode.hasAspect("imec:archive"))
      {
          archiveSpace = curNode;
      }
      if ( help != "childarchive" )
      {
         archivingMonths = Number(help);
         
      }
      var children = curNode.children;
        for (var i=0; i<children.length; i++)
        {
       
            setArchive(children[i],archiveSpace);
      }   
  

  
   }

}
function ltrim(str) {
   for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
   return str.substring(k, str.length);
}
function rtrim(str) {
   for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j–) ;
   return str.substring(0,j+1);
}
function trim(str) {
   return ltrim(rtrim(str));
}
function isWhitespace(charToCheck) {
   var whitespaceChars = " \t\n\r\f";
   return (whitespaceChars.indexOf(charToCheck) != -1);
}

andy
Champ on-the-rise
Champ on-the-rise
Hi

This looks like a bug, but it not obvious where at the moment. I will investigate further. I believe that the scheduled action is setting the user context correctly.

If you run this template via the script action, using a rule on a folder, does it pick up the user context correctly (for example, it runs as the user adding the file that triggers the rule that runs the script ….)?

Andy

xerox
Champ in-the-making
Champ in-the-making
It works when I run it as a script action…

With the scheduled job,it runs as the user(because the modifier of the documents is the right user).

Yes, Probably a bug…
I don't know this bug is still in 2.1….

xerox
Champ in-the-making
Champ in-the-making
any news on this?

andy
Champ on-the-rise
Champ on-the-rise
Hi

No news.

Please raise this issue in Jira.

Andy