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-4698] Managing user defined expressions for Collections #1276

Merged
merged 45 commits into from
Jan 27, 2020

Conversation

yesamer
Copy link
Member

@yesamer yesamer commented Dec 18, 2019

This PR introduce a way to define a user defined expression for collections

@dupliaka @jomarko @danielezonca can you please review and test it?

Examples to test it (Maps) for Given columns (for RULE Scenario)

["Book1" : new com.Book("Bob"), "Book2" : new com.Book("Michael")]

OR

a = "Bob"; map = new java.util.HashMap(); map.put("Bob", new com.Book(a)); map.put("Michael", new com.Book("Michael")); map;

For Expected columns:
java.util.Objects.equals(actualValue.get("Book1").getName(), "Bob");

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

Related PR:https://github.com/kiegroup/drools/pull/2691

@yesamer yesamer marked this pull request as ready for review December 20, 2019 15:46
*/
void initMapStructure(String key, Map<String, String> keyPropertyMap, Map<String, String> valuePropertyMap);
void initMapStructure(String key, Map<String, String> keyPropertyMap, Map<String, String> valuePropertyMap, boolean isRule);
Copy link
Contributor

Choose a reason for hiding this comment

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

@yesamer
Please replace use of boolean with the ENUM

Copy link
Member Author

Choose a reason for hiding this comment

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

@gitgabrio Done

@@ -101,10 +98,14 @@ public void setValue(String jsonString) {
return;
}
JSONValue jsonValue = getJSONValue(jsonString);
if (collectionView.isListWidget()) {
populateList(jsonValue);
if (jsonValue instanceof JSONString) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@yesamer
I think those nested ifs will lead to multiplication of tests - maybe cleaner to add another method to manage them?

Copy link
Member Author

Choose a reason for hiding this comment

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

@gitgabrio I wrapped the logic in a new method, it should be cleaner now.

@@ -160,10 +161,14 @@ public void addMapItem(Map<String, String> keyPropertiesValues, Map<String, Stri
public void save() {
try {
String updatedValue;
if (collectionView.isListWidget()) {
updatedValue = getListValue();
if (collectionView.isExpressionWidget()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@yesamer
Same comment as above. It seems there are two paths to manage: the "expressionwidget"(=JSONString) and the others - maybe cleaner to add specific methods

Copy link
Member Author

Choose a reason for hiding this comment

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

@gitgabrio as above.

@DataField("createCollectionRadio")
protected InputElement createCollectionRadio = Document.get().createRadioInputElement("collectionRadio");

@DataField("defineCollectionRadio")
Copy link
Contributor

Choose a reason for hiding this comment

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

@yesamer
What is the difference between those two radio buttons?

Copy link
Member Author

Choose a reason for hiding this comment

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

@gitgabrio The first one is to enables the Create Collection guided editor, which is the "old" way to populate the Collection. The second one enables the Define Collection editor, which consists on a TextArea where you can write an expression.

/**
* Flag to indicate if this <code>CollectionEditorViewImpl</code> is opened in DMN or RULE scenario
*/
protected boolean ruleScenario;
Copy link
Contributor

Choose a reason for hiding this comment

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

@yesamer
Pls replace boolean with ENUM

Copy link
Member Author

Choose a reason for hiding this comment

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

@gitgabrio Done

presenter.initMapStructure(key, keyPropertyMap, valuePropertyMap, this);
}

protected void commonInit(boolean isRule) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@yesamer
As above- pls replace boolean with ENUM

Copy link
Member Author

Choose a reason for hiding this comment

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

@gitgabrio Done

@@ -174,6 +251,11 @@ public void setValue(String jsonString) {
presenter.setValue(jsonString);
}

@Override
public boolean isExpressionWidget() {
Copy link
Contributor

Choose a reason for hiding this comment

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

@yesamer
Since three possible paths (list/map/expression) I think it would be cleaner to define (another :) ) enum and use it

Copy link
Member Author

Choose a reason for hiding this comment

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

@gitgabrio In this case I'm not agree, the expression property is no related to the Collection type.
Here, I need to know if the user enable the "expression" collection editor, disregarding the Collection type.

Copy link
Member Author

Choose a reason for hiding this comment

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

@gitgabrio I create https://issues.redhat.com/browse/DROOLS-4941 to manage this refactor during next sprint

@@ -318,4 +431,34 @@ protected boolean isShown() {
protected void toggleRowExpansion(boolean toExpand) {
CollectionEditorUtils.toggleRowExpansion(faAngleRight, toExpand);
}

protected void checkExpressionSyntax() {
if (ruleScenario) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@yesamer
Pls replace boolean with enum

Copy link
Member Author

Choose a reason for hiding this comment

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

@gitgabrio Done

JSONValue jsonValue = JSONParser.parseStrict(jsonString);
if (jsonValue instanceof JSONString) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@yesamer
I think it would be clearer to and an "else" statement, or to create two different methods. Wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

@gitgabrio I added the else statement

JSONValue jsonValue = JSONParser.parseStrict(jsonString);
if (jsonValue instanceof JSONString) {
String label = isList ? "List() " : "Map() ";
return label + ConstantHolder.EXPRESSION;
Copy link
Member

Choose a reason for hiding this comment

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

I think it is better to return something like List defined with expression (localized too). Wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

@danielezonca Agree to localize it. I think that List defined with expression it's too long, in a case where we have a lot of column isn't readable in my opinion
Screenshot from 2020-01-16 11-16-56
I would like to change it, be it should be a short string, in my opinion. Suggestions?

Copy link
Member Author

Choose a reason for hiding this comment

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

@danielezonca As agreed I simply put List() or Map().

@@ -1105,7 +1091,7 @@ public BaseSingletonDOMElementFactory getDOMElementFactory(String className,
ScenarioSimulationModel.Type modelType,
FactMappingValueType valueType) {
boolean isRuleScenario = Objects.equals(ScenarioSimulationModel.Type.RULE, modelType);
if (ScenarioSimulationSharedUtils.isCollection(className) && Objects.equals(FactMappingValueType.NOT_EXPRESSION, valueType)) {
if (ScenarioSimulationSharedUtils.isCollection(className)) {
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure it is not possible to reach this code with valueType == FactMappingValueType.EXPRESSION?
If it is possible you should add back the additional condition because mapped the whole object (i.e. a top level list of string in DMN) to that column we should show the normal edit mode

Copy link
Member Author

Choose a reason for hiding this comment

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

@danielezonca This change was required in a previous PR state, where I used FactMappingValueType.EXPRESSION for the Collection expression case too. As you suggested, now I don't use anymore that value for this case, so this change is no longer needed. Removed it.

* @param expressionValue
* @return
*/
public static String checkExpressionSyntax(String expressionValue) {
Copy link
Member

Choose a reason for hiding this comment

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

I think method name checkExpressionSyntax is misleading, what about normalizeExpression or ensureExpressionSyntax?
I usually expect a method that is named check to just perform a validation and return a boolean

Copy link
Member Author

Choose a reason for hiding this comment

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

@danielezonca Agree, I changed it to ensureExpressionSyntax. Thx

@yesamer
Copy link
Member Author

yesamer commented Jan 16, 2020

jenkins retest this please

Copy link

@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.

Please document that format needed for unary test in expect columns (?=[]), Ideally in the cheatsheet in the panel shown below

Screenshot from 2020-01-17 14-13-41

Also please be aware of the issues I have reported

Last thing, Anna self-requested review of this PR, please do not merge without her review or discuss with her.

@yesamer yesamer removed the request for review from dupliaka January 17, 2020 14:35
@yesamer
Copy link
Member Author

yesamer commented Jan 17, 2020

Please document that format needed for unary test in expect columns (?=[]), Ideally in the cheatsheet in the panel shown below

Screenshot from 2020-01-17 14-13-41

Also please be aware of the issues I have reported

* https://issues.redhat.com/browse/DROOLS-4949

* https://issues.redhat.com/browse/DROOLS-4950

Last thing, Anna self-requested review of this PR, please do not merge without her review or discuss with her.

@jomarko Thank you for your review. I analyzed the tickets you created: the first one is solved (I opened a new PR) and the second one is not a bug, in my opinion (I wrote a comment in the ticket).
Regarding your suggestion:

Please document that format needed for unary test in expect columns (?=[]), Ideally in the cheatsheet in the panel shown below

Excellent idea, I added:

In EXPECT section the type could also just a boolean with the result of the assertion and you can use ? identifier to access value to check.

I prefer to refer to ? in a generic way, because it can be used not only with collections.
Screenshot from 2020-01-17 16-38-04
WDYT?

@yesamer
Copy link
Member Author

yesamer commented Jan 20, 2020

@jomarko I agreed with @danielezonca to move the change on cheatsheet doc in #1277 PR. Thanks

@yesamer yesamer requested a review from jomarko January 21, 2020 08:29
Copy link

@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.

No comments to code. Also done with manual review. Spotted issues linked in DROOLS-4698. Discussing on private how to proceed.

Copy link

@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.

Approving to make progress on this, however there is list of jiras to be solved to get feature working completely https://issues.redhat.com/browse/DROOLS-4698

Thank you @yesamer

@yesamer
Copy link
Member Author

yesamer commented Jan 27, 2020

jenkins retest this please

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@danielezonca danielezonca merged commit 082b5ea into kiegroup:master Jan 27, 2020
@yesamer yesamer deleted the DROOLS-4698 branch January 28, 2020 16:57
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.

4 participants