@Test public void commonDeclareThen() { String ruleName = "RULENAME"; String statusToSet = "STATUSTOSET"; String outputFieldName = "OUTPUTFIELDNAME"; Object result = "RESULT"; List<KiePMMLOutputField> outputFields = Collections.singletonList(KiePMMLOutputField.builder(outputFieldName, null).withResultFeature(PREDICTED_VALUE).build()); KiePMMLDroolsRule.Builder builder = KiePMMLDroolsRule.builder(ruleName, statusToSet, outputFields); KiePMMLDroolsRule rule = builder.build(); StringJoiner joiner = new StringJoiner(""); KiePMMLDescrRhsFactory.factory(ruleBuilder).commonDeclareThen(rule, joiner); String retrieved = joiner.toString(); assertTrue(retrieved.isEmpty()); ResultCode resultCode = ResultCode.OK; builder = builder.withResultCode(resultCode); rule = builder.build(); joiner = new StringJoiner(""); KiePMMLDescrRhsFactory.factory(ruleBuilder).commonDeclareThen(rule, joiner); retrieved = joiner.toString(); String expected = String.format(SET_PMML4_RESULT_CODE, resultCode); assertTrue(retrieved.contains(expected)); builder = builder.withResult(result); rule = builder.build(); joiner = new StringJoiner(""); KiePMMLDescrRhsFactory.factory(ruleBuilder).commonDeclareThen(rule, joiner); retrieved = joiner.toString(); expected = String.format(ADD_PMML4_RESULT_VARIABLE, result); assertTrue(retrieved.contains(expected)); expected = String.format(ADD_PMML4_OUTPUT_FIELD, outputFieldName, result); assertTrue(retrieved.contains(expected)); String focusedAgendaGroup = "FOCUSEDAGENDAGROUP"; builder = builder.withFocusedAgendaGroup(focusedAgendaGroup); rule = builder.build(); joiner = new StringJoiner(""); KiePMMLDescrRhsFactory.factory(ruleBuilder).commonDeclareThen(rule, joiner); retrieved = joiner.toString(); expected = String.format(FOCUS_AGENDA_GROUP, focusedAgendaGroup); assertTrue(retrieved.contains(expected)); }
protected void commonDeclareThen(final KiePMMLDroolsRule rule, final StringJoiner joiner) { if (rule.getFocusedAgendaGroup() != null) { joiner.add(String.format(FOCUS_AGENDA_GROUP, rule.getFocusedAgendaGroup())); } if (rule.getToAccumulate() != null) { joiner.add(String.format(UPDATE_STATUS_HOLDER_ACCUMULATE, rule.getToAccumulate())); } if (rule.isAccumulationResult()) { joiner.add(RETURN_ACCUMULATION); } if (rule.getResultCode() != null) { joiner.add(String.format(SET_PMML4_RESULT_CODE, rule.getResultCode())); } if (rule.getResult() != null) { joiner.add(String.format(ADD_PMML4_RESULT_VARIABLE, rule.getResult())); } if (rule.getReasonCodeAndValue() != null) { final KiePMMLReasonCodeAndValue reasonCodeAndValue = rule.getReasonCodeAndValue(); joiner.add(String.format(ADD_OUTPUTFIELD_VALUE, reasonCodeAndValue.getReasonCode(), reasonCodeAndValue.getValue())); } if (rule.getOutputFields() != null) { if (rule.getResult() != null) { commonDeclareOutputFields(rule.getOutputFields(), rule.getResult(), joiner); } else if (rule.isAccumulationResult()) { commonDeclareOutputFields(rule.getOutputFields(), "$statusHolder.getAccumulator()", joiner); } } }
KiePMMLDescrRhsFactory { protected void commonDeclareThen(final KiePMMLDroolsRule rule, final StringJoiner joiner) { if (rule.getFocusedAgendaGroup() != null) { joiner.add(String.format(FOCUS_AGENDA_GROUP, rule.getFocusedAgendaGroup())); } if (rule.getToAccumulate() != null) { joiner.add(String.format(UPDATE_STATUS_HOLDER_ACCUMULATE, rule.getToAccumulate())); } if (rule.isAccumulationResult()) { joiner.add(RETURN_ACCUMULATION); } if (rule.getResultCode() != null) { joiner.add(String.format(SET_PMML4_RESULT_CODE, rule.getResultCode())); } if (rule.getResult() != null) { joiner.add(String.format(ADD_PMML4_RESULT_VARIABLE, rule.getResult())); } if (rule.getReasonCodeAndValue() != null) { final KiePMMLReasonCodeAndValue reasonCodeAndValue = rule.getReasonCodeAndValue(); joiner.add(String.format(ADD_OUTPUTFIELD_VALUE, reasonCodeAndValue.getReasonCode(), reasonCodeAndValue.getValue())); } if (rule.getOutputFields() != null) { if (rule.getResult() != null) { commonDeclareOutputFields(rule.getOutputFields(), rule.getResult(), joiner); } else if (rule.isAccumulationResult()) { commonDeclareOutputFields(rule.getOutputFields(), "$statusHolder.getAccumulator()", joiner); } } } }
KiePMMLDescrRhsFactory { protected void commonDeclareThen(final KiePMMLDroolsRule rule, final StringJoiner joiner) { if (rule.getFocusedAgendaGroup() != null) { joiner.add(String.format(FOCUS_AGENDA_GROUP, rule.getFocusedAgendaGroup())); } if (rule.getToAccumulate() != null) { joiner.add(String.format(UPDATE_STATUS_HOLDER_ACCUMULATE, rule.getToAccumulate())); } if (rule.isAccumulationResult()) { joiner.add(RETURN_ACCUMULATION); } if (rule.getResultCode() != null) { joiner.add(String.format(SET_PMML4_RESULT_CODE, rule.getResultCode())); } if (rule.getResult() != null) { joiner.add(String.format(ADD_PMML4_RESULT_VARIABLE, rule.getResult())); } if (rule.getReasonCodeAndValue() != null) { final KiePMMLReasonCodeAndValue reasonCodeAndValue = rule.getReasonCodeAndValue(); joiner.add(String.format(ADD_OUTPUTFIELD_VALUE, reasonCodeAndValue.getReasonCode(), reasonCodeAndValue.getValue())); } if (rule.getOutputFields() != null) { if (rule.getResult() != null) { commonDeclareOutputFields(rule.getOutputFields(), rule.getResult(), joiner); } else if (rule.isAccumulationResult()) { commonDeclareOutputFields(rule.getOutputFields(), "$statusHolder.getAccumulator()", joiner); } } } private  KiePMMLDescrRhsFactory(final RuleDescrBuilder builder); }
KiePMMLDescrRhsFactory { protected void commonDeclareThen(final KiePMMLDroolsRule rule, final StringJoiner joiner) { if (rule.getFocusedAgendaGroup() != null) { joiner.add(String.format(FOCUS_AGENDA_GROUP, rule.getFocusedAgendaGroup())); } if (rule.getToAccumulate() != null) { joiner.add(String.format(UPDATE_STATUS_HOLDER_ACCUMULATE, rule.getToAccumulate())); } if (rule.isAccumulationResult()) { joiner.add(RETURN_ACCUMULATION); } if (rule.getResultCode() != null) { joiner.add(String.format(SET_PMML4_RESULT_CODE, rule.getResultCode())); } if (rule.getResult() != null) { joiner.add(String.format(ADD_PMML4_RESULT_VARIABLE, rule.getResult())); } if (rule.getReasonCodeAndValue() != null) { final KiePMMLReasonCodeAndValue reasonCodeAndValue = rule.getReasonCodeAndValue(); joiner.add(String.format(ADD_OUTPUTFIELD_VALUE, reasonCodeAndValue.getReasonCode(), reasonCodeAndValue.getValue())); } if (rule.getOutputFields() != null) { if (rule.getResult() != null) { commonDeclareOutputFields(rule.getOutputFields(), rule.getResult(), joiner); } else if (rule.isAccumulationResult()) { commonDeclareOutputFields(rule.getOutputFields(), "$statusHolder.getAccumulator()", joiner); } } } private  KiePMMLDescrRhsFactory(final RuleDescrBuilder builder); static KiePMMLDescrRhsFactory factory(final RuleDescrBuilder builder); void declareRhs(final KiePMMLDroolsRule rule); }
KiePMMLDescrRhsFactory { protected void commonDeclareThen(final KiePMMLDroolsRule rule, final StringJoiner joiner) { if (rule.getFocusedAgendaGroup() != null) { joiner.add(String.format(FOCUS_AGENDA_GROUP, rule.getFocusedAgendaGroup())); } if (rule.getToAccumulate() != null) { joiner.add(String.format(UPDATE_STATUS_HOLDER_ACCUMULATE, rule.getToAccumulate())); } if (rule.isAccumulationResult()) { joiner.add(RETURN_ACCUMULATION); } if (rule.getResultCode() != null) { joiner.add(String.format(SET_PMML4_RESULT_CODE, rule.getResultCode())); } if (rule.getResult() != null) { joiner.add(String.format(ADD_PMML4_RESULT_VARIABLE, rule.getResult())); } if (rule.getReasonCodeAndValue() != null) { final KiePMMLReasonCodeAndValue reasonCodeAndValue = rule.getReasonCodeAndValue(); joiner.add(String.format(ADD_OUTPUTFIELD_VALUE, reasonCodeAndValue.getReasonCode(), reasonCodeAndValue.getValue())); } if (rule.getOutputFields() != null) { if (rule.getResult() != null) { commonDeclareOutputFields(rule.getOutputFields(), rule.getResult(), joiner); } else if (rule.isAccumulationResult()) { commonDeclareOutputFields(rule.getOutputFields(), "$statusHolder.getAccumulator()", joiner); } } } private  KiePMMLDescrRhsFactory(final RuleDescrBuilder builder); static KiePMMLDescrRhsFactory factory(final RuleDescrBuilder builder); void declareRhs(final KiePMMLDroolsRule rule); static final String SET_PMML4_RESULT_CODE; static final String ADD_PMML4_RESULT_VARIABLE; static final String ADD_PMML4_OUTPUT_FIELD; static final String ADD_OUTPUTFIELD_VALUE; static final String UPDATE_STATUS_HOLDER_STATUS; static final String UPDATE_STATUS_HOLDER_ACCUMULATE; static final String UPDATE_STATUS_HOLDER; static final String RETURN_ACCUMULATION; static final String FOCUS_AGENDA_GROUP; }