AnsweredAssumed Answered

Webscript transaction, InvalidNodeRefException

Question asked by pmartin on Jan 21, 2011
Latest reply on Feb 2, 2011 by openpj
I have this error org.alfresco.service.cmr.repository.InvalidNodeRefException - Node does not exist: workspace://SpacesStore/7ad81e86-3a70-4cde-9c21-4d615616b6ad throw by my webscript.

This error is not throw everytime, only when other webscript delete node is use by the first webscript.

Webscript are in javascript.

Exemple :
1- Run a webscript then make an directory with two empty document.
2- Start a second  webscript that read the directorty node and save his children in a variable and after wait for 10 secondes, durring this time start a third webscript that delete one document of the directory. After the 10 seconde when the second webscript loop in the directory children an the exeption is throw (InvalidNodeRefException - Node does not exist: )

This issue il easy to reproduce and can be fix with try catch in the javascript controler but if children node is use in the view (ftl) is not catchabled.

Question

Is this a desired behavior? Why all webscript are not in a transaction. Why other webscript can make fail other webscript? Can y put somme config to solve this issue.
If y make the webscript in java can i use the transaction api to solve this issue ?


// Webscript 1
var node = companyhome;
var testTxNode = companyhome.childByNamePath("txNodeTest");
if (testTxNode != null)
{
   testTxNode.remove();
}
testTxNode = node.createFolder("txNodeTest");
var f1 = testTxNode.createFile('file1.txt');
f1.properties.content.guessMimetype('file1.txt');
var f2 = testTxNode.createFile('file2.txt');
f2.properties.content.guessMimetype('file2.txt');


// Webscript 2
function wait(msecs)
{
   var start = new Date().getTime();
   var cur = start
   while(cur - start < msecs)
   {
      cur = new Date().getTime();
   }   
}
var error = "";
var childrens = "";
var testTxNode = companyhome.childByNamePath("txNodeTest");
if (testTxNode == null)
{
   error = "Step 1 not passed correctly, Step 2 failed"
}
else
{
   var childs = testTxNode.children;
   wait(10000);
   for each (child in childs)
   {
      childrens += " - " + child.name;
   }
   error = "Step 3 not passed correctly, Step 2 Work " + childrens
}
model.error = error;



// Webscript 3
var result = "";
var testTxNode = companyhome.childByNamePath("txNodeTest/file2.txt");
if (testTxNode == null)
{
   result = "Step 1 not passed correctly, Step 3 failed";
}
else
{
   testTxNode.remove();
   result = "passed";
}
model.resultat = result;

Outcomes