Put computation in `execute(CriterionContext ctx)` (when extending `BaseSourcingCriterion`)
Parse configuration in `parseParams(JsonNode params)` if needed
(Optional) Override `normalize(min, max, rating)` when your metric is “lower is better” (e.g., distance)
1@SourcingCriterionInfo(2 name ="mySourcingCriterion",3 type ="company.sourcing.criterion.my",4 tags ={"ATS-agnostic"}// or "ATS-dependent", "Exclusion"5)6publicclassMySourcingCriterionextendsBaseSourcingCriterion{78@SourcingCriterionParam(name ="value", component ="integer")9privateInteger threshold;1011@Override12publicvoidparseParams(finalJsonNode params){13// parse threshold, lists, units, 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.21return0.75f;22}2324// Override normalize(...) only if the default doesn’t fit your scale25}
Note
Return only a float (use -1f for “exclude”)
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 ="SampleCreateFulfilmentWithSourcingProfile",3 description ="Applies Sourcing Profile {"+"profileRef"+"} to a sourcing request (Order, Fulfilment Option, etc.) and produces Fulfilment(s)",4 accepts ={@EventInfo(entityType ="ORDER"),5@EventInfo(entityType ="FULFILMENT_CHOICE")}6)7@ParamString(name ="profileRef", description ="Profile reference to apply.")8@Slf4j9publicclassSampleCreateFulfilmentWithSourcingProfileimplementsRule{1011static{12// register custom criteria13SourcingCriteriaTypeRegistry.register("fc.sourcing.criterion.customCriteria",CustomCriteria.class);14// register custom condition15SourcingConditionTypeRegistry.register("fc.sourcing.condition.customCondition",CustomCondition.class);16}1718@Override19publicvoidrun(Context context){20SourcingCriteriaTypeRegistry.getTypeNameToClassMap().forEach((key, value)-> log.info("registered: {}", key));21SourcingProfile sourcingProfile =loadSourcingProfile(context);22if(sourcingProfile.getSourcingStrategies()!=null){23SourcingContext sourcingContext =loadSourcingContext(context,SourcingUtils::getUnfulfilledItems);24SourcingUtils.SourcingPlan plan =findPlanBasedOnStrategies(context, sourcingContext, sourcingProfile,25ImmutableList.of("ACTIVE","AT_RISK"),null);26if(plan.getFulfilments()!=null){27fillFulfilmentType(sourcingContext, plan.getFulfilments());28createFulfilments(context, sourcingContext, plan.getFulfilments());29}30}31}32}
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: