|
|
|
@ -18,6 +18,7 @@ import org.gcube.common.storagehub.model.service.Version;
|
|
|
|
|
import org.gcube.common.storagehub.model.types.WorkspaceItemType;
|
|
|
|
|
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
|
|
|
|
|
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
|
|
|
|
|
import org.gcube.common.storagehubwrapper.shared.Member;
|
|
|
|
|
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
|
|
|
|
|
import org.gcube.portlets.widgets.workspaceuploader.server.util.UserUtil;
|
|
|
|
|
import org.gcube.portlets.widgets.workspaceuploader.shared.ContactModel;
|
|
|
|
@ -25,96 +26,97 @@ import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The Class NotificationsWorkspaceUploader.
|
|
|
|
|
*
|
|
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
|
|
|
|
* Jul 2, 2018
|
|
|
|
|
* Jul 2, 2018
|
|
|
|
|
*/
|
|
|
|
|
public class NotificationsWorkspaceUploader {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected static Logger logger = LoggerFactory.getLogger(NotificationsWorkspaceUploader.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
* @param np the np
|
|
|
|
|
* @param httpSession the http session
|
|
|
|
|
* @param sourceItem the source item
|
|
|
|
|
* @param sourceSharedId the source shared id
|
|
|
|
|
* @param storageWrapper the storage wrapper
|
|
|
|
|
* @param request the request
|
|
|
|
|
* @param currUser the curr user
|
|
|
|
|
* @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
|
|
|
|
|
* @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 FolderItem folderDestinationItem) {
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
|
|
logger.debug("checkSendNotifyChangedItemToShare called");
|
|
|
|
|
|
|
|
|
|
if(folderDestinationItem!=null){
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
if(folderDestinationItem.isShared()){ //Notify Added Item To Sharing?
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
boolean shareChangeCondition = sourceSharedId==null?false:true;
|
|
|
|
|
logger.debug("shareChangeCondition add item: "+shareChangeCondition);
|
|
|
|
|
if (folderDestinationItem != null) {
|
|
|
|
|
|
|
|
|
|
//if shareChangeCondition is true.. notifies added item to sharing
|
|
|
|
|
if(shareChangeCondition){
|
|
|
|
|
try {
|
|
|
|
|
if (folderDestinationItem.isShared()) { // Notify Added Item To Sharing?
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
boolean shareChangeCondition = sourceSharedId == null ? false : true;
|
|
|
|
|
logger.debug("shareChangeCondition add item: " + shareChangeCondition);
|
|
|
|
|
|
|
|
|
|
// if shareChangeCondition is true.. notifies added item to sharing
|
|
|
|
|
if (shareChangeCondition) {
|
|
|
|
|
|
|
|
|
|
FolderItem folderDest = (FolderItem) folderDestinationItem;
|
|
|
|
|
SharedFolder rootSharedFolder = null;
|
|
|
|
|
try{
|
|
|
|
|
FolderItem sharedFolder = storageWrapper.getStorageHubClientService().getRootSharedFolder(folderDest.getId());
|
|
|
|
|
try {
|
|
|
|
|
FolderItem sharedFolder = storageWrapper.getStorageHubClientService()
|
|
|
|
|
.getRootSharedFolder(folderDest.getId());
|
|
|
|
|
rootSharedFolder = (SharedFolder) sharedFolder;
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
//silent
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Reading memmbers from rootSharedFolder
|
|
|
|
|
List<String> listLogins = storageWrapper.getWorkspace().getSharedFolderMembers(rootSharedFolder.getId());
|
|
|
|
|
List<ContactModel> listContacts = new ArrayList<ContactModel>(listLogins.size());
|
|
|
|
|
for (String login : listLogins) {
|
|
|
|
|
listContacts.add(new ContactModel(login, login, false, UserUtil.getUserFullName(login)));
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// silent
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reading members from rootSharedFolder
|
|
|
|
|
List<Member> listMemebers = storageWrapper.getWorkspace()
|
|
|
|
|
.getSharedFolderMembers(rootSharedFolder.getId());
|
|
|
|
|
|
|
|
|
|
List<ContactModel> listContacts = UserUtil.listMembersToListContact(listMemebers);
|
|
|
|
|
|
|
|
|
|
SocialFileItem socialItem = NotificationMapper.toSocialItem(storageWrapper, sourceItem);
|
|
|
|
|
|
|
|
|
|
//TO folderDest or rootSharedFolder??
|
|
|
|
|
// TO folderDest or rootSharedFolder??
|
|
|
|
|
SocialSharedFolder socialFolder = NotificationMapper.toSocialFolder(rootSharedFolder);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean isUpdate = false;
|
|
|
|
|
try {
|
|
|
|
|
List<Version> versions = storageWrapper.getStorageHubClientService().getListVersions(sourceItem.getId());
|
|
|
|
|
isUpdate = versions.size()>1?true:false;
|
|
|
|
|
logger.debug("Is file updating? "+shareChangeCondition);
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
//silent
|
|
|
|
|
List<Version> versions = storageWrapper.getStorageHubClientService()
|
|
|
|
|
.getListVersions(sourceItem.getId());
|
|
|
|
|
isUpdate = versions.size() > 1 ? true : false;
|
|
|
|
|
logger.debug("Is file updating? " + shareChangeCondition);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// silent
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//SWITCH BETWEEN ADDED OR UPDATED
|
|
|
|
|
if(!isUpdate)
|
|
|
|
|
// SWITCH BETWEEN ADDED OR UPDATED
|
|
|
|
|
if (!isUpdate)
|
|
|
|
|
np.notifyAddedItemToSharing(listContacts, socialItem, socialFolder);
|
|
|
|
|
else
|
|
|
|
|
np.notifyUpdatedItemToSharing(listContacts, socialItem, socialFolder);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
} else
|
|
|
|
|
logger.trace("folder destination is not shared");
|
|
|
|
|
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
logger.error("An error occurred in checkSendNotifyAddItemToShare ",e);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("An error occurred in checkSendNotifyAddItemToShare ", e);
|
|
|
|
|
}
|
|
|
|
|
}else
|
|
|
|
|
logger.warn("The notifies is failure in checkSendNotifyAddItemToShare because folder destination item is null");
|
|
|
|
|
} else
|
|
|
|
|
logger.warn(
|
|
|
|
|
"The notifies is failure in checkSendNotifyAddItemToShare because folder destination item is null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -123,30 +125,29 @@ public class NotificationsWorkspaceUploader {
|
|
|
|
|
* @param wsItem the ws item
|
|
|
|
|
* @return true, if is a shared folder
|
|
|
|
|
*/
|
|
|
|
|
public static boolean isASharedFolder(WorkspaceItem wsItem){
|
|
|
|
|
if(wsItem!=null)
|
|
|
|
|
public static boolean isASharedFolder(WorkspaceItem wsItem) {
|
|
|
|
|
if (wsItem != null)
|
|
|
|
|
return wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if is a shared folder for id.
|
|
|
|
|
*
|
|
|
|
|
* @param workspace the workspace
|
|
|
|
|
* @param itemId the item id
|
|
|
|
|
* @param itemId the item id
|
|
|
|
|
* @return true, if is a shared folder for id
|
|
|
|
|
*/
|
|
|
|
|
public static boolean isASharedFolderForId(Workspace workspace, String itemId){
|
|
|
|
|
public static boolean isASharedFolderForId(Workspace workspace, String itemId) {
|
|
|
|
|
|
|
|
|
|
if(itemId==null || itemId.isEmpty())
|
|
|
|
|
if (itemId == null || itemId.isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
WorkspaceItem wsItem = workspace.getItem(itemId);
|
|
|
|
|
|
|
|
|
|
if(wsItem!=null)
|
|
|
|
|
if (wsItem != null)
|
|
|
|
|
return wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER);
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
@ -156,24 +157,24 @@ public class NotificationsWorkspaceUploader {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check is root folder shared.
|
|
|
|
|
*
|
|
|
|
|
* @param itemId the item id
|
|
|
|
|
* @param itemId the item id
|
|
|
|
|
* @param rootFolderSharedId the root folder shared id
|
|
|
|
|
* @return true, if successful
|
|
|
|
|
*/
|
|
|
|
|
public static boolean checkIsRootFolderShared(String itemId, String rootFolderSharedId) {
|
|
|
|
|
|
|
|
|
|
logger.trace("checkIsRootFolderShared between [itemid: "+itemId +", rootFolderSharedId: "+rootFolderSharedId+"]");
|
|
|
|
|
if(itemId==null)
|
|
|
|
|
logger.trace("checkIsRootFolderShared between [itemid: " + itemId + ", rootFolderSharedId: "
|
|
|
|
|
+ rootFolderSharedId + "]");
|
|
|
|
|
if (itemId == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if(rootFolderSharedId==null)
|
|
|
|
|
if (rootFolderSharedId == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if(itemId.compareTo(rootFolderSharedId)==0)
|
|
|
|
|
if (itemId.compareTo(rootFolderSharedId) == 0)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|