Actions
Overview
The Action Element of a Process represents function in the Process Flow and encapsulates a Stateless Java Class (i.e. Stateless in that it may contain static final constants but contain no instance variables).
These classes have an execute() method to which the Runtime Framework passes the Input Data Items specified in the Action and delivers data returned by the method to the Output Data Items specified in the Action. The execute() method may also generate an Outcome, which is also returned to the Action.
In this tutorial, a new action will be added to the existing SignOn process to log the current user in the console.
What you will learn
- How to add an action to an application process.
Pre-requisite
Should have followed Application Process Tutorial
Adding an action to Application Process
Open the modified SignOn Application process.
From the Outline view, expand the Actions group and search for the action SignOnCompletedExtension
From the Palette, expand the Actions Group, Drag and drop a new Action near SignOnCompletedExtension
Move the link from Success outcome of SignOnCompletedExtension to the new Action.
Double click on the outcome section on the new action and add "Success" as an outcome.
From the Palette, click the Link tool and then add a link from the Success outcome on the new action connecting it to the DisplayLoggedinUser action.
Right click on the action and select show properties.
In the Properties panel modify the Action ID property to LogCurrentUserAction.
Save the changes.
In order to add the User input to the new action, drag the User input from the SignedOn state to the input section of the new action.
(Else you can double click on the input section of the action and add a new input with the name enactor.coreUI.User
and enter type as com.enactor.core.signOn.ISignedOnUser
)
In addition, double click on the Outcomes section of the action and add the Success outcome choosing from the dropdown.
Save the changes.
Creating a new Action
Now, double click on the Action and when the pop up for No classname available is displayed, select New Action option.
Fill the details as follows.
- package : com.enactor.training.actions
- Name : LogCurrentUser
Click Finish.
The LogCurrentUser class should be created under the com.enactor.training.actions package.
As the current user should be logged, Enactor logger package should be imported to the class.
import com.enactor.core.utilities.Logger;
Add a logger instance to the class by inserting the following line as a class-level field.
private static final Logger logger = Logger.getLogger(LogCurrentUser.class.getName());
Finally, in order to log the user name use the below line.
logger.log(Logger.LOG_INFORMATION,String.format("You are logged in as %s", user.getDisplayName()));
Remove unused packages and save the changes.
The final LogCurrentUser class should look as follows.
package com.enactor.training.actions;
import com.enactor.core.application.process.ApplicationProcessException;
import com.enactor.core.application.process.IApplicationProcessData;
import com.enactor.core.application.process.IApplicationProcessOutcome;
import com.enactor.core.utilities.Logger;
import com.enactor.coreUI.actions.IUIAction;
import com.enactor.coreUI.processes.CoreUIOutcomes;
import com.enactor.coreUI.actions.UIActionFunctions;
import com.enactor.mfc.user.IUser;
import com.enactor.coreUI.annotations.Inputs;
import com.enactor.coreUI.annotations.Input;
import com.enactor.coreUI.annotations.Outputs;
import com.enactor.coreUI.annotations.Outcomes;
@Inputs({ @Input(name = "enactor.coreUI.User", type = com.enactor.mfc.user.IUser.class, required = true) })
@Outputs({})
@Outcomes({ "Success" })
public class LogCurrentUser implements IUIAction {
private static final Logger logger = Logger.getLogger(LogCurrentUser.class.getName());
/** Default Serial Version */
private static final long serialVersionUID = 1L;
@Override
public IApplicationProcessOutcome execute(IApplicationProcessData inputData, IApplicationProcessData outputData)
throws ApplicationProcessException {
IUser user = UIActionFunctions.getRequiredDataItem(inputData, "enactor.coreUI.User");
logger.log(Logger.LOG_INFORMATION, String.format("You are logged in as %s", user.getDisplayName()));
return CoreUIOutcomes.SUCCESS_OUTCOME;
}
}
Re-launch the POS application. After signing in, you should see a line similar to the one below appear in the console.
[AWT-EventQueue-0] INFO com.enactor.training.actions.LogCurrentUser - You are logged in as 'Username':Execute Action:'LogCurrentUserAction' State:'Start' Process:'Training/Pos/Sale/Sale'
Further Reading
Refer Actions