ref 13226:StorageHub - Update workspace-sharing-widget to SH

https://support.d4science.org/issues/13226

Added notifications in case of share and unshare

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-sharing-widget@178697 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2019-03-26 16:10:16 +00:00
parent f47d1fa9f5
commit fa3a42ff6b
3 changed files with 91 additions and 84 deletions

View File

@ -36,6 +36,8 @@ import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL.USER_TYPE;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VO;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VRE;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
@ -281,6 +283,26 @@ public class GWTWorkspaceSharingBuilder {
return listContactsModel;
}
public List<InfoContactModel> searchUsersFromKeyword(PortalContextInfo info, String keyword)
throws Exception {
try {
logger.debug("Search Keyword: " + keyword);
List<InfoContactModel> listInfoContactModel = new ArrayList<>();
UserManager userManager = new LiferayUserManager();
List<GCubeUser> users = userManager.searchUsersByGroup(keyword, info.getCurrGroupId());
for (GCubeUser user : users) {
InfoContactModel icm = new InfoContactModel(String.valueOf(user.getUserId()), user.getUsername(),
user.getFullname(), false);
listInfoContactModel.add(icm);
}
return listInfoContactModel;
} catch (Exception e) {
logger.error("Error searching user by kewords: " + e.getLocalizedMessage(), e);
throw e;
}
}
/**
* Builds the gxt info contacts from portal logins.
*
@ -381,25 +403,29 @@ public class GWTWorkspaceSharingBuilder {
logger.info("Workspace item is a SharedFolder...");
SharedFolder shared = (SharedFolder) item;
String name = shared.isVreFolder() ? shared.getDisplayName() : item.getName();
fileModel = new FolderModel(item.getId(), name, item.getDescription(),parent, true, true, shared.isVreFolder());
fileModel = new FolderModel(item.getId(), name, item.getDescription(), parent, true, true,
shared.isVreFolder());
fileModel.setType(GXTFolderItemTypeEnum.SHARED_FOLDER.toString());
fileModel.setDescription(item.getDescription());
} else {
if (item instanceof FolderItem) {
logger.info("Workspace item is a Folder...");
fileModel = new FolderModel(item.getId(), item.getName(), item.getDescription(),parent, true, false, false);
fileModel = new FolderModel(item.getId(), item.getName(), item.getDescription(), parent, true,
false, false);
fileModel.setType(GXTFolderItemTypeEnum.FOLDER.toString());
fileModel.setDescription(item.getDescription());
} else {
if (item instanceof AbstractFileItem) {
logger.info("Workspace item is a AbstractFileItem...");
fileModel = new FileModel(item.getId(), item.getName(), item.getDescription(), parent, false, false);
fileModel = new FileModel(item.getId(), item.getName(), item.getDescription(), parent, false,
false);
AbstractFileItem abstractFileItem = (AbstractFileItem) item;
fileModel = setFolderItemType(fileModel, abstractFileItem);
} else {
if (item instanceof GCubeItem) {
logger.info("Workspace item is a GCubeItem...");
fileModel = new FileModel(item.getId(), item.getName(), item.getDescription(),parent, false, false);
fileModel = new FileModel(item.getId(), item.getName(), item.getDescription(), parent,
false, false);
fileModel.setFolderItemType(GXTFolderItemTypeEnum.GCUBE_ITEM);
} else {
logger.error("gxt conversion return null for item " + item.getName());

View File

@ -111,19 +111,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
}
return listContactsModel;
}
// READING USERS FROM VRE
/*
* UserManager userManag = new LiferayUserManager(); GroupManager gm
* = new LiferayGroupManager(); String aslSessionGN =
* aslSession.getGroupName();
* logger.info("aslSession.getGroupName(): "+ aslSessionGN); String
* groupId = gm.getGroupId(aslSessionGN);
* logger.info("groupId from GroupManager: "+ groupId);
* logger.info("Liferay User Manager getting list users by group: "
* +groupId); List<InfoContactModel> listContactsModel =
* builder.buildGXTListContactsModelFromUserModel(userManag.
* listUsersByGroup(groupId));
*/
PortalContextInfo info = WsUtil.getPortalContext(this.getThreadLocalRequest());
@ -463,6 +451,8 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
Set<String> logins = new HashSet<>(listLogin);
folderContainer.share(logins, getAccessType(acl));
created = true;
NotificationsProducer np = getNotificationProducer(this.getThreadLocalRequest());
np.notifyFolderSharing(listContacts, folderItem);
} else {
logger.debug("The folder is already shared");
throw new Exception("The folder selected is already shared!");
@ -472,6 +462,9 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
Set<String> logins = new HashSet<>(listLogin);
folderContainer.share(logins, getAccessType(acl));
created = true;
NotificationsProducer np = getNotificationProducer(this.getThreadLocalRequest());
np.notifyFolderSharing(listContacts, folderItem);
}
} else {
logger.error("Invalid folder retrieved: [id=" + itemId + "]");
@ -483,27 +476,6 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
}
/*
* if (created) { NotificationsProducer np =
* getNotificationProducer(this.getThreadLocalRequest()); if
* (!sourceFolderIsShared) {// if source folder is not already //
* shared
*
* // TODO ADD NOTIFICATION // np.notifyFolderSharing(listContacts,
* sharedFolder);
*
* } else {
*
* //System.out.println("SHARED CONTACS: ");
* //printContacts(listSharedContact);
* //System.out.println("NEW CONTACS: ");
* //printContacts(listContacts);
*
*
* // TODO ADD NOTIFICATION //
* np.notifyAddedUsersToSharing(listSharedContact, // listContacts,
* sharedFolder); } }
*/
return created;
@ -891,7 +863,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
logger.error("Invalid folder requested: [id=" + itemId + "]");
throw new Exception("Invalid folder requested: [id=" + itemId + "]");
}
boolean shared = false;
boolean unshared = false;
StorageHubClient shc = new StorageHubClient();
OpenResolver openResolver = shc.open(itemId);
FolderContainer folderContainer = openResolver.asFolder();
@ -903,7 +875,15 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
logger.debug("Folder type: SharedFolder");
SharedFolder sharedFolder = (SharedFolder) folderItem;
folderContainer.unshare(sharedFolder.getUsers().getMap().keySet());
shared = true;
unshared = true;
ArrayList<InfoContactModel> listContacts=new ArrayList<>();
for(String key:sharedFolder.getUsers().getMap().keySet()){
InfoContactModel contact=new InfoContactModel(key,key, key, false);
listContacts.add(contact);
}
NotificationsProducer np = getNotificationProducer(this.getThreadLocalRequest());
np.notifyFolderUnSharing(listContacts, folderItem);
} else {
String msg = "The folder requested is not a root shared folder."
+ "To unshare this folder you have to unshare the root shared folder!";
@ -921,7 +901,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
throw new Exception("Invalid folder retrieved: [id=" + itemId + "]");
}
return shared;
return unshared;
} catch (Exception e) {
logger.error("Error in unSharedFolderByFolderSharedId(): " + e.getLocalizedMessage(), e);

View File

@ -10,6 +10,7 @@ import org.gcube.applicationsupportlayer.social.NotificationsManager;
import org.gcube.applicationsupportlayer.social.shared.SocialFileItem;
import org.gcube.applicationsupportlayer.social.shared.SocialSharedFolder;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.storagehub.model.items.FolderItem;
import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.storagehub.model.items.SharedFolder;
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.DiffereceBeetweenInfoContactModel;
@ -64,10 +65,10 @@ public class NotificationsProducer {
*
* @param listContacts
* the list contacts
* @param sharedFolder
* @param folderItem
* the shared folder
*/
public void notifyFolderSharing(final List<InfoContactModel> listContacts, final SharedFolder sharedFolder) {
public void notifyFolderSharing(final List<InfoContactModel> listContacts, final FolderItem folderItem) {
new Thread() {
@Override
@ -81,15 +82,15 @@ public class NotificationsProducer {
// CURRENT USER
if (infoContactModel.getLogin().compareTo(userId) != 0) {
logger.trace("Sending notification new share folder " + sharedFolder.getName()
logger.trace("Sending notification new share folder " + folderItem.getName()
+ " for user " + infoContactModel.getLogin());
// DEBUG
System.out.println("Sending notification new share folder " + sharedFolder.getName()
System.out.println("Sending notification new share folder " + folderItem.getName()
+ " for user " + infoContactModel.getLogin());
SocialItemFactory socialItemFactor = new SocialItemFactory();
SocialSharedFolder socialSharedFolder = socialItemFactor
.createSocialSharedFolder(sharedFolder);
.createSocialSharedFolder(folderItem);
boolean notify = notificationsMng.notifyFolderSharing(infoContactModel.getLogin(),
socialSharedFolder);
@ -184,11 +185,11 @@ public class NotificationsProducer {
* the previous name
* @param item
* the item
* @param sharedFolder
* @param folderItem
* the shared folder
*/
public void notifyItemRenamed(final List<InfoContactModel> listSharedContact, final String previousName,
final Item item, final SharedFolder sharedFolder) {
final Item item, final FolderItem folderItem) {
new Thread() {
@Override
@ -213,8 +214,8 @@ public class NotificationsProducer {
// previousName, item, sharedFolder);
SocialItemFactory socialItemFactor = new SocialItemFactory();
SocialSharedFolder socialSharedFolder = socialItemFactor
.createSocialSharedFolder(sharedFolder);
SocialFileItem socialFileItem = socialItemFactor.createSocialFileItem(item, sharedFolder);
.createSocialSharedFolder(folderItem);
SocialFileItem socialFileItem = socialItemFactor.createSocialFileItem(item, folderItem);
boolean notify = notificationsMng.notifyItemRenaming(infoContactModel.getLogin(),
previousName, socialFileItem, socialSharedFolder);
@ -241,11 +242,11 @@ public class NotificationsProducer {
* - list of contacts already shared
* @param listSharingContact
* - list of "new" contacts witch share
* @param sharedFolder
* @param folderItem
* - the shared folder
*/
public void notifyAddedUsersToSharing(final List<InfoContactModel> listSharedContact,
final List<InfoContactModel> listSharingContact, final SharedFolder sharedFolder) {
final List<InfoContactModel> listSharingContact, final FolderItem folderItem) {
new Thread() {
@Override
@ -284,7 +285,7 @@ public class NotificationsProducer {
logger.trace("Sending notification to user " + contact.getLogin() + ", added user "
+ infoContactModel.getLogin() + " to share folder "
+ sharedFolder.getName());
+ folderItem.getName());
// DEBUG
// System.out.println("Sending notification
@ -294,7 +295,7 @@ public class NotificationsProducer {
// "+contact.getLogin());
SocialItemFactory socialItemFactor = new SocialItemFactory();
SocialSharedFolder socialSharedFolder = socialItemFactor
.createSocialSharedFolder(sharedFolder);
.createSocialSharedFolder(folderItem);
boolean notify = notificationsMng.notifyFolderAddedUser(contact.getLogin(),
socialSharedFolder, infoContactModel.getLogin());
@ -310,7 +311,7 @@ public class NotificationsProducer {
List<InfoContactModel> listCts = new ArrayList<InfoContactModel>();
listCts.add(infoContactModel);
notifyFolderSharing(listCts, sharedFolder); // NOTIFIER
notifyFolderSharing(listCts, folderItem); // NOTIFIER
// NEW
// USER
// OF
@ -335,7 +336,7 @@ public class NotificationsProducer {
try {
logger.trace("Sending notification to user " + contact.getLogin() + ", added "
+ listLogins.size() + " users to share folder " + sharedFolder.getName());
+ listLogins.size() + " users to share folder " + folderItem.getName());
// DEBUG
// System.out.println("Sending notification
@ -345,7 +346,7 @@ public class NotificationsProducer {
// "+contact.getLogin());
SocialItemFactory socialItemFactor = new SocialItemFactory();
SocialSharedFolder socialSharedFolder = socialItemFactor
.createSocialSharedFolder(sharedFolder);
.createSocialSharedFolder(folderItem);
boolean notify = notificationsMng.notifyFolderAddedUsers(contact.getLogin(),
socialSharedFolder, listLogins);
@ -359,7 +360,7 @@ public class NotificationsProducer {
}
}
notifyFolderSharing(listExclusiveContacts, sharedFolder); // NOTIFIER
notifyFolderSharing(listExclusiveContacts, folderItem); // NOTIFIER
// NEW
// USER
// OF
@ -384,10 +385,10 @@ public class NotificationsProducer {
*
* @param listContacts
* the list contacts
* @param unSharedFolder
* @param folderItem
* the un shared folder
*/
public void notifyFolderUnSharing(final List<InfoContactModel> listContacts, final SharedFolder unSharedFolder) {
public void notifyFolderUnSharing(final List<InfoContactModel> listContacts, final FolderItem folderItem) {
new Thread() {
@Override
@ -404,7 +405,7 @@ public class NotificationsProducer {
if (infoContactModel.getLogin().compareTo(userId) != 0) {
logger.trace("Sending notification to user " + infoContactModel.getLogin()
+ " un shared folder " + unSharedFolder.getName());
+ " un shared folder " + folderItem.getName());
// DEBUG
// System.out.println("Sending notification to user
@ -412,7 +413,7 @@ public class NotificationsProducer {
// "+unSharedFolder.getName());
SocialItemFactory socialItemFactor = new SocialItemFactory();
SocialSharedFolder socialSharedFolder = socialItemFactor
.createSocialSharedFolder(unSharedFolder);
.createSocialSharedFolder(folderItem);
boolean notify = notificationsMng.notifyFolderRemovedUser(infoContactModel.getLogin(),
socialSharedFolder);
@ -440,11 +441,11 @@ public class NotificationsProducer {
* the list contacts
* @param item
* the workspace item
* @param sharedFolder
* @param folderItem
* the shared folder
*/
public void notifyAddedItemToSharing(final List<InfoContactModel> listContacts, final Item item,
final SharedFolder sharedFolder) {
final FolderItem folderItem) {
new Thread() {
@Override
@ -464,19 +465,19 @@ public class NotificationsProducer {
if (infoContactModel.getLogin().compareTo(userId) != 0) {
logger.trace("Sending notification to user " + infoContactModel.getLogin() + " added item "
+ item.getName() + " in shared folder " + sharedFolder.getName());
+ item.getName() + " in shared folder " + folderItem.getName());
// DEBUG
System.out.println("Sending notification to user " + infoContactModel.getLogin()
+ " added item " + item.getName() + " in shared folder " + sharedFolder.getName());
+ " added item " + item.getName() + " in shared folder " + folderItem.getName());
// DEBUG
// System.out.println("Send notify folder un share
// user "+infoContactModel.getLogin());
SocialItemFactory socialItemFactor = new SocialItemFactory();
SocialSharedFolder socialSharedFolder = socialItemFactor
.createSocialSharedFolder(sharedFolder);
SocialFileItem socialFileItem = socialItemFactor.createSocialFileItem(item, sharedFolder);
.createSocialSharedFolder(folderItem);
SocialFileItem socialFileItem = socialItemFactor.createSocialFileItem(item, folderItem);
boolean notify = notificationsMng.notifyAddedItem(infoContactModel.getLogin(),
socialFileItem, socialSharedFolder);
@ -511,11 +512,11 @@ public class NotificationsProducer {
* the list contacts
* @param item
* the workspace item
* @param sharedFolder
* @param folderItem
* the shared folder
*/
public void notifyUpdatedItemToSharing(final List<InfoContactModel> listContacts, final Item item,
final SharedFolder sharedFolder) {
final FolderItem folderItem) {
new Thread() {
@Override
@ -537,7 +538,7 @@ public class NotificationsProducer {
logger.trace(
"Sending notification to user " + infoContactModel.getLogin() + " updated item "
+ item.getName() + " in shared folder " + sharedFolder.getName());
+ item.getName() + " in shared folder " + folderItem.getName());
// DEBUG
// System.out.println("Sending notification to user
@ -550,8 +551,8 @@ public class NotificationsProducer {
// user "+infoContactModel.getLogin());
SocialItemFactory socialItemFactor = new SocialItemFactory();
SocialSharedFolder socialSharedFolder = socialItemFactor
.createSocialSharedFolder(sharedFolder);
SocialFileItem socialFileItem = socialItemFactor.createSocialFileItem(item, sharedFolder);
.createSocialSharedFolder(folderItem);
SocialFileItem socialFileItem = socialItemFactor.createSocialFileItem(item, folderItem);
boolean notify = notificationsMng.notifyUpdatedItem(infoContactModel.getLogin(),
socialFileItem, socialSharedFolder);
@ -586,11 +587,11 @@ public class NotificationsProducer {
* the list contacts
* @param item
* the workspace item
* @param sharedFolder
* @param folderItem
* the shared folder
*/
public void notifyMovedItemToSharing(final List<InfoContactModel> listContacts, final Item item,
final SharedFolder sharedFolder) {
final FolderItem folderItem) {
new Thread() {
@Override
@ -601,7 +602,7 @@ public class NotificationsProducer {
try {
NotificationsUtil notificationsUtil=new NotificationsUtil();
if (notificationsUtil.checkIsRootFolderShared(item.getId(), sharedFolder.getId())) {
if (notificationsUtil.checkIsRootFolderShared(item.getId(), folderItem.getId())) {
logger.trace("Notification isn't sent because the event is on root shared folder");
return;
}
@ -624,7 +625,7 @@ public class NotificationsProducer {
if (infoContactModel.getLogin().compareTo(userId) != 0) {
logger.trace("Sending notification to user " + infoContactModel.getLogin() + " moved item "
+ item.getName() + " in shared folder " + sharedFolder.getName());
+ item.getName() + " in shared folder " + folderItem.getName());
// DEBUG
// System.out.println("Sending notification to user
@ -633,8 +634,8 @@ public class NotificationsProducer {
// "+sharedFolder.getName());
SocialItemFactory socialItemFactor = new SocialItemFactory();
SocialSharedFolder socialSharedFolder = socialItemFactor
.createSocialSharedFolder(sharedFolder);
SocialFileItem socialFileItem = socialItemFactor.createSocialFileItem(item, sharedFolder);
.createSocialSharedFolder(folderItem);
SocialFileItem socialFileItem = socialItemFactor.createSocialFileItem(item, folderItem);
boolean notify = notificationsMng.notifyMovedItem(infoContactModel.getLogin(),
socialFileItem, socialSharedFolder);
@ -671,11 +672,11 @@ public class NotificationsProducer {
* the list contacts
* @param itemName
* the item name
* @param sharedFolder
* @param folderItem
* the shared folder
*/
public void notifyRemovedItemToSharing(final List<InfoContactModel> listContacts, final String itemName,
final SharedFolder sharedFolder) {
final FolderItem folderItem) {
new Thread() {
@Override
@ -689,7 +690,7 @@ public class NotificationsProducer {
return;
}
if (sharedFolder == null) {
if (folderItem == null) {
logger.trace("Notification isn't sent - sharedFolder is null");
}
@ -706,7 +707,7 @@ public class NotificationsProducer {
if (infoContactModel.getLogin().compareTo(userId) != 0) {
logger.trace("Sending notification to user " + infoContactModel.getLogin()
+ " removed item " + itemName + " in shared folder " + sharedFolder.getName());
+ " removed item " + itemName + " in shared folder " + folderItem.getName());
// DEBUG
// System.out.println("Sending notification to user
@ -714,7 +715,7 @@ public class NotificationsProducer {
// "+itemName+" in shared folder
// "+sharedFolder.getName());
SocialItemFactory socialItemFactor=new SocialItemFactory();
SocialSharedFolder socialSharedFolder=socialItemFactor.createSocialSharedFolder(sharedFolder);
SocialSharedFolder socialSharedFolder=socialItemFactor.createSocialSharedFolder(folderItem);
boolean notify = notificationsMng.notifyRemovedItem(infoContactModel.getLogin(), itemName,
socialSharedFolder);