workspace-sharing-widget/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/WorkspaceSharingServiceImpl...

1585 lines
56 KiB
Java

package org.gcube.portlets.widgets.workspacesharingwidget.server;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
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;
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;
import org.gcube.portlets.widgets.workspacesharingwidget.client.ConstantsSharing;
import org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService;
import org.gcube.portlets.widgets.workspacesharingwidget.server.notifications.NotificationsProducer;
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.AccessTypeComparator;
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.PortalContextInfo;
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.ScopeUtility;
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.UserUtil;
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.WsUtil;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.AllowAccess;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.CredentialModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.ExtendedWorkspaceACL;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.FileModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.ReportAssignmentACL;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.SessionExpiredException;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/**
* The server side implementation of the RPC service.
*
* @author Francesco Mangiacrapa Aug 3, 2015
*/
@SuppressWarnings("serial")
public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements WorkspaceSharingService {
protected static Logger logger = LoggerFactory.getLogger(WorkspaceSharingServiceImpl.class);
/**
* Gets the notification producer.
*
* @param request
* the request
* @return the notification producer
*/
protected NotificationsProducer getNotificationProducer(HttpServletRequest request) {
return WsUtil.getNotificationProducer(request);
}
/**
* Gets the scope util filter.
*
* @return the scope util filter
*/
protected ScopeUtility getScopeUtilFilter() {
return WsUtil.getScopeUtilFilter(this.getThreadLocalRequest());
}
/**
* Checks if is test mode.
*
* @return true, if is test mode
*/
protected boolean isTestMode() {
return !WsUtil.isWithinPortal(); // IS NOT INTO PORTAL
}
/*
* (non-Javadoc)
*
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.
* WorkspaceSharingService#getAllContacts(boolean, boolean)
*/
@Override
public List<InfoContactModel> getAllContacts() throws Exception {
try {
logger.info("Call getAllContacts()");
if (isTestMode()) {
logger.debug("WORKSPACE PORTLET IS IN TEST MODE - RETURN TEST USERS AND GROUPS");
GWTWorkspaceSharingBuilder.getHashTestUsers();
List<InfoContactModel> listContactsModel = new ArrayList<InfoContactModel>();
for (String key : GWTWorkspaceSharingBuilder.getHashTestUsers().keySet()) {
InfoContactModel contact = GWTWorkspaceSharingBuilder.getHashTestUsers().get(key);
listContactsModel.add(contact);
}
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());
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
List<InfoContactModel> listContactsModel = builder.buildGXTListContactsModelFromUserModel(info);
listContactsModel.addAll(builder.getGXTListContactsModelFromVOs(info));
logger.debug("Get all contacts returning a list having size: " + listContactsModel.size());
return listContactsModel;
} catch (Exception e) {
logger.error("Error in getAllContacts(): " + e.getLocalizedMessage(), e);
throw new Exception("Error retrieving all contacts: " + e.getLocalizedMessage(), e);
}
}
/*
* (non-Javadoc)
*
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.
* WorkspaceSharingService#getListUserSharedByFolderSharedId(java.lang.
* String)
*/
@Override
public List<InfoContactModel> getListUserSharedByFolderSharedId(String itemId) throws Exception {
try {
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);
}
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>();
}
} 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>();
}
} else {
logger.info("The folder with id: " + sharedFolder.getId() + " has a invalid metadata!");
return new ArrayList<InfoContactModel>();
}
}
/*
* (non-Javadoc)
*
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.
* WorkspaceSharingService#getOwnerByItemId(java.lang.String)
*/
@Override
public InfoContactModel getOwnerByItemId(String itemId) throws Exception {
try {
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);
}
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();
}
} else {
logger.debug("Item retrieved is null");
return new InfoContactModel();
}
} catch (Exception e) {
logger.error("Error in getOwnerByItemId(): " + e.getLocalizedMessage(), e);
throw new Exception(e.getMessage());
}
}
/**
* Gets the AC ls.
*
* @return the AC ls
* @throws Exception
* the exception
*/
@Override
public List<WorkspaceACL> getACLs() throws Exception {
try {
logger.info("Call getACLs()");
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
return builder.getWorkspaceACLFromAccessType(Arrays.asList(AccessType.values()));
} catch (Exception e) {
logger.error("Error in getACLs(): " + e.getLocalizedMessage(), e);
String error = ConstantsSharing.SERVER_ERROR + " get ACL rules. " + e.getMessage();
throw new Exception(error);
}
}
/*
* (non-Javadoc)
*
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.
* WorkspaceSharingService#getMyLogin()
*/
@Override
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);
}
}
/*
* (non-Javadoc)
*
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.
* WorkspaceSharingService#getFileModelByWorkpaceItemId(java.lang.String)
*/
@Override
public FileModel getFileModelByWorkpaceItemId(String itemId) throws Exception {
try {
logger.info("Call getFileModelByWorkpaceItemId(): [itemId=" + itemId + "]");
if (itemId == null || itemId.isEmpty()) {
logger.error("The item id is invalid: " + itemId);
throw new Exception("Invalid request item id is invalid: " + itemId);
}
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);
}
OpenResolver openResolverForParent = shc.open(itemId);
ItemContainer<Item> parentContainer = openResolverForParent.asItem();
Item parentItem = parentContainer.get();
logger.debug("Retrieved Parent: " + parentItem);
// 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);
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
FileModel parent = null;
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);
} catch (Exception e) {
logger.error("Error in getFileModelByWorkpaceItemId(): " + e.getLocalizedMessage(), e);
String error = ConstantsSharing.SERVER_ERROR + " retrieving the item from workspace. "
+ e.getLocalizedMessage();
throw new Exception(error);
}
}
/*
* (non-Javadoc)
*
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#
* isSessionExpired()
*/
@Override
public boolean isSessionExpired() throws Exception {
return WsUtil.isSessionExpired(this.getThreadLocalRequest());
}
// DEBUG
/**
* Prints the contacts.
*
* @param listContacts
* the list contacts
*/
// 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);
// }
// }
@Override
public boolean shareFolder(String itemId, String name, String description, String parentId,
List<InfoContactModel> listContacts, boolean isNewFolder, WorkspaceACL acl) throws Exception {
if (isSessionExpired())
throw new SessionExpiredException();
try {
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");
}
logger.debug("ListContacts size: " + listContacts.size());
List<String> listLogin = UserUtil.getListLoginByInfoContactModel(listContacts);
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);
}
StorageHubClient shc = new StorageHubClient();
OpenResolver openResolverForItem = shc.open(parentId);
FolderContainer parentFolderContainer = openResolverForItem.asFolder();
folderContainer = parentFolderContainer.newFolder(name, description);
}
FolderItem folderItem = folderContainer.get();
if (folderItem != null) {
if (folderItem.isShared()) {
logger.debug("Folder is shared");
if (folderItem instanceof SharedFolder) {
logger.debug("Folder type: SharedFolder");
Set<String> logins = new HashSet<>(listLogin);
folderContainer.share(logins, getAccessType(acl));
created = true;
} 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);
folderContainer.share(logins, getAccessType(acl));
created = true;
}
} 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");
}
/*
* 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;
} catch (Exception e) {
logger.error("Error in shareFolder(): " + e.getLocalizedMessage(), e);
String error = ConstantsSharing.SERVER_ERROR + " sharing item.";
throw new Exception(error);
}
}
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;
}
}
/*
* (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()");
if (listAlreadySharedContact == null || listAlreadySharedContact.size() == 0)
throw new Exception("Credentials list is null or empty");
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);
}
}
return listContacts;
} catch (Exception e) {
logger.error("Error in getInfoContactModelsFromCredential(): " + e.getLocalizedMessage(), e);
String error = ConstantsSharing.SERVER_ERROR + " retrieving contacts info from user credentials.";
throw new Exception(error);
}
}
/*
* (non-Javadoc)
*
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.
* WorkspaceSharingService#getAdministratorsByFolderId(java.lang.String)
*/
@Override
public List<InfoContactModel> getAdministratorsByFolderId(String itemId) throws Exception {
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 + "]");
}
} catch (Exception e) {
logger.error("Error in getAdministratorsByFolderId(): " + e.getLocalizedMessage(), e);
throw new Exception("Sorry an error occurred on getting Administrators");
}
}
/*
* (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
*/
/**
* Adds the administrators by folder id.
*
* @param itemId
* the folder id
* @param listContactLogins
* the list contact logins
* @return true, if successful
* @throws Exception
* the exception
*/
@Override
public boolean addAdministratorsByFolderId(String itemId, List<String> listContactLogins) throws Exception {
try {
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);
} 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);
}
}
private List<InfoContactModel> retrieveAdminContactsFromACLs(FolderContainer folderContainer) throws Exception {
List<ACL> acls = folderContainer.getAcls();
logger.debug("Retrieved acls: " + acls);
List<String> admins = new ArrayList<>();
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());
}
}
logger.debug("Retrieved admins list: " + admins);
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
return builder.buildGxtInfoContactsFromPortalLogins(admins);
}
// /**
// * 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 + "]");
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);
}
}
} else {
logger.error("The item is not a shared folder: [id=" + itemId + "]");
throw new Exception("The item is not a shared folder");
}
} catch (Exception e) {
logger.error("Error in getACLsForSharedFolderId(): " + e.getLocalizedMessage(), e);
String error = "Sorry an error occurred when getting ACL for item: " + itemId;
throw new Exception(error);
}
}
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;
}
logger.info("Returning first acl with id: " + wsAcls.get(0).getId());
return wsAcls.get(0);
}
@Override
public String getACLsDescriptionForSharedFolderId(String itemId) throws Exception {
try {
logger.info("Call getACLsDescriptionForSharedFolderId(): [itemId=" + itemId + "]");
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;
}
} 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);
}
}
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);
}
@Override
public boolean unSharedFolderByFolderSharedId(String itemId) throws Exception {
if (isSessionExpired())
throw new SessionExpiredException();
try {
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 + "]");
}
boolean shared = false;
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());
shared = true;
} 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 + "]");
}
return shared;
} catch (Exception e) {
logger.error("Error in unSharedFolderByFolderSharedId(): " + e.getLocalizedMessage(), e);
String error = ConstantsSharing.SERVER_ERROR + " unsharing item.";
throw new Exception(error);
}
}
/**
* Gets the user acl for folder id.
*
* @param itemId
* the folder id
* @return the user acl for folder id
* @throws Exception
* the exception
*/
@Override
public List<ExtendedWorkspaceACL> getUserACLForFolderId(String itemId) throws Exception {
try {
logger.info("Call getUserACLForFolderId(): [itemId=" + itemId + "]");
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");
}
} catch (Exception e) {
logger.error("Error in getUserACLForFolderId(): " + e.getLocalizedMessage(), e);
throw new Exception("Error retrieving ACL rules for selected folder: " + e.getLocalizedMessage(), e);
}
}
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;
}
logger.info("Returning first acl with id: " + wsAcls.get(0).getId());
return wsAcls;
}
/**
* Gets ACLs Description For WorkspaceItem ById.
*
* @param itemId
* the folder id
* @return a description of the ACLs
* @throws Exception
* the exception
*/
@Override
public String getACLsDescriptionForWorkspaceItemById(String itemId) throws Exception {
try {
logger.info("Call getACLsDescriptionForWorkspaceItemById(): " + itemId);
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;
} catch (Exception e) {
logger.error("Error in getACLsDescriptionForWorkspaceItemById(): " + e.getLocalizedMessage(), e);
throw new Exception("Error retrieving ACL descriptions for requested item: " + e.getLocalizedMessage(), e);
}
}
/*
* (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);
for (InfoContactModel icm : listContactsModel) {
if (icm.getLogin().compareTo(folderItem.getOwner()) == 0) {
logger.debug("Retrieved: " + icm);
owner = icm;
}
}
logger.debug("Owner not found from user model!");
owner = new InfoContactModel(folderItem.getOwner(), folderItem.getOwner(), folderItem.getOwner(),
false);
} else {
logger.debug("Owner not found from item");
owner = new InfoContactModel();
}
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);
}
logger.info("owner of: " + folderItem.getName() + " is: " + owner);
logger.info("current context user: " + username);
if (owner.getLogin().compareToIgnoreCase(username) == 0) {
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 + "]");
}
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);
}
}
} 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());
}
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);
}
} catch (
Exception e) {
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);
}
}
/*
* (non-Javadoc)
*
* @see
* org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#setACLs(
* java.lang.String, java.util.List, java.lang.String)
*/
/**
* Sets the ac ls.
*
* @param itemId
* the folder id
* @param listLogins
* the list logins
* @param aclType
* the acl type
* @throws Exception
* the exception
*/
@Override
public void setACLs(String itemId, List<String> listLogins, String aclType) throws Exception {
try {
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);
throw new Exception(error);
// 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);
}
}
/**
* Validate acl to user.
*
* @param itemId
* the folder id
* @param listLogins
* the list logins
* @param aclType
* the acl type
* @return the report assignment acl
* @throws Exception
* the exception
*/
@Override
public ReportAssignmentACL validateACLToUser(String itemId, List<String> listLogins, String aclType)
throws Exception {
try {
logger.info("Call validateACLToUser(): [itemId=" + itemId + "]");
if (itemId == null || itemId.isEmpty()) {
String error = "Invalid folder id: [itemId=" + itemId + "]";
logger.error(error);
return null;
}
AccessType settingACL = AccessType.valueOf(aclType);
if (settingACL == null) {
String error = "Invalid acl type requested: [AccessType=" + aclType + "]";
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<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");
}
} catch (Exception e) {
logger.error("Error on setting ACLs", e);
throw new Exception("Sorry, an error occurred when validating ACL assignment, try again later");
}
}
private ReportAssignmentACL createReportAssignementACL(List<ACL> acls, List<String> listLogins,
AccessType settingACL) {
logger.debug("Retrieved acls: " + acls);
List<String> admins = new ArrayList<>();
// 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());
}
}
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);
}
}
}
// 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;
}
}
}
logger.info("Valid logins: ");
for (String username : validLogins) {
logger.info("Set ACL: " + settingACL + " to " + username);
}
reportValidation.setAclType(settingACL.name());
reportValidation.setErrors(errors);
reportValidation.setValidLogins(validLogins);
return reportValidation;
}
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);
}
}
}
/**
* Update acl for vr eby group name.
*
* @param folderId
* the folder id
* @param aclType
* the acl type
* @throws Exception
* the exception
*/
@Override
public void updateACLForVREbyGroupName(String folderId, String aclType) throws Exception {
try {
if (folderId == null)
throw new Exception("Folder id is null");
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());
logger.trace("PortalContextInfo: " + info);
ScopeProvider.instance.set(info.getCurrentScope());
logger.trace("Scope provider set: " + info.getCurrentScope());
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));
}
} else
throw new Exception("Source item is not shared or shared folder");
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);
}
}
/**
* Check notify add item to share.
*
* @param destinationItem
* the destination item
* @param sourceSharedId
* the source shared id
* @param folderDestinationItem
* the folder destination item
*/
// 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");
// }
/**
* 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);
// }
//
// }
}