Removed ASL Session Dependency

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@134673 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-11-24 11:28:48 +00:00
parent 02ad0cc313
commit a6ba885760
18 changed files with 191 additions and 293 deletions

32
pom.xml
View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.widgets</groupId> <groupId>org.gcube.portlets.widgets</groupId>
<artifactId>workspace-uploader</artifactId> <artifactId>workspace-uploader</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>1.5.0-SNAPSHOT</version> <version>2.0.0-SNAPSHOT</version>
<name>Workspace Uploader Widget</name> <name>Workspace Uploader Widget</name>
<description>Workspace Uploader Widget allows your application to upload file/s in the gCube Workspace</description> <description>Workspace Uploader Widget allows your application to upload file/s in the gCube Workspace</description>
<scm> <scm>
@ -80,7 +80,12 @@
<artifactId>gcube-widgets</artifactId> <artifactId>gcube-widgets</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>client-context-library</artifactId>
<version>[1.0.0-SNAPSHOT,)</version>
<scope>compile</scope>
</dependency>
<!-- FWS --> <!-- FWS -->
<dependency> <dependency>
<groupId>org.gcube.resources.discovery</groupId> <groupId>org.gcube.resources.discovery</groupId>
@ -109,29 +114,11 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.portal</groupId> <groupId>org.gcube.common.portal</groupId>
<artifactId>custom-portal-handler</artifactId> <artifactId>portal-manager</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>accesslogger</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>session-checker</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<!-- HOME LIBRARY --> <!-- HOME LIBRARY -->
<dependency> <dependency>
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
@ -158,7 +145,6 @@
<dependency> <dependency>
<groupId>commons-httpclient</groupId> <groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId> <artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -6,19 +6,14 @@
<inherits name="com.google.gwt.json.JSON" /> <inherits name="com.google.gwt.json.JSON" />
<inherits name='org.gcube.portlets.user.gcubewidgets.WidgetFactory' /> <inherits name='org.gcube.portlets.user.gcubewidgets.WidgetFactory' />
<inherits name='org.gcube.portlets.widgets.sessionchecker.SessionChecker' /> <!--Inherit the GCubeClientContext widget code -->
<!-- Inherit the default GWT style sheet. You can change --> <inherits name='org.gcube.portal.clientcontext.GCubeClientContext' />
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<!-- <inherits name='com.google.gwt.user.theme.standard.Standard' /> -->
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<!-- Other module inherits --> <!-- Other module inherits -->
<stylesheet src='workspaceuploader.css' /> <stylesheet src='workspaceuploader.css' />
<!-- Specify the app entry point class. --> <!-- Specify the app entry point class. -->
<!-- <entry-point class='org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploader' /> --> <!-- <entry-point class='org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploader'
/> -->
<!-- Specify the paths for translatable code --> <!-- Specify the paths for translatable code -->
<source path='client' /> <source path='client' />

View File

@ -11,18 +11,19 @@ import com.google.gwt.core.client.GWT;
*/ */
public class ConstantsWorkspaceUploader { public class ConstantsWorkspaceUploader {
public static final String WORKSPACE_UPLOADER_SERVLET = GWT.getModuleBaseURL() + "workspaceUploadServlet"; public static final String WORKSPACE_UPLOADER_SERVLET_MODIFIED = GWT.getModuleBaseURL() + "workspaceUploadServlet";
public static final String WORKSPACE_UPLOADER_SERVLET_STREAM = GWT.getModuleBaseURL() + "workspaceUploadServletStream"; public static final String WORKSPACE_UPLOADER_SERVLET_STREAM__MODIFIED = GWT.getModuleBaseURL() + "workspaceUploadServletStream";
public static final String WORKSPACE_UPLOADER_SERVICE = GWT.getModuleBaseURL() + "workspaceUploaderService"; public static final String WORKSPACE_UPLOADER_SERVICE_MODIFIED = GWT.getModuleBaseURL() + "workspaceUploaderService";
public static final String WORKSPACE_UPLOADER_WS_UTIL = GWT.getModuleBaseURL() + "workspaceUploaderWsUtil"; public static final String WORKSPACE_UPLOADER_WS_UTIL_MODIFIED = GWT.getModuleBaseURL() + "workspaceUploaderWsUtil";
public static final String SERVER_ERROR = "Sorry, an error has occurred on the server when"; public static final String SERVER_ERROR = "Sorry, an error has occurred on the server when";
public static final String TRY_AGAIN = "Try again"; public static final String TRY_AGAIN = "Try again";
// UPLOAD SERVLET PARAMETERS // UPLOAD SERVLET PARAMETERS
public static final String CURR_GROUP_ID = "currGroupId";
public static final String IS_OVERWRITE = "isOverwrite"; public static final String IS_OVERWRITE = "isOverwrite";
public static final String UPLOAD_TYPE = "uploadType"; public static final String UPLOAD_TYPE = "uploadType";
public static final String ID_FOLDER = "idFolder"; public static final String ID_FOLDER = "idFolder";

View File

@ -1,6 +1,7 @@
package org.gcube.portlets.widgets.workspaceuploader.client; package org.gcube.portlets.widgets.workspaceuploader.client;
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload.UPLOAD_TYPE; import org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload.UPLOAD_TYPE;
import org.gcube.portal.clientcontext.client.GCubeClientContext;
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload; import org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload;
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload; import org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload;
@ -78,7 +79,7 @@ public class WorkspaceUploader implements EntryPoint {
} }
}); });
final MultipleDNDUpload dnd = new MultipleDNDUpload(); final MultipleDNDUpload dnd = new MultipleDNDUpload(parentId, UPLOAD_TYPE.File);
buttonDirect.addClickHandler(new ClickHandler() { buttonDirect.addClickHandler(new ClickHandler() {
@ -87,7 +88,7 @@ public class WorkspaceUploader implements EntryPoint {
// MultipleDilaogUpload uploadStream = new MultipleDilaogUpload(headerTitle, parentId, org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload.UPLOAD_TYPE.File); // MultipleDilaogUpload uploadStream = new MultipleDilaogUpload(headerTitle, parentId, org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload.UPLOAD_TYPE.File);
// uploadStream.initFileReader(); // uploadStream.initFileReader();
// uploadStream.center(); // uploadStream.center();
dnd.setParameters(parentId, UPLOAD_TYPE.File); dnd.setParameters(parentId, UPLOAD_TYPE.File, GCubeClientContext.getCurrentContextId());
} }
}); });

View File

@ -4,7 +4,7 @@ package org.gcube.portlets.widgets.workspaceuploader.client.uploader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession; import org.gcube.portal.clientcontext.client.GCubeClientContext;
import org.gcube.portlets.widgets.workspaceuploader.client.ClosableDialog; import org.gcube.portlets.widgets.workspaceuploader.client.ClosableDialog;
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader; import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
import org.gcube.portlets.widgets.workspaceuploader.client.DialogResult; import org.gcube.portlets.widgets.workspaceuploader.client.DialogResult;
@ -90,11 +90,12 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
this.parentIdentifier = parentId; this.parentIdentifier = parentId;
this.uploadType = uploadType; this.uploadType = uploadType;
this.addStyleName("fileInputUploader"); this.addStyleName("fileInputUploader");
formPanel.setAction(ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVLET_STREAM); formPanel.setAction(ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVLET_STREAM__MODIFIED);
formPanel.setEncoding(FormPanel.ENCODING_MULTIPART); formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
formPanel.setMethod(FormPanel.METHOD_POST); formPanel.setMethod(FormPanel.METHOD_POST);
formPanel.setWidth("auto"); formPanel.setWidth("auto");
// Create a panel to hold all of the form widgets. // Create a panel to hold all of the form widgets.
panel = new VerticalPanel(); panel = new VerticalPanel();
formPanel.setWidget(panel); formPanel.setWidget(panel);
@ -103,8 +104,10 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
fileUpload.setName(ConstantsWorkspaceUploader.UPLOAD_FORM_ELEMENT); fileUpload.setName(ConstantsWorkspaceUploader.UPLOAD_FORM_ELEMENT);
// Add hidden parameters // Add hidden parameters
panel.add(new Hidden(ConstantsWorkspaceUploader.CURR_GROUP_ID, GCubeClientContext.getCurrentContextId()));
panel.add(new Hidden(ConstantsWorkspaceUploader.ID_FOLDER,parentId)); panel.add(new Hidden(ConstantsWorkspaceUploader.ID_FOLDER,parentId));
panel.add(new Hidden(ConstantsWorkspaceUploader.UPLOAD_TYPE,uploadType.toString())); panel.add(new Hidden(ConstantsWorkspaceUploader.UPLOAD_TYPE,uploadType.toString()));
panel.add(hiddenOverwrite); panel.add(hiddenOverwrite);
initJsonClientKeys(); initJsonClientKeys();
@ -219,7 +222,7 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
} }
case SESSION_EXPIRED:{ case SESSION_EXPIRED:{
GWT.log("Upload aborted due to session expired: "+ resultMessage.getMessage()); GWT.log("Upload aborted due to session expired: "+ resultMessage.getMessage());
CheckSession.showLogoutDialog(); Window.alert("Session expired, please reload the page");
removeLoading(); removeLoading();
break; break;
} }

View File

@ -6,7 +6,7 @@ package org.gcube.portlets.widgets.workspaceuploader.client.uploader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader; import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
import org.gcube.portlets.widgets.workspaceuploader.client.DialogResult; import org.gcube.portlets.widgets.workspaceuploader.client.DialogResult;
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderServiceAsync; import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderServiceAsync;
@ -45,7 +45,7 @@ public class MultipleDilaogUpload extends DialogUpload {
private String idFolder; private String idFolder;
private UPLOAD_TYPE type; private UPLOAD_TYPE type;
private String servlet = ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVLET_STREAM;
/** /**
* Instantiates a new multiple dilaog upload stream. * Instantiates a new multiple dilaog upload stream.
@ -168,7 +168,7 @@ public class MultipleDilaogUpload extends DialogUpload {
} }
case SESSION_EXPIRED:{ case SESSION_EXPIRED:{
GWT.log("Upload aborted due to session expired: "+ resultMessage.getMessage()); GWT.log("Upload aborted due to session expired: "+ resultMessage.getMessage());
CheckSession.showLogoutDialog(); Window.alert("Session expired, please reload the page");
removeLoading(); removeLoading();
break; break;
} }

View File

@ -10,6 +10,7 @@ import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.gcube.portal.clientcontext.client.GCubeClientContext;
import org.gcube.portlets.widgets.workspaceuploader.client.ClosableDialog; import org.gcube.portlets.widgets.workspaceuploader.client.ClosableDialog;
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader; import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderListenerController; import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderListenerController;
@ -102,7 +103,8 @@ public class UploaderMonitor {
timer.cancel(); timer.cancel();
RequestBuilder request = new RequestBuilder(RequestBuilder.GET, ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVLET_STREAM+"?"+ConstantsWorkspaceUploader.CLIENT_UPLOAD_KEYS+"="+clientKey+"&"+ConstantsWorkspaceUploader.CANCEL_UPLOAD+"=true"); RequestBuilder request = new RequestBuilder(RequestBuilder.GET, ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVLET_STREAM__MODIFIED+"?"+ConstantsWorkspaceUploader.CLIENT_UPLOAD_KEYS+"="+clientKey+"&"+ConstantsWorkspaceUploader.CANCEL_UPLOAD+"=true");
request = GCubeClientContext.injectContext(request);
try { try {
request.sendRequest(null, new RequestCallback() { request.sendRequest(null, new RequestCallback() {

View File

@ -6,7 +6,7 @@ package org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession; import org.gcube.portal.clientcontext.client.GCubeClientContext;
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader; import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.HasWorskpaceUploadNotificationListener; import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.HasWorskpaceUploadNotificationListener;
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener; import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener;
@ -18,6 +18,7 @@ import com.google.gwt.core.shared.GWT;
import com.google.gwt.user.client.Random; import com.google.gwt.user.client.Random;
import com.google.gwt.user.client.Window; import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Hidden;
import com.google.gwt.user.client.ui.LayoutPanel; import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
@ -34,12 +35,13 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
private UPLOAD_TYPE type; private UPLOAD_TYPE type;
// private String jsonKeys; // private String jsonKeys;
private String servlet = ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVLET_STREAM; private String servlet = ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVLET_STREAM__MODIFIED;
private String service = ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVICE; private String service = ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVICE_MODIFIED;
private String workspaceUtil = ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_WS_UTIL; private String workspaceUtil = ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_WS_UTIL_MODIFIED;
private String folder_parent_id = ConstantsWorkspaceUploader.FOLDER_PARENT_ID; private String folder_parent_id = ConstantsWorkspaceUploader.FOLDER_PARENT_ID;
private String item_name = ConstantsWorkspaceUploader.ITEM_NAME; private String item_name = ConstantsWorkspaceUploader.ITEM_NAME;
private String scopeGroupId = "";
public static final String FILE_DELEMITER = ";"; public static final String FILE_DELEMITER = ";";
private Widget onlyChild; private Widget onlyChild;
@ -65,18 +67,6 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
private String dropTargetInnerID = DROP_TARGET_INNER_CLASS +"-"+ randomID; private String dropTargetInnerID = DROP_TARGET_INNER_CLASS +"-"+ randomID;
private String dropTargetUniqueChildID = DROP_TARGET_UNIQUE_CHILD_ID +"-"+ randomID; private String dropTargetUniqueChildID = DROP_TARGET_UNIQUE_CHILD_ID +"-"+ randomID;
/**
* Instantiates a new DND file reader.
*/
public MultipleDNDUpload() {
this.getElement().setId(dropTargetID);
String dnd = "<div id='"+this.dropTargetOuterID+"' class='"+DROP_TARGET_OUTER_CLASS+"'><div id='"+this.dropTargetInnerID+"' class='"+DROP_TARGET_INNER_CLASS+"'></div></div>";
GWT.log(dnd);
HTML html = new HTML(dnd);
this.add(html);
}
/** /**
* Instantiates a new multiple dnd upload. * Instantiates a new multiple dnd upload.
* *
@ -84,8 +74,13 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
* @param uploadType the upload type * @param uploadType the upload type
*/ */
public MultipleDNDUpload(String parentId, UPLOAD_TYPE uploadType) { public MultipleDNDUpload(String parentId, UPLOAD_TYPE uploadType) {
this(); this.getElement().setId(dropTargetID);
setParameters(parentId, uploadType); String dnd = "<div id='"+this.dropTargetOuterID+"' class='"+DROP_TARGET_OUTER_CLASS+"'><div id='"+this.dropTargetInnerID+"' class='"+DROP_TARGET_INNER_CLASS+"'></div></div>";
GWT.log(dnd);
HTML html = new HTML(dnd);
this.add(html);
scopeGroupId = GCubeClientContext.getCurrentContextId();
setParameters(parentId, uploadType, scopeGroupId);
} }
@ -129,9 +124,10 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
* @param uploadType * @param uploadType
* the upload type * the upload type
*/ */
public void setParameters(String parentId, UPLOAD_TYPE uploadType) { public void setParameters(String parentId, UPLOAD_TYPE uploadType, String scopeGroupId) {
this.idFolder = parentId; this.idFolder = parentId;
this.type = uploadType; this.type = uploadType;
this.scopeGroupId = scopeGroupId;
} }
/** /**
@ -561,6 +557,9 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
var uploadType = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::type; var uploadType = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::type;
console.log("uploadType: " + uploadType); console.log("uploadType: " + uploadType);
var scopeGroupId = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::scopeGroupId;
console.log("scopeGroupId: " + scopeGroupId);
if (idfolder === null || idfolder === undefined if (idfolder === null || idfolder === undefined
|| uploadType === null || uploadType === null
@ -637,6 +636,7 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
formdata.append("client_upload_keys", jsonKeys); formdata.append("client_upload_keys", jsonKeys);
formdata.append("uploadType", uploadType); formdata.append("uploadType", uploadType);
formdata.append("idFolder", idfolder); formdata.append("idFolder", idfolder);
formdata.append("currGroupId", scopeGroupId);
var overwrite = false; var overwrite = false;
formdata.append("isOverwrite", overwrite); formdata.append("isOverwrite", overwrite);
@ -659,6 +659,7 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
var wsUtil = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::workspaceUtil; var wsUtil = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::workspaceUtil;
var folder_parent_id = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::folder_parent_id; var folder_parent_id = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::folder_parent_id;
var item_name = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::item_name; var item_name = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::item_name;
console.log("item_name: " + item_name); console.log("item_name: " + item_name);
var params = folder_parent_id+"="+idfolder+"&"+item_name+"="+files[i].name var params = folder_parent_id+"="+idfolder+"&"+item_name+"="+files[i].name
console.log("params: " + params); console.log("params: " + params);
@ -764,7 +765,7 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
* Show logout dialog. * Show logout dialog.
*/ */
private void showLogoutDialog(){ private void showLogoutDialog(){
CheckSession.showLogoutDialog(); Window.alert("Session expired, please reload the page");
} }
/* /*

View File

@ -8,8 +8,6 @@ import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest; import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse; import javax.portlet.RenderResponse;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
/** /**
* The Class WorkspaceUploaderPortlet. * The Class WorkspaceUploaderPortlet.
@ -40,11 +38,7 @@ public class WorkspaceUploaderPortlet extends GenericPortlet{
* @throws IOException . * @throws IOException .
*/ */
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
System.out.println("LOADING ********* FROM "+VIEW_JSP);
ScopeHelper.setContext(request, ScopeHelper.USERNAME_ATTRIBUTE);
// request.setAttribute("fromportlet","true"); // request.setAttribute("fromportlet","true");
// Invoke the JSP to render // Invoke the JSP to render

View File

@ -374,11 +374,11 @@ public class WorkspaceUploadServlet extends HttpServlet {
* @param destinationFolderId the destination folder id * @param destinationFolderId the destination folder id
* @param isOverwrite the is overwrite * @param isOverwrite the is overwrite
*/ */
public static void notifyUploadInSharedFolder(final HttpServletRequest request, final HttpSession httpSession, final Workspace workspace, final String itemId, final String destinationFolderId, final boolean isOverwrite){ public static void notifyUploadInSharedFolder(final String scopeGroupId, final HttpServletRequest request, final HttpSession httpSession, final Workspace workspace, final String itemId, final String destinationFolderId, final boolean isOverwrite){
boolean requestIsNull = request==null; boolean requestIsNull = request==null;
logger.trace("[2] HttpServletRequest is: null? "+requestIsNull+", URI: "+request.getRequestURI() +", ServerName: "+request.getServerName()); logger.trace("[2] HttpServletRequest is: null? "+requestIsNull+", URI: "+request.getRequestURI() +", ServerName: "+request.getServerName());
final NotificationsWorkspaceUploaderProducer np = new NotificationsWorkspaceUploaderProducer(httpSession,request); final NotificationsWorkspaceUploaderProducer np = new NotificationsWorkspaceUploaderProducer(scopeGroupId, httpSession,request);
new Thread(){ new Thread(){
public void run() { public void run() {
WorkspaceItem sourceItem; WorkspaceItem sourceItem;
@ -387,7 +387,7 @@ public class WorkspaceUploadServlet extends HttpServlet {
String sourceSharedId = sourceItem.getIdSharedFolder(); String sourceSharedId = sourceItem.getIdSharedFolder();
WorkspaceItem folderDestinationItem = workspace.getItem(destinationFolderId); WorkspaceItem folderDestinationItem = workspace.getItem(destinationFolderId);
logger.trace("[3] HttpServletRequest is: URI: "+request.getRequestURI() +", ServerName: "+request.getServerName()); logger.trace("[3] HttpServletRequest is: URI: "+request.getRequestURI() +", ServerName: "+request.getServerName());
NotificationsWorkspaceUploader.checkSendNotifyChangedItemToShare(np, request, httpSession, sourceItem, sourceSharedId, folderDestinationItem,isOverwrite); NotificationsWorkspaceUploader.checkSendNotifyChangedItemToShare(scopeGroupId, np, request, httpSession, sourceItem, sourceSharedId, folderDestinationItem,isOverwrite);
} catch (Exception e) { } catch (Exception e) {
logger.error("Error in notifyUploadInSharedFolder", e); logger.error("Error in notifyUploadInSharedFolder", e);
} }
@ -429,7 +429,7 @@ public class WorkspaceUploadServlet extends HttpServlet {
} }
private void createReport(final HttpServletRequest request, HttpSession httpSession, Workspace wa, String itemName, File file, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{ private void createReport(String scopeGroupId, final HttpServletRequest request, HttpSession httpSession, Workspace wa, String itemName, File file, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{
try { try {
@ -439,7 +439,7 @@ public class WorkspaceUploadServlet extends HttpServlet {
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder); itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
report = wa.createReport(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", "", 0, "", StreamUtils.openInputStream(file), destinationFolder.getId()); report = wa.createReport(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", "", 0, "", StreamUtils.openInputStream(file), destinationFolder.getId());
notifyUploadInSharedFolder(request, httpSession,wa,report.getId(),destinationFolder.getId(), isOverwrite); notifyUploadInSharedFolder(scopeGroupId, request, httpSession,wa,report.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+report.getName()+" imported correctly in "+destinationFolder.getPath()); sendMessage(response, "File "+report.getName()+" imported correctly in "+destinationFolder.getPath());
} }
else{ //CASE OVERWRITE else{ //CASE OVERWRITE
@ -447,7 +447,7 @@ public class WorkspaceUploadServlet extends HttpServlet {
if(rep!=null){ if(rep!=null){
notifyUploadInSharedFolder(request, httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite); notifyUploadInSharedFolder(scopeGroupId, request, httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath()); sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath());
} }
else else
@ -469,7 +469,7 @@ public class WorkspaceUploadServlet extends HttpServlet {
} }
private void createTemplate(final HttpServletRequest request, HttpSession httpSession, Workspace wa, String itemName, File file, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{ private void createTemplate(String scopeGroupId, final HttpServletRequest request, HttpSession httpSession, Workspace wa, String itemName, File file, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{
try { try {
@ -479,7 +479,7 @@ public class WorkspaceUploadServlet extends HttpServlet {
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder); itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
template = wa.createReportTemplate(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", 0, "", StreamUtils.openInputStream(file), destinationFolder.getId()); template = wa.createReportTemplate(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", 0, "", StreamUtils.openInputStream(file), destinationFolder.getId());
notifyUploadInSharedFolder(request, httpSession,wa,template.getId(),destinationFolder.getId(), isOverwrite); notifyUploadInSharedFolder(scopeGroupId, request, httpSession,wa,template.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+template.getName()+" imported correctly in "+destinationFolder.getPath()); sendMessage(response, "File "+template.getName()+" imported correctly in "+destinationFolder.getPath());
}else{ //CASE OVERWRITE }else{ //CASE OVERWRITE
@ -487,7 +487,7 @@ public class WorkspaceUploadServlet extends HttpServlet {
if(rep!=null){ if(rep!=null){
notifyUploadInSharedFolder(request, httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite); notifyUploadInSharedFolder(scopeGroupId, request, httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath()); sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath());
} }
else else

View File

@ -18,6 +18,7 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequestWrapper;
import org.apache.commons.fileupload.FileItemFactory; import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileItemIterator; import org.apache.commons.fileupload.FileItemIterator;
@ -45,6 +46,7 @@ import org.gcube.common.homelibrary.home.workspace.folder.items.ReportTemplate;
import org.gcube.common.homelibrary.util.Extensions; import org.gcube.common.homelibrary.util.Extensions;
import org.gcube.common.homelibrary.util.MimeTypeUtil; import org.gcube.common.homelibrary.util.MimeTypeUtil;
import org.gcube.common.homelibrary.util.WorkspaceUtil; import org.gcube.common.homelibrary.util.WorkspaceUtil;
import org.gcube.common.portal.PortalContext;
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader; import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
import org.gcube.portlets.widgets.workspaceuploader.server.notification.NotificationsWorkspaceUploader; import org.gcube.portlets.widgets.workspaceuploader.server.notification.NotificationsWorkspaceUploader;
import org.gcube.portlets.widgets.workspaceuploader.server.notification.NotificationsWorkspaceUploaderProducer; import org.gcube.portlets.widgets.workspaceuploader.server.notification.NotificationsWorkspaceUploaderProducer;
@ -81,6 +83,9 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
protected static final String UTF_8 = "UTF-8"; protected static final String UTF_8 = "UTF-8";
public static final String VRE_ID_ATTR_NAME = "gcube-vreid";
public static final String CURR_GROUP_ID = ConstantsWorkspaceUploader.CURR_GROUP_ID;
public static final String UPLOAD_TYPE = ConstantsWorkspaceUploader.UPLOAD_TYPE; public static final String UPLOAD_TYPE = ConstantsWorkspaceUploader.UPLOAD_TYPE;
public static final String ID_FOLDER = ConstantsWorkspaceUploader.ID_FOLDER; public static final String ID_FOLDER = ConstantsWorkspaceUploader.ID_FOLDER;
@ -179,12 +184,12 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
logger.info("UPLOAD-SERVLET session: "+session); logger.info("UPLOAD-SERVLET session: "+session);
logger.debug("UPLOAD-SERVLET (" + session.getId() + ") new upload request received."); logger.debug("UPLOAD-SERVLET (" + session.getId() + ") new upload request received.");
if(WsUtil.isSessionExpired(session)){ // if(WsUtil.isSessionExpired(session)){
logger.error("SESSION_EXPIRED: session is expired"); // logger.error("SESSION_EXPIRED: session is expired");
sendSessionExpired(response, "SESSION_EXPIRED: session is expired"); // sendSessionExpired(response, "SESSION_EXPIRED: session is expired");
return; // return;
// sendError(response, "SESSION_EXPIRED: session is expired"); //// sendError(response, "SESSION_EXPIRED: session is expired");
} // }
String destinationId = null; String destinationId = null;
String uploadType = null; String uploadType = null;
@ -204,7 +209,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
FileItemIterator fileItemIterator = servletFileUpload.getItemIterator(request); FileItemIterator fileItemIterator = servletFileUpload.getItemIterator(request);
int uploadItemsCnt = 0; int uploadItemsCnt = 0;
String scopeGroupId = "";
//GET FILE STREAM //GET FILE STREAM
while (fileItemIterator.hasNext()) { while (fileItemIterator.hasNext()) {
FileItemStream item = fileItemIterator.next(); FileItemStream item = fileItemIterator.next();
@ -237,13 +242,18 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.WAIT, "Uploading "+fileName+" at 0%", request.getSession()); saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.WAIT, "Uploading "+fileName+" at 0%", request.getSession());
} }
} }
if (item.isFormField() && CURR_GROUP_ID.equals(item.getFieldName())){
scopeGroupId = Streams.asString(item.openStream());
logger.debug("currentGroupId OK scope=" + PortalContext.getConfiguration().getCurrentScope(scopeGroupId));
}
//MUST BE THE LAST PARAMETER TRASMITTED //MUST BE THE LAST PARAMETER TRASMITTED
if (UPLOAD_FORM_ELEMENT.equals(item.getFieldName())){ if (UPLOAD_FORM_ELEMENT.equals(item.getFieldName())){
uploadItem = item; uploadItem = item;
logger.debug("UPLOAD_FORM_ELEMENT OK "+uploadItem.getName()); logger.debug("UPLOAD_FORM_ELEMENT OK "+uploadItem.getName() + " scopeGroupId="+scopeGroupId);
// break; // break;
uploadData(request, response, uploadItem, destinationId, uploadType, listClientUploadKeys.get(uploadItemsCnt), isOverwrite); uploadData(scopeGroupId, request, response, uploadItem, destinationId, uploadType, listClientUploadKeys.get(uploadItemsCnt), isOverwrite);
uploadItemsCnt++; uploadItemsCnt++;
} }
} }
@ -342,8 +352,10 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
* @throws ServletException the servlet exception * @throws ServletException the servlet exception
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
*/ */
private void uploadData(HttpServletRequest request, final HttpServletResponse response, final FileItemStream uploadItem, String destinationId,String uploadType,String clientUploadKey, boolean isOverwrite) throws ServletException, IOException{ private void uploadData(String scopeGroupId, HttpServletRequest request, final HttpServletResponse response, final FileItemStream uploadItem, String destinationId,String uploadType,String clientUploadKey, boolean isOverwrite) throws ServletException, IOException{
String fileName = uploadItem.getName(); String fileName = uploadItem.getName();
logger.info("Upload servlet parameters: [fileName: "+fileName+ ", destinationId: "+destinationId +", uploadType: "+uploadType+", isOverwrite: "+isOverwrite+", clientUploadKey: "+clientUploadKey+"]"); logger.info("Upload servlet parameters: [fileName: "+fileName+ ", destinationId: "+destinationId +", uploadType: "+uploadType+", isOverwrite: "+isOverwrite+", clientUploadKey: "+clientUploadKey+"]");
@ -368,7 +380,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
WorkspaceUploaderItem workspaceUploader = null; WorkspaceUploaderItem workspaceUploader = null;
try { try {
workspaceUploader = WsUtil.getWorkspaceUploaderInSession(request.getSession(), clientUploadKey); workspaceUploader = WsUtil.getWorkspaceUploaderInSession(request, clientUploadKey);
workspaceUploader.setIsOverwrite(isOverwrite); //SET IS OVERWRITE workspaceUploader.setIsOverwrite(isOverwrite); //SET IS OVERWRITE
} catch (Exception e) { } catch (Exception e) {
logger.error("Error during workspace uploader retrieving", e); logger.error("Error during workspace uploader retrieving", e);
@ -384,8 +396,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
Workspace wa = null; Workspace wa = null;
try { try {
logger.debug("getWorkspace from HL"); logger.debug("getWorkspace from HL scopeGroupId="+scopeGroupId);
wa = WsUtil.getWorkspace(request.getSession()); wa = WsUtil.getWorkspace(request, scopeGroupId);
} catch (Exception e) { } catch (Exception e) {
logger.error("Error during workspace retrieving", e); logger.error("Error during workspace retrieving", e);
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "An error occurred during upload: "+fileName+". Error processing request in upload servlet", request.getSession()); saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "An error occurred during upload: "+fileName+". Error processing request in upload servlet", request.getSession());
@ -400,7 +412,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
return; return;
} }
WorkspaceItem item; WorkspaceItem item = null;
try { try {
logger.debug("getWorkspaceItem destination id: "+destinationId+" from HL"); logger.debug("getWorkspaceItem destination id: "+destinationId+" from HL");
item = wa.getItem(destinationId); item = wa.getItem(destinationId);
@ -409,6 +421,9 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "An error occurred during upload: "+fileName+". No destination folder found", request.getSession()); saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "An error occurred during upload: "+fileName+". No destination folder found", request.getSession());
sendError(response, "Internal error: No destination folder found"); sendError(response, "Internal error: No destination folder found");
return; return;
} catch (InsufficientPrivilegesException e) {
sendError(response, "Internal error: InsufficientPrivilegesException");
e.printStackTrace();
} }
if (item.getType() != WorkspaceItemType.FOLDER && item.getType() != WorkspaceItemType.SHARED_FOLDER) { if (item.getType() != WorkspaceItemType.FOLDER && item.getType() != WorkspaceItemType.SHARED_FOLDER) {
@ -471,16 +486,16 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
String newItemName = itemName; String newItemName = itemName;
logger.debug("createTemplate: "+newItemName); logger.debug("createTemplate: "+newItemName);
createTemplate(request, workspaceUploader, request.getSession(), wa, newItemName, inputStream, destinationFolder, response, isOverwrite); createTemplate(scopeGroupId, request, workspaceUploader, request.getSession(), wa, newItemName, inputStream, destinationFolder, response, isOverwrite);
}else if(isZipFile && extension.compareToIgnoreCase(D4SR)==0){ //Create REPORT }else if(isZipFile && extension.compareToIgnoreCase(D4SR)==0){ //Create REPORT
String newItemName = itemName; String newItemName = itemName;
logger.debug("createReport: "+newItemName); logger.debug("createReport: "+newItemName);
createReport(request, workspaceUploader, request.getSession(), wa, newItemName, inputStream, destinationFolder, response, isOverwrite); createReport(scopeGroupId, request, workspaceUploader, request.getSession(), wa, newItemName, inputStream, destinationFolder, response, isOverwrite);
}else{ //CREATE AN EXTERNAL FILE }else{ //CREATE AN EXTERNAL FILE
workspaceUploader = WorkspaceUploaderMng.uploadFile(request, workspaceUploader, request.getSession(), wa, itemName, inputStream, destinationFolder, contentType, isOverwrite, size); workspaceUploader = WorkspaceUploaderMng.uploadFile(scopeGroupId, request, workspaceUploader, request.getSession(), wa, itemName, inputStream, destinationFolder, contentType, isOverwrite, size);
if(workspaceUploader==null) if(workspaceUploader==null)
throw new Exception("Error when creating uploader, it is null!"); throw new Exception("Error when creating uploader, it is null!");
@ -494,14 +509,14 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
if (MimeTypeUtil.isZipContentType(uploadItem.getContentType())){ //UNZIP?? if (MimeTypeUtil.isZipContentType(uploadItem.getContentType())){ //UNZIP??
logger.debug("Unziping content"); logger.debug("Unziping content");
workspaceUploader = WorkspaceUploaderMng.uploadArchive(workspaceUploader, request.getSession(), itemName, inputStream, destinationFolder, size); workspaceUploader = WorkspaceUploaderMng.uploadArchive(workspaceUploader, request, itemName, inputStream, destinationFolder, size);
if(workspaceUploader==null) if(workspaceUploader==null)
throw new Exception("Error when creating uploader, it is null!"); throw new Exception("Error when creating uploader, it is null!");
sendMessage(response, workspaceUploader.getIdentifier()); sendMessage(response, workspaceUploader.getIdentifier());
} else{ } else{
workspaceUploader = WorkspaceUploaderMng.uploadFile(request, workspaceUploader, request.getSession(), wa, itemName, inputStream, destinationFolder, contentType, isOverwrite, size); workspaceUploader = WorkspaceUploaderMng.uploadFile(scopeGroupId, request, workspaceUploader, request.getSession(), wa, itemName, inputStream, destinationFolder, contentType, isOverwrite, size);
if(workspaceUploader==null) if(workspaceUploader==null)
throw new Exception("Error when creating uploader, it is null!"); throw new Exception("Error when creating uploader, it is null!");
@ -649,10 +664,10 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
* @param destinationFolderId the destination folder id * @param destinationFolderId the destination folder id
* @param isOverwrite the is overwrite * @param isOverwrite the is overwrite
*/ */
public static void notifyUploadInSharedFolder(final HttpServletRequest request, final HttpSession httpSession, final Workspace workspace, final String itemId, final String destinationFolderId, final boolean isOverwrite){ public static void notifyUploadInSharedFolder(final String scopeGroupId, final HttpServletRequest request, final HttpSession httpSession, final Workspace workspace, final String itemId, final String destinationFolderId, final boolean isOverwrite){
logger.trace("[2] HttpServletRequest is: URI: "+request.getRequestURI() +", ServerName: "+request.getServerName()); logger.trace("[2] HttpServletRequest is: URI: "+request.getRequestURI() +", ServerName: "+request.getServerName());
final NotificationsWorkspaceUploaderProducer np = new NotificationsWorkspaceUploaderProducer(httpSession,request); final NotificationsWorkspaceUploaderProducer np = new NotificationsWorkspaceUploaderProducer(scopeGroupId, httpSession,request);
new Thread(){ new Thread(){
public void run() { public void run() {
WorkspaceItem sourceItem; WorkspaceItem sourceItem;
@ -661,7 +676,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
String sourceSharedId = sourceItem.getIdSharedFolder(); String sourceSharedId = sourceItem.getIdSharedFolder();
WorkspaceItem folderDestinationItem = workspace.getItem(destinationFolderId); WorkspaceItem folderDestinationItem = workspace.getItem(destinationFolderId);
logger.trace("[3] HttpServletRequest is: URI: "+request.getRequestURI() +", ServerName: "+request.getServerName()); logger.trace("[3] HttpServletRequest is: URI: "+request.getRequestURI() +", ServerName: "+request.getServerName());
NotificationsWorkspaceUploader.checkSendNotifyChangedItemToShare(np, request, httpSession, sourceItem, sourceSharedId, folderDestinationItem,isOverwrite); NotificationsWorkspaceUploader.checkSendNotifyChangedItemToShare(scopeGroupId, np, request, httpSession, sourceItem, sourceSharedId, folderDestinationItem,isOverwrite);
} catch (Exception e) { } catch (Exception e) {
logger.error("Error in notifyUploadInSharedFolder", e); logger.error("Error in notifyUploadInSharedFolder", e);
} }
@ -728,7 +743,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
* @throws InternalErrorException the internal error exception * @throws InternalErrorException the internal error exception
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
*/ */
private void createReport(final HttpServletRequest request, WorkspaceUploaderItem workspaceUploader, HttpSession httpSession, Workspace wa, String itemName, InputStream fileInputStream, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{ private void createReport(String scopeGroupId, final HttpServletRequest request, WorkspaceUploaderItem workspaceUploader, HttpSession httpSession, Workspace wa, String itemName, InputStream fileInputStream, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{
try { try {
@ -738,7 +753,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder); itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
report = wa.createReport(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", "", 0, "",fileInputStream, destinationFolder.getId()); report = wa.createReport(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", "", 0, "",fileInputStream, destinationFolder.getId());
notifyUploadInSharedFolder(request, httpSession,wa,report.getId(),destinationFolder.getId(), isOverwrite); notifyUploadInSharedFolder(scopeGroupId, request, httpSession,wa,report.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+report.getName()+" imported correctly in "+destinationFolder.getPath()); sendMessage(response, "File "+report.getName()+" imported correctly in "+destinationFolder.getPath());
} }
else{ //CASE OVERWRITE else{ //CASE OVERWRITE
@ -746,7 +761,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
if(rep!=null){ if(rep!=null){
notifyUploadInSharedFolder(request, httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite); notifyUploadInSharedFolder(scopeGroupId, request, httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath()); sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath());
} }
else else
@ -765,7 +780,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
}finally{ }finally{
try { try {
// StreamUtils.deleteTempFile(file); // StreamUtils.deleteTempFile(file);
WsUtil.setErasableWorkspaceUploaderInSession(httpSession, workspaceUploader.getIdentifier()); WsUtil.setErasableWorkspaceUploaderInSession(request, workspaceUploader.getIdentifier());
} catch (Exception e2) { } catch (Exception e2) {
// TODO: handle exception // TODO: handle exception
} }
@ -790,7 +805,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
* @throws InternalErrorException the internal error exception * @throws InternalErrorException the internal error exception
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
*/ */
private void createTemplate(final HttpServletRequest request, WorkspaceUploaderItem workspaceUploader, HttpSession httpSession, Workspace wa, String itemName, InputStream fileInputStream, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{ private void createTemplate(String scopeGroupId, final HttpServletRequest request, WorkspaceUploaderItem workspaceUploader, HttpSession httpSession, Workspace wa, String itemName, InputStream fileInputStream, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{
try { try {
@ -800,7 +815,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder); itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
template = wa.createReportTemplate(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", 0, "", fileInputStream, destinationFolder.getId()); template = wa.createReportTemplate(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", 0, "", fileInputStream, destinationFolder.getId());
notifyUploadInSharedFolder(request, httpSession,wa,template.getId(),destinationFolder.getId(), isOverwrite); notifyUploadInSharedFolder(scopeGroupId, request, httpSession,wa,template.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+template.getName()+" imported correctly in "+destinationFolder.getPath()); sendMessage(response, "File "+template.getName()+" imported correctly in "+destinationFolder.getPath());
}else{ //CASE OVERWRITE }else{ //CASE OVERWRITE
@ -808,7 +823,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
if(rep!=null){ if(rep!=null){
notifyUploadInSharedFolder(request, httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite); notifyUploadInSharedFolder(scopeGroupId, request, httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath()); sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath());
} }
else else
@ -828,7 +843,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
}finally{ }finally{
try { try {
// StreamUtils.deleteTempFile(fileInputStream); // StreamUtils.deleteTempFile(fileInputStream);
WsUtil.setErasableWorkspaceUploaderInSession(httpSession, workspaceUploader.getIdentifier()); WsUtil.setErasableWorkspaceUploaderInSession(request, workspaceUploader.getIdentifier());
} catch (Exception e2) { } catch (Exception e2) {
// TODO: handle exception // TODO: handle exception
} }

View File

@ -5,6 +5,7 @@ import javax.servlet.http.HttpSession;
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType; import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
import org.gcube.common.homelibrary.home.workspace.Workspace; import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.portal.PortalContext;
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderService; import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderService;
import org.gcube.portlets.widgets.workspaceuploader.server.util.WsUtil; import org.gcube.portlets.widgets.workspaceuploader.server.util.WsUtil;
import org.gcube.portlets.widgets.workspaceuploader.shared.UploadProgress; import org.gcube.portlets.widgets.workspaceuploader.shared.UploadProgress;
@ -38,7 +39,7 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement
throw new Exception(exception); throw new Exception(exception);
} }
logger.trace("Get UploadStatus for id: "+identifier); logger.trace("Get UploadStatus for id: "+identifier);
WorkspaceUploaderItem uploader = WsUtil.getWorkspaceUploaderInSession(getThreadLocalRequest().getSession(), identifier); WorkspaceUploaderItem uploader = WsUtil.getWorkspaceUploaderInSession(getThreadLocalRequest(), identifier);
logger.trace("Uploader status for id: "+identifier +" returns "+uploader); logger.trace("Uploader status for id: "+identifier +" returns "+uploader);
if (uploader == null) { if (uploader == null) {
@ -86,7 +87,7 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement
try { try {
logger.trace("Uploader: "+uploader.getClientUploadKey() +", is erasable?"); logger.trace("Uploader: "+uploader.getClientUploadKey() +", is erasable?");
WsUtil.eraseWorkspaceUploaderInSession(httpSession, uploader); WsUtil.eraseWorkspaceUploaderInSession(getThreadLocalRequest(), uploader);
} }
catch (Exception e) { catch (Exception e) {
logger.warn("Error during checkUploaderErasable: ", e); logger.warn("Error during checkUploaderErasable: ", e);
@ -103,7 +104,8 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement
logger.trace("getWorkspaceId"); logger.trace("getWorkspaceId");
Workspace workspace; Workspace workspace;
try { try {
workspace = WsUtil.getWorkspace(getThreadLocalRequest().getSession()); String scopeGroupId = ""+PortalContext.getConfiguration().getCurrentGroupId(getThreadLocalRequest());
workspace = WsUtil.getWorkspace(getThreadLocalRequest(), scopeGroupId);
if(workspace!=null) if(workspace!=null)
return workspace.getRoot().getId(); return workspace.getRoot().getId();
} catch (Exception e) { } catch (Exception e) {
@ -123,8 +125,8 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement
public String itemExistsInWorkpaceFolder(String parentId, String itemName) throws Exception { public String itemExistsInWorkpaceFolder(String parentId, String itemName) throws Exception {
logger.trace("get itemExistsInWorkpace by parentId: "+parentId); logger.trace("get itemExistsInWorkpace by parentId: "+parentId);
try { try {
String scopeGroupId = ""+PortalContext.getConfiguration().getCurrentGroupId(getThreadLocalRequest());
Workspace workspace = WsUtil.getWorkspace(getThreadLocalRequest().getSession()); Workspace workspace = WsUtil.getWorkspace(getThreadLocalRequest(), scopeGroupId);
WorkspaceItem wsItem = workspace.getItem(parentId); //GET PARENT WorkspaceItem wsItem = workspace.getItem(parentId); //GET PARENT
if(wsItem.getType().equals(WorkspaceItemType.FOLDER) || wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)){ if(wsItem.getType().equals(WorkspaceItemType.FOLDER) || wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)){

View File

@ -11,6 +11,7 @@ import javax.servlet.http.HttpSession;
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType; import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
import org.gcube.common.homelibrary.home.workspace.Workspace; import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.portal.PortalContext;
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader; import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
import org.gcube.portlets.widgets.workspaceuploader.server.util.WsUtil; import org.gcube.portlets.widgets.workspaceuploader.server.util.WsUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -62,8 +63,8 @@ public class WorkspaceUploaderWsUtil extends HttpServlet {
public String itemExistsInWorkpaceFolder(HttpServletRequest req, String parentId, String itemName) throws Exception { public String itemExistsInWorkpaceFolder(HttpServletRequest req, String parentId, String itemName) throws Exception {
logger.trace("get itemExistsInWorkpace for name: "+itemName+", by parentId: "+parentId); logger.trace("get itemExistsInWorkpace for name: "+itemName+", by parentId: "+parentId);
try { try {
HttpSession session = req.getSession(); String scopeGroupId = PortalContext.getConfiguration().getCurrentScope(req);
Workspace workspace = WsUtil.getWorkspace(session); Workspace workspace = WsUtil.getWorkspace(req, scopeGroupId);
WorkspaceItem wsItem = workspace.getItem(parentId); //GET PARENT WorkspaceItem wsItem = workspace.getItem(parentId); //GET PARENT
if(wsItem.getType().equals(WorkspaceItemType.FOLDER) || wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)){ if(wsItem.getType().equals(WorkspaceItemType.FOLDER) || wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)){

View File

@ -35,7 +35,7 @@ public class NotificationsWorkspaceUploader {
* @param sourceSharedId * @param sourceSharedId
* @param folderDestinationItem * @param folderDestinationItem
*/ */
public static void checkSendNotifyChangedItemToShare(NotificationsWorkspaceUploaderProducer np, HttpServletRequest request, HttpSession httpSession, final WorkspaceItem sourceItem, final String sourceSharedId, final WorkspaceItem folderDestinationItem, boolean isOverwrite) { public static void checkSendNotifyChangedItemToShare(String scopeGroupId, NotificationsWorkspaceUploaderProducer np, HttpServletRequest request, HttpSession httpSession, final WorkspaceItem sourceItem, final String sourceSharedId, final WorkspaceItem folderDestinationItem, boolean isOverwrite) {
logger.trace("checkSendNotifyAddItemToShare"); logger.trace("checkSendNotifyAddItemToShare");
@ -56,7 +56,7 @@ public class NotificationsWorkspaceUploader {
//if shareChangeCondition is true.. notifies added item to sharing //if shareChangeCondition is true.. notifies added item to sharing
if(shareChangeCondition){ if(shareChangeCondition){
Workspace workspace = WsUtil.getWorkspace(httpSession); Workspace workspace = WsUtil.getWorkspace(request, scopeGroupId);
List<ContactModel> listContacts = getListUserSharedByFolderSharedId(workspace, folderDestinationItem.getIdSharedFolder()); List<ContactModel> listContacts = getListUserSharedByFolderSharedId(workspace, folderDestinationItem.getIdSharedFolder());
@ -144,14 +144,14 @@ public class NotificationsWorkspaceUploader {
* @param wsItem * @param wsItem
* @return * @return
*/ */
public static boolean isASharedFolderForId(HttpSession httpSession, String itemId){ public static boolean isASharedFolderForId(String scopeGroupId, HttpServletRequest request, String itemId){
if(itemId==null || itemId.isEmpty()) if(itemId==null || itemId.isEmpty())
return false; return false;
try { try {
Workspace workspace = WsUtil.getWorkspace(httpSession); Workspace workspace = WsUtil.getWorkspace(request, scopeGroupId);
WorkspaceItem wsItem = workspace.getItem(itemId); WorkspaceItem wsItem = workspace.getItem(itemId);
if(wsItem!=null) if(wsItem!=null)

View File

@ -9,16 +9,17 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
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.SocialNetworkingSite;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser; import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder; import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.impl.ScopeBean; import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.portlets.widgets.workspaceuploader.server.util.WsUtil; import org.gcube.portlets.widgets.workspaceuploader.server.util.WsUtil;
import org.gcube.portlets.widgets.workspaceuploader.shared.ContactModel; import org.gcube.portlets.widgets.workspaceuploader.shared.ContactModel;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
/** /**
@ -34,7 +35,7 @@ public class NotificationsWorkspaceUploaderProducer {
protected static Logger logger = Logger.getLogger(NotificationsWorkspaceUploaderProducer.class); protected static Logger logger = Logger.getLogger(NotificationsWorkspaceUploaderProducer.class);
protected NotificationsManager notificationsMng; protected NotificationsManager notificationsMng;
protected ASLSession aslSession;
protected String userId; protected String userId;
/** /**
@ -44,10 +45,12 @@ public class NotificationsWorkspaceUploaderProducer {
* @param aslSession the asl session * @param aslSession the asl session
* @param request the request * @param request the request
*/ */
public NotificationsWorkspaceUploaderProducer(HttpSession httpSession, HttpServletRequest request) { public NotificationsWorkspaceUploaderProducer(String scopeGroupId, HttpSession httpSession, HttpServletRequest request) {
this.aslSession = WsUtil.getAslSession(httpSession);
this.notificationsMng = getNotificationManager(httpSession, aslSession, request); this.notificationsMng = getNotificationManager(scopeGroupId, httpSession, request);
this.userId = aslSession.getUsername(); PortalContext pContext = PortalContext.getConfiguration();
GCubeUser currUser = pContext.getCurrentUser(request);
this.userId = currUser.getUsername();
} }
/** /**
@ -81,22 +84,26 @@ public class NotificationsWorkspaceUploaderProducer {
* @param request the request * @param request the request
* @return the notification manager * @return the notification manager
*/ */
public NotificationsManager getNotificationManager(HttpSession httpSession, ASLSession session, HttpServletRequest request) public NotificationsManager getNotificationManager(String scopeGroupId, HttpSession httpSession, HttpServletRequest request) {
{
NotificationsManager notifMng = (NotificationsManager) httpSession.getAttribute(WsUtil.NOTIFICATION_MANAGER_UPLOADER); NotificationsManager notifMng = (NotificationsManager) httpSession.getAttribute(WsUtil.NOTIFICATION_MANAGER_UPLOADER);
PortalContext pContext = PortalContext.getConfiguration();
GCubeUser currUser = pContext.getCurrentUser(request);
if (notifMng == null) { if (notifMng == null) {
try{ try{
logger.trace("Create new NotificationsManager for user: "+session.getUsername());
String scope = pContext.getCurrentScope(scopeGroupId);
logger.trace("Create new NotificationsManager for user: "+currUser.getUsername() + " Scope="+scope);
logger.trace("New ApplicationNotificationsManager with portlet class name: "+WsUtil.NOTIFICATION_PORTLET_CLASS_ID); logger.trace("New ApplicationNotificationsManager with portlet class name: "+WsUtil.NOTIFICATION_PORTLET_CLASS_ID);
logger.info("Request URI: "+request.getRequestURI()); logger.info("Request URI: "+request.getRequestURI());
SocialNetworkingSite site = new SocialNetworkingSite(request); SocialNetworkingSite site = new SocialNetworkingSite(request);
SocialNetworkingUser curser = new SocialNetworkingUser(session.getUsername(), session.getUserEmailAddress(), session.getUserFullName(), session.getUserAvatarId()); SocialNetworkingUser curser = new SocialNetworkingUser(currUser.getUsername(), currUser.getEmail(), currUser.getFullname(), currUser.getUserAvatarURL());
notifMng = new ApplicationNotificationsManager(site, session.getScope(), curser, WsUtil.NOTIFICATION_PORTLET_CLASS_ID);
notifMng = new ApplicationNotificationsManager(site, scope, curser, WsUtil.NOTIFICATION_PORTLET_CLASS_ID);
httpSession.setAttribute(WsUtil.NOTIFICATION_MANAGER_UPLOADER, notifMng); httpSession.setAttribute(WsUtil.NOTIFICATION_MANAGER_UPLOADER, notifMng);
}catch (Exception e) { }catch (Exception e) {
logger.error("An error occurred instancing ApplicationNotificationsManager for user: "+session.getUsername(),e); logger.error("An error occurred instancing ApplicationNotificationsManager for user: "+currUser.getUsername(),e);
} }
} }
@ -127,16 +134,7 @@ public class NotificationsWorkspaceUploaderProducer {
this.notificationsMng = notificationMng; this.notificationsMng = notificationMng;
} }
/**
* Gets the asl session.
*
* @return the asl session
*/
public ASLSession getAslSession() {
return aslSession;
}
/** /**
* Runs a new thread to notify the contacts passed in input. * Runs a new thread to notify the contacts passed in input.
* *

View File

@ -64,7 +64,7 @@ public class WorkspaceUploaderMng {
* @throws InternalErrorException the internal error exception * @throws InternalErrorException the internal error exception
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
*/ */
private static WorkspaceUploaderItem createWorkspaceUploaderFile(HttpServletRequest request, final WorkspaceUploaderItem workspaceUploader, final HttpSession httpSession, final boolean isOvewrite, final Workspace wa, final InputStream uploadFile, final String itemName, final WorkspaceFolder destinationFolder, final String contentType, final long totalBytes) throws InternalErrorException, IOException{ private static WorkspaceUploaderItem createWorkspaceUploaderFile(String scopeGroupId, HttpServletRequest request, final WorkspaceUploaderItem workspaceUploader, final HttpSession httpSession, final boolean isOvewrite, final Workspace wa, final InputStream uploadFile, final String itemName, final WorkspaceFolder destinationFolder, final String contentType, final long totalBytes) throws InternalErrorException, IOException{
logger.debug("Creating WorkspaceUploaderFile..."); logger.debug("Creating WorkspaceUploaderFile...");
workspaceUploader.setUploadStatus(UPLOAD_STATUS.IN_PROGRESS); workspaceUploader.setUploadStatus(UPLOAD_STATUS.IN_PROGRESS);
@ -88,7 +88,7 @@ public class WorkspaceUploaderMng {
workspaceUploader.getFile().setParentId(createdItem.getParent().getId());//SET PARENT ID workspaceUploader.getFile().setParentId(createdItem.getParent().getId());//SET PARENT ID
workspaceUploader.setStatusDescription("File \""+createdItem.getName()+"\" uploaded correctly in "+destinationFolder.getPath()); workspaceUploader.setStatusDescription("File \""+createdItem.getName()+"\" uploaded correctly in "+destinationFolder.getPath());
workspaceUploader.setUploadStatus(UPLOAD_STATUS.COMPLETED); workspaceUploader.setUploadStatus(UPLOAD_STATUS.COMPLETED);
WorkspaceUploadServletStream.notifyUploadInSharedFolder(request, httpSession, wa, createdItem.getId(), createdItem.getParent().getId(), isOvewrite); WorkspaceUploadServletStream.notifyUploadInSharedFolder(scopeGroupId, request, httpSession, wa, createdItem.getId(), createdItem.getParent().getId(), isOvewrite);
}else{ }else{
workspaceUploader.setStatusDescription("An error occurred during upload: \""+itemName + "\". Try again"); workspaceUploader.setStatusDescription("An error occurred during upload: \""+itemName + "\". Try again");
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED); workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
@ -134,7 +134,7 @@ public class WorkspaceUploaderMng {
}finally{ }finally{
try { try {
// StreamUtils.deleteTempFile(uploadFile); // StreamUtils.deleteTempFile(uploadFile);
WsUtil.setErasableWorkspaceUploaderInSession(httpSession, workspaceUploader.getIdentifier()); WsUtil.setErasableWorkspaceUploaderInSession(request, workspaceUploader.getIdentifier());
} catch (Exception e2) { } catch (Exception e2) {
logger.error("Error during setErasableWorkspaceUploaderInSession session update: ",e2); logger.error("Error during setErasableWorkspaceUploaderInSession session update: ",e2);
} }
@ -157,8 +157,8 @@ public class WorkspaceUploaderMng {
* @throws InternalErrorException the internal error exception * @throws InternalErrorException the internal error exception
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
*/ */
private static WorkspaceUploaderItem createWorkspaceUploaderArchive(final WorkspaceUploaderItem workspaceUploader, final HttpSession httpSession, final InputStream uploadFile, final String itemName, final WorkspaceFolder destinationFolder, final long totalBytes) throws InternalErrorException, IOException{ private static WorkspaceUploaderItem createWorkspaceUploaderArchive(final WorkspaceUploaderItem workspaceUploader, final HttpServletRequest request, final InputStream uploadFile, final String itemName, final WorkspaceFolder destinationFolder, final long totalBytes) throws InternalErrorException, IOException{
HttpSession httpSession = request.getSession();
logger.info("calling upload archive - [itemName: "+itemName+"]"); logger.info("calling upload archive - [itemName: "+itemName+"]");
try { try {
workspaceUploader.setUploadStatus(UPLOAD_STATUS.IN_PROGRESS); workspaceUploader.setUploadStatus(UPLOAD_STATUS.IN_PROGRESS);
@ -194,7 +194,7 @@ public class WorkspaceUploaderMng {
}finally{ }finally{
try { try {
// StreamUtils.deleteTempFile(uploadFile); // StreamUtils.deleteTempFile(uploadFile);
WsUtil.setErasableWorkspaceUploaderInSession(httpSession, workspaceUploader.getIdentifier()); WsUtil.setErasableWorkspaceUploaderInSession(request, workspaceUploader.getIdentifier());
} catch (Exception e2) { } catch (Exception e2) {
// TODO: handle exception // TODO: handle exception
} }
@ -220,10 +220,10 @@ public class WorkspaceUploaderMng {
* @return the workspace uploader item * @return the workspace uploader item
* @throws Exception the exception * @throws Exception the exception
*/ */
public static WorkspaceUploaderItem uploadFile(HttpServletRequest request, WorkspaceUploaderItem workspaceUploader, HttpSession httpSession, Workspace wa, String itemName, InputStream file, WorkspaceFolder destinationFolder, String contentType, boolean isOverwrite, long totolaBytes) throws Exception { public static WorkspaceUploaderItem uploadFile(String scopeGroupId, HttpServletRequest request, WorkspaceUploaderItem workspaceUploader, HttpSession httpSession, Workspace wa, String itemName, InputStream file, WorkspaceFolder destinationFolder, String contentType, boolean isOverwrite, long totolaBytes) throws Exception {
try { try {
return createWorkspaceUploaderFile(request, workspaceUploader, httpSession, isOverwrite, wa, file, itemName, destinationFolder, contentType, totolaBytes); return createWorkspaceUploaderFile(scopeGroupId, request, workspaceUploader, httpSession, isOverwrite, wa, file, itemName, destinationFolder, contentType, totolaBytes);
} catch (Exception e) { } catch (Exception e) {
logger.error("Error when uploading file to HL : ",e); logger.error("Error when uploading file to HL : ",e);
throw new Exception("An error occurred during upload: "+itemName+". Try again"); throw new Exception("An error occurred during upload: "+itemName+". Try again");
@ -243,10 +243,10 @@ public class WorkspaceUploaderMng {
* @return the workspace uploader item * @return the workspace uploader item
* @throws Exception the exception * @throws Exception the exception
*/ */
public static WorkspaceUploaderItem uploadArchive(WorkspaceUploaderItem workspaceUploader, HttpSession httpSession, String itemName, InputStream file, WorkspaceFolder destinationFolder, long totalBytes) throws Exception { public static WorkspaceUploaderItem uploadArchive(WorkspaceUploaderItem workspaceUploader, HttpServletRequest request, String itemName, InputStream file, WorkspaceFolder destinationFolder, long totalBytes) throws Exception {
try { try {
return createWorkspaceUploaderArchive(workspaceUploader, httpSession, file, itemName, destinationFolder, totalBytes); return createWorkspaceUploaderArchive(workspaceUploader, request, file, itemName, destinationFolder, totalBytes);
} catch (Exception e) { } catch (Exception e) {
logger.error("Error when uploading Archive to HL creation: ",e); logger.error("Error when uploading Archive to HL creation: ",e);
@ -262,8 +262,8 @@ public class WorkspaceUploaderMng {
* @return the workspace uploader item * @return the workspace uploader item
* @throws Exception the exception * @throws Exception the exception
*/ */
public static WorkspaceUploaderItem uploadFileStatus(HttpSession httpSession, WorkspaceUploaderItem workspaceUploader) throws Exception { public static WorkspaceUploaderItem uploadFileStatus(HttpServletRequest request, WorkspaceUploaderItem workspaceUploader) throws Exception {
return WsUtil.getWorkspaceUploaderInSession(httpSession, workspaceUploader.getIdentifier()); return WsUtil.getWorkspaceUploaderInSession(request, workspaceUploader.getIdentifier());
} }
/** /**

View File

@ -64,8 +64,6 @@ public class UserUtil {
} }
}else{ }else{
logger.trace("DEVELOPEMENT MODE ON"); logger.trace("DEVELOPEMENT MODE ON");
logger.trace("Returning "+WsUtil.TEST_USER_FULL_NAME +" full name for: "+portalLogin);
return WsUtil.TEST_USER_FULL_NAME;
} }
logger.trace("Return portal login as full name for: "+portalLogin); logger.trace("Return portal login as full name for: "+portalLogin);

View File

@ -3,18 +3,18 @@
*/ */
package org.gcube.portlets.widgets.workspaceuploader.server.util; package org.gcube.portlets.widgets.workspaceuploader.server.util;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
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;
import org.gcube.common.homelibrary.home.workspace.Workspace; import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException; import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem; import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem;
import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil;
@ -28,15 +28,11 @@ import com.liferay.portal.service.UserLocalServiceUtil;
*/ */
public class WsUtil { public class WsUtil {
public static final String USERNAME_ATTRIBUTE = ScopeHelper.USERNAME_ATTRIBUTE;
public static final String NOTIFICATION_MANAGER_UPLOADER = "WS_UPLOADER_NOTIFICATION_MANAGER"; public static final String NOTIFICATION_MANAGER_UPLOADER = "WS_UPLOADER_NOTIFICATION_MANAGER";
// public static final String NOTIFICATION_PRODUCER = "WORKSPACE_UPLOADER_NOTIFICATION_PRODUCER"; // public static final String NOTIFICATION_PRODUCER = "WORKSPACE_UPLOADER_NOTIFICATION_PRODUCER";
// public static final String NOTIFICATION_PORTLET_CLASS_ID = WorkspaceUploadServletStream.class.getName(); //IN DEV // public static final String NOTIFICATION_PORTLET_CLASS_ID = WorkspaceUploadServletStream.class.getName(); //IN DEV
public static final String NOTIFICATION_PORTLET_CLASS_ID = "org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl"; public static final String NOTIFICATION_PORTLET_CLASS_ID = "org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl";
//IN DEV
public static final String TEST_SCOPE = "/gcube/devsec";
public static String TEST_USER = "test.user";
public static String TEST_USER_FULL_NAME = "Test User";
protected static Logger logger = Logger.getLogger(WsUtil.class); protected static Logger logger = Logger.getLogger(WsUtil.class);
@ -59,79 +55,6 @@ public class WsUtil {
} }
} }
/**
* Gets the asl session.
*
* @param httpSession the http session
* @return the asl session
*/
public static ASLSession getAslSession(HttpSession httpSession)
{
String sessionID = httpSession.getId();
String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE);
ASLSession session;
if (user == null) {
/*USE ANOTHER ACCOUNT (OTHERWHISE BY TEST_USER) FOR RUNNING
* COMMENT THIS IN DEVELOP ENVIROMENT (UNCOMMENT IN PRODUCTION)*/
user=TEST_USER;
if (!isWithinPortal()) { //DEV MODE
// user = "francesco.mangiacrapa";
user=TEST_USER;
TEST_USER_FULL_NAME = "Test User";
}
logger.warn("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND - PORTLETS STARTING WITH FOLLOWING SETTINGS:");
logger.warn("session id: "+sessionID);
logger.warn("TEST_USER: "+user);
logger.warn("TEST_SCOPE: "+TEST_SCOPE);
logger.warn("USERNAME_ATTRIBUTE: "+USERNAME_ATTRIBUTE);
session = SessionManager.getInstance().getASLSession(sessionID, user);
session.setScope(TEST_SCOPE);
//MANDATORY FOR SOCIAL LIBRARY
session.setUserAvatarId(user + "Avatar");
session.setUserFullName(TEST_USER_FULL_NAME);
session.setUserEmailAddress(user + "@mail.test");
//SET HTTP SESSION ATTRIBUTE
httpSession.setAttribute(USERNAME_ATTRIBUTE, user);
return session;
}
return SessionManager.getInstance().getASLSession(sessionID, user);
}
/**
* Checks if is session expired.
*
* @param httpSession the http session
* @return true if current username into ASL session is WsUtil.TEST_USER, false otherwise
* @throws Exception the exception
*/
public static boolean isSessionExpired(HttpSession httpSession) throws Exception {
logger.trace("workspace session validating...");
//READING USERNAME FROM ASL SESSION
String userUsername = getAslSession(httpSession).getUsername();
boolean isTestUser = userUsername.compareTo(WsUtil.TEST_USER)==0;
//TODO UNCOMMENT THIS FOR RELEASE
logger.trace("Is "+WsUtil.TEST_USER+" test user? "+isTestUser);
if(isTestUser){
logger.error("workspace session is expired! username is: "+WsUtil.TEST_USER);
return true; //is TEST_USER, session is expired
}
logger.trace("workspace session is valid! current username is: "+userUsername);
return false;
}
/** /**
* Gets the workspace. * Gets the workspace.
* *
@ -141,39 +64,18 @@ public class WsUtil {
* @throws HomeNotFoundException the home not found exception * @throws HomeNotFoundException the home not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception * @throws WorkspaceFolderNotFoundException the workspace folder not found exception
*/ */
public static Workspace getWorkspace(final HttpSession httpSession) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException{ public static Workspace getWorkspace(final HttpServletRequest request, String scopeGroupId) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException{
logger.trace("Get Workspace"); logger.trace("Get Workspace");
final ASLSession session = getAslSession(httpSession); PortalContext pContext = PortalContext.getConfiguration();
logger.trace("ASLSession scope: "+session.getScope() + " username: "+session.getUsername()); String username = pContext.getCurrentUser(request).getUsername();
String scope = pContext.getCurrentScope(scopeGroupId);
logger.trace("Client context scope: "+ scope + " username: "+username);
ScopeProvider.instance.set(session.getScope()); ScopeProvider.instance.set(scope);
logger.trace("Scope provider instancied"); return HomeLibrary.getUserWorkspace(username);
return HomeLibrary.getUserWorkspace(session.getUsername());
} }
//
// /**
// * Gets the notification producer.
// *
// * @param session the session
// * @param request the request
// * @return the notification producer
// */
// public static NotificationsWorkspaceUploaderProducer getNotificationProducer(ASLSession session, HttpServletRequest request)
// {
//
// NotificationsWorkspaceUploaderProducer notifProducer = (NotificationsWorkspaceUploaderProducer) session.getAttribute(NOTIFICATION_PRODUCER);
//
// if (notifProducer == null) {
// logger.trace("Create new Notification Producer for user: "+session.getUsername());
// notifProducer = new NotificationsWorkspaceUploaderProducer(session, request);
// session.setAttribute(NOTIFICATION_PRODUCER, notifProducer);
// }
//
// return notifProducer;
// }
/** /**
* Put workspace uploader in session. * Put workspace uploader in session.
@ -182,15 +84,14 @@ public class WsUtil {
* @param uploader the uploader * @param uploader the uploader
* @throws Exception the exception * @throws Exception the exception
*/ */
public static void putWorkspaceUploaderInSession(final HttpSession httpSession, WorkspaceUploaderItem uploader) throws Exception public static void putWorkspaceUploaderInSession(final HttpSession httpSession, WorkspaceUploaderItem uploader) throws Exception {
{
logger.trace("Put workspace uploader in session: "+uploader.getIdentifier() + ", STATUS: "+uploader.getUploadStatus()); logger.trace("Put workspace uploader in session: "+uploader.getIdentifier() + ", STATUS: "+uploader.getUploadStatus());
final ASLSession session = getAslSession(httpSession);
if(uploader.getIdentifier()==null || uploader.getIdentifier().isEmpty()) if(uploader.getIdentifier()==null || uploader.getIdentifier().isEmpty())
throw new Exception("Invalid uploader"); throw new Exception("Invalid uploader");
session.setAttribute(uploader.getIdentifier(), uploader); httpSession.setAttribute(uploader.getIdentifier(), uploader);
logger.debug("Added uploader: "+uploader.getIdentifier() +" in session"); logger.debug("Added uploader: "+uploader.getIdentifier() +" in session");
} }
@ -201,15 +102,13 @@ public class WsUtil {
* @param uploader the uploader * @param uploader the uploader
* @throws Exception the exception * @throws Exception the exception
*/ */
public static void forceEraseWorkspaceUploaderInSession(final HttpSession httpSession, WorkspaceUploaderItem uploader) throws Exception public static void forceEraseWorkspaceUploaderInSession(final HttpSession httpSession, WorkspaceUploaderItem uploader) throws Exception {
{
logger.trace("Force Erase WorkspaceUploader workspace uploader in session: "+uploader.getIdentifier()); logger.trace("Force Erase WorkspaceUploader workspace uploader in session: "+uploader.getIdentifier());
final ASLSession session = getAslSession(httpSession);
if(uploader==null || uploader.getIdentifier()==null || uploader.getIdentifier().isEmpty()) if(uploader==null || uploader.getIdentifier()==null || uploader.getIdentifier().isEmpty())
throw new Exception("Invalid uploader"); throw new Exception("Invalid uploader");
session.removeAttribute(uploader.getIdentifier()); httpSession.removeAttribute(uploader.getIdentifier());
logger.info("Erased uploader: "+uploader.getIdentifier()); logger.info("Erased uploader: "+uploader.getIdentifier());
} }
@ -222,17 +121,19 @@ public class WsUtil {
* @param uploader the uploader * @param uploader the uploader
* @throws Exception the exception * @throws Exception the exception
*/ */
public static void eraseWorkspaceUploaderInSession(final HttpSession httpSession, WorkspaceUploaderItem uploader) throws Exception public static void eraseWorkspaceUploaderInSession(final HttpServletRequest request, WorkspaceUploaderItem uploader) throws Exception
{ {
logger.trace("Erase WorkspaceUploader workspace uploader in session: "+uploader.getIdentifier() + ", erasable? "+uploader.isErasable()); logger.trace("Erase WorkspaceUploader workspace uploader in session: "+uploader.getIdentifier() + ", erasable? "+uploader.isErasable());
final ASLSession session = getAslSession(httpSession);
if(uploader==null || uploader.getIdentifier()==null || uploader.getIdentifier().isEmpty()) if(uploader==null || uploader.getIdentifier()==null || uploader.getIdentifier().isEmpty())
throw new Exception("Invalid uploader"); throw new Exception("Invalid uploader");
HttpSession httpSession = request.getSession();
if(uploader.isErasable()){ if(uploader.isErasable()){
// session.setAttribute(uploader.getIdentifier(), null); // session.setAttribute(uploader.getIdentifier(), null);
session.removeAttribute(uploader.getIdentifier()); httpSession.removeAttribute(uploader.getIdentifier());
logger.info("Erased uploader: "+uploader.getIdentifier()); logger.info("Erased uploader: "+uploader.getIdentifier());
} }
} }
@ -246,14 +147,13 @@ public class WsUtil {
* @return the workspace uploader in session * @return the workspace uploader in session
* @throws Exception the exception * @throws Exception the exception
*/ */
public static WorkspaceUploaderItem getWorkspaceUploaderInSession(final HttpSession httpSession, String uploaderIdentifier) throws Exception public static WorkspaceUploaderItem getWorkspaceUploaderInSession(final HttpServletRequest request, String uploaderIdentifier) throws Exception {
{ HttpSession httpSession = request.getSession();
final ASLSession session = getAslSession(httpSession);
if(uploaderIdentifier==null || uploaderIdentifier.isEmpty()) if(uploaderIdentifier==null || uploaderIdentifier.isEmpty())
throw new Exception("Invalid uploader"); throw new Exception("Invalid uploader");
return (WorkspaceUploaderItem) session.getAttribute(uploaderIdentifier); return (WorkspaceUploaderItem) httpSession.getAttribute(uploaderIdentifier);
} }
@ -266,9 +166,10 @@ public class WsUtil {
* @return true, if successful * @return true, if successful
* @throws Exception the exception * @throws Exception the exception
*/ */
public static boolean setErasableWorkspaceUploaderInSession(final HttpSession httpSession, String uploaderIdentifier) throws Exception public static boolean setErasableWorkspaceUploaderInSession(final HttpServletRequest request, String uploaderIdentifier) throws Exception {
{
WorkspaceUploaderItem uploader = getWorkspaceUploaderInSession(httpSession, uploaderIdentifier); HttpSession httpSession = request.getSession();
WorkspaceUploaderItem uploader = getWorkspaceUploaderInSession(request, uploaderIdentifier);
if(uploader!=null){ if(uploader!=null){
/*TODO REMOVE SESSION KEY FROM SESSION MUST BE MANAGED IN ANOTHER WAY IN ORDER TO AVOID THATH IT'S REMOVED FROM SESSION BEFORE THAT /*TODO REMOVE SESSION KEY FROM SESSION MUST BE MANAGED IN ANOTHER WAY IN ORDER TO AVOID THATH IT'S REMOVED FROM SESSION BEFORE THAT
@ -290,11 +191,11 @@ public class WsUtil {
* @param httpSession the http session * @param httpSession the http session
* @return the user id * @return the user id
*/ */
public static String getUserId(HttpSession httpSession) { public static String getUserId(HttpServletRequest request) {
PortalContext pContext = PortalContext.getConfiguration();
ASLSession session = getAslSession(httpSession); String username = pContext.getCurrentUser(request).getUsername();
logger.debug("workspace upload UserId: "+username);
return session.getUsername(); return username;
} }
} }