-
Notifications
You must be signed in to change notification settings - Fork 243
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
Changes from all commits
9370ac8
5fd47ce
b00e8ab
6cfdd61
91c29c6
719c8fd
6e54bb3
fdd463e
a1b5d74
f0c7f97
d3b52ef
8d6d272
b1ac00b
e913b29
6a772f3
e5aa263
d320af1
779c918
2d53c89
4e77f86
10f94db
f8aaa17
cd92809
27e7488
74ec742
657068f
8c5ca83
a44f53f
2815e12
1a7181a
3c398a5
95a8b61
c344854
a5e5544
c02191e
718fb0c
4b8be0d
8b3272b
4cc8731
2e70499
e0ea4da
2545df8
ca69a3e
cb6f8ad
d695ed6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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); | ||
|
@@ -101,10 +98,22 @@ public void setValue(String jsonString) { | |
return; | ||
} | ||
JSONValue jsonValue = getJSONValue(jsonString); | ||
if (jsonValue instanceof JSONString) { | ||
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); | ||
} | ||
} | ||
|
||
|
@@ -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()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yesamer There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -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) { | ||
|
@@ -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(); | ||
|
@@ -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(); | ||
|
@@ -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; | ||
|
@@ -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) -> { | ||
|
There was a problem hiding this comment.
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
if
s will lead to multiplication of tests - maybe cleaner to add another method to manage them?There was a problem hiding this comment.
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.