cancel
Showing results for 
Search instead for 
Did you mean: 

Problem moving node in an Action

ruffp
Champ in-the-making
Champ in-the-making
Hello,

I get a problem with moving nodes inside an Alfresco Action.

Here the details of my task:

1. Put 2 OpenOffice/StarOffice document (.odt) in a specific folder by FTP
2. A specific rule (Action) is launched to process the documents
   - Make some checks
   - Create subdirectories if doesn t exist
   - Move to the directory
   
My problem is when the action occurs, the subdirectories are created (like DIR1/DIR2/DIR3 and DIR1/DIR2/DIR4 )
but one file is inside DIR3 but the other one stay in the root folder. This problem does not occurs every time I test (with the same documents)

The action is not synchronised as I said my bean scope to be "prototype" (Spring context) because I want many actions
processing the files in the same time. That is because the finality is to be able to process hundreds of files at a certain time.

Can you tell me if such Alfresco action could be defined as prototype instead of singleton, and if yes, do you have an idea where I can have a look for that problem.

My Alfresco version is 2.1.1

Thanks for your help
Patrick

PS: I tried to use transactions like in http://wiki.alfresco.com/wiki/Alfresco_Content_Management_Java_API#User_Transaction
but it looks like an action does not support nested transactions (I commit successfully but at the end of (after?) the action Alfresco throws the exception : UserTransaction begin/commit mismatch
3 REPLIES 3

mabayona
Champ on-the-rise
Champ on-the-rise
The solution is easy. You need to be sure that the directories/spaces are COMPLETELLY created and STORED before moving the file in the directory. The solution is to force the creation of the spaces. This is done calling the save() function on the created space (where you plan to store the file). I had such problem and this solved the problem.

ruffp
Champ in-the-making
Champ in-the-making
Thanks for the answer.

The save() method you mention is when programming in JS language but it does not apply to my Action because mine is implemented in Java deriving the ActionExecuterAbstractBase.

For more details, I use the fileFolderService to create the directory structure like this :


   private FileInfo createFolder(NodeRef currentFolder, String folderName) {
      FileInfo fileInfo = getFileOrFolder(currentFolder, folderName); // check existence
      if (fileInfo == null) {
         try {
            fileInfo = this.fileFolderService.create(currentFolder, folderName, ContentModel.TYPE_FOLDER);         
         } catch (FileExistsException e) {
            // Should never happen
         }
      }
      return fileInfo;
   }

This function is called many times and the move is always called after. I don't know if it is my action's responsibility to synchronize all the thread because it is difficult (or impossible?) to control the behavior of the Alfresco services.

I can already say that I refer always to transactional services (with 1st capital letter) beans.

Thanks for help

mabayona
Champ on-the-rise
Champ on-the-rise
It is possible to do the same in Java. I read about it in the forums/wiki. I do no remember exactly where but the concept remains: you have to be sure that the space is created and flushed before trying to copy/move it.

Look for TRANSACTION_COMMIT option in the forums / wiki and you´ll find a solution.

You can also look at:

http://www.ecmarchitect.com/images/articles/alfresco-behavior/behavior-article.pdf