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
This commit is contained in:
Giancarlo Panichi 2014-07-16 14:51:31 +00:00 committed by Giancarlo Panichi
parent 80e069d1d6
commit e84e8df316
7 changed files with 196 additions and 24 deletions

View File

@ -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<FilterPagingLoadConfig, PagingLoadResult<DataRow>> loader;
protected ExtendedGridFilters<DataRow> gridFilters;
protected ArrayList<StaticFilterInformation> staticFilters;
protected TableViewConfig tableViewConfig;
@ -188,6 +191,24 @@ public class TabularDataXGridPanel extends ContentPanel {
return tableDefinition;
}
/**
* Get static filters
*
* @return
*/
public ArrayList<StaticFilterInformation> getStaticFilters() {
return staticFilters;
}
/**
* Set static filters
*
* @param staticFilters
*/
public void setStaticFilters(ArrayList<StaticFilterInformation> 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<FilterPagingLoadConfig> proxy = new HttpProxy<FilterPagingLoadConfig>(
builder);
proxy.setWriter(new PagingLoadUrlEncoder());
proxy.setWriter(new PagingLoadUrlEncoder(staticFilters));
loader = new PagingLoader<FilterPagingLoadConfig, PagingLoadResult<DataRow>>(
proxy, reader) {

View File

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

View File

@ -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<StaticFilterInformation> staticFilters;
/**
*
* @param staticFilters
*/
public PagingLoadUrlEncoder(ArrayList<StaticFilterInformation> 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();

View File

@ -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<StaticFilterInformation> staticFiltersList=new ArrayList<StaticFilterInformation>();
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());

View File

@ -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"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
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<FilterInformation> filters) throws DataSourceXException;
public String getDataAsJSon(int start, int limit, String sortingColumn,
Direction direction, ArrayList<FilterInformation> filters,
ArrayList<StaticFilterInformation> staticFilters)
throws DataSourceXException;
}

View File

@ -16,7 +16,8 @@ public class RequestData implements Serializable {
private String limit;
private ArrayList<SortInformation> sorts;
private ArrayList<FilterInformation> filters;
private ArrayList<StaticFilterInformation> staticFilters;
public RequestData() {
}
@ -52,10 +53,20 @@ public class RequestData implements Serializable {
this.filters = filters;
}
public ArrayList<StaticFilterInformation> getStaticFilters() {
return staticFilters;
}
public void setStaticFilters(ArrayList<StaticFilterInformation> 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" }
* ]
* }
*/

View File

@ -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 + "]";
}
}