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
(When extending `BaseSourcingCriterion`) Put computation in `execute(CriterionContext ctx)`.
(If needed) Parse configuration in `parseParams(JsonNode params)`.
(Optional) Override `normalize(min, max, rating)` when your metric is “lower is better” (e.g., distance).
1@SourcingCriterionInfo(2 name ="CustomSourcingCriterion",3 type ="company.sourcing.criterion.custom",4 tags ={"ATS-agnostic"}// or "ATS-dependent", "Exclusion"5)6publicclassCustomSourcingCriterionextendsBaseSourcingCriterion{78@SourcingCriterionParam(name ="value", component ="integer")9privateInteger threshold;1011@Override12publicvoidparseParams(finalJsonNode params){13// parse threshold, lists, units, and etc.14}1516@Override17protectedfloatexecute(finalSourcingCriteriaUtils.CriterionContext ctx){18// Return:19// -1f to exclude a location,20// 0..1f (or any float) to score/rank a location, higher score is better.21return0.75f;22}2324// Override normalize(...) only if the default doesn’t fit your scale.25}
Tips
Return only a float (use `-1f` for location exclusion)
Validate required data from the context; handle nulls defensively
Mirror conventions from reference Criteria:
naming
logging
units
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: