Feature #11722 - Porting to StorageHub
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@169418 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
9fe9fa86db
commit
907f69c5da
|
@ -1,10 +1,17 @@
|
||||||
<ReleaseNotes>
|
<ReleaseNotes>
|
||||||
|
<Changeset component="org.gcube.portlets-widgets.workspace-uploader.2-0-0"
|
||||||
|
date="2018-06-25">
|
||||||
|
<Change>[Feature #11722] Workspace Uploader - Update to StorageHUB
|
||||||
|
</Change>
|
||||||
|
</Changeset>
|
||||||
<Changeset component="org.gcube.portlets-widgets.workspace-uploader.1-8-0"
|
<Changeset component="org.gcube.portlets-widgets.workspace-uploader.1-8-0"
|
||||||
date="2017-03-27">
|
date="2017-03-27">
|
||||||
<Change>[Task #7820] DaD and Browse: create new version of existing
|
<Change>[Task #7820] DaD and Browse: create new version of existing
|
||||||
items added</Change>
|
items added
|
||||||
|
</Change>
|
||||||
<Change>Removed currUserId parameter from client-side</Change>
|
<Change>Removed currUserId parameter from client-side</Change>
|
||||||
<Change>Updated message displaying also version of file after upload completed</Change>
|
<Change>Updated message displaying also version of file after upload
|
||||||
|
completed</Change>
|
||||||
</Changeset>
|
</Changeset>
|
||||||
<Changeset component="org.gcube.portlets-widgets.workspace-uploader.1-7-0"
|
<Changeset component="org.gcube.portlets-widgets.workspace-uploader.1-7-0"
|
||||||
date="2017-02-23">
|
date="2017-02-23">
|
||||||
|
|
48
pom.xml
48
pom.xml
|
@ -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.8.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>
|
||||||
|
@ -121,26 +121,38 @@
|
||||||
|
|
||||||
<!-- HOME LIBRARY -->
|
<!-- HOME LIBRARY -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.portal</groupId>
|
||||||
<artifactId>home-library-model</artifactId>
|
<artifactId>storagehub-client-wrapper</artifactId>
|
||||||
<scope>provided</scope>
|
<version>[0.0.1-SNAPSHOT, 1.0.0-SNAPSHOT]</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- JSON PARSER -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.json</groupId>
|
||||||
<artifactId>home-library-jcr</artifactId>
|
<artifactId>json</artifactId>
|
||||||
<scope>provided</scope>
|
<version>20090211</version>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.gcube.common</groupId>
|
|
||||||
<artifactId>home-library</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<artifactId>asm-all</artifactId>
|
|
||||||
<groupId>asm</groupId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- <dependency> -->
|
||||||
|
<!-- <groupId>org.gcube.common</groupId> -->
|
||||||
|
<!-- <artifactId>home-library-model</artifactId> -->
|
||||||
|
<!-- <scope>provided</scope> -->
|
||||||
|
<!-- </dependency> -->
|
||||||
|
<!-- <dependency> -->
|
||||||
|
<!-- <groupId>org.gcube.common</groupId> -->
|
||||||
|
<!-- <artifactId>home-library-jcr</artifactId> -->
|
||||||
|
<!-- <scope>provided</scope> -->
|
||||||
|
<!-- </dependency> -->
|
||||||
|
<!-- <dependency> -->
|
||||||
|
<!-- <groupId>org.gcube.common</groupId> -->
|
||||||
|
<!-- <artifactId>home-library</artifactId> -->
|
||||||
|
<!-- <scope>provided</scope> -->
|
||||||
|
<!-- <exclusions> -->
|
||||||
|
<!-- <exclusion> -->
|
||||||
|
<!-- <artifactId>asm-all</artifactId> -->
|
||||||
|
<!-- <groupId>asm</groupId> -->
|
||||||
|
<!-- </exclusion> -->
|
||||||
|
<!-- </exclusions> -->
|
||||||
|
<!-- </dependency> -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-httpclient</groupId>
|
<groupId>commons-httpclient</groupId>
|
||||||
|
|
|
@ -10,7 +10,6 @@ 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 org.gcube.common.homelibrary.util.Extensions;
|
|
||||||
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
|
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -42,8 +41,6 @@ public class WorkspaceUploadServlet extends HttpServlet {
|
||||||
|
|
||||||
public static final String FILE = "File";
|
public static final String FILE = "File";
|
||||||
|
|
||||||
public static final String D4ST = Extensions.REPORT_TEMPLATE.getName(); //extension of Report Template type
|
|
||||||
public static final String D4SR = Extensions.REPORT.getName(); //extension of Report type
|
|
||||||
|
|
||||||
public static Logger logger = LoggerFactory.getLogger(WorkspaceUploadServlet.class);
|
public static Logger logger = LoggerFactory.getLogger(WorkspaceUploadServlet.class);
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,7 @@
|
||||||
package org.gcube.portlets.widgets.workspaceuploader.server;
|
package org.gcube.portlets.widgets.workspaceuploader.server;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -28,26 +26,17 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||||
import org.apache.commons.fileupload.util.Streams;
|
import org.apache.commons.fileupload.util.Streams;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
|
||||||
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
|
||||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
|
||||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
|
|
||||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
|
||||||
import org.gcube.common.homelibrary.home.workspace.exceptions.InsufficientPrivilegesException;
|
|
||||||
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException;
|
|
||||||
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
|
|
||||||
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
|
||||||
import org.gcube.common.homelibrary.home.workspace.exceptions.WrongDestinationException;
|
|
||||||
import org.gcube.common.homelibrary.home.workspace.exceptions.WrongItemTypeException;
|
|
||||||
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
|
|
||||||
import org.gcube.common.homelibrary.home.workspace.folder.items.Report;
|
|
||||||
import org.gcube.common.homelibrary.home.workspace.folder.items.ReportTemplate;
|
|
||||||
import org.gcube.common.homelibrary.util.Extensions;
|
|
||||||
import org.gcube.common.homelibrary.util.MimeTypeUtil;
|
|
||||||
import org.gcube.common.homelibrary.util.WorkspaceUtil;
|
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.common.portal.PortalContext;
|
||||||
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
|
import org.gcube.portal.storagehubwrapper.server.StorageHubWrapper;
|
||||||
|
import org.gcube.portal.storagehubwrapper.shared.tohl.WorkspaceFolder;
|
||||||
|
import org.gcube.portal.storagehubwrapper.shared.tohl.WorkspaceItem;
|
||||||
|
import org.gcube.portal.storagehubwrapper.shared.tohl.WorkspaceItemType;
|
||||||
|
import org.gcube.portal.storagehubwrapper.shared.tohl.exceptions.InsufficientPrivilegesException;
|
||||||
|
import org.gcube.portal.storagehubwrapper.shared.tohl.exceptions.InternalErrorException;
|
||||||
|
import org.gcube.portal.storagehubwrapper.shared.tohl.exceptions.ItemAlreadyExistException;
|
||||||
|
import org.gcube.portal.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException;
|
||||||
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.NotificationsWorkspaceUploaderProducer;
|
import org.gcube.portlets.widgets.workspaceuploader.server.notification.NotificationsWorkspaceUploaderProducer;
|
||||||
import org.gcube.portlets.widgets.workspaceuploader.server.upload.AbstractUploadProgressListener;
|
import org.gcube.portlets.widgets.workspaceuploader.server.upload.AbstractUploadProgressListener;
|
||||||
import org.gcube.portlets.widgets.workspaceuploader.server.upload.MemoryUploadListener;
|
import org.gcube.portlets.widgets.workspaceuploader.server.upload.MemoryUploadListener;
|
||||||
|
@ -104,8 +93,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
||||||
|
|
||||||
public static final String FILE = "File";
|
public static final String FILE = "File";
|
||||||
|
|
||||||
public static final String D4ST = Extensions.REPORT_TEMPLATE.getName(); //extension of Report Template type
|
// public static final String D4ST = Extensions.REPORT_TEMPLATE.getName(); //extension of Report Template type
|
||||||
public static final String D4SR = Extensions.REPORT.getName(); //extension of Report type
|
// public static final String D4SR = Extensions.REPORT.getName(); //extension of Report type
|
||||||
|
|
||||||
public static Logger logger = LoggerFactory.getLogger(WorkspaceUploadServletStream.class);
|
public static Logger logger = LoggerFactory.getLogger(WorkspaceUploadServletStream.class);
|
||||||
|
|
||||||
|
@ -406,12 +395,9 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
||||||
// response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error processing request in upload servlet");
|
// response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error processing request in upload servlet");
|
||||||
// return;
|
// return;
|
||||||
|
|
||||||
Workspace wa = null;
|
StorageHubWrapper storageHubWrapper;
|
||||||
GCubeUser currUser;
|
|
||||||
try {
|
try {
|
||||||
logger.debug("getWorkspace from HL scopeGroupId="+scopeGroupId +", userId="+user);
|
storageHubWrapper = WsUtil.getStorageHubWrapper(request, scopeGroupId, user);
|
||||||
currUser = PortalContext.getConfiguration().getCurrentUser(request);
|
|
||||||
wa = WsUtil.getWorkspace(request, scopeGroupId, currUser);
|
|
||||||
} 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());
|
||||||
|
@ -419,18 +405,18 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wa == null) {
|
if (storageHubWrapper == null) {
|
||||||
logger.error("Now workspace found in session");
|
logger.error("Now workspace found in session");
|
||||||
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "An error occurred during upload: "+fileName+". No workspace in session", request.getSession());
|
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "An error occurred during upload: "+fileName+". No workspace in session", request.getSession());
|
||||||
sendError(response, "Internal error: No workspace in session");
|
sendError(response, "Internal error: No workspace retrieved");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkspaceItem item = null;
|
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 = storageHubWrapper.getWorkspace().getItem(destinationId);
|
||||||
} catch (ItemNotFoundException e) {
|
} catch (ItemNotFoundException | InternalErrorException e) {
|
||||||
logger.error("Error, no destination folder found", e);
|
logger.error("Error, no destination folder found", e);
|
||||||
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");
|
||||||
|
@ -450,7 +436,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
||||||
String itemName = "";
|
String itemName = "";
|
||||||
|
|
||||||
logger.debug("getItemName from HL");
|
logger.debug("getItemName from HL");
|
||||||
if(!isOverwrite){
|
/*if(!isOverwrite){
|
||||||
itemName = WorkspaceUtil.getUniqueName(fileName, destinationFolder);
|
itemName = WorkspaceUtil.getUniqueName(fileName, destinationFolder);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
@ -468,7 +454,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
||||||
isOverwrite = false;
|
isOverwrite = false;
|
||||||
itemName = fileName;
|
itemName = fileName;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
Long size = getContentLength(request);
|
Long size = getContentLength(request);
|
||||||
logger.debug("size: " + size + " bytes");
|
logger.debug("size: " + size + " bytes");
|
||||||
|
@ -505,52 +491,53 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
||||||
|
|
||||||
if(uploadType.compareTo(FILE)==0) {//IS FILE UPLOAD
|
if(uploadType.compareTo(FILE)==0) {//IS FILE UPLOAD
|
||||||
|
|
||||||
boolean isZipFile = MimeTypeUtil.isZipContentType(uploadItem.getContentType()); //UNZIP??
|
// boolean isZipFile = MimeTypeUtil.isZipContentType(uploadItem.getContentType()); //UNZIP??
|
||||||
|
//
|
||||||
|
// if(isZipFile && extension.compareToIgnoreCase(D4ST)==0){ //Create REPORT TEMPLATE
|
||||||
|
//
|
||||||
|
// String newItemName = itemName;
|
||||||
|
// logger.debug("createTemplate: "+newItemName);
|
||||||
|
//
|
||||||
|
// createTemplate(user, scopeGroupId, request, workspaceUploader, request.getSession(), wa, newItemName, inputStream, destinationFolder, response, isOverwrite);
|
||||||
|
//
|
||||||
|
// }else if(isZipFile && extension.compareToIgnoreCase(D4SR)==0){ //Create REPORT
|
||||||
|
//
|
||||||
|
// String newItemName = itemName;
|
||||||
|
// logger.debug("createReport: "+newItemName);
|
||||||
|
// createReport(user, scopeGroupId, request, workspaceUploader, request.getSession(), wa, newItemName, inputStream, destinationFolder, response, isOverwrite);
|
||||||
|
// }else{ //CREATE AN EXTERNAL FILE
|
||||||
|
|
||||||
if(isZipFile && extension.compareToIgnoreCase(D4ST)==0){ //Create REPORT TEMPLATE
|
workspaceUploader = WorkspaceUploaderMng.uploadFile(storageHubWrapper, user, scopeGroupId, request, workspaceUploader, request.getSession(), itemName, inputStream, destinationFolder, contentType, isOverwrite, size);
|
||||||
|
|
||||||
String newItemName = itemName;
|
|
||||||
logger.debug("createTemplate: "+newItemName);
|
|
||||||
|
|
||||||
createTemplate(user, scopeGroupId, request, workspaceUploader, request.getSession(), wa, newItemName, inputStream, destinationFolder, response, isOverwrite);
|
|
||||||
|
|
||||||
}else if(isZipFile && extension.compareToIgnoreCase(D4SR)==0){ //Create REPORT
|
|
||||||
|
|
||||||
String newItemName = itemName;
|
|
||||||
logger.debug("createReport: "+newItemName);
|
|
||||||
createReport(user, scopeGroupId, request, workspaceUploader, request.getSession(), wa, newItemName, inputStream, destinationFolder, response, isOverwrite);
|
|
||||||
}else{ //CREATE AN EXTERNAL FILE
|
|
||||||
|
|
||||||
workspaceUploader = WorkspaceUploaderMng.uploadFile(user, 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!");
|
||||||
|
|
||||||
sendMessage(response, workspaceUploader.getIdentifier());
|
sendMessage(response, workspaceUploader.getIdentifier());
|
||||||
}
|
// }
|
||||||
|
|
||||||
}else {//IS ARCHIVE UPLOAD
|
}else {//IS ARCHIVE UPLOAD
|
||||||
|
|
||||||
logger.debug("Archive content type: "+uploadItem.getContentType());
|
//TODO UPLOAD ARCHIVE
|
||||||
|
// logger.debug("Archive content type: "+uploadItem.getContentType());
|
||||||
if (MimeTypeUtil.isZipContentType(uploadItem.getContentType())){ //UNZIP??
|
//
|
||||||
logger.debug("Unziping content");
|
// if (MimeTypeUtil.isZipContentType(uploadItem.getContentType())){ //UNZIP??
|
||||||
//THE WORKSPACE HAS BEEN INSTANCIED ABOVE
|
// logger.debug("Unziping content");
|
||||||
workspaceUploader = WorkspaceUploaderMng.uploadArchive(user, scopeGroupId, workspaceUploader, request, itemName, inputStream, destinationFolder, size);
|
// //THE WORKSPACE HAS BEEN INSTANCIED ABOVE
|
||||||
|
// workspaceUploader = WorkspaceUploaderMng.uploadArchive(user, scopeGroupId, workspaceUploader, request, itemName, inputStream, destinationFolder, size);
|
||||||
if(workspaceUploader==null)
|
//
|
||||||
throw new Exception("Error when creating uploader, it is null!");
|
// if(workspaceUploader==null)
|
||||||
|
// throw new Exception("Error when creating uploader, it is null!");
|
||||||
sendMessage(response, workspaceUploader.getIdentifier());
|
//
|
||||||
} else{
|
// sendMessage(response, workspaceUploader.getIdentifier());
|
||||||
//THE WORKSPACE HAS BEEN INSTANCIED ABOVE
|
// } else{
|
||||||
workspaceUploader = WorkspaceUploaderMng.uploadFile(user, scopeGroupId, request, workspaceUploader, request.getSession(), wa, itemName, inputStream, destinationFolder, contentType, isOverwrite, size);
|
// //THE WORKSPACE HAS BEEN INSTANCIED ABOVE
|
||||||
|
// workspaceUploader = WorkspaceUploaderMng.uploadFile(user, scopeGroupId, request, workspaceUploader, request.getSession(), wa, itemName, inputStream, destinationFolder, contentType, isOverwrite, size);
|
||||||
if(workspaceUploader==null)
|
//
|
||||||
throw new Exception("Error when creating uploader, it is null!");
|
// if(workspaceUploader==null)
|
||||||
|
// throw new Exception("Error when creating uploader, it is null!");
|
||||||
sendMessage(response, workspaceUploader.getIdentifier());
|
//
|
||||||
}
|
// sendMessage(response, workspaceUploader.getIdentifier());
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
//saveWorkspaceUploaderInSession(workspaceUploader, request.getSession());
|
//saveWorkspaceUploaderInSession(workspaceUploader, request.getSession());
|
||||||
|
@ -687,6 +674,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
||||||
/**
|
/**
|
||||||
* Notify upload in shared folder.
|
* Notify upload in shared folder.
|
||||||
*
|
*
|
||||||
|
* @param storageWrapper the storage wrapper
|
||||||
* @param currUser the curr user
|
* @param currUser the curr user
|
||||||
* @param scopeGroupId the scope group id
|
* @param scopeGroupId the scope group id
|
||||||
* @param request the request
|
* @param request the request
|
||||||
|
@ -696,18 +684,22 @@ 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 GCubeUser currUser, final String scopeGroupId, final HttpServletRequest request, final HttpSession httpSession, final Workspace workspace, final String itemId, final String destinationFolderId, final boolean isOverwrite){
|
public static void notifyUploadInSharedFolder(final StorageHubWrapper storageWrapper, final GCubeUser currUser, final String scopeGroupId, final HttpServletRequest request, final HttpSession httpSession, 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(scopeGroupId, httpSession,request);
|
final NotificationsWorkspaceUploaderProducer np = new NotificationsWorkspaceUploaderProducer(scopeGroupId, httpSession,request);
|
||||||
new Thread(){
|
new Thread(){
|
||||||
public void run() {
|
public void run() {
|
||||||
WorkspaceItem sourceItem;
|
//Item sourceItem;
|
||||||
try {
|
try {
|
||||||
sourceItem = workspace.getItem(itemId);
|
Item sourceItem = storageWrapper.getStorageHubClientService().getItem(itemId);
|
||||||
String sourceSharedId = sourceItem.getIdSharedFolder();
|
|
||||||
WorkspaceItem folderDestinationItem = workspace.getItem(destinationFolderId);
|
//TODO sourceItem.getIdSharedFolder();
|
||||||
|
/*String sourceSharedId = sourceItem.getIdSharedFolder();
|
||||||
|
Item folderDestinationItem = storageWrapper.getStorageHubClientService().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(request, currUser, scopeGroupId, np, httpSession, sourceItem, sourceSharedId, folderDestinationItem,isOverwrite);
|
NotificationsWorkspaceUploader.checkSendNotifyChangedItemToShare(storageWrapper, request, currUser, scopeGroupId, np, httpSession, sourceItem, sourceSharedId, folderDestinationItem,isOverwrite);
|
||||||
|
*/
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Error in notifyUploadInSharedFolder", e);
|
logger.error("Error in notifyUploadInSharedFolder", e);
|
||||||
}
|
}
|
||||||
|
@ -716,177 +708,45 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Overwrite item.
|
// * Overwrite item.
|
||||||
*
|
// *
|
||||||
* @param wa the wa
|
// * @param wa the wa
|
||||||
* @param itemName the item name
|
// * @param itemName the item name
|
||||||
* @param fileData the file data
|
// * @param fileData the file data
|
||||||
* @param destinationFolder the destination folder
|
// * @param destinationFolder the destination folder
|
||||||
* @return the folder item
|
// * @return the folder item
|
||||||
*/
|
// */
|
||||||
private FolderItem overwriteItem(Workspace wa, String itemName, InputStream fileData, WorkspaceFolder destinationFolder){
|
// private FileItem overwriteItem(Workspace wa, String itemName, InputStream fileData, WorkspaceFolder destinationFolder){
|
||||||
|
//
|
||||||
FolderItem overwriteItem = null;
|
// FileItem overwriteItem = null;
|
||||||
|
//
|
||||||
try {
|
// try {
|
||||||
logger.debug("case overwriting item.. "+itemName);
|
// logger.debug("case overwriting item.. "+itemName);
|
||||||
overwriteItem = (FolderItem) wa.find(itemName, destinationFolder.getId());
|
// overwriteItem = (FileItem) wa.find(itemName, destinationFolder.getId());
|
||||||
logger.debug("overwriteItem item was found, id is: "+overwriteItem.getId());
|
// logger.debug("overwriteItem item was found, id is: "+overwriteItem.getId());
|
||||||
wa.updateItem(overwriteItem.getId(), fileData);
|
// wa.upl(overwriteItem.getId(), fileData);
|
||||||
logger.debug("updateItem with id: "+overwriteItem.getId()+ ", is completed");
|
// logger.debug("updateItem with id: "+overwriteItem.getId()+ ", is completed");
|
||||||
} catch (ItemNotFoundException e) {
|
// } catch (ItemNotFoundException e) {
|
||||||
logger.error("Error in createExternalFile, ItemNotFoundException", e);
|
// logger.error("Error in createExternalFile, ItemNotFoundException", e);
|
||||||
} catch (WrongItemTypeException e) {
|
// } catch (WrongItemTypeException e) {
|
||||||
logger.error("Error in createExternalFile, WrongItemTypeException", e);
|
// logger.error("Error in createExternalFile, WrongItemTypeException", e);
|
||||||
} catch (WorkspaceFolderNotFoundException e) {
|
// } catch (WorkspaceFolderNotFoundException e) {
|
||||||
logger.error("Error in createExternalFile, WorkspaceFolderNotFoundException", e);
|
// logger.error("Error in createExternalFile, WorkspaceFolderNotFoundException", e);
|
||||||
} catch (WrongDestinationException e) {
|
// } catch (WrongDestinationException e) {
|
||||||
logger.error("Error in createExternalFile, WrongDestinationException", e);
|
// logger.error("Error in createExternalFile, WrongDestinationException", e);
|
||||||
} catch (InsufficientPrivilegesException e) {
|
// } catch (InsufficientPrivilegesException e) {
|
||||||
logger.error("Error in createExternalFile, InsufficientPrivilegesException", e);
|
// logger.error("Error in createExternalFile, InsufficientPrivilegesException", e);
|
||||||
} catch (ItemAlreadyExistException e) {
|
// } catch (ItemAlreadyExistException e) {
|
||||||
logger.error("Error in createExternalFile, ItemAlreadyExistException", e);
|
// logger.error("Error in createExternalFile, ItemAlreadyExistException", e);
|
||||||
} catch (InternalErrorException e) {
|
// } catch (InternalErrorException e) {
|
||||||
logger.error("Error in createExternalFile, InternalErrorException", e);
|
// logger.error("Error in createExternalFile, InternalErrorException", e);
|
||||||
}catch (Exception e) {
|
// }catch (Exception e) {
|
||||||
logger.error("Error in createExternalFile, Exception", e);
|
// logger.error("Error in createExternalFile, Exception", e);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return overwriteItem;
|
// return overwriteItem;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the report.
|
|
||||||
*
|
|
||||||
* @param currUser the curr user
|
|
||||||
* @param scopeGroupId the scope group id
|
|
||||||
* @param request the request
|
|
||||||
* @param workspaceUploader the workspace uploader
|
|
||||||
* @param httpSession the http session
|
|
||||||
* @param wa the wa
|
|
||||||
* @param itemName the item name
|
|
||||||
* @param fileInputStream the file input stream
|
|
||||||
* @param destinationFolder the destination folder
|
|
||||||
* @param response the response
|
|
||||||
* @param isOverwrite the is overwrite
|
|
||||||
* @throws InsufficientPrivilegesException the insufficient privileges exception
|
|
||||||
* @throws ItemAlreadyExistException the item already exist exception
|
|
||||||
* @throws InternalErrorException the internal error exception
|
|
||||||
* @throws IOException Signals that an I/O exception has occurred.
|
|
||||||
*/
|
|
||||||
private void createReport(GCubeUser currUser, 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 {
|
|
||||||
|
|
||||||
Report report = null;
|
|
||||||
|
|
||||||
if(!isOverwrite){
|
|
||||||
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
|
|
||||||
report = wa.createReport(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", "", 0, "",fileInputStream, destinationFolder.getId());
|
|
||||||
|
|
||||||
notifyUploadInSharedFolder(currUser, scopeGroupId, request, httpSession,wa,report.getId(),destinationFolder.getId(), isOverwrite);
|
|
||||||
sendMessage(response, "File "+report.getName()+" imported correctly in "+destinationFolder.getPath());
|
|
||||||
}
|
|
||||||
else{ //CASE OVERWRITE
|
|
||||||
FolderItem rep = overwriteItem(wa, itemName, fileInputStream, destinationFolder);
|
|
||||||
|
|
||||||
if(rep!=null){
|
|
||||||
|
|
||||||
notifyUploadInSharedFolder(currUser, scopeGroupId, request, httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite);
|
|
||||||
sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
sendError(response,"Internal error: Workspace Item Not Found");
|
|
||||||
}
|
|
||||||
} catch (WrongDestinationException e) {
|
|
||||||
logger.error("Error creating elements", e);
|
|
||||||
workspaceUploader.setStatusDescription("An error occurred in the upload. Wrong Destination");
|
|
||||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
|
|
||||||
sendError(response, "Internal error: Wrong Destination");
|
|
||||||
} catch (WorkspaceFolderNotFoundException e) {
|
|
||||||
logger.error("Error creating elements", e);
|
|
||||||
workspaceUploader.setStatusDescription("An error occurred in the upload. Workspace Folder Not Found");
|
|
||||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
|
|
||||||
sendError(response, "Internal error: Workspace Folder Not Found");
|
|
||||||
}finally{
|
|
||||||
try {
|
|
||||||
// StreamUtils.deleteTempFile(file);
|
|
||||||
WsUtil.setErasableWorkspaceUploaderInSession(request, workspaceUploader.getIdentifier());
|
|
||||||
} catch (Exception e2) {
|
|
||||||
// TODO: handle exception
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the template.
|
|
||||||
*
|
|
||||||
* @param currUser the curr user
|
|
||||||
* @param scopeGroupId the scope group id
|
|
||||||
* @param request the request
|
|
||||||
* @param workspaceUploader the workspace uploader
|
|
||||||
* @param httpSession the http session
|
|
||||||
* @param wa the wa
|
|
||||||
* @param itemName the item name
|
|
||||||
* @param fileInputStream the file input stream
|
|
||||||
* @param destinationFolder the destination folder
|
|
||||||
* @param response the response
|
|
||||||
* @param isOverwrite the is overwrite
|
|
||||||
* @throws InsufficientPrivilegesException the insufficient privileges exception
|
|
||||||
* @throws ItemAlreadyExistException the item already exist exception
|
|
||||||
* @throws InternalErrorException the internal error exception
|
|
||||||
* @throws IOException Signals that an I/O exception has occurred.
|
|
||||||
*/
|
|
||||||
private void createTemplate(GCubeUser currUser, 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 {
|
|
||||||
|
|
||||||
ReportTemplate template = null;
|
|
||||||
|
|
||||||
if(!isOverwrite){
|
|
||||||
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
|
|
||||||
template = wa.createReportTemplate(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", 0, "", fileInputStream, destinationFolder.getId());
|
|
||||||
|
|
||||||
notifyUploadInSharedFolder(currUser, scopeGroupId, request, httpSession,wa,template.getId(),destinationFolder.getId(), isOverwrite);
|
|
||||||
sendMessage(response, "File "+template.getName()+" imported correctly in "+destinationFolder.getPath());
|
|
||||||
|
|
||||||
}else{ //CASE OVERWRITE
|
|
||||||
FolderItem rep = overwriteItem(wa, itemName, fileInputStream, destinationFolder);
|
|
||||||
|
|
||||||
if(rep!=null){
|
|
||||||
|
|
||||||
notifyUploadInSharedFolder(currUser, scopeGroupId, request, httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite);
|
|
||||||
sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
sendError(response,"Internal error: Workspace Item Not Found");
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (WrongDestinationException e) {
|
|
||||||
logger.error("Error creating elements", e);
|
|
||||||
workspaceUploader.setStatusDescription("An error occurred in the upload. Wrong Destination");
|
|
||||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
|
|
||||||
sendError(response, "Internal error: Wrong Destination");
|
|
||||||
} catch (WorkspaceFolderNotFoundException e) {
|
|
||||||
logger.error("Error creating elements", e);
|
|
||||||
workspaceUploader.setStatusDescription("An error occurred in the upload. Workspace Folder Not Found");
|
|
||||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
|
|
||||||
sendError(response, "Internal error: Workspace Folder Not Found");
|
|
||||||
}finally{
|
|
||||||
try {
|
|
||||||
// StreamUtils.deleteTempFile(fileInputStream);
|
|
||||||
WsUtil.setErasableWorkspaceUploaderInSession(request, workspaceUploader.getIdentifier());
|
|
||||||
} catch (Exception e2) {
|
|
||||||
// TODO: handle exception
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,10 +3,10 @@ package org.gcube.portlets.widgets.workspaceuploader.server;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
|
||||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
|
||||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.common.portal.PortalContext;
|
||||||
|
import org.gcube.common.storagehub.model.types.WorkspaceItemType;
|
||||||
|
import org.gcube.portal.storagehubwrapper.server.StorageHubWrapper;
|
||||||
|
import org.gcube.portal.storagehubwrapper.shared.tohl.WorkspaceItem;
|
||||||
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;
|
||||||
|
@ -18,11 +18,12 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The server side implementation of the RPC service.
|
* The Class WorkspaceUploaderServiceImpl.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||||
* May 12, 2016
|
* Jun 25, 2018
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implements WorkspaceUploaderService {
|
public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implements WorkspaceUploaderService {
|
||||||
|
@ -72,7 +73,7 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement
|
||||||
/**
|
/**
|
||||||
* Check uploader erasable.
|
* Check uploader erasable.
|
||||||
*
|
*
|
||||||
* @param httpSession the http session
|
* @param httpRequest the http request
|
||||||
* @param uploader the uploader
|
* @param uploader the uploader
|
||||||
*/
|
*/
|
||||||
private void checkUploaderErasable(final HttpServletRequest httpRequest, final WorkspaceUploaderItem uploader){
|
private void checkUploaderErasable(final HttpServletRequest httpRequest, final WorkspaceUploaderItem uploader){
|
||||||
|
@ -106,13 +107,12 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement
|
||||||
@Override
|
@Override
|
||||||
public String getWorkspaceId() throws Exception {
|
public String getWorkspaceId() throws Exception {
|
||||||
logger.trace("getWorkspaceId");
|
logger.trace("getWorkspaceId");
|
||||||
Workspace workspace;
|
|
||||||
try {
|
try {
|
||||||
String scopeGroupId = ""+PortalContext.getConfiguration().getCurrentGroupId(getThreadLocalRequest());
|
String scopeGroupId = ""+PortalContext.getConfiguration().getCurrentGroupId(getThreadLocalRequest());
|
||||||
GCubeUser currUser = PortalContext.getConfiguration().getCurrentUser(getThreadLocalRequest());
|
GCubeUser currUser = PortalContext.getConfiguration().getCurrentUser(getThreadLocalRequest());
|
||||||
workspace = WsUtil.getWorkspace(getThreadLocalRequest(), scopeGroupId, currUser);
|
StorageHubWrapper stHubWrapper = WsUtil.getStorageHubWrapper(getThreadLocalRequest(), scopeGroupId, currUser);
|
||||||
if(workspace!=null)
|
if(stHubWrapper.getWorkspace()!=null)
|
||||||
return workspace.getRoot().getId();
|
return stHubWrapper.getWorkspace().getRoot().getId();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Get workspace id error", e);
|
logger.error("Get workspace id error", e);
|
||||||
String error = "An error occurred getting root id";
|
String error = "An error occurred getting root id";
|
||||||
|
@ -132,17 +132,20 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement
|
||||||
try {
|
try {
|
||||||
String scopeGroupId = ""+PortalContext.getConfiguration().getCurrentGroupId(getThreadLocalRequest());
|
String scopeGroupId = ""+PortalContext.getConfiguration().getCurrentGroupId(getThreadLocalRequest());
|
||||||
GCubeUser currUser = PortalContext.getConfiguration().getCurrentUser(getThreadLocalRequest());
|
GCubeUser currUser = PortalContext.getConfiguration().getCurrentUser(getThreadLocalRequest());
|
||||||
Workspace workspace = WsUtil.getWorkspace(getThreadLocalRequest(), scopeGroupId, currUser);
|
StorageHubWrapper stHubWrapper = WsUtil.getStorageHubWrapper(getThreadLocalRequest(), scopeGroupId, currUser);
|
||||||
WorkspaceItem wsItem = workspace.getItem(parentId); //GET PARENT
|
WorkspaceItem wsItem = stHubWrapper.getWorkspace().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)){
|
||||||
|
|
||||||
WorkspaceItem itemFound = workspace.find(itemName, parentId);
|
//TODO workspace.find(itemName, parentId);
|
||||||
|
/*WorkspaceItem itemFound = workspace.find(itemName, parentId);
|
||||||
|
|
||||||
if(itemFound==null)
|
if(itemFound==null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return itemFound.getId();
|
return itemFound.getId();*/
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw new Exception("Invalid Folder parent");
|
throw new Exception("Invalid Folder parent");
|
||||||
|
|
|
@ -7,10 +7,11 @@ 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 org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
import org.gcube.common.storagehub.model.types.WorkspaceItemType;
|
||||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
import org.gcube.portal.storagehubwrapper.server.StorageHubWrapper;
|
||||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
import org.gcube.portal.storagehubwrapper.server.tohl.Workspace;
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.portal.storagehubwrapper.server.util.PortalContextUtil;
|
||||||
|
import org.gcube.portal.storagehubwrapper.shared.tohl.WorkspaceItem;
|
||||||
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.gcube.vomanagement.usermanagement.model.GCubeUser;
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||||
|
@ -31,24 +32,39 @@ public class WorkspaceUploaderWsUtil extends HttpServlet {
|
||||||
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
|
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
String folderParentId = req.getParameter(ConstantsWorkspaceUploader.FOLDER_PARENT_ID);
|
String folderParentId = request.getParameter(ConstantsWorkspaceUploader.FOLDER_PARENT_ID);
|
||||||
String itemName = req.getParameter(ConstantsWorkspaceUploader.ITEM_NAME);
|
String itemName = request.getParameter(ConstantsWorkspaceUploader.ITEM_NAME);
|
||||||
String currGroupId = req.getParameter(ConstantsWorkspaceUploader.CURR_GROUP_ID);
|
String currGroupId = request.getParameter(ConstantsWorkspaceUploader.CURR_GROUP_ID);
|
||||||
//String currUserId = req.getParameter(ConstantsWorkspaceUploader.CURR_USER_ID);
|
//String currUserId = req.getParameter(ConstantsWorkspaceUploader.CURR_USER_ID);
|
||||||
logger.debug("folderParentId: "+folderParentId);
|
logger.debug("folderParentId: "+folderParentId);
|
||||||
logger.debug("itemName: "+itemName);
|
logger.debug("itemName: "+itemName);
|
||||||
logger.debug("currGroupId: "+currGroupId);
|
logger.debug("currGroupId: "+currGroupId);
|
||||||
|
|
||||||
|
if(currGroupId==null || currGroupId.isEmpty())
|
||||||
|
sendError(response, "Parameter error: currGroupId is null or empty");
|
||||||
//logger.debug("currUserId: "+currUserId);
|
//logger.debug("currUserId: "+currUserId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String itemId = itemExistsInWorkpaceFolder(currGroupId, req, folderParentId, itemName);
|
|
||||||
sendOKMessage(resp, itemId);
|
Workspace wa = null;
|
||||||
|
//GCubeUser currUser;
|
||||||
|
try {
|
||||||
|
GCubeUser user = PortalContextUtil.getCurrentUser(request);
|
||||||
|
StorageHubWrapper storageWrapper = WsUtil.getStorageHubWrapper(request, currGroupId, user);
|
||||||
|
wa = storageWrapper.getWorkspace();
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error during workspace retrieving", e);
|
||||||
|
sendError(response, "An error occurred during item exists check");
|
||||||
|
}
|
||||||
|
|
||||||
|
String itemId = itemExistsInWorkpaceFolder(wa, folderParentId, itemName);
|
||||||
|
sendOKMessage(response, itemId);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
logger.error("An error occurred during item exists check",e);
|
logger.error("An error occurred during item exists check",e);
|
||||||
sendError(resp, "An error occurred during item exists check");
|
sendError(response, "An error occurred during item exists check");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,15 +79,13 @@ public class WorkspaceUploaderWsUtil extends HttpServlet {
|
||||||
* @return the string
|
* @return the string
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public String itemExistsInWorkpaceFolder(String currGroupId, HttpServletRequest req, String parentId, String itemName) throws Exception {
|
public String itemExistsInWorkpaceFolder(Workspace workspace, 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 {
|
||||||
GCubeUser gcubeUser = PortalContext.getConfiguration().getCurrentUser(req);
|
// //IN THIS CASE THE SESSION EXPIRED IS MANAGED BY UPLOAD SERVLET
|
||||||
//IN THIS CASE THE SESSION EXPIRED IS MANAGED BY UPLOAD SERVLET
|
// if(gcubeUser==null)
|
||||||
if(gcubeUser==null)
|
// return null;
|
||||||
return null;
|
|
||||||
|
|
||||||
Workspace workspace = WsUtil.getWorkspace(req, currGroupId, gcubeUser);
|
|
||||||
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)){
|
||||||
|
|
|
@ -10,12 +10,11 @@ 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.common.homelibary.model.items.type.WorkspaceItemType;
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
import org.gcube.common.storagehub.model.types.WorkspaceItemType;
|
||||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
import org.gcube.portal.storagehubwrapper.server.StorageHubWrapper;
|
||||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder;
|
import org.gcube.portal.storagehubwrapper.server.tohl.Workspace;
|
||||||
import org.gcube.portlets.widgets.workspaceuploader.server.util.UserUtil;
|
import org.gcube.portal.storagehubwrapper.shared.tohl.WorkspaceItem;
|
||||||
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;
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||||
|
|
||||||
|
@ -33,6 +32,7 @@ public class NotificationsWorkspaceUploader {
|
||||||
/**
|
/**
|
||||||
* Check send notify changed item to share.
|
* Check send notify changed item to share.
|
||||||
*
|
*
|
||||||
|
* @param storageWrapper the storage wrapper
|
||||||
* @param request the request
|
* @param request the request
|
||||||
* @param currUser the curr user
|
* @param currUser the curr user
|
||||||
* @param scopeGroupId the scope group id
|
* @param scopeGroupId the scope group id
|
||||||
|
@ -43,7 +43,7 @@ public class NotificationsWorkspaceUploader {
|
||||||
* @param folderDestinationItem the folder destination item
|
* @param folderDestinationItem the folder destination item
|
||||||
* @param isOverwrite the is overwrite
|
* @param isOverwrite the is overwrite
|
||||||
*/
|
*/
|
||||||
public static void checkSendNotifyChangedItemToShare(HttpServletRequest request, GCubeUser currUser, String scopeGroupId, NotificationsWorkspaceUploaderProducer np, HttpSession httpSession, final WorkspaceItem sourceItem, final String sourceSharedId, final WorkspaceItem folderDestinationItem, boolean isOverwrite) {
|
public static void checkSendNotifyChangedItemToShare(StorageHubWrapper storageWrapper, HttpServletRequest request, GCubeUser currUser, String scopeGroupId, NotificationsWorkspaceUploaderProducer np, HttpSession httpSession, final Item sourceItem, final String sourceSharedId, final Item folderDestinationItem, boolean isOverwrite) {
|
||||||
|
|
||||||
logger.trace("checkSendNotifyAddItemToShare");
|
logger.trace("checkSendNotifyAddItemToShare");
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ public class NotificationsWorkspaceUploader {
|
||||||
try{
|
try{
|
||||||
if(folderDestinationItem.isShared()){ //Notify Added Item To Sharing?
|
if(folderDestinationItem.isShared()){ //Notify Added Item To Sharing?
|
||||||
|
|
||||||
|
/* TODO folderDestinationItem.getIdSharedFolder()
|
||||||
logger.trace("checkNotifyAddItemToShare source item: "+sourceItem.getName()+" sourceSharedId: "+sourceSharedId + " folder destination: "+folderDestinationItem.getName() + " folder destination shared folder id: "+folderDestinationItem.getIdSharedFolder());
|
logger.trace("checkNotifyAddItemToShare source item: "+sourceItem.getName()+" sourceSharedId: "+sourceSharedId + " folder destination: "+folderDestinationItem.getName() + " folder destination shared folder id: "+folderDestinationItem.getIdSharedFolder());
|
||||||
|
|
||||||
//share condition is true if source shared folder is not null
|
//share condition is true if source shared folder is not null
|
||||||
|
@ -64,26 +65,28 @@ 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(request, scopeGroupId, currUser);
|
//Workspace workspace = WsUtil.getWorkspace(request, scopeGroupId, currUser);
|
||||||
|
//Workspace workspace = storageWrapper.getWorkspace();
|
||||||
|
|
||||||
List<ContactModel> listContacts = getListUserSharedByFolderSharedId(workspace, folderDestinationItem.getIdSharedFolder());
|
//TODO
|
||||||
|
List<ContactModel> listContacts = getListUserSharedByFolderSharedId(storageWrapper.getWorkspace(), folderDestinationItem.getIdSharedFolder());
|
||||||
|
|
||||||
WorkspaceItem destinationSharedFolder = workspace.getItem(folderDestinationItem.getIdSharedFolder());
|
Item destinationSharedFolder = storageWrapper.getStorageHubClientService().getItem(folderDestinationItem.getIdSharedFolder());
|
||||||
|
|
||||||
if(destinationSharedFolder instanceof WorkspaceSharedFolder){
|
if(destinationSharedFolder instanceof WorkspaceSharedFolder){
|
||||||
|
|
||||||
//SWITCH BEETWEEN ADDED OR UPDATED
|
//SWITCH BEETWEEN ADDED OR UPDATED
|
||||||
if(!isOverwrite)
|
if(!isOverwrite)
|
||||||
np.notifyAddedItemToSharing(listContacts, sourceItem, (WorkspaceSharedFolder) destinationSharedFolder);
|
np.notifyAddedItemToSharing(listContacts, sourceItem, destinationSharedFolder);
|
||||||
else
|
else
|
||||||
np.notifyUpdatedItemToSharing(listContacts, sourceItem, (WorkspaceSharedFolder) destinationSharedFolder);
|
np.notifyUpdatedItemToSharing(listContacts, sourceItem, destinationSharedFolder);
|
||||||
|
|
||||||
|
|
||||||
logger.trace("The notifies was sent correctly");
|
logger.trace("The notifies was sent correctly");
|
||||||
}else
|
}else
|
||||||
logger.trace("The notifies doesn't sent because "+destinationSharedFolder+ " is not instance of WorkspaceSharedFolder");
|
logger.trace("The notifies doesn't sent because "+destinationSharedFolder+ " is not instance of WorkspaceSharedFolder");
|
||||||
// np.notifyAddedItemToSharing(listContacts, (WorkspaceFolder) folderDestinationItem);
|
// np.notifyAddedItemToSharing(listContacts, (WorkspaceFolder) folderDestinationItem);
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
logger.trace("folder destination is not shared");
|
logger.trace("folder destination is not shared");
|
||||||
|
@ -113,14 +116,17 @@ public class NotificationsWorkspaceUploader {
|
||||||
|
|
||||||
if(isASharedFolder(wsItem)){
|
if(isASharedFolder(wsItem)){
|
||||||
|
|
||||||
WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) wsItem;
|
//TODO wsFolder.getUsers();
|
||||||
List<String> listPortalLogin = wsFolder.getUsers();
|
|
||||||
|
|
||||||
ArrayList<ContactModel> users = new ArrayList<ContactModel>(listPortalLogin.size());
|
// WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) wsItem;
|
||||||
|
// List<String> listPortalLogin = wsFolder.getUsers();
|
||||||
for (String login : listPortalLogin) {
|
//
|
||||||
users.add(new ContactModel(login, login, false, UserUtil.getUserFullName(login)));
|
//ArrayList<ContactModel> users = new ArrayList<ContactModel>(listPortalLogin.size());
|
||||||
}
|
ArrayList<ContactModel> users = new ArrayList<ContactModel>();
|
||||||
|
//
|
||||||
|
// for (String login : listPortalLogin) {
|
||||||
|
// users.add(new ContactModel(login, login, false, UserUtil.getUserFullName(login)));
|
||||||
|
// }
|
||||||
|
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
|
@ -157,14 +163,13 @@ public class NotificationsWorkspaceUploader {
|
||||||
* @param itemId the item id
|
* @param itemId the item id
|
||||||
* @return true, if is a shared folder for id
|
* @return true, if is a shared folder for id
|
||||||
*/
|
*/
|
||||||
public static boolean isASharedFolderForId(GCubeUser user, String scopeGroupId, HttpServletRequest request, String itemId){
|
public static boolean isASharedFolderForId(Workspace workspace, String itemId){
|
||||||
|
|
||||||
if(itemId==null || itemId.isEmpty())
|
if(itemId==null || itemId.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
Workspace workspace = WsUtil.getWorkspace(request, scopeGroupId, user);
|
|
||||||
WorkspaceItem wsItem = workspace.getItem(itemId);
|
WorkspaceItem wsItem = workspace.getItem(itemId);
|
||||||
|
|
||||||
if(wsItem!=null)
|
if(wsItem!=null)
|
||||||
|
|
|
@ -13,10 +13,10 @@ 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.WorkspaceSharedFolder;
|
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.common.portal.PortalContext;
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
import org.gcube.common.scope.impl.ScopeBean;
|
||||||
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
|
import org.gcube.common.storagehub.model.items.SharedFolder;
|
||||||
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;
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||||
|
@ -111,7 +111,7 @@ public class NotificationsWorkspaceUploaderProducer {
|
||||||
* @param workspaceItem the workspace item
|
* @param workspaceItem the workspace item
|
||||||
* @param sharedFolder the shared folder
|
* @param sharedFolder the shared folder
|
||||||
*/
|
*/
|
||||||
public void notifyAddedItemToSharing(final List<ContactModel> listContacts, final WorkspaceItem workspaceItem, final WorkspaceSharedFolder sharedFolder) {
|
public void notifyAddedItemToSharing(final List<ContactModel> listContacts, final Item item, final SharedFolder sharedFolder) {
|
||||||
|
|
||||||
new Thread() {
|
new Thread() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -125,12 +125,14 @@ public class NotificationsWorkspaceUploaderProducer {
|
||||||
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
|
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
|
||||||
if(infoContactModel.getLogin().compareTo(username)!=0){
|
if(infoContactModel.getLogin().compareTo(username)!=0){
|
||||||
|
|
||||||
logger.info("Sending notification to user "+infoContactModel.getLogin() +" added item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
|
logger.info("Sending notification to user "+infoContactModel.getLogin() +" added item "+item.getName()+" in shared folder "+sharedFolder.getName());
|
||||||
boolean notify = notificationsMng.notifyAddedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder);
|
|
||||||
|
|
||||||
if(!notify){
|
//TODO notificationsMng.notifyAddedItem
|
||||||
logger.error("An error occured when notify user: "+infoContactModel.getLogin());
|
// boolean notify = notificationsMng.notifyAddedItem(infoContactModel.getLogin(), item, sharedFolder);
|
||||||
}
|
//
|
||||||
|
// if(!notify){
|
||||||
|
// logger.error("An error occured when notify user: "+infoContactModel.getLogin());
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
logger.error("An error occured in notifyAddedItemToSharing ", e);
|
logger.error("An error occured in notifyAddedItemToSharing ", e);
|
||||||
|
@ -151,7 +153,7 @@ public class NotificationsWorkspaceUploaderProducer {
|
||||||
* @param workspaceItem the workspace item
|
* @param workspaceItem the workspace item
|
||||||
* @param sharedFolder the shared folder
|
* @param sharedFolder the shared folder
|
||||||
*/
|
*/
|
||||||
public void notifyUpdatedItemToSharing(final List<ContactModel> listContacts, final WorkspaceItem workspaceItem, final WorkspaceSharedFolder sharedFolder) {
|
public void notifyUpdatedItemToSharing(final List<ContactModel> listContacts, final Item workspaceItem, final SharedFolder sharedFolder) {
|
||||||
|
|
||||||
new Thread() {
|
new Thread() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -162,12 +164,14 @@ public class NotificationsWorkspaceUploaderProducer {
|
||||||
try{
|
try{
|
||||||
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
|
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
|
||||||
if(infoContactModel.getLogin().compareTo(username)!=0){
|
if(infoContactModel.getLogin().compareTo(username)!=0){
|
||||||
|
|
||||||
|
//TODO notificationsMng.notifyUpdatedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder);
|
||||||
logger.info("Sending notification to user "+infoContactModel.getLogin() +" updated item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
|
logger.info("Sending notification to user "+infoContactModel.getLogin() +" updated item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
|
||||||
boolean notify = notificationsMng.notifyUpdatedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder);
|
/*boolean notify = notificationsMng.notifyUpdatedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder);
|
||||||
|
|
||||||
if(!notify){
|
if(!notify){
|
||||||
logger.error("An error updated when notify user: "+infoContactModel.getLogin());
|
logger.error("An error updated when notify user: "+infoContactModel.getLogin());
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
logger.error("An error updated in notifyAddedItemToSharing ", e);
|
logger.error("An error updated in notifyAddedItemToSharing ", e);
|
||||||
|
|
|
@ -9,20 +9,16 @@ import java.io.InputStream;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.gcube.common.homelibary.model.versioning.WorkspaceVersion;
|
import org.gcube.portal.storagehubwrapper.server.StorageHubWrapper;
|
||||||
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
import org.gcube.portal.storagehubwrapper.shared.tohl.WorkspaceFolder;
|
||||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
import org.gcube.portal.storagehubwrapper.shared.tohl.WorkspaceItem;
|
||||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
|
import org.gcube.portal.storagehubwrapper.shared.tohl.exceptions.InsufficientPrivilegesException;
|
||||||
import org.gcube.common.homelibrary.home.workspace.exceptions.InsufficientPrivilegesException;
|
import org.gcube.portal.storagehubwrapper.shared.tohl.exceptions.InternalErrorException;
|
||||||
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException;
|
import org.gcube.portal.storagehubwrapper.shared.tohl.exceptions.ItemAlreadyExistException;
|
||||||
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
|
import org.gcube.portal.storagehubwrapper.shared.tohl.exceptions.WorkspaceFolderNotFoundException;
|
||||||
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
import org.gcube.portal.storagehubwrapper.shared.tohl.exceptions.WrongDestinationException;
|
||||||
import org.gcube.common.homelibrary.home.workspace.exceptions.WrongDestinationException;
|
import org.gcube.portal.storagehubwrapper.shared.tohl.folder.items.WorkspaceVersion;
|
||||||
import org.gcube.common.homelibrary.home.workspace.exceptions.WrongItemTypeException;
|
import org.gcube.portal.storagehubwrapper.shared.tohl.impl.FileItem;
|
||||||
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
|
|
||||||
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
|
|
||||||
import org.gcube.common.homelibrary.util.WorkspaceUtil;
|
|
||||||
import org.gcube.common.homelibrary.util.zip.UnzipUtil;
|
|
||||||
import org.gcube.portlets.widgets.workspaceuploader.server.WorkspaceUploadServletStream;
|
import org.gcube.portlets.widgets.workspaceuploader.server.WorkspaceUploadServletStream;
|
||||||
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.WorkspaceUploaderItem;
|
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem;
|
||||||
|
@ -53,6 +49,7 @@ public class WorkspaceUploaderMng {
|
||||||
/**
|
/**
|
||||||
* Creates the workspace uploader file.
|
* Creates the workspace uploader file.
|
||||||
*
|
*
|
||||||
|
* @param storageWrapper the storage wrapper
|
||||||
* @param currUser the curr user
|
* @param currUser the curr user
|
||||||
* @param scopeGroupId the scope group id
|
* @param scopeGroupId the scope group id
|
||||||
* @param request the request
|
* @param request the request
|
||||||
|
@ -69,41 +66,50 @@ 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(final GCubeUser currUser, final String scopeGroupId, final 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(StorageHubWrapper storageWrapper, final GCubeUser currUser, final String scopeGroupId, final HttpServletRequest request, final WorkspaceUploaderItem workspaceUploader, final HttpSession httpSession, final boolean isOvewrite, final InputStream uploadFile, final String itemName, final WorkspaceFolder destinationFolder, final String contentType, final long totalBytes) throws InternalErrorException, IOException{
|
||||||
logger.debug("Creating WorkspaceUploaderFile... isOvewrite: " +isOvewrite);
|
logger.debug("Creating WorkspaceUploaderFile... isOvewrite: " +isOvewrite);
|
||||||
|
|
||||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.IN_PROGRESS);
|
workspaceUploader.setUploadStatus(UPLOAD_STATUS.IN_PROGRESS);
|
||||||
workspaceUploader.setStatusDescription("Uploading "+itemName);
|
workspaceUploader.setStatusDescription("Uploading "+itemName);
|
||||||
FolderItem createdItem = null;
|
WorkspaceItem createdItem = null;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
Long startTime = WorkspaceUploadServletStream.printStartTime();
|
Long startTime = WorkspaceUploadServletStream.printStartTime();
|
||||||
if(!isOvewrite){
|
// if(!isOvewrite){
|
||||||
logger.debug("Calling HL createExternalFile - [itemName: "+itemName+", contentType: "+contentType+"]");
|
// logger.debug("Calling HL createExternalFile - [itemName: "+itemName+", contentType: "+contentType+"]");
|
||||||
createdItem = WorkspaceUtil.createExternalFile(destinationFolder, itemName, "", contentType, uploadFile);
|
// createdItem = wa.createExternalFile(destinationFolder, itemName, "", contentType, uploadFile);
|
||||||
}
|
// }
|
||||||
else{
|
// else{
|
||||||
createdItem = overwriteItem(wa, itemName, uploadFile, destinationFolder); //CASE OVERWRITE
|
// createdItem = overwriteItem(wa, itemName, uploadFile, destinationFolder); //CASE OVERWRITE
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
createdItem = storageWrapper.getWorkspace().uploadFile(destinationFolder.getId(), uploadFile, itemName, "");
|
||||||
|
|
||||||
if(createdItem!=null){
|
if(createdItem!=null){
|
||||||
WorkspaceUploadServletStream.printElapsedTime(startTime);
|
WorkspaceUploadServletStream.printElapsedTime(startTime);
|
||||||
logger.debug("HL file: "+createdItem.getName() + " with id: "+createdItem.getId() + " uploaded correctly in "+destinationFolder.getPath());
|
logger.debug("HL file: "+createdItem.getName() + " with id: "+createdItem.getId() + " uploaded correctly in "+destinationFolder.getPath());
|
||||||
workspaceUploader.getFile().setItemId(createdItem.getId()); //SET HL ID
|
workspaceUploader.getFile().setItemId(createdItem.getId()); //SET HL ID
|
||||||
workspaceUploader.getFile().setParentId(createdItem.getParent().getId());//SET PARENT ID
|
workspaceUploader.getFile().setParentId(createdItem.getParentId());//SET PARENT ID
|
||||||
|
|
||||||
//ADDING VERSION NAME
|
//ADDING VERSION NAME
|
||||||
if(createdItem instanceof ExternalFile){
|
if(createdItem instanceof FileItem){
|
||||||
ExternalFile file = (ExternalFile) createdItem;
|
FileItem file = (FileItem) createdItem;
|
||||||
WorkspaceVersion currVersion = file.getCurrentVersion();
|
WorkspaceVersion currVersion = file.getCurrentVersion();
|
||||||
workspaceUploader.getFile().setVersionName(currVersion.getName());
|
if(currVersion!=null){
|
||||||
logger.debug("HL file: "+createdItem.getName() + " has version: "+currVersion.getName());
|
workspaceUploader.getFile().setVersionName(currVersion.getName());
|
||||||
|
logger.debug("StorageHub file: "+createdItem.getName() + " has version: "+currVersion.getName());
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
logger.debug("StorageHub file: "+createdItem.getName() + " has no current version");
|
||||||
|
workspaceUploader.getFile().setVersionName(file.getName());
|
||||||
|
}
|
||||||
|
|
||||||
}else
|
}else
|
||||||
logger.debug("HL file: "+createdItem.getName() + " has not version");
|
logger.debug("HL file: "+createdItem.getName() + " has not version");
|
||||||
|
|
||||||
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(currUser, scopeGroupId, request, httpSession, wa, createdItem.getId(), createdItem.getParent().getId(), isOvewrite);
|
WorkspaceUploadServletStream.notifyUploadInSharedFolder(storageWrapper, currUser, scopeGroupId, request, httpSession, createdItem.getId(), createdItem.getParentId(), 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);
|
||||||
|
@ -113,7 +119,7 @@ public class WorkspaceUploaderMng {
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
||||||
}
|
}
|
||||||
} catch (InternalErrorException | IOException e) {
|
} catch (InternalErrorException e) {
|
||||||
logger.error("Error during upload: ",e);
|
logger.error("Error during upload: ",e);
|
||||||
workspaceUploader.setStatusDescription("An error occurred server-side during upload: "+itemName+". "+e.getMessage() +". Try again");
|
workspaceUploader.setStatusDescription("An error occurred server-side during upload: "+itemName+". "+e.getMessage() +". Try again");
|
||||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
|
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
|
||||||
|
@ -123,7 +129,7 @@ public class WorkspaceUploaderMng {
|
||||||
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (InsufficientPrivilegesException | ItemAlreadyExistException | ItemNotFoundException | WrongItemTypeException | WorkspaceFolderNotFoundException | WrongDestinationException e) {
|
} catch (InsufficientPrivilegesException | ItemAlreadyExistException | WorkspaceFolderNotFoundException | WrongDestinationException e) {
|
||||||
logger.error("Error during file uploading: ",e);
|
logger.error("Error during file uploading: ",e);
|
||||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
|
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
|
||||||
|
|
||||||
|
@ -164,89 +170,89 @@ public class WorkspaceUploaderMng {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Creates the workspace uploader archive.
|
// * Creates the workspace uploader archive.
|
||||||
*
|
// *
|
||||||
* @param currUser the curr user
|
// * @param currUser the curr user
|
||||||
* @param scopeGroupId the scope group id
|
// * @param scopeGroupId the scope group id
|
||||||
* @param workspaceUploader the workspace uploader
|
// * @param workspaceUploader the workspace uploader
|
||||||
* @param request the request
|
// * @param request the request
|
||||||
* @param uploadFile the upload file
|
// * @param uploadFile the upload file
|
||||||
* @param itemName the item name
|
// * @param itemName the item name
|
||||||
* @param destinationFolder the destination folder
|
// * @param destinationFolder the destination folder
|
||||||
* @param totalBytes the total bytes
|
// * @param totalBytes the total bytes
|
||||||
* @return the workspace uploader item
|
// * @return the workspace uploader item
|
||||||
* @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 GCubeUser currUser, final String scopeGroupId, final WorkspaceUploaderItem workspaceUploader, final HttpServletRequest request, final InputStream uploadFile, final String itemName, final WorkspaceFolder destinationFolder, final long totalBytes) throws InternalErrorException, IOException{
|
// private static WorkspaceUploaderItem createWorkspaceUploaderArchive(final GCubeUser currUser, final String scopeGroupId, 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();
|
// 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);
|
||||||
UnzipUtil.unzip(destinationFolder, uploadFile, itemName);
|
// UnzipUtil.unzip(destinationFolder, uploadFile, itemName);
|
||||||
|
//
|
||||||
logger.info("Archive "+itemName+ " imported correctly in "+destinationFolder.getPath());
|
// logger.info("Archive "+itemName+ " imported correctly in "+destinationFolder.getPath());
|
||||||
workspaceUploader.setStatusDescription("Archive "+itemName+ " imported correctly in "+destinationFolder.getPath());
|
// workspaceUploader.setStatusDescription("Archive "+itemName+ " imported correctly in "+destinationFolder.getPath());
|
||||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.COMPLETED);
|
// workspaceUploader.setUploadStatus(UPLOAD_STATUS.COMPLETED);
|
||||||
|
//
|
||||||
try {
|
// try {
|
||||||
WsUtil.putWorkspaceUploaderInSession(httpSession, workspaceUploader);
|
// WsUtil.putWorkspaceUploaderInSession(httpSession, workspaceUploader);
|
||||||
} catch (Exception e1) {
|
// } catch (Exception e1) {
|
||||||
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
// logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
||||||
}
|
// }
|
||||||
} catch (InternalErrorException e) {
|
// } catch (InternalErrorException e) {
|
||||||
logger.error("Error during uploading: ",e);
|
// logger.error("Error during uploading: ",e);
|
||||||
workspaceUploader.setStatusDescription("An error occurred during upload: "+itemName+". "+e.getMessage());
|
// workspaceUploader.setStatusDescription("An error occurred during upload: "+itemName+". "+e.getMessage());
|
||||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
|
// workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
|
||||||
try {
|
// try {
|
||||||
WsUtil.putWorkspaceUploaderInSession(httpSession, workspaceUploader);
|
// WsUtil.putWorkspaceUploaderInSession(httpSession, workspaceUploader);
|
||||||
} catch (Exception e1) {
|
// } catch (Exception e1) {
|
||||||
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
// logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
||||||
}
|
// }
|
||||||
}catch(UploadCanceledException e){
|
// }catch(UploadCanceledException e){
|
||||||
logger.info("UploadCanceledException thrown by client..");
|
// logger.info("UploadCanceledException thrown by client..");
|
||||||
workspaceUploader.setStatusDescription("Aborted upload: "+itemName);
|
// workspaceUploader.setStatusDescription("Aborted upload: "+itemName);
|
||||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.ABORTED);
|
// workspaceUploader.setUploadStatus(UPLOAD_STATUS.ABORTED);
|
||||||
try {
|
// try {
|
||||||
WsUtil.putWorkspaceUploaderInSession(httpSession, workspaceUploader);
|
// WsUtil.putWorkspaceUploaderInSession(httpSession, workspaceUploader);
|
||||||
} catch (Exception e1) {
|
// } catch (Exception e1) {
|
||||||
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
// logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
||||||
}
|
// }
|
||||||
}finally{
|
// }finally{
|
||||||
try {
|
// try {
|
||||||
// StreamUtils.deleteTempFile(uploadFile);
|
//// StreamUtils.deleteTempFile(uploadFile);
|
||||||
WsUtil.setErasableWorkspaceUploaderInSession(request, workspaceUploader.getIdentifier());
|
// WsUtil.setErasableWorkspaceUploaderInSession(request, workspaceUploader.getIdentifier());
|
||||||
} catch (Exception e2) {
|
// } catch (Exception e2) {
|
||||||
// TODO: handle exception
|
// // TODO: handle exception
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return workspaceUploader;
|
// return workspaceUploader;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload file.
|
* Upload file.
|
||||||
*
|
*
|
||||||
* @param currUser the curr user
|
* @param storageWrapper the storage wrapper
|
||||||
* @param scopeGroupId the scope group id
|
* @param currUser the curr user
|
||||||
* @param request the request
|
* @param scopeGroupId the scope group id
|
||||||
* @param workspaceUploader the workspace uploader
|
* @param request the request
|
||||||
* @param httpSession the http session
|
* @param workspaceUploader the workspace uploader
|
||||||
* @param wa the wa
|
* @param httpSession the http session
|
||||||
* @param itemName the item name
|
* @param itemName the item name
|
||||||
* @param file the file
|
* @param file the file
|
||||||
* @param destinationFolder the destination folder
|
* @param destinationFolder the destination folder
|
||||||
* @param contentType the content type
|
* @param contentType the content type
|
||||||
* @param isOverwrite the is overwrite
|
* @param isOverwrite the is overwrite
|
||||||
* @param totolaBytes the totola bytes
|
* @param totolaBytes the totola bytes
|
||||||
* @return the workspace uploader item
|
* @return the workspace uploader item
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public static WorkspaceUploaderItem uploadFile(GCubeUser currUser, String scopeGroupId, 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(StorageHubWrapper storageWrapper, GCubeUser currUser, String scopeGroupId, HttpServletRequest request, WorkspaceUploaderItem workspaceUploader, HttpSession httpSession, String itemName, InputStream file, WorkspaceFolder destinationFolder, String contentType, boolean isOverwrite, long totolaBytes) throws Exception {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return createWorkspaceUploaderFile(currUser, scopeGroupId, request, workspaceUploader, httpSession, isOverwrite, wa, file, itemName, destinationFolder, contentType, totolaBytes);
|
return createWorkspaceUploaderFile(storageWrapper, currUser, scopeGroupId, request, workspaceUploader, httpSession, isOverwrite, 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");
|
||||||
|
@ -254,30 +260,30 @@ public class WorkspaceUploaderMng {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Upload archive.
|
// * Upload archive.
|
||||||
*
|
// *
|
||||||
* @param currUser the curr user
|
// * @param currUser the curr user
|
||||||
* @param scopeGroupId the scope group id
|
// * @param scopeGroupId the scope group id
|
||||||
* @param workspaceUploader the workspace uploader
|
// * @param workspaceUploader the workspace uploader
|
||||||
* @param request the request
|
// * @param request the request
|
||||||
* @param itemName the item name
|
// * @param itemName the item name
|
||||||
* @param file the file
|
// * @param file the file
|
||||||
* @param destinationFolder the destination folder
|
// * @param destinationFolder the destination folder
|
||||||
* @param totalBytes the total bytes
|
// * @param totalBytes the total bytes
|
||||||
* @return the workspace uploader item
|
// * @return the workspace uploader item
|
||||||
* @throws Exception the exception
|
// * @throws Exception the exception
|
||||||
*/
|
// */
|
||||||
public static WorkspaceUploaderItem uploadArchive(GCubeUser currUser, String scopeGroupId, WorkspaceUploaderItem workspaceUploader, HttpServletRequest request, String itemName, InputStream file, WorkspaceFolder destinationFolder, long totalBytes) throws Exception {
|
// public static WorkspaceUploaderItem uploadArchive(GCubeUser currUser, String scopeGroupId, WorkspaceUploaderItem workspaceUploader, HttpServletRequest request, String itemName, InputStream file, WorkspaceFolder destinationFolder, long totalBytes) throws Exception {
|
||||||
|
//
|
||||||
try {
|
// try {
|
||||||
return createWorkspaceUploaderArchive(currUser, scopeGroupId, workspaceUploader, request, file, itemName, destinationFolder, totalBytes);
|
// return createWorkspaceUploaderArchive(currUser, scopeGroupId, 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);
|
||||||
throw new Exception("An error occurred during upload:: "+itemName+". Try again");
|
// throw new Exception("An error occurred during upload:: "+itemName+". Try again");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload file status.
|
* Upload file status.
|
||||||
|
@ -291,31 +297,31 @@ public class WorkspaceUploaderMng {
|
||||||
return WsUtil.getWorkspaceUploaderInSession(request, workspaceUploader.getIdentifier());
|
return WsUtil.getWorkspaceUploaderInSession(request, workspaceUploader.getIdentifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Overwrite item.
|
// * Overwrite item.
|
||||||
*
|
// *
|
||||||
* @param wa the wa
|
// * @param wa the wa
|
||||||
* @param itemName the item name
|
// * @param itemName the item name
|
||||||
* @param fileData the file data
|
// * @param fileData the file data
|
||||||
* @param destinationFolder the destination folder
|
// * @param destinationFolder the destination folder
|
||||||
* @return the folder item
|
// * @return the folder item
|
||||||
* @throws ItemNotFoundException the item not found exception
|
// * @throws ItemNotFoundException the item not found exception
|
||||||
* @throws WrongItemTypeException the wrong item type exception
|
// * @throws WrongItemTypeException the wrong item type exception
|
||||||
* @throws InternalErrorException the internal error exception
|
// * @throws InternalErrorException the internal error exception
|
||||||
* @throws InsufficientPrivilegesException the insufficient privileges exception
|
// * @throws InsufficientPrivilegesException the insufficient privileges exception
|
||||||
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
|
// * @throws WorkspaceFolderNotFoundException the workspace folder not found exception
|
||||||
* @throws ItemAlreadyExistException the item already exist exception
|
// * @throws ItemAlreadyExistException the item already exist exception
|
||||||
* @throws WrongDestinationException the wrong destination exception
|
// * @throws WrongDestinationException the wrong destination exception
|
||||||
*/
|
// */
|
||||||
private static FolderItem overwriteItem(Workspace wa, String itemName, InputStream fileData, WorkspaceFolder destinationFolder) throws ItemNotFoundException, WrongItemTypeException, InternalErrorException, InsufficientPrivilegesException, WorkspaceFolderNotFoundException, ItemAlreadyExistException, WrongDestinationException{
|
// private static FileItem overwriteItem(Workspace wa, String itemName, InputStream fileData, WorkspaceFolder destinationFolder) throws ItemNotFoundException, WrongItemTypeException, InternalErrorException, InsufficientPrivilegesException, WorkspaceFolderNotFoundException, ItemAlreadyExistException, WrongDestinationException{
|
||||||
|
//
|
||||||
FolderItem overwriteItem = null;
|
// FileItem overwriteItem = null;
|
||||||
logger.debug("case overwriting item.. "+itemName);
|
// logger.debug("case overwriting item.. "+itemName);
|
||||||
overwriteItem = (FolderItem) wa.find(itemName, destinationFolder.getId());
|
// overwriteItem = (FileItem) wa.find(itemName, destinationFolder.getId());
|
||||||
logger.debug("overwriteItem item was found, id is: "+overwriteItem.getId());
|
// logger.debug("overwriteItem item was found, id is: "+overwriteItem.getId());
|
||||||
wa.updateItem(overwriteItem.getId(), fileData);
|
// wa.updateItem(overwriteItem.getId(), fileData);
|
||||||
logger.debug("updateItem with id: "+overwriteItem.getId()+ ", is completed");
|
// logger.debug("updateItem with id: "+overwriteItem.getId()+ ", is completed");
|
||||||
return overwriteItem;
|
// return overwriteItem;
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,11 @@ 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.common.homelibrary.home.HomeLibrary;
|
|
||||||
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
|
||||||
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
|
||||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
|
||||||
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.common.portal.PortalContext;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.portal.storagehubwrapper.server.StorageHubWrapper;
|
||||||
|
import org.gcube.portal.storagehubwrapper.server.util.PortalContextUtil;
|
||||||
|
import org.gcube.portal.storagehubwrapper.shared.tohl.exceptions.InternalErrorException;
|
||||||
|
import org.gcube.portal.storagehubwrapper.shared.tohl.exceptions.WorkspaceFolderNotFoundException;
|
||||||
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem;
|
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem;
|
||||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||||
|
|
||||||
|
@ -64,33 +62,36 @@ public class WsUtil {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the workspace.
|
* Gets the storage hub wrapper.
|
||||||
*
|
*
|
||||||
* @param request the request
|
* @param request the request
|
||||||
* @param scopeGroupId the scope group id
|
* @param scopeGroupId the scope group id
|
||||||
* @param currUserId the curr user id
|
* @param user the user
|
||||||
* @return the workspace
|
* @return the storage hub wrapper
|
||||||
* @throws InternalErrorException the internal error exception
|
* @throws InternalErrorException the internal error exception
|
||||||
* @throws HomeNotFoundException the home not found exception
|
|
||||||
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
|
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
|
||||||
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public static Workspace getWorkspace(final HttpServletRequest request, String scopeGroupId, GCubeUser user) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException, Exception{
|
public static StorageHubWrapper getStorageHubWrapper(final HttpServletRequest request, String scopeGroupId, GCubeUser user) throws InternalErrorException, WorkspaceFolderNotFoundException, Exception{
|
||||||
|
|
||||||
if(user==null || user.getUsername().isEmpty())
|
if(user==null || user.getUsername().isEmpty())
|
||||||
throw new Exception("Session expired");
|
throw new Exception("Session expired");
|
||||||
|
|
||||||
logger.trace("Get Workspace scope group id: "+scopeGroupId);
|
try {
|
||||||
PortalContext pContext = PortalContext.getConfiguration();
|
logger.debug("getWorkspace from HL scopeGroupId="+scopeGroupId +", userId="+user);
|
||||||
String scope;
|
String scope;
|
||||||
if(isWithinPortal())
|
PortalContext pContext = PortalContextUtil.getPortalContext(request);
|
||||||
scope = pContext.getCurrentScope(scopeGroupId);
|
if(WsUtil.isWithinPortal() && scopeGroupId!=null)
|
||||||
else
|
scope = pContext.getCurrentScope(scopeGroupId);
|
||||||
scope = pContext.getCurrentScope(request);
|
else
|
||||||
|
scope = pContext.getCurrentScope(request);
|
||||||
|
|
||||||
ScopeProvider.instance.set(scope);
|
String token = PortalContextUtil.getContextUserToken(request);
|
||||||
String username = user.getUsername();
|
return new StorageHubWrapper(scope, token);
|
||||||
logger.info("Client context scope: "+ scope + " username: "+username);
|
} catch (Exception e) {
|
||||||
return HomeLibrary.getUserWorkspace(username);
|
logger.error("Error during getting storageHub wrapper", e);
|
||||||
|
throw new InternalErrorException("Error on gettig the StorageHub wrapper for userId: "+user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue