Authors:
Ankit Mehta, Cille Schliebitz, Anita Gu
Changed on:
4 Feb 2025
`public static final String PARAM_NAME_HIGH_VALUE_THRESHOLD = "highValueThreshold"``@ParamInteger(name = Constants.PARAM_NAME_HIGH_VALUE_THRESHOLD, description = "The value threshold of which Orders should be marked as High Value")`Use accepts property to list which Entity type is accepted by the rule. Some Rules can accept only some specific entities if we don't use accepts then Rule can accept any Orchestration entity.

`context.action().mutation(updateOrderAttributesMutation);`1package com.training.rule;
2
3import com.fluentretail.rubix.event.Event;
4import com.fluentretail.rubix.foundation.graphql.type.UpdateOrderInput;
5import com.fluentretail.rubix.rule.meta.EventInfo;
6import com.fluentretail.rubix.rule.meta.ParamInteger;
7import com.fluentretail.rubix.rule.meta.RuleInfo;
8import com.fluentretail.rubix.v2.context.Context;
9import com.fluentretail.rubix.v2.rule.Rule;
10import com.training.util.Constants;
11
12@RuleInfo(name = "MarkOrderHighValueRule"
13 , description = "Mark the Order as HIGH_VALUE when the Order " +
14 "Total Price is greater than {" + Constants.PARAM_NAME_HIGH_VALUE_THRESHOLD + "}"
15 , accepts = {
16 @EventInfo(entityType = "ORDER")
17 }
18 )
19@ParamInteger(name = Constants.PARAM_NAME_HIGH_VALUE_THRESHOLD, description = "The value " +
20 "threshold of which Orders should be marked as High Value", defaultValue = 1000)
21
22
23public class MarkOrderHighValueRule implements Rule
24{
25 @Override
26 public <C extends Context> void run(C context)
27 {
28
29 }
30}1 /*
2 * Query Result Validation Code extracted into Private method, but should be a Util method.
3 */
4 private void validateQueryResult(GetOrderByIdQuery.Data data, String orderId, Context context) {
5
6 if (data.orderById() == null) {
7 throw new RuleExecutionException(String.format("Unable to process Rule: %s - No Order Found for Id: %s, Order Ref: %s",this.getName(),orderId, context.getEntity().getRef()), context.getEvent());
8 }
9
10 if (data.orderById().totalPrice() == null) {
11 throw new RuleExecutionException(String.format("Unable to process Rule: %s - No TotalPrice Found for Order Id: %s, Order Ref: %s",this.getName(),orderId, context.getEntity().getRef()), context.getEvent());
12 }
13 }1// Simple Logic:
2if (data.orderById().totalPrice() <= threshold) {
3return;
4}1mutation updateOrderAttributes($input: UpdateOrderInput) {
2 updateOrder(input: $input) {
3 ref
4 }
5}1/*
2 * Extracted to private method, but should be a Util method.
3 */
4 private List<AttributeInput> createNewAttributeInputAsList(String attrName, Class type, Object attrValue) {
5
6 AttributeInput attrInput = AttributeInput.builder().name(attrName).type(type.getSimpleName().toUpperCase()).value(attrValue).build();
7 List<AttributeInput> attributeInputList = new ArrayList<>();
8 attributeInputList.add(attrInput);
9 return attributeInputList;
10 }1// Prepare for Action:
2 List<AttributeInput> attributeInputList = createNewAttributeInputAsList(IS_HIGH_VALUE_ORDER_ATTRIBUTE_NAME, Attribute.Type.BOOLEAN.getValueClass(), Boolean.TRUE);
3
4 UpdateOrderInput updateOrderInput = UpdateOrderInput.builder()
5 .id(orderId)
6 .attributes(attributeInputList)
7 .build();
8 UpdateOrderAttributesMutation updateOrderAttributesMutation = UpdateOrderAttributesMutation.builder().input(updateOrderInput).build();