Annotations
Annotations
Contents
AP components
These annotations are mandatory to successfully run AP. Otherwise the code will break apart and won't be started
@ApModuleEntry
This one signifies that target class represents Automation Process
When node executes AP from jar package the class annotated by ApModuleEntry will be started
In case there is more than one annotated class the one with defaultRunModule=true
will be started
Annotated class is normally extended from ApModuleBase
class so its execution starts from run()
method
import eu.ibagroup.easyrpa.engine.annotation.ApModuleEntry; import eu.ibagroup.easyrpa.engine.apflow.ApModule; import eu.ibagroup.easyrpa.engine.apflow.TaskOutput; @ApModuleEntry(defaultRunModule=true) public class RdpAp extends ApModule { @Override public TaskOutput run() { // workflow resulting in TaskOutput } }
@ApTaskEntry
ApTaskEntry can be viewed as a single step inside Automation Process
Annotated class is normally extended from ApTaskBase with execute()
method as entry point, which encapsulates the business logic of this step
import eu.ibagroup.easyrpa.engine.annotation.ApTaskEntry; import eu.ibagroup.easyrpa.engine.apflow.ApTask; @ApTaskEntry(name = "Calculator task", description = "Demonstrates image-based automation") public class PerformCalcMultiUser extends ApTask { @Override public void execute() { // sequence of actions } }
Task level annotations
These annotations can be applied to fields and methods inside AP task entry
@Inject
The field annotated by @Inject will be set to a requested object defined in Feather scope, services, repositories, objects defined in ConfigurationModule-s:
import javax.inject.Inject; import eu.ibagroup.easyrpa.engine.annotation.ApTaskEntry; import eu.ibagroup.easyrpa.engine.apflow.ApTask; import eu.ibagroup.easyrpa.engine.service.StorageManager; @ApTaskEntry(name = "Extract Debtors") public class ExtractDebtors extends ApTask { @Inject private DebtorRepository repo; @Inject private StorageManager storageManager; @Override public void execute() { List<String> filesPathList = storageManager.listFiles(StorageManager.DEFAULT_S3_BUCKET, "input_directory", ".*\\.txt"); . . . . repo.save(. . . .); } }
@Output
The field annotated by @Output will be exported as a part of task output after its execution is finished.
It can be later imported into successive task using @Input
import eu.ibagroup.easyrpa.engine.annotation.ApTaskEntry; import eu.ibagroup.easyrpa.engine.annotation.Output; import eu.ibagroup.easyrpa.engine.apflow.ApTask; @ApTaskEntry(name = "Extract Debtors") public class ExtractDebtors extends ApTask { @Output(key = "Debtor") private DebtorsResultTo debtorsResult; @Override public void execute() { debtorsResult = new DebtorsResultTo("abc"); } }
@Input
@Input annotation allows import of the value exported from previous task
import eu.ibagroup.easyrpa.engine.annotation.ApTaskEntry; import eu.ibagroup.easyrpa.engine.annotation.Input; import eu.ibagroup.easyrpa.engine.apflow.ApTask; @ApTaskEntry(name = "Check Bank Guarantees") public class CheckBankGuarantees extends ApTask { @Input(key = "Debtor") private DebtorsResultTo debtorsResult; @Override public void execute() { // actions performed on debtorsResult } }
both @Input
and @Output
have properties key
and required
key
- the key associated with stored and retrieved value
required
- the boolean flag which enforces associated value to be checked on null
Variables with @Input annotation can only be used in execute() method. Such variables can not be used in other methods (e.g. they can not be used in a method marked with @AfterInit annotation).
@InputToOutput
This annotation is used to pass input variables to output.
It work before @Output takes place, i.e. the @Output has priority.
It has attributes:
- String[] value - list of keys is used to pass from input to output
Here is the code that pass only "id" to the output:
import eu.ibagroup.easyrpa.engine.annotation.ApTaskEntry; import eu.ibagroup.easyrpa.engine.annotation.InputToOutput; import eu.ibagroup.easyrpa.engine.apflow.ApTask; @ApTaskEntry(name = "Extract Debtors") @InputToOutput("id") public class ExtractDebtors extends ApTask { . . . . }
Here is the code that pass all keys to the output:
import eu.ibagroup.easyrpa.engine.annotation.ApTaskEntry; import eu.ibagroup.easyrpa.engine.annotation.InputToOutput; import eu.ibagroup.easyrpa.engine.apflow.ApTask; @ApTaskEntry(name = "Extract Debtors") @InputToOutput public class ExtractDebtors extends ApTaskBase { . . . . }
@Configuration
This annotation is used to obtain settings from configuration or vault.
It has attributes:
- String value - configuration key or vault alias with which the specified field to be associated if empty then field name is used.
- Class<ConfigurationService.Formatter> formatter - Value formatter, deserializes value object from string
- String defaultValue - default value as string
- boolean required - the value is required
- boolean vault - the target configuration is vault storage
import eu.ibagroup.easyrpa.engine.annotation.ApTaskEntry; import eu.ibagroup.easyrpa.engine.annotation.Configuration; import eu.ibagroup.easyrpa.engine.apflow.ApTask; @ApTaskEntry(name = "Demo Task") public class DemoTask extends ApTaskBase { @Configuration(value = "invoiceplane.client.url", defaultValue = "http://10.224.0.35:8085/index.php/sessions/login") protected String invoicePlaneUrl; @Configuration(value = "invoiceplane.secrets", defaultValue = "{\"user\": \"admin@ibagroup.eu\",\"password\": \"o66Lc1Jn6Z\"}") protected SecretCredentials invoicePlaneCredentials; @Configuration(value = "products_count", defaultValue = "20") private int maxProductsCountToRead; @Configuration(value = "private_key", vault = true) private String privateKey; . . . . . }
@AfterInit
@AfterInit
method will be called аfter a task object is initialized before ApTask.execute(TaskInput input)
is called.
At this execution point only @Inject/@Config annotations has not been processed yet for the task class, i.e. variables annotated with the others annotations are still null.
It makes a good practice to do additional task class initialization, for example:
import eu.ibagroup.easyrpa.engine.annotation.ApTaskEntry; import eu.ibagroup.easyrpa.engine.apflow.ApTask; @ApTaskEntry(name = "Demo Task") public class DemoTask extends ApTaskBase { private String filePath; @AfterInit public void init() { filePath = getConfigurationService().get("viljamis.file.path", System.getProperty("user.home")); } @Override public void execute() { . . . . } }
@OnError
Normally execute()
method can propagate exceptions outside of the task entry
In order to capture such exceptions and separate exception-handling logic it is recommended to create a specific method annotated with @OnError
import eu.ibagroup.easyrpa.engine.annotation.ApTaskEntry; import eu.ibagroup.easyrpa.engine.annotation.OnError; import eu.ibagroup.easyrpa.engine.apflow.ApTask; @ApTaskEntry(name = "Arithmetic Calculation") public class ArithmeticCalculation extends ApTask { @Override public void execute() throws Throwable { int a = 1/0; } @OnError public void onError(Throwable throwable) { System.err.println("Arithmetic error occured!"); } }
Page elements
This group annotates Page Object elements such as input fields, buttons, window panels etc
@FindBy
Indicates the locating mechanism for page element. Can receive field id, name, xpath, image and other parameters depending on the driver.
import eu.ibagroup.easyrpa.engine.annotation.FindBy; @FindBy(name = "One") private BrowserElement one; @FindBy(xpath = "//*[@id='userName']") private BrowserElement username;
@Wait
Indicates wait timeout in seconds and wait function for element expected condition. Can be paired with @FindBy annotation
import eu.ibagroup.easyrpa.engine.annotation.FindBy; import eu.ibagroup.easyrpa.engine.annotation.Wait; @FindBy(xpath = "//input[@id=\"Name\"]") @Wait(waitFunc = Wait.WaitFunc.VISIBLE, required = false) private BrowserElement nameField; @FindBy(xpath = "//a[@id=\"searchButton\"]") @Wait(value = 30, waitFunc = Wait.WaitFunc.CLICKABLE) private BrowserElement searchBtn;
@AfterInit
@AfterInit
method will be called аfter a page object is initialized.
import eu.ibagroup.easyrpa.engine.annotation.AfterInit; public class AboutNotepadPage extends Page<DesktopDriver, DesktopElement> { @AfterInit public void init() { getDriver().waitAndSwitchToWindow("About Notepad", 5); } . . . . }
Lombok Annotations
This set of annotations is provided by Lombok, the code generating library.
They help to avoid repetitive code writing and hence reduces the typical errors in daily tasks.
We covered Lombok use cases in separate article.