Transaction and version management in a webscript

cancel
Showing results for 
Search instead for 
Did you mean: 
fmstasi
Customer

Transaction and version management in a webscript

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
<transaction>none</transaction>
in the webscript descriptor; if it is set to
<transaction>required</transaction>
, 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…
3 Replies
openpj
Moderator
Moderator

Re: Transaction and version management in a webscript

Ti suggerisco di lasciare transaction a required e probabilmente la versione viene sovrascritta perché le versionproperties sono le stesse.
fmstasi
Customer

Re: Transaction and version management in a webscript

Oh, I was convinced I was posting in the English forum… I am afraid I selected an Italian subforum and then switched to English, while I should have done the opposite! Ok, I will reply in English anyway, for the sake of those searching answers via google in the future ;-)

Piergiorgio, above, suggests to leave transaction required, and explains that probably the version is overwritten because there is no change in properties. Thank you, Piergiorgio, this sounds very reasonable; and if this is the case, the problem should probably solve by itself, since one of my next steps will be to add a "Signed" aspect, which should be enough to change properties. I will check soon, and then post my findings here!
fmstasi
Customer

Re: Transaction and version management in a webscript

Coming back to the forums after a while, I can confirm that adding the "signed" aspect and setting a property creates a new version even with transaction=required. Many thanks to Giorgio for his answer!