Rule Parameters
TopicTopics usually cover more ground than other articles.
Author:
Fluent Commerce
Changed on:
28 Sept 2023
Author:
Fluent Commerce
Changed on:
28 Sept 2023
Author:
Fluent Commerce
Changed on:
28 Sept 2023
`@ParamString` Annotation defines a Parameter for the Rule of type `String`.It contains 3 properties:`name` - the Name of the Parameter. This is Required.`description` - the Description of the Parameters. This is Required.`defaultValue` - this is the Default Value of the Parameter. This is Optional.| Property Name | Description | Required | Default Value |
`name` | The name of the rule parameter. This becomes the key name used in the `props` construct of the Workflow JSON configuration. | Y | |
`description` | A helpful text describing the parameter. This is important meta data for use within the Workflow Builder UI and the Plugin GET API. | Y | |
`defaultValue` | A default value if the parameter is not set. | N |
`@ParamInteger` Annotation defines a Parameter for the Rule of type `Integer`.It contains 5 properties:| Property Name | Description | Required | Default Value |
`name` | The name of the rule parameter. This becomes the key name used in the `props` construct of the Workflow JSON configuration. | Y | |
`description` | A helpful text describing the parameter. This is important meta data for use within the Workflow Builder UI and the Plugin GET API. | Y | |
`min` | The minimum value allowed to be entered for the rule parameter. | N | `Integer.MIN_VALUE` |
`max` | The maximum value allowed to be entered for the rule parameter. | N | `Integer.MAX_VALUE` |
`defaultValue` | A default value if the parameter is not set. | N | `Integer.MIN_VALUE` |
`@ParamEnum` Annotation defines a Parameter for the Rule of type `Enum`. This is useful for circumstances where only a specific set of values is acceptable as an input. There is however a downside though. If ever the list of parameter values needs to be changed or extended, it would require a code change, so use this only when this is not likely to be the case. If you need a list of parameter values for a Rule, but it needs to remain configurable at runtime, this can be achieved using Settings. See Multi-value Parameters for more information.It contains 4 properties:| Property Name | Description | Required | Default Value |
`name` | The name of the rule parameter. This becomes the key name used in the `props` construct of the Workflow JSON configuration. | Y | |
`description` | A helpful text describing the parameter. This is important meta data for use within the Workflow Builder UI and the Plugin GET API. | Y | |
`options` | This is the Enum class providing the available options to be selected. | Y | |
`defaultValue` | A default value if the parameter is not set. | N |
`@ParamTimePeriod` Annotation defines a Parameter for the Rule of type `Integer` signifying a duration in seconds.It contains 5 properties:| Property Name | Description | Required | Default Value |
`name` | The name of the rule parameter. This becomes the key name used in the `props` construct of the Workflow JSON configuration. | Y | |
`description` | A helpful text describing the parameter. This is important meta data for use within the Workflow Builder UI and the Plugin GET API. | Y | |
`min` | The minimum value allowed to be entered for the rule parameter. | N | `Integer.MIN_VALUE` |
`max` | The maximum value allowed to be entered for the rule parameter. | N | `Integer.MAX_VALUE` |
`defaultValue` | A default value if the parameter is not set. | N | `Integer.MIN_VALUE` |
`acme.sourcing.multi-channel.catalogues`, which expects a JSON value such as the following:1@ParamString(name = "productCatalogueRef", description = "The reference to the Product Catalogue", defaultValue = "FCRG:PC:MASTER")1@ParamInteger(name = "ParamInt1", description = "Parameter Int 1", min = 0, max = 9, defaultValue = 0)1// Define an Enum use either in the same Java file as the Rule, or in a separate file within your Plugin Project:
2enum YesNoEnum {
3 YES, NO
4}
5
6@ParamEnum(name = "DoSomething", description = "Select YES or NO to doing something", options = YesNoEnum.class, defaultValue = YesNoEnum.YES)1@ParamTimePeriod(name = "delaySeconds", description = "Delay value in seconds", min = 0, max = 9, defaultValue = 5)1{
2 "virtualCatalogueRefs": [
3 "VC:ATS:ECOMMERCE",
4 "VC:ATS:MARKETPLACE"
5 ]
6}1@RuleInfo(name = "FulfilFromMultiSources", description = "Fulfils from any available positions in multiple Virtual Catalogues configured in setting {cataloguesSetting}")
2@ParamString(name = "cataloguesSetting", description = "The Setting name holding the list of Virtual Catalogue References to include in the search")
3public class FulfilFromMultiChannelSources implements Rule {
4 @Override
5 public <C extends Context> void run(C context) {
6 String cataloguesSetting = context.getProp("cataloguesSetting");
7
8 // Note: the `getSetting` method is not provided, but encapsulates querying the GraphQL Settings API.
9 Optional<VirtualCataloguesSetting> setting = getSetting(context, cataloguesSetting).as(VirtualCataloguesSetting.class);
10
11 if(setting.isPresent()) {
12 // Continue Sourcing...
13 } else {
14 // Note: the `logOnce` method is not provided, but encapsulates the `context.action().log()` action.
15 logOnce(context, VirtualCataloguesSetting.class, "No Catalogues config found at '%s'", cataloguesSetting);
16 }
17 }
18
19 @Data
20 @AllArgsConstructor
21 private static final class VirtualCataloguesSetting {
22 String[] virtualCatalogueRefs;
23 }
24}