diff --git a/.classpath b/.classpath index 4dc55e9..27e030b 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,6 @@ - + @@ -20,10 +20,10 @@ - + - + - + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 6249222..672496e 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,12 +1,12 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 22f85c8..b648fc3 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -4,6 +4,9 @@ + + uses + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml index f801044..376d52f 100644 --- a/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -3,5 +3,5 @@ - + diff --git a/distro/changelog.xml b/distro/changelog.xml index d173cd9..b41f4a1 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,4 +1,8 @@ + + Support Java 8 compatibility [ticket #8432] + Fixed groupId diff --git a/pom.xml b/pom.xml index b17f2e6..a8731b7 100644 --- a/pom.xml +++ b/pom.xml @@ -15,9 +15,10 @@ org.gcube.portlets.user databases-manager-portlet war - 1.7.0-SNAPSHOT + 1.8.0-SNAPSHOT DatabasesResourceManagerPortlet Databases Resource Manager Portlet + https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet @@ -40,6 +41,9 @@ distro config + + 1.7 + 2.6.1 3.3.2 @@ -99,13 +103,9 @@ - org.gcube.portal - custom-portal-handler - - - - org.gcube.applicationsupportlayer - aslcore + org.gcube.common.portal + portal-manager + provided @@ -114,6 +114,13 @@ provided + + org.gcube.portal + client-context-library + [1.0.0-SNAPSHOT,) + compile + + diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/DatabasesManager.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/DatabasesManager.java index 963e19d..b6d0daa 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/DatabasesManager.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/DatabasesManager.java @@ -1,5 +1,9 @@ package org.gcube.portlets.user.databasesmanager.client; +import org.gcube.portlets.user.databasesmanager.client.panels.GxtBorderLayoutPanel; +import org.gcube.portlets.user.databasesmanager.client.resources.Resources; +import org.gcube.portlets.user.databasesmanager.shared.Constants; + import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; import com.google.gwt.event.logical.shared.ResizeEvent; @@ -9,11 +13,6 @@ import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.ServiceDefTarget; import com.google.gwt.user.client.ui.RootPanel; -import org.gcube.portlets.user.databasesmanager.client.panels.GxtBorderLayoutPanel; -import org.gcube.portlets.user.databasesmanager.client.resources.Resources; -import org.gcube.portlets.user.databasesmanager.shared.Constants; -import org.gcube.portlets.widgets.sessionchecker.client.CheckSession; - /** * @author "Loredana Liccardo loredana.liccardo@isti.cnr.it" * @@ -33,7 +32,7 @@ public class DatabasesManager implements EntryPoint { public void onModuleLoad() { - CheckSession.getInstance().startPolling(); + //CheckSession.getInstance().startPolling(); HandlerManager eventBus = new HandlerManager(this); diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/utils/UIDGenerator.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/utils/UIDGenerator.java index 238cc12..7e1a04f 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/utils/UIDGenerator.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/utils/UIDGenerator.java @@ -8,8 +8,9 @@ public class UIDGenerator { * Generate a random uuid of the specified length. Example: uuid(15) returns * "VcydxgltxrVZSTV" * - * @param len - * the desired number of characters + * + * @param len the desired number of characters + * @return string len */ public static String get(int len) { return get(len, CHARS.length); @@ -17,17 +18,18 @@ public class UIDGenerator { /** * Generate a random uuid of the specified length, and radix. Examples: - *
    - *
  • uuid(8, 2) returns "01001010" (8 character ID, base=2) - *
  • uuid(8, 10) returns "47473046" (8 character ID, base=10) - *
  • uuid(8, 16) returns "098F4D35" (8 character ID, base=16) - *
+ * + * uuid(8, 2) returns "01001010" (8 character ID, base=2) + * uuid(8, 10) returns "47473046" (8 character ID, base=10) + * uuid(8, 16) returns "098F4D35" (8 character ID, base=16) + * * * @param len * the desired number of characters * @param radix * the number of allowable values for each character (must be <= * 62) + * @return random uuid */ public static String get(int len, int radix) { if (radix > CHARS.length) { @@ -44,6 +46,8 @@ public class UIDGenerator { /** * Generate a RFC4122, version 4 ID. Example: * "92329D39-6F5C-4520-ABFC-AAB64544E172" + * + * @return id */ public static String get() { char[] uuid = new char[36]; diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/portlet/DatabasesManager.java b/src/main/java/org/gcube/portlets/user/databasesmanager/portlet/DatabasesManager.java index 94fda40..a604627 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/portlet/DatabasesManager.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/portlet/DatabasesManager.java @@ -7,10 +7,16 @@ import javax.portlet.PortletException; import javax.portlet.PortletRequestDispatcher; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; -import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; + +import org.gcube.common.portal.PortalContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class DatabasesManager extends GenericPortlet { + private final Logger logger= LoggerFactory.getLogger(DatabasesManager.class); + + /** * JSP folder name */ @@ -29,7 +35,10 @@ public class DatabasesManager extends GenericPortlet { */ public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { - ScopeHelper.setContext(request); + logger.trace("DatabasesManager loading from JSP: "+VIEW_JSP); + logger.trace("Setting user in session using PortalContext"); + PortalContext.setUserInSession(request); + PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(VIEW_JSP); rd.include(request,response); } diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/server/GWTdbManagerServiceImpl.java b/src/main/java/org/gcube/portlets/user/databasesmanager/server/GWTdbManagerServiceImpl.java index 877cbc5..6c3bb68 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/server/GWTdbManagerServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/server/GWTdbManagerServiceImpl.java @@ -5,11 +5,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; import java.io.OutputStreamWriter; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLStreamHandler; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; @@ -19,6 +15,8 @@ import java.util.Set; import java.util.concurrent.ConcurrentLinkedQueue; import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; import net.sf.ehcache.Cache; import net.sf.ehcache.CacheManager; @@ -29,8 +27,6 @@ import net.sf.ehcache.store.MemoryStoreEvictionPolicy; import org.apache.log4j.Logger; import org.apache.regexp.RE; -import org.gcube.application.framework.core.session.ASLSession; -import org.gcube.contentmanager.storageclient.model.protocol.smp.SMPURLConnection; import org.gcube.data.analysis.dataminermanagercl.server.DataMinerService; import org.gcube.data.analysis.dataminermanagercl.server.dmservice.SClient; import org.gcube.data.analysis.dataminermanagercl.shared.data.OutputData; @@ -51,6 +47,7 @@ import org.gcube.portlets.user.databasesmanager.client.datamodel.Row; import org.gcube.portlets.user.databasesmanager.client.datamodel.SamplingResultWithFileFromServlet; import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryResultWithFileFromServlet; import org.gcube.portlets.user.databasesmanager.server.util.DataExchangedThroughQueue; +import org.gcube.portlets.user.databasesmanager.server.util.ServiceCredentials; import org.gcube.portlets.user.databasesmanager.server.util.SessionUtil; import org.gcube.portlets.user.databasesmanager.shared.AlgorithmsName; import org.gcube.portlets.user.databasesmanager.shared.Constants; @@ -265,7 +262,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } } - private void initVariables(ASLSession session) { + private void initVariables(HttpServletRequest httpRequest, + ServiceCredentials serviceCredentials) { + HttpSession session = httpRequest.getSession(); // Hashmap that contains computationId with a uid key HashMap computationIDMap = new HashMap(); @@ -310,16 +309,15 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements public List getResource() throws Exception { try { - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); - // get scope - String scope = session.getScope(); + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + ServiceCredentials serviceCredentials = SessionUtil + .getServiceCredentials(httpRequest); // check if the thread is already started - Boolean value = getThreadStarted(scope); + Boolean value = getThreadStarted(serviceCredentials.getScope()); if ((value == null) || (value.booleanValue() == false)) { DataExchangedThroughQueue dataqueue = new DataExchangedThroughQueue( - scope); + serviceCredentials.getScope()); queue.offer(dataqueue); Thread t = new Thread(dataLoader); @@ -329,8 +327,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } // initialize variables with application startup - initVariables(session); - return recoverResources(scope); + initVariables(httpRequest, serviceCredentials); + return recoverResources(serviceCredentials.getScope()); } catch (Exception e) { logger.error("dbmanager-> ", e); throw e; @@ -344,10 +342,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements try { - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + ServiceCredentials serviceCredentials = SessionUtil + .getServiceCredentials(httpRequest); + // get scope - String scope = session.getScope(); + String scope = serviceCredentials.getScope(); return recoverDatabases(scope, resourceName); } catch (Exception e) { logger.error("dbmanager-> ", e); @@ -362,10 +362,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements try { - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + ServiceCredentials serviceCredentials = SessionUtil + .getServiceCredentials(httpRequest); + // get scope - String scope = session.getScope(); + String scope = serviceCredentials.getScope(); return recoverSchema(scope, dataInput); } catch (Exception e) { logger.error("dbmanager-> ", e); @@ -379,10 +381,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements try { - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + ServiceCredentials serviceCredentials = SessionUtil + .getServiceCredentials(httpRequest); + // get scope - String scope = session.getScope(); + String scope = serviceCredentials.getScope(); return recoverTables(scope, dataInput, elementType); } catch (Exception e) { logger.error("dbmanager-> ", e); @@ -484,10 +488,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements try { logger.info("Submit Query Request received. Starting to manage the request."); - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + ServiceCredentials serviceCredentials = SessionUtil + .getServiceCredentials(httpRequest); + // get scope - String scope = session.getScope(); + String scope = serviceCredentials.getScope(); logger.info("dbmanager-> Dialect used for smart correction: " + language); @@ -729,10 +735,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements try { logger.info("dbmanager-> Sampling on table Request received. Starting to manage the request."); - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + ServiceCredentials serviceCredentials = SessionUtil + .getServiceCredentials(httpRequest); + // get scope - String scope = session.getScope(); + String scope = serviceCredentials.getScope(); // data input List inputParameters = new ArrayList(); @@ -881,10 +889,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements try { logger.info("dbmanager-> Smart Sampling on table Request received. Starting to manage the request."); - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + ServiceCredentials serviceCredentials = SessionUtil + .getServiceCredentials(httpRequest); + // get scope - String scope = session.getScope(); + String scope = serviceCredentials.getScope(); // data input List inputParameters = new ArrayList(); @@ -1030,10 +1040,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements try { logger.info("dbmanager-> Random Sampling on table Request received. Starting to manage the request."); - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + ServiceCredentials serviceCredentials = SessionUtil + .getServiceCredentials(httpRequest); + // get scope - String scope = session.getScope(); + String scope = serviceCredentials.getScope(); // data input List inputParameters = new ArrayList(); @@ -1144,10 +1156,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements try { logger.info("dbmanager-> Table Details Recovery Request received. Starting to manage the request."); - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + ServiceCredentials serviceCredentials = SessionUtil + .getServiceCredentials(httpRequest); + // get scope - String scope = session.getScope(); + String scope = serviceCredentials.getScope(); // data input List inputParameters = new ArrayList(); @@ -1419,9 +1433,11 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements throws Exception { if (jobID != null) { // add the job status - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); - HashMap JobStatusMap = (HashMap) session + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + HttpSession session=httpRequest.getSession(); + + @SuppressWarnings("unchecked") + HashMap JobStatusMap = (HashMap) session .getAttribute("JobStatusList"); JobStatusMap.put(jobID, status); session.setAttribute("JobStatusList", JobStatusMap); @@ -1430,8 +1446,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // remove job with the related status private synchronized void removeJobStatus(String jobID) throws Exception { - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + HttpSession session=httpRequest.getSession(); + + @SuppressWarnings("unchecked") HashMap JobStatusMap = (HashMap) session .getAttribute("JobStatusList"); String status = JobStatusMap.get(jobID); @@ -1443,8 +1461,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // get job status private synchronized String getJobStatus(String jobID) throws Exception { - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + HttpSession session=httpRequest.getSession(); + + @SuppressWarnings("unchecked") HashMap JobStatusMap = (HashMap) session .getAttribute("JobStatusList"); String status = JobStatusMap.get(jobID); @@ -1456,10 +1476,14 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements ComputationId computationId) throws Exception { if (jobID != null) { // add the computation in the map - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + HttpSession session=httpRequest.getSession(); + + + @SuppressWarnings("unchecked") HashMap computationIDMap = (HashMap) session .getAttribute("ComputationIDList"); + computationIDMap.put(jobID, computationId); session.setAttribute("ComputationIDList", computationIDMap); } @@ -1470,8 +1494,11 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements if (jobID != null) { // System.out.println("remove jobID " + job); // add the computation in the map - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + HttpSession session=httpRequest.getSession(); + + + @SuppressWarnings("unchecked") HashMap computationIDMap = (HashMap) session .getAttribute("ComputationIDList"); ComputationId computationId = computationIDMap.get(jobID); @@ -1487,8 +1514,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements private synchronized boolean checkJob(String jobID) throws Exception { boolean isContained = false; if (jobID != null) { - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + HttpSession session=httpRequest.getSession(); + + @SuppressWarnings("unchecked") HashMap computationIDMap = (HashMap) session .getAttribute("ComputationIDList"); if (computationIDMap.containsKey(jobID)) { @@ -1503,9 +1532,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements private synchronized void updateListSubmitQueryUIDCachedData(String UID, Boolean value) throws Exception { - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); - + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + HttpSession session=httpRequest.getSession(); + + @SuppressWarnings("unchecked") HashMap listSubmitQueryUIDCachedData = (HashMap) session .getAttribute("listSubmitQueryUIDCachedData"); listSubmitQueryUIDCachedData.put(UID, value); @@ -1516,9 +1546,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements private synchronized Boolean checkSubmitQueryUIDCachedData(String UID) throws Exception { - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); - + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + HttpSession session=httpRequest.getSession(); + + @SuppressWarnings("unchecked") HashMap listSubmitQueryUIDCachedData = (HashMap) session .getAttribute("listSubmitQueryUIDCachedData"); return listSubmitQueryUIDCachedData.get(UID); @@ -1526,9 +1557,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements private synchronized void removeSubmitQueryUIDCachedData(String UID) throws Exception { - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); - + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + HttpSession session=httpRequest.getSession(); + + @SuppressWarnings("unchecked") HashMap listSubmitQueryUIDCachedData = (HashMap) session .getAttribute("listSubmitQueryUIDCachedData"); @@ -1541,9 +1573,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements private synchronized void removeKeySubmitQueryResult(String UID) throws Exception { - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); - + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + HttpSession session=httpRequest.getSession(); + + @SuppressWarnings("unchecked") HashMap listKeySubmitQueryResult = (HashMap) session .getAttribute("listKeySubmitQueryResult"); @@ -1556,9 +1589,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements private synchronized void updateListKeySubmitQueryResult(String UID, String value) throws Exception { - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); - + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + HttpSession session=httpRequest.getSession(); + + @SuppressWarnings("unchecked") HashMap listKeySubmitQueryResult = (HashMap) session .getAttribute("listKeySubmitQueryResult"); listKeySubmitQueryResult.put(UID, value); @@ -1569,9 +1603,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements private synchronized String getKeySubmitQueryResult(String UID) throws Exception { - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); - + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + HttpSession session=httpRequest.getSession(); + + @SuppressWarnings("unchecked") HashMap listKeySubmitQueryResult = (HashMap) session .getAttribute("listKeySubmitQueryResult"); return listKeySubmitQueryResult.get(UID); @@ -1579,9 +1614,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements private synchronized List getSubmitQueryResult(String UID) throws Exception { - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); - + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + HttpSession session=httpRequest.getSession(); + + @SuppressWarnings("unchecked") HashMap> listSubmitQueryResult = (HashMap>) session .getAttribute("listSubmitQueryResult"); return listSubmitQueryResult.get(UID); @@ -1589,9 +1625,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements private synchronized void updateListSubmitQueryResult(String UID, List value) throws Exception { - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); - + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + HttpSession session=httpRequest.getSession(); + + @SuppressWarnings("unchecked") HashMap> listSubmitQueryResult = (HashMap>) session .getAttribute("listSubmitQueryResult"); listSubmitQueryResult.put(UID, value); @@ -1601,9 +1638,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements private synchronized void removeSubmitQueryResult(String UID) throws Exception { - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); - + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + HttpSession session=httpRequest.getSession(); + + @SuppressWarnings("unchecked") HashMap> listSubmitQueryResult = (HashMap>) session .getAttribute("listSubmitQueryResult"); @@ -1764,16 +1802,20 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements } + /* private InputStream getStorageClientInputStream(String url) throws Exception { - URL u = new URL(null, url, new URLStreamHandler() { - @Override - protected URLConnection openConnection(URL u) throws IOException { - return new SMPURLConnection(u); - } - }); + //URL u = new URL(null, url, new URLStreamHandler() { + // @Override + // protected URLConnection openConnection(URL u) throws IOException { + // return new SMPURLConnection(u); + // } + //}); + + URL u=new URL(url); + u.openConnection().getInputStream(); return u.openConnection().getInputStream(); - } + }*/ /* * private StatisticalManagerFactory getFactory(String scope) { // @@ -1799,10 +1841,14 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements try { logger.info("dbmanager-> Remove Computation Request received. Starting to manage the request."); - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); - // get scope - String scope = session.getScope(); + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + @SuppressWarnings("unused") + ServiceCredentials serviceCredentials = SessionUtil + .getServiceCredentials(httpRequest); + + //HttpSession session=httpRequest.getSession(); + // get scope + //String scope = serviceCredentials.getScope(); Boolean isComputationRemoved = false; // verify if this uid submitQuery request uses data in cache @@ -1878,9 +1924,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements @Override public void refreshDataOnServer(String submitQueryUID) throws Exception { - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); - + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + @SuppressWarnings("unused") + ServiceCredentials serviceCredentials = SessionUtil + .getServiceCredentials(httpRequest); + + if ((submitQueryUID != null) && (!submitQueryUID.equals(""))) { removeKeySubmitQueryResult(submitQueryUID); removeSubmitQueryResult(submitQueryUID); @@ -2154,10 +2203,13 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements try { - ASLSession session = SessionUtil.getASLSession(this - .getThreadLocalRequest().getSession()); + HttpServletRequest httpRequest = this.getThreadLocalRequest(); + ServiceCredentials serviceCredentials = SessionUtil + .getServiceCredentials(httpRequest); + + // get scope - String scope = session.getScope(); + String scope = serviceCredentials.getScope(); // call the method related to the element selected String resourceName = ""; @@ -2672,7 +2724,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // get data from cache // check if data exist considering as key the input parameters // String key = inputParameters.get(0).getDefaultValue(); - String key = scope + Constants.RESOURCESLIST; + String key = scope + + Constants.RESOURCESLIST; net.sf.ehcache.Element dataFromCache = getDataFromCache(key); Object value = null; @@ -2698,7 +2751,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements ComputationOutput outputData = new ComputationOutput(); // computationId ComputationId computationId = startComputation(algorithmId, - inputParameters, outputData, scope, null); + inputParameters, outputData, + scope, null); // print check // retrieve data diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/server/util/ServiceCredentials.java b/src/main/java/org/gcube/portlets/user/databasesmanager/server/util/ServiceCredentials.java new file mode 100644 index 0000000..7bc2515 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/server/util/ServiceCredentials.java @@ -0,0 +1,141 @@ +package org.gcube.portlets.user.databasesmanager.server.util; + +import java.io.Serializable; + +/** + * + * @author Giancarlo Panichi email: g.panichi@isti.cnr.it + * + */ +public class ServiceCredentials implements Serializable { + + private static final long serialVersionUID = 3560918948310315680L; + private String userName; + private String fullName; + private String name; + private String lastName; + private String email; + private String scope; + private String groupId; + private String groupName; + private String userAvatarURL; + private String token; + + public ServiceCredentials() { + super(); + } + + public ServiceCredentials(String userName, String scope, String token) { + super(); + this.userName = userName; + this.scope = scope; + this.token = token; + } + + public ServiceCredentials(String userName, String fullName, String name, + String lastName, String email, String scope, String groupId, + String groupName, String userAvatarURL, String token) { + super(); + this.userName = userName; + this.fullName = fullName; + this.name = name; + this.lastName = lastName; + this.email = email; + this.scope = scope; + this.groupId = groupId; + this.groupName = groupName; + this.userAvatarURL = userAvatarURL; + this.token = token; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getFullName() { + return fullName; + } + + public void setFullName(String fullName) { + this.fullName = fullName; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getGroupName() { + return groupName; + } + + public void setGroupName(String groupName) { + this.groupName = groupName; + } + + public String getUserAvatarURL() { + return userAvatarURL; + } + + public void setUserAvatarURL(String userAvatarURL) { + this.userAvatarURL = userAvatarURL; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + @Override + public String toString() { + return "ServiceCredentials [userName=" + userName + ", fullName=" + + fullName + ", name=" + name + ", lastName=" + lastName + + ", email=" + email + ", scope=" + scope + ", groupId=" + + groupId + ", groupName=" + groupName + ", userAvatarURL=" + + userAvatarURL + ", token=" + token + "]"; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/server/util/SessionUtil.java b/src/main/java/org/gcube/portlets/user/databasesmanager/server/util/SessionUtil.java index d8f43ba..64cdba4 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/server/util/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/server/util/SessionUtil.java @@ -1,72 +1,178 @@ package org.gcube.portlets.user.databasesmanager.server.util; -import java.util.HashMap; - -import javax.servlet.http.HttpSession; +import javax.servlet.http.HttpServletRequest; import org.apache.log4j.Logger; -import org.gcube.application.framework.core.session.ASLSession; -import org.gcube.application.framework.core.session.SessionManager; -import org.gcube.data.analysis.dataminermanagercl.server.DataMinerService; -import org.gcube.data.analysis.dataminermanagercl.server.dmservice.SClient; -import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; +import org.gcube.common.authorization.library.provider.SecurityTokenProvider; +import org.gcube.common.portal.PortalContext; +import org.gcube.common.scope.api.ScopeProvider; import org.gcube.portlets.user.databasesmanager.shared.Constants; -import org.gcube.portlets.user.databasesmanager.shared.SessionExpiredException; +import org.gcube.portlets.user.databasesmanager.shared.exception.ServiceException; +import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; +import org.gcube.vomanagement.usermanagement.model.GCubeGroup; +import org.gcube.vomanagement.usermanagement.model.GCubeUser; public class SessionUtil { - private static Logger logger = Logger.getLogger(SessionUtil.class); - //public static final String TEST_USER = "test.user"; - //public static final String USER = "database.manager"; - + private static final Logger logger = Logger.getLogger(SessionUtil.class); - public static ASLSession getASLSession(HttpSession httpSession) - throws Exception { - String username = (String) httpSession - .getAttribute(ScopeHelper.USERNAME_ATTRIBUTE); - ASLSession aslSession; - if (username == null) { - if (Constants.DEBUG_MODE) { - logger.info("no user found in session, use test user"); - - // Remove comment for Test - username = Constants.DEFAULT_USER; - String scope = Constants.DEFAULT_SCOPE; - - httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, - username); - aslSession = SessionManager.getInstance().getASLSession( - httpSession.getId(), username); - aslSession.setScope(scope); - } else { - logger.info("No user found in session"); - throw new SessionExpiredException(); - - } - } else { - aslSession = SessionManager.getInstance().getASLSession( - httpSession.getId(), username); - - } - - logger.info("SessionUtil: aslSession " + aslSession.getUsername() + " " - + aslSession.getScope()); - - return aslSession; + /** + * + * @param httpServletRequest + * @return + * @throws TDGWTServiceException + */ + public static ServiceCredentials getServiceCredentials( + HttpServletRequest httpServletRequest) throws org.gcube.portlets.user.databasesmanager.shared.exception.ServiceException { + return getServiceCredentials(httpServletRequest, null); } - public static String getToken(ASLSession aslSession) throws Exception { - String token = null; - if (Constants.DEBUG_MODE) { - token = Constants.DEFAULT_TOKEN; - } else { - token = aslSession.getSecurityToken(); - } - logger.info("received token: " + token); - return token; + /** + * + * @param httpServletRequest + * @param scopeGroupId + * @return + * @throws TDGWTServiceException + */ + public static ServiceCredentials getServiceCredentials( + HttpServletRequest httpServletRequest, String scopeGroupId) + throws ServiceException { - } + ServiceCredentials sCredentials = null; + String userName = null; + String scope = null; + String token = null; + String groupId = null; + String groupName = null; + + if (Constants.DEBUG_MODE) { + logger.debug("No credential found in session, use test user!"); + /* + * InfoLocale infoLocale = getInfoLocale(httpServletRequest, null); + * Locale locale = new Locale(infoLocale.getLanguage()); + * + * ResourceBundle messages = ResourceBundle.getBundle( + * StatAlgoImporterServiceMessagesConstants.TDGWTServiceMessages, + * locale); + */ + userName = Constants.DEFAULT_USER; + scope = Constants.DEFAULT_SCOPE; + token = Constants.DEFAULT_TOKEN; + + logger.debug("Set SecurityToken: " + token); + SecurityTokenProvider.instance.set(token); + logger.debug("Set ScopeProvider: " + scope); + ScopeProvider.instance.set(scope); + + sCredentials = new ServiceCredentials(userName, scope, token); + + } else { + logger.debug("Retrieving credential in session!"); + PortalContext pContext = PortalContext.getConfiguration(); + boolean hasScopeGroupId = false; + + if (scopeGroupId != null && !scopeGroupId.isEmpty()) { + hasScopeGroupId = true; + + } else { + hasScopeGroupId = false; + } + + if (hasScopeGroupId) { + scope = pContext.getCurrentScope(scopeGroupId); + } else { + scope = pContext.getCurrentScope(httpServletRequest); + } + + if (scope == null || scope.isEmpty()) { + String error = "Error retrieving scope: " + scope; + logger.error(error); + throw new ServiceException(error); + } + + GCubeUser gCubeUser = pContext.getCurrentUser(httpServletRequest); + + if (gCubeUser == null) { + String error = "Error retrieving gCubeUser in scope " + scope + + ": " + gCubeUser; + logger.error(error); + throw new ServiceException(error); + } + + userName = gCubeUser.getUsername(); + + if (userName == null || userName.isEmpty()) { + String error = "Error retrieving username in scope " + scope + + ": " + userName; + logger.error(error); + throw new ServiceException(error); + } + + token = pContext.getCurrentUserToken(scope, userName); + + if (token == null || token.isEmpty()) { + String error = "Error retrieving token for " + userName + + " in " + scope + ": " + token; + logger.error(error); + throw new ServiceException(error); + } + + String name = gCubeUser.getFirstName(); + String lastName = gCubeUser.getLastName(); + String fullName = gCubeUser.getFullname(); + + String userAvatarURL = gCubeUser.getUserAvatarURL(); + + String email = gCubeUser.getEmail(); + + if (hasScopeGroupId) { + logger.debug("Set SecurityToken: " + token); + SecurityTokenProvider.instance.set(token); + logger.debug("Set ScopeProvider: " + scope); + ScopeProvider.instance.set(scope); + + groupId = scopeGroupId; + + long gId; + + try { + gId = Long.parseLong(scopeGroupId); + } catch (Throwable e) { + String error = "Error retrieving groupId: " + scopeGroupId; + logger.error(error, e); + throw new ServiceException(error); + } + + GCubeGroup group; + try { + group = new LiferayGroupManager().getGroup(gId); + } catch (Throwable e) { + String error = "Error retrieving group: " + groupName; + logger.error(error); + throw new ServiceException(error); + } + + groupName = group.getGroupName(); + + } else { + + groupId = String.valueOf(pContext + .getCurrentGroupId(httpServletRequest)); + + groupName = pContext.getCurrentGroupName(httpServletRequest); + + } + + sCredentials = new ServiceCredentials(userName, fullName, name, + lastName, email, scope, groupId, groupName, userAvatarURL, + token); + } + + logger.debug("ServiceCredentials: " + sCredentials); + + return sCredentials; + } } diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/shared/AlgorithmsName.java b/src/main/java/org/gcube/portlets/user/databasesmanager/shared/AlgorithmsName.java index f49b822..e6cf415 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/shared/AlgorithmsName.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/shared/AlgorithmsName.java @@ -44,8 +44,8 @@ public enum AlgorithmsName { /** * - * @param fullPackageName - * @return + * @param fullPackageName full package name + * @return AlgorithmsName */ public static AlgorithmsName getFromFullPackageName(String fullPackageName) { if (fullPackageName == null || fullPackageName.isEmpty()) diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/shared/exception/ServiceException.java b/src/main/java/org/gcube/portlets/user/databasesmanager/shared/exception/ServiceException.java new file mode 100644 index 0000000..501b8e9 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/shared/exception/ServiceException.java @@ -0,0 +1,39 @@ +/** + * + */ +package org.gcube.portlets.user.databasesmanager.shared.exception; + +/** + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public class ServiceException extends Exception { + + + private static final long serialVersionUID = -2255657546267656458L; + + + /** + * + */ + public ServiceException() { + super(); + } + + /** + * + * @param message error message + */ + public ServiceException(String message) { + super(message); + } + + + public ServiceException(String message,Throwable t) { + super(message,t); + } + + +} diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index b4890fc..51cd221 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -21,11 +21,6 @@ - - checkServlet - org.gcube.portlets.widgets.sessionchecker.server.SessionCheckerServiceImpl - - dbmanagerservlet @@ -41,11 +36,6 @@ jUnitHostImpl /databasesmanager/junithost/* - - - checkServlet - /databasesmanager/checksession -