Integrated with notification
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@169591 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
da2cee84f3
commit
5a49174e61
|
@ -26,7 +26,9 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||||
import org.apache.commons.fileupload.util.Streams;
|
import org.apache.commons.fileupload.util.Streams;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.common.portal.PortalContext;
|
||||||
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||||
import org.gcube.common.storagehub.model.items.Item;
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
|
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
|
||||||
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder;
|
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder;
|
||||||
|
@ -475,11 +477,6 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
||||||
//CONFIRM DESTINATION FOLDER
|
//CONFIRM DESTINATION FOLDER
|
||||||
workspaceUploader.getFile().setParentId(destinationFolder.getId());
|
workspaceUploader.getFile().setParentId(destinationFolder.getId());
|
||||||
|
|
||||||
//Create Item Uploader to read progress
|
|
||||||
// WorkspaceUploadFile wsUploadFile = new WorkspaceUploadFile(destinationFolder.getId(), itemName);
|
|
||||||
// workspaceUploader.setFile(wsUploadFile);
|
|
||||||
// workspaceUploader.setStatusDescription("Uploading "+itemName+" at 0%");
|
|
||||||
|
|
||||||
//instanciate the progress listener
|
//instanciate the progress listener
|
||||||
final AbstractUploadProgressListener uploadProgressListener = createNewListener(request.getSession(), clientUploadKey);
|
final AbstractUploadProgressListener uploadProgressListener = createNewListener(request.getSession(), clientUploadKey);
|
||||||
final UploadProgressInputStream inputStream = new UploadProgressInputStream(uploadItem.openStream(), size);
|
final UploadProgressInputStream inputStream = new UploadProgressInputStream(uploadItem.openStream(), size);
|
||||||
|
@ -492,29 +489,12 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
||||||
|
|
||||||
if(uploadType.compareTo(FILE)==0) {//IS FILE UPLOAD
|
if(uploadType.compareTo(FILE)==0) {//IS FILE UPLOAD
|
||||||
|
|
||||||
// boolean isZipFile = MimeTypeUtil.isZipContentType(uploadItem.getContentType()); //UNZIP??
|
workspaceUploader = WorkspaceUploaderMng.uploadFile(storageHubWrapper, user, scopeGroupId, request, workspaceUploader, request.getSession(), itemName, inputStream, destinationFolder, contentType, isOverwrite, size);
|
||||||
//
|
|
||||||
// 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(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!");
|
||||||
|
|
||||||
if(workspaceUploader==null)
|
sendMessage(response, workspaceUploader.getIdentifier());
|
||||||
throw new Exception("Error when creating uploader, it is null!");
|
|
||||||
|
|
||||||
sendMessage(response, workspaceUploader.getIdentifier());
|
|
||||||
// }
|
|
||||||
|
|
||||||
}else {//IS ARCHIVE UPLOAD
|
}else {//IS ARCHIVE UPLOAD
|
||||||
|
|
||||||
|
@ -693,11 +673,22 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
||||||
//Item sourceItem;
|
//Item sourceItem;
|
||||||
try {
|
try {
|
||||||
Item sourceItem = storageWrapper.getStorageHubClientService().getItem(itemId);
|
Item sourceItem = storageWrapper.getStorageHubClientService().getItem(itemId);
|
||||||
//TODO sourceItem.getIdSharedFolder();
|
|
||||||
String sourceSharedId = null;
|
String sourceSharedId = null;
|
||||||
|
try{
|
||||||
|
sourceSharedId = storageWrapper.getStorageHubClientService().getIdSharedFolder(itemId);
|
||||||
|
}catch(Exception e){
|
||||||
|
//silent
|
||||||
|
}
|
||||||
Item folderDestinationItem = storageWrapper.getStorageHubClientService().getItem(destinationFolderId);
|
Item folderDestinationItem = storageWrapper.getStorageHubClientService().getItem(destinationFolderId);
|
||||||
|
FolderItem folderDestination = null;
|
||||||
|
if(folderDestinationItem instanceof FolderItem){
|
||||||
|
folderDestination = (FolderItem) folderDestinationItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
Validate.notNull(folderDestination, "The folder destionation is null");
|
||||||
|
|
||||||
logger.trace("[3] HttpServletRequest is: URI: "+request.getRequestURI() +", ServerName: "+request.getServerName());
|
logger.trace("[3] HttpServletRequest is: URI: "+request.getRequestURI() +", ServerName: "+request.getServerName());
|
||||||
NotificationsWorkspaceUploader.checkSendNotifyChangedItemToShare(storageWrapper, request, currUser, scopeGroupId, np, httpSession, sourceItem, sourceSharedId, folderDestinationItem,isOverwrite);
|
NotificationsWorkspaceUploader.checkSendNotifyChangedItemToShare(storageWrapper, request, currUser, scopeGroupId, np, httpSession, sourceItem, sourceSharedId, folderDestination,isOverwrite);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Error in notifyUploadInSharedFolder", e);
|
logger.error("Error in notifyUploadInSharedFolder", e);
|
||||||
|
|
|
@ -11,6 +11,7 @@ import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.gcube.applicationsupportlayer.social.shared.SocialFileItem;
|
import org.gcube.applicationsupportlayer.social.shared.SocialFileItem;
|
||||||
import org.gcube.applicationsupportlayer.social.shared.SocialSharedFolder;
|
import org.gcube.applicationsupportlayer.social.shared.SocialSharedFolder;
|
||||||
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||||
import org.gcube.common.storagehub.model.items.Item;
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
import org.gcube.common.storagehub.model.items.SharedFolder;
|
import org.gcube.common.storagehub.model.items.SharedFolder;
|
||||||
import org.gcube.common.storagehub.model.types.WorkspaceItemType;
|
import org.gcube.common.storagehub.model.types.WorkspaceItemType;
|
||||||
|
@ -24,17 +25,19 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class NotificationsWorkspaceUploader.
|
* The Class NotificationsWorkspaceUploader.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||||
* Jun 26, 2018
|
* Jul 2, 2018
|
||||||
*/
|
*/
|
||||||
public class NotificationsWorkspaceUploader {
|
public class NotificationsWorkspaceUploader {
|
||||||
|
|
||||||
|
|
||||||
protected static Logger logger = LoggerFactory.getLogger(NotificationsWorkspaceUploader.class);
|
protected static Logger logger = LoggerFactory.getLogger(NotificationsWorkspaceUploader.class);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check send notify changed item to share.
|
* Check send notify changed item to share.
|
||||||
*
|
*
|
||||||
|
@ -49,7 +52,7 @@ public class NotificationsWorkspaceUploader {
|
||||||
* @param folderDestinationItem the folder destination item
|
* @param folderDestinationItem the folder destination item
|
||||||
* @param isOverwrite the is overwrite
|
* @param isOverwrite the is overwrite
|
||||||
*/
|
*/
|
||||||
public static void checkSendNotifyChangedItemToShare(StorageHubWrapper storageWrapper, HttpServletRequest request, GCubeUser currUser, String scopeGroupId, NotificationsWorkspaceUploaderProducer np, HttpSession httpSession, final Item sourceItem, final String sourceSharedId, final Item 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 FolderItem folderDestinationItem, boolean isOverwrite) {
|
||||||
|
|
||||||
logger.trace("checkSendNotifyAddItemToShare");
|
logger.trace("checkSendNotifyAddItemToShare");
|
||||||
|
|
||||||
|
@ -59,7 +62,7 @@ public class NotificationsWorkspaceUploader {
|
||||||
if(folderDestinationItem.isShared()){ //Notify Added Item To Sharing?
|
if(folderDestinationItem.isShared()){ //Notify Added Item To Sharing?
|
||||||
|
|
||||||
//TODO folderDestinationItem.getIdSharedFolder()
|
//TODO folderDestinationItem.getIdSharedFolder()
|
||||||
logger.trace("checkNotifyAddItemToShare source item: "+sourceItem.getName()+" sourceSharedId: "+sourceSharedId + " folder destination: "+folderDestinationItem.getName() + " folder destination shared folder id: "+folderDestinationItem);
|
logger.trace("checkNotifyAddItemToShare source item: "+sourceItem.getName()+" sourceSharedId: "+sourceSharedId + " folder destination name: "+folderDestinationItem.getName() + " folder destination id: "+folderDestinationItem.getId());
|
||||||
|
|
||||||
//share condition is true if source shared folder is not null
|
//share condition is true if source shared folder is not null
|
||||||
boolean shareChangeCondition = sourceSharedId==null?false:true;
|
boolean shareChangeCondition = sourceSharedId==null?false:true;
|
||||||
|
@ -71,27 +74,25 @@ public class NotificationsWorkspaceUploader {
|
||||||
//if shareChangeCondition is true.. notifies added item to sharing
|
//if shareChangeCondition is true.. notifies added item to sharing
|
||||||
if(shareChangeCondition){
|
if(shareChangeCondition){
|
||||||
|
|
||||||
//Workspace workspace = WsUtil.getWorkspace(request, scopeGroupId, currUser);
|
|
||||||
//Workspace workspace = storageWrapper.getWorkspace();
|
|
||||||
|
|
||||||
SharedFolder folderDest = (SharedFolder) folderDestinationItem;
|
SharedFolder folderDest = (SharedFolder) folderDestinationItem;
|
||||||
|
SharedFolder rootSharedFolder = null;
|
||||||
//TODO
|
try{
|
||||||
//WorkspaceItem destinationSharedFolder = workspace.getItem(folderDestinationItem.getIdSharedFolder());
|
FolderItem sharedFolder = storageWrapper.getStorageHubClientService().getRootSharedFolder(folderDest.getId());
|
||||||
//List<String> listLogins = storageWrapper.getWorkspace().getSharedFolderMembers(destinationSharedFolder.getId());
|
rootSharedFolder = (SharedFolder) sharedFolder;
|
||||||
|
}catch(Exception e){
|
||||||
|
//silent
|
||||||
|
}
|
||||||
|
|
||||||
List<String> listLogins = storageWrapper.getWorkspace().getSharedFolderMembers(folderDest.getId());
|
//Reading memmbers from rootSharedFolder
|
||||||
|
List<String> listLogins = storageWrapper.getWorkspace().getSharedFolderMembers(rootSharedFolder.getId());
|
||||||
List<ContactModel> listContacts = new ArrayList<ContactModel>(listLogins.size());
|
List<ContactModel> listContacts = new ArrayList<ContactModel>(listLogins.size());
|
||||||
for (String login : listLogins) {
|
for (String login : listLogins) {
|
||||||
listContacts.add(new ContactModel(login, login, false, UserUtil.getUserFullName(login)));
|
listContacts.add(new ContactModel(login, login, false, UserUtil.getUserFullName(login)));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Item destinationSharedFolder = storageWrapper.getWorkspace().getItem(folderDest.getIdSharedFolder());
|
|
||||||
|
|
||||||
SocialFileItem socialItem = NotificationMapper.toSocialItem(storageWrapper, sourceItem);
|
SocialFileItem socialItem = NotificationMapper.toSocialItem(storageWrapper, sourceItem);
|
||||||
|
|
||||||
//TODO
|
//TO folderDest or rootSharedFolder??
|
||||||
//SocialSharedFolder socialFolder = NotificationMapper.toSocialFolder(destinationSharedFolder);
|
|
||||||
SocialSharedFolder socialFolder = NotificationMapper.toSocialFolder(folderDest);
|
SocialSharedFolder socialFolder = NotificationMapper.toSocialFolder(folderDest);
|
||||||
|
|
||||||
//SWITCH BEETWEEN ADDED OR UPDATED
|
//SWITCH BEETWEEN ADDED OR UPDATED
|
||||||
|
@ -99,20 +100,6 @@ public class NotificationsWorkspaceUploader {
|
||||||
np.notifyAddedItemToSharing(listContacts, socialItem, socialFolder);
|
np.notifyAddedItemToSharing(listContacts, socialItem, socialFolder);
|
||||||
else
|
else
|
||||||
np.notifyUpdatedItemToSharing(listContacts, socialItem, socialFolder);
|
np.notifyUpdatedItemToSharing(listContacts, socialItem, socialFolder);
|
||||||
|
|
||||||
// if(destinationSharedFolder instanceof WorkspaceSharedFolder){
|
|
||||||
//
|
|
||||||
// //SWITCH BEETWEEN ADDED OR UPDATED
|
|
||||||
// if(!isOverwrite)
|
|
||||||
// np.notifyAddedItemToSharing(listContacts, sourceItem, destinationSharedFolder);
|
|
||||||
// else
|
|
||||||
// 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
|
else
|
||||||
|
@ -125,30 +112,6 @@ public class NotificationsWorkspaceUploader {
|
||||||
logger.warn("The notifies is failure in checkSendNotifyAddItemToShare because folder destination item is null");
|
logger.warn("The notifies is failure in checkSendNotifyAddItemToShare because folder destination item is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Gets the list user shared by folder shared id.
|
|
||||||
// *
|
|
||||||
// * @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(SharedFolder folder) throws Exception {
|
|
||||||
//
|
|
||||||
// try {
|
|
||||||
// ArrayList<ContactModel> users = new ArrayList<ContactModel>(listPortalLogin.size());
|
|
||||||
// for (String login : listPortalLogin) {
|
|
||||||
// users.add(new ContactModel(login, login, false, UserUtil.getUserFullName(login)));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return users;
|
|
||||||
//
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// logger.error("Error in getListUserSharedByItemId ", e);
|
|
||||||
// throw new Exception(e.getMessage());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if is a shared folder.
|
* Checks if is a shared folder.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue