2014-02-25 14:28:30 +01:00
|
|
|
package org.gcube.portlets.widgets.workspacesharingwidget.server;
|
|
|
|
|
2014-02-25 15:58:42 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
2019-02-22 11:14:22 +01:00
|
|
|
import java.util.HashSet;
|
2014-02-25 15:58:42 +01:00
|
|
|
import java.util.List;
|
2019-02-22 11:14:22 +01:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
2014-02-25 15:58:42 +01:00
|
|
|
|
2016-05-31 16:35:57 +02:00
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
2015-06-04 15:41:55 +02:00
|
|
|
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
2014-06-23 12:27:21 +02:00
|
|
|
import org.gcube.common.homelibrary.home.HomeLibrary;
|
2014-02-25 15:58:42 +01:00
|
|
|
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.accessmanager.ACLType;
|
2019-02-22 11:14:22 +01:00
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
|
|
|
import org.gcube.common.storagehub.client.dsl.ItemContainer;
|
|
|
|
import org.gcube.common.storagehub.client.dsl.OpenResolver;
|
|
|
|
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
|
|
|
import org.gcube.common.storagehub.model.Metadata;
|
|
|
|
import org.gcube.common.storagehub.model.acls.ACL;
|
|
|
|
import org.gcube.common.storagehub.model.acls.AccessType;
|
|
|
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
|
|
|
import org.gcube.common.storagehub.model.items.Item;
|
|
|
|
import org.gcube.common.storagehub.model.items.SharedFolder;
|
2014-02-25 15:58:42 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.client.ConstantsSharing;
|
2014-02-25 14:28:30 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService;
|
2014-02-25 15:58:42 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.server.notifications.NotificationsProducer;
|
2019-02-22 11:14:22 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.AccessTypeComparator;
|
2016-11-25 16:24:20 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.PortalContextInfo;
|
2014-07-18 12:20:11 +02:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.ScopeUtility;
|
2014-03-03 16:37:03 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.UserUtil;
|
2014-02-25 15:58:42 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.WsUtil;
|
2019-02-22 11:14:22 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.AllowAccess;
|
2014-03-03 19:17:26 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.CredentialModel;
|
2019-02-22 11:14:22 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.ExtendedWorkspaceACL;
|
2014-02-28 12:30:44 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.FileModel;
|
2014-02-25 15:58:42 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
|
2019-02-22 11:14:22 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.ReportAssignmentACL;
|
2014-03-03 16:37:03 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.SessionExpiredException;
|
2014-02-25 15:58:42 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL;
|
2014-03-03 13:03:34 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2014-02-25 14:28:30 +01:00
|
|
|
|
|
|
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The server side implementation of the RPC service.
|
2015-08-03 12:10:59 +02:00
|
|
|
*
|
2019-02-22 11:14:22 +01:00
|
|
|
* @author Francesco Mangiacrapa Aug 3, 2015
|
2014-02-25 14:28:30 +01:00
|
|
|
*/
|
|
|
|
@SuppressWarnings("serial")
|
2019-02-22 11:14:22 +01:00
|
|
|
public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements WorkspaceSharingService {
|
2014-02-25 14:28:30 +01:00
|
|
|
|
2014-06-26 17:44:22 +02:00
|
|
|
protected static Logger logger = LoggerFactory.getLogger(WorkspaceSharingServiceImpl.class);
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2015-08-03 12:10:59 +02:00
|
|
|
/**
|
|
|
|
* Gets the notification producer.
|
|
|
|
*
|
2019-02-22 11:14:22 +01:00
|
|
|
* @param request
|
|
|
|
* the request
|
2015-08-03 12:10:59 +02:00
|
|
|
* @return the notification producer
|
|
|
|
*/
|
2019-02-22 11:14:22 +01:00
|
|
|
protected NotificationsProducer getNotificationProducer(HttpServletRequest request) {
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2016-11-25 16:24:20 +01:00
|
|
|
return WsUtil.getNotificationProducer(request);
|
2014-02-25 15:58:42 +01:00
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2015-08-03 12:10:59 +02:00
|
|
|
/**
|
|
|
|
* Gets the scope util filter.
|
|
|
|
*
|
|
|
|
* @return the scope util filter
|
|
|
|
*/
|
2019-02-22 11:14:22 +01:00
|
|
|
protected ScopeUtility getScopeUtilFilter() {
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2016-11-25 16:24:20 +01:00
|
|
|
return WsUtil.getScopeUtilFilter(this.getThreadLocalRequest());
|
2014-02-25 15:58:42 +01:00
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2015-08-03 12:10:59 +02:00
|
|
|
/**
|
|
|
|
* Checks if is test mode.
|
|
|
|
*
|
|
|
|
* @return true, if is test mode
|
|
|
|
*/
|
2019-02-22 11:14:22 +01:00
|
|
|
protected boolean isTestMode() {
|
|
|
|
return !WsUtil.isWithinPortal(); // IS NOT INTO PORTAL
|
2014-02-25 15:58:42 +01:00
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.
|
|
|
|
* WorkspaceSharingService#getAllContacts(boolean, boolean)
|
2015-08-03 12:10:59 +02:00
|
|
|
*/
|
2014-02-25 15:58:42 +01:00
|
|
|
@Override
|
2019-02-22 11:14:22 +01:00
|
|
|
public List<InfoContactModel> getAllContacts() throws Exception {
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2014-02-25 15:58:42 +01:00
|
|
|
try {
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.info("Call getAllContacts()");
|
2016-11-25 16:24:20 +01:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
if (isTestMode()) {
|
|
|
|
logger.debug("WORKSPACE PORTLET IS IN TEST MODE - RETURN TEST USERS AND GROUPS");
|
2014-09-18 19:02:41 +02:00
|
|
|
GWTWorkspaceSharingBuilder.getHashTestUsers();
|
2014-02-25 15:58:42 +01:00
|
|
|
List<InfoContactModel> listContactsModel = new ArrayList<InfoContactModel>();
|
2014-09-18 19:02:41 +02:00
|
|
|
for (String key : GWTWorkspaceSharingBuilder.getHashTestUsers().keySet()) {
|
|
|
|
InfoContactModel contact = GWTWorkspaceSharingBuilder.getHashTestUsers().get(key);
|
|
|
|
listContactsModel.add(contact);
|
|
|
|
}
|
2014-02-25 15:58:42 +01:00
|
|
|
return listContactsModel;
|
|
|
|
}
|
2019-02-22 11:14:22 +01:00
|
|
|
|
|
|
|
PortalContextInfo info = WsUtil.getPortalContext(this.getThreadLocalRequest());
|
|
|
|
|
|
|
|
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
|
|
|
|
|
|
|
|
List<InfoContactModel> listContactsModel = builder.buildGXTListContactsModelFromUserModel(info);
|
|
|
|
|
|
|
|
listContactsModel.addAll(builder.getGXTListContactsModelFromVOs(info));
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.debug("Get all contacts returning a list having size: " + listContactsModel.size());
|
2014-06-23 12:27:21 +02:00
|
|
|
return listContactsModel;
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2014-02-25 15:58:42 +01:00
|
|
|
} catch (Exception e) {
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.error("Error in getAllContacts(): " + e.getLocalizedMessage(), e);
|
|
|
|
throw new Exception("Error retrieving all contacts: " + e.getLocalizedMessage(), e);
|
2014-02-25 15:58:42 +01:00
|
|
|
}
|
|
|
|
}
|
2014-07-18 12:20:11 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.
|
|
|
|
* WorkspaceSharingService#getListUserSharedByFolderSharedId(java.lang.
|
|
|
|
* String)
|
2015-08-03 12:10:59 +02:00
|
|
|
*/
|
2014-02-25 15:58:42 +01:00
|
|
|
@Override
|
2019-02-22 11:14:22 +01:00
|
|
|
public List<InfoContactModel> getListUserSharedByFolderSharedId(String itemId) throws Exception {
|
2014-02-25 15:58:42 +01:00
|
|
|
|
|
|
|
try {
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.info("Call getListUserSharedByFolderSharedId(): [folderId=" + itemId + "]");
|
|
|
|
if (itemId == null || itemId.isEmpty()) {
|
|
|
|
logger.error("Error in getListUserSharedByFolderSharedId(), invalid folder id: [id=" + itemId + "]");
|
|
|
|
throw new Exception("Invalid item id requested: " + itemId);
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
OpenResolver openResolver = shc.open(itemId);
|
|
|
|
FolderContainer folderContainer = openResolver.asFolder();
|
|
|
|
FolderItem folder = folderContainer.get();
|
|
|
|
if (folder.isShared()) {
|
|
|
|
if (folder instanceof SharedFolder) {
|
|
|
|
SharedFolder sharedFolder = (SharedFolder) folder;
|
|
|
|
return retrieveUsersListFromSharedFolder(sharedFolder);
|
|
|
|
} else {
|
|
|
|
FolderContainer rootSharedFolderContainer = folderContainer.getRootSharedFolder();
|
|
|
|
FolderItem rootSharedFolder = rootSharedFolderContainer.get();
|
|
|
|
if (rootSharedFolder instanceof SharedFolder) {
|
|
|
|
SharedFolder sharedFolder = (SharedFolder) rootSharedFolder;
|
|
|
|
return retrieveUsersListFromSharedFolder(sharedFolder);
|
|
|
|
} else {
|
|
|
|
String error = "The root shared folder has a invalid type: RootSharedFolder[id="
|
|
|
|
+ rootSharedFolder.getId() + "]";
|
|
|
|
logger.error(error);
|
|
|
|
throw new Exception(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logger.info("The item with id: " + itemId + " is not shared a folder!");
|
|
|
|
return new ArrayList<InfoContactModel>();
|
2014-02-25 15:58:42 +01:00
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error in getListUserSharedByFolderSharedId(): " + e.getLocalizedMessage(), e);
|
|
|
|
throw new Exception(e.getLocalizedMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<InfoContactModel> retrieveUsersListFromSharedFolder(SharedFolder sharedFolder) throws Exception {
|
|
|
|
Metadata metadata = sharedFolder.getUsers();
|
|
|
|
if (metadata != null) {
|
|
|
|
Map<String, Object> map = metadata.getMap();
|
|
|
|
if (map != null && !map.isEmpty()) {
|
|
|
|
List<InfoContactModel> listShared = new ArrayList<>();
|
|
|
|
List<String> keys = new ArrayList<String>(map.keySet());
|
|
|
|
List<InfoContactModel> listContactsModel = getAllContacts();
|
|
|
|
for (String username : keys) {
|
|
|
|
for (InfoContactModel contact : listContactsModel) {
|
|
|
|
if (contact != null && contact.getLogin() != null
|
|
|
|
&& contact.getLogin().compareTo(username) == 0) {
|
|
|
|
listShared.add(contact);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return listShared;
|
|
|
|
} else {
|
|
|
|
logger.info("The folder with id: " + sharedFolder.getId() + " has a invalid map!");
|
|
|
|
return new ArrayList<InfoContactModel>();
|
2014-02-25 15:58:42 +01:00
|
|
|
}
|
2019-02-22 11:14:22 +01:00
|
|
|
} else {
|
|
|
|
logger.info("The folder with id: " + sharedFolder.getId() + " has a invalid metadata!");
|
2014-02-25 15:58:42 +01:00
|
|
|
return new ArrayList<InfoContactModel>();
|
|
|
|
}
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.
|
|
|
|
* WorkspaceSharingService#getOwnerByItemId(java.lang.String)
|
2015-08-03 12:10:59 +02:00
|
|
|
*/
|
2014-02-25 15:58:42 +01:00
|
|
|
@Override
|
|
|
|
public InfoContactModel getOwnerByItemId(String itemId) throws Exception {
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2014-02-25 15:58:42 +01:00
|
|
|
try {
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.info("Call getOwnerByItemId(): [itemId=" + itemId + "]");
|
|
|
|
if (itemId == null || itemId.isEmpty()) {
|
|
|
|
logger.error("Error in getOwnerByItemId(), invalid item id: " + itemId);
|
|
|
|
throw new Exception("Invalid request, item id: " + itemId);
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
OpenResolver openResolverForFile = shc.open(itemId);
|
|
|
|
ItemContainer<Item> itemContainer = openResolverForFile.asItem();
|
|
|
|
Item item = itemContainer.get();
|
|
|
|
logger.debug("Retrieved Item: " + item);
|
|
|
|
if (item != null) {
|
|
|
|
logger.debug("Owner: " + item.getOwner());
|
|
|
|
if (item.getOwner() != null && !item.getOwner().isEmpty()) {
|
|
|
|
PortalContextInfo info = WsUtil.getPortalContext(this.getThreadLocalRequest());
|
|
|
|
|
|
|
|
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
|
|
|
|
|
|
|
|
List<InfoContactModel> listContactsModel = builder.buildGXTListContactsModelFromUserModel(info);
|
|
|
|
for (InfoContactModel infoContactModel : listContactsModel) {
|
|
|
|
if (infoContactModel.getLogin().compareTo(item.getOwner()) == 0) {
|
|
|
|
logger.debug("Retrieved: " + infoContactModel);
|
|
|
|
return infoContactModel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logger.debug("Owner not found from user model!");
|
|
|
|
return new InfoContactModel(item.getOwner(), item.getOwner(), item.getOwner(), false);
|
|
|
|
} else {
|
|
|
|
logger.debug("Owner not found from item");
|
|
|
|
return new InfoContactModel();
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
} else {
|
|
|
|
logger.debug("Item retrieved is null");
|
|
|
|
return new InfoContactModel();
|
|
|
|
}
|
2014-02-25 15:58:42 +01:00
|
|
|
} catch (Exception e) {
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.error("Error in getOwnerByItemId(): " + e.getLocalizedMessage(), e);
|
2014-02-25 15:58:42 +01:00
|
|
|
throw new Exception(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2014-02-25 15:58:42 +01:00
|
|
|
/**
|
2015-08-03 12:10:59 +02:00
|
|
|
* Gets the AC ls.
|
|
|
|
*
|
|
|
|
* @return the AC ls
|
2019-02-22 11:14:22 +01:00
|
|
|
* @throws Exception
|
|
|
|
* the exception
|
2014-02-25 15:58:42 +01:00
|
|
|
*/
|
|
|
|
@Override
|
2019-02-22 11:14:22 +01:00
|
|
|
public List<WorkspaceACL> getACLs() throws Exception {
|
2014-02-25 15:58:42 +01:00
|
|
|
try {
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.info("Call getACLs()");
|
|
|
|
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
|
|
|
|
return builder.getWorkspaceACLFromAccessType(Arrays.asList(AccessType.values()));
|
2014-02-25 15:58:42 +01:00
|
|
|
} catch (Exception e) {
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.error("Error in getACLs(): " + e.getLocalizedMessage(), e);
|
|
|
|
String error = ConstantsSharing.SERVER_ERROR + " get ACL rules. " + e.getMessage();
|
2014-02-25 15:58:42 +01:00
|
|
|
throw new Exception(error);
|
|
|
|
}
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.
|
|
|
|
* WorkspaceSharingService#getMyLogin()
|
2015-08-03 12:10:59 +02:00
|
|
|
*/
|
2014-02-25 15:58:42 +01:00
|
|
|
@Override
|
2019-02-22 11:14:22 +01:00
|
|
|
public String getMyLogin() throws Exception {
|
|
|
|
try {
|
|
|
|
logger.info("Call getMyLogin()");
|
|
|
|
PortalContextInfo info = WsUtil.getPortalContext(this.getThreadLocalRequest());
|
|
|
|
logger.debug("Username: " + info.getUsername());
|
|
|
|
return info.getUsername();
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error in getMyLogin(): " + e.getLocalizedMessage(), e);
|
|
|
|
throw new Exception("Error retrieving user information: " + e.getLocalizedMessage(), e);
|
|
|
|
}
|
2014-02-25 15:58:42 +01:00
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.
|
|
|
|
* WorkspaceSharingService#getFileModelByWorkpaceItemId(java.lang.String)
|
2015-08-03 12:10:59 +02:00
|
|
|
*/
|
2014-02-28 12:30:44 +01:00
|
|
|
@Override
|
|
|
|
public FileModel getFileModelByWorkpaceItemId(String itemId) throws Exception {
|
|
|
|
|
|
|
|
try {
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.info("Call getFileModelByWorkpaceItemId(): [itemId=" + itemId + "]");
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
if (itemId == null || itemId.isEmpty()) {
|
|
|
|
logger.error("The item id is invalid: " + itemId);
|
|
|
|
throw new Exception("Invalid request item id is invalid: " + itemId);
|
|
|
|
}
|
2014-02-28 12:30:44 +01:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
OpenResolver openResolverForItem = shc.open(itemId);
|
|
|
|
ItemContainer<Item> itemContainer = openResolverForItem.asItem();
|
|
|
|
Item item = itemContainer.get();
|
|
|
|
logger.debug("Retrieved Item: " + item);
|
|
|
|
if (item == null) {
|
|
|
|
String error = "Error item not found: [itemId=" + itemId + "]";
|
|
|
|
logger.error(error);
|
|
|
|
throw new Exception(error);
|
|
|
|
}
|
|
|
|
if (item.getParentId() == null || item.getParentId().isEmpty()) {
|
|
|
|
String error = "Error parent item not found: [itemId=" + itemId + "]";
|
|
|
|
logger.error(error);
|
|
|
|
throw new Exception(error);
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
OpenResolver openResolverForParent = shc.open(itemId);
|
|
|
|
ItemContainer<Item> parentContainer = openResolverForParent.asItem();
|
|
|
|
Item parentItem = parentContainer.get();
|
|
|
|
logger.debug("Retrieved Parent: " + parentItem);
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
// Long startTime = System.currentTimeMillis();
|
|
|
|
//
|
|
|
|
// Long endTime = System.currentTimeMillis() - startTime;
|
|
|
|
// String time = String.format("%d msc %d sec", endTime,
|
|
|
|
// TimeUnit.MILLISECONDS.toSeconds(endTime));
|
|
|
|
// logger.debug("get child for Grid by id returning element in " +
|
|
|
|
// time);
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2014-02-28 12:30:44 +01:00
|
|
|
FileModel parent = null;
|
2019-02-22 11:14:22 +01:00
|
|
|
if (parentItem != null) {
|
|
|
|
logger.info("Folder parent has id: " + parentItem.getId() + " and name: " + parentItem.getName());
|
|
|
|
parent = builder.buildGXTFileModelItem(parentItem, null);
|
|
|
|
} else
|
|
|
|
logger.info("Folder parent for item: " + item.getId() + " is null");
|
|
|
|
|
|
|
|
return builder.buildGXTFileModelItem(item, parent);
|
2014-02-28 12:30:44 +01:00
|
|
|
} catch (Exception e) {
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.error("Error in getFileModelByWorkpaceItemId(): " + e.getLocalizedMessage(), e);
|
|
|
|
String error = ConstantsSharing.SERVER_ERROR + " retrieving the item from workspace. "
|
|
|
|
+ e.getLocalizedMessage();
|
2014-02-28 12:30:44 +01:00
|
|
|
throw new Exception(error);
|
|
|
|
}
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#
|
|
|
|
* isSessionExpired()
|
2014-03-03 16:37:03 +01:00
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public boolean isSessionExpired() throws Exception {
|
2016-11-25 16:24:20 +01:00
|
|
|
return WsUtil.isSessionExpired(this.getThreadLocalRequest());
|
2014-03-03 16:37:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// DEBUG
|
2015-08-03 12:10:59 +02:00
|
|
|
/**
|
|
|
|
* Prints the contacts.
|
|
|
|
*
|
2019-02-22 11:14:22 +01:00
|
|
|
* @param listContacts
|
|
|
|
* the list contacts
|
2015-08-03 12:10:59 +02:00
|
|
|
*/
|
2019-02-22 11:14:22 +01:00
|
|
|
// private void printContacts(List<InfoContactModel> listContacts) {
|
|
|
|
//
|
|
|
|
// boolean testMode = isTestMode();
|
|
|
|
// if (testMode)
|
|
|
|
// System.out.println("Contacts: ");
|
|
|
|
// else
|
|
|
|
// logger.debug("Contacts:");
|
|
|
|
//
|
|
|
|
// for (InfoContactModel infoContactModel : listContacts) {
|
|
|
|
// if (testMode)
|
|
|
|
// System.out.println("User: " + infoContactModel);
|
|
|
|
// else
|
|
|
|
// logger.debug("User: " + infoContactModel);
|
|
|
|
// }
|
|
|
|
// }
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2014-03-03 16:37:03 +01:00
|
|
|
@Override
|
2019-02-22 11:14:22 +01:00
|
|
|
public boolean shareFolder(String itemId, String name, String description, String parentId,
|
|
|
|
List<InfoContactModel> listContacts, boolean isNewFolder, WorkspaceACL acl) throws Exception {
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
if (isSessionExpired())
|
2014-03-03 16:37:03 +01:00
|
|
|
throw new SessionExpiredException();
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2014-03-03 16:37:03 +01:00
|
|
|
try {
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.info("Call shareFolder(): [id=" + itemId + ", name=" + name + ", description=" + description
|
|
|
|
+ ", parentId=" + parentId + ", isNewFolder=" + isNewFolder + "]");
|
|
|
|
if (listContacts == null || listContacts.isEmpty()) {
|
|
|
|
logger.error("Invalid contacts requested: " + listContacts);
|
|
|
|
throw new Exception("Invalid contacts requested");
|
2014-03-03 16:37:03 +01:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
}
|
|
|
|
logger.debug("ListContacts size: " + listContacts.size());
|
2014-03-03 16:37:03 +01:00
|
|
|
|
|
|
|
List<String> listLogin = UserUtil.getListLoginByInfoContactModel(listContacts);
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
boolean created = false;
|
|
|
|
if (!listLogin.isEmpty()) {
|
|
|
|
FolderContainer folderContainer = null;
|
|
|
|
if (!isNewFolder) {
|
|
|
|
logger.info("Sharing item: [id=" + itemId + "]");
|
|
|
|
if (itemId == null || itemId.isEmpty()) {
|
|
|
|
logger.error("Invalid folder id requested: " + itemId);
|
|
|
|
throw new Exception("Invalid folder id requested: " + itemId);
|
|
|
|
}
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
OpenResolver openResolverForItem = shc.open(itemId);
|
|
|
|
folderContainer = openResolverForItem.asFolder();
|
|
|
|
} else {
|
|
|
|
if (parentId == null || parentId.isEmpty()) {
|
|
|
|
logger.error("Invalid parent folder id requested: " + parentId);
|
|
|
|
throw new Exception("Invalid parent folder id requested: " + parentId);
|
|
|
|
}
|
|
|
|
if (name == null || name.isEmpty()) {
|
|
|
|
logger.error("Invalid folder name: " + name);
|
|
|
|
throw new Exception("Invalid folder name: " + name);
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
OpenResolver openResolverForItem = shc.open(parentId);
|
|
|
|
FolderContainer parentFolderContainer = openResolverForItem.asFolder();
|
|
|
|
folderContainer = parentFolderContainer.newFolder(name, description);
|
2014-03-03 16:37:03 +01:00
|
|
|
}
|
2019-02-22 11:14:22 +01:00
|
|
|
FolderItem folderItem = folderContainer.get();
|
|
|
|
if (folderItem != null) {
|
|
|
|
if (folderItem.isShared()) {
|
|
|
|
logger.debug("Folder is shared");
|
|
|
|
if (folderItem instanceof SharedFolder) {
|
|
|
|
logger.debug("Folder type: SharedFolder");
|
2019-04-29 18:37:42 +02:00
|
|
|
SharedFolder sharedFolder = (SharedFolder) folderItem;
|
|
|
|
String currentUser = getMyLogin();
|
|
|
|
logger.debug("Current User: " + currentUser);
|
2019-05-07 15:02:53 +02:00
|
|
|
|
2019-04-30 15:06:06 +02:00
|
|
|
Set<String> alreadySharedUsers = null;
|
2019-04-29 18:37:42 +02:00
|
|
|
Metadata usersMetadata = sharedFolder.getUsers();
|
|
|
|
if (usersMetadata != null) {
|
|
|
|
Map<String, Object> usersMap = usersMetadata.getMap();
|
|
|
|
if (usersMap != null) {
|
2019-04-30 15:06:06 +02:00
|
|
|
alreadySharedUsers = usersMap.keySet();
|
2019-04-29 18:37:42 +02:00
|
|
|
logger.debug("Already shared logins: " + alreadySharedUsers);
|
|
|
|
if (alreadySharedUsers.contains(currentUser)) {
|
|
|
|
alreadySharedUsers.remove(currentUser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-07 15:02:53 +02:00
|
|
|
|
2019-04-30 15:06:06 +02:00
|
|
|
Set<String> logins = new HashSet<>(listLogin);
|
|
|
|
if (logins.contains(currentUser)) {
|
|
|
|
logins.remove(currentUser);
|
|
|
|
}
|
2019-04-29 18:37:42 +02:00
|
|
|
|
|
|
|
logger.debug("Share logins: " + logins);
|
2019-04-30 15:06:06 +02:00
|
|
|
folderContainer = folderContainer.share(logins, getAccessType(acl));
|
2019-04-29 18:37:42 +02:00
|
|
|
logger.debug("Shared done");
|
2019-04-30 15:06:06 +02:00
|
|
|
|
|
|
|
if (alreadySharedUsers != null && !alreadySharedUsers.isEmpty()) {
|
|
|
|
alreadySharedUsers.removeAll(logins);
|
|
|
|
if (!alreadySharedUsers.isEmpty()) {
|
|
|
|
logger.debug("Unshare the logins: " + alreadySharedUsers);
|
|
|
|
folderContainer = folderContainer.unshare(alreadySharedUsers);
|
|
|
|
logger.debug("Unshare done");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
created = true;
|
2019-04-29 18:37:42 +02:00
|
|
|
NotificationsProducer np = getNotificationProducer(this.getThreadLocalRequest());
|
2019-04-30 15:06:06 +02:00
|
|
|
np.notifyFolderSharing(listContacts, folderContainer.get());
|
2019-02-22 11:14:22 +01:00
|
|
|
} else {
|
|
|
|
logger.debug("The folder is already shared");
|
|
|
|
throw new Exception("The folder selected is already shared!");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logger.debug("Folder is not shared");
|
|
|
|
Set<String> logins = new HashSet<>(listLogin);
|
2019-04-29 18:37:42 +02:00
|
|
|
logger.debug("Share logins: " + logins);
|
2019-05-07 15:02:53 +02:00
|
|
|
folderContainer = folderContainer.share(logins, getAccessType(acl));
|
2019-04-29 18:37:42 +02:00
|
|
|
logger.debug("Shared done");
|
2019-02-22 11:14:22 +01:00
|
|
|
created = true;
|
2019-04-29 18:37:42 +02:00
|
|
|
NotificationsProducer np = getNotificationProducer(this.getThreadLocalRequest());
|
2019-04-30 15:06:06 +02:00
|
|
|
np.notifyFolderSharing(listContacts, folderContainer.get());
|
2019-04-29 18:37:42 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logger.error("Invalid folder retrieved: [id=" + itemId + "]");
|
|
|
|
throw new Exception("Invalid folder retrieved: [id=" + itemId + "]");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logger.error("The list of users is invalid!");
|
|
|
|
throw new Exception("The list of users is invalid");
|
|
|
|
|
2014-03-03 16:37:03 +01:00
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
return created;
|
2014-03-03 16:37:03 +01:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error in shareFolder(): " + e.getLocalizedMessage(), e);
|
|
|
|
String error = ConstantsSharing.SERVER_ERROR + " sharing item.";
|
|
|
|
throw new Exception(error);
|
|
|
|
}
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
private AccessType getAccessType(WorkspaceACL acl) {
|
|
|
|
logger.debug("Convert GXTACL to AccessType: " + acl);
|
|
|
|
if (acl.getAclType() != null) {
|
|
|
|
switch (acl.getAclType()) {
|
|
|
|
case READ_ONLY:
|
|
|
|
return AccessType.READ_ONLY;
|
|
|
|
case WRITE_ANY:
|
|
|
|
return AccessType.WRITE_ALL;
|
|
|
|
case WRITE_OWNER:
|
|
|
|
return AccessType.WRITE_OWNER;
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.
|
|
|
|
* WorkspaceSharingService#getInfoContactModelsFromCredential(java.util.
|
|
|
|
* List)
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public List<InfoContactModel> getInfoContactModelsFromCredential(List<CredentialModel> listAlreadySharedContact)
|
|
|
|
throws Exception {
|
|
|
|
try {
|
|
|
|
logger.info("Call getInfoContactModelsFromCredential()");
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
if (listAlreadySharedContact == null || listAlreadySharedContact.size() == 0)
|
|
|
|
throw new Exception("Credentials list is null or empty");
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
|
|
|
|
List<InfoContactModel> listContacts = new ArrayList<InfoContactModel>(listAlreadySharedContact.size());
|
|
|
|
for (CredentialModel credentialModel : listAlreadySharedContact) {
|
|
|
|
|
|
|
|
if (!credentialModel.isGroup()) {
|
|
|
|
InfoContactModel contact = builder.buildGxtInfoContactFromPortalLogin(credentialModel.getLogin());
|
|
|
|
contact.setReferenceCredential(credentialModel);
|
|
|
|
listContacts.add(contact);
|
|
|
|
logger.trace("Converted contact: " + credentialModel + ", into: " + contact);
|
|
|
|
} else if (credentialModel.getName() == null || credentialModel.getName().isEmpty()) {
|
|
|
|
InfoContactModel contact = builder.buildGxtInfoContactFromPortalGroup(credentialModel.getLogin());
|
|
|
|
contact.setReferenceCredential(credentialModel);
|
|
|
|
listContacts.add(contact);
|
|
|
|
logger.trace("Converted group: " + credentialModel + ", into: " + contact);
|
2014-03-03 16:37:03 +01:00
|
|
|
}
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
return listContacts;
|
2014-03-03 16:37:03 +01:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error in getInfoContactModelsFromCredential(): " + e.getLocalizedMessage(), e);
|
|
|
|
String error = ConstantsSharing.SERVER_ERROR + " retrieving contacts info from user credentials.";
|
2014-03-03 16:37:03 +01:00
|
|
|
throw new Exception(error);
|
2019-02-22 11:14:22 +01:00
|
|
|
}
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.
|
|
|
|
* WorkspaceSharingService#getAdministratorsByFolderId(java.lang.String)
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public List<InfoContactModel> getAdministratorsByFolderId(String itemId) throws Exception {
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
try {
|
|
|
|
logger.info("Call getAdministratorsByFolderId(): [itemId=" + itemId + "]");
|
|
|
|
|
|
|
|
if (itemId == null || itemId.isEmpty()) {
|
|
|
|
String error = "Invalid shared folder: [id=" + itemId + "]";
|
|
|
|
logger.error(error);
|
|
|
|
throw new Exception(error);
|
|
|
|
}
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
OpenResolver openResolverForItem = shc.open(itemId);
|
|
|
|
FolderContainer folderContainer = openResolverForItem.asFolder();
|
|
|
|
FolderItem folderItem = folderContainer.get();
|
|
|
|
if (folderItem.isShared()) {
|
|
|
|
if (folderItem instanceof SharedFolder) {
|
|
|
|
return retrieveAdminContactsFromACLs(folderContainer);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
FolderContainer rootSharedFolderContainer = folderContainer.getRootSharedFolder();
|
|
|
|
FolderItem rootSharedFolder = rootSharedFolderContainer.get();
|
|
|
|
if (rootSharedFolder instanceof SharedFolder) {
|
|
|
|
return retrieveAdminContactsFromACLs(rootSharedFolderContainer);
|
|
|
|
} else {
|
|
|
|
String error = "The root shared folder has a invalid type: RootSharedFolder[id="
|
|
|
|
+ rootSharedFolder.getId() + "]";
|
|
|
|
logger.error(error);
|
|
|
|
throw new Exception(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logger.error("The item requested is not a valid shared folder : [itemId=" + itemId + "]");
|
|
|
|
throw new Exception("The item requested is not a valid shared folder : [itemId=" + itemId + "]");
|
|
|
|
}
|
2014-03-03 16:37:03 +01:00
|
|
|
|
|
|
|
} catch (Exception e) {
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.error("Error in getAdministratorsByFolderId(): " + e.getLocalizedMessage(), e);
|
|
|
|
throw new Exception("Sorry an error occurred on getting Administrators");
|
2014-03-03 16:37:03 +01:00
|
|
|
}
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#
|
|
|
|
* addAdministratorsByFolderId(java.lang.String, java.util.List)
|
|
|
|
*
|
|
|
|
* true if administrators have been added, false otherwise
|
|
|
|
*/
|
2015-02-16 15:35:41 +01:00
|
|
|
/**
|
2019-02-22 11:14:22 +01:00
|
|
|
* Adds the administrators by folder id.
|
2015-08-03 12:10:59 +02:00
|
|
|
*
|
2019-02-22 11:14:22 +01:00
|
|
|
* @param itemId
|
|
|
|
* the folder id
|
|
|
|
* @param listContactLogins
|
|
|
|
* the list contact logins
|
|
|
|
* @return true, if successful
|
|
|
|
* @throws Exception
|
|
|
|
* the exception
|
2015-02-16 15:35:41 +01:00
|
|
|
*/
|
2019-02-22 11:14:22 +01:00
|
|
|
@Override
|
|
|
|
public boolean addAdministratorsByFolderId(String itemId, List<String> listContactLogins) throws Exception {
|
2014-03-03 16:37:03 +01:00
|
|
|
try {
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.info("Call addAdministratorsByFolderId(): [itemId=" + itemId + ", listContactLogins"
|
|
|
|
+ listContactLogins + "]");
|
|
|
|
logger.info("This function is not available in StorageHub!");
|
|
|
|
return false;
|
|
|
|
// if(folderId==null || listContactLogins==null ||
|
|
|
|
// listContactLogins.size()==0)
|
|
|
|
// return false;
|
|
|
|
// Workspace workspace = getWorkspace();
|
|
|
|
// WorkspaceItem item = workspace.getItem(folderId);
|
|
|
|
// workspaceLogger.info("Adding administator/s to folder:
|
|
|
|
// "+folderId);
|
|
|
|
//
|
|
|
|
// if(item!=null &&
|
|
|
|
// item.getType().equals(WorkspaceItemType.SHARED_FOLDER)){
|
|
|
|
// WorkspaceSharedFolder sharedFolder = (WorkspaceSharedFolder)
|
|
|
|
// item;
|
|
|
|
//
|
|
|
|
// //retrieving old administrators list
|
|
|
|
// GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder();
|
|
|
|
// workspaceLogger.info("Retrieving old administator/s..");
|
|
|
|
// List<InfoContactModel> oldAdmins =
|
|
|
|
// builder.buildGxtInfoContactsFromPortalLogins(sharedFolder.getAdministrators());
|
|
|
|
// workspaceLogger.info("Retrieving old administator/s are/is:
|
|
|
|
// "+oldAdmins.size());
|
|
|
|
//
|
|
|
|
// workspaceLogger.info("Setting administators:");
|
|
|
|
// printList(listContactLogins);
|
|
|
|
// sharedFolder.setAdmins(listContactLogins);
|
|
|
|
//
|
|
|
|
// workspaceLogger.info("Converting new administator/s..");
|
|
|
|
// List<InfoContactModel> newAdmins =
|
|
|
|
// builder.buildGxtInfoContactsFromPortalLogins(listContactLogins);
|
|
|
|
// NotificationsProducer np = getNotificationProducer();
|
|
|
|
//
|
|
|
|
// workspaceLogger.info("Sending notifications downgrade/upgrade
|
|
|
|
// administator/s..");
|
|
|
|
// DifferenceBetweenInfoContactModel diff1 = new
|
|
|
|
// DifferenceBetweenInfoContactModel(oldAdmins, newAdmins);
|
|
|
|
// List<InfoContactModel> contactsDowngrade =
|
|
|
|
// diff1.getDifferentsContacts();
|
|
|
|
//
|
|
|
|
// for (InfoContactModel infoContactModel : contactsDowngrade) {
|
|
|
|
// np.notifyAdministratorDowngrade(infoContactModel, sharedFolder);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// DifferenceBetweenInfoContactModel diff2 = new
|
|
|
|
// DifferenceBetweenInfoContactModel(newAdmins, oldAdmins);
|
|
|
|
// List<InfoContactModel> contactsUpgrade =
|
|
|
|
// diff2.getDifferentsContacts();
|
|
|
|
//
|
|
|
|
// for (InfoContactModel infoContactModel : contactsUpgrade) {
|
|
|
|
// np.notifyAdministratorUpgrade(infoContactModel, sharedFolder);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return true;
|
|
|
|
//
|
|
|
|
// }else
|
|
|
|
// throw new Exception("The item is null or not instanceof
|
|
|
|
// "+WorkspaceItemType.SHARED_FOLDER);
|
2014-03-03 16:37:03 +01:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error in addAdministratorsByFolderId(): " + e.getLocalizedMessage(), e);
|
|
|
|
String error = "Attention, administrators can not be added by StorageHub.";
|
|
|
|
throw new Exception(error);
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
private List<InfoContactModel> retrieveAdminContactsFromACLs(FolderContainer folderContainer) throws Exception {
|
2019-05-07 15:02:53 +02:00
|
|
|
if (folderContainer == null) {
|
|
|
|
logger.debug("FolderContainer is null");
|
|
|
|
return new ArrayList<InfoContactModel>();
|
|
|
|
} else {
|
|
|
|
logger.debug("Retrieve Admins for: " + folderContainer.get());
|
|
|
|
List<String> admins = new ArrayList<>();
|
|
|
|
|
|
|
|
List<ACL> acls = folderContainer.getAcls();
|
|
|
|
logger.debug("Retrieved acls: " + acls);
|
|
|
|
for (ACL acl : acls) {
|
|
|
|
boolean isAdmin = false;
|
|
|
|
for (AccessType accesstype : acl.getAccessTypes()) {
|
|
|
|
if (accesstype != null && accesstype == AccessType.ADMINISTRATOR) {
|
|
|
|
isAdmin = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isAdmin) {
|
|
|
|
admins.add(acl.getPricipal());
|
2019-02-22 11:14:22 +01:00
|
|
|
}
|
|
|
|
}
|
2019-05-07 15:02:53 +02:00
|
|
|
logger.debug("Retrieved admins list: " + admins);
|
|
|
|
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
|
|
|
|
return builder.buildGxtInfoContactsFromPortalLogins(admins);
|
2019-02-22 11:14:22 +01:00
|
|
|
}
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
// /**
|
|
|
|
// * DEBUG.
|
|
|
|
// *
|
|
|
|
// * @return the fake groups
|
|
|
|
// */
|
|
|
|
// private List<InfoContactModel> getFakeGroups() {
|
|
|
|
//
|
|
|
|
// List<InfoContactModel> listContactsModel = new
|
|
|
|
// ArrayList<InfoContactModel>();
|
|
|
|
//
|
|
|
|
// PortalContext context = PortalContext.getConfiguration();
|
|
|
|
// System.out.println("context.getInfrastructureName(): " +
|
|
|
|
// context.getInfrastructureName());
|
|
|
|
// // System.out.println("context.getVOsAsString():
|
|
|
|
// // "+context.getVOsAsString());
|
|
|
|
// List<VO> vos =
|
|
|
|
// WsUtil.getVresFromInfrastructure(context.getInfrastructureName(),
|
|
|
|
// "devsec");
|
|
|
|
//
|
|
|
|
// for (VO vo : vos) {
|
|
|
|
// System.out.println("vo name " + vo.getName());
|
|
|
|
//
|
|
|
|
// for (VRE vre : vo.getVres()) {
|
|
|
|
// System.out.println("vre name " + vre.getName());
|
|
|
|
// listContactsModel.add(new InfoContactModel(vre.getName(), vre.getName(),
|
|
|
|
// vre.getName(), true));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return listContactsModel;
|
|
|
|
// }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.
|
|
|
|
* WorkspaceSharingService#getACLForSharedItemId(java.lang.String)
|
|
|
|
*
|
|
|
|
* return the WorkspaceACL of shared folder, null otherwise
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public WorkspaceACL getACLsForSharedFolderId(String itemId) throws Exception {
|
|
|
|
try {
|
|
|
|
logger.info("Call getACLsForSharedFolderId(): [itemId=" + itemId + "]");
|
2015-02-16 15:35:41 +01:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
if (itemId == null || itemId.isEmpty()) {
|
|
|
|
String error = "Invalid shared folder: [itemId=" + itemId + "]";
|
|
|
|
logger.error(error);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
OpenResolver openResolverForItem = shc.open(itemId);
|
|
|
|
FolderContainer folderContainer = openResolverForItem.asFolder();
|
|
|
|
FolderItem folderItem = folderContainer.get();
|
|
|
|
if (folderItem.isShared()) {
|
|
|
|
if (folderItem instanceof SharedFolder) {
|
|
|
|
return retrieveContactsFromACLs(folderContainer);
|
|
|
|
} else {
|
|
|
|
FolderContainer rootSharedFolderContainer = folderContainer.getRootSharedFolder();
|
|
|
|
FolderItem rootSharedFolder = rootSharedFolderContainer.get();
|
|
|
|
if (rootSharedFolder instanceof SharedFolder) {
|
|
|
|
return retrieveContactsFromACLs(rootSharedFolderContainer);
|
|
|
|
} else {
|
|
|
|
String error = "The root shared folder has a invalid type: RootSharedFolder[id="
|
|
|
|
+ rootSharedFolder.getId() + "]";
|
|
|
|
logger.error(error);
|
|
|
|
throw new Exception(error);
|
|
|
|
}
|
2015-02-16 15:35:41 +01:00
|
|
|
}
|
2019-02-22 11:14:22 +01:00
|
|
|
} else {
|
|
|
|
logger.error("The item is not a shared folder: [id=" + itemId + "]");
|
|
|
|
throw new Exception("The item is not a shared folder");
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2014-03-03 16:37:03 +01:00
|
|
|
} catch (Exception e) {
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.error("Error in getACLsForSharedFolderId(): " + e.getLocalizedMessage(), e);
|
|
|
|
String error = "Sorry an error occurred when getting ACL for item: " + itemId;
|
2014-03-03 16:37:03 +01:00
|
|
|
throw new Exception(error);
|
|
|
|
}
|
|
|
|
}
|
2014-02-25 15:58:42 +01:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
private WorkspaceACL retrieveContactsFromACLs(FolderContainer folderContainer) throws Exception {
|
|
|
|
List<ACL> acls = folderContainer.getAcls();
|
|
|
|
logger.debug("Retrieved acls: " + acls);
|
|
|
|
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
|
|
|
|
List<WorkspaceACL> wsAcls = builder.getWorkspaceACLFromACLs(acls);
|
|
|
|
if (wsAcls == null || wsAcls.isEmpty()) {
|
|
|
|
logger.info("Converted ACLBySharedFolderId is null or empty, returning null");
|
|
|
|
return null;
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.info("Returning first acl with id: " + wsAcls.get(0).getId());
|
|
|
|
return wsAcls.get(0);
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
@Override
|
|
|
|
public String getACLsDescriptionForSharedFolderId(String itemId) throws Exception {
|
|
|
|
try {
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.info("Call getACLsDescriptionForSharedFolderId(): [itemId=" + itemId + "]");
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
if (itemId == null || itemId.isEmpty()) {
|
|
|
|
String error = "Invalid shared folder: [id=" + itemId + "]";
|
|
|
|
logger.error(error);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
OpenResolver openResolverForItem = shc.open(itemId);
|
|
|
|
FolderContainer folderContainer = openResolverForItem.asFolder();
|
|
|
|
FolderItem folderItem = folderContainer.get();
|
|
|
|
if (folderItem.isShared()) {
|
|
|
|
if (folderItem instanceof SharedFolder) {
|
|
|
|
return retrieveACLsDescription(folderContainer);
|
|
|
|
} else {
|
|
|
|
FolderContainer rootSharedFolderContainer = folderContainer.getRootSharedFolder();
|
|
|
|
FolderItem rootSharedFolder = rootSharedFolderContainer.get();
|
|
|
|
if (rootSharedFolder instanceof SharedFolder) {
|
|
|
|
return retrieveACLsDescription(rootSharedFolderContainer);
|
|
|
|
} else {
|
|
|
|
String error = "The root shared folder has a invalid type: RootSharedFolder[id="
|
|
|
|
+ rootSharedFolder.getId() + "]";
|
|
|
|
logger.error(error);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
String error = "This item isn't a valid shared folder: [id=" + itemId + "]";
|
|
|
|
logger.error(error);
|
|
|
|
return null;
|
2014-03-03 19:17:26 +01:00
|
|
|
}
|
2019-02-22 11:14:22 +01:00
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error in getACLsDescriptionForSharedFolderId(): " + e.getLocalizedMessage(), e);
|
|
|
|
String error = "Sorry an error occurred when getting ACL rules for selected folder. "
|
|
|
|
+ e.getLocalizedMessage();
|
|
|
|
throw new Exception(error);
|
2014-03-03 19:17:26 +01:00
|
|
|
}
|
2019-02-22 11:14:22 +01:00
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
private String retrieveACLsDescription(FolderContainer folderContainer) throws Exception {
|
|
|
|
List<ACL> acls = folderContainer.getAcls();
|
|
|
|
logger.debug("Retrieved acls: " + acls);
|
|
|
|
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
|
|
|
|
return builder.getFormattedHtmlACLFromACLs(acls);
|
2014-03-03 19:17:26 +01:00
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2014-08-25 15:29:49 +02:00
|
|
|
@Override
|
2019-02-22 11:14:22 +01:00
|
|
|
public boolean unSharedFolderByFolderSharedId(String itemId) throws Exception {
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
if (isSessionExpired())
|
|
|
|
throw new SessionExpiredException();
|
2014-08-25 15:29:49 +02:00
|
|
|
|
|
|
|
try {
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.debug("Call unSharedFolderByFolderSharedId(): [id=" + itemId + "]");
|
|
|
|
if (itemId == null || itemId.isEmpty()) {
|
|
|
|
logger.error("Invalid folder requested: [id=" + itemId + "]");
|
|
|
|
throw new Exception("Invalid folder requested: [id=" + itemId + "]");
|
|
|
|
}
|
2019-03-26 17:10:16 +01:00
|
|
|
boolean unshared = false;
|
2019-02-22 11:14:22 +01:00
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
OpenResolver openResolver = shc.open(itemId);
|
|
|
|
FolderContainer folderContainer = openResolver.asFolder();
|
|
|
|
FolderItem folderItem = folderContainer.get();
|
|
|
|
if (folderItem != null) {
|
|
|
|
if (folderItem.isShared()) {
|
|
|
|
logger.debug("Folder is shared");
|
|
|
|
if (folderItem instanceof SharedFolder) {
|
|
|
|
logger.debug("Folder type: SharedFolder");
|
|
|
|
SharedFolder sharedFolder = (SharedFolder) folderItem;
|
|
|
|
folderContainer.unshare(sharedFolder.getUsers().getMap().keySet());
|
2019-03-26 17:10:16 +01:00
|
|
|
unshared = true;
|
2019-04-29 18:37:42 +02:00
|
|
|
ArrayList<InfoContactModel> listContacts = new ArrayList<>();
|
|
|
|
for (String key : sharedFolder.getUsers().getMap().keySet()) {
|
|
|
|
InfoContactModel contact = new InfoContactModel(key, key, key, false);
|
2019-03-26 17:10:16 +01:00
|
|
|
listContacts.add(contact);
|
|
|
|
}
|
2019-04-29 18:37:42 +02:00
|
|
|
NotificationsProducer np = getNotificationProducer(this.getThreadLocalRequest());
|
|
|
|
np.notifyFolderUnSharing(listContacts, folderItem);
|
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
} else {
|
|
|
|
String msg = "The folder requested is not a root shared folder."
|
|
|
|
+ "To unshare this folder you have to unshare the root shared folder!";
|
|
|
|
logger.debug(msg);
|
|
|
|
throw new Exception("The folder requested is not a root shared folder."
|
|
|
|
+ "To unshare this folder you have to unshare the root shared folder");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logger.error("Folder requested is not a shared ");
|
|
|
|
throw new Exception("The folder requested is not shared!");
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logger.error("Invalid folder retrieved: [id=" + itemId + "]");
|
|
|
|
throw new Exception("Invalid folder retrieved: [id=" + itemId + "]");
|
|
|
|
}
|
|
|
|
|
2019-03-26 17:10:16 +01:00
|
|
|
return unshared;
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2014-08-25 15:29:49 +02:00
|
|
|
} catch (Exception e) {
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.error("Error in unSharedFolderByFolderSharedId(): " + e.getLocalizedMessage(), e);
|
|
|
|
String error = ConstantsSharing.SERVER_ERROR + " unsharing item.";
|
2014-08-25 15:29:49 +02:00
|
|
|
throw new Exception(error);
|
|
|
|
}
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2014-06-26 15:06:10 +02:00
|
|
|
/**
|
2019-02-22 11:14:22 +01:00
|
|
|
* Gets the user acl for folder id.
|
2015-08-03 12:10:59 +02:00
|
|
|
*
|
2019-02-22 11:14:22 +01:00
|
|
|
* @param itemId
|
|
|
|
* the folder id
|
|
|
|
* @return the user acl for folder id
|
|
|
|
* @throws Exception
|
|
|
|
* the exception
|
2014-06-26 15:06:10 +02:00
|
|
|
*/
|
2019-02-22 11:14:22 +01:00
|
|
|
@Override
|
|
|
|
public List<ExtendedWorkspaceACL> getUserACLForFolderId(String itemId) throws Exception {
|
|
|
|
try {
|
|
|
|
logger.info("Call getUserACLForFolderId(): [itemId=" + itemId + "]");
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
if (itemId == null || itemId.isEmpty()) {
|
|
|
|
String error = "Invalid shared folder: [itemId=" + itemId + "]";
|
|
|
|
logger.error(error);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
OpenResolver openResolverForItem = shc.open(itemId);
|
|
|
|
FolderContainer folderContainer = openResolverForItem.asFolder();
|
|
|
|
FolderItem folderItem = folderContainer.get();
|
|
|
|
if (folderItem.isShared()) {
|
|
|
|
if (folderItem instanceof SharedFolder) {
|
|
|
|
List<WorkspaceACL> acls = retrieveACLsFromFolderContainer(folderContainer);
|
|
|
|
List<ExtendedWorkspaceACL> listEACL = new ArrayList<ExtendedWorkspaceACL>(acls.size());
|
|
|
|
for (WorkspaceACL workspaceACL : acls) {
|
|
|
|
boolean isBaseSharedFolder = true;
|
|
|
|
ExtendedWorkspaceACL eac = new ExtendedWorkspaceACL(workspaceACL.getId(),
|
|
|
|
workspaceACL.getAclType(), workspaceACL.getLabel(), workspaceACL.getDefaultValue(),
|
|
|
|
workspaceACL.getUserType(), workspaceACL.getDescription(), folderItem.getOwner(),
|
|
|
|
itemId, isBaseSharedFolder);
|
|
|
|
logger.debug("ACL " + workspaceACL + " converted in: " + eac);
|
|
|
|
listEACL.add(eac);
|
|
|
|
}
|
|
|
|
return listEACL;
|
|
|
|
} else {
|
|
|
|
FolderContainer rootSharedFolderContainer = folderContainer.getRootSharedFolder();
|
|
|
|
FolderItem rootSharedFolder = rootSharedFolderContainer.get();
|
|
|
|
if (rootSharedFolder instanceof SharedFolder) {
|
|
|
|
List<WorkspaceACL> acls = retrieveACLsFromFolderContainer(folderContainer);
|
|
|
|
List<ExtendedWorkspaceACL> listEACL = new ArrayList<ExtendedWorkspaceACL>(acls.size());
|
|
|
|
for (WorkspaceACL workspaceACL : acls) {
|
|
|
|
boolean isBaseSharedFolder = true;
|
|
|
|
ExtendedWorkspaceACL eac = new ExtendedWorkspaceACL(workspaceACL.getId(),
|
|
|
|
workspaceACL.getAclType(), workspaceACL.getLabel(), workspaceACL.getDefaultValue(),
|
|
|
|
workspaceACL.getUserType(), workspaceACL.getDescription(), folderItem.getOwner(),
|
|
|
|
itemId, isBaseSharedFolder);
|
|
|
|
logger.debug("ACL " + workspaceACL + " converted in: " + eac);
|
|
|
|
listEACL.add(eac);
|
|
|
|
}
|
|
|
|
return listEACL;
|
|
|
|
} else {
|
|
|
|
String error = "The root shared folder has a invalid type: RootSharedFolder[id="
|
|
|
|
+ rootSharedFolder.getId() + "]";
|
|
|
|
logger.error(error);
|
|
|
|
throw new Exception(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logger.error("The item is not a shared folder: [id=" + itemId + "]");
|
|
|
|
throw new Exception("The item is not a shared folder");
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error in getUserACLForFolderId(): " + e.getLocalizedMessage(), e);
|
|
|
|
throw new Exception("Error retrieving ACL rules for selected folder: " + e.getLocalizedMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
private List<WorkspaceACL> retrieveACLsFromFolderContainer(FolderContainer folderContainer) throws Exception {
|
|
|
|
List<ACL> acls = folderContainer.getAcls();
|
|
|
|
logger.debug("Retrieved acls: " + acls);
|
|
|
|
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
|
|
|
|
List<WorkspaceACL> wsAcls = builder.getWorkspaceACLFromACLs(acls);
|
|
|
|
if (wsAcls == null || wsAcls.isEmpty()) {
|
|
|
|
logger.info("Converted ACLBySharedFolderId is null or empty, returning null");
|
|
|
|
return null;
|
2014-06-26 15:06:10 +02:00
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.info("Returning first acl with id: " + wsAcls.get(0).getId());
|
|
|
|
return wsAcls;
|
2014-06-26 15:06:10 +02:00
|
|
|
}
|
2014-08-25 15:29:49 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
/**
|
|
|
|
* Gets ACLs Description For WorkspaceItem ById.
|
2016-04-14 15:16:09 +02:00
|
|
|
*
|
2019-02-22 11:14:22 +01:00
|
|
|
* @param itemId
|
|
|
|
* the folder id
|
|
|
|
* @return a description of the ACLs
|
|
|
|
* @throws Exception
|
|
|
|
* the exception
|
2015-01-28 11:21:10 +01:00
|
|
|
*/
|
|
|
|
@Override
|
2019-02-22 11:14:22 +01:00
|
|
|
public String getACLsDescriptionForWorkspaceItemById(String itemId) throws Exception {
|
2015-01-28 11:21:10 +01:00
|
|
|
try {
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.info("Call getACLsDescriptionForWorkspaceItemById(): " + itemId);
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
OpenResolver openResolverForItem = shc.open(itemId);
|
|
|
|
FolderContainer folderContainer = openResolverForItem.asFolder();
|
|
|
|
String aclDescription = retrieveACLsDescription(folderContainer);
|
|
|
|
logger.debug("Retrieved ACL description: " + aclDescription);
|
|
|
|
return aclDescription;
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error in getACLsDescriptionForWorkspaceItemById(): " + e.getLocalizedMessage(), e);
|
|
|
|
throw new Exception("Error retrieving ACL descriptions for requested item: " + e.getLocalizedMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#
|
|
|
|
* accessToFolderLink(java.lang.String)
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Access to folder link.
|
|
|
|
*
|
|
|
|
* @param itemId
|
|
|
|
* the item id
|
|
|
|
* @return the allow access
|
|
|
|
* @throws SessionExpiredException
|
|
|
|
* the session expired exception
|
|
|
|
* @throws Exception
|
|
|
|
* the exception
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public AllowAccess accessToFolderLink(String itemId) throws Exception {
|
|
|
|
try {
|
|
|
|
logger.info("Call accessToFolderLink(): " + itemId);
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
OpenResolver openResolverForItem = shc.open(itemId);
|
|
|
|
FolderContainer folderContainer = openResolverForItem.asFolder();
|
|
|
|
FolderItem folderItem = folderContainer.get();
|
|
|
|
InfoContactModel owner = null;
|
|
|
|
if (folderItem != null) {
|
|
|
|
logger.debug("Owner: " + folderItem.getOwner());
|
|
|
|
PortalContextInfo info = WsUtil.getPortalContext(this.getThreadLocalRequest());
|
|
|
|
if (folderItem.getOwner() != null && !folderItem.getOwner().isEmpty()) {
|
|
|
|
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
|
|
|
|
|
|
|
|
List<InfoContactModel> listContactsModel = builder.buildGXTListContactsModelFromUserModel(info);
|
2019-05-07 15:02:53 +02:00
|
|
|
boolean ownerFound = false;
|
2019-02-22 11:14:22 +01:00
|
|
|
for (InfoContactModel icm : listContactsModel) {
|
|
|
|
if (icm.getLogin().compareTo(folderItem.getOwner()) == 0) {
|
2019-05-07 15:02:53 +02:00
|
|
|
logger.debug("Owner Retrieved: " + icm);
|
2019-02-22 11:14:22 +01:00
|
|
|
owner = icm;
|
2019-05-07 15:02:53 +02:00
|
|
|
ownerFound = true;
|
|
|
|
break;
|
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
}
|
|
|
|
}
|
2019-05-07 15:02:53 +02:00
|
|
|
if (!ownerFound) {
|
|
|
|
logger.debug("Owner not found from user model!");
|
|
|
|
owner = new InfoContactModel(folderItem.getOwner(), folderItem.getOwner(),
|
|
|
|
folderItem.getOwner(), false);
|
|
|
|
}
|
2019-02-22 11:14:22 +01:00
|
|
|
} else {
|
|
|
|
logger.debug("Owner not found from item");
|
2019-05-07 15:02:53 +02:00
|
|
|
owner = null;
|
2019-02-22 11:14:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
String username = info.getUsername();
|
|
|
|
if (folderItem.isPublicItem()) {
|
|
|
|
logger.info("The folder is already public. Access granted to " + username);
|
|
|
|
return new AllowAccess(itemId, true, "The folder is already public. Access granted to " + username,
|
|
|
|
null);
|
|
|
|
}
|
2019-05-07 15:02:53 +02:00
|
|
|
logger.info("The owner of: " + folderItem.getName() + " is: " + owner);
|
|
|
|
logger.info("The current context user: " + username);
|
|
|
|
if (owner != null && owner.getLogin().compareToIgnoreCase(username) == 0) {
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.info("Access to Folder Link " + folderItem.getName() + " granted, " + username
|
|
|
|
+ " is the owner of: " + itemId);
|
|
|
|
return new AllowAccess(itemId, true,
|
|
|
|
info.getUserFullName() + " is the owner of: " + folderItem.getName(), null);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
List<InfoContactModel> admins = null;
|
|
|
|
|
|
|
|
if (folderItem.isShared()) {
|
|
|
|
if (folderItem instanceof SharedFolder) {
|
|
|
|
admins = retrieveAdminContactsFromACLs(folderContainer);
|
|
|
|
} else {
|
|
|
|
FolderContainer rootSharedFolderContainer = folderContainer.getRootSharedFolder();
|
|
|
|
FolderItem rootSharedFolder = rootSharedFolderContainer.get();
|
|
|
|
if (rootSharedFolder instanceof SharedFolder) {
|
|
|
|
admins = retrieveAdminContactsFromACLs(rootSharedFolderContainer);
|
|
|
|
} else {
|
|
|
|
String error = "The root shared folder has a invalid type: RootSharedFolder[id="
|
|
|
|
+ rootSharedFolder.getId() + "]";
|
|
|
|
logger.error(error);
|
|
|
|
throw new Exception(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logger.error("The item requested is not a valid shared folder : [itemId=" + itemId + "]");
|
|
|
|
throw new Exception(
|
|
|
|
"The item requested is not a valid shared folder : [itemId=" + itemId + "]");
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-05-07 15:02:53 +02:00
|
|
|
if (admins != null) {
|
|
|
|
for (InfoContactModel infoContactModel : admins) {
|
|
|
|
if (infoContactModel.getLogin().compareToIgnoreCase(username) == 0) {
|
|
|
|
logger.info("Access to Folder Link " + logger.getName() + " granted, " + username
|
|
|
|
+ " is the admin of: " + itemId);
|
|
|
|
return new AllowAccess(itemId, true,
|
|
|
|
info.getUserFullName() + " is the admin of: " + folderItem.getName(), null);
|
|
|
|
}
|
2019-02-22 11:14:22 +01:00
|
|
|
}
|
2019-05-07 15:02:53 +02:00
|
|
|
} else {
|
|
|
|
return new AllowAccess(itemId, false,
|
|
|
|
"You have not permission to get Folder Link, you must be owner or administrator to the folder", "Permission not found");
|
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
return new AllowAccess(itemId, false,
|
|
|
|
"You have not permission to get Folder Link, you must be owner or administrator to the folder",
|
|
|
|
e.getMessage());
|
2015-01-28 11:21:10 +01:00
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
return new AllowAccess(itemId, false,
|
|
|
|
"You have not permission to get Folder Link, you must be owner or administrator to the folder",
|
|
|
|
null);
|
|
|
|
} else {
|
|
|
|
return new AllowAccess(itemId, false, "The item is not a folder", null);
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-05-07 15:02:53 +02:00
|
|
|
} catch (Exception e) {
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.error("Error in server FormattedGcubeItemProperties: " + e.getLocalizedMessage(), e);
|
|
|
|
String error = "Error when reading access policy to Folder Link: " + itemId + ", Refresh and try again";
|
|
|
|
throw new Exception(error, e);
|
2015-01-28 11:21:10 +01:00
|
|
|
}
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see
|
|
|
|
* org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#setACLs(
|
|
|
|
* java.lang.String, java.util.List, java.lang.String)
|
|
|
|
*/
|
2015-01-28 17:41:11 +01:00
|
|
|
/**
|
2019-02-22 11:14:22 +01:00
|
|
|
* Sets the ac ls.
|
2015-08-03 12:10:59 +02:00
|
|
|
*
|
2019-02-22 11:14:22 +01:00
|
|
|
* @param itemId
|
|
|
|
* the folder id
|
|
|
|
* @param listLogins
|
|
|
|
* the list logins
|
|
|
|
* @param aclType
|
|
|
|
* the acl type
|
|
|
|
* @throws Exception
|
|
|
|
* the exception
|
2015-01-28 17:41:11 +01:00
|
|
|
*/
|
|
|
|
@Override
|
2019-02-22 11:14:22 +01:00
|
|
|
public void setACLs(String itemId, List<String> listLogins, String aclType) throws Exception {
|
2015-01-28 17:41:11 +01:00
|
|
|
try {
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.info("Call setACLs(): [itemId=" + itemId + ", listLogins=" + listLogins + ", aclType=" + aclType);
|
|
|
|
String error = "Set ACLs is not enabled in StorageHub. You must share, or unshare a root folder for set ACLs.";
|
|
|
|
logger.error(error);
|
2015-01-28 17:41:11 +01:00
|
|
|
throw new Exception(error);
|
2019-02-22 11:14:22 +01:00
|
|
|
// if(folderId == null)
|
|
|
|
// throw new Exception("Folder id is null");
|
|
|
|
//
|
|
|
|
// if(listLogins==null || listLogins.size()==0)
|
|
|
|
// throw new Exception("List Logins is null or empty");
|
|
|
|
//
|
|
|
|
// logger.trace("Setting ACL for folder id: "+folderId);
|
|
|
|
// logger.trace("ACL type is: "+aclType);
|
|
|
|
// Workspace workspace = getWorkspace();
|
|
|
|
// WorkspaceItem wsItem = workspace.getItem(folderId);
|
|
|
|
//
|
|
|
|
// //IS A WORKSPACE FOLDER?
|
|
|
|
// if(wsItem!= null && wsItem.isFolder() && wsItem.isShared()){
|
|
|
|
// WorkspaceFolder ite;
|
|
|
|
// if(wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)){
|
|
|
|
// //IS ROOT SHARED FOLDER
|
|
|
|
// ite = (WorkspaceSharedFolder) wsItem;
|
|
|
|
// logger.trace("Folder " +ite.getName()+" is a
|
|
|
|
// "+WorkspaceSharedFolder.class.getName());
|
|
|
|
// // ite = (WorkspaceSharedFolder)
|
|
|
|
// workspace.getItemByPath(wsItem.getPath());
|
|
|
|
// }else{
|
|
|
|
// // IS SUB FOLDER OF THE SHARING
|
|
|
|
// ite = (WorkspaceFolder) wsItem;
|
|
|
|
// logger.trace("Folder " +ite.getName()+" is a
|
|
|
|
// "+WorkspaceFolder.class.getName());
|
|
|
|
// // ite = (WorkspaceSharedFolder)
|
|
|
|
// workspace.getItem(wsItem.getIdSharedFolder());
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// ite.setACL(listLogins, ACLType.valueOf(aclType));
|
|
|
|
// }else
|
|
|
|
// throw new Exception("Source item is not shared or shared
|
|
|
|
// folder");
|
|
|
|
//
|
|
|
|
// logger.info("Setting ACL for "+wsItem.getName()+" completed,
|
|
|
|
// returning");
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error in setACLs(): " + e.getLocalizedMessage(), e);
|
|
|
|
String error = "Error setting permissions. " + e.getLocalizedMessage();
|
|
|
|
throw new Exception(error, e);
|
2015-01-28 17:41:11 +01:00
|
|
|
}
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2015-02-16 12:31:51 +01:00
|
|
|
/**
|
2019-02-22 11:14:22 +01:00
|
|
|
* Validate acl to user.
|
2015-08-03 12:10:59 +02:00
|
|
|
*
|
2019-02-22 11:14:22 +01:00
|
|
|
* @param itemId
|
|
|
|
* the folder id
|
|
|
|
* @param listLogins
|
|
|
|
* the list logins
|
|
|
|
* @param aclType
|
|
|
|
* the acl type
|
|
|
|
* @return the report assignment acl
|
|
|
|
* @throws Exception
|
|
|
|
* the exception
|
2015-02-16 12:31:51 +01:00
|
|
|
*/
|
2019-02-22 11:14:22 +01:00
|
|
|
@Override
|
|
|
|
public ReportAssignmentACL validateACLToUser(String itemId, List<String> listLogins, String aclType)
|
|
|
|
throws Exception {
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
try {
|
|
|
|
logger.info("Call validateACLToUser(): [itemId=" + itemId + "]");
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
if (itemId == null || itemId.isEmpty()) {
|
|
|
|
String error = "Invalid folder id: [itemId=" + itemId + "]";
|
|
|
|
logger.error(error);
|
|
|
|
return null;
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
AccessType settingACL = AccessType.valueOf(aclType);
|
|
|
|
if (settingACL == null) {
|
|
|
|
String error = "Invalid acl type requested: [AccessType=" + aclType + "]";
|
|
|
|
logger.error(error);
|
|
|
|
return null;
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
OpenResolver openResolverForItem = shc.open(itemId);
|
|
|
|
FolderContainer folderContainer = openResolverForItem.asFolder();
|
|
|
|
FolderItem folderItem = folderContainer.get();
|
|
|
|
if (folderItem.isShared()) {
|
|
|
|
if (folderItem instanceof SharedFolder) {
|
|
|
|
List<ACL> acls = folderContainer.getAcls();
|
|
|
|
logger.debug("Retrieved acls: " + acls);
|
|
|
|
return createReportAssignementACL(acls, listLogins, settingACL);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
FolderContainer rootSharedFolderContainer = folderContainer.getRootSharedFolder();
|
|
|
|
FolderItem rootSharedFolder = rootSharedFolderContainer.get();
|
|
|
|
if (rootSharedFolder instanceof SharedFolder) {
|
|
|
|
List<ACL> acls = folderContainer.getAcls();
|
|
|
|
logger.debug("Retrieved acls: " + acls);
|
|
|
|
return createReportAssignementACL(acls, listLogins, settingACL);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
String error = "The root shared folder has a invalid type: RootSharedFolder[id="
|
|
|
|
+ rootSharedFolder.getId() + "]";
|
|
|
|
logger.error(error);
|
|
|
|
throw new Exception(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logger.error("The item is not a shared folder: [id=" + itemId + "]");
|
|
|
|
throw new Exception("The item is not a shared folder");
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error on setting ACLs", e);
|
|
|
|
throw new Exception("Sorry, an error occurred when validating ACL assignment, try again later");
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
private ReportAssignmentACL createReportAssignementACL(List<ACL> acls, List<String> listLogins,
|
|
|
|
AccessType settingACL) {
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.debug("Retrieved acls: " + acls);
|
|
|
|
List<String> admins = new ArrayList<>();
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
// REMOVE ADMINS
|
|
|
|
for (ACL acl : acls) {
|
|
|
|
boolean isAdmin = false;
|
|
|
|
for (AccessType accesstype : acl.getAccessTypes()) {
|
|
|
|
if (accesstype != null && accesstype == AccessType.ADMINISTRATOR) {
|
|
|
|
isAdmin = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isAdmin) {
|
|
|
|
admins.add(acl.getPricipal());
|
2015-01-28 17:41:11 +01:00
|
|
|
}
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
List<String> errors = new ArrayList<String>();
|
|
|
|
if (!admins.isEmpty()) {
|
|
|
|
for (String admin : admins) {
|
|
|
|
boolean removed = listLogins.remove(admin);
|
|
|
|
logger.info("Reject username: " + admin + " as " + AccessType.ADMINISTRATOR);
|
|
|
|
if (removed) {
|
|
|
|
String fullname = isTestMode() ? admin : UserUtil.getUserFullName(admin);
|
|
|
|
errors.add("Unable to grant the privilege " + settingACL + " for " + fullname + ", he/she is an: "
|
|
|
|
+ AccessType.ADMINISTRATOR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
// COMPLETE REPORT
|
|
|
|
AccessTypeComparator comparator = new AccessTypeComparator();
|
|
|
|
List<String> validLogins = new ArrayList<String>(listLogins);
|
|
|
|
ReportAssignmentACL reportValidation = new ReportAssignmentACL();
|
|
|
|
logger.debug("\nChecking listLogins: " + listLogins);
|
|
|
|
|
|
|
|
for (String username : listLogins) {
|
|
|
|
logger.trace("\nChecking username: " + username);
|
|
|
|
String fullname = isTestMode() ? username : UserUtil.getUserFullName(username);
|
|
|
|
for (ACL acl : acls) {
|
|
|
|
if (acl.getPricipal().compareTo(username) == 0) {
|
|
|
|
checkAccessType(settingACL, errors, comparator, validLogins, username, fullname, acl);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-01-28 17:41:11 +01:00
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.info("Valid logins: ");
|
|
|
|
for (String username : validLogins) {
|
|
|
|
logger.info("Set ACL: " + settingACL + " to " + username);
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
reportValidation.setAclType(settingACL.name());
|
|
|
|
reportValidation.setErrors(errors);
|
|
|
|
reportValidation.setValidLogins(validLogins);
|
|
|
|
return reportValidation;
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
private void checkAccessType(AccessType settingACL, List<String> errors, AccessTypeComparator comparator,
|
|
|
|
List<String> validLogins, String username, String fullname, ACL acl) {
|
|
|
|
for (AccessType currentAccessType : acl.getAccessTypes()) {
|
|
|
|
int cmp = comparator.compare(settingACL, currentAccessType);
|
|
|
|
if (cmp == -1) {
|
|
|
|
// CHANGE ACL IS NOT VALID
|
|
|
|
logger.debug("Reject ACL: " + settingACL + " to " + username);
|
|
|
|
validLogins.remove(username);
|
|
|
|
errors.add("Unable to grant the privilege " + settingACL + " for " + fullname
|
|
|
|
+ ", it's lower than (parent privilege) " + currentAccessType);
|
|
|
|
break;
|
|
|
|
} else if (cmp == 0) {
|
|
|
|
// SAME ACL
|
|
|
|
logger.debug("Skipping ACL: " + settingACL + " to " + username);
|
|
|
|
errors.add(settingACL + " privilege for " + fullname + " already assigned");
|
|
|
|
validLogins.remove(username);
|
|
|
|
break;
|
|
|
|
} else if (cmp == 1) {
|
|
|
|
// CHANGE ACL IS VALID
|
|
|
|
logger.debug("Valid ACL: " + settingACL + " to " + fullname);
|
2015-01-28 17:41:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
|
|
|
/**
|
2019-02-22 11:14:22 +01:00
|
|
|
* Update acl for vr eby group name.
|
2016-04-14 15:16:09 +02:00
|
|
|
*
|
2019-02-22 11:14:22 +01:00
|
|
|
* @param folderId
|
|
|
|
* the folder id
|
|
|
|
* @param aclType
|
|
|
|
* the acl type
|
|
|
|
* @throws Exception
|
|
|
|
* the exception
|
2016-04-14 15:16:09 +02:00
|
|
|
*/
|
2019-02-22 11:14:22 +01:00
|
|
|
@Override
|
|
|
|
public void updateACLForVREbyGroupName(String folderId, String aclType) throws Exception {
|
|
|
|
try {
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
if (folderId == null)
|
|
|
|
throw new Exception("Folder id is null");
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.trace("Updating ACL to VRE FOLDER id: " + folderId);
|
|
|
|
logger.trace("ACL type is: " + aclType);
|
|
|
|
logger.trace("Get Workspace");
|
|
|
|
PortalContextInfo info = WsUtil.getPortalContext(this.getThreadLocalRequest());
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.trace("PortalContextInfo: " + info);
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
ScopeProvider.instance.set(info.getCurrentScope());
|
|
|
|
logger.trace("Scope provider set: " + info.getCurrentScope());
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
Workspace workspace = HomeLibrary.getUserWorkspace(info.getUsername());
|
|
|
|
WorkspaceItem wsItem = workspace.getItem(folderId);
|
|
|
|
|
|
|
|
if (wsItem.isShared() && wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)) {
|
|
|
|
WorkspaceSharedFolder ite = (WorkspaceSharedFolder) wsItem;
|
|
|
|
// PATCH TODO TEMPORARY SOLUTION
|
|
|
|
if (ite.isVreFolder()) {
|
|
|
|
List<String> groupName = new ArrayList<String>();
|
|
|
|
groupName.add(wsItem.getName());
|
|
|
|
ite.setACL(groupName, ACLType.valueOf(aclType));
|
2016-04-14 15:16:09 +02:00
|
|
|
}
|
2019-02-22 11:14:22 +01:00
|
|
|
} else
|
|
|
|
throw new Exception("Source item is not shared or shared folder");
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
logger.trace("Updating ACL completed, retuning");
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error in set ACLs", e);
|
|
|
|
String error = "Error updating the permissions. " + e.getMessage();
|
|
|
|
throw new Exception(error);
|
|
|
|
}
|
|
|
|
}
|
2016-04-14 15:16:09 +02:00
|
|
|
|
|
|
|
/**
|
2019-02-22 11:14:22 +01:00
|
|
|
* Check notify add item to share.
|
2016-04-14 15:16:09 +02:00
|
|
|
*
|
2019-02-22 11:14:22 +01:00
|
|
|
* @param destinationItem
|
|
|
|
* the destination item
|
|
|
|
* @param sourceSharedId
|
|
|
|
* the source shared id
|
|
|
|
* @param folderDestinationItem
|
|
|
|
* the folder destination item
|
2016-04-14 15:16:09 +02:00
|
|
|
*/
|
2019-02-22 11:14:22 +01:00
|
|
|
// private void checkNotifyAddItemToShare(final WorkspaceItem
|
|
|
|
// destinationItem,
|
|
|
|
// final String sourceSharedId, final WorkspaceItem folderDestinationItem) {
|
|
|
|
//
|
|
|
|
// logger.trace("checkNotifyAddItemToShare");
|
|
|
|
//
|
|
|
|
// if(folderDestinationItem!=null){
|
|
|
|
//
|
|
|
|
// try{
|
|
|
|
// //if folder destination is shared folder
|
|
|
|
// if(folderDestinationItem.isShared()){ //Notify Added Item To Sharing?
|
|
|
|
// logger.trace("checkNotifyAddItemToShare destination item:
|
|
|
|
// "+destinationItem.getName()+" sourceSharedId: "+sourceSharedId + " folder
|
|
|
|
// destination: "+folderDestinationItem.getName());
|
|
|
|
// //share condition is true if source shared folder is null or not equal to
|
|
|
|
// destination shared folder
|
|
|
|
// boolean shareChangeCondition = sourceSharedId==null ||
|
|
|
|
// sourceSharedId.compareTo(folderDestinationItem.getIdSharedFolder())!=0;
|
|
|
|
// logger.trace("shareChangeCondition add item: "+shareChangeCondition);
|
|
|
|
// //if shareChangeCondition is true.. notifies added item to sharing
|
|
|
|
// if(shareChangeCondition){
|
|
|
|
//
|
|
|
|
// List<InfoContactModel> listContacts =
|
|
|
|
// getListUserSharedByFolderSharedId(folderDestinationItem.getIdSharedFolder());
|
|
|
|
//
|
|
|
|
// //DEBUG
|
|
|
|
// //printContacts(listContacts);
|
|
|
|
// Workspace workspace = getWorkspace();
|
|
|
|
// WorkspaceItem destinationSharedFolder =
|
|
|
|
// workspace.getItem(folderDestinationItem.getIdSharedFolder());
|
|
|
|
// NotificationsProducer np = getNotificationProducer();
|
|
|
|
//
|
|
|
|
// if(destinationSharedFolder instanceof WorkspaceSharedFolder){
|
|
|
|
// np.notifyAddedItemToSharing(listContacts, destinationItem,
|
|
|
|
// (WorkspaceSharedFolder) destinationSharedFolder);
|
|
|
|
// logger.trace("The notifies sent correctly");
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// logger.warn("Notifies added item: "+destinationItem+ "to share doesn't
|
|
|
|
// sent
|
|
|
|
// because "+destinationSharedFolder+" is not istance of
|
|
|
|
// WorkspaceSharedFolder");
|
|
|
|
// // np.notifyAddedItemToSharing(listContacts, (WorkspaceFolder)
|
|
|
|
// folderDestinationItem);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// logger.trace("folder destination is not shared");
|
|
|
|
//
|
|
|
|
// }catch (Exception e) {
|
|
|
|
// logger.error("An error occurred in verifyNotifyAddItemToShare ",e);
|
|
|
|
// }
|
|
|
|
// }else
|
|
|
|
// logger.warn("The notifies is failure in verifyNotifyAddItemToShare
|
|
|
|
// because
|
|
|
|
// folder destination item is null");
|
|
|
|
// }
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
/**
|
|
|
|
* Check notify move item from share.
|
|
|
|
*
|
|
|
|
* @param sourceItemIsShared
|
|
|
|
* the source item is shared
|
|
|
|
* @param sourceItem
|
|
|
|
* the source item
|
|
|
|
* @param sourceSharedId
|
|
|
|
* the source shared id
|
|
|
|
* @param folderDestinationItem
|
|
|
|
* the folder destination item
|
|
|
|
*/
|
|
|
|
// private void checkNotifyMoveItemFromShare(final boolean
|
|
|
|
// sourceItemIsShared,
|
|
|
|
// final WorkspaceItem sourceItem, final String sourceSharedId, final
|
|
|
|
// WorkspaceItem folderDestinationItem) {
|
|
|
|
//
|
|
|
|
// logger.trace("checkNotifyMoveItemFromShare:");
|
|
|
|
//
|
|
|
|
// try{
|
|
|
|
//
|
|
|
|
// if(folderDestinationItem!=null){
|
|
|
|
//
|
|
|
|
// String idSharedFolder =
|
|
|
|
// folderDestinationItem.getIdSharedFolder()!=null?folderDestinationItem.getIdSharedFolder():"";
|
|
|
|
//
|
|
|
|
// //share condition is true if source shared folder is not equal to
|
|
|
|
// destination
|
|
|
|
// shared folder
|
|
|
|
// boolean shareChangeCondition =
|
|
|
|
// sourceSharedId==null?false:sourceSharedId.compareTo(idSharedFolder)!=0;
|
|
|
|
//
|
|
|
|
// logger.trace("checkNotifyMoveItemFromShare source item:
|
|
|
|
// "+sourceItem.getName()+" sourceSharedId: "+sourceSharedId + " folder
|
|
|
|
// destination: "+folderDestinationItem.getName() +" sourceItemIsShared:
|
|
|
|
// "+sourceItemIsShared);
|
|
|
|
//
|
|
|
|
// // System.out.println("shareChangeCondition remove item: "+
|
|
|
|
// shareChangeCondition);
|
|
|
|
//
|
|
|
|
// logger.trace("shareChangeCondition remove item: "+ shareChangeCondition);
|
|
|
|
//
|
|
|
|
// //Notify Removed Item To Sharing?
|
|
|
|
// //if source Item is shared and folder destination is not shared or
|
|
|
|
// shareChangeCondition is true.. notifies removed item to sharing
|
|
|
|
// if(sourceItemIsShared && (!folderDestinationItem.isShared() ||
|
|
|
|
// shareChangeCondition)){
|
|
|
|
//
|
|
|
|
// //get contacts
|
|
|
|
// List<InfoContactModel> listContacts =
|
|
|
|
// getListUserSharedByFolderSharedId(sourceSharedId);
|
|
|
|
//
|
|
|
|
// //DEBUG
|
|
|
|
// printContacts(listContacts);
|
|
|
|
// Workspace workspace = getWorkspace();
|
|
|
|
// WorkspaceItem sourceSharedFolder = workspace.getItem(sourceSharedId);
|
|
|
|
// NotificationsProducer np = getNotificationProducer();
|
|
|
|
//
|
|
|
|
// if(sourceSharedFolder instanceof WorkspaceSharedFolder){
|
|
|
|
// np.notifyMovedItemToSharing(listContacts, sourceItem,
|
|
|
|
// (WorkspaceSharedFolder)
|
|
|
|
// sourceSharedFolder);
|
|
|
|
// logger.trace("The notifies was sent correctly");
|
|
|
|
// }else
|
|
|
|
// logger.warn("Notifies moved item: "+sourceItem+ "from share doesn't sent
|
|
|
|
// because "+sourceSharedFolder+" is not istance of WorkspaceSharedFolder");
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// }else
|
|
|
|
// logger.warn("The notifies is failure in checkNotifyMoveItemFromShare
|
|
|
|
// because
|
|
|
|
// folder destination item is null");
|
|
|
|
//
|
|
|
|
// }catch (Exception e) {
|
|
|
|
// logger.error("An error occurred in checkNotifyMoveItemFromShare ",e);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// }
|
2016-04-14 15:16:09 +02:00
|
|
|
|
2014-02-25 14:28:30 +01:00
|
|
|
}
|