2013-03-04 14:38:25 +01:00
|
|
|
/**
|
2017-01-13 11:00:53 +01:00
|
|
|
*
|
2013-03-04 14:38:25 +01:00
|
|
|
*/
|
|
|
|
package org.gcube.portlets.user.speciesdiscovery.server.asl;
|
|
|
|
|
2013-10-24 12:52:34 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
import javax.persistence.EntityManagerFactory;
|
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
import org.gcube.application.framework.core.session.ASLSession;
|
|
|
|
import org.gcube.application.framework.core.session.SessionManager;
|
2017-02-09 18:23:28 +01:00
|
|
|
import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.GisLayerJobPersistence;
|
2013-03-04 14:38:25 +01:00
|
|
|
import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.OccurrenceJobPersistence;
|
|
|
|
import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.OccurrenceRowPersistence;
|
|
|
|
import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.ResultRowPersistence;
|
|
|
|
import org.gcube.portlets.user.speciesdiscovery.server.persistence.dao.TaxonRowPersistence;
|
|
|
|
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.server.service.SpeciesService;
|
|
|
|
import org.gcube.portlets.user.speciesdiscovery.server.session.FetchingSession;
|
|
|
|
import org.gcube.portlets.user.speciesdiscovery.shared.FetchingElement;
|
|
|
|
import org.gcube.portlets.user.speciesdiscovery.shared.Occurrence;
|
2013-10-24 12:52:34 +02:00
|
|
|
import org.gcube.portlets.user.speciesdiscovery.shared.TaxonomyRow;
|
|
|
|
import org.gcube.portlets.user.speciesdiscovery.shared.cluster.ClusterCommonNameDataSourceForResultRow;
|
|
|
|
import org.gcube.portlets.user.speciesdiscovery.shared.cluster.ClusterCommonNameDataSourceForTaxonomyRow;
|
2013-03-04 14:38:25 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-13 11:00:53 +01:00
|
|
|
*
|
2013-03-04 14:38:25 +01:00
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class SessionUtil {
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
public static final String SPECIES_SERVICE = "SPECIES_SERVICE";
|
|
|
|
public static final String SEARCH_SESSION = "SEARCH_SESSION";
|
|
|
|
public static final String TAXONOMY_OCCURRENCE = "TAXONOMY_OCCURRENCE";
|
|
|
|
public static final String CONNECTION_SOURCE = "CONNECTION_SOURCE";
|
|
|
|
public static final String USERNAME_ATTRIBUTE = "username";
|
|
|
|
public static final String ENTITY_FACTORY = "ENTITY_FACTORY";
|
|
|
|
public static final String EJB_RESULT_ROW = "EJB_RESULT_ROW";
|
|
|
|
public static final String EJB_TAXON_ROW = "EJB_TAXON_ROW";
|
|
|
|
public static final String EJB_OCCURENCE = "EJB_OCCURENCE";
|
|
|
|
public static final String EJB_TAXONOMY = "EJB_TAXONOMY";
|
|
|
|
public static final String EJB_OCCURRENCES_JOB = "EJB_OCCURRENCES_JOB";
|
|
|
|
public static final String EJB_TAXONOMY_JOB = "EJB_TAXONOMY_JOB";
|
2017-02-09 18:23:28 +01:00
|
|
|
public static final String EJB_GIS_LAYER_JOB = "EJB_GIS_LAYER_JOB";
|
2013-07-18 18:32:28 +02:00
|
|
|
public static final String CURRENT_SPD_QUERY = "CURRENT_SPD_QUERY";
|
2013-10-24 12:52:34 +02:00
|
|
|
private static final String CLUSTER_COMMONNAME_FOR_RESULTROW = "CLUSTER_COMMONNAME_FOR_RESULTROW";
|
|
|
|
private static final String CLUSTER_COMMONNAME_FOR_TAXONOMYROW = "CLUSTER_COMMONNAME_FOR_TAXONOMYROW";
|
|
|
|
private static final String CACHE_HASH_MAP_CHILDREN_TAXONOMY = "CACHE_HASH_MAP_CHILDREN_TAXONOMY";
|
|
|
|
private static final String CACHE_HASH_MAP_SYNONYMS_TAXONOMY = "CACHE_HASH_MAP_SYNONYMS_TAXONOMY";
|
|
|
|
private static final String CACHE_HASH_MAP_TAXONOMYID_TAXONOMY = "CACHE_HASH_MAP_TAXONOMYID_TAXONOMY";
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
protected static Logger logger = Logger.getLogger(SessionUtil.class);
|
2017-01-13 11:00:53 +01:00
|
|
|
|
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
public static EntityManagerFactory getEntityManagerFactory(ASLSession session) {
|
|
|
|
return (EntityManagerFactory) session.getAttribute(ENTITY_FACTORY);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setEntityManagerFactory(ASLSession session, EntityManagerFactory factory) {
|
|
|
|
session.setAttribute(ENTITY_FACTORY, factory);
|
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
public static SpeciesService getService(ASLSession session) throws Exception
|
|
|
|
{
|
|
|
|
SpeciesService service = (SpeciesService) session.getAttribute(SPECIES_SERVICE);
|
|
|
|
if (service==null) {
|
|
|
|
logger.trace("Service not found, creating it");
|
2017-01-13 11:00:53 +01:00
|
|
|
service = new SpeciesService();
|
2013-03-04 14:38:25 +01:00
|
|
|
session.setAttribute(SPECIES_SERVICE, service);
|
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
return service;
|
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public static FetchingSession<? extends FetchingElement> getCurrentSearchSession(ASLSession session)
|
|
|
|
{
|
|
|
|
return (FetchingSession<? extends FetchingElement>) session.getAttribute(SEARCH_SESSION);
|
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
public static void setCurrentSearchSession(ASLSession session, FetchingSession<? extends FetchingElement> searchSession){
|
|
|
|
session.setAttribute(SEARCH_SESSION, searchSession);
|
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public static FetchingSession<Occurrence> getCurrentOccurrenceSession(ASLSession session){
|
|
|
|
return (FetchingSession<Occurrence>) session.getAttribute(TAXONOMY_OCCURRENCE);
|
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
public static void setCurrentOccurrenceSession(ASLSession session, FetchingSession<Occurrence> searchSession){
|
|
|
|
session.setAttribute(TAXONOMY_OCCURRENCE, searchSession);
|
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
public static ASLSession getAslSession(HttpSession httpSession)
|
|
|
|
{
|
|
|
|
String sessionID = httpSession.getId();
|
|
|
|
String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE);
|
|
|
|
|
|
|
|
if (user == null) {
|
|
|
|
|
|
|
|
//for test only
|
2013-09-13 14:12:39 +02:00
|
|
|
user = "test.user";
|
2017-03-20 14:43:11 +01:00
|
|
|
String scope = "/gcube/preprod/preVRE"; //Development
|
2013-07-03 15:47:39 +02:00
|
|
|
// String scope = "/d4science.research-infrastructures.eu/gCubeApps/BiodiversityResearchEnvironment"; //Production
|
2013-03-04 14:38:25 +01:00
|
|
|
httpSession.setAttribute(USERNAME_ATTRIBUTE, user);
|
|
|
|
ASLSession session = SessionManager.getInstance().getASLSession(sessionID, user);
|
2013-03-15 19:18:12 +01:00
|
|
|
session.setScope(scope);
|
|
|
|
logger.warn("TaxonomySearchServiceImpl STARTING IN TEST MODE - NO USER FOUND");
|
|
|
|
logger.warn("Created fake Asl session for user "+user + " with scope "+scope);
|
2013-03-04 14:38:25 +01:00
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SessionManager.getInstance().getASLSession(sessionID, user);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setCurrentEJBResultRow(ASLSession session, ResultRowPersistence resultRowPersistence) {
|
|
|
|
session.setAttribute(EJB_RESULT_ROW, resultRowPersistence);
|
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
public static ResultRowPersistence getCurrentEJBResultRow(ASLSession session) {
|
|
|
|
return (ResultRowPersistence) session.getAttribute(EJB_RESULT_ROW);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setCurrentEJBTaxonRow(ASLSession session,TaxonRowPersistence taxonRowPersistence) {
|
|
|
|
session.setAttribute(EJB_TAXON_ROW, taxonRowPersistence);
|
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
public static TaxonRowPersistence getCurrentEJBTaxonRow(ASLSession session) {
|
|
|
|
return (TaxonRowPersistence) session.getAttribute(EJB_TAXON_ROW);
|
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
public static void setCurrentEJBOccurrence(ASLSession session, OccurrenceRowPersistence occurrenceRowPersistence) {
|
|
|
|
session.setAttribute(EJB_OCCURENCE, occurrenceRowPersistence);
|
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
public static OccurrenceRowPersistence getCurrentEJBOccurrence(ASLSession session) {
|
|
|
|
return (OccurrenceRowPersistence) session.getAttribute(EJB_OCCURENCE);
|
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public static TaxonomyRowPersistence getCurrentEJBTaxonomyItem(ASLSession session) {
|
|
|
|
return (TaxonomyRowPersistence) session.getAttribute(EJB_TAXONOMY);
|
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
public static void setCurrentEJBTaxonomyItem(ASLSession session, TaxonomyRowPersistence taxonomyItemDAO) {
|
|
|
|
session.setAttribute(EJB_TAXONOMY, taxonomyItemDAO);
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void setCurrentEJBOccurrencesJob(ASLSession session, OccurrenceJobPersistence occurrenceJobPersistence) {
|
|
|
|
session.setAttribute(EJB_OCCURRENCES_JOB, occurrenceJobPersistence);
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public static OccurrenceJobPersistence getCurrentDaoOccurrencesJob(ASLSession session) {
|
|
|
|
return (OccurrenceJobPersistence) session.getAttribute(EJB_OCCURRENCES_JOB);
|
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public static TaxonomyJobPersistence getCurrentDAOTaxonomyJob(ASLSession session) {
|
|
|
|
return (TaxonomyJobPersistence) session.getAttribute(EJB_TAXONOMY_JOB);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setCurrentDAOTaxonomyJob(ASLSession session, TaxonomyJobPersistence taxonomyJobPeristence) {
|
|
|
|
session.setAttribute(EJB_TAXONOMY_JOB, taxonomyJobPeristence);
|
|
|
|
}
|
2013-07-18 18:32:28 +02:00
|
|
|
|
2017-02-09 18:23:28 +01:00
|
|
|
/**
|
|
|
|
* @param session
|
|
|
|
* @param gisLayerJobDao
|
|
|
|
*/
|
|
|
|
public static void setCurrentEJBGisLayerJob(ASLSession session, GisLayerJobPersistence gisLayerJobDao) {
|
|
|
|
session.setAttribute(EJB_GIS_LAYER_JOB, gisLayerJobDao);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param session
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static GisLayerJobPersistence getCurrentGisLayersJob( ASLSession session) {
|
|
|
|
return (GisLayerJobPersistence) session.getAttribute(EJB_GIS_LAYER_JOB);
|
|
|
|
}
|
|
|
|
|
2013-07-18 18:32:28 +02:00
|
|
|
/**
|
|
|
|
* @param aslSession
|
|
|
|
* @param lastQuery
|
|
|
|
*/
|
|
|
|
public static void setCurrentQuery(ASLSession aslSession, String lastQuery) {
|
|
|
|
logger.trace("Last query in session: "+lastQuery);
|
|
|
|
aslSession.setAttribute(CURRENT_SPD_QUERY, lastQuery);
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-07-18 18:32:28 +02:00
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-07-18 18:32:28 +02:00
|
|
|
/**
|
2017-01-13 11:00:53 +01:00
|
|
|
*
|
2013-07-18 18:32:28 +02:00
|
|
|
* @param aslSession
|
|
|
|
*/
|
|
|
|
public static String getCurrentQuery(ASLSession aslSession) {
|
|
|
|
return (String) aslSession.getAttribute(CURRENT_SPD_QUERY);
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-07-18 18:32:28 +02:00
|
|
|
}
|
2013-10-24 12:52:34 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param hashClusterCommonNameDataSource
|
|
|
|
*/
|
|
|
|
public static void setCurrentClusterCommonNameForResultRow(ASLSession session, HashMap<String, ClusterCommonNameDataSourceForResultRow> hashClusterCommonNameDataSource) {
|
|
|
|
session.setAttribute(CLUSTER_COMMONNAME_FOR_RESULTROW, hashClusterCommonNameDataSource);
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-10-24 12:52:34 +02:00
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-10-24 12:52:34 +02:00
|
|
|
/**
|
|
|
|
* @param hashClusterCommonNameDataSource
|
2017-01-13 11:00:53 +01:00
|
|
|
* @return
|
2013-10-24 12:52:34 +02:00
|
|
|
*/
|
|
|
|
public static HashMap<String, ClusterCommonNameDataSourceForResultRow> getCurrentClusterCommonNameForResultRow(ASLSession session) {
|
|
|
|
return (HashMap<String, ClusterCommonNameDataSourceForResultRow>) session.getAttribute(CLUSTER_COMMONNAME_FOR_RESULTROW);
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-10-24 12:52:34 +02:00
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
|
|
|
|
2013-10-24 12:52:34 +02:00
|
|
|
/**
|
|
|
|
* @param hashClusterCommonNameDataSource
|
|
|
|
*/
|
|
|
|
public static void setCurrentClusterCommonNameForTaxonomyRow(ASLSession session, HashMap<String, ClusterCommonNameDataSourceForTaxonomyRow> hashClusterCommonNameDataSource) {
|
|
|
|
session.setAttribute(CLUSTER_COMMONNAME_FOR_TAXONOMYROW, hashClusterCommonNameDataSource);
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-10-24 12:52:34 +02:00
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-10-24 12:52:34 +02:00
|
|
|
/**
|
|
|
|
* @param hashClusterCommonNameDataSource
|
2017-01-13 11:00:53 +01:00
|
|
|
* @return
|
2013-10-24 12:52:34 +02:00
|
|
|
*/
|
|
|
|
public static HashMap<String, ClusterCommonNameDataSourceForTaxonomyRow> getCurrentClusterCommonNameForTaxonomyRow(ASLSession session) {
|
|
|
|
return (HashMap<String, ClusterCommonNameDataSourceForTaxonomyRow>) session.getAttribute(CLUSTER_COMMONNAME_FOR_TAXONOMYROW);
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-10-24 12:52:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 11:00:53 +01:00
|
|
|
* @return
|
|
|
|
*
|
2013-10-24 12:52:34 +02:00
|
|
|
*/
|
|
|
|
public static HashMap<String, TaxonomyRow> getHashMapChildrenTaxonomyCache(ASLSession session) {
|
|
|
|
return (HashMap<String, TaxonomyRow>) session.getAttribute(CACHE_HASH_MAP_CHILDREN_TAXONOMY);
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-10-24 12:52:34 +02:00
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-10-24 12:52:34 +02:00
|
|
|
/**
|
2017-01-13 11:00:53 +01:00
|
|
|
* @return
|
|
|
|
*
|
2013-10-24 12:52:34 +02:00
|
|
|
*/
|
|
|
|
public static void setHashMapChildrenTaxonomyCache(ASLSession session, Map<String, TaxonomyRow> list) {
|
|
|
|
session.setAttribute(CACHE_HASH_MAP_CHILDREN_TAXONOMY, list);
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-10-24 12:52:34 +02:00
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-10-24 12:52:34 +02:00
|
|
|
/**
|
2017-01-13 11:00:53 +01:00
|
|
|
* @return
|
|
|
|
*
|
2013-10-24 12:52:34 +02:00
|
|
|
*/
|
|
|
|
public static HashMap<String, TaxonomyRow> getHashMapSynonymsTaxonomyCache(ASLSession session) {
|
|
|
|
return (HashMap<String, TaxonomyRow>) session.getAttribute(CACHE_HASH_MAP_SYNONYMS_TAXONOMY);
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-10-24 12:52:34 +02:00
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-10-24 12:52:34 +02:00
|
|
|
/**
|
2017-01-13 11:00:53 +01:00
|
|
|
* @return
|
|
|
|
*
|
2013-10-24 12:52:34 +02:00
|
|
|
*/
|
|
|
|
public static void setHashMapSynonymsTaxonomyCache(ASLSession session, Map<String, TaxonomyRow> list) {
|
|
|
|
session.setAttribute(CACHE_HASH_MAP_SYNONYMS_TAXONOMY, list);
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-10-24 12:52:34 +02:00
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
|
|
|
|
2013-10-24 12:52:34 +02:00
|
|
|
/**
|
2017-01-13 11:00:53 +01:00
|
|
|
* @return
|
|
|
|
*
|
2013-10-24 12:52:34 +02:00
|
|
|
*/
|
|
|
|
public static HashMap<String, TaxonomyRow> getHashMapTaxonomyByIdsCache(ASLSession session) {
|
|
|
|
return (HashMap<String, TaxonomyRow>) session.getAttribute(CACHE_HASH_MAP_TAXONOMYID_TAXONOMY);
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-10-24 12:52:34 +02:00
|
|
|
}
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-10-24 12:52:34 +02:00
|
|
|
/**
|
2017-01-13 11:00:53 +01:00
|
|
|
* @return
|
|
|
|
*
|
2013-10-24 12:52:34 +02:00
|
|
|
*/
|
|
|
|
public static void setHashMapTaxonomyByIdsCache(ASLSession session, Map<String, TaxonomyRow> list) {
|
|
|
|
session.setAttribute(CACHE_HASH_MAP_TAXONOMYID_TAXONOMY, list);
|
2017-01-13 11:00:53 +01:00
|
|
|
|
2013-10-24 12:52:34 +02:00
|
|
|
}
|
2017-02-09 18:23:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-04 14:38:25 +01:00
|
|
|
}
|