Authors:
Kirill Gaiduk, Ben Harrison, Holger Lierse
Changed on:
15 Aug 2025
`util-core` for essential daily tasks, `util-dynamic` for building runtime queries, and `util-test` for simplifying testing.`pom.xml`, ensuring your implementation stays current.`pom.xml`. No more manual merging.`RuleUtils` utility helps retrieve them safely.`JsonUtils`.`getOrder(context)` method that would require every Rule to then filter out already fulfilled items, a better utility is `getUnfulfilledItems(context)`, which does that logic for you.`updateFulfilment` mutations.`pom.xml`.`EventUtils`, `SettingUtils`, `QueryUtils`, `RuleUtils`, `JsonUtils`.`DynamicUtils`, an advanced `JsonUtils`.`RuleExecutor`, `WorkflowExecutor`, `MockApiClient`.1@RuleInfo(name = "UpdateStatusHistory", /*...*/)
2public class UpdateStatusHistory implements Rule {
3
4 // A POJO to represent the entity fields we need
5 // With @Data, 'private' is redundant
6 @Data
7 public static class EntityData {
8 String createdOn;
9 String status;
10 List<Attribute> attributes;
11 }
12
13 @Override
14 public void run(Context context) {
15 // 1. DATA FETCHING: Use DynamicUtils to get only the fields we need
16 EntityData entity = DynamicUtils.query(context, EntityData.class);
17
18 // Find the existing history attribute from the entity's attributes
19 // (Logic to find attribute by name is omitted for brevity)
20 Optional<Attribute> historyAttribute = findHistoryAttribute(entity.getAttributes());
21
22 // 2. BUSINESS LOGIC: Deserialize old history, calculate time, add new entry
23 // The list of previous status updates is retrieved from the attribute using JsonUtils
24 List<StatusUpdate> history = getHistoryFromAttribute(historyAttribute);
25 long durationInPreviousStatus = calculateDuration(history, entity.getCreatedOn());
26 history.add(new StatusUpdate(entity.getStatus(), /*...*/));
27
28 // 3. ACTIONS: Use DynamicUtils to persist the updated attribute list
29 Attribute updatedAttribute = createHistoryAttribute(history);
30 DynamicUtils.mutate(
31 context,
32 ImmutableMap.of("attributes", Collections.singletonList(updatedAttribute))
33 );
34 }
35}