Skip to content

Commit 5c6326b

Browse files
committed
[dashboard] redundant dependency is dropped; code is simplyfied
Signed-off-by: Maxim Solodovnik <solomax@apache.org>
1 parent 494e6d9 commit 5c6326b

4 files changed

Lines changed: 15 additions & 53 deletions

File tree

dashboard-parent/dashboard-core/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616
<name>Wicketstuff Dashboard Core</name>
1717

1818
<dependencies>
19-
<!-- Gson (json for java) -->
20-
<dependency>
21-
<groupId>com.google.code.gson</groupId>
22-
<artifactId>gson</artifactId>
23-
</dependency>
24-
2519
<!-- Xstream -->
2620
<dependency>
2721
<groupId>com.thoughtworks.xstream</groupId>

dashboard-parent/dashboard-core/src/main/java/module-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
requires org.apache.wicket.request;
88
requires org.apache.wicket.util;
99
requires xstream;
10-
requires com.google.gson;
10+
requires com.github.openjson;
1111
requires de.agilecoders.wicket.webjars;
1212
}

dashboard-parent/dashboard-core/src/main/java/org/wicketstuff/dashboard/web/SortableAjaxBehavior.java

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
2121
import org.wicketstuff.dashboard.WidgetLocation;
2222

23-
import com.google.gson.Gson;
23+
import com.github.openjson.JSONArray;
24+
import com.github.openjson.JSONObject;
2425

2526
/**
2627
* @author Decebal Suiu
@@ -37,54 +38,21 @@ public abstract class SortableAjaxBehavior extends AbstractDefaultAjaxBehavior {
3738
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
3839
super.updateAjaxAttributes(attributes);
3940

40-
StringBuilder buffer = new StringBuilder();
41-
buffer.append("var data = serializeWidgetLocations();");
42-
buffer.append("return {'" + JSON_DATA + "': data};");
43-
44-
attributes.getDynamicExtraParameters().add(buffer);
41+
attributes.getDynamicExtraParameters()
42+
.add("var data = serializeWidgetLocations();" +
43+
"return {'" + JSON_DATA + "': data};");
4544
}
4645

4746
@Override
4847
protected void respond(AjaxRequestTarget target) {
49-
String jsonData = getComponent().getRequest().getRequestParameters().getParameterValue(JSON_DATA).toString();
50-
Item[] items = getItems(jsonData);
5148
Map<String, WidgetLocation> locations = new HashMap<String, WidgetLocation>();
52-
for (Item item : items) {
53-
WidgetLocation location = new WidgetLocation(item.column, item.sortIndex);
54-
locations.put(item.widget, location);
49+
String jsonData = getComponent().getRequest().getRequestParameters().getParameterValue(JSON_DATA).toString();
50+
JSONArray arr = new JSONArray(jsonData);
51+
for (int i = 0; i < arr.length(); ++i) {
52+
JSONObject obj = arr.getJSONObject(i);
53+
locations.put(obj.getString("widget"),
54+
new WidgetLocation(obj.getInt("column"), obj.getInt("sortIndex")));
5555
}
56-
5756
onSort(target, locations);
5857
}
59-
60-
private Item[] getItems(String jsonData) {
61-
Gson gson = new Gson();
62-
Item[] items = gson.fromJson(jsonData, Item[].class);
63-
/*
64-
System.out.println(items.length);
65-
for (Item item : items) {
66-
System.out.println(item);
67-
}
68-
*/
69-
70-
return items;
71-
}
72-
73-
static class Item {
74-
public int column;
75-
public String widget;
76-
public int sortIndex;
77-
78-
@Override
79-
public String toString() {
80-
StringBuffer buffer = new StringBuffer();
81-
buffer.append("Item[");
82-
buffer.append("column = ").append(column);
83-
buffer.append(" widget = ").append(widget);
84-
buffer.append(" sortIndex = ").append(sortIndex);
85-
buffer.append("]");
86-
87-
return buffer.toString();
88-
}
89-
}
9058
}

dashboard-parent/dashboard-core/src/test/java/org/wicketstuff/dashboard/AbstractWidgetTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.wicketstuff.dashboard.web.DashboardPanel;
2121
import org.wicketstuff.dashboard.web.WidgetView;
2222

23-
public class AbstractWidgetTest {
23+
class AbstractWidgetTest {
2424
private static final String MARKUP = "<html><body><div wicket:id=\"dashboard\"></div></body></html>";
2525
private WicketTester browser;
2626

@@ -96,12 +96,12 @@ public WidgetView createView(String viewId) {
9696
}
9797

9898
@BeforeEach
99-
public void setup() {
99+
void setup() {
100100
browser = new WicketTester(new WebApp());
101101
}
102102

103103
@Test
104-
public void canExposeConfigurationAsString() {
104+
void canExposeConfigurationAsString() {
105105
Dashboard dashboard = Application.get().getMetaData(DASHBOARD_KEY);
106106
browser.startComponentInPage(new DashboardPanel("dashboard", Model.<Dashboard> of(dashboard)), Markup.of(MARKUP));
107107
browser.assertNoErrorMessage();

0 commit comments

Comments
 (0)