Skip to content

Commit

Permalink
DROOLS-3795 : Added new row with action in between of guided decision…
Browse files Browse the repository at this point in the history
… table is replicating in source for other below rows (apache#2287)
  • Loading branch information
Rikkola authored and manstis committed Mar 28, 2019
1 parent feafede commit 634fbe5
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright 2010 Red Hat, Inc. and/or its affiliates.
*
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
Expand All @@ -23,7 +23,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.StringTokenizer;

import org.drools.workbench.models.datamodel.rule.ActionExecuteWorkItem;
import org.drools.workbench.models.datamodel.rule.ActionFieldList;
Expand Down Expand Up @@ -323,12 +322,30 @@ private boolean hasVariables(BRLActionColumn column) {
private void addAction(IAction action,
List<LabelledAction> actions) {
String binding = null;
boolean isUpdate = false;
if (action instanceof ActionInsertFact) {
final ActionInsertFact af = (ActionInsertFact) action;
binding = af.getBoundName();
final ActionInsertFact original = (ActionInsertFact) action;

final ActionInsertFact af = new ActionInsertFact(original.getFactType());
af.setBoundName(original.getBoundName());
af.setFieldValues(original.getFieldValues());

action = af;
binding = original.getBoundName();
} else if (action instanceof ActionSetField) {
final ActionSetField af = (ActionSetField) action;
binding = af.getVariable();
final ActionSetField original = (ActionSetField) action;

ActionSetField asf = null;
if (original instanceof ActionUpdateField) {
asf = new ActionUpdateField(original.getVariable());
isUpdate = true;
} else {
asf = new ActionSetField(original.getVariable());
}
asf.setFieldValues(original.getFieldValues());

action = asf;
binding = original.getVariable();
}

//Binding is used to group related field setters together. It is essential for
Expand All @@ -343,6 +360,7 @@ private void addAction(IAction action,
final LabelledAction a = new LabelledAction();
a.boundName = binding;
a.action = action;
a.isUpdate = isUpdate;
actions.add(a);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,75 @@ public void testUpdateModifyMultipleFieldsWithMultipleSkipped4() {
drl);
}

@Test
/**
* DROOLS-3795
*/
public void testMakeSureHeaderDefinitionIsNotEdited() {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();

Pattern52 p1 = new Pattern52();
p1.setBoundName("x");
p1.setFactType("Context");

ConditionCol52 c = new ConditionCol52();
c.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
p1.getChildColumns().add(c);
dt.getConditions().add(p1);

BRLActionColumn brlAction1 = new BRLActionColumn();
ActionUpdateField auf1 = new ActionUpdateField("x");
auf1.addFieldValue(new ActionFieldValue("f1",
"$f1",
DataType.TYPE_STRING));
auf1.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);

brlAction1.getDefinition().add(auf1);
brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f1",
DataType.TYPE_STRING,
"Context",
"f1"));
dt.getActionCols().add(brlAction1);
ActionSetFieldCol52 set = new ActionSetFieldCol52();
set.setBoundName("x");
set.setFactField("f2");

dt.getActionCols().add(set);

dt.setData(DataUtilities.makeDataLists(new String[][]{
new String[]{"1", "desc", "x", "v1", "v2"},
new String[]{"2", "desc", "x", "v1", null}
}));
String drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
final String expected = "//from row number: 1\n" +
"//desc\n" +
"rule \"Row 1 null\"\n" +
"dialect \"mvel\"\n" +
"when\n" +
" x : Context( )\n" +
"then\n" +
" modify( x ) {\n" +
" setF1( \"v1\" )\n" +
"}\n" +
"x.setF2( \"v2\" );\n" +
"end\n"+
"\n"+
"//from row number: 2\n" +
"//desc\n" +
"rule \"Row 2 null\"\n" +
"dialect \"mvel\"\n" +
"when\n" +
" x : Context( )\n" +
"then\n" +
" modify( x ) {\n" +
" setF1( \"v1\" )\n" +
"}\n" +
"end\n";

assertEqualsIgnoreWhitespace(expected,
drl);
}

@Test
public void testLHSNonEmptyStringValues() {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();
Expand Down

0 comments on commit 634fbe5

Please sign in to comment.