I have developed a custom AMP action for Alfresco repo. I want Alfresco to understand that the action is failed if some condition is not satisfied and as a result show the failure message in pop-up.
I have written the followings in executeImpl
method but the action does not fail if condition is not satisfied.
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
if (condition) {
// Do something
} else {
((ActionImpl) action).setExecutionEndDate(new Date());
((ActionImpl) action).setExecutionStatus(ActionStatus.Failed);
((ActionImpl) action).setExecutionFailureMessage("Action is failed");
throw new RuntimeException("Action is failed");
}
}
Alfresco considers that the action is executed successfully. Yes, I have defined failure and success messages in share-config-custom.xml
. Is there any way to manage the action in this context?
I have tried throwing RuntimeException
, ActionServiceException
but I don't know why throwing a WebScriptException
works. Leaving the answer here if someone is looking for it:
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
if (condition) {
// Do something
} else {
throw new WebScriptException("Action is failed");
}
}