Skip to main content

Java Action

Action Naming Convention (JA-001)

Action class (i.e. any class that inherit from IUIAction) should end with "Action", for instance

CreateApplicationDataAction

Such actions should be located in a java package that also ends with .actions, for instance

package com.enactor.coreUI.actions;
public class CreateApplicationDataAction implements IUIAction {

Creating an Action (JA-002)

  • An Enactor Action should implement the com.enactor.coreUI.actions.IUIAction interface.
  • The Enactor Action must define the execute method.
  • Action annotations should be configured to declare inputs, outputs, and outcomes.

@Inputs({
@Input(name = CoreUIDataTypes.MESSAGE_BASENAME_DATA_NAME, type = String.class, required = true),
@Input(name = MyClass.MY_CUSTOM_DATA_NAME, type = MyClass.class, required = false),
@Input(name = MyClass.MY_CUSTOM_DATA_NAME, type = MyClass.class, required = false),
})
@Outputs({
@Output(name = CoreUIDataTypes.MAP_DATA_NAME, type = Map.class) ,
@Output(name = MyClass.MY_CUSTOM_DATA_NAME, type = MyClass.class),
})
@Outcomes({
CoreUIOutcomes.SUCCESS_OUTCOME_NAME,
CoreUIOutcomes.FAIL_OUTCOME,
MyCustomAction.MY_CUSTOM_OUTCOME_NAME
})
public class MyCustomAction implements IUIAction {

public static final String MY_CUSTOM_OUTCOME_NAME = "MyCustomOutcome";
public static final IApplicationProcessOutcome MY_CUSTOM_OUTCOME = new ApplicationProcessOutcome(MY_CUSTOM_OUTCOME_NAME);

public IApplicationProcessOutcome execute(IApplicationProcessData inputData, IApplicationProcessData outputData) throws UIProcessException,
ApplicationProcessException {

//TODO: Implement
return MY_CUSTOM_OUTCOME;
}

Use UIActionFunctions for Input validation (JA-003)

For mandatory inputs, use UIActionFunctions.getRequiredDataItem()

// Bad
if (inputData.containsNotNullData(LISTED_ITEMS_LIST_DATA_NAME)) {
listedItemsList = (List<IModifiableItem>) inputData
.getData(LISTED_ITEMS_LIST_DATA_NAME);
} else {
throw new UIProcessException(UIProcessException.MISSING_DATA,
"The variable "+LISTED_ITEMS_LIST_DATA_NAME+" is required as an input");
}
// Good
listedItemsList = UIActionFunctions.getRequiredDataItem(inputData, LISTED_ITEMS_LIST_DATA_NAME);

If you need to get an optional parameter, use one the following

// Good
listedItemsList = UIActionFunctions.getOptionalDataItem(inputData, LISTED_ITEMS_LIST_DATA_NAME);
listedItemsList = UIActionFunctions.getOptionalDataItem(inputData, LISTED_ITEMS_LIST_DATA_NAME, defaultValue);

Setting Action Outputs (JA-004)

We can set the action outputs directly the outputData object provided to the execute method of an Action.

Unlike Java methods, an Enactor Action can have multiple outputData objects.

outputData.setData( CoreUIDataTypes.BOOLEAN_DATA, Boolean.FALSE);
outputData.setData( MyClass.MY_CUSTOM_DATA, myClassObject);

Action should be stateless (JA-005)

Define your variables inside the execute method of an action or inside other private methods and not as class member. The runtime engine can (although it doesn't at the moment) re-use an instance of an action and we do not want side effect between execution.

public class MyAction implements IUIAction {

// Bad
List<String> MyList = new ArrayList<>();

public IApplicationProcessOutcome execute(...) {
// Good
List<String> MyList = new ArrayList<>();
...
}
}