Minor Update

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widgetx@95138 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-04-28 08:15:42 +00:00 committed by Giancarlo Panichi
parent f41062fa39
commit 22107f0e32
3 changed files with 145 additions and 156 deletions

View File

@ -55,6 +55,8 @@ import com.sencha.gxt.data.shared.event.StoreUpdateEvent;
import com.sencha.gxt.data.shared.loader.FilterPagingLoadConfig;
import com.sencha.gxt.data.shared.loader.FilterPagingLoadConfigBean;
import com.sencha.gxt.data.shared.loader.Loader;
import com.sencha.gxt.data.shared.loader.PagingLoadConfig;
import com.sencha.gxt.data.shared.loader.PagingLoadConfigBean;
import com.sencha.gxt.data.shared.loader.PagingLoadResult;
import com.sencha.gxt.data.shared.loader.PagingLoader;
import com.sencha.gxt.widget.core.client.ContentPanel;
@ -110,7 +112,7 @@ public class TabularDataXGridPanel extends ContentPanel {
protected DataRowPagingReader reader;
protected PagingLoader<FilterPagingLoadConfig, PagingLoadResult<DataRow>> loader;
protected PagingLoader<PagingLoadConfig, PagingLoadResult<DataRow>> loader;
protected TableViewConfig tableViewConfig;
@ -574,11 +576,11 @@ public class TabularDataXGridPanel extends ContentPanel {
reader = new DataRowPagingReader(tableDefinition);
String path = GWT.getModuleBaseURL() + "tdwxdata";
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
path);
builder.setHeader(ServletParameters.TD_SESSION_ID,
String.valueOf(tdSessionId));
HttpProxy<FilterPagingLoadConfig> proxy = new HttpProxy<FilterPagingLoadConfig>(
/*HttpProxy<FilterPagingLoadConfig> proxy = new HttpProxy<FilterPagingLoadConfig>(
builder);
proxy.setWriter(new PagingLoadUrlEncoder());
@ -588,7 +590,20 @@ public class TabularDataXGridPanel extends ContentPanel {
protected FilterPagingLoadConfig newLoadConfig() {
return new FilterPagingLoadConfigBean();
}
};*/
HttpProxy<PagingLoadConfig> proxy = new HttpProxy<PagingLoadConfig>(
builder);
proxy.setWriter(new PagingLoadUrlEncoder());
loader = new PagingLoader<PagingLoadConfig, PagingLoadResult<DataRow>>(
proxy, reader) {
@Override
protected PagingLoadConfig newLoadConfig() {
return new PagingLoadConfigBean();
}
};
loader.setRemoteSort(true);
/*
* loader.addLoadHandler(new
@ -620,7 +635,7 @@ public class TabularDataXGridPanel extends ContentPanel {
// numberer.initPlugin(grid);
// Filter
ArrayList<Filter<DataRow, ?>> filters = FiltersGenerator
/*ArrayList<Filter<DataRow, ?>> filters = FiltersGenerator
.generate(columnModel);
ExtendedGridFilters<DataRow> gridFilters = new ExtendedGridFilters<DataRow>(
loader);
@ -630,7 +645,7 @@ public class TabularDataXGridPanel extends ContentPanel {
Log.debug("Filters: " + filters.size());
for (Filter<DataRow, ?> filterGeneric : filters) {
gridFilters.addFilter(filterGeneric);
}
}*/
container.add(grid, new VerticalLayoutData(1, 1, new Margins(0)));

View File

@ -3,24 +3,13 @@
*/
package org.gcube.portlets.user.tdwx.client.util;
import java.beans.XMLEncoder;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
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.ServletParameters;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.SerializationException;
import com.google.gwt.user.client.rpc.SerializationStreamFactory;
import com.google.gwt.user.client.rpc.SerializationStreamWriter;
import com.sencha.gxt.data.shared.SortInfo;
import com.sencha.gxt.data.shared.loader.FilterConfig;
import com.sencha.gxt.data.shared.loader.FilterPagingLoadConfig;
import com.sencha.gxt.data.shared.loader.PagingLoadConfig;
import com.sencha.gxt.data.shared.writer.DataWriter;
/**
@ -30,91 +19,86 @@ import com.sencha.gxt.data.shared.writer.DataWriter;
*
*/
public class PagingLoadUrlEncoder implements
DataWriter<FilterPagingLoadConfig, String> {
DataWriter<PagingLoadConfig, String> {
//DataWriter<FilterPagingLoadConfig, String> {
protected UrlBuilder urlBuilder = new UrlBuilder();
protected RequestData requestData;
public String write(FilterPagingLoadConfig config) {
requestData = new RequestData();
public String write(PagingLoadConfig config) {
/*
* requestData = new RequestData();
*
* requestData.setOffset(String.valueOf(config.getOffset()));
* requestData.setLimit(String.valueOf(config.getLimit()));
*
* ArrayList<SortInformation> sorts = new ArrayList<SortInformation>();
*
* SortInformation si; for (SortInfo info : config.getSortInfo()) { si =
* new SortInformation(info.getSortField(), (info.getSortDir() == null)
* ? null : info.getSortDir() .toString()); sorts.add(si); }
* requestData.setSorts(sorts);
*
* ArrayList<FilterInformation> filters = new
* ArrayList<FilterInformation>(); FilterInformation fi;
*
* for (FilterConfig filterConfig : config.getFilters()) { fi = new
* FilterInformation(filterConfig.getField(), filterConfig.getType(),
* filterConfig.getComparison(), filterConfig.getValue());
* filters.add(fi); } requestData.setFilters(filters);
*
* SerializationStreamFactory streamFactory =
* (SerializationStreamFactory) GWT.create(RequestData.class);
* SerializationStreamWriter streamWriter =
* streamFactory.createStreamWriter(); try {
* streamWriter.writeObject(requestData); } catch
* (SerializationException e) { Log.error(e.getLocalizedMessage());
* e.printStackTrace(); return null; }
*
*
* return streamWriter.toString();
*/
requestData.setOffset(String.valueOf(config.getOffset()));
requestData.setLimit(String.valueOf(config.getLimit()));
Log.debug("Offset: " + config.getOffset());
Log.debug("Limit: " + config.getLimit());
ArrayList<SortInformation> sorts = new ArrayList<SortInformation>();
urlBuilder.clear();
SortInformation si;
for (SortInfo info : config.getSortInfo()) {
si = new SortInformation(info.getSortField(),
(info.getSortDir() == null) ? null : info.getSortDir()
.toString());
sorts.add(si);
urlBuilder.addParameter(ServletParameters.OFFSET,
String.valueOf(config.getOffset()));
urlBuilder.addParameter(ServletParameters.LIMIT,
String.valueOf(config.getLimit()));
if(config.getSortInfo()!=null && !config.getSortInfo().isEmpty()){
SortInfo info = config.getSortInfo().get(0);
Log.debug("SortField: " + info.getSortField());
Log.debug("SortDir: " + info.getSortDir());
urlBuilder.addParameter(ServletParameters.SORTFIELD,
info.getSortField());
urlBuilder.addParameter(ServletParameters.SORTDIR, (info
.getSortDir() == null) ? null : info.getSortDir()
.toString());
}
requestData.setSorts(sorts);
ArrayList<FilterInformation> filters = new ArrayList<FilterInformation>();
FilterInformation fi;
for (FilterConfig filterConfig : config.getFilters()) {
fi = new FilterInformation(filterConfig.getField(),
filterConfig.getType(), filterConfig.getComparison(),
filterConfig.getValue());
filters.add(fi);
}
requestData.setFilters(filters);
SerializationStreamFactory streamFactory = (SerializationStreamFactory) GWT.create(RequestData.class);
SerializationStreamWriter streamWriter = streamFactory.createStreamWriter();
try {
streamWriter.writeObject(requestData);
} catch (SerializationException e) {
Log.error(e.getLocalizedMessage());
e.printStackTrace();
return null;
}
return streamWriter.toString();
/*
* Log.debug("Offset: "+config.getOffset());
* Log.debug("Limit: "+config.getLimit());
*
*
* urlBuilder.clear();
*
* urlBuilder.addParameter(ServletParameters.OFFSET,
* String.valueOf(config.getOffset()));
* urlBuilder.addParameter(ServletParameters.LIMIT,
* String.valueOf(config.getLimit()));
*
* for (SortInfo info:config.getSortInfo()) {
*
* Log.debug("SortField: "+info.getSortField());
* Log.debug("SortDir: "+info.getSortDir());
* urlBuilder.addParameter(ServletParameters.SORTFIELD,
* info.getSortField());
* urlBuilder.addParameter(ServletParameters.SORTDIR,
* (info.getSortDir()==null)?null:info.getSortDir().toString()); }
*
* for (FilterConfig filterConfig:config.getFilters()) {
* Log.debug("FilterField: "+filterConfig.getField());
* Log.debug("FilterType: "+filterConfig.getType());
* Log.debug("FilterComparison: "+filterConfig.getComparison());
* Log.debug("FilterValue: "+filterConfig.getValue());
*
* urlBuilder.addParameter(ServletParameters.FILTERFIELD,
* filterConfig.getField());
* urlBuilder.addParameter(ServletParameters.FILTERTYPE,
* filterConfig.getType());
* urlBuilder.addParameter(ServletParameters.FILTERCOMPARISON,
* filterConfig.getComparison());
* urlBuilder.addParameter(ServletParameters.FILTERVALUE,
* filterConfig.getValue());
*
* }
*
* return urlBuilder.toString();
*/
for (FilterConfig filterConfig : config.getFilters()) {
Log.debug("FilterField: " + filterConfig.getField());
Log.debug("FilterType: " + filterConfig.getType());
Log.debug("FilterComparison: " + filterConfig.getComparison());
Log.debug("FilterValue: " + filterConfig.getValue());
urlBuilder.addParameter(ServletParameters.FILTERFIELD,
filterConfig.getField());
urlBuilder.addParameter(ServletParameters.FILTERTYPE,
filterConfig.getType());
urlBuilder.addParameter(ServletParameters.FILTERCOMPARISON,
filterConfig.getComparison());
urlBuilder.addParameter(ServletParameters.FILTERVALUE,
filterConfig.getValue());
}*/
return urlBuilder.toString();
}
}

View File

@ -1,30 +1,19 @@
package org.gcube.portlets.user.tdwx.server;
import java.beans.XMLDecoder;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
import org.gcube.portlets.user.tdwx.server.datasource.DataSourceX;
import org.gcube.portlets.user.tdwx.server.datasource.Direction;
import org.gcube.portlets.user.tdwx.server.util.SessionUtil;
import org.gcube.portlets.user.tdwx.shared.RequestData;
import org.gcube.portlets.user.tdwx.shared.ServletParameters;
import org.gcube.portlets.user.tdwx.shared.SortInformation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.SerializationStreamFactory;
import com.google.gwt.user.client.rpc.SerializationStreamReader;
/**
*
* @author "Giancarlo Panichi" <a
@ -54,69 +43,70 @@ public class TabularDataXServlet extends HttpServlet {
try {
ObjectInputStream in = new ObjectInputStream(request.getInputStream());
RequestData requestData=null;
try {
requestData = (RequestData) in.readObject();
logger.debug("RequestData: "+requestData);
} catch (ClassNotFoundException e) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
"ERROR-Error retreiving expression in request: "+e.getLocalizedMessage());
}
logger.debug(requestData.toString());
/*
* ObjectInputStream in = new
* ObjectInputStream(request.getInputStream()); RequestData
* requestData=null; try { requestData = (RequestData)
* in.readObject(); logger.debug("RequestData: "+requestData); }
* catch (ClassNotFoundException e) {
* response.sendError(HttpServletResponse.SC_BAD_REQUEST,
* "ERROR-Error retreiving expression in request: "
* +e.getLocalizedMessage()); }
*
* logger.debug(requestData.toString());
*/
// TD SESSION ID
String tdSessionIdParameter = request
.getHeader(ServletParameters.TD_SESSION_ID);
logger.trace("tdSessionIdParameter: " + tdSessionIdParameter);
int tdSessionId = Integer.parseInt(tdSessionIdParameter);
/*
* // SORTING DIRECTION String sortDirectionParameter = request
* .getParameter(ServletParameters.SORTDIR);
* log.trace("sortDirectionParameter: " + sortDirectionParameter);
* Direction direction = (sortDirectionParameter == null) ?
* Direction.ASC : Direction.valueOf(sortDirectionParameter);
*
* // SORTING COLUMN String sortColumn = request
* .getParameter(ServletParameters.SORTFIELD);
* log.trace("sortColumn: " + sortColumn);
*
* // START
* String startParameter = request
* .getParameter(ServletParameters.OFFSET);
* log.trace("startParameter: " + startParameter); int start =
* Integer.parseInt(startParameter);
*
* // LIMIT String limitParameter = request
* .getParameter(ServletParameters.LIMIT);
* log.trace("limitParameter: " + limitParameter); int limit =
* Integer.parseInt(limitParameter);
*
*
* DataSourceX dataSource = SessionUtil.getDataSource(
* request.getSession(), tdSessionId); String json =
* dataSource.getDataAsJSon(start, limit, sortColumn, direction);
*/
// SORTING DIRECTION
String sortDirectionParameter = request
.getParameter(ServletParameters.SORTDIR);
logger.trace("sortDirectionParameter: " + sortDirectionParameter);
Direction direction = (sortDirectionParameter == null) ? Direction.ASC
: Direction.valueOf(sortDirectionParameter);
// SORTING COLUMN
String sortColumn = request
.getParameter(ServletParameters.SORTFIELD);
logger.trace("sortColumn: " + sortColumn);
// START
String startParameter = request
.getParameter(ServletParameters.OFFSET);
logger.trace("startParameter: " + startParameter);
int start = Integer.parseInt(startParameter);
// LIMIT
String limitParameter = request
.getParameter(ServletParameters.LIMIT);
logger.trace("limitParameter: " + limitParameter);
int limit = Integer.parseInt(limitParameter);
DataSourceX dataSource = SessionUtil.getDataSource(
request.getSession(), tdSessionId);
int start=Integer.parseInt(requestData.getOffset());
int limit=Integer.parseInt(requestData.getLimit());
ArrayList<SortInformation> sorts=requestData.getSorts();
String json = dataSource.getDataAsJSon(start, limit, sortColumn,
direction);
Direction direction=Direction.ASC;
String sortColumn=null;
for(SortInformation sort:sorts){
direction = (sort.getSortDir() == null) ?
Direction.ASC : Direction.valueOf(sort.getSortDir());
sortColumn=sort.getSortField();
/*DataSourceX dataSource = SessionUtil.getDataSource(
request.getSession(), tdSessionId);
int start = Integer.parseInt(requestData.getOffset());
int limit = Integer.parseInt(requestData.getLimit());
ArrayList<SortInformation> sorts = requestData.getSorts();
Direction direction = Direction.ASC;
String sortColumn = null;
for (SortInformation sort : sorts) {
direction = (sort.getSortDir() == null) ? Direction.ASC
: Direction.valueOf(sort.getSortDir());
sortColumn = sort.getSortField();
}
String json = dataSource.getDataAsJSon(start, limit, sortColumn,
direction);
*/
response.getOutputStream().write(json.getBytes());
response.setStatus(HttpServletResponse.SC_OK);
// logger.trace("JSON: "+json);