refs:3772: SAI - Create a github project importer

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

Updated SAI to liferay 6.2

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/statistical-algorithms-importer@129242 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2016-06-21 16:42:08 +00:00
parent 0dc91f41e0
commit cd983e2180
11 changed files with 384 additions and 269 deletions

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" output="target/statistical-algorithms-importer-1.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/java"> <classpathentry kind="src" output="target/statistical-algorithms-importer-1.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/statistical-algorithms-importer-1.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources"> <classpathentry excluding="**" kind="src" output="target/statistical-algorithms-importer-1.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
@ -45,5 +45,5 @@
</classpathentry> </classpathentry>
<classpathentry kind="lib" path="/home/giancarlo/gwt/gwt-2.6.1/validation-api-1.0.0.GA.jar" sourcepath="/home/giancarlo/gwt/gwt-2.6.1/validation-api-1.0.0.GA-sources.jar"/> <classpathentry kind="lib" path="/home/giancarlo/gwt/gwt-2.6.1/validation-api-1.0.0.GA.jar" sourcepath="/home/giancarlo/gwt/gwt-2.6.1/validation-api-1.0.0.GA-sources.jar"/>
<classpathentry kind="lib" path="/home/giancarlo/gwt/gwt-2.6.1/validation-api-1.0.0.GA-sources.jar"/> <classpathentry kind="lib" path="/home/giancarlo/gwt/gwt-2.6.1/validation-api-1.0.0.GA-sources.jar"/>
<classpathentry kind="output" path="target/statistical-algorithms-importer-1.1.0-SNAPSHOT/WEB-INF/classes"/> <classpathentry kind="output" path="target/statistical-algorithms-importer-1.2.0-SNAPSHOT/WEB-INF/classes"/>
</classpath> </classpath>

177
pom.xml
View File

@ -13,7 +13,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.portlets.user</groupId> <groupId>org.gcube.portlets.user</groupId>
<artifactId>statistical-algorithms-importer</artifactId> <artifactId>statistical-algorithms-importer</artifactId>
<version>1.1.0-SNAPSHOT</version> <version>1.2.0-SNAPSHOT</version>
<packaging>war</packaging> <packaging>war</packaging>
@ -60,12 +60,7 @@
<profile> <profile>
<id>localRun</id> <id>localRun</id>
<dependencies> <dependencies>
<!-- Xerces --> <!-- Logger -->
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.11.0</version>
</dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
@ -76,24 +71,55 @@
<artifactId>slf4j-log4j12</artifactId> <artifactId>slf4j-log4j12</artifactId>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xerces</artifactId>
<version>2.4.0</version>
</dependency>
<!-- Storage -->
<dependency>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-core</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-wrapper</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Home Library -->
<dependency> <dependency>
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>home-library</artifactId> <artifactId>home-library</artifactId>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>home-library-jcr</artifactId> <artifactId>home-library-jcr</artifactId>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>home-library-model</artifactId> <artifactId>home-library-model</artifactId>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<!-- Authorization -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-authorization</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
<scope>runtime</scope>
</dependency>
<dependency> <dependency>
<groupId>com.thoughtworks.xstream</groupId> <groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId> <artifactId>xstream</artifactId>
@ -120,11 +146,7 @@
<artifactId>gwt-servlet</artifactId> <artifactId>gwt-servlet</artifactId>
<version>${gwtVersion}</version> <version>${gwtVersion}</version>
</dependency> </dependency>
<!-- <dependency> <groupId>com.google.gwt</groupId> <artifactId>gwt-dev</artifactId>
<version>${gwtVersion}</version> </dependency> -->
<!-- GXT 3 --> <!-- GXT 3 -->
<dependency> <dependency>
@ -146,23 +168,15 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<!-- GXT-Theme-Neptune -->
<!-- <dependency> <groupId>com.sencha.gxt</groupId> <artifactId>gxt-theme-neptune</artifactId>
<version>${gxtVersion}</version> </dependency> -->
<!-- Portlet --> <!-- Portlet -->
<dependency> <dependency>
<groupId>javax.portlet</groupId> <groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId> <artifactId>portlet-api</artifactId>
<scope>provided</scope>
</dependency> </dependency>
<!-- PORTAL --> <!-- PORTAL -->
<dependency> <dependency>
<groupId>org.gcube.core</groupId> <groupId>org.gcube.core</groupId>
@ -178,14 +192,78 @@
<dependency> <dependency>
<groupId>org.gcube.applicationsupportlayer</groupId> <groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId> <artifactId>aslcore</artifactId>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.applicationsupportlayer</groupId> <groupId>org.gcube.dvos</groupId>
<artifactId>accesslogger</artifactId> <artifactId>usermanagement-core</artifactId>
<scope>provided</scope>
</dependency> </dependency>
<!-- Authorization -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-authorization</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
<scope>provided</scope>
</dependency>
<!-- GCube Widgets -->
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-widgets</artifactId>
<scope>compile</scope>
</dependency>
<!-- Session Checker -->
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>session-checker</artifactId>
<version>[0.0.0-SNAPSHOT,1.0.0-SNAPSHOT)</version>
</dependency>
<!-- Storage -->
<dependency>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-wrapper</artifactId>
<scope>provided</scope>
</dependency>
<!-- Home Library -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library-jcr</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library-model</artifactId>
<scope>provided</scope>
</dependency>
<!-- Social --> <!-- Social -->
<!-- <dependency> <groupId>org.gcube.portal</groupId> <artifactId>social-networking-library</artifactId> <!-- <dependency> <groupId>org.gcube.portal</groupId> <artifactId>social-networking-library</artifactId>
<scope>provided</scope> </dependency> --> <scope>provided</scope> </dependency> -->
@ -204,27 +282,6 @@
</dependency> </dependency>
<!-- GCube Widgets -->
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-widgets</artifactId>
<scope>compile</scope>
</dependency>
<!-- WSLT dependencies <dependency> <groupId>org.gcube.portlets.widgets</groupId>
<artifactId>workspace-light-tree</artifactId> <version>[2.13.1-SNAPSHOT,
3.0.0-SNAPSHOT)</version> </dependency> <dependency> <groupId>org.gcube.common</groupId>
<artifactId>home-library</artifactId> <version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<scope>provided</scope> </dependency> -->
<!-- Session Checker -->
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>session-checker</artifactId>
<version>[0.2.0-SNAPSHOT,1.0.0-SNAPSHOT)</version>
</dependency>
<!-- Apache Common Library --> <!-- Apache Common Library -->
<dependency> <dependency>
<groupId>commons-io</groupId> <groupId>commons-io</groupId>
@ -270,28 +327,6 @@
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version> <version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency> </dependency>
<!-- Home Library -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library-jcr</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library-model</artifactId>
<scope>provided</scope>
</dependency>
<!-- Uri Resolver Manager -->
<!-- <dependency> <groupId>org.gcube.portlets.user</groupId> <artifactId>uri-resolver-manager</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version> </dependency> -->
<!-- 52n-wps-client --> <!-- 52n-wps-client -->
<dependency> <dependency>
@ -339,12 +374,6 @@
<artifactId>slf4j-log4j12</artifactId> <artifactId>slf4j-log4j12</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId>
<scope>provided</scope> </dependency> -->
<!-- <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId>
<version>1.0.1</version> <scope>runtime</scope> </dependency> -->
<!-- JUnit TEST --> <!-- JUnit TEST -->

View File

@ -18,85 +18,89 @@ import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException; import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.CodeFileUploadSession; import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.CodeFileUploadSession;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.FileUploadListener; import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.FileUploadListener;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.FileUtil; import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.FileUtil;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.Constants; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.Constants;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterSessionExpiredException; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.file.FileUploadMonitor; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.file.FileUploadMonitor;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.file.FileUploadState; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.file.FileUploadState;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.allen_sauer.gwt.log.client.Log; import com.allen_sauer.gwt.log.client.Log;
/** /**
* *
* @author "Giancarlo Panichi" * @author "Giancarlo Panichi" <a
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a> * href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
* *
*/ */
public class LocalUploadServlet extends HttpServlet { public class LocalUploadServlet extends HttpServlet {
protected static Logger logger = LoggerFactory.getLogger(LocalUploadServlet.class); protected static Logger logger = LoggerFactory
.getLogger(LocalUploadServlet.class);
/** /**
* *
*/ */
private static final long serialVersionUID = -4197748678713054285L; private static final long serialVersionUID = -4197748678713054285L;
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
logger.trace("Post"); logger.trace("Post");
HttpSession session = request.getSession(); HttpSession session = request.getSession();
if(session==null){ if (session == null) {
logger.error("Error getting the upload session, no session valid found: "+session); logger.error("Error getting the upload session, no session valid found: "
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "ERROR-Error getting the user session, no session found"+session); + session);
return ; response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"ERROR-Error getting the user session, no session found"
+ session);
return;
} }
logger.info("Code Import session id: "+session.getId()); logger.info("Code Import session id: " + session.getId());
CodeFileUploadSession fileUploadSession=new CodeFileUploadSession();
FileUploadMonitor fileUploadMonitor=new FileUploadMonitor();
fileUploadSession.setId(session.getId());
fileUploadSession.setFileUploadState(FileUploadState.STARTED);
//fileUploadSession.setCsvImportMonitor(csvImportMonitor);
SessionUtil.setFileUploadMonitor(session, fileUploadMonitor);
try { try {
SessionUtil.setCodeFileUploadSession(session,fileUploadSession); ASLSession aslSession = SessionUtil.getASLSession(session);
} catch (StatAlgoImporterSessionExpiredException e) { String token=SessionUtil.getToken(aslSession);
logger.debug("UserToken: "+token);
ScopeProvider.instance.set(aslSession.getScope().toString());
} catch (StatAlgoImporterServiceException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw new ServletException(e.getLocalizedMessage());
}
CodeFileUploadSession fileUploadSession = new CodeFileUploadSession();
FileUploadMonitor fileUploadMonitor = new FileUploadMonitor();
fileUploadSession.setId(session.getId());
fileUploadSession.setFileUploadState(FileUploadState.STARTED);
// fileUploadSession.setCsvImportMonitor(csvImportMonitor);
SessionUtil.setFileUploadMonitor(session, fileUploadMonitor);
try {
SessionUtil.setCodeFileUploadSession(session, fileUploadSession);
} catch (StatAlgoImporterServiceException e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage());
e.printStackTrace(); e.printStackTrace();
throw new ServletException(e.getLocalizedMessage()); throw new ServletException(e.getLocalizedMessage());
} }
FileItemFactory factory = new DiskFileItemFactory(); FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory); ServletFileUpload upload = new ServletFileUpload(factory);
FileUploadListener uploadListener = new FileUploadListener(
FileUploadListener uploadListener = new FileUploadListener(fileUploadMonitor); fileUploadMonitor);
upload.setProgressListener(uploadListener); upload.setProgressListener(uploadListener);
FileItem uploadItem = null; FileItem uploadItem = null;
Log.info("Start upload file "); Log.info("Start upload file ");
try { try {
@ -104,78 +108,90 @@ public class LocalUploadServlet extends HttpServlet {
Iterator it = items.iterator(); Iterator it = items.iterator();
while (it.hasNext()) { while (it.hasNext()) {
FileItem item = (FileItem) it.next(); FileItem item = (FileItem) it.next();
if (!item.isFormField() && Constants.FILE_UPLOADED_FIELD.equals(item.getFieldName())) { if (!item.isFormField()
&& Constants.FILE_UPLOADED_FIELD.equals(item
.getFieldName())) {
uploadItem = item; uploadItem = item;
} }
} }
} catch (FileUploadException e) { } catch (FileUploadException e) {
FileUploadMonitor fum=SessionUtil.getFileUploadMonitor(session); FileUploadMonitor fum = SessionUtil.getFileUploadMonitor(session);
fum.setFailed("An error occured elaborating the HTTP request", FileUtil.exceptionDetailMessage(e)); fum.setFailed("An error occured elaborating the HTTP request",
FileUtil.exceptionDetailMessage(e));
SessionUtil.setFileUploadMonitor(session, fum); SessionUtil.setFileUploadMonitor(session, fum);
fileUploadSession.setFileUploadState(FileUploadState.FAILED); fileUploadSession.setFileUploadState(FileUploadState.FAILED);
try { try {
SessionUtil.setCodeFileUploadSession(session, fileUploadSession); SessionUtil
} catch (StatAlgoImporterSessionExpiredException e1) { .setCodeFileUploadSession(session, fileUploadSession);
} catch (StatAlgoImporterServiceException e1) {
logger.error(e1.getLocalizedMessage()); logger.error(e1.getLocalizedMessage());
e1.printStackTrace(); e1.printStackTrace();
throw new ServletException(e1.getLocalizedMessage()); throw new ServletException(e1.getLocalizedMessage());
} }
logger.error("Error processing request in upload servlet", e); logger.error("Error processing request in upload servlet", e);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "ERROR-Error during request processing: "+e.getMessage()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"ERROR-Error during request processing: " + e.getMessage());
return; return;
} }
if (uploadItem == null) { if (uploadItem == null) {
FileUploadMonitor fum=SessionUtil.getFileUploadMonitor(session); FileUploadMonitor fum = SessionUtil.getFileUploadMonitor(session);
fum.setFailed("An error occured elaborating the HTTP request: No file found", "Upload request without file"); fum.setFailed(
"An error occured elaborating the HTTP request: No file found",
"Upload request without file");
SessionUtil.setFileUploadMonitor(session, fum); SessionUtil.setFileUploadMonitor(session, fum);
fileUploadSession.setFileUploadState(FileUploadState.FAILED); fileUploadSession.setFileUploadState(FileUploadState.FAILED);
try { try {
SessionUtil.setCodeFileUploadSession(session, fileUploadSession); SessionUtil
} catch (StatAlgoImporterSessionExpiredException e) { .setCodeFileUploadSession(session, fileUploadSession);
} catch (StatAlgoImporterServiceException e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage());
e.printStackTrace(); e.printStackTrace();
throw new ServletException(e.getLocalizedMessage()); throw new ServletException(e.getLocalizedMessage());
} }
logger.error("Error processing request in upload servlet: No file to upload"); logger.error("Error processing request in upload servlet: No file to upload");
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "No file to upload"); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"No file to upload");
return; return;
} }
String contentType = uploadItem.getContentType(); String contentType = uploadItem.getContentType();
logger.trace("ContentType: "+contentType); logger.trace("ContentType: " + contentType);
try { try {
FileUtil.setImportCodeFile(fileUploadSession, uploadItem.getInputStream(), uploadItem.getName(), contentType); FileUtil.setImportCodeFile(fileUploadSession,
uploadItem.getInputStream(), uploadItem.getName(),
contentType);
} catch (Exception e) { } catch (Exception e) {
FileUploadMonitor fum=SessionUtil.getFileUploadMonitor(session); FileUploadMonitor fum = SessionUtil.getFileUploadMonitor(session);
fum.setFailed("An error occured elaborating the file", FileUtil.exceptionDetailMessage(e)); fum.setFailed("An error occured elaborating the file",
FileUtil.exceptionDetailMessage(e));
SessionUtil.setFileUploadMonitor(session, fum); SessionUtil.setFileUploadMonitor(session, fum);
fileUploadSession.setFileUploadState(FileUploadState.FAILED); fileUploadSession.setFileUploadState(FileUploadState.FAILED);
try { try {
SessionUtil.setCodeFileUploadSession(session, fileUploadSession); SessionUtil
} catch (StatAlgoImporterSessionExpiredException e1) { .setCodeFileUploadSession(session, fileUploadSession);
} catch (StatAlgoImporterServiceException e1) {
logger.error(e1.getLocalizedMessage()); logger.error(e1.getLocalizedMessage());
e1.printStackTrace(); e1.printStackTrace();
throw new ServletException(e1.getLocalizedMessage()); throw new ServletException(e1.getLocalizedMessage());
} }
logger.error("Error elaborating the stream", e); logger.error("Error elaborating the stream", e);
uploadItem.delete(); uploadItem.delete();
response.getWriter().write("ERROR-"+e.getMessage()); response.getWriter().write("ERROR-" + e.getMessage());
return; return;
} }
uploadItem.delete(); uploadItem.delete();
logger.trace("changing state"); logger.trace("changing state");
FileUploadMonitor fum=SessionUtil.getFileUploadMonitor(session); FileUploadMonitor fum = SessionUtil.getFileUploadMonitor(session);
fum.setState(FileUploadState.COMPLETED); fum.setState(FileUploadState.COMPLETED);
SessionUtil.setFileUploadMonitor(session, fum); SessionUtil.setFileUploadMonitor(session, fum);
try { try {
SessionUtil.setCodeFileUploadSession(session, fileUploadSession); SessionUtil.setCodeFileUploadSession(session, fileUploadSession);
} catch (StatAlgoImporterSessionExpiredException e) { } catch (StatAlgoImporterServiceException e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage());
e.printStackTrace(); e.printStackTrace();
throw new ServletException(e.getLocalizedMessage()); throw new ServletException(e.getLocalizedMessage());

View File

@ -3,18 +3,21 @@
*/ */
package org.gcube.portlets.user.statisticalalgorithmsimporter.server; package org.gcube.portlets.user.statisticalalgorithmsimporter.server;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager; import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.CodeFileUploadSession; import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.CodeFileUploadSession;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.social.Recipient; import org.gcube.portlets.user.statisticalalgorithmsimporter.server.social.Recipient;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.Constants; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.Constants;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterSessionExpiredException; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterSessionExpiredException;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.file.FileUploadMonitor; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.file.FileUploadMonitor;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project;
@ -32,54 +35,77 @@ public class SessionUtil {
private static Logger logger = LoggerFactory.getLogger(SessionUtil.class); private static Logger logger = LoggerFactory.getLogger(SessionUtil.class);
public static ASLSession getAslSession(HttpSession httpSession) public static ASLSession getASLSession(HttpSession httpSession)
throws StatAlgoImporterSessionExpiredException { throws StatAlgoImporterServiceException {
String username = (String) httpSession String username = (String) httpSession
.getAttribute(ScopeHelper.USERNAME_ATTRIBUTE); .getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
ASLSession session; ASLSession aslSession;
if (username == null) { if (username == null) {
logger.warn("no user found in session, use test user"); if (Constants.DEBUG_MODE) {
/*throw new AccountingManagerSessionExpiredException("Session Expired!");*/ logger.info("no user found in session, use test user");
username = Constants.DEFAULT_USER;
String scope = Constants.DEFAULT_SCOPE;
// Remove comment for Test
username = Constants.DEFAULT_USER;
String scope = Constants.DEFAULT_SCOPE;
httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, username); httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE,
session = SessionManager.getInstance().getASLSession( username);
httpSession.getId(), username); aslSession = SessionManager.getInstance().getASLSession(
session.setScope(scope); httpSession.getId(), username);
aslSession.setScope(scope);
} else {
logger.info("no user found in session!");
throw new StatAlgoImporterSessionExpiredException(
"Session Expired!");
}
} else { } else {
session = SessionManager.getInstance().getASLSession( aslSession = SessionManager.getInstance().getASLSession(
httpSession.getId(), username); httpSession.getId(), username);
} }
logger.info("SessionUtil: aslSession " + session.getUsername() + " " logger.info("SessionUtil: aslSession " + aslSession.getUsername() + " "
+ session.getScope()); + aslSession.getScope());
return session; return aslSession;
}
public static String getToken(ASLSession aslSession) {
String token = null;
if (Constants.DEBUG_MODE) {
List<String> userRoles = new ArrayList<>();
userRoles.add(Constants.DEFAULT_ROLE);
/*
* if (aslSession.getUsername().compareTo("lucio.lelii") == 0)
* userRoles.add("VRE-Manager");
*/
token = authorizationService().build().generate(
aslSession.getUsername(), userRoles);
} else {
token = aslSession.getSecurityToken();
}
logger.info("received token: " + token);
return token;
} }
// //
public static ArrayList<Recipient> getRecipients(ServletContext servletContest) { public static ArrayList<Recipient> getRecipients(
ServletContext servletContest) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ArrayList<Recipient> recipients=(ArrayList<Recipient>)servletContest.getAttribute(Constants.RECIPIENTS); ArrayList<Recipient> recipients = (ArrayList<Recipient>) servletContest
.getAttribute(Constants.RECIPIENTS);
return recipients; return recipients;
} }
public static ArrayList<Recipient> setRecipients(ServletContext servletContest, ArrayList<Recipient> recipients) { public static ArrayList<Recipient> setRecipients(
servletContest.setAttribute(Constants.RECIPIENTS,recipients); ServletContext servletContest, ArrayList<Recipient> recipients) {
servletContest.setAttribute(Constants.RECIPIENTS, recipients);
return recipients; return recipients;
} }
// //
public static FileUploadMonitor getFileUploadMonitor(HttpSession httpSession) { public static FileUploadMonitor getFileUploadMonitor(HttpSession httpSession) {
FileUploadMonitor fileUploadMonitor = (FileUploadMonitor) httpSession FileUploadMonitor fileUploadMonitor = (FileUploadMonitor) httpSession
@ -105,10 +131,11 @@ public class SessionUtil {
fileUploadMonitor); fileUploadMonitor);
} }
// //
public static void setCodeFileUploadSession(HttpSession httpSession, public static void setCodeFileUploadSession(HttpSession httpSession,
CodeFileUploadSession s) throws StatAlgoImporterSessionExpiredException { CodeFileUploadSession s)
throws StatAlgoImporterServiceException {
CodeFileUploadSession session = (CodeFileUploadSession) httpSession CodeFileUploadSession session = (CodeFileUploadSession) httpSession
.getAttribute(SessionConstants.IMPORT_CODE_FILE_UPLOAD_SESSION); .getAttribute(SessionConstants.IMPORT_CODE_FILE_UPLOAD_SESSION);
@ -117,8 +144,7 @@ public class SessionUtil {
.removeAttribute(SessionConstants.IMPORT_CODE_FILE_UPLOAD_SESSION); .removeAttribute(SessionConstants.IMPORT_CODE_FILE_UPLOAD_SESSION);
httpSession.setAttribute( httpSession.setAttribute(
SessionConstants.IMPORT_CODE_FILE_UPLOAD_SESSION, s); SessionConstants.IMPORT_CODE_FILE_UPLOAD_SESSION, s);
ASLSession aslSession = getAslSession(httpSession);
ScopeProvider.instance.set(aslSession.getScope().toString());
} }
public static CodeFileUploadSession getCodeFileUploadSession( public static CodeFileUploadSession getCodeFileUploadSession(
@ -137,15 +163,12 @@ public class SessionUtil {
Project p = (Project) httpSession Project p = (Project) httpSession
.getAttribute(SessionConstants.PROJECT); .getAttribute(SessionConstants.PROJECT);
if (p != null) if (p != null)
httpSession httpSession.removeAttribute(SessionConstants.PROJECT);
.removeAttribute(SessionConstants.PROJECT); httpSession.setAttribute(SessionConstants.PROJECT, project);
httpSession.setAttribute(
SessionConstants.PROJECT, project);
} }
public static Project getProjectSession( public static Project getProjectSession(HttpSession httpSession) {
HttpSession httpSession) {
Project project = (Project) httpSession Project project = (Project) httpSession
.getAttribute(SessionConstants.PROJECT); .getAttribute(SessionConstants.PROJECT);
if (project == null) { if (project == null) {
@ -154,7 +177,4 @@ public class SessionUtil {
return project; return project;
} }
} }

View File

@ -99,13 +99,15 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
public UserInfo hello() throws StatAlgoImporterServiceException { public UserInfo hello() throws StatAlgoImporterServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
UserInfo userInfo = new UserInfo(aslSession.getUsername(), UserInfo userInfo = new UserInfo(aslSession.getUsername(),
aslSession.getGroupId(), aslSession.getGroupName(), aslSession.getGroupId(), aslSession.getGroupName(),
aslSession.getScope(), aslSession.getScopeName(), aslSession.getScope(), aslSession.getScopeName(),
aslSession.getUserEmailAddress(), aslSession.getUserEmailAddress(),
aslSession.getUserFullName()); aslSession.getUserFullName());
logger.debug("UserInfo: " + userInfo); logger.debug("UserInfo: " + userInfo);
logger.debug("UserToken: " + token);
return userInfo; return userInfo;
} catch (StatAlgoImporterServiceException e) { } catch (StatAlgoImporterServiceException e) {
e.printStackTrace(); e.printStackTrace();
@ -123,7 +125,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException { throws StatAlgoImporterServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
logger.debug("restoreUISession(): " + value); logger.debug("restoreUISession(): " + value);
Project project = SessionUtil.getProjectSession(session); Project project = SessionUtil.getProjectSession(session);
return project; return project;
@ -148,10 +152,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException { throws StatAlgoImporterServiceException {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
if (session == null) { ASLSession aslSession = SessionUtil.getASLSession(session);
throw new StatAlgoImporterServiceException( String token = SessionUtil.getToken(aslSession);
"Error retrieving the session: null"); logger.debug("UserToken: " + token);
}
FileUploadMonitor fileUploadMonitor = SessionUtil FileUploadMonitor fileUploadMonitor = SessionUtil
.getFileUploadMonitor(session); .getFileUploadMonitor(session);
@ -175,7 +178,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException { throws StatAlgoImporterServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
logger.debug("getCode()"); logger.debug("getCode()");
Project projectSession = SessionUtil.getProjectSession(session); Project projectSession = SessionUtil.getProjectSession(session);
if (projectSession != null) { if (projectSession != null) {
@ -211,8 +216,10 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException { throws StatAlgoImporterServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getASLSession(session);
logger.debug("createProjectOnWorkspace(): "+newProjectFolder); String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
logger.debug("createProjectOnWorkspace(): " + newProjectFolder);
if (ProjectArchiver.existProjectInFolder(newProjectFolder, if (ProjectArchiver.existProjectInFolder(newProjectFolder,
aslSession)) { aslSession)) {
throw new StatAlgoImporterServiceException( throw new StatAlgoImporterServiceException(
@ -222,9 +229,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
newProjectFolder); newProjectFolder);
Project projectSession = new Project(projectFolder); Project projectSession = new Project(projectFolder);
SessionUtil.setProjectSession(session, projectSession); SessionUtil.setProjectSession(session, projectSession);
logger.debug("Create Project: "+projectSession); logger.debug("Create Project: " + projectSession);
} }
return; return;
} catch (StatAlgoImporterServiceException e) { } catch (StatAlgoImporterServiceException e) {
e.printStackTrace(); e.printStackTrace();
@ -242,7 +249,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException { throws StatAlgoImporterServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
logger.debug("openProjectOnWorkspace()"); logger.debug("openProjectOnWorkspace()");
Project project = ProjectArchiver.readProject(newProjectFolder, Project project = ProjectArchiver.readProject(newProjectFolder,
@ -267,17 +276,19 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException { throws StatAlgoImporterServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession=SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getASLSession(session);
logger.debug("SetMainCode(): "+itemDescription); String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
logger.debug("SetMainCode(): " + itemDescription);
Project project = SessionUtil.getProjectSession(session); Project project = SessionUtil.getProjectSession(session);
if (project != null) { if (project != null) {
project.setMainCode(new MainCode(itemDescription)); project.setMainCode(new MainCode(itemDescription));
project.setInputData(null); project.setInputData(null);
project.setProjectTarget(null); project.setProjectTarget(null);
WPS4RParser wps4Parser=new WPS4RParser(project, aslSession); WPS4RParser wps4Parser = new WPS4RParser(project, aslSession);
project=wps4Parser.parse(); project = wps4Parser.parse();
SessionUtil.setProjectSession(session, project); SessionUtil.setProjectSession(session, project);
logger.debug("Project: "+project); logger.debug("Project: " + project);
} else { } else {
throw new StatAlgoImporterServiceException("No project open!"); throw new StatAlgoImporterServiceException("No project open!");
} }
@ -299,7 +310,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException { throws StatAlgoImporterServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
logger.debug("addResourceToProject(): " + itemDescription); logger.debug("addResourceToProject(): " + itemDescription);
if (itemDescription == null || itemDescription.getId() == null) { if (itemDescription == null || itemDescription.getId() == null) {
throw new StatAlgoImporterServiceException( throw new StatAlgoImporterServiceException(
@ -336,7 +349,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException { throws StatAlgoImporterServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
logger.debug("deleteResourceOnProject(): " + itemDescription); logger.debug("deleteResourceOnProject(): " + itemDescription);
if (itemDescription == null || itemDescription.getId() == null) { if (itemDescription == null || itemDescription.getId() == null) {
throw new StatAlgoImporterServiceException( throw new StatAlgoImporterServiceException(
@ -345,10 +360,10 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
} }
Project project = SessionUtil.getProjectSession(session); Project project = SessionUtil.getProjectSession(session);
checkProjectInfoForDelete(itemDescription,aslSession, session, project); checkProjectInfoForDelete(itemDescription, aslSession, session,
project);
FilesStorage fileStorage = new FilesStorage(); FilesStorage fileStorage = new FilesStorage();
fileStorage.deleteItemOnFolder( fileStorage.deleteItemOnFolder(aslSession.getUsername(),
aslSession.getUsername(),
itemDescription.getId()); itemDescription.getId());
return project; return project;
@ -388,13 +403,11 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
ProjectArchiver.archive(project, aslSession); ProjectArchiver.archive(project, aslSession);
} else { } else {
if (project.getProjectTarget() != null if (project.getProjectTarget() != null
&& project.getProjectTarget() && project.getProjectTarget().getProjectCompile() != null
.getProjectCompile() != null && project.getProjectTarget().getProjectCompile()
&& project.getProjectTarget() .getFolder() != null
.getProjectCompile().getFolder() != null && project.getProjectTarget().getProjectCompile()
&& project.getProjectTarget() .getFolder().getId()
.getProjectCompile().getFolder()
.getId()
.compareTo(itemDescription.getId()) == 0) { .compareTo(itemDescription.getId()) == 0) {
project.getProjectTarget().setProjectCompile(null); project.getProjectTarget().setProjectCompile(null);
SessionUtil.setProjectSession(session, project); SessionUtil.setProjectSession(session, project);
@ -406,11 +419,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
&& project.getProjectTarget() && project.getProjectTarget()
.getProjectDeploy().getFolder() != null .getProjectDeploy().getFolder() != null
&& project.getProjectTarget() && project.getProjectTarget()
.getProjectDeploy().getFolder() .getProjectDeploy().getFolder().getId()
.getId()
.compareTo(itemDescription.getId()) == 0) { .compareTo(itemDescription.getId()) == 0) {
project.getProjectTarget().setProjectDeploy( project.getProjectTarget().setProjectDeploy(null);
null);
SessionUtil.setProjectSession(session, project); SessionUtil.setProjectSession(session, project);
ProjectArchiver.archive(project, aslSession); ProjectArchiver.archive(project, aslSession);
} else { } else {
@ -420,20 +431,16 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
&& project.getProjectTarget() && project.getProjectTarget()
.getProjectDeploy() .getProjectDeploy()
.getPackageProject() != null .getPackageProject() != null
&& project && project.getProjectTarget()
.getProjectTarget()
.getProjectDeploy() .getProjectDeploy()
.getPackageProject() .getPackageProject().getId()
.getId() .compareTo(itemDescription.getId()) == 0) {
.compareTo( project.getProjectTarget().getProjectDeploy()
itemDescription.getId()) == 0) {
project.getProjectTarget()
.getProjectDeploy()
.setPackageProject(null); .setPackageProject(null);
SessionUtil.setProjectSession(session, project); SessionUtil.setProjectSession(session, project);
ProjectArchiver.archive(project, aslSession); ProjectArchiver.archive(project, aslSession);
} else { } else {
} }
} }
} }
@ -449,7 +456,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException { throws StatAlgoImporterServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
logger.debug("saveProject():" + inputData); logger.debug("saveProject():" + inputData);
Project project = SessionUtil.getProjectSession(session); Project project = SessionUtil.getProjectSession(session);
if (project != null) { if (project != null) {
@ -476,7 +485,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
public void saveCode(String code) throws StatAlgoImporterServiceException { public void saveCode(String code) throws StatAlgoImporterServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
logger.debug("saveCode():" + code); logger.debug("saveCode():" + code);
Project project = SessionUtil.getProjectSession(session); Project project = SessionUtil.getProjectSession(session);
if (project != null) { if (project != null) {
@ -506,11 +517,13 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
} }
@Override @Override
public Project setNewMainCode(ItemDescription fileDescription, public Project setNewMainCode(ItemDescription fileDescription, String code)
String code) throws StatAlgoImporterServiceException { throws StatAlgoImporterServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
logger.debug("saveCode(): itemDescription" + fileDescription logger.debug("saveCode(): itemDescription" + fileDescription
+ ", code:" + code); + ", code:" + code);
Project project = SessionUtil.getProjectSession(session); Project project = SessionUtil.getProjectSession(session);
@ -523,8 +536,8 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
project.setMainCode(mainCode); project.setMainCode(mainCode);
project.setInputData(null); project.setInputData(null);
project.setProjectTarget(null); project.setProjectTarget(null);
WPS4RParser wps4Parser=new WPS4RParser(project, aslSession); WPS4RParser wps4Parser = new WPS4RParser(project, aslSession);
project=wps4Parser.parse(); project = wps4Parser.parse();
SessionUtil.setProjectSession(session, project); SessionUtil.setProjectSession(session, project);
return project; return project;
} else { } else {
@ -547,7 +560,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException { throws StatAlgoImporterServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
logger.debug("createSoftware(): " + inputData); logger.debug("createSoftware(): " + inputData);
Project project = SessionUtil.getProjectSession(session); Project project = SessionUtil.getProjectSession(session);
if (project != null) { if (project != null) {
@ -579,7 +594,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
throws StatAlgoImporterServiceException { throws StatAlgoImporterServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
logger.debug("GetPublicLink(): " + itemDescription); logger.debug("GetPublicLink(): " + itemDescription);
FilesStorage filesStorage = new FilesStorage(); FilesStorage filesStorage = new FilesStorage();
String link = filesStorage.getPublicLink(aslSession.getUsername(), String link = filesStorage.getPublicLink(aslSession.getUsername(),
@ -600,7 +617,10 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
public void publishSoftware() throws StatAlgoImporterServiceException { public void publishSoftware() throws StatAlgoImporterServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session);
ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
logger.debug("PublishSoftware()"); logger.debug("PublishSoftware()");
ArrayList<Recipient> recipients = SessionUtil.getRecipients(session ArrayList<Recipient> recipients = SessionUtil.getRecipients(session
.getServletContext()); .getServletContext());
@ -612,7 +632,8 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
SessionUtil.setProjectSession(session, project); SessionUtil.setProjectSession(session, project);
ProjectArchiver.archive(project, aslSession); ProjectArchiver.archive(project, aslSession);
AlgorithmNotification notify = new AlgorithmNotification( AlgorithmNotification notify = new AlgorithmNotification(
aslSession, project, recipients); this.getThreadLocalRequest(), token, aslSession,
project, recipients);
notify.run(); notify.run();
} else { } else {
throw new StatAlgoImporterServiceException( throw new StatAlgoImporterServiceException(
@ -635,7 +656,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
public void repackageSoftware() throws StatAlgoImporterServiceException { public void repackageSoftware() throws StatAlgoImporterServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session); ASLSession aslSession = SessionUtil.getASLSession(session);
String token = SessionUtil.getToken(aslSession);
logger.debug("UserToken: " + token);
logger.debug("RepackageSoftware()"); logger.debug("RepackageSoftware()");
Project project = SessionUtil.getProjectSession(session); Project project = SessionUtil.getProjectSession(session);
if (project != null) { if (project != null) {

View File

@ -3,9 +3,13 @@ package org.gcube.portlets.user.statisticalalgorithmsimporter.server.social;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager; import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
import org.gcube.applicationsupportlayer.social.NotificationsManager; import org.gcube.applicationsupportlayer.social.NotificationsManager;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
import org.gcube.common.homelibrary.home.HomeLibrary; import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException; import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
@ -27,16 +31,20 @@ import org.slf4j.LoggerFactory;
public class AlgorithmNotification extends Thread { public class AlgorithmNotification extends Thread {
private static Logger logger = LoggerFactory private static Logger logger = LoggerFactory
.getLogger(AlgorithmNotification.class); .getLogger(AlgorithmNotification.class);
private HttpServletRequest httpServletRequest;
private ASLSession aslSession; private ASLSession aslSession;
// private NotificationType notificationType; // private NotificationType notificationType;
private Project project; private Project project;
private ArrayList<Recipient> recipients; private ArrayList<Recipient> recipients;
public AlgorithmNotification(ASLSession aslSession, Project project, public AlgorithmNotification(HttpServletRequest httpServletRequest,
String token, ASLSession aslSession, Project project,
ArrayList<Recipient> recipients) { ArrayList<Recipient> recipients) {
this.aslSession = aslSession; this.aslSession = aslSession;
this.project = project; this.project = project;
this.recipients = recipients; this.recipients = recipients;
this.httpServletRequest = httpServletRequest;
// this.notificationType = NotificationType.SAI_ALGORITHM_PUBLICATION; // this.notificationType = NotificationType.SAI_ALGORITHM_PUBLICATION;
} }
@ -80,8 +88,10 @@ public class AlgorithmNotification extends Thread {
+ aslSession.getUserFullName() + aslSession.getUserFullName()
+ "\n\n has requested to publish the algorithm " + "\n\n has requested to publish the algorithm "
+ project.getInputData().getProjectInfo() + project.getInputData().getProjectInfo()
.getAlgorithmName() + " with the following jar " .getAlgorithmName()
+ project.getProjectTarget().getProjectDeploy().getCodeJar().getPublicLink(); + " with the following jar "
+ project.getProjectTarget().getProjectDeploy()
.getCodeJar().getPublicLink();
String messageId; String messageId;
@ -91,8 +101,15 @@ public class AlgorithmNotification extends Thread {
logger.debug("Sending message notification to: " logger.debug("Sending message notification to: "
+ recipientIds.toString()); + recipientIds.toString());
NotificationsManager nm = new ApplicationNotificationsManager(
aslSession); SocialNetworkingSite site = new SocialNetworkingSite(
httpServletRequest);
SocialNetworkingUser user = new SocialNetworkingUser(
aslSession.getUsername(), aslSession.getUserEmailAddress(),
aslSession.getUserFullName(), aslSession.getUserAvatarId());
NotificationsManager nm = new ApplicationNotificationsManager(site,
aslSession.getScope(), user);
Thread thread = new Thread(new MessageNotificationsThread( Thread thread = new Thread(new MessageNotificationsThread(
recipients, messageId, subject, body, nm)); recipients, messageId, subject, body, nm));
thread.start(); thread.start();

View File

@ -8,18 +8,21 @@ package org.gcube.portlets.user.statisticalalgorithmsimporter.shared;
*/ */
public class Constants { public class Constants {
public static final boolean DEBUG_MODE = false;
public static final boolean TEST_ENABLE = false;
public static final String APPLICATION_ID = "org.gcube.portlets.user.statisticalalgorithmsimporter.server.portlet.StatAlgoImporterPortlet"; public static final String APPLICATION_ID = "org.gcube.portlets.user.statisticalalgorithmsimporter.server.portlet.StatAlgoImporterPortlet";
public static final String STATISTICAL_ALGORITHMS_IMPORTER_ID = "SAIId"; public static final String STATISTICAL_ALGORITHMS_IMPORTER_ID = "SAIId";
public static final String STATISTICAL_ALGORITHMS_IMPORTER_COOKIE = "SAILangCookie"; public static final String STATISTICAL_ALGORITHMS_IMPORTER_COOKIE = "SAILangCookie";
public static final String STATISTICAL_ALGORITHMS_IMPORTER_LANG = "SAILang"; public static final String STATISTICAL_ALGORITHMS_IMPORTER_LANG = "SAILang";
public final static String DEFAULT_USER = "giancarlo.panichi"; public final static String DEFAULT_USER = "giancarlo.panichi";
//public final static String DEFAULT_SCOPE = "/gcube/devNext";
public final static String DEFAULT_SCOPE = "/gcube/devsec/devVRE"; public final static String DEFAULT_SCOPE = "/gcube/devsec/devVRE";
public static final String DEFAULT_ROLE = "OrganizationMember";
public static final String FILE_UPLOADED_FIELD = "FileUploadedField"; public static final String FILE_UPLOADED_FIELD = "FileUploadedField";
public static final String STATISTICAL_ALGORITHMS_IMPORTER_JAR_PUBLIC_LINK = "JarPublicLink"; public static final String STATISTICAL_ALGORITHMS_IMPORTER_JAR_PUBLIC_LINK = "JarPublicLink";
public static final String RECIPIENTS = "Recipients"; public static final String RECIPIENTS = "Recipients";
} }

View File

@ -1,10 +1,13 @@
/** Add css rules here for your application. */ /* Workspace Explorer */
/*table {
border-spacing: 1px !important;
top: 0px !important;
}*/
#drop_target_inner { #drop_target_inner {
background-image: url("statalgoimporter/images/upload_128.png") !important; background-image: url("statalgoimporter/images/upload_128.png") !important;
} }
/* FIX FOR Portal Theme */
.aui input[type="text"], .aui select, .aui textarea, .aui .uneditable-input {
margin-bottom: 0px !important;
}
.aui img {
vertical-align: baseline !important;
}

View File

@ -1,3 +1,7 @@
<?xml version="1.0"?>
<!DOCTYPE display PUBLIC "-//Liferay//DTD Display 6.2.0//EN"
"http://www.liferay.com/dtd/liferay-display_6_2_0.dtd">
<display> <display>
<category name="gCube Applications"> <category name="gCube Applications">
<portlet id="StatisticalAlgorithmsImporter" /> <portlet id="StatisticalAlgorithmsImporter" />

View File

@ -1,6 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 5.2.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_5_2_0.dtd"> <!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 6.2.0//EN"
"http://www.liferay.com/dtd/liferay-portlet-app_6_2_0.dtd">
<liferay-portlet-app> <liferay-portlet-app>
<portlet> <portlet>
<portlet-name>StatisticalAlgorithmsImporter</portlet-name> <portlet-name>StatisticalAlgorithmsImporter</portlet-name>

View File

@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
"http://java.sun.com/dtd/web-app_2_3.dtd"> http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<web-app>
<!-- Servlets --> <!-- Servlets -->
<!-- JUnit --> <!-- JUnit -->