Create a condition using Package SDK
- Updated: 2022/05/19
Create a condition using Package SDK
When using Automation 360, you can create a condition with the SDK package.
Using a condition
If and Loop are branching constructs in
Automation 360. They are used to run a sequence of actions when a
condition is set to true
. A condition is used along with the If and Loop packages. A condition
takes a set of inputs and returns a Boolean value.
Required annotations
For creating a condition, the following annotations are required:
Annotation | Usage |
---|---|
BotCommand
|
Use the BotCommand annotation with the
condition as commandType . This
ensures that the plain old Java object (POJO) is suitable for the creation
of an Automation 360 condition. |
CommandPkg
|
These values are used when creating a package. Provide a name, label, and description to the annotation. |
Idx
|
Annotate all the parameters and member variables that are required and
help with the validation check, or they might be displayed in the interface
for the input. Provide the index (Idx ) and the type.
|
Pkg
|
Annotate all the parameters and member variables that will be shown in
the interface. This annotation will be ignored if it is not accompanied by
the Idx . |
ConditionTest
|
The method that has to be called for testing the condition. It must
return a Boolean value. If the method accepts parameters, then annotate them
with Idx . |
Use case example
The following use case verifies whether the given number is greater than the other number.
- Create the POJO class with the business
logic:
public class IsGreater { public Boolean checkGreater(Double first, Double checkAgainst) { return first > checkAgainst; } }
- Annotate the POJO class to enable it for the Automation 360
condition and to create the
package:
@BotCommand(commandType = Condition) @CommandPkg(label = "Is greater condition", name = "IsGreater", description = "Checks if the given number is greater than the other.", node_label = "{{first}} > {{checkAgainst}} ") public class IsGreater { public Boolean checkGreater(Double first, Double checkAgainst) { return first > checkAgainst; } }
- Annotate the
checkGreater
method to indicate that this method should be used as a comparison method.@ConditionTest public Boolean checkGreater(Double first, Double checkAgainst) { return first > checkAgainst; }
Every condition must have exactly one test condition method.
- Annotate the parameters of the
checkGreater
method withIdx
andPkg
.Add
@NotEmpty
to ensure the value is not null.@ConditionTest public Boolean checkGreater( @Idx(index = "1", type = AttributeType.NUMBER) @Pkg(label = "Number to check") @NotEmpty Double first, @Idx(index = "2", type = AttributeType.NUMBER) @Pkg(label = "Number to compare against") @NotEmpty Double checkAgainst) { return first > checkAgainst; }
The attribute type number returns a
Double
.