Added codelist list rpc paging load

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@91135 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-02-07 15:59:14 +00:00
parent de13301bfc
commit 7f9499c5c1
6 changed files with 408 additions and 38 deletions

View File

@ -26,13 +26,14 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnT
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRMetadata;
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.table.metadata.TabMetadata;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Agencies;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@ -140,6 +141,25 @@ public interface TDGWTService extends RemoteService {
public ArrayList<TabResource> getTabularResources()
throws TDGWTServiceException;
/**
* Initialize Codelists Paging Loader
*
* @throws TDGWTServiceException
*/
public void setCodelistsPagingLoader() throws TDGWTServiceException;
/**
* Retrieves a portion of Codelists
*
* @param codelistPagingLoadConfig
* @return
* @throws TDGWTServiceException
*/
public CodelistPagingLoadResult getCodelistsPagingLoader(
CodelistPagingLoadConfig codelistPagingLoadConfig)
throws TDGWTServiceException;;
/**
* Set open session for return all tabular resource of a user
*
@ -347,7 +367,6 @@ public interface TDGWTService extends RemoteService {
public void startSDMXExport(SDMXExportSession exportSession)
throws TDGWTServiceException;
// Change Column Type
/**
@ -360,12 +379,13 @@ public interface TDGWTService extends RemoteService {
throws TDGWTServiceException;
/**
* Start change column type
* Start change column type
*
* @param changeColumnTypeSession
* @param changeColumnTypeSession
* @throws TDGWTServiceException
*/
public void startChangeColumnType(
ChangeColumnTypeSession changeColumnTypeSession) throws TDGWTServiceException;
ChangeColumnTypeSession changeColumnTypeSession)
throws TDGWTServiceException;
}

View File

@ -25,6 +25,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnT
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRMetadata;
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.table.metadata.TabMetadata;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Agencies;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist;
@ -72,6 +74,14 @@ public interface TDGWTServiceAsync {
void removeTabularResource(TRId trId, AsyncCallback<Void> callback);
//CodelistPagingLoaded
void setCodelistsPagingLoader(AsyncCallback<Void> callback);
void getCodelistsPagingLoader(
CodelistPagingLoadConfig codelistPagingLoadConfig,
AsyncCallback<CodelistPagingLoadResult> callback);
//Open
void startTDOpen(TDOpenSession tdOpenSession, AsyncCallback<Void> callback);

View File

@ -67,12 +67,15 @@ public class SessionUtil {
protected static final String CSV_EXPORT_TASK = "CSV_EXPORT_TASK";
protected static final String CSV_EXPORT_END = "CSV_EXPORT_END";
protected static final String CSV_EXPORT_MONITOR = "CSV_EXPORT_MONITOR";
protected static final String CHANGE_COLUMN_TYPE_SESSION="CHANGE_COLUMN_TYPE_SESSION";
protected static final String CHANGE_COLUMN_TYPE_MONITOR="CHANGE_COLUMN_TYPE_MONITOR";
protected static final String CHANGE_COLUMN_TYPE_TASK="CHANGE_COLUMN_TYPE_TASK";
protected static final String CHANGE_COLUMN_TYPE_SESSION = "CHANGE_COLUMN_TYPE_SESSION";
protected static final String CHANGE_COLUMN_TYPE_MONITOR = "CHANGE_COLUMN_TYPE_MONITOR";
protected static final String CHANGE_COLUMN_TYPE_TASK = "CHANGE_COLUMN_TYPE_TASK";
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_FILTER = "CODELISTS_PAGING_LOADED_FILTER";
protected static Logger logger = LoggerFactory.getLogger(SessionUtil.class);
protected static ASLSession getAslSession(HttpSession httpSession) {
@ -96,8 +99,8 @@ public class SessionUtil {
}
logger.info("SessionUtil: aslSession " + session.getUsername() + " "
+ session.getScope());
+ session.getScope());
return session;
}
@ -347,7 +350,6 @@ public class SessionUtil {
return client.getAllAgencies();
}
public static void setSDMXRegistrySource(HttpSession httpSession,
SDMXRegistrySource sdmxRegistrySource) {
@ -360,7 +362,8 @@ public class SessionUtil {
ScopeProvider.instance.set(aslSession.getScope().toString());
}
public static SDMXRegistrySource getSDMXRegistrySource(HttpSession httpSession) {
public static SDMXRegistrySource getSDMXRegistrySource(
HttpSession httpSession) {
SDMXRegistrySource sdmxRegistrySource = (SDMXRegistrySource) httpSession
.getAttribute(SDMX_REGISTRY_SOURCE);
if (sdmxRegistrySource == null) {
@ -368,8 +371,7 @@ public class SessionUtil {
}
return sdmxRegistrySource;
}
public static SDMXClient getSdmxClient(HttpSession httpSession) {
SDMXClient sdmxClient = (SDMXClient) httpSession
.getAttribute(SDMX_CLIENT_ATTRIBUTE);
@ -378,8 +380,7 @@ public class SessionUtil {
if (sdmxRegistrySource == null) {
logger.error("SDMXRegistrySource was not acquired");
} else {
String url = sdmxRegistrySource
.getUrl();
String url = sdmxRegistrySource.getUrl();
if (url == null || url.isEmpty()) {
if (sdmxClient == null) {
sdmxClient = new SDMXClient();
@ -452,7 +453,7 @@ public class SessionUtil {
httpSession.removeAttribute(CSV_EXPORT_TASK);
httpSession.setAttribute(CSV_EXPORT_TASK, task);
}
public static void setCSVExportEnd(HttpSession httpSession, Boolean end) {
Boolean fin = (Boolean) httpSession.getAttribute(CSV_EXPORT_END);
if (fin != null)
@ -462,14 +463,13 @@ public class SessionUtil {
public static Boolean getCSVExportEnd(HttpSession httpSession) {
Boolean end = (Boolean) httpSession.getAttribute(CSV_EXPORT_END);
logger.debug("getCSVExportEnd(): "+end);
logger.debug("getCSVExportEnd(): " + end);
if (end == null) {
logger.error("CSV_EXPORT_END was not acquired");
end=false;
end = false;
}
return end;
}
public static Task getSDMXExportTask(HttpSession httpSession) {
Task monitor = (Task) httpSession.getAttribute(SDMX_EXPORT_TASK);
@ -478,7 +478,7 @@ public class SessionUtil {
}
return monitor;
}
public static void setSDMXExportTask(HttpSession httpSession, Task task) {
Task monitor = (Task) httpSession.getAttribute(SDMX_EXPORT_TASK);
if (monitor != null)
@ -508,16 +508,17 @@ public class SessionUtil {
httpSession.setAttribute(TR_TASK_MANAGER, trTasksManager);
}
public static ChangeColumnTypeSession getChangeColumnTypeSession(HttpSession httpSession) {
public static ChangeColumnTypeSession getChangeColumnTypeSession(
HttpSession httpSession) {
ChangeColumnTypeSession changeColumnTypeSession = (ChangeColumnTypeSession) httpSession
.getAttribute(CHANGE_COLUMN_TYPE_SESSION);
if (changeColumnTypeSession != null) {
return changeColumnTypeSession;
} else {
changeColumnTypeSession = new ChangeColumnTypeSession();
httpSession.setAttribute(CHANGE_COLUMN_TYPE_SESSION, changeColumnTypeSession);
httpSession.setAttribute(CHANGE_COLUMN_TYPE_SESSION,
changeColumnTypeSession);
return changeColumnTypeSession;
}
}
@ -529,18 +530,21 @@ public class SessionUtil {
if (ct != null) {
httpSession.removeAttribute(CHANGE_COLUMN_TYPE_SESSION);
}
httpSession.setAttribute(CHANGE_COLUMN_TYPE_SESSION, changeColumnTypeSession);
httpSession.setAttribute(CHANGE_COLUMN_TYPE_SESSION,
changeColumnTypeSession);
}
public static ChangeColumnTypeMonitor getChangeColumnTypeMonitor(HttpSession httpSession) {
public static ChangeColumnTypeMonitor getChangeColumnTypeMonitor(
HttpSession httpSession) {
ChangeColumnTypeMonitor changeColumnTypeMonitor = (ChangeColumnTypeMonitor) httpSession
.getAttribute(CHANGE_COLUMN_TYPE_MONITOR);
if (changeColumnTypeMonitor != null) {
return changeColumnTypeMonitor;
} else {
changeColumnTypeMonitor = new ChangeColumnTypeMonitor();
httpSession.setAttribute(CHANGE_COLUMN_TYPE_MONITOR, changeColumnTypeMonitor);
httpSession.setAttribute(CHANGE_COLUMN_TYPE_MONITOR,
changeColumnTypeMonitor);
return changeColumnTypeMonitor;
}
}
@ -552,10 +556,11 @@ public class SessionUtil {
if (cm != null) {
httpSession.removeAttribute(CHANGE_COLUMN_TYPE_MONITOR);
}
httpSession.setAttribute(CHANGE_COLUMN_TYPE_MONITOR, changeColumnTypeMonitor);
httpSession.setAttribute(CHANGE_COLUMN_TYPE_MONITOR,
changeColumnTypeMonitor);
}
public static Task getChangeColumnTypeTask(HttpSession httpSession) {
Task monitor = (Task) httpSession.getAttribute(CHANGE_COLUMN_TYPE_TASK);
if (monitor == null) {
@ -563,14 +568,73 @@ public class SessionUtil {
}
return monitor;
}
public static void setChangeColumnTypeTask(HttpSession httpSession, Task task) {
public static void setChangeColumnTypeTask(HttpSession httpSession,
Task task) {
Task monitor = (Task) httpSession.getAttribute(CHANGE_COLUMN_TYPE_TASK);
if (monitor != null)
httpSession.removeAttribute(CHANGE_COLUMN_TYPE_TASK);
httpSession.setAttribute(CHANGE_COLUMN_TYPE_TASK, task);
}
public static ArrayList<TabResource> getCodelistsPagingLoaded(
HttpSession httpSession) {
@SuppressWarnings("unchecked")
ArrayList<TabResource> ltr = ((ArrayList<TabResource>) httpSession
.getAttribute(CODELISTS_PAGING_LOADED));
if (ltr == null) {
logger.error("CODELISTS_PAGING_LOADED was not acquired");
}
return ltr;
}
public static void setCodelistsPagingLoaded(HttpSession httpSession,
ArrayList<TabResource> listCodelists) {
@SuppressWarnings("unchecked")
ArrayList<TabResource> ltr = ((ArrayList<TabResource>) httpSession
.getAttribute(CODELISTS_PAGING_LOADED));
if (ltr != null)
httpSession.removeAttribute(CODELISTS_PAGING_LOADED);
httpSession.setAttribute(CODELISTS_PAGING_LOADED, listCodelists);
}
public static String getCodelistsPagingLoadedDirection(
HttpSession httpSession) {
String direction = (String) httpSession
.getAttribute(CODELISTS_PAGING_LOADED_DIRECTION);
if (direction == null) {
logger.error("CODELISTS_PAGING_LOADED_DIRECTION was not acquired");
}
return direction;
}
public static void setCodelistsPagingLoadedDirection(
HttpSession httpSession, String direction) {
String dir = ((String) httpSession
.getAttribute(CODELISTS_PAGING_LOADED_DIRECTION));
if (dir != null)
httpSession.removeAttribute(CODELISTS_PAGING_LOADED_DIRECTION);
httpSession.setAttribute(CODELISTS_PAGING_LOADED_DIRECTION, direction);
}
public static String getCodelistsPagingLoadedFilter(HttpSession httpSession) {
String filter = (String) httpSession
.getAttribute(CODELISTS_PAGING_LOADED_FILTER);
if (filter == null) {
logger.error("CODELISTS_PAGING_LOADED_FILTER was not acquired");
}
return filter;
}
public static void setCodelistsPagingLoadedFilter(HttpSession httpSession,
String filter) {
String fil = ((String) httpSession
.getAttribute(CODELISTS_PAGING_LOADED_FILTER));
if (fil != null)
httpSession.removeAttribute(CODELISTS_PAGING_LOADED_FILTER);
httpSession.setAttribute(CODELISTS_PAGING_LOADED_FILTER, filter);
}
}

View File

@ -43,6 +43,7 @@ import org.gcube.data.analysis.tabulardata.model.metadata.table.TableMetadata;
import org.gcube.data.analysis.tabulardata.model.metadata.table.VersionMetadata;
import org.gcube.data.analysis.tabulardata.model.table.Table;
import org.gcube.data.analysis.tabulardata.model.table.TableId;
import org.gcube.data.analysis.tabulardata.model.table.type.CodelistTableType;
import org.gcube.data.analysis.tabulardata.service.TabularDataService;
import org.gcube.data.analysis.tabulardata.service.exception.InvalidTabularResourceException;
import org.gcube.data.analysis.tabulardata.service.exception.NoSuchTabularResourceException;
@ -98,6 +99,8 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRMetadata;
import org.gcube.portlets.user.td.gwtservice.shared.tr.metadata.TRNameMetadata;
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.table.metadata.TabDescriptionsMetadata;
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.metadata.TabExportMetadata;
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.metadata.TabGenericMapMetadata;
@ -635,6 +638,137 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
return t;
}
/**
*
* {@inheritDoc}
*/
public void setCodelistsPagingLoader()
throws TDGWTServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session);
AuthorizationProvider.instance.set(new AuthorizationToken(
aslSession.getUsername()));
TabularDataService service = TabularDataServiceFactory.getService();
CodelistTableType codType=new CodelistTableType();
List<TabularResource> trs = service.getTabularResourcesByType(codType.getName());
SessionUtil.setTabularResources(session, trs);
ArrayList<TabResource> ltr = new ArrayList<TabResource>();
int i;
for (i = 0; i < trs.size(); i++) {
TabularResource tr = trs.get(i);
TabResource t = retriveTRMetadataFromService(service, tr, i);
if (t.getTrId() != null) {
ltr.add(t);
}
}
logger.debug("Codelists retrived: " + ltr);
SessionUtil.setCodelistsPagingLoaded(session, ltr);
} catch (Exception e) {
e.printStackTrace();
logger.error("Error retrieving Codelist in setCodelistsPagingLoader(): "
+ e.getLocalizedMessage());
throw new TDGWTServiceException(
"Error retrieving Codelist: "
+ e.getLocalizedMessage());
}
}
/**
*
* {@inheritDoc}
*/
public CodelistPagingLoadResult getCodelistsPagingLoader(CodelistPagingLoadConfig plc)
throws TDGWTServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ArrayList<TabResource> ltr = SessionUtil.getCodelistsPagingLoaded(session);
String direction=SessionUtil.getCodelistsPagingLoadedDirection(session);
String filter=SessionUtil.getCodelistsPagingLoadedFilter(session);
if(ltr==null){
logger.error("Error no codelist present in session");
throw new TDGWTServiceException(
"Error no codelist present in session");
}
if(direction==null){
logger.error("Error no codelist direction present in session");
throw new TDGWTServiceException(
"Error no codelist direction present in session");
}
if(filter==null){
logger.error("Error no codelist filter present in session");
throw new TDGWTServiceException(
"Error no codelist filter present in session");
}
if(plc.getOffset()<0 || plc.getOffset()>=ltr.size()){
logger.error("Error CodelistPagingLoadConfig no valid range request");
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();
}
ArrayList<TabResource> ltrTemp=new ArrayList<TabResource>();
if(filter.compareTo(plc.getFilter())!=0){
}
if(direction.compareTo(plc.getDirection())!=0){
}
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");
}
}
CodelistPagingLoadResult codelistPagingLoadResult=new CodelistPagingLoadResult();
codelistPagingLoadResult.setFilter(plc.getFilter());
codelistPagingLoadResult.setDirection(plc.getDirection());
codelistPagingLoadResult.setLimit(plc.getLimit());
codelistPagingLoadResult.setOffset(plc.getOffset());
codelistPagingLoadResult.setTotalLenght(ltr.size());
codelistPagingLoadResult.setLtr(ltrTemp);
logger.debug("Codelists retrieved: " + ltrTemp);
return codelistPagingLoadResult;
} catch (Exception e) {
e.printStackTrace();
logger.error("Error retrieving Codelist in getCodelistsPagingLoader(): "
+ e.getLocalizedMessage());
throw new TDGWTServiceException(
"Error retrieving Codelist: "
+ e.getLocalizedMessage());
}
}
/**
*
* {@inheritDoc}

View File

@ -0,0 +1,62 @@
package org.gcube.portlets.user.td.gwtservice.shared.tr.paging;
import java.io.Serializable;
import java.util.ArrayList;
import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class CodelistPagingLoadConfig implements Serializable {
private static final long serialVersionUID = -8831947012755493644L;
protected int offset;
protected int limit;
protected String direction;
protected String filter;
public int getOffset() {
return offset;
}
public void setOffset(int offset) {
this.offset = offset;
}
public int getLimit() {
return limit;
}
public void setLimit(int limit) {
this.limit = limit;
}
public String getDirection() {
return direction;
}
public void setDirection(String direction) {
this.direction = direction;
}
public String getFilter() {
return filter;
}
public void setFilter(String filter) {
this.filter = filter;
}
@Override
public String toString() {
return "CodelistPagingLoadConfig [offset=" + offset + ", limit="
+ limit + ", direction=" + direction + ", filter=" + filter
+ "]";
}
}

View File

@ -0,0 +1,80 @@
package org.gcube.portlets.user.td.gwtservice.shared.tr.paging;
import java.io.Serializable;
import java.util.ArrayList;
import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class CodelistPagingLoadResult implements Serializable {
private static final long serialVersionUID = -8831947012755493644L;
protected int offset;
protected int limit;
protected int totalLenght;
protected ArrayList<TabResource> ltr;
protected String direction;
protected String filter;
public int getOffset() {
return offset;
}
public void setOffset(int offset) {
this.offset = offset;
}
public int getLimit() {
return limit;
}
public void setLimit(int limit) {
this.limit = limit;
}
public int getTotalLenght() {
return totalLenght;
}
public void setTotalLenght(int totalLenght) {
this.totalLenght = totalLenght;
}
public ArrayList<TabResource> getLtr() {
return ltr;
}
public void setLtr(ArrayList<TabResource> ltr) {
this.ltr = ltr;
}
public String getDirection() {
return direction;
}
public void setDirection(String direction) {
this.direction = direction;
}
public String getFilter() {
return filter;
}
public void setFilter(String filter) {
this.filter = filter;
}
@Override
public String toString() {
return "CodelistPagingLoadResult [offset=" + offset + ", limit="
+ limit + ", totalLenght=" + totalLenght + ", ltr=" + ltr
+ ", direction=" + direction + ", filter=" + filter + "]";
}
}