AnsweredAssumed Answered

Transaction and version management in a webscript

Question asked by fmstasi on Nov 14, 2014
Latest reply on Dec 9, 2014 by fmstasi
I am developing a webscript to add electronic signatures to a PDF document in Alfresco Share. I have a webscript in the repository which takes the input stream from the node, generates a new version, takes the output stream, and then calls a business method to insert the signature:

      InputStream is = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT).getContentInputStream() ;
      Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
      versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
      Version newVersion = versionService.createVersion(nodeRef, versionProperties) ;
      OutputStream os = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true).getContentOutputStream() ;
      signer.sign(is, os, […]) ;

This works correctly if I use
in the webscript descriptor; if it is set to
, the original version is overwritten, rather than a new one being generated.

Unfortunately, in this configuration if the signing method fails, a useless new version is generated.

I am not sure what is the better strategy to solve this problem: should I set transaction to required and manage streams differently, or should I leave it as it is and insert a transaction in the webscript?

Any suggestion is highly welcome…