From 58c3f5d8ffd09662866673a8aed77a88940ac53d Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Mon, 3 Mar 2014 14:19:35 +0000 Subject: [PATCH] Minor Updated git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@92557 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../gwtservice/server/TDGWTServiceImpl.java | 120 +++++++++++++++--- 1 file changed, 100 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java index e229eb7..6b78489 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java @@ -845,23 +845,29 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements HttpSession session) { String filter = SessionUtil.getCodelistsPagingLoadedFilter(session); ArrayList ltrCopy = new ArrayList(); + SessionUtil.setCodelistsPagingLoadedFilter(session, plc.getFilter()); if (filter == null) { logger.debug("No filter filter present in session"); logger.debug("New Filter: " + plc.getFilter()); if (plc.getFilter() == null || plc.getFilter().isEmpty()) { + + SessionUtil.setCodelistsPagingLoadedFilteredCopy(session, ltr); return ltr; } else { for (TabResource tr : ltr) { - if (tr.getName().contains(plc.getFilter())) { + if (tr.getName() != null && !tr.getName().isEmpty() + && tr.getName().contains(plc.getFilter())) { ltrCopy.add(tr); continue; } else { - if (tr.getAgency().contains(plc.getFilter())) { + if (tr.getAgency() != null && !tr.getAgency().isEmpty() + && tr.getAgency().contains(plc.getFilter())) { ltrCopy.add(tr); continue; } else { } + } } SessionUtil.setCodelistsPagingLoadedFilteredCopy(session, @@ -870,12 +876,12 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } else { - + logger.debug("Old Filter:" + filter); logger.debug("New Filter: " + plc.getFilter()); - + if (plc.getFilter() == null || plc.getFilter().isEmpty()) { - SessionUtil.setCodelistsPagingLoadedFilter(session,plc.getFilter()); + SessionUtil.setCodelistsPagingLoadedFilteredCopy(session, ltr); return ltr; } else { if (filter.compareTo(plc.getFilter()) == 0) { @@ -883,27 +889,29 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements .getCodelistsPagingLoadedFilteredCopy(session); return ltrFilteredCopy; } else { - SessionUtil.setCodelistsPagingLoadedFilter(session,plc.getFilter()); for (TabResource tr : ltr) { - if (tr.getName().contains(plc.getFilter())) { + if (tr.getName() != null && !tr.getName().isEmpty() + && tr.getName().contains(plc.getFilter())) { ltrCopy.add(tr); continue; } else { - if (tr.getAgency().contains(plc.getFilter())) { + if (tr.getAgency() != null + && !tr.getAgency().isEmpty() + && tr.getAgency().contains(plc.getFilter())) { ltrCopy.add(tr); continue; } else { } + } } - SessionUtil.setCodelistsPagingLoadedFilteredCopy(session, ltrCopy); return ltrCopy; } } - + } } @@ -920,14 +928,36 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements Collections.sort(ltrCopy, new Comparator() { @Override public int compare(TabResource tr1, TabResource tr2) { - return tr1.getName().compareTo(tr2.getName()); + int comp = 0; + if (tr1.getName() == null) { + comp = -1; + } else { + if (tr2.getName() == null) { + comp = 1; + } else { + comp = tr1.getName().compareTo( + tr2.getName()); + } + } + return comp; } }); } else { Collections.sort(ltrCopy, new Comparator() { @Override public int compare(TabResource tr1, TabResource tr2) { - return -tr1.getName().compareTo(tr2.getName()); + int comp = 0; + if (tr1.getName() == null) { + comp = -1; + } else { + if (tr2.getName() == null) { + comp = 1; + } else { + comp = tr1.getName().compareTo( + tr2.getName()); + } + } + return -comp; } }); } @@ -943,8 +973,20 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements @Override public int compare(TabResource tr1, TabResource tr2) { - return tr1.getAgency().compareTo( - tr2.getAgency()); + int comp = 0; + if (tr1.getAgency() == null) { + comp = -1; + } else { + if (tr2.getAgency() == null) { + comp = 1; + } else { + comp = tr1 + .getAgency() + .compareTo( + tr2.getAgency()); + } + } + return comp; } }); } else { @@ -953,8 +995,20 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements @Override public int compare(TabResource tr1, TabResource tr2) { - return -tr1.getAgency().compareTo( - tr2.getAgency()); + int comp = 0; + if (tr1.getAgency() == null) { + comp = -1; + } else { + if (tr2.getAgency() == null) { + comp = 1; + } else { + comp = tr1 + .getAgency() + .compareTo( + tr2.getAgency()); + } + } + return -comp; } }); } @@ -968,8 +1022,21 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements @Override public int compare(TabResource tr1, TabResource tr2) { - return tr1.getDate().compareTo( - tr2.getDate()); + int comp = 0; + if (tr1.getDate() == null) { + comp = -1; + } else { + if (tr2.getDate() == null) { + comp = 1; + } else { + comp = tr1 + .getDate() + .compareTo( + tr2.getDate()); + } + } + + return comp; } }); } else { @@ -978,8 +1045,21 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements @Override public int compare(TabResource tr1, TabResource tr2) { - return -tr1.getDate().compareTo( - tr2.getDate()); + int comp = 0; + if (tr1.getDate() == null) { + comp = -1; + } else { + if (tr2.getDate() == null) { + comp = 1; + } else { + comp = tr1 + .getDate() + .compareTo( + tr2.getDate()); + } + } + + return -comp; } }); }