diff --git a/.classpath b/.classpath
index 7de8e04..43577c0 100644
--- a/.classpath
+++ b/.classpath
@@ -1,7 +1,7 @@
-
+
@@ -32,5 +32,5 @@
-
+
diff --git a/.settings/com.google.gdt.eclipse.core.prefs b/.settings/com.google.gdt.eclipse.core.prefs
index 9eec524..d0bed6a 100644
--- a/.settings/com.google.gdt.eclipse.core.prefs
+++ b/.settings/com.google.gdt.eclipse.core.prefs
@@ -1,5 +1,5 @@
eclipse.preferences.version=1
jarsExcludedFromWebInfLib=
-lastWarOutDir=/home/francesco-mangiacrapa/wseclipseluna/species-discovery-TRUNK/target/species-discovery-3.7.2-SNAPSHOT
+lastWarOutDir=/home/francesco-mangiacrapa/wseclipseluna/species-discovery-TRUNK-TOTEST/target/species-discovery-3.9.1-SNAPSHOT
warSrcDir=src/main/webapp
warSrcDirIsOutput=false
diff --git a/distro/changelog.xml b/distro/changelog.xml
index e367d07..c3be6e8 100644
--- a/distro/changelog.xml
+++ b/distro/changelog.xml
@@ -1,4 +1,8 @@
+
+ [Bug #7568] Managed ASL session expiration during polling on SPD jobs
+
[Feature #6313] SPD portlet upgrade: porting to spd-client-library 4.0.0
diff --git a/pom.xml b/pom.xml
index a8ad964..e80bcd1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,7 +19,7 @@
org.gcube.portlets.user
species-discovery
war
- 3.9.0-SNAPSHOT
+ 3.9.1-SNAPSHOT
gCube Species Discovery
gCube Species Discovery Portlet lets the users discovery species information from the Species Service.
@@ -92,6 +92,12 @@
[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)
compile
+
+
+ org.gcube.portlets.widgets
+ session-checker
+ [1.0.0-SNAPSHOT,)
+
diff --git a/src/main/java/org/gcube/portlets/user/speciesdiscovery/client/SearchController.java b/src/main/java/org/gcube/portlets/user/speciesdiscovery/client/SearchController.java
index a00fcdc..da76038 100644
--- a/src/main/java/org/gcube/portlets/user/speciesdiscovery/client/SearchController.java
+++ b/src/main/java/org/gcube/portlets/user/speciesdiscovery/client/SearchController.java
@@ -93,9 +93,11 @@ import org.gcube.portlets.user.speciesdiscovery.shared.SearchByQueryParameter;
import org.gcube.portlets.user.speciesdiscovery.shared.SearchFilters;
import org.gcube.portlets.user.speciesdiscovery.shared.SearchResultType;
import org.gcube.portlets.user.speciesdiscovery.shared.SearchType;
+import org.gcube.portlets.user.speciesdiscovery.shared.SessionExpired;
import org.gcube.portlets.user.speciesdiscovery.shared.SpeciesCapability;
import org.gcube.portlets.user.speciesdiscovery.shared.filter.ResultFilter;
import org.gcube.portlets.user.speciesdiscovery.shared.util.SearchTermValidator;
+import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSaveNotification.WorskpaceExplorerSaveNotificationListener;
import org.gcube.portlets.widgets.wsexplorer.client.save.WorkspaceExplorerSaveDialog;
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
@@ -1763,6 +1765,8 @@ public class SearchController {
@Override
public void onFailure(Throwable caught) {
+ if(caught instanceof SessionExpired)
+ CheckSession.showLogoutDialog();
}
@Override
@@ -1794,6 +1798,8 @@ public class SearchController {
@Override
public void onFailure(Throwable caught) {
+ if(caught instanceof SessionExpired)
+ CheckSession.showLogoutDialog();
}
@Override
@@ -1826,6 +1832,9 @@ public class SearchController {
@Override
public void onFailure(Throwable caught) {
+ if(caught instanceof SessionExpired)
+ CheckSession.showLogoutDialog();
+
}
@Override
diff --git a/src/main/java/org/gcube/portlets/user/speciesdiscovery/client/rpc/TaxonomySearchService.java b/src/main/java/org/gcube/portlets/user/speciesdiscovery/client/rpc/TaxonomySearchService.java
index a0d69d4..18dae7c 100644
--- a/src/main/java/org/gcube/portlets/user/speciesdiscovery/client/rpc/TaxonomySearchService.java
+++ b/src/main/java/org/gcube/portlets/user/speciesdiscovery/client/rpc/TaxonomySearchService.java
@@ -24,6 +24,7 @@ import org.gcube.portlets.user.speciesdiscovery.shared.SearchFilters;
import org.gcube.portlets.user.speciesdiscovery.shared.SearchResult;
import org.gcube.portlets.user.speciesdiscovery.shared.SearchServiceException;
import org.gcube.portlets.user.speciesdiscovery.shared.SearchStatus;
+import org.gcube.portlets.user.speciesdiscovery.shared.SessionExpired;
import org.gcube.portlets.user.speciesdiscovery.shared.Taxon;
import org.gcube.portlets.user.speciesdiscovery.shared.TaxonomyRow;
import org.gcube.portlets.user.speciesdiscovery.shared.cluster.ClusterCommonNameDataSourceForResultRow;
@@ -89,7 +90,7 @@ public interface TaxonomySearchService extends RemoteService {
public SearchResult getSearchResultRows(int start, int limit,
ResultFilter activeFiltersObject, boolean onlySelected)
- throws SearchServiceException;
+ throws SearchServiceException, SessionExpired;
public SearchResult getSearchTaxonomyRow(int start, int limit,
ResultFilter activeFiltersObject, boolean showOnlySelected)
@@ -104,7 +105,7 @@ public interface TaxonomySearchService extends RemoteService {
public OccurrencesStatus getCountOfOccurrencesBatch()
throws SearchServiceException;
- public List getListTaxonomyJobs() throws Exception;
+ public List getListTaxonomyJobs() throws SessionExpired, Exception;
// public JobTaxonomyModel createTaxonomyJobByChildren(TaxonomyRow taxonomy,
// String dataSourceName) throws Exception;
@@ -124,7 +125,7 @@ public interface TaxonomySearchService extends RemoteService {
SaveFileFormat saveFileFormat, OccurrencesSaveEnum csvType,
boolean isByDataSource, int expectedOccurrence) throws Exception;
- public List getListOccurrencesJob() throws Exception;
+ public List getListOccurrencesJob() throws SessionExpired, Exception;
public boolean saveOccurrenceJob(JobOccurrencesModel jobModel,
String destinationFolderId, String fileName, String scientificName,
@@ -208,8 +209,7 @@ public interface TaxonomySearchService extends RemoteService {
* @return
* @throws Exception
*/
- List getListGisLayerJob()
- throws Exception;
+ List getListGisLayerJob() throws SessionExpired, Exception;
boolean saveGisLayerAsWsLink(
JobGisLayerModel jobGisLayer, String destinationFolderId, String fileName) throws Exception;
diff --git a/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/TaxonomyRowTable.java b/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/TaxonomyRowTable.java
index 022b766..facd5b0 100644
--- a/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/TaxonomyRowTable.java
+++ b/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/TaxonomyRowTable.java
@@ -30,6 +30,7 @@ import org.gcube.portlets.user.speciesdiscovery.server.stream.CloseableIterator;
import org.gcube.portlets.user.speciesdiscovery.shared.CommonName;
import org.gcube.portlets.user.speciesdiscovery.shared.ItemParameter;
import org.gcube.portlets.user.speciesdiscovery.shared.SearchServiceException;
+import org.gcube.portlets.user.speciesdiscovery.shared.SessionExpired;
import org.gcube.portlets.user.speciesdiscovery.shared.TaxonomyRow;
@@ -190,6 +191,9 @@ public class TaxonomyRowTable extends HttpServlet {
} catch (Exception e) {
+ if(e instanceof SessionExpired)
+ throw new SessionExpired("Sorry, user session is expired, Refresh and Try again");
+
logger.error("Error in TaxonomyRowTable servlet ",e);
throw new Exception("Error in ResultRowTable servlet ", e);
}
@@ -199,7 +203,12 @@ public class TaxonomyRowTable extends HttpServlet {
out.close(); //CLOSE STREAM
}catch (Exception e) {
- String error = "Sorry an error occurred when creating the table for taxonomy row with id: "+taxonomyServiceRowID;
+ String error;
+
+ if(e instanceof SessionExpired)
+ error = e.getMessage();
+ else
+ error = "Sorry an error occurred when creating the table for taxonomy row with id: "+taxonomyServiceRowID;
if(out==null){
try{
diff --git a/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/TaxonomySearchServiceImpl.java b/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/TaxonomySearchServiceImpl.java
index 3fd97ac..119c293 100644
--- a/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/TaxonomySearchServiceImpl.java
+++ b/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/TaxonomySearchServiceImpl.java
@@ -93,6 +93,7 @@ import org.gcube.portlets.user.speciesdiscovery.shared.SearchResultType;
import org.gcube.portlets.user.speciesdiscovery.shared.SearchServiceException;
import org.gcube.portlets.user.speciesdiscovery.shared.SearchStatus;
import org.gcube.portlets.user.speciesdiscovery.shared.SearchType;
+import org.gcube.portlets.user.speciesdiscovery.shared.SessionExpired;
import org.gcube.portlets.user.speciesdiscovery.shared.Taxon;
import org.gcube.portlets.user.speciesdiscovery.shared.TaxonomyJob;
import org.gcube.portlets.user.speciesdiscovery.shared.TaxonomyRow;
@@ -128,17 +129,12 @@ public class TaxonomySearchServiceImpl extends RemoteServiceServlet implements T
public static final String BASETAXONOMY = "Kingdom";
public static final String UNK = "Unk";
-// static {
-// Logger root = Logger.getLogger("org.gcube.portlets.user.speciesdiscovery");
-// root.setLevel(Level.ALL);
-// }
-
/**
- * Gets the ASL session.
- *
- * @return the ASL session
- */
-protected ASLSession getASLSession()
+ * Gets the ASL session.
+ *
+ * @return the ASL session
+ */
+ protected ASLSession getASLSession()
{
return SessionUtil.getAslSession(this.getThreadLocalRequest().getSession());
}
@@ -334,7 +330,7 @@ protected ASLSession getASLSession()
*/
@SuppressWarnings("unchecked")
@Override
- public SearchResult getSearchResultRows(int start, int limit, ResultFilter activeFiltersObject, boolean onlySelected) throws SearchServiceException {
+ public SearchResult getSearchResultRows(int start, int limit, ResultFilter activeFiltersObject, boolean onlySelected) throws SessionExpired, SearchServiceException {
logger.info("getSearchResultRows start: "+start+" limit: "+limit+" onlySelected: "+onlySelected);
Long startTime = System.currentTimeMillis();
@@ -389,6 +385,10 @@ protected ASLSession getASLSession()
String time = String.format("%d msc %d sec", endTime, TimeUnit.MILLISECONDS.toSeconds(endTime));
logger.info("returning "+chunk.size()+" elements in " + time);
} catch (Exception e) {
+
+ if(e instanceof SessionExpired)
+ throw new SessionExpired("The session is expired");
+
logger.error("Error in getSearchResultRows ", e);
throw new SearchServiceException(e.getMessage());
}
@@ -1314,7 +1314,7 @@ protected ASLSession getASLSession()
* @see org.gcube.portlets.user.speciesdiscovery.client.rpc.TaxonomySearchService#getListTaxonomyJobs()
*/
@Override
- public List getListTaxonomyJobs() throws Exception {
+ public List getListTaxonomyJobs() throws SessionExpired, Exception {
logger.info("getListTaxonomyJobs... ");
List listJobs = new ArrayList();
@@ -1836,7 +1836,7 @@ protected ASLSession getASLSession()
* @see org.gcube.portlets.user.speciesdiscovery.client.rpc.TaxonomySearchService#getListOccurrencesJob()
*/
@Override
- public List getListOccurrencesJob() throws Exception{
+ public List getListOccurrencesJob() throws SessionExpired, Exception{
logger.info("getListOccurencesJob... ");
List listJobs = new ArrayList();
@@ -1876,6 +1876,13 @@ protected ASLSession getASLSession()
}
} catch (Exception e) {
+
+ if(e instanceof SessionExpired){
+ logger.error("Session is expired");
+ throw new SessionExpired(e.getMessage());
+ }
+
+
logger.error("Error on get iterator "+e, e);
}
@@ -1888,7 +1895,7 @@ protected ASLSession getASLSession()
* @see org.gcube.portlets.user.speciesdiscovery.client.rpc.TaxonomySearchService#getListGisLayerJob()
*/
@Override
- public List getListGisLayerJob() throws Exception{
+ public List getListGisLayerJob() throws SessionExpired, Exception{
logger.info("getListGisLayerJob... ");
List listJobs = new ArrayList();
diff --git a/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/asl/SessionUtil.java b/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/asl/SessionUtil.java
index 4dee867..cdc0eab 100644
--- a/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/asl/SessionUtil.java
+++ b/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/asl/SessionUtil.java
@@ -107,7 +107,7 @@ public class SessionUtil {
//for test only
user = "test.user";
- String scope = "/gcube/devsec"; //Development
+ String scope = "/gcube/preprod/preVRE"; //Development
// String scope = "/d4science.research-infrastructures.eu/gCubeApps/BiodiversityResearchEnvironment"; //Production
httpSession.setAttribute(USERNAME_ATTRIBUTE, user);
ASLSession session = SessionManager.getInstance().getASLSession(sessionID, user);
diff --git a/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/persistence/DaoSession.java b/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/persistence/DaoSession.java
index 5931893..c8c848f 100644
--- a/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/persistence/DaoSession.java
+++ b/src/main/java/org/gcube/portlets/user/speciesdiscovery/server/persistence/DaoSession.java
@@ -18,13 +18,15 @@ import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.TaxonRowP
import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.TaxonomyJobPersistence;
import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.TaxonomyRowPersistence;
import org.gcube.portlets.user.speciesdiscovery.shared.DatabaseServiceException;
+import org.gcube.portlets.user.speciesdiscovery.shared.SessionExpired;
+
/**
* The Class DaoSession.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
- * Feb 9, 2017
+ * Mar 17, 2017
*/
public class DaoSession {
@@ -35,14 +37,48 @@ public class DaoSession {
private static final String JDBCDRIVER = "jdbc:h2:";
+ /**
+ * Check asl session.
+ *
+ * @param session the session
+ * @return true, if is valid
+ * @throws SessionExpired the session expired
+ */
+ public static boolean checkASLSession(ASLSession session) throws SessionExpired{
+
+ if(session==null){
+ String error = "ASL session is null!!!!";
+ logger.error(error);
+ throw new SessionExpired(error);
+ }
+
+ String username = session.getUsername();
+ String scope = session.getScopeName();
+
+ if(username==null || username.isEmpty() ){
+ String error = "Username is null or empty, throwing session expired exception";
+ logger.error(error);
+ throw new SessionExpired(error);
+ }
+
+ if(scope==null || scope.isEmpty() ){
+ String error = "Scope is null or empty, throwing session expired exception";
+ logger.error(error);
+ throw new SessionExpired(error);
+ }
+ logger.trace("Session is valid: [username: "+username+", scope: "+scope+"]");
+ return true;
+ }
+
/**
* Gets the username scope value.
*
* @param username the username
* @param scope the scope
* @return the username scope value
+ * @throws SessionExpired the session expired
*/
- public static String getUsernameScopeValue(String username, String scope){
+ public static String getUsernameScopeValue(String username, String scope) throws SessionExpired{
scope = scope.replaceAll("/","");
username = username.replaceAll("\\.","");
@@ -51,8 +87,6 @@ public class DaoSession {
}
-
-
/**
* Gets the tomcat folder.
*
@@ -75,12 +109,12 @@ public class DaoSession {
*
* @param session the session
* @return the connection url
+ * @throws SessionExpired the session expired
*/
- public static String getConnectionUrl(ASLSession session){
+ public static String getConnectionUrl(ASLSession session) throws SessionExpired{
- String username = session.getUsername();
- String scope = session.getScopeName();
- return JDBCDRIVER +getTomcatFolder()+PERSISTENCE_H2DBSPECIES_H2+getUsernameScopeValue(username,scope)+";create=true";
+ checkASLSession(session);
+ return JDBCDRIVER +getTomcatFolder()+PERSISTENCE_H2DBSPECIES_H2+getUsernameScopeValue(session.getUsername(),session.getScopeName())+";create=true";
}
@@ -112,8 +146,10 @@ public class DaoSession {
*
* @param session the session
* @return the entity manager
+ * @throws SessionExpired the session expired
+ * @throws Exception the exception
*/
- public static EntityManager newEntityManager(ASLSession session){
+ public static EntityManager newEntityManager(ASLSession session) throws SessionExpired, Exception{
return getEntityManagerFactory(session).createEntityManager();
}
@@ -123,8 +159,10 @@ public class DaoSession {
*
* @param session the session
* @return the entity manager factory
+ * @throws SessionExpired the session expired
+ * @throws Exception the exception
*/
- public static EntityManagerFactory getEntityManagerFactory(ASLSession session){
+ public static EntityManagerFactory getEntityManagerFactory(ASLSession session) throws SessionExpired, Exception{
EntityManagerFactory factory = SessionUtil.getEntityManagerFactory(session);
@@ -142,11 +180,12 @@ public class DaoSession {
*
* @param session the session
* @return the occurrences job dao
+ * @throws SessionExpired the session expired
* @throws Exception the exception
*/
- public static OccurrenceJobPersistence getOccurrencesJobDAO(ASLSession session) throws Exception
- {
+ public static OccurrenceJobPersistence getOccurrencesJobDAO(ASLSession session) throws SessionExpired, Exception{
+ checkASLSession(session);
OccurrenceJobPersistence occurrencesJobDao = SessionUtil.getCurrentDaoOccurrencesJob(session);
if(occurrencesJobDao==null){
@@ -164,10 +203,12 @@ public class DaoSession {
*
* @param session the session
* @return the gis layers job dao
+ * @throws SessionExpired the session expired
* @throws Exception the exception
*/
- public static GisLayerJobPersistence getGisLayersJobDAO(ASLSession session) throws Exception {
+ public static GisLayerJobPersistence getGisLayersJobDAO(ASLSession session) throws SessionExpired, Exception{
+ checkASLSession(session);
GisLayerJobPersistence gisLayerJobDao = SessionUtil.getCurrentGisLayersJob(session);
if(gisLayerJobDao==null){
@@ -184,8 +225,10 @@ public class DaoSession {
*
* @param session the session
* @return the gis layer job persistence
+ * @throws SessionExpired the session expired
+ * @throws Exception the exception
*/
- private static GisLayerJobPersistence initGisLayerJobsDao(ASLSession session) {
+ private static GisLayerJobPersistence initGisLayerJobsDao(ASLSession session) throws SessionExpired, Exception {
GisLayerJobPersistence gisLayerJobP = new GisLayerJobPersistence(getEntityManagerFactory(session));
SessionUtil.setCurrentEJBGisLayerJob(session, gisLayerJobP);
return gisLayerJobP;
@@ -196,11 +239,11 @@ public class DaoSession {
*
* @param session the session
* @return the taxonomy job dao
+ * @throws SessionExpired the session expired
* @throws Exception the exception
*/
- public static TaxonomyJobPersistence getTaxonomyJobDAO(ASLSession session) throws Exception
- {
-
+ public static TaxonomyJobPersistence getTaxonomyJobDAO(ASLSession session) throws SessionExpired, Exception {
+ checkASLSession(session);
TaxonomyJobPersistence taxonomyJobPeristence = SessionUtil.getCurrentDAOTaxonomyJob(session);
if(taxonomyJobPeristence==null){
@@ -216,9 +259,12 @@ public class DaoSession {
*
* @param session the session
* @return the entity manager factory
+ * @throws SessionExpired the session expired
+ * @throws Exception the exception
*/
- public static EntityManagerFactory createEntityManagerFactory(ASLSession session){
+ public static EntityManagerFactory createEntityManagerFactory(ASLSession session) throws SessionExpired, Exception {
+ checkASLSession(session);
Map properties = new HashMap();
// properties.put("javax.persistence.jdbc.driver", jdbcDriverH2);
try{
@@ -226,9 +272,8 @@ public class DaoSession {
}
catch (Exception e) {
logger.error("error on get connection url "+e, e);
- String username = session.getUsername();
- String scope = session.getScopeName();
- properties.put("javax.persistence.jdbc.url", JDBCDRIVER+getTomcatFolder()+"/temp/h2dbspecies/h2"+getUsernameScopeValue(username,scope)+";create=true");
+ checkASLSession(session);
+ properties.put("javax.persistence.jdbc.url", JDBCDRIVER+getTomcatFolder()+"/temp/h2dbspecies/h2"+getUsernameScopeValue(session.getUsername(),session.getScopeName())+";create=true");
}
//emf = Persistence.createEntityManagerFactory("jpablogPUnit");
return Persistence.createEntityManagerFactory("SPD_PERSISTENCE_FACTORY",properties);
@@ -241,14 +286,11 @@ public class DaoSession {
*
* @param session the session
* @return the occurrence job persistence
+ * @throws SessionExpired the session expired
* @throws Exception the exception
*/
- public static OccurrenceJobPersistence initOccurrencesJobsDao(ASLSession session) throws Exception
- {
-
- String username = session.getUsername();
- String scope = session.getScopeName();
- return createOccurrencesJobDao(username, scope, session);
+ public static OccurrenceJobPersistence initOccurrencesJobsDao(ASLSession session) throws SessionExpired, Exception {
+ return createOccurrencesJobDao(session.getUsername(), session.getScopeName(), session);
}
@@ -274,9 +316,10 @@ public class DaoSession {
* @param scope the scope
* @param session the session
* @return the occurrence job persistence
+ * @throws SessionExpired the session expired
* @throws Exception the exception
*/
- public static OccurrenceJobPersistence createOccurrencesJobDao(String username, String scope, ASLSession session) throws Exception{
+ public static OccurrenceJobPersistence createOccurrencesJobDao(String username, String scope, ASLSession session) throws SessionExpired, Exception{
OccurrenceJobPersistence occurrenceJobPersistence = new OccurrenceJobPersistence(getEntityManagerFactory(session));
SessionUtil.setCurrentEJBOccurrencesJob(session, occurrenceJobPersistence);
@@ -310,11 +353,11 @@ public class DaoSession {
*
* @param session the session
* @return the occurrence dao
+ * @throws SessionExpired the session expired
* @throws Exception the exception
*/
- public static OccurrenceRowPersistence getOccurrenceDAO(ASLSession session) throws Exception
- {
-
+ public static OccurrenceRowPersistence getOccurrenceDAO(ASLSession session) throws SessionExpired, Exception {
+ checkASLSession(session);
OccurrenceRowPersistence occurrenceEJB = SessionUtil.getCurrentEJBOccurrence(session);
if(occurrenceEJB==null){
@@ -330,10 +373,10 @@ public class DaoSession {
*
* @param session the session
* @return the taxon row persistence
+ * @throws SessionExpired the session expired
* @throws Exception the exception
*/
- public static TaxonRowPersistence initTaxonDao(ASLSession session) throws Exception
- {
+ public static TaxonRowPersistence initTaxonDao(ASLSession session) throws SessionExpired, Exception {
TaxonRowPersistence taxonRowPersistence = new TaxonRowPersistence(getEntityManagerFactory(session));
SessionUtil.setCurrentEJBTaxonRow(session, taxonRowPersistence);
@@ -367,11 +410,11 @@ public class DaoSession {
*
* @param session the session
* @return the taxon dao
+ * @throws SessionExpired the session expired
* @throws Exception the exception
*/
- public static TaxonRowPersistence getTaxonDAO(ASLSession session) throws Exception
- {
-
+ public static TaxonRowPersistence getTaxonDAO(ASLSession session) throws SessionExpired, Exception{
+ checkASLSession(session);
TaxonRowPersistence taxonDao = SessionUtil.getCurrentEJBTaxonRow(session);
if(taxonDao==null){
@@ -390,10 +433,11 @@ public class DaoSession {
*
* @param session the session
* @return the taxonomy dao
+ * @throws SessionExpired the session expired
* @throws Exception the exception
*/
- public static TaxonomyRowPersistence getTaxonomyDAO(ASLSession session) throws Exception
- {
+ public static TaxonomyRowPersistence getTaxonomyDAO(ASLSession session) throws SessionExpired, Exception{
+ checkASLSession(session);
logger.trace("In getTaxonomyDAO...");
TaxonomyRowPersistence taxonItemDAO = SessionUtil.getCurrentEJBTaxonomyItem(session);
@@ -430,27 +474,19 @@ public class DaoSession {
*
* @param session the session
* @return the result row dao
+ * @throws SessionExpired the session expired
* @throws Exception the exception
*/
- public static ResultRowPersistence getResultRowDAO(ASLSession session) throws Exception
- {
-
+ public static ResultRowPersistence getResultRowDAO(ASLSession session) throws SessionExpired, Exception {
+ checkASLSession(session);
logger.trace("In getResultRowDAO...");
-
ResultRowPersistence resultRowEJB = SessionUtil.getCurrentEJBResultRow(session);
if(resultRowEJB==null){
resultRowEJB = initResultRowDao(session);
SessionUtil.setCurrentEJBResultRow(session, resultRowEJB);
}
-
-// logger.trace("Return result row Dao : " + resultRowEJB + " table name: " + resultRowDAO.getTableConfig().getTableName());
-// logger.trace("session id: " + session.getExternalSessionID() + " sessione username: " +session.getUsername() + " session scope: "+session.getScopeName());
-
return resultRowEJB;
}
-
-
-
}
diff --git a/src/main/java/org/gcube/portlets/user/speciesdiscovery/shared/SessionExpired.java b/src/main/java/org/gcube/portlets/user/speciesdiscovery/shared/SessionExpired.java
new file mode 100644
index 0000000..2cbb496
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/speciesdiscovery/shared/SessionExpired.java
@@ -0,0 +1,30 @@
+/**
+ *
+ */
+package org.gcube.portlets.user.speciesdiscovery.shared;
+
+
+/**
+ *
+ * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
+ * Mar 17, 2017
+ */
+public class SessionExpired extends Exception {
+
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -4412298198084979081L;
+
+ /**
+ *
+ */
+ public SessionExpired() {
+
+ }
+
+ public SessionExpired(String arg0){
+ super(arg0);
+ }
+}
diff --git a/src/main/resources/org/gcube/portlets/user/speciesdiscovery/SpeciesDiscovery.gwt.xml b/src/main/resources/org/gcube/portlets/user/speciesdiscovery/SpeciesDiscovery.gwt.xml
index 72dafc0..221c5e8 100644
--- a/src/main/resources/org/gcube/portlets/user/speciesdiscovery/SpeciesDiscovery.gwt.xml
+++ b/src/main/resources/org/gcube/portlets/user/speciesdiscovery/SpeciesDiscovery.gwt.xml
@@ -4,6 +4,8 @@
+
+
diff --git a/src/test/java/org/gcube/portlets/user/speciesdiscovery/client/H2TestResultItemRetrievingAndConverting.java b/src/test/java/org/gcube/portlets/user/speciesdiscovery/client/H2TestResultItemRetrievingAndConverting.java
index 818f127..01378f3 100644
--- a/src/test/java/org/gcube/portlets/user/speciesdiscovery/client/H2TestResultItemRetrievingAndConverting.java
+++ b/src/test/java/org/gcube/portlets/user/speciesdiscovery/client/H2TestResultItemRetrievingAndConverting.java
@@ -1,5 +1,5 @@
/**
- *
+ *
*/
package org.gcube.portlets.user.speciesdiscovery.client;
@@ -16,6 +16,7 @@ import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.portlets.user.speciesdiscovery.server.persistence.DaoSession;
import org.gcube.portlets.user.speciesdiscovery.shared.ResultRow;
+import org.gcube.portlets.user.speciesdiscovery.shared.SessionExpired;
import org.gcube.portlets.user.speciesdiscovery.shared.TaxonomyRow;
/**
@@ -23,53 +24,53 @@ import org.gcube.portlets.user.speciesdiscovery.shared.TaxonomyRow;
*
*/
public class H2TestResultItemRetrievingAndConverting {
-
+
private static final int MAX_ELEMENTS = 20;
static String sessionID = "1";
static String user = "test.user";
static ScopeBean scope;
static ASLSession session;
-
-
+
+
public static void main(String[] args) throws Exception
{
-
+
session = SessionManager.getInstance().getASLSession(sessionID, user);
scope = new ScopeBean("/gcube/devsec");
session.setScope(scope.toString());
-
+
EntityManagerFactory factory = DaoSession.getEntityManagerFactory(session);
-
+
EntityManager em = factory.createEntityManager();
// ScopeProvider.instance.set("/gcube/devsec");
-
+
int removed;
String tableName;
List list;
-
+
// String tableName = "ParentTaxonomyRow";
-//
+//
// List list = getList(em, tableName);
-//
+//
// System.out.println("list "+tableName+ "size is "+list.size());
-
+
// em = factory.createEntityManager();
// removed = removeAll(em, tableName);
-//
+//
// System.out.println("removed " +removed);
-
+
tableName = "ResultRow";
-
+
em = factory.createEntityManager();
list = getList(em, tableName);
-
+
System.out.println("list "+tableName+ "size is "+list.size());
-
-
+
+
// removeAll(em, "ParentTaxonomyRow");
// em = factory.createEntityManager();
// removed = removeAll(em, tableName);
-
+
// System.out.println("removed " +removed);
@@ -87,130 +88,130 @@ public class H2TestResultItemRetrievingAndConverting {
// CloseableIterator output = IteratorChainBuilder.buildChain(input, resultType, session);
//
// FetchingSession fetchingSession = (FetchingSession) FetchingSessionUtil.createFetchingSession(output, resultType, session);
-//
+//
-//
+//
// while(!fetchingSession.isComplete()) {
-//
+//
// System.out.println((System.currentTimeMillis()-start)+" buffer size "+fetchingSession.getBufferSize());
// last = System.currentTimeMillis();
-//
+//
// Thread.sleep(1000);
-//
+//
// System.out.println("COMPLETE: "+(System.currentTimeMillis()-last)+"ms from last item to close the stream; buffer size "+fetchingSession.getBufferSize());
//
// System.out.println(fetchingSession.getBufferSize() + " results in "+(System.currentTimeMillis()-start)+"ms total; "+(last-start)+"ms from first to last result");
// }
-
+
// System.out.println("Start time: "+last);
-//
+//
// while(output.hasNext()) {
-//
+//
// System.out.println((System.currentTimeMillis()-last)+"ms "+output.next());
// last = System.currentTimeMillis();
// counter++;
// }
-
+
// Stream input = taxonomyService.searchByQuery2("'sarda sarda' as ScientificName return Taxon");
// //from ResultItem to ResultRow
//// List listElements = new ArrayList();
//// List listRR = new ArrayList();
//// ResultItemConverter converter = new ResultItemConverter(session);
-//
+//
// TaxonomyItemConverter converter = new TaxonomyItemConverter(session);
// List listRR = new ArrayList();
// List listElements = new ArrayList();
-//
+//
// while(input.hasNext()) {
-//
+//
//// ResultItem result = (ResultItem) input.next();
-//
+//
// TaxonomyItem result = (TaxonomyItem) input.next();
-//
+//
// System.out.println((System.currentTimeMillis()-last)+" ms to recover "+result);
// last = System.currentTimeMillis();
// counter++;
-//
+//
// listElements.add(result);
-//
+//
// listRR.add(converter.convert(result));
-//
+//
// System.out.println((System.currentTimeMillis()-last)+" ms to convert "+result);
-//
+//
// if(MAX_ELEMENTS == counter)
// break;
// }
-//
+//
// input.close();
//
// counter = 0;
// start = System.currentTimeMillis();
// last = System.currentTimeMillis();
-
-//
+
+//
//// for (ResultRow resultRow : listRR) {
// for (TaxonomyRow resultRow : listRR) {
-//
+//
// System.out.println(counter + ")" + (System.currentTimeMillis()-last)+" ms "+resultRow);
// last = System.currentTimeMillis();
-//
-//
+//
+//
// try{
-//
+//
//// storeTaxonParents(resultRow);
//// storeCommonName(listElements.get(counter), resultRow);
// storeRR(resultRow);
-//
+//
// }catch (Exception e) {
// e.printStackTrace();
// }
-//
+//
// if(counter==50)
// break;
-//
+//
// counter++;
// }
-
+
// System.out.println("BUFFER SIZE: " + fetchingSession.getBuffer().getList().size());
-
-
+
+
// System.out.println("COMPLETE: "+(System.currentTimeMillis()-last)+" ms from last item to close the stream");
-//
+//
// System.out.println(counter + " results in "+(System.currentTimeMillis()-start)+" ms total; "+(last-start)+" ms from first to last result");
-
-
-
+
+
+
List listServiceId = new ArrayList();
-
+
int i = 0;
for (ResultRow rr : list) {
-
+
listServiceId.add(rr.getIdToString());
-
+
System.out.println(++i +")listserviceId "+listServiceId);
-
+
if(i==30)
break;
}
-
-
-
+
+
+
em = factory.createEntityManager();
String queryStr = "select t from ResultRow t where t."+ResultRow.ID_FIELD+" IN :inclList";
-
+
TypedQuery query2 = em.createQuery(queryStr, ResultRow.class);
-
+
query2.setParameter("inclList", listServiceId);
-
+
// query.setFirstResult(2);
-//
+//
// query.setMaxResults(5);
-
+
start = System.currentTimeMillis();
List results = query2.getResultList();
-//
+//
i = 0;
for (ResultRow r: results) {
System.out.println("ResultRow query "+ ++i +") " + r);
@@ -221,43 +222,43 @@ public class H2TestResultItemRetrievingAndConverting {
//
//
// CriteriaBuilder cb = em.getCriteriaBuilder();
-//
+//
// // Query for a List of objects.
//// CriteriaQuery