AnsweredAssumed Answered

Unzip file from FTP and delete the node if any error

Question asked by saket.saraf on Jun 2, 2013
Latest reply on Jun 10, 2013 by mrogers
Hi All,

I am completely new in Alfresco. I am trying to build one sample application in which I want to add zip files from ftp to one of the alfresco repository. I have created one TEST folder in repository and able to upload the zip file into TEST folder.I am facing below problems

1) When file uploads into TEST folder i have written OnCreateNode policy which executes properly and it calls my customize method. In my customize method I have written the code where it checks the MIME_TYPE. For that purpose I have written below code

      AuthenticationUtil.runAsSystem(new AuthenticationUtil.RunAsWork<Object>() {
         public Object doWork() throws Exception {
            try {
               NodeRef nodeRef = childAssocRef.getChildRef();
               String nodeRefPath = nodeService.getPath(nodeRef)
                     .toString();      

               if (!serviceRegistry.getPermissionService()
                     .hasPermission(nodeRef, PermissionService.WRITE)
                     .equals(AccessStatus.ALLOWED)) {
                  return false;
               }
               if (nodeService.exists(nodeRef)) {
                  ContentReader reader = contentService.getReader(
                        nodeRef, ContentModel.PROP_CONTENT);
                                        if (reader != null) {
                        if (MimetypeMap.MIMETYPE_ZIP.equals(reader
                           .getMimetype())) {
……….
}

The above code works properly when I add zip file from Alfresco client using Add Content. But when i upload the zip file from FTP it breaks and it returns null for reader object. For you information I am uploading file using WinSCP tool and I have created new user for uploading the file with all roles.


2) Continuation to the same If I use alfresco client and add the zip file in TEST folder, my method unzip that file and stores in my customized folder and it returns the proper noderef for newly unzipped folder.

NodeRef parent = unzipFile(addedZipFile, extractFileLocationNodeRef);

But if I try to delete this folder using FileFolderService it always returns me with Node not exist error.
I tried to delete all children first, tried with NodeService delete method. Every time I got the same error.


It would be great if someone can provide me the valuable inputs for above problems.

Thanks

Outcomes