AnsweredAssumed Answered

Scheduled move action corrupts explorer search

Question asked by whaleshogun on Jun 29, 2012
Hello,

I have the following problem with Alfresco 3.4e (Explorer)

I have implemented a custom action I call "archive" which is very similar to the build-in "move" action. It basically moves all files from the actioned folder to another one within the company home.

I use the action both through the Explorer GUI ("run action") and as a scheduled action, and it works both ways. But unfortunately there is a difference when it comes to file search:

1) after calling it through the GUI the files can be found by search (using the search field in Alfresco Explorer) at their new location
2) when the action runs scheduled, the moved files are excluded from the search results, the cannot be found, although I see them both in Explorer GUI and node browser.

I have realised that if I make changes to the moved files through the Explorer GUI (such as editing content or taking ownership) makes the files reappear in the search results again.

Maybe someone can point out a solution so that the scheduled action also updates the search index?

Here are the files:

Action definitions:


<bean id="templateActionModelFactory" class="org.alfresco.repo.action.scheduled.FreeMarkerWithLuceneExtensionsModelFactory">
        <property name="serviceRegistry">
            <ref bean="ServiceRegistry"/>
        </property>
    </bean>

   <bean id="archive" class="com.evolit.bw.archive.ArchiveActionExecuter" parent="action-executer">
      <property name="nodeService">
         <ref bean="NodeService" />
      </property>
      <property name="fileFolderService">
         <ref bean="FileFolderService" />
      </property>
   </bean>

   <bean id="runArchiveAction" class="org.alfresco.repo.action.scheduled.SimpleTemplateActionDefinition">
      <property name="actionName">
         <value>archive</value>
      </property>
      <property name="parameterTemplates">
         <map>
         </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="archiveEndOfYear" class="org.alfresco.repo.action.scheduled.CronScheduledQueryBasedTemplateActionDefinition">
      <property name="transactionMode">
         <value>ISOLATED_TRANSACTIONS</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/app:dictionary/cm:AEINGANG"</value>
      </property>
      <property name="cronExpression">
         <value>0/30 * * * * ?</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="runArchiveAction" />
      </property>
      <property name="transactionService">
         <ref bean="TransactionService" />
      </property>
      <property name="runAsUser">
         <value>admin</value>
      </property>
   </bean>

Java code for the action:


public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) {
      logger.info("start archiving " + actionedUponNodeRef );
      try {
         if (this.fileFolderService.exists(actionedUponNodeRef) == true) {
            FileInfo folderInfo = this.fileFolderService.getFileInfo(actionedUponNodeRef);
            if (folderInfo.isFolder()) {                     
               
               List<FileInfo> path = this.fileFolderService.getNamePath( null, actionedUponNodeRef );
               FileInfo parentInfo = path.get( path.size() - 2 );

               logger.info("archiving folder " + folderInfo.getName() );
               for (FileInfo fileInfo : this.fileFolderService.listFiles(actionedUponNodeRef)) {
                  Calendar cal = new GregorianCalendar();
                  cal.setTime( fileInfo.getCreatedDate() );
                  int year = cal.get( Calendar.YEAR );
                  
                  String targetName = folderInfo.getName() + "_archiv_" + year;
                  
                  NodeRef targetNodeRef = this.fileFolderService.searchSimple( parentInfo.getNodeRef(), targetName );
                  if( targetNodeRef == null || !this.fileFolderService.exists( targetNodeRef ) ) {
                     logger.info("creating new archive folder " + targetName );
                     targetNodeRef = this.fileFolderService.create( parentInfo.getNodeRef(), targetName, ContentModel.TYPE_FOLDER ).getNodeRef();
                     nodeService.setProperty( targetNodeRef, ApplicationModel.PROP_ICON, "space-icon-cd" );
                  }

                  logger.info("moving " + fileInfo.getName() + " –> " + targetName );
                  FileInfo movedInfo = this.fileFolderService.move( fileInfo.getNodeRef(), targetNodeRef, null );
               }
            }
            logger.info("done archiving " + folderInfo.getName() );
         }
      } catch ( FileNotFoundException fnf ) {
         logger.warn( fnf );
      }
   }

Outcomes