cancel
Showing results for 
Search instead for 
Did you mean: 

Read-Write transaction started within read-only transaction

ceeliro
Champ in-the-making
Champ in-the-making
Hi All, thanks for reading

Time ago I created a custom-transformer and added to the end of the chain of some fail-over transformers to make some jobs (send email, replace the content of the document with an default content, add aspect, etc) if the content cannot be transform for some reason (encrypted, corrupted, etc) It used to work like a charm for community 4.2.d but since I upgraded to the community 5.0.a it doesn't work anymore (I updated all the old configuration for transformers to the new mechanism in the alfresco-global.properties). The thing is that my custom transformer is still called if something is going wrong but fails to add the custom aspect, reason: Read-Write transaction started within read-only transaction. I know that the exception it is produced when applying the aspect but don't know how to sort it out. Any help?

Excuse my english


public class NotSupportedContentTransformer extends AbstractContentTransformer2 {



@Override
protected void transformInternal(ContentReader reader,
        ContentWriter writer, TransformationOptions options) throws Exception {

   // At this point we know that something went wrong so lets give a shout
   // to the Work-Group administrators to let them know…
   String fileName = this.serviceRegistry.getFileFolderService().getFileInfo(
              options.getSourceNodeRef()).getName();
   sendFailedThumbnailNotification(fileName, options.getSourceNodeRef());
      
   InputStream input = this.getClass().getClassLoader().getResourceAsStream(corruptedFileTemplate);
   OutputStream output = writer.getContentOutputStream();
        IOUtils.copy(input, output);
       output.close();
       input.close();
       
       // if everything is O.K. we apply the aspect "icmr:emcryptedContet". Even if it is not encrypted but corrupted
       try {
          this.serviceRegistry.getNodeService().addAspect(options.getSourceNodeRef(),
                IcmrModel.ASPECT_ENCRYPTED_CONTENT, null);
       } catch (Exception e) {
          log.error("Unexpected error", e);
       }
}
2 REPLIES 2

kaynezhang
World-Class Innovator
World-Class Innovator
You can first check if it is in a read-only transaction, if yes force to create a new transaction like following


        RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
        txnHelper.setForceWritable(true);
        boolean requiresNew = false;
        if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_READ_WRITE)
        {
           
            requiresNew = true;
        }
        txnHelper.doInTransaction(new RetryingTransactionCallback<Object>()
        {

            @Override
            public Object execute() throws Throwable
            {
          try {
             this.serviceRegistry.getNodeService().addAspect(options.getSourceNodeRef(),
                IcmrModel.ASPECT_ENCRYPTED_CONTENT, null);
             } catch (Exception e) {
             log.error("Unexpected error", e);
             }
            }
   
        }, false, requiresNew);

ceeliro
Champ in-the-making
Champ in-the-making
Thanks very much! it made the job…