From cd983e2180213c91012ab7ab6643be6c8174cc90 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Tue, 21 Jun 2016 16:42:08 +0000 Subject: [PATCH] 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 --- .classpath | 6 +- pom.xml | 177 ++++++++++-------- .../server/LocalUploadServlet.java | 154 ++++++++------- .../server/SessionUtil.java | 110 ++++++----- .../server/StatAlgoImporterServiceImpl.java | 131 +++++++------ .../server/social/AlgorithmNotification.java | 27 ++- .../shared/Constants.java | 11 +- src/main/webapp/StatAlgoImporter.css | 19 +- src/main/webapp/WEB-INF/liferay-display.xml | 4 + src/main/webapp/WEB-INF/liferay-portlet.xml | 5 +- src/main/webapp/WEB-INF/web.xml | 9 +- 11 files changed, 384 insertions(+), 269 deletions(-) diff --git a/.classpath b/.classpath index b8700c9..3d16876 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - + - + @@ -45,5 +45,5 @@ - + diff --git a/pom.xml b/pom.xml index 4ae9e3b..c696fc4 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ 4.0.0 org.gcube.portlets.user statistical-algorithms-importer - 1.1.0-SNAPSHOT + 1.2.0-SNAPSHOT war @@ -60,12 +60,7 @@ localRun - - - xerces - xercesImpl - 2.11.0 - + org.slf4j slf4j-api @@ -76,24 +71,55 @@ slf4j-log4j12 runtime + + + xerces + xerces + 2.4.0 + + + + + org.gcube.contentmanagement + storage-manager-core + runtime + + + org.gcube.contentmanagement + storage-manager-wrapper + runtime + + + org.gcube.common home-library runtime - org.gcube.common home-library-jcr runtime - org.gcube.common home-library-model runtime + + + org.gcube.common + common-authorization + runtime + + + + org.gcube.common + authorization-client + runtime + + com.thoughtworks.xstream xstream @@ -120,11 +146,7 @@ gwt-servlet ${gwtVersion} - - - - + @@ -146,23 +168,15 @@ - - - - - - + javax.portlet portlet-api - provided - org.gcube.core @@ -178,14 +192,78 @@ org.gcube.applicationsupportlayer aslcore + provided - org.gcube.applicationsupportlayer - accesslogger + org.gcube.dvos + usermanagement-core + provided + + + org.gcube.common + common-authorization + provided + + + + org.gcube.common + authorization-client + provided + + + + + org.gcube.portlets.user + gcube-widgets + compile + + + + + org.gcube.portlets.widgets + session-checker + [0.0.0-SNAPSHOT,1.0.0-SNAPSHOT) + + + + + + org.gcube.contentmanagement + storage-manager-core + provided + + + + org.gcube.contentmanagement + storage-manager-wrapper + provided + + + + + org.gcube.common + home-library + provided + + + + org.gcube.common + home-library-jcr + provided + + + + org.gcube.common + home-library-model + provided + + + + @@ -204,27 +282,6 @@ - - - org.gcube.portlets.user - gcube-widgets - compile - - - - - - - - org.gcube.portlets.widgets - session-checker - [0.2.0-SNAPSHOT,1.0.0-SNAPSHOT) - - commons-io @@ -270,28 +327,6 @@ [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) - - - org.gcube.common - home-library - provided - - - - org.gcube.common - home-library-jcr - provided - - - - org.gcube.common - home-library-model - provided - - - - @@ -339,12 +374,6 @@ slf4j-log4j12 provided - - - - diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/LocalUploadServlet.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/LocalUploadServlet.java index e12d5e8..49a6ab0 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/LocalUploadServlet.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/LocalUploadServlet.java @@ -18,85 +18,89 @@ import org.apache.commons.fileupload.FileItemFactory; import org.apache.commons.fileupload.FileUploadException; import org.apache.commons.fileupload.disk.DiskFileItemFactory; 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.FileUploadListener; import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.FileUtil; 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.FileUploadState; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - - - - - - - - - - - import com.allen_sauer.gwt.log.client.Log; - /** * - * @author "Giancarlo Panichi" - * g.panichi@isti.cnr.it + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it * */ 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; @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"); - + HttpSession session = request.getSession(); - - if(session==null){ - logger.error("Error getting the upload session, no session valid found: "+session); - response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "ERROR-Error getting the user session, no session found"+session); - return ; + + if (session == null) { + logger.error("Error getting the upload session, no session valid found: " + + session); + 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 { - SessionUtil.setCodeFileUploadSession(session,fileUploadSession); - } catch (StatAlgoImporterSessionExpiredException e) { + ASLSession aslSession = SessionUtil.getASLSession(session); + 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()); e.printStackTrace(); throw new ServletException(e.getLocalizedMessage()); } - FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); - - - FileUploadListener uploadListener = new FileUploadListener(fileUploadMonitor); + + FileUploadListener uploadListener = new FileUploadListener( + fileUploadMonitor); upload.setProgressListener(uploadListener); - + FileItem uploadItem = null; Log.info("Start upload file "); try { @@ -104,78 +108,90 @@ public class LocalUploadServlet extends HttpServlet { Iterator it = items.iterator(); while (it.hasNext()) { 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; } } } catch (FileUploadException e) { - FileUploadMonitor fum=SessionUtil.getFileUploadMonitor(session); - fum.setFailed("An error occured elaborating the HTTP request", FileUtil.exceptionDetailMessage(e)); + FileUploadMonitor fum = SessionUtil.getFileUploadMonitor(session); + fum.setFailed("An error occured elaborating the HTTP request", + FileUtil.exceptionDetailMessage(e)); SessionUtil.setFileUploadMonitor(session, fum); fileUploadSession.setFileUploadState(FileUploadState.FAILED); try { - SessionUtil.setCodeFileUploadSession(session, fileUploadSession); - } catch (StatAlgoImporterSessionExpiredException e1) { + SessionUtil + .setCodeFileUploadSession(session, fileUploadSession); + } catch (StatAlgoImporterServiceException e1) { logger.error(e1.getLocalizedMessage()); e1.printStackTrace(); throw new ServletException(e1.getLocalizedMessage()); } 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; } - + if (uploadItem == null) { - FileUploadMonitor fum=SessionUtil.getFileUploadMonitor(session); - fum.setFailed("An error occured elaborating the HTTP request: No file found", "Upload request without file"); + FileUploadMonitor fum = SessionUtil.getFileUploadMonitor(session); + fum.setFailed( + "An error occured elaborating the HTTP request: No file found", + "Upload request without file"); SessionUtil.setFileUploadMonitor(session, fum); fileUploadSession.setFileUploadState(FileUploadState.FAILED); try { - SessionUtil.setCodeFileUploadSession(session, fileUploadSession); - } catch (StatAlgoImporterSessionExpiredException e) { + SessionUtil + .setCodeFileUploadSession(session, fileUploadSession); + } catch (StatAlgoImporterServiceException e) { logger.error(e.getLocalizedMessage()); e.printStackTrace(); throw new ServletException(e.getLocalizedMessage()); } 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; } - + String contentType = uploadItem.getContentType(); - - logger.trace("ContentType: "+contentType); - - + + logger.trace("ContentType: " + contentType); + try { - FileUtil.setImportCodeFile(fileUploadSession, uploadItem.getInputStream(), uploadItem.getName(), contentType); + FileUtil.setImportCodeFile(fileUploadSession, + uploadItem.getInputStream(), uploadItem.getName(), + contentType); } catch (Exception e) { - FileUploadMonitor fum=SessionUtil.getFileUploadMonitor(session); - fum.setFailed("An error occured elaborating the file", FileUtil.exceptionDetailMessage(e)); + FileUploadMonitor fum = SessionUtil.getFileUploadMonitor(session); + fum.setFailed("An error occured elaborating the file", + FileUtil.exceptionDetailMessage(e)); SessionUtil.setFileUploadMonitor(session, fum); fileUploadSession.setFileUploadState(FileUploadState.FAILED); try { - SessionUtil.setCodeFileUploadSession(session, fileUploadSession); - } catch (StatAlgoImporterSessionExpiredException e1) { + SessionUtil + .setCodeFileUploadSession(session, fileUploadSession); + } catch (StatAlgoImporterServiceException e1) { logger.error(e1.getLocalizedMessage()); e1.printStackTrace(); throw new ServletException(e1.getLocalizedMessage()); } logger.error("Error elaborating the stream", e); uploadItem.delete(); - response.getWriter().write("ERROR-"+e.getMessage()); + response.getWriter().write("ERROR-" + e.getMessage()); return; } - + uploadItem.delete(); - + logger.trace("changing state"); - FileUploadMonitor fum=SessionUtil.getFileUploadMonitor(session); + FileUploadMonitor fum = SessionUtil.getFileUploadMonitor(session); fum.setState(FileUploadState.COMPLETED); SessionUtil.setFileUploadMonitor(session, fum); try { SessionUtil.setCodeFileUploadSession(session, fileUploadSession); - } catch (StatAlgoImporterSessionExpiredException e) { + } catch (StatAlgoImporterServiceException e) { logger.error(e.getLocalizedMessage()); e.printStackTrace(); throw new ServletException(e.getLocalizedMessage()); diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/SessionUtil.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/SessionUtil.java index ec458aa..bf8a5b7 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/SessionUtil.java @@ -3,18 +3,21 @@ */ package org.gcube.portlets.user.statisticalalgorithmsimporter.server; +import static org.gcube.common.authorization.client.Constants.authorizationService; + import java.util.ArrayList; +import java.util.List; import javax.servlet.ServletContext; import javax.servlet.http.HttpSession; import org.gcube.application.framework.core.session.ASLSession; 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.portlets.user.statisticalalgorithmsimporter.server.file.CodeFileUploadSession; import org.gcube.portlets.user.statisticalalgorithmsimporter.server.social.Recipient; 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.file.FileUploadMonitor; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project; @@ -32,54 +35,77 @@ public class SessionUtil { private static Logger logger = LoggerFactory.getLogger(SessionUtil.class); - public static ASLSession getAslSession(HttpSession httpSession) - throws StatAlgoImporterSessionExpiredException { + public static ASLSession getASLSession(HttpSession httpSession) + throws StatAlgoImporterServiceException { String username = (String) httpSession .getAttribute(ScopeHelper.USERNAME_ATTRIBUTE); - ASLSession session; + ASLSession aslSession; if (username == null) { - logger.warn("no user found in session, use test user"); - /*throw new AccountingManagerSessionExpiredException("Session Expired!");*/ - - - // Remove comment for Test - username = Constants.DEFAULT_USER; - String scope = Constants.DEFAULT_SCOPE; + if (Constants.DEBUG_MODE) { + logger.info("no user found in session, use test user"); + username = Constants.DEFAULT_USER; + String scope = Constants.DEFAULT_SCOPE; - httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, username); - session = SessionManager.getInstance().getASLSession( - httpSession.getId(), username); - session.setScope(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 StatAlgoImporterSessionExpiredException( + "Session Expired!"); + + } } else { - session = SessionManager.getInstance().getASLSession( + aslSession = SessionManager.getInstance().getASLSession( httpSession.getId(), username); } - logger.info("SessionUtil: aslSession " + session.getUsername() + " " - + session.getScope()); + logger.info("SessionUtil: aslSession " + aslSession.getUsername() + " " + + aslSession.getScope()); - return session; + return aslSession; + } + + public static String getToken(ASLSession aslSession) { + String token = null; + if (Constants.DEBUG_MODE) { + List 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 getRecipients(ServletContext servletContest) { + public static ArrayList getRecipients( + ServletContext servletContest) { @SuppressWarnings("unchecked") - ArrayList recipients=(ArrayList)servletContest.getAttribute(Constants.RECIPIENTS); + ArrayList recipients = (ArrayList) servletContest + .getAttribute(Constants.RECIPIENTS); return recipients; - + } - - public static ArrayList setRecipients(ServletContext servletContest, ArrayList recipients) { - servletContest.setAttribute(Constants.RECIPIENTS,recipients); + + public static ArrayList setRecipients( + ServletContext servletContest, ArrayList recipients) { + servletContest.setAttribute(Constants.RECIPIENTS, recipients); return recipients; - + } - - + // public static FileUploadMonitor getFileUploadMonitor(HttpSession httpSession) { FileUploadMonitor fileUploadMonitor = (FileUploadMonitor) httpSession @@ -105,10 +131,11 @@ public class SessionUtil { fileUploadMonitor); } - + // public static void setCodeFileUploadSession(HttpSession httpSession, - CodeFileUploadSession s) throws StatAlgoImporterSessionExpiredException { + CodeFileUploadSession s) + throws StatAlgoImporterServiceException { CodeFileUploadSession session = (CodeFileUploadSession) httpSession .getAttribute(SessionConstants.IMPORT_CODE_FILE_UPLOAD_SESSION); @@ -117,8 +144,7 @@ public class SessionUtil { .removeAttribute(SessionConstants.IMPORT_CODE_FILE_UPLOAD_SESSION); httpSession.setAttribute( SessionConstants.IMPORT_CODE_FILE_UPLOAD_SESSION, s); - ASLSession aslSession = getAslSession(httpSession); - ScopeProvider.instance.set(aslSession.getScope().toString()); + } public static CodeFileUploadSession getCodeFileUploadSession( @@ -137,15 +163,12 @@ public class SessionUtil { Project p = (Project) httpSession .getAttribute(SessionConstants.PROJECT); if (p != null) - httpSession - .removeAttribute(SessionConstants.PROJECT); - httpSession.setAttribute( - SessionConstants.PROJECT, project); - + httpSession.removeAttribute(SessionConstants.PROJECT); + httpSession.setAttribute(SessionConstants.PROJECT, project); + } - public static Project getProjectSession( - HttpSession httpSession) { + public static Project getProjectSession(HttpSession httpSession) { Project project = (Project) httpSession .getAttribute(SessionConstants.PROJECT); if (project == null) { @@ -154,7 +177,4 @@ public class SessionUtil { return project; } - - - } diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/StatAlgoImporterServiceImpl.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/StatAlgoImporterServiceImpl.java index 9fa258d..89c97bd 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/StatAlgoImporterServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/StatAlgoImporterServiceImpl.java @@ -99,13 +99,15 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements public UserInfo hello() throws StatAlgoImporterServiceException { try { 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(), aslSession.getGroupId(), aslSession.getGroupName(), aslSession.getScope(), aslSession.getScopeName(), aslSession.getUserEmailAddress(), aslSession.getUserFullName()); logger.debug("UserInfo: " + userInfo); + logger.debug("UserToken: " + token); return userInfo; } catch (StatAlgoImporterServiceException e) { e.printStackTrace(); @@ -123,7 +125,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements throws StatAlgoImporterServiceException { try { 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); Project project = SessionUtil.getProjectSession(session); return project; @@ -148,10 +152,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements throws StatAlgoImporterServiceException { HttpSession session = this.getThreadLocalRequest().getSession(); - if (session == null) { - throw new StatAlgoImporterServiceException( - "Error retrieving the session: null"); - } + ASLSession aslSession = SessionUtil.getASLSession(session); + String token = SessionUtil.getToken(aslSession); + logger.debug("UserToken: " + token); FileUploadMonitor fileUploadMonitor = SessionUtil .getFileUploadMonitor(session); @@ -175,7 +178,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements throws StatAlgoImporterServiceException { try { 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()"); Project projectSession = SessionUtil.getProjectSession(session); if (projectSession != null) { @@ -211,8 +216,10 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements throws StatAlgoImporterServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); - ASLSession aslSession = SessionUtil.getAslSession(session); - logger.debug("createProjectOnWorkspace(): "+newProjectFolder); + ASLSession aslSession = SessionUtil.getASLSession(session); + String token = SessionUtil.getToken(aslSession); + logger.debug("UserToken: " + token); + logger.debug("createProjectOnWorkspace(): " + newProjectFolder); if (ProjectArchiver.existProjectInFolder(newProjectFolder, aslSession)) { throw new StatAlgoImporterServiceException( @@ -222,9 +229,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements newProjectFolder); Project projectSession = new Project(projectFolder); SessionUtil.setProjectSession(session, projectSession); - logger.debug("Create Project: "+projectSession); + logger.debug("Create Project: " + projectSession); } - + return; } catch (StatAlgoImporterServiceException e) { e.printStackTrace(); @@ -242,7 +249,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements throws StatAlgoImporterServiceException { try { 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()"); Project project = ProjectArchiver.readProject(newProjectFolder, @@ -267,17 +276,19 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements throws StatAlgoImporterServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); - ASLSession aslSession=SessionUtil.getAslSession(session); - logger.debug("SetMainCode(): "+itemDescription); + ASLSession aslSession = SessionUtil.getASLSession(session); + String token = SessionUtil.getToken(aslSession); + logger.debug("UserToken: " + token); + logger.debug("SetMainCode(): " + itemDescription); Project project = SessionUtil.getProjectSession(session); if (project != null) { project.setMainCode(new MainCode(itemDescription)); project.setInputData(null); project.setProjectTarget(null); - WPS4RParser wps4Parser=new WPS4RParser(project, aslSession); - project=wps4Parser.parse(); + WPS4RParser wps4Parser = new WPS4RParser(project, aslSession); + project = wps4Parser.parse(); SessionUtil.setProjectSession(session, project); - logger.debug("Project: "+project); + logger.debug("Project: " + project); } else { throw new StatAlgoImporterServiceException("No project open!"); } @@ -299,7 +310,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements throws StatAlgoImporterServiceException { try { 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); if (itemDescription == null || itemDescription.getId() == null) { throw new StatAlgoImporterServiceException( @@ -336,7 +349,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements throws StatAlgoImporterServiceException { try { 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); if (itemDescription == null || itemDescription.getId() == null) { throw new StatAlgoImporterServiceException( @@ -345,10 +360,10 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements } Project project = SessionUtil.getProjectSession(session); - checkProjectInfoForDelete(itemDescription,aslSession, session, project); + checkProjectInfoForDelete(itemDescription, aslSession, session, + project); FilesStorage fileStorage = new FilesStorage(); - fileStorage.deleteItemOnFolder( - aslSession.getUsername(), + fileStorage.deleteItemOnFolder(aslSession.getUsername(), itemDescription.getId()); return project; @@ -388,13 +403,11 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements ProjectArchiver.archive(project, aslSession); } else { if (project.getProjectTarget() != null - && project.getProjectTarget() - .getProjectCompile() != null - && project.getProjectTarget() - .getProjectCompile().getFolder() != null - && project.getProjectTarget() - .getProjectCompile().getFolder() - .getId() + && project.getProjectTarget().getProjectCompile() != null + && project.getProjectTarget().getProjectCompile() + .getFolder() != null + && project.getProjectTarget().getProjectCompile() + .getFolder().getId() .compareTo(itemDescription.getId()) == 0) { project.getProjectTarget().setProjectCompile(null); SessionUtil.setProjectSession(session, project); @@ -406,11 +419,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements && project.getProjectTarget() .getProjectDeploy().getFolder() != null && project.getProjectTarget() - .getProjectDeploy().getFolder() - .getId() + .getProjectDeploy().getFolder().getId() .compareTo(itemDescription.getId()) == 0) { - project.getProjectTarget().setProjectDeploy( - null); + project.getProjectTarget().setProjectDeploy(null); SessionUtil.setProjectSession(session, project); ProjectArchiver.archive(project, aslSession); } else { @@ -420,20 +431,16 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements && project.getProjectTarget() .getProjectDeploy() .getPackageProject() != null - && project - .getProjectTarget() + && project.getProjectTarget() .getProjectDeploy() - .getPackageProject() - .getId() - .compareTo( - itemDescription.getId()) == 0) { - project.getProjectTarget() - .getProjectDeploy() + .getPackageProject().getId() + .compareTo(itemDescription.getId()) == 0) { + project.getProjectTarget().getProjectDeploy() .setPackageProject(null); SessionUtil.setProjectSession(session, project); ProjectArchiver.archive(project, aslSession); } else { - + } } } @@ -449,7 +456,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements throws StatAlgoImporterServiceException { try { 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); Project project = SessionUtil.getProjectSession(session); if (project != null) { @@ -476,7 +485,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements public void saveCode(String code) throws StatAlgoImporterServiceException { try { 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); Project project = SessionUtil.getProjectSession(session); if (project != null) { @@ -506,11 +517,13 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements } @Override - public Project setNewMainCode(ItemDescription fileDescription, - String code) throws StatAlgoImporterServiceException { + public Project setNewMainCode(ItemDescription fileDescription, String code) + throws StatAlgoImporterServiceException { try { 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 + ", code:" + code); Project project = SessionUtil.getProjectSession(session); @@ -523,8 +536,8 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements project.setMainCode(mainCode); project.setInputData(null); project.setProjectTarget(null); - WPS4RParser wps4Parser=new WPS4RParser(project, aslSession); - project=wps4Parser.parse(); + WPS4RParser wps4Parser = new WPS4RParser(project, aslSession); + project = wps4Parser.parse(); SessionUtil.setProjectSession(session, project); return project; } else { @@ -547,7 +560,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements throws StatAlgoImporterServiceException { try { 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); Project project = SessionUtil.getProjectSession(session); if (project != null) { @@ -579,7 +594,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements throws StatAlgoImporterServiceException { try { 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); FilesStorage filesStorage = new FilesStorage(); String link = filesStorage.getPublicLink(aslSession.getUsername(), @@ -600,7 +617,10 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements public void publishSoftware() throws StatAlgoImporterServiceException { try { 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()"); ArrayList recipients = SessionUtil.getRecipients(session .getServletContext()); @@ -612,7 +632,8 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements SessionUtil.setProjectSession(session, project); ProjectArchiver.archive(project, aslSession); AlgorithmNotification notify = new AlgorithmNotification( - aslSession, project, recipients); + this.getThreadLocalRequest(), token, aslSession, + project, recipients); notify.run(); } else { throw new StatAlgoImporterServiceException( @@ -635,7 +656,9 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements public void repackageSoftware() throws StatAlgoImporterServiceException { try { 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()"); Project project = SessionUtil.getProjectSession(session); if (project != null) { diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/social/AlgorithmNotification.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/social/AlgorithmNotification.java index 9151a95..195861f 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/social/AlgorithmNotification.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/server/social/AlgorithmNotification.java @@ -3,9 +3,13 @@ package org.gcube.portlets.user.statisticalalgorithmsimporter.server.social; import java.util.ArrayList; import java.util.List; +import javax.servlet.http.HttpServletRequest; + import org.gcube.application.framework.core.session.ASLSession; import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager; 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.exceptions.HomeNotFoundException; import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; @@ -27,16 +31,20 @@ import org.slf4j.LoggerFactory; public class AlgorithmNotification extends Thread { private static Logger logger = LoggerFactory .getLogger(AlgorithmNotification.class); + private HttpServletRequest httpServletRequest; private ASLSession aslSession; + // private NotificationType notificationType; private Project project; private ArrayList recipients; - public AlgorithmNotification(ASLSession aslSession, Project project, + public AlgorithmNotification(HttpServletRequest httpServletRequest, + String token, ASLSession aslSession, Project project, ArrayList recipients) { this.aslSession = aslSession; this.project = project; this.recipients = recipients; + this.httpServletRequest = httpServletRequest; // this.notificationType = NotificationType.SAI_ALGORITHM_PUBLICATION; } @@ -80,8 +88,10 @@ public class AlgorithmNotification extends Thread { + aslSession.getUserFullName() + "\n\n has requested to publish the algorithm " + project.getInputData().getProjectInfo() - .getAlgorithmName() + " with the following jar " - + project.getProjectTarget().getProjectDeploy().getCodeJar().getPublicLink(); + .getAlgorithmName() + + " with the following jar " + + project.getProjectTarget().getProjectDeploy() + .getCodeJar().getPublicLink(); String messageId; @@ -91,8 +101,15 @@ public class AlgorithmNotification extends Thread { logger.debug("Sending message notification to: " + 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( recipients, messageId, subject, body, nm)); thread.start(); diff --git a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/shared/Constants.java b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/shared/Constants.java index 084d57f..51799e8 100644 --- a/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/shared/Constants.java +++ b/src/main/java/org/gcube/portlets/user/statisticalalgorithmsimporter/shared/Constants.java @@ -8,18 +8,21 @@ package org.gcube.portlets.user.statisticalalgorithmsimporter.shared; */ 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 STATISTICAL_ALGORITHMS_IMPORTER_ID = "SAIId"; public static final String STATISTICAL_ALGORITHMS_IMPORTER_COOKIE = "SAILangCookie"; public static final String STATISTICAL_ALGORITHMS_IMPORTER_LANG = "SAILang"; 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 static final String DEFAULT_ROLE = "OrganizationMember"; + + public static final String FILE_UPLOADED_FIELD = "FileUploadedField"; public static final String STATISTICAL_ALGORITHMS_IMPORTER_JAR_PUBLIC_LINK = "JarPublicLink"; public static final String RECIPIENTS = "Recipients"; - - - + } diff --git a/src/main/webapp/StatAlgoImporter.css b/src/main/webapp/StatAlgoImporter.css index 42f1e09..1b577f3 100644 --- a/src/main/webapp/StatAlgoImporter.css +++ b/src/main/webapp/StatAlgoImporter.css @@ -1,10 +1,13 @@ -/** Add css rules here for your application. */ -/*table { - border-spacing: 1px !important; - top: 0px !important; -}*/ - - +/* Workspace Explorer */ #drop_target_inner { background-image: url("statalgoimporter/images/upload_128.png") !important; -} \ No newline at end of file +} + +/* 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; +} diff --git a/src/main/webapp/WEB-INF/liferay-display.xml b/src/main/webapp/WEB-INF/liferay-display.xml index 0614ba0..bed1959 100644 --- a/src/main/webapp/WEB-INF/liferay-display.xml +++ b/src/main/webapp/WEB-INF/liferay-display.xml @@ -1,3 +1,7 @@ + + + diff --git a/src/main/webapp/WEB-INF/liferay-portlet.xml b/src/main/webapp/WEB-INF/liferay-portlet.xml index 6f4541c..0f4e2de 100644 --- a/src/main/webapp/WEB-INF/liferay-portlet.xml +++ b/src/main/webapp/WEB-INF/liferay-portlet.xml @@ -1,6 +1,7 @@ - - + + StatisticalAlgorithmsImporter diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 8bc6cb1..e2d2faa 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -1,9 +1,8 @@ - - - +