Outcome: After completing this guide, you will know how to extend the Responsive Sourcing Framework with a Custom Condition and apply it in real Strategies
Minimal essentials: The process has four parts - implement the Condition, register it, expose it in the Setting, and verify behavior
Application: You will be able to influence sourcing decisions with your own logic, tailored to specific business contexts
2. Include Sourcing Utilitiesin your plugin dependencies.Your plugin must have access to its own copy of `util-sourcing` at runtime so it can initialize its own local sourcing registries.You can include it in your project by:
Using a provided JAR, depending on your build setup
Reminder
Each plugin runs in an isolated classloader. Your custom Sourcing Conditions / Criteria will only be available if `util-sourcing` is included in the same plugin where your custom logic is implemented and executed
Create a class in your custom plugin that implements the `SourcingCondition` interface:1. Create your class, for example: `CustomSourcingCondition`.2. Implement the `SourcingCondition` interface.3. Add your business logic inside `evaluateWithContext` method.
1publicclassCustomSourcingConditionimplementsSourcingCondition{23// Declare your parameters4@JsonProperty5protectedString parameter1;67@JsonProperty8protectedString parameterN;910/**
11 * Evaluates the sourcing condition using the provided context.
12 *
13 * @paramsourcingContext a {@linkJsonNode} containing data used for evaluation;
14 * typically includes fields related to the order, location,
15 * inventory, or product information, implements
16 * {@linkcom.fluentcommerce.util.sourcing.context.SourcingContext}17 * @return{@codetrue} if the condition is satisfied based on the context,
18 * {@codefalse} otherwise
19 */20@Override21publicbooleanevaluateWithContext(finalJsonNode sourcingContext){22// Add your business logic here23returntrue;24}25}
Tips
Return only a boolean decision
Validate required fields from `sourcingContext` and handle missing/invalid data defensively
Mirror conventions from `DefaultSourcingCondition`:
naming
null handling
logging
Introduce Custom Sourcing Rules
Introduce custom versions of the Sourcing Rules that will execute your sourcing logic inside your plugin.
Note
Custom type registration and Rule execution must be initialized within the same plugin module.Creating custom Rules ensures that your Sourcing Condition or Criterion type is available during runtime evaluation.
1. Copy the reference SourcingRule implementation:
2. Rename the class3. Register your custom Sourcing Condition or Criterion inside the Rule class
1@RuleInfo(2 name ="CustomCreateFulfilmentWithSourcingProfile",3 description ="Applies Sourcing Profile {"+"profileRef"+"} to a sourcing request (Order, Fulfilment Option, etc.) and produces Fulfillment(s)",4 accepts ={@EventInfo(entityType ="ORDER"),5@EventInfo(entityType ="FULFILMENT_CHOICE")}6)7@ParamString(name ="profileRef", description ="Profile reference to apply.")8@Slf4j9publicclassCustomCreateFulfilmentWithSourcingProfileimplementsRule{1011static{12// register custom sourcing criterion13SourcingCriteriaTypeRegistry.register("company.sourcing.criterion.custom",CustomSourcingCriterion.class);14// register custom sourcing condition15SourcingConditionTypeRegistry.register("company.sourcing.condition.custom",CustomSourcingCondition.class);16}1718@Override19publicvoidrun(Context context){20SourcingProfile sourcingProfile =loadSourcingProfile(context);21if(sourcingProfile.getSourcingStrategies()!=null){22SourcingContext sourcingContext =loadSourcingContext(context,SourcingUtils::getUnfulfilledItems);23SourcingUtils.SourcingPlan plan =findPlanBasedOnStrategies(context, sourcingContext, sourcingProfile,24ImmutableList.of("ACTIVE","AT_RISK"),null);25if(plan.getFulfilments()!=null){26fillFulfilmentType(sourcingContext, plan.getFulfilments());27createFulfilments(context, sourcingContext, plan.getFulfilments());28}29}30}31}
4. Replace the reference Rule in your Workflow configuration with your custom Rule
Reminder
Each plugin initializes its own Sourcing registries.To ensure correct registration and runtime resolution of custom Sourcing Conditions or Criteria, your custom Rule must: