Fluent Commerce Logo
Docs
Sign In

Rule Parameters

Topic

Author:

Fluent Commerce

Changed on:

28 Sept 2023

Overview

Rule Parameters, also known as properties or props, and the configuration time inputs to the Rule.

Rule Parameters should be considered always required. Optional inputs to a Rule should usually be managed via Event Attributes.


Rule Parameters

Author:

Fluent Commerce

Changed on:

28 Sept 2023

Overview

Rule Parameters, also known as properties or props, and the configuration time inputs to the Rule.

Rule Parameters should be considered always required. Optional inputs to a Rule should usually be managed via Event Attributes.

Key points

  • There are 4 Parameter types available to declare on Rules:
    • String Parameters
    • Integer Parameters
    • Enum Parameters
    • Time Period Parameters
  • Also, on this page, see how to implement Multi-value Parameters

String Parameters

The 

`@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


1@ParamString(name = "productCatalogueRef", description = "The reference to the Product Catalogue", defaultValue = "FCRG:PC:MASTER")

Language: java

Name: Here is an example declaration of @ParamString:

Description:

[Warning: empty required content area]

Integer Parameters

The 

`@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`

1@ParamInteger(name = "ParamInt1", description = "Parameter Int 1", min = 0, max = 9, defaultValue = 0)

Language: java

Name: Here is an example declaration of @ParamInteger:

Description:

[Warning: empty required content area]

Enum Parameters

The 

`@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


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)

Language: java

Name: Here is an example declaration of @ParamEnum:

Description:

[Warning: empty required content area]

Time Period Parameters

The 

`@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`

1@ParamTimePeriod(name = "delaySeconds", description = "Delay value in seconds", min = 0, max = 9, defaultValue = 5)

Language: java

Name: Here is an example declaration of @ParamTimePeriod:

Description:

[Warning: empty required content area]

Multi-value Parameters

Rules can receive complex objects, such as Arrays or a JSON object, as Parameter inputs.

For example, you may need to receive an object containing a number of fields, or an array of Strings, Integers, or any other Objects.

Typically, we recommend using a standard String Parameter which receives a Setting name which references a Setting in the platform.

It is up to the Rule logic to handle the correct parsing of this complex type.

For example, let's say you want to provide a list of Virtual Catalogue References for querying Virtual Positions within the Rule. You could create a Rule Parameter for the Setting Name, such as 

`acme.sourcing.multi-channel.catalogues`
, which expects a JSON value such as the following:

1{
2  "virtualCatalogueRefs": [
3    "VC:ATS:ECOMMERCE",
4    "VC:ATS:MARKETPLACE"
5  ]
6}

Language: json

Name: Example

Description:

[Warning: empty required content area]
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}

Language: java

Name: The Rule could be implemented as follows:

Description:

[Warning: empty required content area]
Fluent Commerce

Fluent Commerce

Copyright © 2024 Fluent Retail Pty Ltd (trading as Fluent Commerce). All rights reserved. No materials on this docs.fluentcommerce.com site may be used in any way and/or for any purpose without prior written authorisation from Fluent Commerce. Current customers and partners shall use these materials strictly in accordance with the terms and conditions of their written agreements with Fluent Commerce or its affiliates.

Fluent Logo