Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DROOLS-4618] Test Scenario: refactor ExpressionEvaluator implementations #2690

Merged
merged 9 commits into from
Jan 3, 2020

Conversation

danielezonca
Copy link
Contributor

Changed ExpressionEvaluator input value to String (it should be possible to refactor factMappingValue.getRawValue() to String too but impact is big so will be done in the future)

@gitgabrio @yesamer @dupliaka

https://issues.redhat.com/browse/DROOLS-4618

@@ -67,6 +69,9 @@ protected boolean isStructuredInput(String className) {
}

protected Object convertResult(String rawString, String className, List<String> genericClasses) {
if(rawString == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space between if and (

if (!rawValue.endsWith("]")) {
throw new IllegalArgumentException(new StringBuilder().append("Malformed expression: ").append(rawValue).toString());
}
return Stream.of(rawValue.substring(1, ((String) raw).length() - 1).split(","))
return Stream.of(rawValue.substring(1, (rawValue).length() - 1).split(","))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove parentheses on rawValue variable

Copy link
Contributor

@yesamer yesamer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielezonca Excellent refactoring, I agree with you this should be considered as first step, the next one is to convert factMappingValue.getRawValue() from Object to String in a future ticket. We will have conflicts with my PR https://github.com/kiegroup/drools/pull/2691, but I think I can resolve them easily. So, I propose to review / test / merge this PR before mine.

Copy link
Contributor

@jomarko jomarko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See inline comments/questions.

}
Object expressionResult = compileAndExecute((String) rawExpression, Collections.emptyMap());
public Object evaluateLiteralExpression(String rawExpression, String className, List<String> genericClasses) {
Object expressionResult = compileAndExecute(rawExpression, Collections.emptyMap());
Class<Object> requiredClass = loadClass(className, classLoader);
if (expressionResult != null && !requiredClass.isAssignableFrom(expressionResult.getClass())) {
throw new IllegalArgumentException("Cannot assign a '" + expressionResult.getClass().getCanonicalName() +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing, we miss ending apostrophe in the exception message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch :)
Done

Object value = expressionEvaluator.evaluateLiteralExpression(factMapping.getClassName(),
factMapping.getGenericTypes(),
factMappingValue.getRawValue());
Object value = expressionEvaluator.evaluateLiteralExpression((String) factMappingValue.getRawValue(), factMapping.getClassName(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please keep arguments of evaluateLiteralExpression one per line?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we change also signature of evaluateLiteralExpression in future to eliminate this casting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We plan to remove the cast in the future changing factMappingValue.rawValue from Object to String

@@ -301,7 +301,7 @@ protected ResultWrapper getResultWrapper(String className,
Object resultRaw,
Class<?> resultClass) {
try {
boolean evaluationSucceed = expressionEvaluator.evaluateUnaryExpression(expectedResultRaw, resultRaw, resultClass);
boolean evaluationSucceed = expressionEvaluator.evaluateUnaryExpression((String) expectedResultRaw, resultRaw, resultClass);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we change also signature of evaluateUnaryExpression in future to eliminate this casting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, after the change of factMappingValue.rawValue from Object to String the cast will be no more needed

@danielezonca danielezonca merged commit 682d6ad into apache:master Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants