cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco Rule - Javascript

alfsender
Champ in-the-making
Champ in-the-making
Hi All,

I have created a Rule, in Alfresco which will transform all incoming document to PDF. These PDFs will be copied to Transform folder, which will in be same location as original document.

If transformation fails say for XLS file (which is password protected) then i have to copy same file to Transform folder. javascript code which i am using is as below.


   try{
      var action = actions.create("transform");
      action.parameters["destination-folder"] = transformSpaceNode;
      action.parameters["assoc-type"] = "{http://www.alfresco.org/model/content/1.0}contains";
      action.parameters["assoc-name"] = pdfFileName;
      action.parameters["mime-type"] = "application/pdf"; 
   // Execute
      action.execute(document);            
   }catch(e)
   {
      logger.log(e);   
      logger.log(" Exception Occured while transformation for the Doc " + document.name);
      // copy original doc to transform space
      var copiedNode = document.copy(transformSpaceNode);
      logger.log("After Copy :: " + copiedNode.nodeRef);
   }



If code throws exception in Transformation, it will come to catch block and copy node to Transform space. It also displays nodeRef in logger after copy. But after executing script it does transaction rollback so node which it has copied is removed from Transform space.

please advise what should I do make it work.

Thank you.
6 REPLIES 6

mitpatoliya
Star Collaborator
Star Collaborator
try adding  copiedNode.save();

Thank you for your reply..

I have tried copiedNode.sace(), but still behaviour is same. As per my understading its executing script in one transaction, so if any thing fails its getting rollbacked. Is there any way we can control transaction in javascript.

Regards.

alfsender
Champ in-the-making
Champ in-the-making
Hi all

Now I have created the same transformation rule in java. Is there any way I can control transaction in java so it does not get rolled back. In my java action  I am getting new transaction through


transactoknService.getNonPropogationUserTransaction().

Then transaction.begin();

Here I am doing actual Transformation so if it fails it should not mark parent transaction of action for rollback.

but after that it still marks parent transaction for rollback and whatever node I have copied to new folder gets rollbacked..

So what should be the best way to copy file to folder if its transaction fails ?

Request all to send me your valuable suggestions.

mitpatoliya
Star Collaborator
Star Collaborator
I have checked your script again few  questions

how you are getting "transformSpaceNode" node reference?
Also after transformation action create new copy of transformed document original document will be as it is so you need to figure out the way to get noderef of that new transformed document.

Other option is you can also go for other transformation APIs rather then action APIs

Thank you for your reply.

I am creating a rule to transfom checked in document to PDF. Below are the steps.

Whats is Happening:

1) User checks in a document (say Native File), which gets uploaded through a webscript, now this webscript will have be executed in transaction.
2) After saving new node to alfresco, i am executing a custom action which is written java to convert native to PDF, this PDF will be stored in separate folder (Say : Web) not the folder in which native is checked in.
3) If new checked in file (native file) is password protected, in transformation action it will through exception.
4) After getting exception it will mark whole transaction for roll back, so new checked in native documents will also be rolled back.

What i am Expecting.
When exception is thrown while Transformation, i want same native file to be copied in Web folder.

Hops this explains what i am trying to achieve.

Let me know your inputs.

Thank you.

mitpatoliya
Star Collaborator
Star Collaborator
Why don't you handler exception in Java class where you are transforming the file?
There you can do similar operation in catch.