Chained Action Executer - tsgrp/HPI GitHub Wiki
The Chained Action Executer gives you the ability to control the execution of multiple action executers from within the context of a single action executer. With this, executing a single action from HPI gives you the ability to execute multiple OC actions in a particular order, or execute some but not all actions based on parameters sent over in the execution of the action.
For example, you may want to pass the results of one subAction into another subAction. Or, you may have logic that determines which subActions are triggered based on parameters sent to the chained action when executed from HPI. Chained Action Executer allows you to accomplish both of these tasks.
Create a new Java class that will be your chained action executer. This is where your logic for calling your subActions will live. See the example section for how to call the subActions.
All actions that should be made available for execution within the Chained Action Executer
All required conditions that must be true for the chained action to show up in HPI. This should be condition-alwaystrue
unless using ignoreSubActionConditionEvals
. See Ignore SubAction Condition Evaluators
below.
All non-required conditions actions will be evaluated by the chained action. This should be condition-alwaystrue
unless using ignoreSubActionConditionEvals
. See Ignore SubAction Condition Evaluators
below.
Further conditions that must be met to show the action, supporting both AND and OR. This should be condition-alwaystrue
unless using ignoreSubActionConditionEvals
. See Ignore SubAction Condition Evaluators
below.
When using a Chained Actions Executer, all conditions on all subActions are evaluated and must return true
in order for the chained action to be shown. If you want to ignore all subAction conditions and define your own Required, Non-Required, and Grouped Conditions, set ignoreSubActionConditionEvals
to true
and configure the necessary conditions on the chained action executer accordingly. THIS MUST BE THE FIRST PROPERTY SET IN THE BEAN IN ORDER TO AVOID THE SUBACTION CONDITION EVALUATORS FROM FIRING
NOTE: This flag simply ignores the conditions when evaluating if the action should appear or not for the user, it does not affect the action's execution itself. (i.e. if a subAction has condition-write-conditionevaluator
, ignoreSubActionConditionEvals
is used, and the conditions configured on the chained action executer give a user that does not have write ability on the given object access to the action, executing that action will result in a failure in OC)
Same concept as Ignore SubAction Conditions Evaluators
. If one of your subActions requires a mandatory parameter that you will be obtaining from the execution of another subAction, the mandatory parameters evaluation will fail. To avoid this, list all mandatory parameters from all subActions EXCEPT the ones that will be obtained from another subActions execution. For example, if one subAction requires an objectId that will be obtained from the execution from another subAction, list all subActions' mandatory parameters on the chained action executer's mandatory parameter list EXECPT for objectId. This will allow the actions to evaluate correctly.
Below is an example of a configured chained action bean (EmailWithFolderNotesActionExecuter):
<bean id="action-sendEmail" class="com.tsgrp.opencontent.core.action.executer.EmailWithFolderNoteActionExecuter" parent="AbstractActionExecuter" scope="prototype">
<property name="ignoreSubActionConditionEvals" value="false" />
<property name="subActionsList">
<list>
<ref bean="sendEmail-chained"/>
<ref bean="folderNotes-chained"/>
</list>
</property>
<!-- this is here, because we need it for spring to call the setRequiredConditions method -->
<property name="requiredConditionEvaluatorList">
<list>
<value>condition-alwaystrue</value>
</list>
</property>
<!-- this is here, because we need it for spring to call the setNonRequiredConditions method -->
<property name="nonRequiredConditionEvaluatorList">
<list>
<value>condition-alwaystrue</value>
</list>
</property>
<property name="groupedConditionEvaluatorList">
<list>
<list>
<value>condition-alwaystrue</value>
</list>
</list>
</property>
<property name="description" value="Sends an email and can be configured to then attach a folder note to the email object."/>
</bean>
To access your subActions in your chained action exectuer, grab each action off of the subActions array, like this:
AbstractActionExecuter emailExecuter = subActionsList.get(0);
AbstractActionExecuter noteExecuter = subActionsList.get(1);
Now you can call executeImpl
on your actions at the appropriate time.
To pass a result from one action to the next, call action.setResult()
in a subAction. This result will now be available in any other subAction that is executed by the chained action exectuer. Note that the results is placed on the general Action
object which is passed into each subAction. If setResult
is called again in another subAction, the original result value will be overridden.