cancel
Showing results for 
Search instead for 
Did you mean: 

Update content using Rule in background

jamilnour
Star Contributor
Star Contributor

Hello,

I created an action-executer to change and replace the content of a document. I used this action to create a Rule and the rule is working fine and the document is well replaced.

But when I choose to Run the Rule in background I have the action not working with the following error when trying to update the noderef:  "ConcurrencyFailureException: Failed to update node".

Note that the rule is fired after a create/upload a document

Any help on how to fix this issue?

Thank you

Jamil

5 REPLIES 5

kaynezhang
World-Class Innovator
World-Class Innovator

It seems two threads  try to concurrently modify the same node 
Please check if there is another thread (job or action or another rule still have effect that trigger your action) try to modify the node when your action-executer is triggered

jamilnour
Star Contributor
Star Contributor

Yes it is clear that what you said is happen. I don't have any other rule or action running. 

So the action-executer is run during the entering of the document inside the folder but how to make sure the document and the node is ready to be updated? How "Rule in background" is working? and what is the difference between "Run in background" and "Run normally".

It seems Run normally means that after the document is uploaded and entered the folder the Rule is started so my Rule is well working

My action-executer is written in java so what to add to tell to wait until the noderef is ready to be replaced?


Thank you

Jamil

kaynezhang
World-Class Innovator
World-Class Innovator

Run normally tells the action to be executed synchronously,and it is in the same transaction with calling method
Run in background Indicates the rule should execute the action asynchronously ,it is running in its own transaction.

So you error may be caused by transactions ,could you please paste your action java code here?

Hi Kayne,

Below is a portion of the action-executer. Add aspect to the actionedUponNodeRef gives the ConcurrencyFailureException. 

actionedUponNodeRef is the document itself and I can get the bytes without problems

We are using the Asynchronous calls of the actionExecuter from web-script call like the following and works well:

Action action = getServiceRegistry().getActionService().createAction("lock-folder", params);
action.setExecuteAsynchronously(true);

But my question is how to call an action-executer asynchronously from inside a rule? (no option for that)

Do I need to add some code for that?

Thank you

Jamil

public class LockFileRuleActionExecuter extends ActionExecuterAbstractBase {

....
@Override
protected void addParameterDefinitions(List<ParameterDefinition> paramList) {
paramList.add(new ParameterDefinitionImpl(PARAM_COMMENT,
DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_COMMENT)));
}


@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
...
if (m_nodeService.exists(actionedUponNodeRef)) {
...
if (!getNodeService().hasAspect(actionedUponNodeRef, IndorseModel.ASPECT_LOCK)) {
// add the aspect with properties (first time access)
getNodeService().addAspect(actionedUponNodeRef, IndorseModel.ASPECT_LOCK, new HashMap<QName, Serializable>());<---Exception
getNodeService().setProperty(actionedUponNodeRef, IndorseModel.PROP_LOCKTO, "fullName");
getNodeService().setProperty(actionedUponNodeRef, IndorseModel.PROP_LOCKDATE, new java.util.Date());
getNodeService().setProperty(actionedUponNodeRef, IndorseModel.PROP_LOCKBY, "fullName");

//add aspects
m_alfrescoRepoHelper.updateContent(actionedUponNodeRef, signedDoc2, true);

}
else{
action.setParameterValue(PARAM_RESULT, "Can't lock a locked document");
}
}
}

}