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>
|
||||
<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"
|
||||
date="2017-03-27">
|
||||
<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>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 component="org.gcube.portlets-widgets.workspace-uploader.1-7-0"
|
||||
date="2017-02-23">
|
||||
|
|
48
pom.xml
48
pom.xml
|
@ -12,7 +12,7 @@
|
|||
<groupId>org.gcube.portlets.widgets</groupId>
|
||||
<artifactId>workspace-uploader</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.8.0-SNAPSHOT</version>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<name>Workspace Uploader Widget</name>
|
||||
<description>Workspace Uploader Widget allows your application to upload file/s in the gCube Workspace</description>
|
||||
<scm>
|
||||
|
@ -121,26 +121,38 @@
|
|||
|
||||
<!-- HOME LIBRARY -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>home-library-model</artifactId>
|
||||
<scope>provided</scope>
|
||||
<groupId>org.gcube.portal</groupId>
|
||||
<artifactId>storagehub-client-wrapper</artifactId>
|
||||
<version>[0.0.1-SNAPSHOT, 1.0.0-SNAPSHOT]</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JSON PARSER -->
|
||||
<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>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20090211</version>
|
||||
</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>
|
||||
<groupId>commons-httpclient</groupId>
|
||||
|
|
|
@ -10,7 +10,6 @@ import javax.servlet.http.HttpServlet;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.gcube.common.homelibrary.util.Extensions;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -42,8 +41,6 @@ public class WorkspaceUploadServlet extends HttpServlet {
|
|||
|
||||
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);
|
||||
|
||||
|
|
|
@ -4,9 +4,7 @@
|
|||
package org.gcube.portlets.widgets.workspaceuploader.server;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
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.util.Streams;
|
||||
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.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.server.notification.NotificationsWorkspaceUploader;
|
||||
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.MemoryUploadListener;
|
||||
|
@ -104,8 +93,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
|||
|
||||
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 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(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");
|
||||
// return;
|
||||
|
||||
Workspace wa = null;
|
||||
GCubeUser currUser;
|
||||
StorageHubWrapper storageHubWrapper;
|
||||
try {
|
||||
logger.debug("getWorkspace from HL scopeGroupId="+scopeGroupId +", userId="+user);
|
||||
currUser = PortalContext.getConfiguration().getCurrentUser(request);
|
||||
wa = WsUtil.getWorkspace(request, scopeGroupId, currUser);
|
||||
storageHubWrapper = WsUtil.getStorageHubWrapper(request, scopeGroupId, user);
|
||||
} catch (Exception 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());
|
||||
|
@ -419,18 +405,18 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
|||
return;
|
||||
}
|
||||
|
||||
if (wa == null) {
|
||||
if (storageHubWrapper == null) {
|
||||
logger.error("Now workspace found in session");
|
||||
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;
|
||||
}
|
||||
|
||||
WorkspaceItem item = null;
|
||||
try {
|
||||
logger.debug("getWorkspaceItem destination id: "+destinationId+" from HL");
|
||||
item = wa.getItem(destinationId);
|
||||
} catch (ItemNotFoundException e) {
|
||||
item = storageHubWrapper.getWorkspace().getItem(destinationId);
|
||||
} catch (ItemNotFoundException | InternalErrorException 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());
|
||||
sendError(response, "Internal error: No destination folder found");
|
||||
|
@ -450,7 +436,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
|||
String itemName = "";
|
||||
|
||||
logger.debug("getItemName from HL");
|
||||
if(!isOverwrite){
|
||||
/*if(!isOverwrite){
|
||||
itemName = WorkspaceUtil.getUniqueName(fileName, destinationFolder);
|
||||
}
|
||||
else{
|
||||
|
@ -468,7 +454,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
|||
isOverwrite = false;
|
||||
itemName = fileName;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
Long size = getContentLength(request);
|
||||
logger.debug("size: " + size + " bytes");
|
||||
|
@ -505,52 +491,53 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
|||
|
||||
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
|
||||
|
||||
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);
|
||||
workspaceUploader = WorkspaceUploaderMng.uploadFile(storageHubWrapper, user, scopeGroupId, request, workspaceUploader, request.getSession(), itemName, inputStream, destinationFolder, contentType, isOverwrite, size);
|
||||
|
||||
if(workspaceUploader==null)
|
||||
throw new Exception("Error when creating uploader, it is null!");
|
||||
|
||||
sendMessage(response, workspaceUploader.getIdentifier());
|
||||
}
|
||||
// }
|
||||
|
||||
}else {//IS ARCHIVE UPLOAD
|
||||
|
||||
logger.debug("Archive content type: "+uploadItem.getContentType());
|
||||
|
||||
if (MimeTypeUtil.isZipContentType(uploadItem.getContentType())){ //UNZIP??
|
||||
logger.debug("Unziping content");
|
||||
//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!");
|
||||
|
||||
sendMessage(response, workspaceUploader.getIdentifier());
|
||||
} else{
|
||||
//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!");
|
||||
|
||||
sendMessage(response, workspaceUploader.getIdentifier());
|
||||
}
|
||||
//TODO UPLOAD ARCHIVE
|
||||
// logger.debug("Archive content type: "+uploadItem.getContentType());
|
||||
//
|
||||
// if (MimeTypeUtil.isZipContentType(uploadItem.getContentType())){ //UNZIP??
|
||||
// logger.debug("Unziping content");
|
||||
// //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!");
|
||||
//
|
||||
// sendMessage(response, workspaceUploader.getIdentifier());
|
||||
// } else{
|
||||
// //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!");
|
||||
//
|
||||
// sendMessage(response, workspaceUploader.getIdentifier());
|
||||
// }
|
||||
}
|
||||
|
||||
//saveWorkspaceUploaderInSession(workspaceUploader, request.getSession());
|
||||
|
@ -687,6 +674,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
|||
/**
|
||||
* Notify upload in shared folder.
|
||||
*
|
||||
* @param storageWrapper the storage wrapper
|
||||
* @param currUser the curr user
|
||||
* @param scopeGroupId the scope group id
|
||||
* @param request the request
|
||||
|
@ -696,18 +684,22 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
|||
* @param destinationFolderId the destination folder id
|
||||
* @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());
|
||||
final NotificationsWorkspaceUploaderProducer np = new NotificationsWorkspaceUploaderProducer(scopeGroupId, httpSession,request);
|
||||
new Thread(){
|
||||
public void run() {
|
||||
WorkspaceItem sourceItem;
|
||||
//Item sourceItem;
|
||||
try {
|
||||
sourceItem = workspace.getItem(itemId);
|
||||
String sourceSharedId = sourceItem.getIdSharedFolder();
|
||||
WorkspaceItem folderDestinationItem = workspace.getItem(destinationFolderId);
|
||||
Item sourceItem = storageWrapper.getStorageHubClientService().getItem(itemId);
|
||||
|
||||
//TODO sourceItem.getIdSharedFolder();
|
||||
/*String sourceSharedId = sourceItem.getIdSharedFolder();
|
||||
Item folderDestinationItem = storageWrapper.getStorageHubClientService().getItem(destinationFolderId);
|
||||
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) {
|
||||
logger.error("Error in notifyUploadInSharedFolder", e);
|
||||
}
|
||||
|
@ -716,177 +708,45 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
|||
}.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite item.
|
||||
*
|
||||
* @param wa the wa
|
||||
* @param itemName the item name
|
||||
* @param fileData the file data
|
||||
* @param destinationFolder the destination folder
|
||||
* @return the folder item
|
||||
*/
|
||||
private FolderItem overwriteItem(Workspace wa, String itemName, InputStream fileData, WorkspaceFolder destinationFolder){
|
||||
|
||||
FolderItem overwriteItem = null;
|
||||
|
||||
try {
|
||||
logger.debug("case overwriting item.. "+itemName);
|
||||
overwriteItem = (FolderItem) wa.find(itemName, destinationFolder.getId());
|
||||
logger.debug("overwriteItem item was found, id is: "+overwriteItem.getId());
|
||||
wa.updateItem(overwriteItem.getId(), fileData);
|
||||
logger.debug("updateItem with id: "+overwriteItem.getId()+ ", is completed");
|
||||
} catch (ItemNotFoundException e) {
|
||||
logger.error("Error in createExternalFile, ItemNotFoundException", e);
|
||||
} catch (WrongItemTypeException e) {
|
||||
logger.error("Error in createExternalFile, WrongItemTypeException", e);
|
||||
} catch (WorkspaceFolderNotFoundException e) {
|
||||
logger.error("Error in createExternalFile, WorkspaceFolderNotFoundException", e);
|
||||
} catch (WrongDestinationException e) {
|
||||
logger.error("Error in createExternalFile, WrongDestinationException", e);
|
||||
} catch (InsufficientPrivilegesException e) {
|
||||
logger.error("Error in createExternalFile, InsufficientPrivilegesException", e);
|
||||
} catch (ItemAlreadyExistException e) {
|
||||
logger.error("Error in createExternalFile, ItemAlreadyExistException", e);
|
||||
} catch (InternalErrorException e) {
|
||||
logger.error("Error in createExternalFile, InternalErrorException", e);
|
||||
}catch (Exception e) {
|
||||
logger.error("Error in createExternalFile, Exception", e);
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// /**
|
||||
// * Overwrite item.
|
||||
// *
|
||||
// * @param wa the wa
|
||||
// * @param itemName the item name
|
||||
// * @param fileData the file data
|
||||
// * @param destinationFolder the destination folder
|
||||
// * @return the folder item
|
||||
// */
|
||||
// private FileItem overwriteItem(Workspace wa, String itemName, InputStream fileData, WorkspaceFolder destinationFolder){
|
||||
//
|
||||
// FileItem overwriteItem = null;
|
||||
//
|
||||
// try {
|
||||
// logger.debug("case overwriting item.. "+itemName);
|
||||
// overwriteItem = (FileItem) wa.find(itemName, destinationFolder.getId());
|
||||
// logger.debug("overwriteItem item was found, id is: "+overwriteItem.getId());
|
||||
// wa.upl(overwriteItem.getId(), fileData);
|
||||
// logger.debug("updateItem with id: "+overwriteItem.getId()+ ", is completed");
|
||||
// } catch (ItemNotFoundException e) {
|
||||
// logger.error("Error in createExternalFile, ItemNotFoundException", e);
|
||||
// } catch (WrongItemTypeException e) {
|
||||
// logger.error("Error in createExternalFile, WrongItemTypeException", e);
|
||||
// } catch (WorkspaceFolderNotFoundException e) {
|
||||
// logger.error("Error in createExternalFile, WorkspaceFolderNotFoundException", e);
|
||||
// } catch (WrongDestinationException e) {
|
||||
// logger.error("Error in createExternalFile, WrongDestinationException", e);
|
||||
// } catch (InsufficientPrivilegesException e) {
|
||||
// logger.error("Error in createExternalFile, InsufficientPrivilegesException", e);
|
||||
// } catch (ItemAlreadyExistException e) {
|
||||
// logger.error("Error in createExternalFile, ItemAlreadyExistException", e);
|
||||
// } catch (InternalErrorException e) {
|
||||
// logger.error("Error in createExternalFile, InternalErrorException", e);
|
||||
// }catch (Exception e) {
|
||||
// logger.error("Error in createExternalFile, Exception", e);
|
||||
// }
|
||||
//
|
||||
// return overwriteItem;
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,10 +3,10 @@ package org.gcube.portlets.widgets.workspaceuploader.server;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
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.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.server.util.WsUtil;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.shared.UploadProgress;
|
||||
|
@ -18,11 +18,12 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
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
|
||||
* May 12, 2016
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Jun 25, 2018
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implements WorkspaceUploaderService {
|
||||
|
@ -72,7 +73,7 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement
|
|||
/**
|
||||
* Check uploader erasable.
|
||||
*
|
||||
* @param httpSession the http session
|
||||
* @param httpRequest the http request
|
||||
* @param uploader the uploader
|
||||
*/
|
||||
private void checkUploaderErasable(final HttpServletRequest httpRequest, final WorkspaceUploaderItem uploader){
|
||||
|
@ -106,13 +107,12 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement
|
|||
@Override
|
||||
public String getWorkspaceId() throws Exception {
|
||||
logger.trace("getWorkspaceId");
|
||||
Workspace workspace;
|
||||
try {
|
||||
String scopeGroupId = ""+PortalContext.getConfiguration().getCurrentGroupId(getThreadLocalRequest());
|
||||
GCubeUser currUser = PortalContext.getConfiguration().getCurrentUser(getThreadLocalRequest());
|
||||
workspace = WsUtil.getWorkspace(getThreadLocalRequest(), scopeGroupId, currUser);
|
||||
if(workspace!=null)
|
||||
return workspace.getRoot().getId();
|
||||
StorageHubWrapper stHubWrapper = WsUtil.getStorageHubWrapper(getThreadLocalRequest(), scopeGroupId, currUser);
|
||||
if(stHubWrapper.getWorkspace()!=null)
|
||||
return stHubWrapper.getWorkspace().getRoot().getId();
|
||||
} catch (Exception e) {
|
||||
logger.error("Get workspace id error", e);
|
||||
String error = "An error occurred getting root id";
|
||||
|
@ -132,17 +132,20 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement
|
|||
try {
|
||||
String scopeGroupId = ""+PortalContext.getConfiguration().getCurrentGroupId(getThreadLocalRequest());
|
||||
GCubeUser currUser = PortalContext.getConfiguration().getCurrentUser(getThreadLocalRequest());
|
||||
Workspace workspace = WsUtil.getWorkspace(getThreadLocalRequest(), scopeGroupId, currUser);
|
||||
WorkspaceItem wsItem = workspace.getItem(parentId); //GET PARENT
|
||||
StorageHubWrapper stHubWrapper = WsUtil.getStorageHubWrapper(getThreadLocalRequest(), scopeGroupId, currUser);
|
||||
WorkspaceItem wsItem = stHubWrapper.getWorkspace().getItem(parentId); //GET PARENT
|
||||
|
||||
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)
|
||||
return null;
|
||||
|
||||
return itemFound.getId();
|
||||
return itemFound.getId();*/
|
||||
|
||||
return null;
|
||||
}
|
||||
else
|
||||
throw new Exception("Invalid Folder parent");
|
||||
|
|
|
@ -7,10 +7,11 @@ import javax.servlet.http.HttpServlet;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
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.storagehub.model.types.WorkspaceItemType;
|
||||
import org.gcube.portal.storagehubwrapper.server.StorageHubWrapper;
|
||||
import org.gcube.portal.storagehubwrapper.server.tohl.Workspace;
|
||||
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.server.util.WsUtil;
|
||||
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)
|
||||
*/
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
String folderParentId = req.getParameter(ConstantsWorkspaceUploader.FOLDER_PARENT_ID);
|
||||
String itemName = req.getParameter(ConstantsWorkspaceUploader.ITEM_NAME);
|
||||
String currGroupId = req.getParameter(ConstantsWorkspaceUploader.CURR_GROUP_ID);
|
||||
String folderParentId = request.getParameter(ConstantsWorkspaceUploader.FOLDER_PARENT_ID);
|
||||
String itemName = request.getParameter(ConstantsWorkspaceUploader.ITEM_NAME);
|
||||
String currGroupId = request.getParameter(ConstantsWorkspaceUploader.CURR_GROUP_ID);
|
||||
//String currUserId = req.getParameter(ConstantsWorkspaceUploader.CURR_USER_ID);
|
||||
logger.debug("folderParentId: "+folderParentId);
|
||||
logger.debug("itemName: "+itemName);
|
||||
logger.debug("currGroupId: "+currGroupId);
|
||||
|
||||
if(currGroupId==null || currGroupId.isEmpty())
|
||||
sendError(response, "Parameter error: currGroupId is null or empty");
|
||||
//logger.debug("currUserId: "+currUserId);
|
||||
|
||||
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) {
|
||||
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
|
||||
* @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);
|
||||
try {
|
||||
GCubeUser gcubeUser = PortalContext.getConfiguration().getCurrentUser(req);
|
||||
//IN THIS CASE THE SESSION EXPIRED IS MANAGED BY UPLOAD SERVLET
|
||||
if(gcubeUser==null)
|
||||
return null;
|
||||
// //IN THIS CASE THE SESSION EXPIRED IS MANAGED BY UPLOAD SERVLET
|
||||
// if(gcubeUser==null)
|
||||
// return null;
|
||||
|
||||
Workspace workspace = WsUtil.getWorkspace(req, currGroupId, gcubeUser);
|
||||
WorkspaceItem wsItem = workspace.getItem(parentId); //GET PARENT
|
||||
|
||||
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 org.apache.log4j.Logger;
|
||||
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.homelibrary.home.workspace.WorkspaceSharedFolder;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.server.util.UserUtil;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.server.util.WsUtil;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.gcube.common.storagehub.model.types.WorkspaceItemType;
|
||||
import org.gcube.portal.storagehubwrapper.server.StorageHubWrapper;
|
||||
import org.gcube.portal.storagehubwrapper.server.tohl.Workspace;
|
||||
import org.gcube.portal.storagehubwrapper.shared.tohl.WorkspaceItem;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.shared.ContactModel;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
|
||||
|
@ -33,6 +32,7 @@ public class NotificationsWorkspaceUploader {
|
|||
/**
|
||||
* Check send notify changed item to share.
|
||||
*
|
||||
* @param storageWrapper the storage wrapper
|
||||
* @param request the request
|
||||
* @param currUser the curr user
|
||||
* @param scopeGroupId the scope group id
|
||||
|
@ -43,7 +43,7 @@ public class NotificationsWorkspaceUploader {
|
|||
* @param folderDestinationItem the folder destination item
|
||||
* @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");
|
||||
|
||||
|
@ -52,6 +52,7 @@ public class NotificationsWorkspaceUploader {
|
|||
try{
|
||||
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());
|
||||
|
||||
//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){
|
||||
|
||||
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){
|
||||
|
||||
//SWITCH BEETWEEN ADDED OR UPDATED
|
||||
if(!isOverwrite)
|
||||
np.notifyAddedItemToSharing(listContacts, sourceItem, (WorkspaceSharedFolder) destinationSharedFolder);
|
||||
np.notifyAddedItemToSharing(listContacts, sourceItem, destinationSharedFolder);
|
||||
else
|
||||
np.notifyUpdatedItemToSharing(listContacts, sourceItem, (WorkspaceSharedFolder) destinationSharedFolder);
|
||||
np.notifyUpdatedItemToSharing(listContacts, sourceItem, destinationSharedFolder);
|
||||
|
||||
|
||||
logger.trace("The notifies was sent correctly");
|
||||
}else
|
||||
logger.trace("The notifies doesn't sent because "+destinationSharedFolder+ " is not instance of WorkspaceSharedFolder");
|
||||
// np.notifyAddedItemToSharing(listContacts, (WorkspaceFolder) folderDestinationItem);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
else
|
||||
logger.trace("folder destination is not shared");
|
||||
|
@ -113,14 +116,17 @@ public class NotificationsWorkspaceUploader {
|
|||
|
||||
if(isASharedFolder(wsItem)){
|
||||
|
||||
WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) wsItem;
|
||||
List<String> listPortalLogin = wsFolder.getUsers();
|
||||
//TODO wsFolder.getUsers();
|
||||
|
||||
ArrayList<ContactModel> users = new ArrayList<ContactModel>(listPortalLogin.size());
|
||||
|
||||
for (String login : listPortalLogin) {
|
||||
users.add(new ContactModel(login, login, false, UserUtil.getUserFullName(login)));
|
||||
}
|
||||
// WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) wsItem;
|
||||
// List<String> listPortalLogin = wsFolder.getUsers();
|
||||
//
|
||||
//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;
|
||||
}
|
||||
|
@ -157,14 +163,13 @@ public class NotificationsWorkspaceUploader {
|
|||
* @param itemId the item 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())
|
||||
return false;
|
||||
|
||||
try {
|
||||
|
||||
Workspace workspace = WsUtil.getWorkspace(request, scopeGroupId, user);
|
||||
WorkspaceItem wsItem = workspace.getItem(itemId);
|
||||
|
||||
if(wsItem!=null)
|
||||
|
|
|
@ -13,10 +13,10 @@ import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
|
|||
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
||||
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
|
||||
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
||||
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.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.shared.ContactModel;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
|
@ -111,7 +111,7 @@ public class NotificationsWorkspaceUploaderProducer {
|
|||
* @param workspaceItem the workspace item
|
||||
* @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() {
|
||||
@Override
|
||||
|
@ -125,12 +125,14 @@ public class NotificationsWorkspaceUploaderProducer {
|
|||
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
|
||||
if(infoContactModel.getLogin().compareTo(username)!=0){
|
||||
|
||||
logger.info("Sending notification to user "+infoContactModel.getLogin() +" added item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
|
||||
boolean notify = notificationsMng.notifyAddedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder);
|
||||
logger.info("Sending notification to user "+infoContactModel.getLogin() +" added item "+item.getName()+" in shared folder "+sharedFolder.getName());
|
||||
|
||||
if(!notify){
|
||||
logger.error("An error occured when notify user: "+infoContactModel.getLogin());
|
||||
}
|
||||
//TODO notificationsMng.notifyAddedItem
|
||||
// boolean notify = notificationsMng.notifyAddedItem(infoContactModel.getLogin(), item, sharedFolder);
|
||||
//
|
||||
// if(!notify){
|
||||
// logger.error("An error occured when notify user: "+infoContactModel.getLogin());
|
||||
// }
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occured in notifyAddedItemToSharing ", e);
|
||||
|
@ -151,7 +153,7 @@ public class NotificationsWorkspaceUploaderProducer {
|
|||
* @param workspaceItem the workspace item
|
||||
* @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() {
|
||||
@Override
|
||||
|
@ -162,12 +164,14 @@ public class NotificationsWorkspaceUploaderProducer {
|
|||
try{
|
||||
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
|
||||
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());
|
||||
boolean notify = notificationsMng.notifyUpdatedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder);
|
||||
/*boolean notify = notificationsMng.notifyUpdatedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder);
|
||||
|
||||
if(!notify){
|
||||
logger.error("An error updated when notify user: "+infoContactModel.getLogin());
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}catch (Exception 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.HttpSession;
|
||||
|
||||
import org.gcube.common.homelibary.model.versioning.WorkspaceVersion;
|
||||
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.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.ExternalFile;
|
||||
import org.gcube.common.homelibrary.util.WorkspaceUtil;
|
||||
import org.gcube.common.homelibrary.util.zip.UnzipUtil;
|
||||
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.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.WorkspaceFolderNotFoundException;
|
||||
import org.gcube.portal.storagehubwrapper.shared.tohl.exceptions.WrongDestinationException;
|
||||
import org.gcube.portal.storagehubwrapper.shared.tohl.folder.items.WorkspaceVersion;
|
||||
import org.gcube.portal.storagehubwrapper.shared.tohl.impl.FileItem;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.server.WorkspaceUploadServletStream;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.server.util.WsUtil;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem;
|
||||
|
@ -53,6 +49,7 @@ public class WorkspaceUploaderMng {
|
|||
/**
|
||||
* Creates the workspace uploader file.
|
||||
*
|
||||
* @param storageWrapper the storage wrapper
|
||||
* @param currUser the curr user
|
||||
* @param scopeGroupId the scope group id
|
||||
* @param request the request
|
||||
|
@ -69,41 +66,50 @@ public class WorkspaceUploaderMng {
|
|||
* @throws InternalErrorException the internal error exception
|
||||
* @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);
|
||||
|
||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.IN_PROGRESS);
|
||||
workspaceUploader.setStatusDescription("Uploading "+itemName);
|
||||
FolderItem createdItem = null;
|
||||
WorkspaceItem createdItem = null;
|
||||
|
||||
try{
|
||||
Long startTime = WorkspaceUploadServletStream.printStartTime();
|
||||
if(!isOvewrite){
|
||||
logger.debug("Calling HL createExternalFile - [itemName: "+itemName+", contentType: "+contentType+"]");
|
||||
createdItem = WorkspaceUtil.createExternalFile(destinationFolder, itemName, "", contentType, uploadFile);
|
||||
}
|
||||
else{
|
||||
createdItem = overwriteItem(wa, itemName, uploadFile, destinationFolder); //CASE OVERWRITE
|
||||
}
|
||||
// if(!isOvewrite){
|
||||
// logger.debug("Calling HL createExternalFile - [itemName: "+itemName+", contentType: "+contentType+"]");
|
||||
// createdItem = wa.createExternalFile(destinationFolder, itemName, "", contentType, uploadFile);
|
||||
// }
|
||||
// else{
|
||||
// createdItem = overwriteItem(wa, itemName, uploadFile, destinationFolder); //CASE OVERWRITE
|
||||
// }
|
||||
|
||||
createdItem = storageWrapper.getWorkspace().uploadFile(destinationFolder.getId(), uploadFile, itemName, "");
|
||||
|
||||
if(createdItem!=null){
|
||||
WorkspaceUploadServletStream.printElapsedTime(startTime);
|
||||
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().setParentId(createdItem.getParent().getId());//SET PARENT ID
|
||||
workspaceUploader.getFile().setParentId(createdItem.getParentId());//SET PARENT ID
|
||||
|
||||
//ADDING VERSION NAME
|
||||
if(createdItem instanceof ExternalFile){
|
||||
ExternalFile file = (ExternalFile) createdItem;
|
||||
if(createdItem instanceof FileItem){
|
||||
FileItem file = (FileItem) createdItem;
|
||||
WorkspaceVersion currVersion = file.getCurrentVersion();
|
||||
workspaceUploader.getFile().setVersionName(currVersion.getName());
|
||||
logger.debug("HL file: "+createdItem.getName() + " has version: "+currVersion.getName());
|
||||
if(currVersion!=null){
|
||||
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
|
||||
logger.debug("HL file: "+createdItem.getName() + " has not version");
|
||||
|
||||
workspaceUploader.setStatusDescription("File \""+createdItem.getName()+"\" uploaded correctly in "+destinationFolder.getPath());
|
||||
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{
|
||||
workspaceUploader.setStatusDescription("An error occurred during upload: \""+itemName + "\". Try again");
|
||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
|
||||
|
@ -113,7 +119,7 @@ public class WorkspaceUploaderMng {
|
|||
} catch (Exception e1) {
|
||||
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
||||
}
|
||||
} catch (InternalErrorException | IOException e) {
|
||||
} catch (InternalErrorException e) {
|
||||
logger.error("Error during upload: ",e);
|
||||
workspaceUploader.setStatusDescription("An error occurred server-side during upload: "+itemName+". "+e.getMessage() +". Try again");
|
||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
|
||||
|
@ -123,7 +129,7 @@ public class WorkspaceUploaderMng {
|
|||
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);
|
||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
|
||||
|
||||
|
@ -164,89 +170,89 @@ public class WorkspaceUploaderMng {
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* Creates the workspace uploader archive.
|
||||
*
|
||||
* @param currUser the curr user
|
||||
* @param scopeGroupId the scope group id
|
||||
* @param workspaceUploader the workspace uploader
|
||||
* @param request the request
|
||||
* @param uploadFile the upload file
|
||||
* @param itemName the item name
|
||||
* @param destinationFolder the destination folder
|
||||
* @param totalBytes the total bytes
|
||||
* @return the workspace uploader item
|
||||
* @throws InternalErrorException the internal error exception
|
||||
* @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{
|
||||
HttpSession httpSession = request.getSession();
|
||||
logger.info("calling upload archive - [itemName: "+itemName+"]");
|
||||
try {
|
||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.IN_PROGRESS);
|
||||
UnzipUtil.unzip(destinationFolder, uploadFile, itemName);
|
||||
|
||||
logger.info("Archive "+itemName+ " imported correctly in "+destinationFolder.getPath());
|
||||
workspaceUploader.setStatusDescription("Archive "+itemName+ " imported correctly in "+destinationFolder.getPath());
|
||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.COMPLETED);
|
||||
|
||||
try {
|
||||
WsUtil.putWorkspaceUploaderInSession(httpSession, workspaceUploader);
|
||||
} catch (Exception e1) {
|
||||
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
||||
}
|
||||
} catch (InternalErrorException e) {
|
||||
logger.error("Error during uploading: ",e);
|
||||
workspaceUploader.setStatusDescription("An error occurred during upload: "+itemName+". "+e.getMessage());
|
||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
|
||||
try {
|
||||
WsUtil.putWorkspaceUploaderInSession(httpSession, workspaceUploader);
|
||||
} catch (Exception e1) {
|
||||
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
||||
}
|
||||
}catch(UploadCanceledException e){
|
||||
logger.info("UploadCanceledException thrown by client..");
|
||||
workspaceUploader.setStatusDescription("Aborted upload: "+itemName);
|
||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.ABORTED);
|
||||
try {
|
||||
WsUtil.putWorkspaceUploaderInSession(httpSession, workspaceUploader);
|
||||
} catch (Exception e1) {
|
||||
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
||||
}
|
||||
}finally{
|
||||
try {
|
||||
// StreamUtils.deleteTempFile(uploadFile);
|
||||
WsUtil.setErasableWorkspaceUploaderInSession(request, workspaceUploader.getIdentifier());
|
||||
} catch (Exception e2) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
}
|
||||
return workspaceUploader;
|
||||
}
|
||||
// /**
|
||||
// * Creates the workspace uploader archive.
|
||||
// *
|
||||
// * @param currUser the curr user
|
||||
// * @param scopeGroupId the scope group id
|
||||
// * @param workspaceUploader the workspace uploader
|
||||
// * @param request the request
|
||||
// * @param uploadFile the upload file
|
||||
// * @param itemName the item name
|
||||
// * @param destinationFolder the destination folder
|
||||
// * @param totalBytes the total bytes
|
||||
// * @return the workspace uploader item
|
||||
// * @throws InternalErrorException the internal error exception
|
||||
// * @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{
|
||||
// HttpSession httpSession = request.getSession();
|
||||
// logger.info("calling upload archive - [itemName: "+itemName+"]");
|
||||
// try {
|
||||
// workspaceUploader.setUploadStatus(UPLOAD_STATUS.IN_PROGRESS);
|
||||
// UnzipUtil.unzip(destinationFolder, uploadFile, itemName);
|
||||
//
|
||||
// logger.info("Archive "+itemName+ " imported correctly in "+destinationFolder.getPath());
|
||||
// workspaceUploader.setStatusDescription("Archive "+itemName+ " imported correctly in "+destinationFolder.getPath());
|
||||
// workspaceUploader.setUploadStatus(UPLOAD_STATUS.COMPLETED);
|
||||
//
|
||||
// try {
|
||||
// WsUtil.putWorkspaceUploaderInSession(httpSession, workspaceUploader);
|
||||
// } catch (Exception e1) {
|
||||
// logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
||||
// }
|
||||
// } catch (InternalErrorException e) {
|
||||
// logger.error("Error during uploading: ",e);
|
||||
// workspaceUploader.setStatusDescription("An error occurred during upload: "+itemName+". "+e.getMessage());
|
||||
// workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
|
||||
// try {
|
||||
// WsUtil.putWorkspaceUploaderInSession(httpSession, workspaceUploader);
|
||||
// } catch (Exception e1) {
|
||||
// logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
||||
// }
|
||||
// }catch(UploadCanceledException e){
|
||||
// logger.info("UploadCanceledException thrown by client..");
|
||||
// workspaceUploader.setStatusDescription("Aborted upload: "+itemName);
|
||||
// workspaceUploader.setUploadStatus(UPLOAD_STATUS.ABORTED);
|
||||
// try {
|
||||
// WsUtil.putWorkspaceUploaderInSession(httpSession, workspaceUploader);
|
||||
// } catch (Exception e1) {
|
||||
// logger.error("Error during WorkspaceUploaderItem session update: ",e1);
|
||||
// }
|
||||
// }finally{
|
||||
// try {
|
||||
//// StreamUtils.deleteTempFile(uploadFile);
|
||||
// WsUtil.setErasableWorkspaceUploaderInSession(request, workspaceUploader.getIdentifier());
|
||||
// } catch (Exception e2) {
|
||||
// // TODO: handle exception
|
||||
// }
|
||||
// }
|
||||
// return workspaceUploader;
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Upload file.
|
||||
*
|
||||
* @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 file the file
|
||||
* @param destinationFolder the destination folder
|
||||
* @param contentType the content type
|
||||
* @param isOverwrite the is overwrite
|
||||
* @param totolaBytes the totola bytes
|
||||
* @return the workspace uploader item
|
||||
* @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 {
|
||||
* Upload file.
|
||||
*
|
||||
* @param storageWrapper the storage wrapper
|
||||
* @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 itemName the item name
|
||||
* @param file the file
|
||||
* @param destinationFolder the destination folder
|
||||
* @param contentType the content type
|
||||
* @param isOverwrite the is overwrite
|
||||
* @param totolaBytes the totola bytes
|
||||
* @return the workspace uploader item
|
||||
* @throws Exception the 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 {
|
||||
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) {
|
||||
logger.error("Error when uploading file to HL : ",e);
|
||||
throw new Exception("An error occurred during upload: "+itemName+". Try again");
|
||||
|
@ -254,30 +260,30 @@ public class WorkspaceUploaderMng {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Upload archive.
|
||||
*
|
||||
* @param currUser the curr user
|
||||
* @param scopeGroupId the scope group id
|
||||
* @param workspaceUploader the workspace uploader
|
||||
* @param request the request
|
||||
* @param itemName the item name
|
||||
* @param file the file
|
||||
* @param destinationFolder the destination folder
|
||||
* @param totalBytes the total bytes
|
||||
* @return the workspace uploader item
|
||||
* @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 {
|
||||
|
||||
try {
|
||||
return createWorkspaceUploaderArchive(currUser, scopeGroupId, workspaceUploader, request, file, itemName, destinationFolder, totalBytes);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error when uploading Archive to HL creation: ",e);
|
||||
throw new Exception("An error occurred during upload:: "+itemName+". Try again");
|
||||
}
|
||||
}
|
||||
// /**
|
||||
// * Upload archive.
|
||||
// *
|
||||
// * @param currUser the curr user
|
||||
// * @param scopeGroupId the scope group id
|
||||
// * @param workspaceUploader the workspace uploader
|
||||
// * @param request the request
|
||||
// * @param itemName the item name
|
||||
// * @param file the file
|
||||
// * @param destinationFolder the destination folder
|
||||
// * @param totalBytes the total bytes
|
||||
// * @return the workspace uploader item
|
||||
// * @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 {
|
||||
//
|
||||
// try {
|
||||
// return createWorkspaceUploaderArchive(currUser, scopeGroupId, workspaceUploader, request, file, itemName, destinationFolder, totalBytes);
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// logger.error("Error when uploading Archive to HL creation: ",e);
|
||||
// throw new Exception("An error occurred during upload:: "+itemName+". Try again");
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* Upload file status.
|
||||
|
@ -291,31 +297,31 @@ public class WorkspaceUploaderMng {
|
|||
return WsUtil.getWorkspaceUploaderInSession(request, workspaceUploader.getIdentifier());
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite item.
|
||||
*
|
||||
* @param wa the wa
|
||||
* @param itemName the item name
|
||||
* @param fileData the file data
|
||||
* @param destinationFolder the destination folder
|
||||
* @return the folder item
|
||||
* @throws ItemNotFoundException the item not found exception
|
||||
* @throws WrongItemTypeException the wrong item type exception
|
||||
* @throws InternalErrorException the internal error exception
|
||||
* @throws InsufficientPrivilegesException the insufficient privileges exception
|
||||
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
|
||||
* @throws ItemAlreadyExistException the item already exist 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{
|
||||
|
||||
FolderItem overwriteItem = null;
|
||||
logger.debug("case overwriting item.. "+itemName);
|
||||
overwriteItem = (FolderItem) wa.find(itemName, destinationFolder.getId());
|
||||
logger.debug("overwriteItem item was found, id is: "+overwriteItem.getId());
|
||||
wa.updateItem(overwriteItem.getId(), fileData);
|
||||
logger.debug("updateItem with id: "+overwriteItem.getId()+ ", is completed");
|
||||
return overwriteItem;
|
||||
|
||||
}
|
||||
// /**
|
||||
// * Overwrite item.
|
||||
// *
|
||||
// * @param wa the wa
|
||||
// * @param itemName the item name
|
||||
// * @param fileData the file data
|
||||
// * @param destinationFolder the destination folder
|
||||
// * @return the folder item
|
||||
// * @throws ItemNotFoundException the item not found exception
|
||||
// * @throws WrongItemTypeException the wrong item type exception
|
||||
// * @throws InternalErrorException the internal error exception
|
||||
// * @throws InsufficientPrivilegesException the insufficient privileges exception
|
||||
// * @throws WorkspaceFolderNotFoundException the workspace folder not found exception
|
||||
// * @throws ItemAlreadyExistException the item already exist exception
|
||||
// * @throws WrongDestinationException the wrong destination exception
|
||||
// */
|
||||
// private static FileItem overwriteItem(Workspace wa, String itemName, InputStream fileData, WorkspaceFolder destinationFolder) throws ItemNotFoundException, WrongItemTypeException, InternalErrorException, InsufficientPrivilegesException, WorkspaceFolderNotFoundException, ItemAlreadyExistException, WrongDestinationException{
|
||||
//
|
||||
// FileItem overwriteItem = null;
|
||||
// logger.debug("case overwriting item.. "+itemName);
|
||||
// overwriteItem = (FileItem) wa.find(itemName, destinationFolder.getId());
|
||||
// logger.debug("overwriteItem item was found, id is: "+overwriteItem.getId());
|
||||
// wa.updateItem(overwriteItem.getId(), fileData);
|
||||
// logger.debug("updateItem with id: "+overwriteItem.getId()+ ", is completed");
|
||||
// return overwriteItem;
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -7,13 +7,11 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpSession;
|
||||
|
||||
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.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.vomanagement.usermanagement.model.GCubeUser;
|
||||
|
||||
|
@ -64,33 +62,36 @@ public class WsUtil {
|
|||
|
||||
|
||||
/**
|
||||
* Gets the workspace.
|
||||
* Gets the storage hub wrapper.
|
||||
*
|
||||
* @param request the request
|
||||
* @param scopeGroupId the scope group id
|
||||
* @param currUserId the curr user id
|
||||
* @return the workspace
|
||||
* @param user the user
|
||||
* @return the storage hub wrapper
|
||||
* @throws InternalErrorException the internal error exception
|
||||
* @throws HomeNotFoundException the home 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())
|
||||
throw new Exception("Session expired");
|
||||
|
||||
logger.trace("Get Workspace scope group id: "+scopeGroupId);
|
||||
PortalContext pContext = PortalContext.getConfiguration();
|
||||
String scope;
|
||||
if(isWithinPortal())
|
||||
scope = pContext.getCurrentScope(scopeGroupId);
|
||||
else
|
||||
scope = pContext.getCurrentScope(request);
|
||||
try {
|
||||
logger.debug("getWorkspace from HL scopeGroupId="+scopeGroupId +", userId="+user);
|
||||
String scope;
|
||||
PortalContext pContext = PortalContextUtil.getPortalContext(request);
|
||||
if(WsUtil.isWithinPortal() && scopeGroupId!=null)
|
||||
scope = pContext.getCurrentScope(scopeGroupId);
|
||||
else
|
||||
scope = pContext.getCurrentScope(request);
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
String username = user.getUsername();
|
||||
logger.info("Client context scope: "+ scope + " username: "+username);
|
||||
return HomeLibrary.getUserWorkspace(username);
|
||||
String token = PortalContextUtil.getContextUserToken(request);
|
||||
return new StorageHubWrapper(scope, token);
|
||||
} catch (Exception e) {
|
||||
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