cancel
Showing results for 
Search instead for 
Did you mean: 

Moving files (Error before enter in a custom action)

dranakan
Champ on-the-rise
Champ on-the-rise
Hello,

I have developed an action to move files in a structure directories : /year/month/day. When I add a file, the directories are created and the file is moved. If the file to add has the same name than a present file, this one is renamed before the copy.

All is good with the web interface (to add the file) but with the CIFS there is a error message saying that the file is yet present (Windows message)(but I doesn't enter in the debug mode or printing in the console. It doesn't enter in my action)…
It's like it try to interprete that the file will move… The Cifs does some check… but I have no idea than what it does….

In my action : (I always rename the files to find the bug… but I have fund nothing ) :

(Global) :
private Random random = new Random();

(in the method) :
   …
  newName += System.currentTimeMillis() + random.nextInt();
  fileFolderService.move(nodeToMove, parentNodeRef, newName);
  …


Has someone an idea of this behavior :?:
11 REPLIES 11

dranakan
Champ on-the-rise
Champ on-the-rise
Hello,

Has someone an idea about the work that do the cifs before executing the action  :?:

dranakan
Champ on-the-rise
Champ on-the-rise
I have test without moving in directories (just changing name) and all is ok.

Now I show you my code (here, the file will be moved in the directory "newRep").

(Global) :
private Random random = new Random();

public void executeImpl(Action action, NodeRef actionedUponNodeRef) {
      if (logger.isDebugEnabled()) {
         logger.debug("Action : OrganiseFileInDirectory");
      }
      // Check that the node still exists
      if (this.nodeService.exists(actionedUponNodeRef) == true) {
         try {
            if (logger.isDebugEnabled()) {
               logger.debug("Begin");
            }
            // Create tool to manage nodes
            NodeManager nodeManager = new NodeManager(nodeService,
                  fileFolderService, mimetypeService, contentService);

            // Get the name of the node
            String nameDocument = nodeManager
                  .getNameOfNodeRef(actionedUponNodeRef);
            
            // Directory to create
            String newRep = "newRep";
            
            // Test that it is not newRep coming (the action is not generate by the creation of this directory)
            if (nameDocument.equals(newRep)){
               return;
            }
            
            // Get infos on the present directory
            NodeRef parentNodeRef = nodeService.getPrimaryParent(
                  actionedUponNodeRef).getParentRef();
            
            // Creation of a directory
            NodeRef nodeNewRep = nodeService.getChildByName(parentNodeRef,
                  ContentModel.ASSOC_CONTAINS, newRep);
            if (nodeNewRep == null) {
               // Create the newRep
               FileInfo fileInfo = fileFolderService.create(parentNodeRef,
                     newRep, ContentModel.TYPE_FOLDER);
               nodeNewRep=fileInfo.getNodeRef();
            }

            // Move the file in the directory
            nameDocument += System.currentTimeMillis() + random.nextInt();
            fileFolderService.move(actionedUponNodeRef, nodeNewRep, nameDocument);

         } catch (Exception e) {
            if (logger.isDebugEnabled()) {
               logger.debug(e.getMessage());
               logger.debug(e.toString());
            }
         }

         if (logger.isDebugEnabled()) {
            logger.debug("End");

         }

      }

   }

I can use it with the UI, but in the CIFS, I can put the file just one time (it doesn't enter in the code, just popup to say that the file exist).

Need your help 🙂

dranakan
Champ on-the-rise
Champ on-the-rise
I have try to rename the file and after moving it, but I have always the same problem 😞

Rename the file is ok

// Move the file in the directory
nameDocument += System.currentTimeMillis() + random.nextInt();
            
fileFolderService.move(actionedUponNodeRef, parentNodeRef,
nameDocument);         

But rename the file and after moving it : "Impossible to add the file, it exists"


// Move the file in the directory
nameDocument += System.currentTimeMillis() + random.nextInt();      
fileFolderService.move(actionedUponNodeRef, parentNodeRef, nameDocument);
            
fileFolderService.move(actionedUponNodeRef, nodeNewRep,null);

loftux
Star Contributor
Star Contributor
Have you tried to run your rule in background ("Run rule in background" in the rule wizard step 3)?
It may be that your script kicks in before cifs has completed the save process.

dranakan
Champ on-the-rise
Champ on-the-rise
Thanks for your response Loftux,

Yes, I have try to run it in background … but I have the same result.

It is perhaps a bug behavior… I am not sure because I think this action could be yet created by other people (I think that it's useful automatic task). As nobody says that the code have a important mistake, I have created a bug report : https://issues.alfresco.com/jira/browse/JLAN-84

loftux
Star Contributor
Star Contributor
Just another thing to try (as workaround),
can you make a copy, and move that copy to your target folder. Then as a last step delete original.
Making a copy in Alfresco is inexpensive, it only makes a new db entry, it still points to the same content file (until one of them is changed).

dranakan
Champ on-the-rise
Champ on-the-rise
same result…

I have do like this :



fileFolderService.move(actionedUponNodeRef, parentNodeRef,nameDocument);
fileFolderService.copy(actionedUponNodeRef, nodeNewRep,null);

dranakan
Champ on-the-rise
Champ on-the-rise
Hello,

I have also this problem (I know… I am negative… Smiley Sad  ) with the FTP (no action started).
With the UI, the file is uploaded, the action start (all I want is done), but I need to give another name (on the properties page) to continue.

I think Alfresco keeps some information in cache or somewhere else about the content in the repository. Perhaps I need to clear this information…

If you have any ideas… don't be afraid to write something… I share this page 🙂

Thanks

luminary_becky
Champ in-the-making
Champ in-the-making
I was under the impression that if you had rules on the UI that they needed to be re-written (in effect written twice) for the CIFs interface. In what, I am not sure, but when we looked at it, it was a double overhead.