ref 8432:TDM - DatabasesManager - Support Java 8 compatibility

https://support.d4science.org/issues/8432

Updated to support Java 8 compatibility

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@148376 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2017-05-09 09:11:08 +00:00
parent 87ca61215a
commit e1e322c6c6
15 changed files with 553 additions and 197 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/databases-manager-portlet-1.7.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/databases-manager-portlet-1.8.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
@ -20,10 +20,10 @@
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/databases-manager-portlet-1.7.0-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/databases-manager-portlet-1.8.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

View File

@ -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

View File

@ -4,6 +4,9 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="data-miner-manager-cl-1.2.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/data-miner-manager-cl/data-miner-manager-cl">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>
<property name="context-root" value="databases-manager-portlet"/>
</wb-module>

View File

@ -3,5 +3,5 @@
<fixed facet="wst.jsdt.web"/>
<installed facet="jst.web" version="3.0"/>
<installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="java" version="1.7"/>
<installed facet="java" version="1.8"/>
</faceted-project>

View File

@ -1,4 +1,8 @@
<ReleaseNotes>
<Changeset component="org.gcube.portlets.user.databases-manager-portlet.1-8-0"
date="2017-06-12">
<Change>Support Java 8 compatibility [ticket #8432]</Change>
</Changeset>
<Changeset component="org.gcube.portlets.user.databases-manager-portlet.1-7-0"
date="2017-02-15">
<Change>Fixed groupId</Change>

23
pom.xml
View File

@ -15,9 +15,10 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>databases-manager-portlet</artifactId>
<packaging>war</packaging>
<version>1.7.0-SNAPSHOT</version>
<version>1.8.0-SNAPSHOT</version>
<name>DatabasesResourceManagerPortlet</name>
<description>Databases Resource Manager Portlet</description>
<scm>
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet</url>
@ -40,6 +41,9 @@
<distroDirectory>distro</distroDirectory>
<configDirectory>config</configDirectory>
<!-- Java -->
<maven.compiler.source>1.7</maven.compiler.source>
<!-- GWT configuration -->
<gwtVersion>2.6.1</gwtVersion>
<gwtLogVersion>3.3.2</gwtLogVersion>
@ -99,13 +103,9 @@
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
<groupId>org.gcube.common.portal</groupId>
<artifactId>portal-manager</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
@ -114,6 +114,13 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>client-context-library</artifactId>
<version>[1.0.0-SNAPSHOT,)</version>
<scope>compile</scope>
</dependency>
<!-- Authorization -->
<dependency>

View File

@ -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);

View File

@ -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:
* <ul>
* <li>uuid(8, 2) returns "01001010" (8 character ID, base=2)
* <li>uuid(8, 10) returns "47473046" (8 character ID, base=10)
* <li>uuid(8, 16) returns "098F4D35" (8 character ID, base=16)
* </ul>
*
* 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];

View File

@ -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);
}

View File

@ -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<String, ComputationId> computationIDMap = new HashMap<String, ComputationId>();
@ -310,16 +309,15 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
public List<FileModel> 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<Parameter> inputParameters = new ArrayList<Parameter>();
@ -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<Parameter> inputParameters = new ArrayList<Parameter>();
@ -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<Parameter> inputParameters = new ArrayList<Parameter>();
@ -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<Parameter> inputParameters = new ArrayList<Parameter>();
@ -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<String, String> JobStatusMap = (HashMap<String, String>) session
HttpServletRequest httpRequest = this.getThreadLocalRequest();
HttpSession session=httpRequest.getSession();
@SuppressWarnings("unchecked")
HashMap<String, String> JobStatusMap = (HashMap<String, String>) 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<String, String> JobStatusMap = (HashMap<String, String>) 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<String, String> JobStatusMap = (HashMap<String, String>) 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<String, ComputationId> computationIDMap = (HashMap<String, ComputationId>) 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<String, ComputationId> computationIDMap = (HashMap<String, ComputationId>) 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<String, ComputationId> computationIDMap = (HashMap<String, ComputationId>) 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<String, Boolean> listSubmitQueryUIDCachedData = (HashMap<String, Boolean>) 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<String, Boolean> listSubmitQueryUIDCachedData = (HashMap<String, Boolean>) 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<String, Boolean> listSubmitQueryUIDCachedData = (HashMap<String, Boolean>) 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<String, String> listKeySubmitQueryResult = (HashMap<String, String>) 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<String, String> listKeySubmitQueryResult = (HashMap<String, String>) 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<String, String> listKeySubmitQueryResult = (HashMap<String, String>) session
.getAttribute("listKeySubmitQueryResult");
return listKeySubmitQueryResult.get(UID);
@ -1579,9 +1614,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
private synchronized List<Result> getSubmitQueryResult(String UID)
throws Exception {
ASLSession session = SessionUtil.getASLSession(this
.getThreadLocalRequest().getSession());
HttpServletRequest httpRequest = this.getThreadLocalRequest();
HttpSession session=httpRequest.getSession();
@SuppressWarnings("unchecked")
HashMap<String, List<Result>> listSubmitQueryResult = (HashMap<String, List<Result>>) session
.getAttribute("listSubmitQueryResult");
return listSubmitQueryResult.get(UID);
@ -1589,9 +1625,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
private synchronized void updateListSubmitQueryResult(String UID,
List<Result> value) throws Exception {
ASLSession session = SessionUtil.getASLSession(this
.getThreadLocalRequest().getSession());
HttpServletRequest httpRequest = this.getThreadLocalRequest();
HttpSession session=httpRequest.getSession();
@SuppressWarnings("unchecked")
HashMap<String, List<Result>> listSubmitQueryResult = (HashMap<String, List<Result>>) 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<String, List<Result>> listSubmitQueryResult = (HashMap<String, List<Result>>) 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

View File

@ -0,0 +1,141 @@
package org.gcube.portlets.user.databasesmanager.server.util;
import java.io.Serializable;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
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 + "]";
}
}

View File

@ -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;
}
}

View File

@ -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())

View File

@ -0,0 +1,39 @@
/**
*
*/
package org.gcube.portlets.user.databasesmanager.shared.exception;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
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);
}
}

View File

@ -21,11 +21,6 @@
<!-- <servlet-class>com.google.gwt.junit.server.JUnitHostImpl</servlet-class> -->
<!-- </servlet> -->
<servlet>
<servlet-name>checkServlet</servlet-name>
<servlet-class>org.gcube.portlets.widgets.sessionchecker.server.SessionCheckerServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dbmanagerservlet</servlet-name>
@ -41,11 +36,6 @@
<servlet-name>jUnitHostImpl</servlet-name>
<url-pattern>/databasesmanager/junithost/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>checkServlet</servlet-name>
<url-pattern>/databasesmanager/checksession</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->