AnsweredAssumed Answered

Committing successful individual operation before Rollback

Question asked by ashokharnal on May 20, 2012
Latest reply on May 28, 2012 by ashokharnal
I am trying to transform all pdf files in a folder  to plain text; extract some meta-data
from each one of the plain text files and as it gets extracted, fill up Alfresco meta data
fields for that pdf file with those extracted values from text file.
However, if even in a single file there is a transformation error , the whole transaction
is rolled back.  Even log file is not saved.

For example, the following is a simple code to transform all pdf files
to plain text files in a folder. But if there is an error in transformation, not a single pdf file gets converted
to text file. Even log file is not saved. If the error causing file is deleted, all rest pdf files will get
transformed to plain text. (alfresco version is: 3.4.d)

This is very frustrating for I cannot carry out operation even on a single file. Please advise what
is the way out so that except the error causing file all other files get processed/transformed?

// Location of log file report
var dest = companyhome.childByNamePath("Sites/myoffice/documentLibrary/AURC Space/DEO/Reports") ;
// Create new log file and add heading
logFile =  dest.createFile("log.txt") ;
logFile.content = "Record of which files failed transformation" + "\r\n" ;

// Start iterating over all files in Drafts folder and transform each, one by one
var draftfolder =  companyhome.childByNamePath("Sites/myoffice/documentLibrary/AURC Space/DEO/Drafts") ;
var childfiles = draftfolder.children ;
var filenumb = childfiles.length ;
var count = 0 ;
// Go through each file, one by one
for ( i = 0 ; i < filenumb ; i++ )
   var docu = childfiles[i] ;
   var newtxtNode ;
      newtxtNode = docu.transformDocument("text/plain") ;
   catch (e)
      logFile.content += ++count + " Error in transformation: " +     ;
} // end of for loop ;

Will be grateful for reply.