Fixed bug on currUserId. Not it is passed as parameter

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@141318 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-12-21 13:20:48 +00:00
parent da55a34c39
commit 7a658e4f68
9 changed files with 185 additions and 621 deletions

View File

@ -24,6 +24,7 @@ public class ConstantsWorkspaceUploader {
// UPLOAD SERVLET PARAMETERS
public static final String CURR_GROUP_ID = "currGroupId";
public static final String CURR_USER_ID = "currUserId";
public static final String IS_OVERWRITE = "isOverwrite";
public static final String UPLOAD_TYPE = "uploadType";
public static final String ID_FOLDER = "idFolder";
@ -40,4 +41,6 @@ public class ConstantsWorkspaceUploader {
public static final String FOLDER_PARENT_ID = "FOLDER_PARENT_ID";
public static final String ITEM_NAME = "ITEM_NAME";
}

View File

@ -18,7 +18,6 @@ import com.google.gwt.core.shared.GWT;
import com.google.gwt.user.client.Random;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Hidden;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.Widget;
@ -42,6 +41,7 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
private String folder_parent_id = ConstantsWorkspaceUploader.FOLDER_PARENT_ID;
private String item_name = ConstantsWorkspaceUploader.ITEM_NAME;
private String scopeGroupId = ConstantsWorkspaceUploader.CURR_GROUP_ID;
private String currUserId = ConstantsWorkspaceUploader.CURR_USER_ID;
public static final String FILE_DELEMITER = ";";
private Widget onlyChild;
@ -74,6 +74,7 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
HTML html = new HTML(dnd);
this.add(html);
scopeGroupId = GCubeClientContext.getCurrentContextId();
currUserId = GCubeClientContext.getCurrentUserId();
}
/**
* Instantiates a new multiple dnd upload.
@ -88,6 +89,7 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
HTML html = new HTML(dnd);
this.add(html);
scopeGroupId = GCubeClientContext.getCurrentContextId();
currUserId = GCubeClientContext.getCurrentUserId();
setParameters(parentId, uploadType);
}
@ -136,6 +138,7 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
this.idFolder = parentId;
this.type = uploadType;
this.scopeGroupId = GCubeClientContext.getCurrentContextId();
this.currUserId = GCubeClientContext.getCurrentUserId();
}
/**
@ -569,6 +572,9 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
var scopeGroupId = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::scopeGroupId;
console.log("scopeGroupId: " + scopeGroupId);
var currUserId = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::currUserId;
console.log("currUserId: " + currUserId);
if (idfolder === null || idfolder === undefined
|| uploadType === null
|| uploadType === undefined) {
@ -645,6 +651,7 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
formdata.append("uploadType", uploadType);
formdata.append("idFolder", idfolder);
formdata.append("currGroupId", scopeGroupId);
formdata.append("currUserId", currUserId);
var overwrite = false;
formdata.append("isOverwrite", overwrite);
@ -667,10 +674,10 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
var wsUtil = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::workspaceUtil;
var folder_parent_id = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::folder_parent_id;
var item_name = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::item_name;
var scopegroupid = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::scopeGroupId;
//var scopegroupid = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::scopeGroupId;
console.log("item_name: " + item_name);
var params = folder_parent_id+"="+idfolder+"&"+item_name+"="+files[i].name+"&currGroupId="+scopeGroupId;
var params = folder_parent_id+"="+idfolder+"&"+item_name+"="+files[i].name+"&currGroupId="+scopeGroupId+"&currUserId="+currUserId;
console.log("params: " + params);
var response = isFileOverwrite(wsUtil, params, "");
console.log("response overwrite: " + response);

View File

@ -3,50 +3,23 @@
*/
package org.gcube.portlets.widgets.workspaceuploader.server;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Calendar;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.fileupload.FileItemStream;
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.WorkspaceUtil;
import org.gcube.common.portal.PortalContext;
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.util.WsUtil;
import org.gcube.portlets.widgets.workspaceuploader.shared.HandlerResultMessage;
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class WorkspaceUploadServlet.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Jan 21, 2014
*
*/
public class WorkspaceUploadServlet extends HttpServlet {
@ -74,30 +47,13 @@ public class WorkspaceUploadServlet extends HttpServlet {
public static Logger logger = LoggerFactory.getLogger(WorkspaceUploadServlet.class);
/*private static String UPLOAD_LOCATION = System.getProperty("java.io.tmpdir");
@Override
public void init() throws ServletException {
try{
System.out.println(WorkspaceUploadServlet.class.getName()+" ready.");
logger.debug(WorkspaceUploadServlet.class.getName()+" ready.");
if (System.getenv("CATALINA_TMPDIR") != null && System.getenv("CATALINA_TMPDIR").compareTo("") != 0) {
UPLOAD_LOCATION = System.getenv("CATALINA_TMPDIR");
}
super.init();
}catch(Exception e){
e.printStackTrace();
}
}*/
/**
* {@inheritDoc}
*/
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// System.out.println("GET on LocalUploadServlet");
System.out.println("GET method in WorkspaceUploadServlet is running");
sendError(response, "Internal error: GET method not supported");
}
/**
@ -106,462 +62,5 @@ public class WorkspaceUploadServlet extends HttpServlet {
@SuppressWarnings("rawtypes")
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// System.out.println("POST on UploadServlet");
// logger.info("POST on UploadServlet");
//
// if (!ServletFileUpload.isMultipartContent(request)) {
// logger.error("ERROR: multipart request not found");
// sendError(response, "ERROR: multipart request not found");
// }
//
// String destinationId = null;
// String uploadType = null;
// boolean isOverwrite = false;
// String clientUploadKey = null;
// FileItemStream uploadItem = null;
//
// FileItemFactory factory = new DiskFileItemFactory();
// ServletFileUpload servletFileUpload = new ServletFileUpload(factory);
//
// try {
//
// FileItemIterator fileItemIterator = servletFileUpload.getItemIterator(request);
//
// //GET FILE STREAM
// while (fileItemIterator.hasNext()) {
// FileItemStream item = fileItemIterator.next();
//
// if (item.isFormField() && ID_FOLDER.equals(item.getFieldName())){
// destinationId = Streams.asString(item.openStream());
// logger.debug("ID_FOLDER OK");
// }
//
// if (item.isFormField() && UPLOAD_TYPE.equals(item.getFieldName())){
// uploadType = Streams.asString(item.openStream());
// logger.debug("UPLOAD_TYPE OK");
// }
//
// if (item.isFormField() && IS_OVERWRITE.equals(item.getFieldName())){
// isOverwrite = Boolean.parseBoolean(Streams.asString(item.openStream()));
// logger.debug("IS_OVERWRITE OK");
// }
//
// if(item.isFormField() && CLIENT_UPLOAD_KEY.equals(item.getFieldName())){
// clientUploadKey = Streams.asString(item.openStream());
// logger.debug("CLIENT_UPLOAD_KEY OK");
// }
//
// //MUST BE THE LAST PARAMETER TRASMITTED
// if (UPLOAD_FORM_ELEMENT.equals(item.getFieldName())){
// logger.debug(UPLOAD_FORM_ELEMENT);
// uploadItem = item;
// break;
// }
// }
// uploadData(request, response, uploadItem, destinationId, uploadType, clientUploadKey, isOverwrite);
// } catch (FileUploadException e) {
// logger.error("Error processing request in upload servlet", e);
// sendError(response, "Internal error: Error during request processing");
// return;
// }
}
private void uploadData(HttpServletRequest request, HttpServletResponse response, FileItemStream uploadItem, String destinationId,String uploadType,String clientUploadKey, boolean isOverwrite) throws ServletException, IOException{
// String fileName = uploadItem.getName();
// logger.info("Upload servlet parameters: [fileName: "+fileName+ ", destinationId: "+destinationId +", uploadType: "+uploadType+", isOverwrite: "+isOverwrite+", clientUploadKey: "+clientUploadKey+"]");
//
// if (uploadType == null || uploadType.isEmpty()) {
// logger.error("Error processing request in upload servlet: No upload type found");
// sendError(response, "Internal error: No upload type found");
// return;
// }
//
// if(clientUploadKey==null || clientUploadKey.isEmpty()){
// logger.error("Error processing request in upload servlet: No client upload key found");
// sendError(response, "Internal error: No client upload key found");
// return;
// }
//
//
// Workspace wa = null;
// try {
// logger.debug("getWorkspace from HL");
// wa = WsUtil.getWorkspace(request.getSession());
// } catch (Exception e) {
// logger.error("Error during workspace retrieving", e);
// response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error processing request in upload servlet");
// return;
// }
//
// if (wa == null) {
// logger.error("Now workspace found in session");
// sendError(response, "Internal error: No workspace in session");
// return;
// }
//
// WorkspaceItem item;
// try {
// logger.debug("getWorkspace Item from HL");
// item = wa.getItem(destinationId);
// } catch (ItemNotFoundException e) {
// logger.error("Error, no destination folder found", e);
// sendError(response, "Internal error: No destination folder found");
// return;
// }
//
// if (item.getType() != WorkspaceItemType.FOLDER && item.getType() != WorkspaceItemType.SHARED_FOLDER) {
// logger.error("Error processing request in upload servlet: Wrong destination item");
// sendError(response, "Internal error: Wrong destination item");
// return;
// }
//
// WorkspaceFolder destinationFolder = (WorkspaceFolder) item;
//
// try {
// //we calculate an unique name for the current destination
// String itemName = "";
//
// logger.debug("getItemName from HL");
// if(!isOverwrite)
// itemName = WorkspaceUtil.getUniqueName(fileName, destinationFolder);
// else
// itemName = fileName;
//
// Long size = Long.parseLong(request.getHeader("Content-Length"));
// logger.debug("size: " + size + " bytes");
//
//
// //Create Item Uploader to read progress
// WorkspaceUploadFile wsUploadFile = new WorkspaceUploadFile(destinationFolder.getId(), itemName);
// String identifier = wsUploadFile.hashCode()+getRandom()+"";
// WorkspaceUploaderItem workspaceUploader = new WorkspaceUploaderItem(identifier);
// workspaceUploader.setUploadStatus(UPLOAD_STATUS.WAIT);
// workspaceUploader.setFile(wsUploadFile);
// workspaceUploader.setStatusDescription("Uploading "+itemName+" at 0%");
// workspaceUploader.setClientUploadKey(clientUploadKey);
//
// //instanciate the progress listener
// AbstractUploadProgressListener uploadProgressListener = new AbstractUploadProgressListener(request, new UploadProgress(), 0, 70);
// final UploadProgressInputStream inputStream = new UploadProgressInputStream(uploadItem.openStream(), size);
// inputStream.addListener(uploadProgressListener);
// workspaceUploader.setUploadProgress(uploadProgressListener.getUploadProgress());
// saveWorkspaceUploaderInSession(workspaceUploader, request.getSession());
//
// printStartTime();
// File file = StreamUtils.stream2file(inputStream, uploadItem.getName()+UUID.randomUUID(), ".tmp");
//
// logger.debug("getMimeType from HL");
// String contentType = MimeTypeUtil.getMimeType(itemName, StreamUtils.openInputStream(file));
// logger.debug("Content type (mime type): "+contentType + " unique name: "+itemName);
//
// String extension = FilenameUtils.getExtension(itemName);
// logger.debug("extension: "+extension);
//
// if(uploadType.compareTo(FILE)==0) {//IS FILE UPLOAD
//
// boolean isZipFile = MimeTypeUtil.isZipContentType(contentType);
//
// if(isZipFile && (extension.compareToIgnoreCase(D4ST)==0)){ //Create REPORT TEMPLATE
//
// String newItemName = itemName;
// logger.debug("createTemplate: "+newItemName);
// createTemplate(request.getSession(), wa, newItemName, file, destinationFolder, response, isOverwrite);
//
// }else if(isZipFile && (extension.compareToIgnoreCase(D4SR)==0)){ //Create REPORT
//
// String newItemName = itemName;
// logger.debug("createReport: "+newItemName);
// createReport(request.getSession(), wa, newItemName, file, destinationFolder, response, isOverwrite);
// }else{ //CREATE AN EXTERNAL FILE
//
// workspaceUploader = WorkspaceUploaderManager.uploadFile(request, workspaceUploader, wa, itemName, file, 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
//
// if (MimeTypeUtil.isZipContentType(contentType)){
// logger.debug("Unziping content");
// workspaceUploader = WorkspaceUploaderManager.uploadArchive(request, workspaceUploader, itemName, file, destinationFolder, size);
//
// if(workspaceUploader==null)
// throw new Exception("Error when creating uploader, it is null!");
//
// sendMessage(response, workspaceUploader.getIdentifier());
// } else{
// workspaceUploader = WorkspaceUploaderManager.uploadFile(request, workspaceUploader, wa, itemName, file, destinationFolder, contentType, isOverwrite, size);
//
// if(workspaceUploader==null)
// throw new Exception("Error when creating uploader, it is null!");
//
// sendMessage(response, workspaceUploader.getIdentifier());
// }
// }
//
//// file.delete();
// } catch (InsufficientPrivilegesException e) {
// logger.error("Error creating elements", e);
// sendError(response, "Internal error: Insufficient privileges");
// return;
// } catch (InternalErrorException e) {
// logger.error("Error creating elements", e);
// sendError(response, "Internal error: "+e.getMessage());
// return;
// } catch (ItemAlreadyExistException e) {
// logger.error("Error creating elements", e);
// sendError(response, "Internal error: An item with that name already exists");
// return;
// }catch (Exception e) {
// logger.error("Error creating elements", e);
// sendError(response, "Internal error: An error occurred on uploading the file, try again later");
// return;
// }
}
public static WorkspaceUploaderItem saveWorkspaceUploaderInSession(WorkspaceUploaderItem workspaceUploader, HttpSession httpSession) throws Exception {
if(workspaceUploader!=null){
try {
WsUtil.putWorkspaceUploaderInSession(httpSession, workspaceUploader);
return workspaceUploader;
} catch (Exception e) {
logger.error("Error during WorkspaceUploaderItem save in session workspace uploader: "+workspaceUploader,e);
throw new Exception("An error occurred in the upload. Try again");
}
}
throw new Exception("An error occurredin the upload. Workspace Uploader not found. Abort and try again");
}
/**
* Gets the random.
*
* @return the random
*/
private static int getRandom(){
Random randomGenerator = new Random();
return randomGenerator.nextInt(Integer.MAX_VALUE);
}
//TEST TIME
public static Long startTime = new Long(0);
//TEST TIME
public static Long printStartTime(){
startTime = System.currentTimeMillis();
logger.debug("Start time: "+startTime);
return startTime;
}
//TEST TIME
public static void printElapsedTime(long startTime){
Long endTime = System.currentTimeMillis() - startTime;
String time = String.format("%d msc %d sec", endTime, TimeUnit.MILLISECONDS.toSeconds(endTime));
logger.debug("Elapsed Time: "+time);
}
/**
* Notify upload in shared folder.
*
* @param request the request
* @param httpSession the http session
* @param workspace the workspace
* @param itemId the item id
* @param destinationFolderId the destination folder id
* @param isOverwrite the is overwrite
*/
public static void notifyUploadInSharedFolder(final String scopeGroupId, final HttpServletRequest request, final HttpSession httpSession, final Workspace workspace, final String itemId, final String destinationFolderId, final boolean isOverwrite){
final GCubeUser currUser = PortalContext.getConfiguration().getCurrentUser(request);
System.out.println("\n\n*****\n\n notifyUploadInSharedFolder currUser=" + currUser.toString());
boolean requestIsNull = request==null;
logger.trace("[2] HttpServletRequest is: null? "+requestIsNull+", URI: "+request.getRequestURI() +", ServerName: "+request.getServerName());
final NotificationsWorkspaceUploaderProducer np = new NotificationsWorkspaceUploaderProducer(scopeGroupId, httpSession,request);
new Thread(){
public void run() {
WorkspaceItem sourceItem;
try {
sourceItem = workspace.getItem(itemId);
String sourceSharedId = sourceItem.getIdSharedFolder();
WorkspaceItem folderDestinationItem = workspace.getItem(destinationFolderId);
logger.trace("[3] HttpServletRequest is: URI: "+request.getRequestURI() +", ServerName: "+request.getServerName());
NotificationsWorkspaceUploader.checkSendNotifyChangedItemToShare(currUser, scopeGroupId, np, httpSession, sourceItem, sourceSharedId, folderDestinationItem,isOverwrite);
} catch (Exception e) {
logger.error("Error in notifyUploadInSharedFolder", e);
}
};
}.start();
}
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;
}
private void createReport(String scopeGroupId, final HttpServletRequest request, HttpSession httpSession, Workspace wa, String itemName, File file, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{
try {
Report report = null;
if(!isOverwrite){
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
report = wa.createReport(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", "", 0, "", StreamUtils.openInputStream(file), destinationFolder.getId());
notifyUploadInSharedFolder(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, StreamUtils.openInputStream(file), destinationFolder);
if(rep!=null){
notifyUploadInSharedFolder(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);
sendError(response, "Internal error: Wrong Destination");
} catch (WorkspaceFolderNotFoundException e) {
logger.error("Error creating elements", e);
sendError(response, "Internal error: Workspace Folder Not Found");
}finally{
try {
StreamUtils.deleteTempFile(file);
} catch (Exception e2) {
// TODO: handle exception
}
}
}
private void createTemplate(String scopeGroupId, final HttpServletRequest request, HttpSession httpSession, Workspace wa, String itemName, File file, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{
try {
ReportTemplate template = null;
if(!isOverwrite){
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
template = wa.createReportTemplate(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", 0, "", StreamUtils.openInputStream(file), destinationFolder.getId());
notifyUploadInSharedFolder(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, StreamUtils.openInputStream(file), destinationFolder);
if(rep!=null){
notifyUploadInSharedFolder(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);
sendError(response, "Internal error: Wrong Destination");
} catch (WorkspaceFolderNotFoundException e) {
logger.error("Error creating elements", e);
sendError(response, "Internal error: Workspace Folder Not Found");
}finally{
try {
StreamUtils.deleteTempFile(file);
} catch (Exception e2) {
// TODO: handle exception
}
}
}
protected void sendError(HttpServletResponse response, String message) throws IOException{
try {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
HandlerResultMessage resultMessage = HandlerResultMessage.errorResult(message);
response.getWriter().write(resultMessage.toString());
//5.6 Closure of Response Object:
//When a response is closed, the container must immediately flush all remaining content in the response buffer to the client
// response.flushBuffer();
} catch (IOException e){
logger.warn("IOException class name: "+e.getClass().getSimpleName());
if (e.getClass().getSimpleName().equals("ClientAbortException"))
logger.warn("Skipping ClientAbortException: "+e.getMessage());
else
throw e; //Sending Exceptions
}
}
protected void sendMessage(HttpServletResponse response, String message) throws IOException{
try {
response.setStatus(HttpServletResponse.SC_ACCEPTED);
HandlerResultMessage resultMessage = HandlerResultMessage.okResult(message);
response.getWriter().write(resultMessage.toString());
//5.6 Closure of Response Object:
//When a response is closed, the container must immediately flush all remaining content in the response buffer to the client
// response.flushBuffer();
} catch (IOException e){
logger.warn("IOException class name: "+e.getClass().getSimpleName());
if (e.getClass().getSimpleName().equals("ClientAbortException"))
logger.warn("Skipping ClientAbortException: "+e.getMessage());
else
throw e; //Sending Exceptions
}
}
protected void sendWarnMessage(HttpServletResponse response, String message) throws IOException{
try {
response.setStatus(HttpServletResponse.SC_ACCEPTED);
HandlerResultMessage resultMessage = HandlerResultMessage.warnResult(message);
response.getWriter().write(resultMessage.toString());
//5.6 Closure of Response Object:
//When a response is closed, the container must immediately flush all remaining content in the response buffer to the client
// response.flushBuffer();
} catch (IOException e){
logger.warn("IOException class name: "+e.getClass().getSimpleName());
if (e.getClass().getSimpleName().equals("ClientAbortException"))
logger.warn("Skipping ClientAbortException: "+e.getMessage());
else
throw e; //Sending Exceptions
}
}
}

View File

@ -18,7 +18,6 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequestWrapper;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileItemIterator;
@ -61,7 +60,6 @@ import org.gcube.portlets.widgets.workspaceuploader.shared.HandlerResultMessage;
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploadFile;
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem;
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem.UPLOAD_STATUS;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@ -87,6 +85,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
public static final String VRE_ID_ATTR_NAME = "gcube-vreid";
public static final String CURR_GROUP_ID = ConstantsWorkspaceUploader.CURR_GROUP_ID;
public static final String CURR_USER_ID = ConstantsWorkspaceUploader.CURR_USER_ID;
public static final String UPLOAD_TYPE = ConstantsWorkspaceUploader.UPLOAD_TYPE;
public static final String ID_FOLDER = ConstantsWorkspaceUploader.ID_FOLDER;
@ -209,6 +209,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
int uploadItemsCnt = 0;
String scopeGroupId = "";
String currUserId = "";
//GET FILE STREAM
while (fileItemIterator.hasNext()) {
FileItemStream item = fileItemIterator.next();
@ -244,7 +245,14 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
if (item.isFormField() && CURR_GROUP_ID.equals(item.getFieldName())){
scopeGroupId = Streams.asString(item.openStream());
logger.debug("currentGroupId OK scope=" + PortalContext.getConfiguration().getCurrentScope(scopeGroupId));
logger.debug("currentGroupId passed as parameter = " + scopeGroupId);
logger.debug("currentGroupId into PortalContext scope= " + PortalContext.getConfiguration().getCurrentScope(scopeGroupId));
}
if (item.isFormField() && CURR_USER_ID.equals(item.getFieldName())){
currUserId = Streams.asString(item.openStream());
logger.debug("currUserId passed as parameter = " + currUserId);
logger.debug("currUserId into PortalContext scope= " + PortalContext.getConfiguration().getCurrentUser(request));
}
//MUST BE THE LAST PARAMETER TRASMITTED
@ -252,7 +260,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
uploadItem = item;
logger.debug("UPLOAD_FORM_ELEMENT OK "+uploadItem.getName() + " scopeGroupId="+scopeGroupId);
// break;
uploadData(scopeGroupId, request, response, uploadItem, destinationId, uploadType, listClientUploadKeys.get(uploadItemsCnt), isOverwrite);
uploadData(currUserId, scopeGroupId, request, response, uploadItem, destinationId, uploadType, listClientUploadKeys.get(uploadItemsCnt), isOverwrite);
uploadItemsCnt++;
}
}
@ -338,9 +346,12 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
return keyFiles;
}
/**
* Upload data.
*
* @param currUserId the curr user id
* @param scopeGroupId the scope group id
* @param request the request
* @param response the response
* @param uploadItem the upload item
@ -351,9 +362,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
* @throws ServletException the servlet exception
* @throws IOException Signals that an I/O exception has occurred.
*/
private void uploadData(String scopeGroupId, HttpServletRequest request, final HttpServletResponse response, final FileItemStream uploadItem, String destinationId,String uploadType,String clientUploadKey, boolean isOverwrite) throws ServletException, IOException{
private void uploadData(String currUserId, String scopeGroupId, HttpServletRequest request, final HttpServletResponse response, final FileItemStream uploadItem, String destinationId,String uploadType,String clientUploadKey, boolean isOverwrite) throws ServletException, IOException{
String fileName = uploadItem.getName();
logger.info("Upload servlet parameters: [fileName: "+fileName+ ", destinationId: "+destinationId +", uploadType: "+uploadType+", isOverwrite: "+isOverwrite+", clientUploadKey: "+clientUploadKey+"]");
@ -374,7 +383,6 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
// WorkspaceUploaderItem workspaceUploader = createNewWorkspaceUploader(clientUploadKey,destinationId,fileName);
// saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.WAIT, "Uploading "+fileName+" at 0%", request.getSession());
//RETRIVE WORKSPACE UPLOADER FROM SESSION
WorkspaceUploaderItem workspaceUploader = null;
@ -395,8 +403,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
Workspace wa = null;
try {
logger.debug("getWorkspace from HL scopeGroupId="+scopeGroupId);
wa = WsUtil.getWorkspace(request, scopeGroupId);
logger.debug("getWorkspace from HL scopeGroupId="+scopeGroupId +", userId="+currUserId);
wa = WsUtil.getWorkspace(request, scopeGroupId, currUserId);
} 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());
@ -482,16 +490,16 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
String newItemName = itemName;
logger.debug("createTemplate: "+newItemName);
createTemplate(scopeGroupId, request, workspaceUploader, request.getSession(), wa, newItemName, inputStream, destinationFolder, response, isOverwrite);
createTemplate(currUserId, 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(scopeGroupId, request, workspaceUploader, request.getSession(), wa, newItemName, inputStream, destinationFolder, response, isOverwrite);
createReport(currUserId, scopeGroupId, request, workspaceUploader, request.getSession(), wa, newItemName, inputStream, destinationFolder, response, isOverwrite);
}else{ //CREATE AN EXTERNAL FILE
workspaceUploader = WorkspaceUploaderMng.uploadFile(scopeGroupId, request, workspaceUploader, request.getSession(), wa, itemName, inputStream, destinationFolder, contentType, isOverwrite, size);
workspaceUploader = WorkspaceUploaderMng.uploadFile(currUserId, 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!");
@ -505,14 +513,14 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
if (MimeTypeUtil.isZipContentType(uploadItem.getContentType())){ //UNZIP??
logger.debug("Unziping content");
workspaceUploader = WorkspaceUploaderMng.uploadArchive(workspaceUploader, request, itemName, inputStream, destinationFolder, size);
workspaceUploader = WorkspaceUploaderMng.uploadArchive(currUserId, 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{
workspaceUploader = WorkspaceUploaderMng.uploadFile(scopeGroupId, request, workspaceUploader, request.getSession(), wa, itemName, inputStream, destinationFolder, contentType, isOverwrite, size);
workspaceUploader = WorkspaceUploaderMng.uploadFile(currUserId, 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!");
@ -650,9 +658,12 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
logger.debug("Elapsed Time: "+time);
}
/**
* Notify upload in shared folder.
*
* @param currUserId the curr user id
* @param scopeGroupId the scope group id
* @param request the request
* @param httpSession the http session
* @param workspace the workspace
@ -660,9 +671,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
* @param destinationFolderId the destination folder id
* @param isOverwrite the is overwrite
*/
public static void notifyUploadInSharedFolder(final String scopeGroupId, final HttpServletRequest request, final HttpSession httpSession, final Workspace workspace, final String itemId, final String destinationFolderId, final boolean isOverwrite){
final GCubeUser currUser = PortalContext.getConfiguration().getCurrentUser(request);
System.out.println("**currUser="+currUser.toString());
public static void notifyUploadInSharedFolder(final String currUserId, final String scopeGroupId, final HttpServletRequest request, final HttpSession httpSession, final Workspace workspace, final String itemId, final String destinationFolderId, final boolean isOverwrite){
logger.trace("[2] HttpServletRequest is: URI: "+request.getRequestURI() +", ServerName: "+request.getServerName());
final NotificationsWorkspaceUploaderProducer np = new NotificationsWorkspaceUploaderProducer(scopeGroupId, httpSession,request);
new Thread(){
@ -673,7 +682,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
String sourceSharedId = sourceItem.getIdSharedFolder();
WorkspaceItem folderDestinationItem = workspace.getItem(destinationFolderId);
logger.trace("[3] HttpServletRequest is: URI: "+request.getRequestURI() +", ServerName: "+request.getServerName());
NotificationsWorkspaceUploader.checkSendNotifyChangedItemToShare(currUser, scopeGroupId, np, httpSession, sourceItem, sourceSharedId, folderDestinationItem,isOverwrite);
NotificationsWorkspaceUploader.checkSendNotifyChangedItemToShare(request, currUserId, scopeGroupId, np, httpSession, sourceItem, sourceSharedId, folderDestinationItem,isOverwrite);
} catch (Exception e) {
logger.error("Error in notifyUploadInSharedFolder", e);
}
@ -726,6 +735,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
/**
* Creates the report.
*
* @param currUserId the curr user id
* @param scopeGroupId the scope group id
* @param request the request
* @param workspaceUploader the workspace uploader
* @param httpSession the http session
@ -740,7 +751,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
* @throws InternalErrorException the internal error exception
* @throws IOException Signals that an I/O exception has occurred.
*/
private void createReport(String scopeGroupId, final HttpServletRequest request, WorkspaceUploaderItem workspaceUploader, HttpSession httpSession, Workspace wa, String itemName, InputStream fileInputStream, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{
private void createReport(String currUserId, 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 {
@ -750,7 +761,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
report = wa.createReport(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", "", 0, "",fileInputStream, destinationFolder.getId());
notifyUploadInSharedFolder(scopeGroupId, request, httpSession,wa,report.getId(),destinationFolder.getId(), isOverwrite);
notifyUploadInSharedFolder(currUserId, scopeGroupId, request, httpSession,wa,report.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+report.getName()+" imported correctly in "+destinationFolder.getPath());
}
else{ //CASE OVERWRITE
@ -758,7 +769,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
if(rep!=null){
notifyUploadInSharedFolder(scopeGroupId, request, httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite);
notifyUploadInSharedFolder(currUserId, scopeGroupId, request, httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath());
}
else
@ -785,9 +796,12 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
}
/**
* Creates the template.
*
* @param currUserId the curr user id
* @param scopeGroupId the scope group id
* @param request the request
* @param workspaceUploader the workspace uploader
* @param httpSession the http session
@ -802,7 +816,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
* @throws InternalErrorException the internal error exception
* @throws IOException Signals that an I/O exception has occurred.
*/
private void createTemplate(String scopeGroupId, final HttpServletRequest request, WorkspaceUploaderItem workspaceUploader, HttpSession httpSession, Workspace wa, String itemName, InputStream fileInputStream, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{
private void createTemplate(String currUserId, 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 {
@ -812,7 +826,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
template = wa.createReportTemplate(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", 0, "", fileInputStream, destinationFolder.getId());
notifyUploadInSharedFolder(scopeGroupId, request, httpSession,wa,template.getId(),destinationFolder.getId(), isOverwrite);
notifyUploadInSharedFolder(currUserId, scopeGroupId, request, httpSession,wa,template.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+template.getName()+" imported correctly in "+destinationFolder.getPath());
}else{ //CASE OVERWRITE
@ -820,7 +834,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
if(rep!=null){
notifyUploadInSharedFolder(scopeGroupId, request, httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite);
notifyUploadInSharedFolder(currUserId, scopeGroupId, request, httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath());
}
else

View File

@ -108,7 +108,8 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement
Workspace workspace;
try {
String scopeGroupId = ""+PortalContext.getConfiguration().getCurrentGroupId(getThreadLocalRequest());
workspace = WsUtil.getWorkspace(getThreadLocalRequest(), scopeGroupId);
String currUserId = ""+PortalContext.getConfiguration().getCurrentUser(getThreadLocalRequest());
workspace = WsUtil.getWorkspace(getThreadLocalRequest(), scopeGroupId, currUserId);
if(workspace!=null)
return workspace.getRoot().getId();
} catch (Exception e) {
@ -129,7 +130,8 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement
logger.trace("get itemExistsInWorkpace by parentId: "+parentId);
try {
String scopeGroupId = ""+PortalContext.getConfiguration().getCurrentGroupId(getThreadLocalRequest());
Workspace workspace = WsUtil.getWorkspace(getThreadLocalRequest(), scopeGroupId);
String currUserId = ""+PortalContext.getConfiguration().getCurrentUser(getThreadLocalRequest());
Workspace workspace = WsUtil.getWorkspace(getThreadLocalRequest(), scopeGroupId, currUserId);
WorkspaceItem wsItem = workspace.getItem(parentId); //GET PARENT
if(wsItem.getType().equals(WorkspaceItemType.FOLDER) || wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)){

View File

@ -34,12 +34,14 @@ public class WorkspaceUploaderWsUtil extends HttpServlet {
String folderParentId = req.getParameter(ConstantsWorkspaceUploader.FOLDER_PARENT_ID);
String itemName = req.getParameter(ConstantsWorkspaceUploader.ITEM_NAME);
String currGroupId = req.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);
logger.debug("currUserId: "+currUserId);
try {
String itemId = itemExistsInWorkpaceFolder(currGroupId, req, folderParentId, itemName);
String itemId = itemExistsInWorkpaceFolder(currUserId, currGroupId, req, folderParentId, itemName);
sendOKMessage(resp, itemId);
}
catch (Exception e) {
@ -48,23 +50,21 @@ public class WorkspaceUploaderWsUtil extends HttpServlet {
}
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#itemExistsInWorkpaceFolder(java.lang.String, java.lang.String)
*/
//@Override
/**
* Item exists in workpace folder.
*
* @param currUserId the curr user id
* @param currGroupId the curr group id
* @param req the req
* @param parentId the parent id
* @param itemName the item name
* @return the string
* @throws Exception the exception
*/
public String itemExistsInWorkpaceFolder(String currGroupId, HttpServletRequest req, String parentId, String itemName) throws Exception {
public String itemExistsInWorkpaceFolder(String currUserId, String currGroupId, HttpServletRequest req, String parentId, String itemName) throws Exception {
logger.trace("get itemExistsInWorkpace for name: "+itemName+", by parentId: "+parentId);
try {
Workspace workspace = WsUtil.getWorkspace(req, currGroupId);
Workspace workspace = WsUtil.getWorkspace(req, currGroupId, currUserId);
WorkspaceItem wsItem = workspace.getItem(parentId); //GET PARENT
if(wsItem.getType().equals(WorkspaceItemType.FOLDER) || wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)){

View File

@ -17,26 +17,33 @@ 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.portlets.widgets.workspaceuploader.shared.ContactModel;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
/**
* The Class NotificationsWorkspaceUploader.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @May 27, 2013
*
*/
public class NotificationsWorkspaceUploader {
protected static Logger logger = Logger.getLogger(NotificationsWorkspaceUploader.class);
/**
* Send a notification if an item is added or updated to sharing folder
* @param httpSession
* @param sourceItem
* @param sourceSharedId
* @param folderDestinationItem
* Check send notify changed item to share.
*
* @param request the request
* @param currUserId the curr user id
* @param scopeGroupId the scope group id
* @param np the np
* @param httpSession the http session
* @param sourceItem the source item
* @param sourceSharedId the source shared id
* @param folderDestinationItem the folder destination item
* @param isOverwrite the is overwrite
*/
public static void checkSendNotifyChangedItemToShare(GCubeUser currUser, String scopeGroupId, NotificationsWorkspaceUploaderProducer np, HttpSession httpSession, final WorkspaceItem sourceItem, final String sourceSharedId, final WorkspaceItem folderDestinationItem, boolean isOverwrite) {
public static void checkSendNotifyChangedItemToShare(HttpServletRequest request, String currUserId, String scopeGroupId, NotificationsWorkspaceUploaderProducer np, HttpSession httpSession, final WorkspaceItem sourceItem, final String sourceSharedId, final WorkspaceItem folderDestinationItem, boolean isOverwrite) {
logger.trace("checkSendNotifyAddItemToShare");
@ -57,7 +64,7 @@ public class NotificationsWorkspaceUploader {
//if shareChangeCondition is true.. notifies added item to sharing
if(shareChangeCondition){
Workspace workspace = WsUtil.getWorkspace(currUser.getUsername(), scopeGroupId);
Workspace workspace = WsUtil.getWorkspace(request, scopeGroupId, currUserId);
List<ContactModel> listContacts = getListUserSharedByFolderSharedId(workspace, folderDestinationItem.getIdSharedFolder());
@ -89,11 +96,12 @@ public class NotificationsWorkspaceUploader {
}
/**
* Gets the list user shared by folder shared id.
*
* @param workspace
* @param idSharedFolder
* @return
* @throws Exception
* @param workspace the workspace
* @param idSharedFolder the id shared folder
* @return the list user shared by folder shared id
* @throws Exception the exception
*/
public static List<ContactModel> getListUserSharedByFolderSharedId(Workspace workspace, String idSharedFolder) throws Exception {
@ -128,9 +136,10 @@ public class NotificationsWorkspaceUploader {
}
/**
* Checks if is a shared folder.
*
* @param wsItem
* @return
* @param wsItem the ws item
* @return true, if is a shared folder
*/
public static boolean isASharedFolder(WorkspaceItem wsItem){
if(wsItem!=null)
@ -138,19 +147,24 @@ public class NotificationsWorkspaceUploader {
return false;
}
/**
* Checks if is a shared folder for id.
*
* @param wsItem
* @return
* @param currUserId the curr user id
* @param scopeGroupId the scope group id
* @param request the request
* @param itemId the item id
* @return true, if is a shared folder for id
*/
public static boolean isASharedFolderForId(String scopeGroupId, HttpServletRequest request, String itemId){
public static boolean isASharedFolderForId(String currUserId, String scopeGroupId, HttpServletRequest request, String itemId){
if(itemId==null || itemId.isEmpty())
return false;
try {
Workspace workspace = WsUtil.getWorkspace(request, scopeGroupId);
Workspace workspace = WsUtil.getWorkspace(request, scopeGroupId, currUserId);
WorkspaceItem wsItem = workspace.getItem(itemId);
if(wsItem!=null)
@ -165,10 +179,11 @@ public class NotificationsWorkspaceUploader {
/**
* Check is root folder shared.
*
* @param itemId
* @param rootFolderSharedId
* @return
* @param itemId the item id
* @param rootFolderSharedId the root folder shared id
* @return true, if successful
*/
public static boolean checkIsRootFolderShared(String itemId, String rootFolderSharedId) {

View File

@ -50,6 +50,8 @@ public class WorkspaceUploaderMng {
/**
* Creates the workspace uploader file.
*
* @param currUserId the curr user id
* @param scopeGroupId the scope group id
* @param request the request
* @param workspaceUploader the workspace uploader
* @param httpSession the http session
@ -64,7 +66,7 @@ public class WorkspaceUploaderMng {
* @throws InternalErrorException the internal error exception
* @throws IOException Signals that an I/O exception has occurred.
*/
private static WorkspaceUploaderItem createWorkspaceUploaderFile(String scopeGroupId, HttpServletRequest request, final WorkspaceUploaderItem workspaceUploader, final HttpSession httpSession, final boolean isOvewrite, final Workspace wa, final InputStream uploadFile, final String itemName, final WorkspaceFolder destinationFolder, final String contentType, final long totalBytes) throws InternalErrorException, IOException{
private static WorkspaceUploaderItem createWorkspaceUploaderFile(String currUserId, String scopeGroupId, HttpServletRequest request, final WorkspaceUploaderItem workspaceUploader, final HttpSession httpSession, final boolean isOvewrite, final Workspace wa, final InputStream uploadFile, final String itemName, final WorkspaceFolder destinationFolder, final String contentType, final long totalBytes) throws InternalErrorException, IOException{
logger.debug("Creating WorkspaceUploaderFile...");
workspaceUploader.setUploadStatus(UPLOAD_STATUS.IN_PROGRESS);
@ -88,7 +90,7 @@ public class WorkspaceUploaderMng {
workspaceUploader.getFile().setParentId(createdItem.getParent().getId());//SET PARENT ID
workspaceUploader.setStatusDescription("File \""+createdItem.getName()+"\" uploaded correctly in "+destinationFolder.getPath());
workspaceUploader.setUploadStatus(UPLOAD_STATUS.COMPLETED);
WorkspaceUploadServletStream.notifyUploadInSharedFolder(scopeGroupId, request, httpSession, wa, createdItem.getId(), createdItem.getParent().getId(), isOvewrite);
WorkspaceUploadServletStream.notifyUploadInSharedFolder(currUserId, scopeGroupId, request, httpSession, wa, createdItem.getId(), createdItem.getParent().getId(), isOvewrite);
}else{
workspaceUploader.setStatusDescription("An error occurred during upload: \""+itemName + "\". Try again");
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
@ -147,8 +149,10 @@ public class WorkspaceUploaderMng {
/**
* Creates the workspace uploader archive.
*
* @param currUserId the curr user id
* @param scopeGroupId the scope group id
* @param workspaceUploader the workspace uploader
* @param httpSession the http session
* @param request the request
* @param uploadFile the upload file
* @param itemName the item name
* @param destinationFolder the destination folder
@ -157,7 +161,7 @@ public class WorkspaceUploaderMng {
* @throws InternalErrorException the internal error exception
* @throws IOException Signals that an I/O exception has occurred.
*/
private static WorkspaceUploaderItem createWorkspaceUploaderArchive(final WorkspaceUploaderItem workspaceUploader, final HttpServletRequest request, final InputStream uploadFile, final String itemName, final WorkspaceFolder destinationFolder, final long totalBytes) throws InternalErrorException, IOException{
private static WorkspaceUploaderItem createWorkspaceUploaderArchive(String currUserId, 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 {
@ -203,10 +207,11 @@ public class WorkspaceUploaderMng {
}
/**
* Upload file.
*
* @param currUserId the curr user id
* @param scopeGroupId the scope group id
* @param request the request
* @param workspaceUploader the workspace uploader
* @param httpSession the http session
@ -220,10 +225,10 @@ public class WorkspaceUploaderMng {
* @return the workspace uploader item
* @throws Exception the exception
*/
public static WorkspaceUploaderItem uploadFile(String scopeGroupId, HttpServletRequest request, WorkspaceUploaderItem workspaceUploader, HttpSession httpSession, Workspace wa, String itemName, InputStream file, WorkspaceFolder destinationFolder, String contentType, boolean isOverwrite, long totolaBytes) throws Exception {
public static WorkspaceUploaderItem uploadFile(String currUserId, String scopeGroupId, HttpServletRequest request, WorkspaceUploaderItem workspaceUploader, HttpSession httpSession, Workspace wa, String itemName, InputStream file, WorkspaceFolder destinationFolder, String contentType, boolean isOverwrite, long totolaBytes) throws Exception {
try {
return createWorkspaceUploaderFile(scopeGroupId, request, workspaceUploader, httpSession, isOverwrite, wa, file, itemName, destinationFolder, contentType, totolaBytes);
return createWorkspaceUploaderFile(currUserId, scopeGroupId, request, workspaceUploader, httpSession, isOverwrite, wa, 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");
@ -234,8 +239,10 @@ public class WorkspaceUploaderMng {
/**
* Upload archive.
*
* @param currUserId the curr user id
* @param scopeGroupId the scope group id
* @param workspaceUploader the workspace uploader
* @param httpSession the http session
* @param request the request
* @param itemName the item name
* @param file the file
* @param destinationFolder the destination folder
@ -243,10 +250,10 @@ public class WorkspaceUploaderMng {
* @return the workspace uploader item
* @throws Exception the exception
*/
public static WorkspaceUploaderItem uploadArchive(WorkspaceUploaderItem workspaceUploader, HttpServletRequest request, String itemName, InputStream file, WorkspaceFolder destinationFolder, long totalBytes) throws Exception {
public static WorkspaceUploaderItem uploadArchive(String currUserId, String scopeGroupId, WorkspaceUploaderItem workspaceUploader, HttpServletRequest request, String itemName, InputStream file, WorkspaceFolder destinationFolder, long totalBytes) throws Exception {
try {
return createWorkspaceUploaderArchive(workspaceUploader, request, file, itemName, destinationFolder, totalBytes);
return createWorkspaceUploaderArchive(currUserId, scopeGroupId, workspaceUploader, request, file, itemName, destinationFolder, totalBytes);
} catch (Exception e) {
logger.error("Error when uploading Archive to HL creation: ",e);
@ -257,7 +264,7 @@ public class WorkspaceUploaderMng {
/**
* Upload file status.
*
* @param httpSession the http session
* @param request the request
* @param workspaceUploader the workspace uploader
* @return the workspace uploader item
* @throws Exception the exception

View File

@ -15,29 +15,25 @@ import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNot
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import com.liferay.portal.service.UserLocalServiceUtil;
/**
* The Class WsUtil.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Feb 18, 2014
* Dec 21, 2016
*/
public class WsUtil {
public static final String NOTIFICATION_MANAGER_UPLOADER = "WS_UPLOADER_NOTIFICATION_MANAGER";
// public static final String NOTIFICATION_PRODUCER = "WORKSPACE_UPLOADER_NOTIFICATION_PRODUCER";
// public static final String NOTIFICATION_PORTLET_CLASS_ID = WorkspaceUploadServletStream.class.getName(); //IN DEV
public static final String NOTIFICATION_PORTLET_CLASS_ID = "org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl";
protected static Logger logger = Logger.getLogger(WsUtil.class);
// public static boolean withoutPortal = false;
/**
* Checks if is within portal.
*
@ -54,46 +50,67 @@ public class WsUtil {
}
}
/**
* Gets the workspace.
*
* @param httpSession the http session
* @param request the request
* @param scopeGroupId the scope group id
* @param currUserId the curr user id
* @return the workspace
* @throws InternalErrorException the internal error exception
* @throws HomeNotFoundException the home not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
*/
public static Workspace getWorkspace(final HttpServletRequest request, String scopeGroupId) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException{
public static Workspace getWorkspace(final HttpServletRequest request, String scopeGroupId, String currUserId) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException{
logger.trace("Get Workspace");
PortalContext pContext = PortalContext.getConfiguration();
String username = pContext.getCurrentUser(request).getUsername();
String scope = pContext.getCurrentScope(scopeGroupId);
logger.trace("Client context scope: "+ scope + " username: "+username);
ScopeProvider.instance.set(scope);
String username = null;
try {
GCubeUser gCubeUser = new LiferayUserManager().getUserById(Long.valueOf(currUserId));
logger.debug("Gcube user read from liferay: "+gCubeUser);
if(gCubeUser!=null && gCubeUser.getUsername()!=null)
username = gCubeUser.getUsername();
} catch (Exception e) {
String error = "Error retrieving gCubeUser for: [userId= "
+ currUserId + ", scope: " + scope + "]";
logger.error(error, e);
}
if(username==null || username.isEmpty())
username = pContext.getCurrentUser(request).getUsername();
logger.info("Client context scope: "+ scope + " username: "+username);
return HomeLibrary.getUserWorkspace(username);
}
/**
* Gets the workspace.
*
* @param httpSession the http session
* @return the workspace
* @throws InternalErrorException the internal error exception
* @throws HomeNotFoundException the home not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
*/
public static Workspace getWorkspace(String username, String scopeGroupId) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException{
logger.trace("Get Workspace for user = " + username);
PortalContext pContext = PortalContext.getConfiguration();
String scope = pContext.getCurrentScope(scopeGroupId);
logger.trace("Client context scope: "+ scope + " username: "+username);
ScopeProvider.instance.set(scope);
return HomeLibrary.getUserWorkspace(username);
}
// /**
// * Gets the workspace.
// *
// * @param username the username
// * @param scopeGroupId the scope group id
// * @param currUserId the curr user id
// * @return the workspace
// * @throws InternalErrorException the internal error exception
// * @throws HomeNotFoundException the home not found exception
// * @throws WorkspaceFolderNotFoundException the workspace folder not found exception
// */
// public static Workspace getWorkspace(String username, String scopeGroupId, String currUserId) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException{
//
// logger.trace("Get Workspace for user = " + username);
// PortalContext pContext = PortalContext.getConfiguration();
// String scope = pContext.getCurrentScope(scopeGroupId);
// logger.trace("Client context scope: "+ scope + " username: "+username);
//
// ScopeProvider.instance.set(scope);
// return HomeLibrary.getUserWorkspace(username);
// }
/**
@ -157,7 +174,7 @@ public class WsUtil {
/**
* Gets the workspace uploader in session.
*
* @param httpSession the http session
* @param request the request
* @param uploaderIdentifier the uploader identifier
* @return the workspace uploader in session
* @throws Exception the exception
@ -176,7 +193,7 @@ public class WsUtil {
/**
* Sets the erasable workspace uploader in session.
*
* @param httpSession the http session
* @param request the request
* @param uploaderIdentifier the uploader identifier
* @return true, if successful
* @throws Exception the exception
@ -203,7 +220,7 @@ public class WsUtil {
/**
* Gets the user id.
*
* @param httpSession the http session
* @param request the request
* @return the user id
*/
public static String getUserId(HttpServletRequest request) {