From e84e8df316d348c5985acb4e7c11f1f7895d5c1b Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Wed, 16 Jul 2014 14:51:31 +0000 Subject: [PATCH] Added Static Filter git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widgetx@98695 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../tdwx/client/TabularDataXGridPanel.java | 24 ++++++- .../model/util/ColumnConfigGenerator.java | 1 - .../client/util/PagingLoadUrlEncoder.java | 15 ++++ .../user/tdwx/server/TabularDataXServlet.java | 27 +++++++- .../tdwx/server/datasource/DataSourceX.java | 30 +++++--- .../user/tdwx/shared/RequestData.java | 55 ++++++++++++--- .../tdwx/shared/StaticFilterInformation.java | 68 +++++++++++++++++++ 7 files changed, 196 insertions(+), 24 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/tdwx/shared/StaticFilterInformation.java diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/TabularDataXGridPanel.java b/src/main/java/org/gcube/portlets/user/tdwx/client/TabularDataXGridPanel.java index 9198f97..d651c98 100644 --- a/src/main/java/org/gcube/portlets/user/tdwx/client/TabularDataXGridPanel.java +++ b/src/main/java/org/gcube/portlets/user/tdwx/client/TabularDataXGridPanel.java @@ -34,6 +34,7 @@ import org.gcube.portlets.user.tdwx.client.style.DefaultRowStyle; import org.gcube.portlets.user.tdwx.client.util.ColumnPositionComparator; import org.gcube.portlets.user.tdwx.client.util.PagingLoadUrlEncoder; import org.gcube.portlets.user.tdwx.shared.ServletParameters; +import org.gcube.portlets.user.tdwx.shared.StaticFilterInformation; import org.gcube.portlets.user.tdwx.shared.model.ColumnDefinition; import org.gcube.portlets.user.tdwx.shared.model.ColumnKey; import org.gcube.portlets.user.tdwx.shared.model.ColumnType; @@ -113,6 +114,8 @@ public class TabularDataXGridPanel extends ContentPanel { protected PagingLoader> loader; protected ExtendedGridFilters gridFilters; + + protected ArrayList staticFilters; protected TableViewConfig tableViewConfig; @@ -188,6 +191,24 @@ public class TabularDataXGridPanel extends ContentPanel { return tableDefinition; } + /** + * Get static filters + * + * @return + */ + public ArrayList getStaticFilters() { + return staticFilters; + } + + /** + * Set static filters + * + * @param staticFilters + */ + public void setStaticFilters(ArrayList staticFilters) { + this.staticFilters = staticFilters; + } + /** * Returns the selected row. * @@ -246,6 +267,7 @@ public class TabularDataXGridPanel extends ContentPanel { } + /** * * @@ -683,7 +705,7 @@ public class TabularDataXGridPanel extends ContentPanel { HttpProxy proxy = new HttpProxy( builder); - proxy.setWriter(new PagingLoadUrlEncoder()); + proxy.setWriter(new PagingLoadUrlEncoder(staticFilters)); loader = new PagingLoader>( proxy, reader) { diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/model/util/ColumnConfigGenerator.java b/src/main/java/org/gcube/portlets/user/tdwx/client/model/util/ColumnConfigGenerator.java index f41e088..1b2a637 100644 --- a/src/main/java/org/gcube/portlets/user/tdwx/client/model/util/ColumnConfigGenerator.java +++ b/src/main/java/org/gcube/portlets/user/tdwx/client/model/util/ColumnConfigGenerator.java @@ -11,7 +11,6 @@ import org.gcube.portlets.user.tdwx.shared.model.ColumnType; import org.gcube.portlets.user.tdwx.shared.model.DataRow; import com.google.gwt.cell.client.AbstractCell; -import com.google.gwt.cell.client.Cell.Context; import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.safecss.shared.SafeStyles; import com.google.gwt.safecss.shared.SafeStylesBuilder; diff --git a/src/main/java/org/gcube/portlets/user/tdwx/client/util/PagingLoadUrlEncoder.java b/src/main/java/org/gcube/portlets/user/tdwx/client/util/PagingLoadUrlEncoder.java index 2d784c4..f919fe8 100644 --- a/src/main/java/org/gcube/portlets/user/tdwx/client/util/PagingLoadUrlEncoder.java +++ b/src/main/java/org/gcube/portlets/user/tdwx/client/util/PagingLoadUrlEncoder.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import org.gcube.portlets.user.tdwx.shared.FilterInformation; import org.gcube.portlets.user.tdwx.shared.RequestData; import org.gcube.portlets.user.tdwx.shared.SortInformation; +import org.gcube.portlets.user.tdwx.shared.StaticFilterInformation; import com.allen_sauer.gwt.log.client.Log; import com.sencha.gxt.data.shared.SortInfo; @@ -28,6 +29,15 @@ public class PagingLoadUrlEncoder implements // protected UrlBuilder urlBuilder = new UrlBuilder(); protected RequestData requestData; + protected ArrayList staticFilters; + + /** + * + * @param staticFilters + */ + public PagingLoadUrlEncoder(ArrayList staticFilters){ + this.staticFilters=staticFilters; + } public String write(FilterPagingLoadConfig config) { @@ -58,6 +68,11 @@ public class PagingLoadUrlEncoder implements } requestData.setFilters(filters); + if(staticFilters!=null){ + requestData.setStaticFilters(staticFilters); + } + + Log.debug("JSON request:"+requestData.toJsonObject()); return requestData.toJsonObject(); diff --git a/src/main/java/org/gcube/portlets/user/tdwx/server/TabularDataXServlet.java b/src/main/java/org/gcube/portlets/user/tdwx/server/TabularDataXServlet.java index 5f63e69..f21c6dc 100644 --- a/src/main/java/org/gcube/portlets/user/tdwx/server/TabularDataXServlet.java +++ b/src/main/java/org/gcube/portlets/user/tdwx/server/TabularDataXServlet.java @@ -17,6 +17,7 @@ import org.gcube.portlets.user.tdwx.server.util.SessionUtil; import org.gcube.portlets.user.tdwx.shared.FilterInformation; import org.gcube.portlets.user.tdwx.shared.ServletParameters; import org.gcube.portlets.user.tdwx.shared.SortInformation; +import org.gcube.portlets.user.tdwx.shared.StaticFilterInformation; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -113,7 +114,7 @@ public class TabularDataXServlet extends HttpServlet { try { filters = jsonRequest.getJSONArray("filters"); } catch (JSONException e) { - logger.debug("sorts: " + e.getLocalizedMessage()); + logger.debug("filters: " + e.getLocalizedMessage()); } if (filters != null) { @@ -127,12 +128,34 @@ public class TabularDataXServlet extends HttpServlet { } } logger.debug("Filters:" + filtersList.size()); + + + //STATIC FILTERS + JSONArray staticFilters = null; + ArrayList staticFiltersList=new ArrayList(); + try { + staticFilters = jsonRequest.getJSONArray("staticFilters"); + } catch (JSONException e) { + logger.debug("staticFilters: " + e.getLocalizedMessage()); + } + + if (staticFilters != null) { + for (int i = 0; i < staticFilters.length(); i++) { + JSONObject staticFilter = staticFilters.getJSONObject(i); + StaticFilterInformation sfi= new StaticFilterInformation(staticFilter.getString("columnName"), + staticFilter.getString("columnLocalId"), + staticFilter.getString("filterValue")); + staticFiltersList.add(sfi); + } + } + logger.debug("StaticFilters:" + staticFiltersList.size()); + DataSourceX dataSource = SessionUtil.getDataSource( request.getSession(), tdSessionId); String json = dataSource.getDataAsJSon(start, limit, sortColumn, - direction, filtersList); + direction, filtersList, staticFiltersList); response.getOutputStream().write(json.getBytes()); diff --git a/src/main/java/org/gcube/portlets/user/tdwx/server/datasource/DataSourceX.java b/src/main/java/org/gcube/portlets/user/tdwx/server/datasource/DataSourceX.java index ebf1452..d1e9a09 100644 --- a/src/main/java/org/gcube/portlets/user/tdwx/server/datasource/DataSourceX.java +++ b/src/main/java/org/gcube/portlets/user/tdwx/server/datasource/DataSourceX.java @@ -3,40 +3,50 @@ package org.gcube.portlets.user.tdwx.server.datasource; import java.util.ArrayList; import org.gcube.portlets.user.tdwx.shared.FilterInformation; +import org.gcube.portlets.user.tdwx.shared.StaticFilterInformation; import org.gcube.portlets.user.tdwx.shared.model.TableDefinition; /** * - * @author "Giancarlo Panichi" - * g.panichi@isti.cnr.it - * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * */ public interface DataSourceX { - + /** * Returns the id of the {@link DataSourceXFactory} that have generated it. + * * @return the {@link DataSourceXFactory} id. */ public String getDataSourceFactoryId(); - + /** * Returns the table definition. + * * @return a table definition. - * @throws DataSourceXException if an error occurred retrieving the table definition. + * @throws DataSourceXException + * if an error occurred retrieving the table definition. */ public TableDefinition getTableDefinition() throws DataSourceXException; + /** * Retrieves the table data as JSON object. + * * @param start the starting row index. * @param limit the number of rows after the starting index to retrieve. * @param sortingColumn the column used for sorting. * @param direction the sorting direction. + * @param filters dynamic filters + * @param staticFilters static filters * @return the JSON object as String. - * @throws DataSourceXException if an error occurred retrieving the table data. + * @throws DataSourceXException + * if an error occurred retrieving the table data. */ - public String getDataAsJSon(int start, int limit, String sortingColumn, Direction direction, ArrayList filters) throws DataSourceXException; + public String getDataAsJSon(int start, int limit, String sortingColumn, + Direction direction, ArrayList filters, + ArrayList staticFilters) + throws DataSourceXException; - - } diff --git a/src/main/java/org/gcube/portlets/user/tdwx/shared/RequestData.java b/src/main/java/org/gcube/portlets/user/tdwx/shared/RequestData.java index 8b52c74..0a22c36 100644 --- a/src/main/java/org/gcube/portlets/user/tdwx/shared/RequestData.java +++ b/src/main/java/org/gcube/portlets/user/tdwx/shared/RequestData.java @@ -16,7 +16,8 @@ public class RequestData implements Serializable { private String limit; private ArrayList sorts; private ArrayList filters; - + private ArrayList staticFilters; + public RequestData() { } @@ -52,10 +53,20 @@ public class RequestData implements Serializable { this.filters = filters; } + + public ArrayList getStaticFilters() { + return staticFilters; + } + + public void setStaticFilters(ArrayList staticFilters) { + this.staticFilters = staticFilters; + } + @Override public String toString() { return "RequestData [offset=" + offset + ", limit=" + limit - + ", sorts=" + sorts + ", filters=" + filters + "]"; + + ", sorts=" + sorts + ", filters=" + filters + + ", staticFilters=" + staticFilters +"]"; } @@ -101,17 +112,41 @@ public class RequestData implements Serializable { json.append("]"); } + if(staticFilters!=null && !staticFilters.isEmpty()){ + json.append(","); + json.append(" \"staticFilters\": ["); + boolean first=true; + for(StaticFilterInformation staticFilter:staticFilters){ + if(first){ + first=false; + } else{ + json.append(","); + } + json.append("{ \"columnName\":\""+staticFilter.getColumnName()+"\" ," + + "\"columnLocalId\":\""+staticFilter.getColumnLocalId()+"\" ," + + "\"filterValue\": \""+staticFilter.getFilterValue()+"\" }"); + + } + json.append("]"); + } + json.append("}"); - /* "company": "ACME, Inc", - "partNumber": "7402-129", - "prices": [ - { "minQty": 1, "price": 12.49 }, - { "minQty": 10, "price": 9.99 }, - { "minQty": 50, "price": 7.99 } - ] - */ + + + /* + * { "limit": "200", + * "offset": "330", + * "filters": [ + * { "filterField":"kqljyp" ,"filterType":"date" ,"filterComparison":"on" ,"filterValue": "1399370400000" }, + * { "filterField":"kqasdp" ,"filterType":"date" ,"filterComparison":"on" ,"filterValue": "1399370400000" }, + * ], + * "staticFilter: [" + * { "columnName:"kdsafd" ,"columnLocalId":"dsafadfacaseasdsafafe","filterValue":"10" } + * ] + * } + */ diff --git a/src/main/java/org/gcube/portlets/user/tdwx/shared/StaticFilterInformation.java b/src/main/java/org/gcube/portlets/user/tdwx/shared/StaticFilterInformation.java new file mode 100644 index 0000000..a4e3129 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/tdwx/shared/StaticFilterInformation.java @@ -0,0 +1,68 @@ +package org.gcube.portlets.user.tdwx.shared; + +import java.io.Serializable; + +/** + * Filter Information + * + * @author "Giancarlo Panichi" + * + */ +public class StaticFilterInformation implements Serializable { + + private static final long serialVersionUID = 856712991956862922L; + + private String columnName; + private String columnLocalId; + private String filterValue; + + + public StaticFilterInformation() { + } + + /** + * + * @param columnLocalId + * @param filterValue + */ + public StaticFilterInformation(String columnName,String columnLocalId, String filterValue) { + this.columnName=columnName; + this.columnLocalId=columnLocalId; + this.filterValue=filterValue; + + } + + public String getColumnLocalId() { + return columnLocalId; + } + + public void setColumnLocalId(String columnLocalId) { + this.columnLocalId = columnLocalId; + } + + public String getFilterValue() { + return filterValue; + } + + public void setFilterValue(String filterValue) { + this.filterValue = filterValue; + } + + public String getColumnName() { + return columnName; + } + + public void setColumnName(String columnName) { + this.columnName = columnName; + } + + @Override + public String toString() { + return "StaticFilterInformation [columnName=" + columnName + + ", columnLocalId=" + columnLocalId + ", filterValue=" + + filterValue + "]"; + } + + + +}