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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
9370ac8
DROOLS-4804: Disabling TestTools when switching grids
yesamer Nov 28, 2019
5fd47ce
DROOLS-4698: Manage expressions in Collection editor
yesamer Nov 29, 2019
b00e8ab
DROOLS-4698: Manage expressions in Collection editor
yesamer Nov 29, 2019
6cfdd61
DROOLS-4698: Manage expressions in Collection editor
yesamer Nov 29, 2019
91c29c6
Merge remote-tracking branch 'origin/master' into DROOLS-4827
yesamer Dec 4, 2019
719c8fd
Merge remote-tracking branch 'origin/master' into DROOLS-4698
yesamer Dec 4, 2019
6e54bb3
Merge remote-tracking branch 'origin/master' into DROOLS-4698
yesamer Dec 5, 2019
fdd463e
DROOLS-4698: Manage expressions in Collection editor
yesamer Dec 5, 2019
a1b5d74
DROOLS-4698: Manage expressions in Collection editor
yesamer Dec 6, 2019
f0c7f97
Merge remote-tracking branch 'origin/master' into DROOLS-4698
yesamer Dec 6, 2019
d3b52ef
DROOLS-4698: Manage expressions in Collection editor
yesamer Dec 9, 2019
8d6d272
Merge remote-tracking branch 'origin/master' into DROOLS-4698
yesamer Dec 9, 2019
b1ac00b
Merge remote-tracking branch 'origin/master' into DROOLS-4698
yesamer Dec 10, 2019
e913b29
DROOLS-4698: Manage expressions in Collection editor
yesamer Dec 10, 2019
6a772f3
DROOLS-4698: Manage expressions in Collection editor
yesamer Dec 10, 2019
e5aa263
DROOLS-4698: Manage expressions in Collection editor
yesamer Dec 11, 2019
d320af1
Merge remote-tracking branch 'origin/master' into DROOLS-4698
yesamer Dec 12, 2019
779c918
DROOLS-4698: Manage expressions in Collection editor
yesamer Dec 16, 2019
2d53c89
DROOLS-4698: Manage expressions in Collection editor
yesamer Dec 18, 2019
4e77f86
DROOLS-4698: Manage expressions in Collection editor
yesamer Dec 18, 2019
10f94db
DROOLS-4698: Manage expressions in Collection editor - Tests
yesamer Dec 20, 2019
f8aaa17
DROOLS-4698: Manage expressions in Collection editor - Tests
yesamer Dec 20, 2019
cd92809
DROOLS-4698: Manage expressions in Collection editor - Tests
yesamer Dec 20, 2019
27e7488
DROOLS-4698: Manage expressions in Collection editor - Tests
yesamer Dec 20, 2019
74ec742
DROOLS-4698: Manage expressions in Collection editor - Tests
yesamer Dec 20, 2019
657068f
DROOLS-4698: Manage expressions in Collection editor - Tests
yesamer Dec 20, 2019
8c5ca83
DROOLS-4698: Manage expressions in Collection editor - Tests
yesamer Jan 2, 2020
a44f53f
DROOLS-4698: Manage expressions in Collection editor - Tests
yesamer Jan 2, 2020
2815e12
Merge remote-tracking branch 'origin/master' into DROOLS-4698
yesamer Jan 7, 2020
1a7181a
DROOLS-4698: Changes required during code review
yesamer Jan 9, 2020
3c398a5
Merge remote-tracking branch 'origin/master' into DROOLS-4698
yesamer Jan 9, 2020
95a8b61
Merge remote-tracking branch 'origin/master' into DROOLS-4698
yesamer Jan 13, 2020
c344854
Merge remote-tracking branch 'origin/master' into DROOLS-4698
yesamer Jan 14, 2020
a5e5544
DROOLS-3879: KogitoRuntimeDmnAssetsDropdownProviderImpl
yesamer Jan 15, 2020
c02191e
Merge remote-tracking branch 'origin/master' into DROOLS-4698
yesamer Jan 15, 2020
718fb0c
DROOLS-3879: KogitoRuntimeDmnAssetsDropdownProviderImpl
yesamer Jan 15, 2020
4b8be0d
DROOLS-3879: Clean up
yesamer Jan 15, 2020
8b3272b
DROOLS-4698: Changes required during CR
yesamer Jan 16, 2020
4cc8731
DROOLS-4698: Changes required during CR
yesamer Jan 16, 2020
2e70499
DROOLS-4698: Solving SONAR reported vulnerabilities and bugs
yesamer Jan 16, 2020
e0ea4da
DROOLS-4698: Documented how to refer to actualValue paramenter in FEE…
yesamer Jan 17, 2020
2545df8
DROOLS-4698: Previous commit reverted
yesamer Jan 20, 2020
ca69a3e
Merge remote-tracking branch 'origin/master' into DROOLS-4698
yesamer Jan 20, 2020
cb6f8ad
Merge remote-tracking branch 'origin/master' into DROOLS-4698
yesamer Jan 21, 2020
d695ed6
Merge remote-tracking branch 'origin/master' into DROOLS-4698
yesamer Jan 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import javax.inject.Inject;

import com.google.gwt.dom.client.LIElement;
import com.google.gwt.dom.client.Style;
import com.google.gwt.dom.client.UListElement;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
Expand Down Expand Up @@ -73,8 +72,6 @@ public class CollectionPresenter implements CollectionView.Presenter {

protected CollectionView collectionView;

protected LIElement objectSeparatorLI;

@Override
public void initListStructure(String key, Map<String, String> simplePropertiesMap, Map<String, Map<String, String>> expandablePropertiesMap, CollectionView collectionView) {
commonInit(key, collectionView);
Expand All @@ -101,10 +98,22 @@ public void setValue(String jsonString) {
return;
}
JSONValue jsonValue = getJSONValue(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 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.

populateExpression(jsonValue);
} else {
populateCreateCollection(jsonValue);
}
}

/**
* It populates the guided "Create Collection" editor
* @param value
*/
protected void populateCreateCollection(JSONValue value) {
if (collectionView.isListWidget()) {
populateList(jsonValue);
populateList(value);
} else {
populateMap(jsonValue);
populateMap(value);
}
}

Expand Down Expand Up @@ -160,17 +169,28 @@ 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.

updatedValue = getExpressionValue();
} else {
updatedValue = getMapValue();
updatedValue = getValueFromCreateCollection();
}
collectionView.updateValue(updatedValue);
} catch (IllegalStateException e) {
confirmPopupPresenter.show(ScenarioSimulationEditorConstants.INSTANCE.collectionError(), e.getMessage());
}
}

/**
* It gets the guided "Create Collection" editor
*/
protected String getValueFromCreateCollection() {
if (collectionView.isListWidget()) {
return getListValue();
} else {
return getMapValue();
}
}

@Override
public void remove() {
org.uberfire.mvp.Command okRemoveCommand = this::okRemoveCommandMethod;
Expand Down Expand Up @@ -206,12 +226,9 @@ protected void okRemoveCommandMethod() {

protected void commonInit(String key, CollectionView collectionView) {
this.collectionView = collectionView;
String propertyName = key.substring(key.lastIndexOf("#") + 1);
String propertyName = key.substring(key.lastIndexOf('#') + 1);
this.collectionView.getEditorTitle().setInnerText(key);
this.collectionView.getPropertyTitle().setInnerText(propertyName);
objectSeparatorLI = collectionView.getObjectSeparator();
objectSeparatorLI.addClassName("kie-object-list");
objectSeparatorLI.getStyle().setPadding(5, Style.Unit.PX);
}

protected void populateList(JSONValue jsonValue) {
Expand Down Expand Up @@ -246,6 +263,11 @@ protected void populateMap(JSONValue jsonValue) {
});
}

protected void populateExpression(JSONValue jsonValue) {
final JSONString jsonString = jsonValue.isString();
collectionView.setExpression(jsonString.stringValue());
}

protected JSONObject getJSONObject(String jsonString) {
try {
return getJSONValue(jsonString).isObject();
Expand All @@ -262,6 +284,11 @@ protected JSONValue getJSONValue(String jsonString) {
}
}

protected String getExpressionValue() {
final JSONString jsonString = new JSONString(collectionView.getExpression());
return jsonString.toString();
}

protected String getListValue() {
Map<String, Map<String, String>> simpleItemsProperties = listElementPresenter.getSimpleItemsProperties();
Map<String, Map<String, Map<String, String>>> nestedItemsProperties = listElementPresenter.getExpandableItemsProperties();
Expand Down Expand Up @@ -317,8 +344,7 @@ protected Map<String, Map<String, String>> getExpandablePropertiesValues(JSONObj
jsonObject.keySet().forEach(propertyName -> {
final JSONValue jsonValue = jsonObject.get(propertyName);
if (jsonValue.isObject() != null) {
final Map<String, String> simplePropertiesMap = getSimplePropertiesMap(jsonValue.isObject());
toReturn.put(propertyName, simplePropertiesMap);
toReturn.put(propertyName, getSimplePropertiesMap(jsonValue.isObject()));
}
});
return toReturn;
Expand All @@ -327,7 +353,7 @@ protected Map<String, Map<String, String>> getExpandablePropertiesValues(JSONObj
/**
* @return
*/
protected String getMapValue() throws IllegalStateException {
protected String getMapValue() {
Map<Map<String, String>, Map<String, String>> itemsProperties = mapElementPresenter.getItemsProperties();
JSONObject toReturnModel = new JSONObject();
itemsProperties.forEach((keyPropertiesValues, valuePropertiesMap) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

import com.google.gwt.dom.client.ButtonElement;
import com.google.gwt.dom.client.HeadingElement;
import com.google.gwt.dom.client.LIElement;
import com.google.gwt.dom.client.SpanElement;
import com.google.gwt.dom.client.Style;
import com.google.gwt.dom.client.UListElement;
import org.drools.scenariosimulation.api.model.ScenarioSimulationModel;

/**
* Interface defining the contract for actual implementations
Expand Down Expand Up @@ -130,10 +130,9 @@ interface Presenter {
String getValue();

/**
* @param listWidget set to <code>true</code> if the current instance will manage a <code>List</code>,
* <code>false</code> for a <code>Map</code>.
* Returns <code>true</code> if the current instance is managing an user defined expression.
*/
void setListWidget(boolean listWidget);
boolean isExpressionWidget();

/**
* Returns <code>true</code> if the current instance will manage a <code>List</code>,
Expand All @@ -144,8 +143,6 @@ interface Presenter {

UListElement getElementsContainer();

LIElement getObjectSeparator();

HeadingElement getEditorTitle();

SpanElement getPropertyTitle();
Expand All @@ -158,6 +155,10 @@ interface Presenter {

ButtonElement getSaveButton();

String getExpression();

void setExpression(String expressionValue);

void toggleRowExpansion();

/**
Expand All @@ -183,19 +184,21 @@ interface Presenter {
* Set the <b>name</b> of the property and the <code>Map</code> to be used to create the skeleton of the current <code>CollectionViewImpl</code> editor
* showing a <b>List</b> of elements
* @param key The key representing the property, i.e Classname#propertyname (e.g Author#books)
* @param instancePropertyMap
* @param simplePropertiesMap
* @param expandablePropertiesMap
* @param type
*/
void initListStructure(String key, Map<String, String> instancePropertyMap, Map<String, Map<String, String>> expandablePropertiesMap);
void initListStructure(String key, Map<String, String> simplePropertiesMap, Map<String, Map<String, String>> expandablePropertiesMap, ScenarioSimulationModel.Type type);

/**
* Set the <b>name</b> of the property and the <code>Map</code>s to be used to create the skeleton of the current <code>CollectionViewImpl</code> editor
* showing a <b>Map</b> of elements
* @param key The key representing the property, i.e Classname#propertyname (e.g Author#books)
* @param keyPropertyMap
* @param valuePropertyMap
* @param type
*/
void initMapStructure(String key, Map<String, String> keyPropertyMap, Map<String, String> valuePropertyMap);
void initMapStructure(String key, Map<String, String> keyPropertyMap, Map<String, String> valuePropertyMap, ScenarioSimulationModel.Type type);

void setFixedHeight(double value, Style.Unit px);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,58 @@ <h4 class="modal-title" data-field="editorTitle"><span class="fa fa-list"></span
</div>
<div class="modal-body" style="overflow-y: auto" data-field="collectionEditorModalBody">
<div class="container-fluid">
<div class="row">
<div class="form-group col-xs-12">
<label data-field="collectionCreationModeLabel"></label>
<div class="radio">
<label>
<input type="radio" data-field="createCollectionRadio" name="collectionRadio" id="kie-radio-option-1" value="option1" style="margin-top: 0px;" checked="">
<span data-field="collectionCreationCreateLabel" style="font-weight: bold;"></span>
<span data-field="collectionCreationCreateSpan"></span>
</label>
</div>
<div class="radio">
<label>
<input type="radio" data-field="defineCollectionRadio" name="collectionRadio" id="kie-radio-option-2" value="option2" style="margin-top: 0px;">
<span data-field="collectionCreationDefineLabel" style="font-weight: bold;"></span>
<span data-field="collectionCreationDefineSpan"></span>
</label>
</div>
</div>
</div>
<div class="row">
<!-- Data objects -->
<div class="col-xs-12 tab-content">
<label data-field="createLabel"></label>
<!-- Data objects -->
<div class="tab-content">
<!-- first right side panel -->
<div class="tab-pane active" id="kie-ObjectListItem1" aria-labelledby="#kie-ObjectListTab1">
<ul class="list-group list-group kie-object-lis" data-field="elementsContainer">
<li class="list-group-item" style="list-style-type: none;">
<span class="fa fa-angle-down kie-object-list__expander" data-field="faAngleRight"></span>
<span class="kie-object-list__field-value" data-field="propertyTitle">visitedcities</span>
</li>
</ul>
<div class="tab-pane active" data-field="createCollectionContainer" id="kie-ObjectListItem1" aria-labelledby="#kie-ObjectListTab1">
<ul class="list-group list-group kie-object-lis" data-field="elementsContainer">
<li class="list-group-item" style="list-style-type: none;">
<span class="fa fa-angle-down kie-object-list__expander" data-field="faAngleRight"></span>
<span class="kie-object-list__field-value" data-field="propertyTitle"></span>
</li>
</ul>
</div>
<div data-field="defineCollectionContainer">
<textarea class="collection-editor-expression_textarea" data-field="expressionElement"></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="kie-object-list__separator" data-field="objectSeparator">
<div class="modal-body" data-field="addItemButtonContainer">
<button class="btn btn-link" data-field="addItemButton">
<span class="fa fa-plus"></span> Add new item
<span class="fa fa-plus"></span>
<span data-field="addItemButtonLabel"></span>
</button>
</div>
<div class="modal-footer">

<button type="button" class="btn btn-default" data-dismiss="modal" data-field="cancelButton">Cancel</button>
<button type="button" class="btn btn-danger" data-dismiss="modal" data-field="removeButton">Remove</button>
<button type="button" class="btn btn-primary" data-dismiss="modal" data-field="saveButton">Save</button>
<button type="button" class="btn btn-default" data-dismiss="modal" data-field="cancelButton"></button>
<button type="button" class="btn btn-danger" data-dismiss="modal" data-field="removeButton"></button>
<button type="button" class="btn btn-primary" data-dismiss="modal" data-field="saveButton"></button>
</div>
</div>
</div>
Expand Down
Loading