Fluent Commerce Logo
Docs
Sign In

Rules SDK - Event Attributes

Essential knowledge

Author:

Fluent Commerce

Changed on:

13 Dec 2023

Overview

The 

`@EventAttribute`
 Annotation declares the Event Attributes the Rule requires from the Event.

Key points

  • Event Attributes

It contains 2 properties:

  • `name`
     - the Name of the Event Attribute.
  • `type`
     - the Type of the Event Attribute.

`@EventAttribute(name = "EventAttribute1", type = "STRING")`

Event Attribute Types include:

  • STRING (default)
  • INTEGER
  • BOOLEAN

The Event Attribute Type is used to provide configuration guidance to the Workflow, which is used to drive User Actions on the front end.

When using a complex event attribute type such as a JSON object, it is helpful to provide a meaningful name for that Type to the workflow configurators and frontend developers.

Currently, the Rules SDK only supports a limited set of Attribute Type names, and therefore the JSON attribute must use the default type of 

`STRING`
.

The Rule code can cast the event attribute into a specific type, such as 

`StockReserveDetails`
 below:

StockReserveDetails Class:

1@Value
2@Builder(builderClassName = "Builder", toBuilder = true)
3@JsonDeserialize(builder = StockReserveDetails.Builder.class)
4public class StockReserveDetails {
5    String locationRef;
6    Integer requestedQuantity;
7
8    @JsonPOJOBuilder(withPrefix = "")
9    public static class Builder {
10
11    }
12}

Language: json

Name: StockReserveDetails Class:

Description:

[Warning: empty required content area]

`
`

StockReservationRequest Rule:

1@EventAttribute(name = "StockReserveDetails") // user action attribute declaration type = "STOCK_RESERVE_DETAILS"
2public class StockReservationRequest implements Rule {
3
4    @Override
5    public <C extends Context> void run(C context) {
6        StockReserveDetails stockReserveDetails = context.getEvent().getAttribute("StockReserveDetails", StockReserveDetails.class);
7        // ...
8    }
9}

Language: json

Name: StockReservationRequest Rule

Description:

[Warning: empty required content area]

When declaring a User Action on a Ruleset using this rule, the Event Attribute Type should now be declared as follows:

StockReservation Ruleset & User Action:

1{
2    "name": "StockReservationRequest",
3    "type": "PRODUCT",
4    "subtype": "VARIANT",
5    "eventType": "NORMAL",
6    "rules": [
7        {
8            "name": "FCTRAINAU142.lesley.StockReservationRequest",
9            "props": {
10                "eventName": "SoftReserve",
11                "reservationCatalogue": "DEFAULT:1"
12            }
13        }
14    ],
15    "triggers": [
16        {
17            "status": "ACTIVE"
18        }
19    ],
20    "userActions": [
21        {
22            "context": [
23                {
24                    "label": "Reserve Stock",
25                    "type": "PRIMARY",
26                    "modules": [
27                        "servicepoint"
28                    ],
29                    "confirm": false
30                }
31            ],
32            "attributes": [
33                {
34                    "name": "StockReserveDetails",
35                    "label": "Stock Reservation Details",
36                    "type": "STOCK_RESERVE_DETAILS",
37                    "source": "",
38                    "defaultValue": "",
39                    "mandatory": false
40                }
41            ]
42        }
43    ]
44}

Language: json

Name: StockReservation Ruleset & User Action

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