private static List<MethodCallExpr> ruleAttributes(RuleContext context, RuleDescr ruleDescr) {
        final List<MethodCallExpr> ruleAttributes = new ArrayList<>();
        final Set<Entry<String, AttributeDescr>> excludingDialect =
                ruleDescr.getAttributes().entrySet()
                        .stream().filter(r -> !r.getKey().equals("dialect"))
                        .collect(Collectors.toSet());
        for (Entry<String, AttributeDescr> as : excludingDialect) {
            MethodCallExpr attributeCall = new MethodCallExpr(null, ATTRIBUTE_CALL);
            attributeCall.addArgument(attributesMap.get(as.getKey()));
            String value = as.getValue().getValue().trim();
            switch (as.getKey()) {
                case "salience":
                    try {
                        Integer.parseInt( value );
                        attributeCall.addArgument( value );
                    } catch (NumberFormatException nfe) {
                        addDynamicAttributeArgument( context, attributeCall, value );
                    }
                    break;
                case "enabled":
                    if (value.equalsIgnoreCase( "true" ) || value.equalsIgnoreCase( "false" )) {
                        attributeCall.addArgument( value.toLowerCase() );
                    } else {
                        addDynamicAttributeArgument( context, attributeCall, value );
                    }
                    break;
                case "no-loop":
                case "auto-focus":
                case "lock-on-active":
                    attributeCall.addArgument( value );
                    break;
                case "agenda-group":
                case "activation-group":
                case "ruleflow-group":
                case "duration":
                case "timer":
                    attributeCall.addArgument( new StringLiteralExpr( value ) );
                    break;
                case "calendars":
                    if (value.startsWith( "[" )) {
                        value = value.substring( 1, value.length()-1 ).trim();
                    }
                    Expression arrayExpr = parseExpression("new String[] { " + value + " }");
                    attributeCall.addArgument( arrayExpr );
                    break;
                case "date-effective":
                case "date-expires":
                    attributeCall.addArgument( parseExpression(String.format("GregorianCalendar.from(LocalDate.parse(\"%s\", " + DATE_TIME_FORMATTER_FIELD + ").atStartOfDay(ZoneId.systemDefault()))", as.getValue().getValue())));
                    break;
                default:
                    throw new UnsupportedOperationException("Unhandled case for rule attribute: " + as.getKey());
            }
            ruleAttributes.add(attributeCall);
        }
        return ruleAttributes;
    }
private static List < MethodCallExpr > ruleAttributes ( RuleContext context , RuleDescr ruleDescr ) { final List < MethodCallExpr > ruleAttributes = new ArrayList < > ( ) ; final Set < Entry < String , AttributeDescr > > excludingDialect = ruleDescr . getAttributes ( ) . entrySet ( ) . stream ( ) . filter ( r -> ! r . getKey ( ) . equals ( "dialect" ) ) . collect ( Collectors . toSet ( ) ) ; for ( Entry < String , AttributeDescr > as : excludingDialect ) { MethodCallExpr attributeCall = new MethodCallExpr ( null , ATTRIBUTE_CALL ) ; attributeCall . addArgument ( attributesMap . get ( as . getKey ( ) ) ) ; String value = as . getValue ( ) . getValue ( ) . trim ( ) ; switch ( as . getKey ( ) ) { case "salience" : try { Integer . parseInt ( value ) ; attributeCall . addArgument ( value ) ; } catch ( NumberFormatException nfe ) { addDynamicAttributeArgument ( context , attributeCall , value ) ; } break ; case "enabled" : if ( value . equalsIgnoreCase ( "true" ) || value . equalsIgnoreCase ( "false" ) ) { attributeCall . addArgument ( value . toLowerCase ( ) ) ; } else { addDynamicAttributeArgument ( context , attributeCall , value ) ; } break ; case "no-loop" : case "auto-focus" : case "lock-on-active" : attributeCall . addArgument ( value ) ; break ; case "agenda-group" : case "activation-group" : case "ruleflow-group" : case "duration" : case "timer" : attributeCall . addArgument ( new StringLiteralExpr ( value ) ) ; break ; case "calendars" : if ( value . startsWith ( "[" ) ) { value = value . substring ( 1 , value . length ( ) - 1 ) . trim ( ) ; } Expression arrayExpr = parseExpression ( "new String[] { " + value + " }" ) ; attributeCall . addArgument ( arrayExpr ) ; break ; case "date-effective" : case "date-expires" : attributeCall . addArgument ( parseExpression ( String . format ( "GregorianCalendar.from(LocalDate.parse(\"%s\", " + DATE_TIME_FORMATTER_FIELD + ").atStartOfDay(ZoneId.systemDefault()))" , as . getValue ( ) . getValue ( ) ) ) ) ; break ; default : throw new UnsupportedOperationException ( "Unhandled case for rule attribute: " + as . getKey ( ) ) ; } ruleAttributes . add ( attributeCall ) ; } return ruleAttributes ; }
Build a list of method calls, representing each needed {@link org.drools.model.impl.RuleBuilder#attribute(org.drools.model.Rule.Attribute, Object)}
starting from a drools-compiler {@link RuleDescr}.
The tuple represent the Rule Attribute expressed in JavParser form, and the attribute value expressed in JavaParser form.