2015-10-02 11:46:32 +02:00
|
|
|
/**
|
2016-05-31 15:53:54 +02:00
|
|
|
*
|
2015-10-02 11:46:32 +02:00
|
|
|
*/
|
|
|
|
package org.gcube.portlets.widgets.workspaceuploader.server.notification;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2016-05-31 15:53:54 +02:00
|
|
|
import javax.servlet.http.HttpServletRequest;
|
2015-10-02 11:46:32 +02:00
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
|
|
|
|
import org.apache.log4j.Logger;
|
2018-06-25 12:42:41 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.Item;
|
2018-06-26 17:17:10 +02:00
|
|
|
import org.gcube.common.storagehub.model.items.SharedFolder;
|
2018-06-25 12:42:41 +02:00
|
|
|
import org.gcube.common.storagehub.model.types.WorkspaceItemType;
|
2018-06-26 17:17:10 +02:00
|
|
|
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
|
|
|
|
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
|
|
|
|
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
|
|
|
|
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder;
|
2015-10-02 11:46:32 +02:00
|
|
|
import org.gcube.portlets.widgets.workspaceuploader.shared.ContactModel;
|
2017-01-20 14:26:38 +01:00
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
2015-10-02 11:46:32 +02:00
|
|
|
|
|
|
|
/**
|
2016-12-21 14:20:48 +01:00
|
|
|
* The Class NotificationsWorkspaceUploader.
|
|
|
|
*
|
2015-10-02 11:46:32 +02:00
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
|
|
* @May 27, 2013
|
|
|
|
*/
|
|
|
|
public class NotificationsWorkspaceUploader {
|
2016-05-31 15:53:54 +02:00
|
|
|
|
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
protected static Logger logger = Logger.getLogger(NotificationsWorkspaceUploader.class);
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
/**
|
2016-12-21 14:20:48 +01:00
|
|
|
* Check send notify changed item to share.
|
|
|
|
*
|
2018-06-25 12:42:41 +02:00
|
|
|
* @param storageWrapper the storage wrapper
|
2016-12-21 14:20:48 +01:00
|
|
|
* @param request the request
|
2017-01-20 14:26:38 +01:00
|
|
|
* @param currUser the curr user
|
2016-12-21 14:20:48 +01:00
|
|
|
* @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
|
2015-10-02 11:46:32 +02:00
|
|
|
*/
|
2018-06-25 12:42:41 +02:00
|
|
|
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) {
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
logger.trace("checkSendNotifyAddItemToShare");
|
2016-05-31 15:53:54 +02:00
|
|
|
|
|
|
|
if(folderDestinationItem!=null){
|
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
try{
|
|
|
|
if(folderDestinationItem.isShared()){ //Notify Added Item To Sharing?
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2018-06-26 17:17:10 +02:00
|
|
|
//TODO folderDestinationItem.getIdSharedFolder()
|
2015-10-02 11:46:32 +02:00
|
|
|
logger.trace("checkNotifyAddItemToShare source item: "+sourceItem.getName()+" sourceSharedId: "+sourceSharedId + " folder destination: "+folderDestinationItem.getName() + " folder destination shared folder id: "+folderDestinationItem.getIdSharedFolder());
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
//share condition is true if source shared folder is not null
|
|
|
|
boolean shareChangeCondition = sourceSharedId==null?false:true;
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
//System.out.println("shareChangeCondition add item: "+ shareChangeCondition);
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
logger.trace("shareChangeCondition add item: "+shareChangeCondition);
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
//if shareChangeCondition is true.. notifies added item to sharing
|
2016-05-31 15:53:54 +02:00
|
|
|
if(shareChangeCondition){
|
2015-10-02 11:46:32 +02:00
|
|
|
|
2018-06-25 12:42:41 +02:00
|
|
|
//Workspace workspace = WsUtil.getWorkspace(request, scopeGroupId, currUser);
|
|
|
|
//Workspace workspace = storageWrapper.getWorkspace();
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2018-06-26 17:17:10 +02:00
|
|
|
SharedFolder folderDest = (SharedFolder) folderDestinationItem;
|
2018-06-25 12:42:41 +02:00
|
|
|
//TODO
|
2018-06-26 17:17:10 +02:00
|
|
|
List<ContactModel> listContacts = getListUserSharedByFolderSharedId(storageWrapper.getWorkspace(), folderDest.getIdSharedFolder());
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2018-06-26 17:17:10 +02:00
|
|
|
Item destinationSharedFolder = storageWrapper.getStorageHubClientService().getItem(folderDest.getIdSharedFolder());
|
2015-10-02 11:46:32 +02:00
|
|
|
|
|
|
|
if(destinationSharedFolder instanceof WorkspaceSharedFolder){
|
|
|
|
|
|
|
|
//SWITCH BEETWEEN ADDED OR UPDATED
|
|
|
|
if(!isOverwrite)
|
2018-06-25 12:42:41 +02:00
|
|
|
np.notifyAddedItemToSharing(listContacts, sourceItem, destinationSharedFolder);
|
2015-10-02 11:46:32 +02:00
|
|
|
else
|
2018-06-25 12:42:41 +02:00
|
|
|
np.notifyUpdatedItemToSharing(listContacts, sourceItem, destinationSharedFolder);
|
2016-05-31 15:53:54 +02:00
|
|
|
|
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
logger.trace("The notifies was sent correctly");
|
|
|
|
}else
|
|
|
|
logger.trace("The notifies doesn't sent because "+destinationSharedFolder+ " is not instance of WorkspaceSharedFolder");
|
2016-05-31 15:53:54 +02:00
|
|
|
// np.notifyAddedItemToSharing(listContacts, (WorkspaceFolder) folderDestinationItem);
|
2018-06-26 17:17:10 +02:00
|
|
|
}
|
2015-10-02 11:46:32 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
logger.trace("folder destination is not shared");
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
}catch (Exception e) {
|
|
|
|
logger.error("An error occurred in checkSendNotifyAddItemToShare ",e);
|
|
|
|
}
|
|
|
|
}else
|
2016-05-31 15:53:54 +02:00
|
|
|
logger.warn("The notifies is failure in checkSendNotifyAddItemToShare because folder destination item is null");
|
2015-10-02 11:46:32 +02:00
|
|
|
}
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
/**
|
2016-12-21 14:20:48 +01:00
|
|
|
* Gets the list user shared by folder shared id.
|
2016-05-31 15:53:54 +02:00
|
|
|
*
|
2016-12-21 14:20:48 +01:00
|
|
|
* @param workspace the workspace
|
|
|
|
* @param idSharedFolder the id shared folder
|
|
|
|
* @return the list user shared by folder shared id
|
|
|
|
* @throws Exception the exception
|
2015-10-02 11:46:32 +02:00
|
|
|
*/
|
|
|
|
public static List<ContactModel> getListUserSharedByFolderSharedId(Workspace workspace, String idSharedFolder) throws Exception {
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
logger.trace("getListUserSharedByFolderSharedId "+ idSharedFolder);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
WorkspaceItem wsItem = workspace.getItem(idSharedFolder);
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
if(isASharedFolder(wsItem)){
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2018-06-25 12:42:41 +02:00
|
|
|
//TODO wsFolder.getUsers();
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2018-06-25 12:42:41 +02:00
|
|
|
// 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)));
|
|
|
|
// }
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
return users;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
logger.info("the item with id: "+idSharedFolder+ " is not "+WorkspaceItemType.SHARED_FOLDER);
|
|
|
|
}
|
|
|
|
return new ArrayList<ContactModel>();
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error in getListUserSharedByItemId ", e);
|
|
|
|
throw new Exception(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
/**
|
2016-12-21 14:20:48 +01:00
|
|
|
* Checks if is a shared folder.
|
2016-05-31 15:53:54 +02:00
|
|
|
*
|
2016-12-21 14:20:48 +01:00
|
|
|
* @param wsItem the ws item
|
|
|
|
* @return true, if is a shared folder
|
2015-10-02 11:46:32 +02:00
|
|
|
*/
|
|
|
|
public static boolean isASharedFolder(WorkspaceItem wsItem){
|
|
|
|
if(wsItem!=null)
|
|
|
|
return wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER);
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2016-12-21 14:20:48 +01:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
/**
|
2016-12-21 14:20:48 +01:00
|
|
|
* Checks if is a shared folder for id.
|
2016-05-31 15:53:54 +02:00
|
|
|
*
|
2017-01-20 14:26:38 +01:00
|
|
|
* @param user the user
|
2016-12-21 14:20:48 +01:00
|
|
|
* @param scopeGroupId the scope group id
|
|
|
|
* @param request the request
|
|
|
|
* @param itemId the item id
|
|
|
|
* @return true, if is a shared folder for id
|
2015-10-02 11:46:32 +02:00
|
|
|
*/
|
2018-06-25 12:42:41 +02:00
|
|
|
public static boolean isASharedFolderForId(Workspace workspace, String itemId){
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
if(itemId==null || itemId.isEmpty())
|
|
|
|
return false;
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
try {
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
WorkspaceItem wsItem = workspace.getItem(itemId);
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
if(wsItem!=null)
|
|
|
|
return wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER);
|
|
|
|
return false;
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("An errror occurred in isASharedFolderForId", e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
|
|
|
|
/**
|
2016-12-21 14:20:48 +01:00
|
|
|
* Check is root folder shared.
|
2016-05-31 15:53:54 +02:00
|
|
|
*
|
2016-12-21 14:20:48 +01:00
|
|
|
* @param itemId the item id
|
|
|
|
* @param rootFolderSharedId the root folder shared id
|
|
|
|
* @return true, if successful
|
2015-10-02 11:46:32 +02:00
|
|
|
*/
|
|
|
|
public static boolean checkIsRootFolderShared(String itemId, String rootFolderSharedId) {
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
logger.trace("checkIsRootFolderShared between [itemid: "+itemId +", rootFolderSharedId: "+rootFolderSharedId+"]");
|
|
|
|
if(itemId==null)
|
|
|
|
return false;
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
if(rootFolderSharedId==null)
|
|
|
|
return false;
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
if(itemId.compareTo(rootFolderSharedId)==0)
|
|
|
|
return true;
|
2016-05-31 15:53:54 +02:00
|
|
|
|
2015-10-02 11:46:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|