Skip to content

Commit

Permalink
DROOLS-5766 : Issue while using LocalDateTime field reference in GRE (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Rikkola authored Nov 18, 2020
1 parent 751f17b commit db2becc
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ private ActionFieldFunction getActionFieldFunction(String param,
default:
paramValue = adjustParam(dataType,
param,
boundParams,
isJavaDialect);
}
ActionFieldFunction actionField = new ActionFieldFunction(methodName,
Expand Down Expand Up @@ -286,7 +285,6 @@ private String assertParamDataType(final String methodParamDataType,
new SimpleDateFormat(DateUtils.getDateFormatMask(),
Locale.ENGLISH).parse(adjustParam(methodParamDataType,
paramValue,
Collections.EMPTY_MAP,
isJavaDialect));
return methodParamDataType;
} catch (ParseException e) {
Expand All @@ -304,7 +302,6 @@ private String assertParamDataType(final String methodParamDataType,
try {
new BigDecimal(adjustParam(methodParamDataType,
paramValue,
Collections.EMPTY_MAP,
isJavaDialect));
return methodParamDataType;
} catch (NumberFormatException e) {
Expand All @@ -314,7 +311,6 @@ private String assertParamDataType(final String methodParamDataType,
try {
new BigInteger(adjustParam(methodParamDataType,
paramValue,
Collections.EMPTY_MAP,
isJavaDialect));
return methodParamDataType;
} catch (NumberFormatException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3462,7 +3462,6 @@ private ActionFieldValue buildFieldValue(final boolean isJavaDialect,
default:
paramValue = adjustParam(dataType,
value,
boundParams,
isJavaDialect);
}
ActionFieldValue fieldValue = new ActionFieldValue(field,
Expand Down Expand Up @@ -4108,7 +4107,6 @@ private String getParameterValue(final String paramDataType,

return RuleModelPersistenceHelper.adjustParam(paramDataType,
parameters.get(index).trim(),
boundParams,
isJavaDialect);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ static int inferFieldNature(final String dataType,
new SimpleDateFormat(DateUtils.getDateFormatMask(),
Locale.ENGLISH).parse(adjustParam(dataType,
value,
Collections.emptyMap(),
isJavaDialect));
return FieldNatureType.TYPE_LITERAL;
} catch (ParseException e) {
Expand All @@ -129,7 +128,6 @@ static int inferFieldNature(final String dataType,
try {
LocalDate.parse(adjustParam(dataType,
value,
Collections.emptyMap(),
isJavaDialect), DateTimeFormatter.ofPattern(DateUtils.getDateFormatMask()));
return FieldNatureType.TYPE_LITERAL;
} catch (DateTimeParseException e) {
Expand All @@ -150,7 +148,6 @@ static int inferFieldNature(final String dataType,
try {
new BigDecimal(adjustParam(dataType,
value,
Collections.EMPTY_MAP,
isJavaDialect));
return FieldNatureType.TYPE_LITERAL;
} catch (NumberFormatException e) {
Expand All @@ -160,7 +157,6 @@ static int inferFieldNature(final String dataType,
try {
new BigInteger(adjustParam(dataType,
value,
Collections.EMPTY_MAP,
isJavaDialect));
return FieldNatureType.TYPE_LITERAL;
} catch (NumberFormatException e) {
Expand Down Expand Up @@ -498,7 +494,6 @@ static String inferDataTypeFromActionValue(final String param,

static String adjustParam(final String dataType,
final String param,
final Map<String, String> boundParams,
final boolean isJavaDialect) {
if (DataType.TYPE_DATE.equals(dataType)) {
if (param.contains("sdf.parse(\"")) {
Expand Down Expand Up @@ -537,8 +532,6 @@ static String adjustParam(final String dataType,
return param.substring(0,
param.length() - 1);
}
} else if (boundParams.containsKey(param)) {
return "=" + param;
}
return param;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8623,6 +8623,52 @@ public void testExpressionWhenMethodNameIsExsistingOperator() {
assertEquals("contains(\"test\")", expressionParts.get(2).getName());
}

@Test
public void testDoNotAddEqualsToExpressionValues() {
String drl = "rule \"TestRule\"\n" +
"dialect \"mvel\"\n" +
"when\n" +
"t1 : Transaction( $transactiontime1 : transactiontime)\n" +
"Transaction( newtransactiontime.isBefore($transactiontime1))\n" +
"then\n" +
"end\n";

addModelField("Transaction",
"this",
"Transaction1",
DataType.TYPE_THIS);
addModelField("Transaction",
"newtransactiontime",
"Transaction",
DataType.TYPE_OBJECT);
addMethodInformation("Transaction",
"isBefore",
new ArrayList<String>() {{
add("Comparable");
}},
"boolean",
null,
DataType.TYPE_BOOLEAN);

final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl,
Collections.emptyList(),
dmo);

assertNotNull(m);

assertTrue(m.lhs[1] instanceof FactPattern);
FactPattern pattern = (FactPattern) m.lhs[1];
assertEquals("Transaction",
pattern.getFactType());
assertTrue(pattern.getConstraint(0) instanceof SingleFieldConstraintEBLeftSide);
SingleFieldConstraintEBLeftSide fieldConstraint = (SingleFieldConstraintEBLeftSide) pattern.getConstraint(0);
assertTrue(fieldConstraint.getExpressionLeftSide().getParts().get(2) instanceof ExpressionMethod);
ExpressionMethod expressionMethod = (ExpressionMethod) fieldConstraint.getExpressionLeftSide().getParts().get(2);
ExpressionFormLine expressionFormLine = expressionMethod.getParams().values().iterator().next();
assertEquals("$transactiontime1",
expressionFormLine.getParts().get(0).getName());
}

@Test
public void testStringReplaceExpression() throws Exception {
//https://bugzilla.redhat.com/show_bug.cgi?id=1264321
Expand Down

0 comments on commit db2becc

Please sign in to comment.