Fluent Commerce Logo
Docs
Sign In

Core Utilities Overview

Essential knowledge

Author:

Kirill Gaiduk

Changed on:

10 July 2025

Overview

The Core Utility (`util-core`) is a standard library of utility functions designed to simplify and accelerate Rule development on the Fluent Commerce platform. It provides a foundational set of helper classes that address common development challenges - such as safely handling event attributes, retrieving and converting settings, logging consistently, and minimizing boilerplate code when forwarding events or querying data.

Prerequisites

These articles assumes you're familiar with:

  • Java
  • Maven
  • JUnit

Key points

  • Event Management (`EventUtils`): Simplifies creating and forwarding events, ensuring attributes are copied correctly.
  • Rule Properties (`RuleUtils`): Streamlines retrieving and validating rule properties to avoid configuration errors.
  • Query Simplification (`QueryUtils`): Eases the execution of GraphQL queries, especially for paginated data.
  • Settings Management (`SettingUtils`) : Simplifies retrieving settings and automatically converts them from JSON to POJOs.
  • Logging (`LogUtils`): Provides structured logging for easier debugging and auditing.
  • JSON Handling (`JsonUtils`): Offers helpers for JSON serialization, deserialization, and comparison.
  • Date Formatting (`GqlDateUtils`): A simple utility for handling GraphQL-compatible dates.

Value Proposition

The `util-core` bundle delivers significant value to Fluent Commerce developers by addressing common pain points and accelerating development velocity:

Development Efficiency

  • Eliminate Boilerplate: Pre-built utility methods handle repetitive tasks like event forwarding, property validation, and JSON processing
  • Faster Implementation: Common patterns are abstracted into reusable, tested components
  • Reduced Debugging: Standardized approaches prevent common errors and edge cases

Code Quality & Maintainability

  • Consistent Patterns: Enforce best practices across your rule implementations
  • Better Maintainability: Centralized utilities make code easier to understand and modify
  • Type Safety: Strongly-typed utilities prevent runtime errors

Team & Production Benefits

  • Battle-Tested: Utilities are used across production environments
  • Team Productivity: Standard utilities create a common language and accelerate onboarding
  • Comprehensive Documentation: Detailed JavaDocs and examples for every utility


Explanation through an Example

At this point, it’s assumed you’ve already set up a plugin project and have some logic ready to implement. Let’s focus on how to write a Rule using the Core Utilities.

In this example, we’ll explore how to send a Webhook to a defined endpoint by writing a Rule using Core Utilities.

1import com.fluentretail.rubix.rule.meta.ParamString;
2import com.fluentretail.rubix.rule.meta.RuleInfo;
3import com.fluentretail.rubix.v2.context.Context;
4import com.fluentretail.rubix.v2.rule.Rule;
5import lombok.AllArgsConstructor;
6import lombok.Data;
7
8import java.util.Optional;
9
10import static com.fluentcommerce.util.core.EventUtils.cloneAndRenameEvent;
11import static com.fluentcommerce.util.core.LogUtils.logOnce;
12import static com.fluentcommerce.util.core.SettingUtils.getSetting;
13
14@RuleInfo(name = "SendWebhook", description = "Send webhook {setting}")
15@ParamString(name = "setting", description = "Name of the setting to load webhook info from")
16public class SendWebhook implements Rule {
17    @Override
18    public void run(Context context) {
19        String settingName = context.getProp("setting");
20
21        Optional<WebhookSetting> setting = getSetting(context, settingName).as(WebhookSetting.class);
22
23        if(setting.isPresent()) {
24            context.action().postWebhook(setting.get().url, cloneAndRenameEvent(context, setting.get().name));
25        } else {
26            logOnce(context, SendWebhook.class, "No webhook config found at '%s'", settingName);
27        }
28    }
29
30    @Data
31    @AllArgsConstructor
32    private static final class WebhookSetting {
33        String url;
34        String name;
35    }
36}