Updated getColdelistPagingLoader

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@92546 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-03-03 11:21:41 +00:00
parent 1b11d3301d
commit b1360e458e
2 changed files with 211 additions and 78 deletions

View File

@ -30,7 +30,6 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.column.LabelColumnSession
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.open.TDOpenSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.OrderInfo;
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.ChangeTableTypeMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.ChangeTableTypeSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Agencies;
@ -93,9 +92,8 @@ public class SessionUtil {
protected static final String CODELISTS_PAGING_LOADED = "CODELISTS_PAGING_LOADED";
protected static final String CODELISTS_PAGING_LOADED_DIRECTION = "CODELISTS_PAGING_LOADED_DIRECTION";
protected static final String CODELISTS_PAGING_LOADED_FILTERED_COPY="CODELISTS_PAGING_LOADED_FILTERED_COPY";
protected static final String CODELISTS_PAGING_LOADED_FILTER = "CODELISTS_PAGING_LOADED_FILTER";
protected static Logger logger = LoggerFactory.getLogger(SessionUtil.class);
@ -836,27 +834,28 @@ public class SessionUtil {
httpSession.setAttribute(CODELISTS_PAGING_LOADED, listCodelists);
}
public static ArrayList<OrderInfo> getCodelistsPagingLoadedDirection(
public static ArrayList<TabResource> getCodelistsPagingLoadedFilteredCopy(
HttpSession httpSession) {
@SuppressWarnings("unchecked")
ArrayList<OrderInfo> direction = (ArrayList<OrderInfo> ) httpSession
.getAttribute(CODELISTS_PAGING_LOADED_DIRECTION);
if (direction == null) {
logger.error("CODELISTS_PAGING_LOADED_DIRECTION was not acquired");
ArrayList<TabResource> ltrFilteredCopy = ((ArrayList<TabResource>) httpSession
.getAttribute(CODELISTS_PAGING_LOADED_FILTERED_COPY));
if (ltrFilteredCopy == null) {
logger.error("CODELISTS_PAGING_LOADED_FILTERED_COPY was not acquired");
}
return direction;
return ltrFilteredCopy;
}
public static void setCodelistsPagingLoadedDirection(
HttpSession httpSession, ArrayList<OrderInfo> direction) {
public static void setCodelistsPagingLoadedFilteredCopy(HttpSession httpSession,
ArrayList<TabResource> listCodelistsFilteredCopy) {
@SuppressWarnings("unchecked")
ArrayList<OrderInfo> dir = ((ArrayList<OrderInfo>) httpSession
.getAttribute(CODELISTS_PAGING_LOADED_DIRECTION));
if (dir != null)
httpSession.removeAttribute(CODELISTS_PAGING_LOADED_DIRECTION);
httpSession.setAttribute(CODELISTS_PAGING_LOADED_DIRECTION, direction);
}
ArrayList<TabResource> ltrFilteredCopy = ((ArrayList<TabResource>) httpSession
.getAttribute(CODELISTS_PAGING_LOADED_FILTERED_COPY));
if (ltrFilteredCopy != null)
httpSession.removeAttribute(CODELISTS_PAGING_LOADED_FILTERED_COPY);
httpSession.setAttribute(CODELISTS_PAGING_LOADED_FILTERED_COPY, listCodelistsFilteredCopy);
}
public static String getCodelistsPagingLoadedFilter(HttpSession httpSession) {
String filter = (String) httpSession

View File

@ -12,6 +12,8 @@ import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -116,6 +118,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRRightsMetadata
import org.gcube.portlets.user.td.gwtservice.shared.tr.open.TDOpenSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.CodelistPagingLoadConfig;
import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.CodelistPagingLoadResult;
import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.Direction;
import org.gcube.portlets.user.td.gwtservice.shared.tr.paging.OrderInfo;
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.ChangeTableTypeMonitor;
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.ChangeTableTypeSession;
@ -773,9 +776,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
ArrayList<TabResource> ltr = SessionUtil
.getCodelistsPagingLoaded(session);
ArrayList<OrderInfo> listOrderInfo = SessionUtil
.getCodelistsPagingLoadedDirection(session);
String filter = SessionUtil.getCodelistsPagingLoadedFilter(session);
if (ltr == null) {
logger.error("Error no codelist present in session");
@ -786,44 +786,35 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
ArrayList<TabResource> ltrTemp = new ArrayList<TabResource>();
if (ltr.size() != 0) {
if (filter == null) {
logger.debug("No filter filter present in session");
} else {
logger.debug("Old Filter:" + filter);
logger.debug("New Filter: " + plc.getFilter());
}
ArrayList<TabResource> ltrCopy = filterPagingRow(plc, ltr,
session);
ltrCopy = OrderPagingRow(plc, ltrCopy, session);
if (ltrCopy.size() != 0) {
if (plc.getOffset() < 0
|| plc.getOffset() >= ltrCopy.size()) {
logger.error("Error CodelistPagingLoadConfig no valid range request, listsize: "
+ ltrCopy.size());
throw new TDGWTServiceException(
"Error CodelistPagingLoadConfig no valid range request");
}
if (listOrderInfo == null) {
logger.debug("No listOrderInfo present in session");
} else {
int request_end = plc.getOffset() + plc.getLimit();
if (request_end > ltrCopy.size()) {
request_end = ltrCopy.size();
}
logger.debug("Old listOrderInfo:" + listOrderInfo);
}
for (int i = plc.getOffset(); i < request_end; i++) {
try {
// ltrCopy.get(i);
ltrTemp.add(ltrCopy.get(i));
if (plc.getOffset() < 0 || plc.getOffset() >= ltr.size()) {
logger.error("Error CodelistPagingLoadConfig no valid range request, listsize: "
+ ltr.size());
throw new TDGWTServiceException(
"Error CodelistPagingLoadConfig no valid range request");
}
int request_end = plc.getOffset() + plc.getLimit();
if (request_end > ltr.size()) {
request_end = ltr.size();
}
for (int i = plc.getOffset(); i < request_end; i++) {
try {
ltr.get(i);
ltrTemp.add(ltr.get(i));
} catch (IndexOutOfBoundsException e) {
logger.debug("OutOfBounds in getCodelistsPagingLoader() size:"
+ ltr.size()
+ " index: "
+ i
+ " Error:"
+ e.getMessage() + "\n");
} catch (IndexOutOfBoundsException e) {
logger.debug("OutOfBounds in getCodelistsPagingLoader() size:"
+ ltrCopy.size()
+ " index: "
+ i
+ " Error:" + e.getMessage() + "\n");
}
}
}
@ -834,7 +825,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
codelistPagingLoadResult.setListOrderInfo(plc.getListOrderInfo());
codelistPagingLoadResult.setLimit(plc.getLimit());
codelistPagingLoadResult.setOffset(plc.getOffset());
codelistPagingLoadResult.setTotalLenght(ltr.size());
codelistPagingLoadResult.setTotalLenght(ltrTemp.size());
codelistPagingLoadResult.setLtr(ltrTemp);
logger.debug("Codelists retrieved: " + ltrTemp);
@ -849,6 +840,157 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
protected ArrayList<TabResource> filterPagingRow(
CodelistPagingLoadConfig plc, ArrayList<TabResource> ltr,
HttpSession session) {
String filter = SessionUtil.getCodelistsPagingLoadedFilter(session);
ArrayList<TabResource> ltrCopy = new ArrayList<TabResource>();
if (filter == null) {
logger.debug("No filter filter present in session");
logger.debug("New Filter: " + plc.getFilter());
if (plc.getFilter() == null || plc.getFilter().isEmpty()) {
return ltr;
} else {
for (TabResource tr : ltr) {
if (tr.getName().contains(plc.getFilter())) {
ltrCopy.add(tr);
continue;
} else {
if (tr.getAgency().contains(plc.getFilter())) {
ltrCopy.add(tr);
continue;
} else {
}
}
}
SessionUtil.setCodelistsPagingLoadedFilteredCopy(session,
ltrCopy);
return ltrCopy;
}
} else {
logger.debug("Old Filter:" + filter);
logger.debug("New Filter: " + plc.getFilter());
if (plc.getFilter() == null || plc.getFilter().isEmpty()) {
return ltr;
} else {
if (filter.compareTo(plc.getFilter()) == 0) {
ArrayList<TabResource> ltrFilteredCopy = SessionUtil
.getCodelistsPagingLoadedFilteredCopy(session);
return ltrFilteredCopy;
} else {
for (TabResource tr : ltr) {
if (tr.getName().contains(plc.getFilter())) {
ltrCopy.add(tr);
continue;
} else {
if (tr.getAgency().contains(plc.getFilter())) {
ltrCopy.add(tr);
continue;
} else {
}
}
}
SessionUtil.setCodelistsPagingLoadedFilteredCopy(session,
ltrCopy);
return ltrCopy;
}
}
}
}
protected ArrayList<TabResource> OrderPagingRow(
CodelistPagingLoadConfig plc, ArrayList<TabResource> ltrCopy,
HttpSession session) {
ArrayList<OrderInfo> orders = plc.getListOrderInfo();
for (OrderInfo order : orders) {
if (order.getField().compareTo("name") == 0) {
Direction direction = order.getDirection();
if (direction == Direction.ASC) {
Collections.sort(ltrCopy, new Comparator<TabResource>() {
@Override
public int compare(TabResource tr1, TabResource tr2) {
return tr1.getName().compareTo(tr2.getName());
}
});
} else {
Collections.sort(ltrCopy, new Comparator<TabResource>() {
@Override
public int compare(TabResource tr1, TabResource tr2) {
return -tr1.getName().compareTo(tr2.getName());
}
});
}
logger.debug("LTR Ordered by name;");
} else {
if (order.getField().compareTo("agency") == 0) {
Direction direction = order.getDirection();
if (direction == Direction.ASC) {
Collections.sort(ltrCopy,
new Comparator<TabResource>() {
@Override
public int compare(TabResource tr1,
TabResource tr2) {
return tr1.getAgency().compareTo(
tr2.getAgency());
}
});
} else {
Collections.sort(ltrCopy,
new Comparator<TabResource>() {
@Override
public int compare(TabResource tr1,
TabResource tr2) {
return -tr1.getAgency().compareTo(
tr2.getAgency());
}
});
}
logger.debug("LTR Ordered by agency;");
} else {
if (order.getField().compareTo("date") == 0) {
Direction direction = order.getDirection();
if (direction == Direction.ASC) {
Collections.sort(ltrCopy,
new Comparator<TabResource>() {
@Override
public int compare(TabResource tr1,
TabResource tr2) {
return tr1.getDate().compareTo(
tr2.getDate());
}
});
} else {
Collections.sort(ltrCopy,
new Comparator<TabResource>() {
@Override
public int compare(TabResource tr1,
TabResource tr2) {
return -tr1.getDate().compareTo(
tr2.getDate());
}
});
}
logger.debug("LTR Ordered by date;");
} else {
}
}
}
}
return ltrCopy;
}
/**
*
* {@inheritDoc}
@ -1162,7 +1304,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
sdmxImportTabResource);
SessionUtil.setTRId(session, trId);
break;
case ABORTED:
break;
@ -1565,7 +1707,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
SessionUtil.setTabResource(session,
csvImportTabResource);
SessionUtil.setTRId(session, trId);
break;
case IN_PROGRESS:
importMonitor.setProgress(task.getProgress());
@ -2448,9 +2590,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
.getCodelistColumnReference();
logger.debug("ReferenceColumn To Set: " + col);
ColumnLocalId cId = new ColumnLocalId(col.getColumnId());
TRId trId=col.getTrId();
logger.debug("trID: "+trId);
long tabId=new Long(trId.getTableId());
TRId trId = col.getTrId();
logger.debug("trID: " + trId);
long tabId = new Long(trId.getTableId());
TableId tId = new TableId(tabId);
ColumnReference columnReference = new ColumnReference(tId, cId);
map.put(Constants.PARAMETER_REFERENCE_COLUMN, columnReference);
@ -2640,8 +2782,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
.valueOf(table.getId().getValue()));
trId.setTableType(table.getTableType().getName());
changeColumnTypeMonitor.setTrId(trId);
tabResource = SessionUtil
.getTabResource(session);
tabResource = SessionUtil.getTabResource(session);
tabResource.setTrId(trId);
SessionUtil.setTabResource(session, tabResource);
SessionUtil.setTRId(session, trId);
@ -2664,8 +2805,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
.valueOf(table.getId().getValue()));
trId.setTableType(table.getTableType().getName());
changeColumnTypeMonitor.setTrId(trId);
tabResource = SessionUtil
.getTabResource(session);
tabResource = SessionUtil.getTabResource(session);
tabResource.setTrId(trId);
SessionUtil.setTabResource(session, tabResource);
SessionUtil.setTRId(session, trId);
@ -2786,8 +2926,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
.valueOf(table.getId().getValue()));
trId.setTableType(table.getTableType().getName());
deleteColumnMonitor.setTrId(trId);
tabResource = SessionUtil
.getTabResource(session);
tabResource = SessionUtil.getTabResource(session);
tabResource.setTrId(trId);
SessionUtil.setTabResource(session, tabResource);
SessionUtil.setTRId(session, trId);
@ -2812,8 +2951,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
.valueOf(table.getId().getValue()));
trId.setTableType(table.getTableType().getName());
deleteColumnMonitor.setTrId(trId);
tabResource = SessionUtil
.getTabResource(session);
tabResource = SessionUtil.getTabResource(session);
tabResource.setTrId(trId);
SessionUtil.setTabResource(session, tabResource);
SessionUtil.setTRId(session, trId);
@ -2934,8 +3072,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
.valueOf(table.getId().getValue()));
trId.setTableType(table.getTableType().getName());
labelColumnMonitor.setTrId(trId);
tabResource = SessionUtil
.getTabResource(session);
tabResource = SessionUtil.getTabResource(session);
tabResource.setTrId(trId);
SessionUtil.setTabResource(session, tabResource);
SessionUtil.setTRId(session, trId);
@ -2960,8 +3097,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
.valueOf(table.getId().getValue()));
trId.setTableType(table.getTableType().getName());
labelColumnMonitor.setTrId(trId);
tabResource = SessionUtil
.getTabResource(session);
tabResource = SessionUtil.getTabResource(session);
tabResource.setTrId(trId);
SessionUtil.setTabResource(session, tabResource);
SessionUtil.setTRId(session, trId);
@ -3084,8 +3220,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
.valueOf(table.getId().getValue()));
trId.setTableType(table.getTableType().getName());
changeTableTypeMonitor.setTrId(trId);
tabResource = SessionUtil
.getTabResource(session);
tabResource = SessionUtil.getTabResource(session);
tabResource.setTrId(trId);
SessionUtil.setTabResource(session, tabResource);
SessionUtil.setTRId(session, trId);
@ -3109,8 +3244,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
.valueOf(table.getId().getValue()));
trId.setTableType(table.getTableType().getName());
changeTableTypeMonitor.setTrId(trId);
tabResource = SessionUtil
.getTabResource(session);
tabResource = SessionUtil.getTabResource(session);
tabResource.setTrId(trId);
SessionUtil.setTabResource(session, tabResource);
SessionUtil.setTRId(session, trId);