> aclOwner) {
-
+
String html = "";
-
+
logger.trace("Formatting "+aclOwner.size() +" ACL/s");
-
+
for (ACLType type : aclOwner.keySet()) {
List listLogins = aclOwner.get(type);
-
+
html+=""+type+": ";
html+="";
for (String login : listLogins) {
@@ -508,8 +573,8 @@ public class GWTWorkspaceSharingBuilder {
html+="
";
}
html+="
";
-
-
+
+
return html;
}
diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/WorkspaceSharingServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/WorkspaceSharingServiceImpl.java
index b9fcd9b..ca89377 100644
--- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/WorkspaceSharingServiceImpl.java
+++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/WorkspaceSharingServiceImpl.java
@@ -51,8 +51,8 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
WorkspaceSharingService {
protected static Logger logger = LoggerFactory.getLogger(WorkspaceSharingServiceImpl.class);
-
-
+
+
/**
* Gets the GWT workspace builder.
*
@@ -75,27 +75,27 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
{
return WsUtil.getWorkspace(this.getThreadLocalRequest().getSession());
}
-
+
/**
* Gets the notification producer.
*
* @return the notification producer
*/
protected NotificationsProducer getNotificationProducer(){
-
+
return WsUtil.getNotificationProducer(WsUtil.getAslSession(this.getThreadLocalRequest().getSession()));
}
-
+
/**
* Gets the scope util filter.
*
* @return the scope util filter
*/
protected ScopeUtility getScopeUtilFilter(){
-
+
return WsUtil.getScopeUtilFilter(this.getThreadLocalRequest().getSession());
}
-
+
/**
* Checks if is test mode.
*
@@ -104,19 +104,19 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
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 getAllContacts(boolean readGroupsFromHL, boolean readGroupsFromPortal) throws Exception {
-
+
try {
ASLSession aslSession = WsUtil.getAslSession(this.getThreadLocalRequest().getSession()); //THIS FORCE THE SESSION CREATION
logger.info("Get all contacts");
-
+
GWTWorkspaceSharingBuilder builder = getGWTWorkspaceBuilder();
-
+
if(isTestMode()){
logger.warn("WORKSPACE PORTLET IS IN TEST MODE - RETURN TEST USERS AND GROUPS");
GWTWorkspaceSharingBuilder.getHashTestUsers();
@@ -138,10 +138,10 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
List listContactsModel = builder.buildGXTListContactsModelFromUserModel(userManag.listUsersByGroup(groupId));
*/
List users = UserUtil.getOrganizationUsers(aslSession.getScope());
-
+
if(users==null)
throw new Exception("An error occurred on recovering users from Portal, try again later");
-
+
List listContactsModel = builder.buildGXTListContactsModelFromUserModel(users);
if(readGroupsFromHL){
@@ -154,18 +154,18 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
listContactsModel.addAll(builder.buildGXTListContactsModelFromGcubeGroup(groups));
}else
logger.warn("Read group names from HL, return list null, skipping");
- }
-
+ }
+
if(readGroupsFromPortal){
logger.info("Reading group names as scopes from Infrastructure..");
-
+
PortalContext context = PortalContext.getConfiguration();
logger.info("context.getInfrastructureName(): "+context.getInfrastructureName());
logger.info("aslSession.getGroupName(): "+ aslSession.getGroupName());
logger.info("aslSession.getScope().toString(): "+ aslSession.getScope());
try{
ScopeUtility scopeUtility = new ScopeUtility(aslSession.getScope());
-
+
if(scopeUtility.getVoName()!=null){
logger.info("VO name is not null, trying to calculate List VO");
List lsVOs = WsUtil.getVresFromInfrastructure(context.getInfrastructureName(), scopeUtility.getVoName());
@@ -173,15 +173,15 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
listContactsModel.addAll(builder.buildGXTListContactsModelFromVOs(lsVOs, scopeUtility.getVo()));
}else
logger.warn("VO name is null, skipping list VO "+ aslSession.getGroupName());
-
+
}catch(Exception e){
logger.warn("An error occurred on recovering vo name, skipping list VO "+ aslSession.getGroupName());
}
}
-
+
logger.info("Get all contacts returning a list having size: "+listContactsModel.size());
return listContactsModel;
-
+
} catch (Exception e) {
logger.error("Error in server get all contacts ", e);
// return new ArrayList();
@@ -194,17 +194,17 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
*/
@Override
public List getListUserSharedByFolderSharedId(String folderSharedId) throws Exception{
-
+
logger.info("getListUserSharedByFolderSharedId "+ folderSharedId);
try {
Workspace workspace = getWorkspace();
WorkspaceItem wsItem = workspace.getItem(folderSharedId);
-
+
//TODO CHANGE TO READ ACL FROM SHARED SUBFOLDER
if(isASharedFolder(wsItem, false)){
-
+
WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) workspace.getItem(wsItem.getIdSharedFolder());
GWTWorkspaceSharingBuilder builder = getGWTWorkspaceBuilder();
@@ -215,13 +215,13 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
if(isTestMode())
return builder.buildGxtInfoContactFromPortalLoginTestMode(listPortalLogin);
-
+
return builder.buildGxtInfoContactsFromPortalLogins(listPortalLogin);
-
+
}
else{
logger.info("the item with id: "+folderSharedId+ " is not "+WorkspaceItemType.SHARED_FOLDER);
-
+
//DEBUG
//System.out.println("the item with id: "+folderSharedId+ " is not "+WorkspaceItemType.SHARED_FOLDER);
}
@@ -234,30 +234,30 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
throw new Exception(e.getMessage());
}
}
-
+
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService#getOwnerByItemId(java.lang.String)
*/
@Override
public InfoContactModel getOwnerByItemId(String itemId) throws Exception {
-
+
logger.info("get Owner By ItemId "+ itemId);
try {
-
+
Workspace workspace = getWorkspace();
WorkspaceItem wsItem = workspace.getItem(itemId);
GWTWorkspaceSharingBuilder builder = getGWTWorkspaceBuilder();
-
+
return builder.buildGXTInfoContactModel(wsItem.getOwner());
-
+
} catch (Exception e) {
logger.error("Error in getOwnerByItemId ", e);
throw new Exception(e.getMessage());
}
}
-
+
/**
* Gets the AC ls.
*
@@ -276,7 +276,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
throw new Exception(error);
}
}
-
+
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService#getMyLogin()
*/
@@ -285,7 +285,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
ASLSession asl = WsUtil.getAslSession(this.getThreadLocalRequest().getSession());
return asl.getUsername();
}
-
+
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService#getFileModelByWorkpaceItemId(java.lang.String)
*/
@@ -293,35 +293,35 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
public FileModel getFileModelByWorkpaceItemId(String itemId) throws Exception {
try {
-
+
// System.out.println("Get file model by itemId: "+itemId);
-
+
if(itemId == null || itemId.isEmpty())
- throw new Exception("Identifier is null or empty");
-
+ throw new Exception("Identifier is null or empty");
+
Workspace workspace = getWorkspace();
-
+
logger.info("Get file model by itemId: "+itemId);
-
+
WorkspaceItem wsItem = workspace.getItem(itemId);
-
+
GWTWorkspaceSharingBuilder builder = getGWTWorkspaceBuilder();
// 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);
-
+
logger.info("Getting folder parent");
-
+
WorkspaceFolder folderParent = null;
if(wsItem!=null)
folderParent = wsItem.getParent(); //BUILD PARENT
else
throw new Exception("Workspace item not found");
-
-
+
+
FileModel parent = null;
if(folderParent!=null){
logger.info("Folder parent has id: "+folderParent.getId() + " and name: "+folderParent.getName());
@@ -329,7 +329,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
}
else
logger.info("Folder parent for item: "+wsItem.getId() +" is null");
-
+
//BUILD ITEM
return builder.buildGXTFileModelItem(wsItem, parent);
}catch (ItemNotFoundException e){
@@ -341,7 +341,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
throw new Exception(error);
}
}
-
+
/* (non-Javadoc)
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#isSessionExpired()
*/
@@ -350,7 +350,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
return WsUtil.isSessionExpired(this.getThreadLocalRequest().getSession());
}
-
+
// DEBUG
/**
* Prints the contacts.
@@ -373,25 +373,25 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
}
}
-
+
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService#shareFolder(org.gcube.portlets.widgets.workspacesharingwidget.shared.FileModel, java.util.List, boolean, org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL)
*/
@Override
public boolean shareFolder(FileModel folder, List listContacts, boolean isNewFolder, WorkspaceACL acl) throws Exception {
-
+
if(isSessionExpired())
throw new SessionExpiredException();
-
+
try {
Workspace workspace = getWorkspace();
-
- logger.info("sharing item id: "+ folder.getIdentifier()
- + " name: "+ folder.getName()
+
+ logger.info("sharing item id: "+ folder.getIdentifier()
+ + " name: "+ folder.getName()
// + " parent name: " + folder.getParentFileModel().getName()
+ " listContacts size: " + listContacts.size());
-
+
// //DEBUG
//System.out.println("shareFolder "+ folder.getIdentifier() + " name: "+ folder.getName() + " parent name: " + folder.getParentFileModel().getName() + " listContacts size: " + listContacts.size());
// for (InfoContactModel infoContactModel : listContacts) {
@@ -400,19 +400,19 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
// printContacts(listContacts);
List listLogin = UserUtil.getListLoginByInfoContactModel(listContacts);
-
+
WorkspaceSharedFolder sharedFolder = null;
-
+
List listSharedContact = null;
-
+
boolean sourceFolderIsShared = folder.isShared();
-
+
if(sourceFolderIsShared){ //if source folder is already share... retrieve old list of sharing to notify
listSharedContact = getListUserSharedByFolderSharedId(folder.getIdentifier());
}
if(listLogin.size()>0){
-
+
if(!isNewFolder){
sharedFolder = workspace.shareFolder(listLogin, folder.getIdentifier());
sharedFolder.setDescription(folder.getDescription()); //SET NEW DESCRIPTION
@@ -420,42 +420,42 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
else
sharedFolder = workspace.createSharedFolder(folder.getName(), folder.getDescription(), listLogin, folder.getParentFileModel().getIdentifier());
}
-
+
boolean created = sharedFolder==null?false:true;
if(acl!=null)
setACLs(sharedFolder.getId(), listLogin, acl.getId().toString());
-
+
if(created){
NotificationsProducer np = getNotificationProducer();
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 (InsufficientPrivilegesException e) {
logger.error("Error in shareFolder ", e);
String error = "An error occurred on creating shared folder. "+ e.getMessage();
throw new Exception(error);
-
+
} catch (ItemAlreadyExistException e) {
logger.error("Error in shareFolder ", e);
String error = "An error occurred on creating shared folder. "+ e.getMessage();
throw new Exception(error);
-
+
} catch (WrongDestinationException e) {
logger.error("Error in shareFolder ", e);
String error = "An error occurred on creating shared folder. "+ e.getMessage();
@@ -468,7 +468,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
throw new Exception(error);
}
}
-
+
/**
* Sets the ac ls.
*
@@ -481,34 +481,34 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
try {
if(folderId == null)
- throw new Exception("Folder id is null");
-
+ throw new Exception("Folder id is null");
+
if(listLogins==null || listLogins.size()==0)
throw new Exception("List Logins is null or empty");
-
+
logger.info("Setting ACL for folder id: "+folderId);
logger.info("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)){
+ if(wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)){
//IS ROOT SHARED FOLDER
ite = (WorkspaceSharedFolder) wsItem;
logger.trace("Folder " +ite.getName()+" is a "+WorkspaceSharedFolder.class.getName());
- }else{
- // IS SUB FOLDER OF THE SHARING
+ }else{
+ // IS SUB FOLDER OF THE SHARING
ite = (WorkspaceFolder) wsItem;
logger.trace("Folder " +ite.getName()+" is a "+WorkspaceFolder.class.getName());
}
-
+
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.info("Error in set ACLs", e);
@@ -522,49 +522,55 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
*/
@Override
public List getInfoContactModelsFromCredential(List listAlreadySharedContact) throws Exception {
-
+
if(listAlreadySharedContact==null || listAlreadySharedContact.size()==0)
throw new Exception("Credentials list is null or empty");
-
-
+
+
GWTWorkspaceSharingBuilder builder = getGWTWorkspaceBuilder();
List listContacts = new ArrayList(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;
}
-
+
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService#getAdministratorsByFolderId(java.lang.String)
*/
@Override
public List getAdministratorsByFolderId(String sharedFolderId) throws Exception {
-
+
if(sharedFolderId==null || sharedFolderId.isEmpty())
throw new Exception("Shared Folder id is null or empty");
try {
-
+
Workspace workspace = getWorkspace();
WorkspaceItem item = workspace.getItem(sharedFolderId);
logger.info("Getting administator/s to folder: "+sharedFolderId);
-
+
if(item!=null && item.getType().equals(WorkspaceItemType.SHARED_FOLDER)){
WorkspaceSharedFolder sharedFolder = (WorkspaceSharedFolder) item;
GWTWorkspaceSharingBuilder builder = getGWTWorkspaceBuilder();
List admins = sharedFolder.getAdministrators();
logger.info("Converting "+admins.size()+" administator/s List");
-
+
if(isTestMode())
return builder.buildGxtInfoContactFromPortalLoginTestMode(admins);
-
+
return builder.buildGxtInfoContactsFromPortalLogins(admins);
}else
throw new Exception("The item is null or not instanceof "+WorkspaceItemType.SHARED_FOLDER);
@@ -577,75 +583,37 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
throw new Exception(error);
}
}
-
-
+
+
/**
* DEBUG.
*
* @return the fake groups
*/
private List getFakeGroups(){
-
+
List listContactsModel = new ArrayList();
-
+
PortalContext context = PortalContext.getConfiguration();
System.out.println("context.getInfrastructureName(): "+context.getInfrastructureName());
// System.out.println("context.getVOsAsString(): "+context.getVOsAsString());
List 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;
}
-
- /**
- * The main method.
- *
- * @param args the arguments
- */
- public static void main(String[] args) {
-
- WorkspaceSharingServiceImpl impl = new WorkspaceSharingServiceImpl();
-
- PortalContext context = PortalContext.getConfiguration();
-
- try {
-
- String nameVO = "devsec";
- String vrePath = ConstantsSharing.PATH_SEPARATOR+context.getInfrastructureName() + ConstantsSharing.PATH_SEPARATOR + nameVO + ConstantsSharing.PATH_SEPARATOR;
-
- List lsVOs = WsUtil.getVresFromInfrastructure(context.getInfrastructureName(), nameVO);
- GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
- List groups = builder.buildGXTListContactsModelFromVOs(lsVOs, vrePath);
-
- for (VO vo : lsVOs) {
- System.out.println(vo.getName());
-
- for (VRE vre : vo.getVres()) {
- System.out.println("VRE: "+vre.getName());
- }
- }
-
- for (InfoContactModel infoContactModel : groups) {
- System.out.println(infoContactModel);
- }
-
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService#getACLForSharedItemId(java.lang.String)
- *
+ *
* return the WorkspaceACL of shared folder, null otherwise
*/
@Override
@@ -656,38 +624,38 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
return null;
}
try {
-
+
Workspace workspace = getWorkspace();
WorkspaceItem item = workspace.getItem(itemID);
-
+
if(isASharedFolder(item, false)){ //IS A SHARED FOLDER
-
+
//TODO REMOVE PARENT SHARED FOLDER
// WorkspaceSharedFolder parentSharedFolder = (WorkspaceSharedFolder) workspace.getItem(item.getIdSharedFolder());
WorkspaceSharedFolder sharedFolder = (WorkspaceSharedFolder) item;
GWTWorkspaceSharingBuilder builder = getGWTWorkspaceBuilder();
-
+
logger.info("Read getPrivilege from HL: "+sharedFolder.getACLUser());
List wsAcls = builder.getWorkspaceACLFromACLs(Arrays.asList(sharedFolder.getACLUser()));
-
+
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);
-
+
}else
throw new Exception("The item is null or not a shared folder");
-
+
} catch (Exception e) {
logger.error("Error in server getACLForSharedItemId", e);
String error = "Sorry an error occurred when getting ACL for item: "+itemID;
throw new Exception(error);
}
}
-
+
/**
* Gets the AC ls description for shared folder id.
*
@@ -698,7 +666,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
@Override
public String getACLsDescriptionForSharedFolderId(String folderId) throws Exception{
try {
-
+
WorkspaceFolder wsFolder = getSharedFolderForId(folderId);
GWTWorkspaceSharingBuilder builder = getGWTWorkspaceBuilder();
return builder.getFormattedHtmlACLFromACLs(wsFolder.getACLOwner());
@@ -708,7 +676,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
throw new Exception(error);
}
}
-
+
/**
* Gets the shared folder for id.
*
@@ -717,36 +685,36 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
* @throws Exception the exception
*/
private WorkspaceFolder getSharedFolderForId(String folderId) throws Exception{
-
+
if(folderId == null)
- throw new Exception("Folder id is null");
-
+ throw new Exception("Folder id is null");
+
logger.trace("Get SharedFolderForId: "+folderId);
-
+
Workspace workspace = getWorkspace();
WorkspaceItem wsItem = null;
-
+
try{
wsItem = workspace.getItem(folderId);
}catch(Exception e){
logger.error("Get SharedFolderForId error on folder id: "+folderId, e);
throw new Exception("Sorry, an error has occurred on the server when retrieving item with id: "+folderId+". Try again later!");
}
-
+
if(isASharedFolder(wsItem, false)){
logger.trace("Get SharedFolderForId: folder id "+folderId+" is shared");
-
+
//TODO REMOVE wsItem.getIdSharedFolder()
// WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) workspace.getItem(wsItem.getIdSharedFolder());
WorkspaceFolder wsFolder = (WorkspaceFolder) workspace.getItem(wsItem.getId());
-
+
if(wsFolder!=null){
logger.info("Get SharedFolderForId return name: "+wsFolder.getName());
return wsFolder;
-
+
//TODO USE THIS
// return (WorkspaceFolder) wsItem;
-
+
}else{
logger.warn("Source item is not a shared folder, throw exception");
throw new Exception("Source item is not a shared folder");
@@ -756,7 +724,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
throw new Exception("Source item is null or not shared for id: "+folderId);
}
}
-
+
/**
* Checks if is a shared folder.
*
@@ -764,24 +732,24 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
* @param asRoot true check if itemID is root, not otherwise
* @return true, if is a shared folder
*/
-
+
public boolean isASharedFolder(String itemID, boolean asRoot){
try {
-
+
if(itemID==null)
throw new Exception("ItemId is null");
-
+
Workspace workspace = getWorkspace();
WorkspaceItem item = workspace.getItem(itemID);
return isASharedFolder(item, asRoot);
-
+
}catch(Exception e){
logger.error("Error in server isASharedFolder", e);
return false;
}
}
-
+
/**
* Checks if is a shared folder.
*
@@ -791,18 +759,95 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
*/
public boolean isASharedFolder(WorkspaceItem item, boolean asRoot){
try {
-
+
if(item!=null && item.isFolder() && item.isShared()){ //IS A SHARED SUB-FOLDER
if(asRoot)
return item.getType().equals(WorkspaceItemType.SHARED_FOLDER); //IS ROOT?
-
+
return true;
}
-
+
return false;
}catch(Exception e){
logger.error("Error in server isASharedFolder", e);
return false;
}
}
+
+ /**
+ * Check list share name for group.
+ *
+ * @param listAlreadySharedContact the list already shared contact
+ * @return the list
+ */
+ /*private static List checkShareNameForGroup(List listAlreadySharedContact){
+
+ if(listAlreadySharedContact==null)
+ return null;
+
+ for (CredentialModel credentialModel : listAlreadySharedContact) {
+ if(credentialModel.isGroup() && (credentialModel.getName()==null || credentialModel.getName().isEmpty())){
+
+ //RECOVERING VRE NAME
+ if(credentialModel.getLogin().contains("/")){
+
+ int start = credentialModel.getLogin().lastIndexOf("/");
+ int end = credentialModel.getLogin().length();
+
+ if(start lsVOs = WsUtil.getVresFromInfrastructure(root, nameVO);
+ GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
+ List groups = builder.buildGXTListContactsModelFromVOs(lsVOs, vrePath);
+
+ for (VO vo : lsVOs) {
+ System.out.println(vo.getName());
+
+ for (VRE vre : vo.getVres()) {
+ System.out.println("VRE: "+vre.getName());
+ }
+ }
+
+// for (InfoContactModel infoContactModel : groups) {
+// System.out.println(infoContactModel);
+// }
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }*/
+
+ /*List list = new ArrayList();
+ list.add(new CredentialModel(null, "test.user", false));
+ list.add(new CredentialModel(null, "/gcube/devsec/devVRE", true));
+ list.add(new CredentialModel(null, "francesco.mangiacrapa", false));
+ list.add(new CredentialModel(null, "devVRE", true));
+ list.add(new CredentialModel(null, "/gcube/devsec/NextNext", true));
+
+ list = checkListShareNameForGroup(list);
+
+ for (CredentialModel credentialModel : list) {
+ System.out.println(credentialModel);
+ }*/
+ }
}
diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/util/UserUtil.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/util/UserUtil.java
index b04ffcf..a6f8735 100644
--- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/util/UserUtil.java
+++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/util/UserUtil.java
@@ -17,8 +17,6 @@ import org.gcube.vomanagement.usermanagement.model.UserModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
-
/**
* The Class UserUtil.
*
@@ -26,11 +24,11 @@ import org.slf4j.LoggerFactory;
* Aug 3, 2015
*/
public class UserUtil {
-
+
static UserManager um = new LiferayUserManager();
protected static Logger logger = LoggerFactory.getLogger(UserUtil.class);
-
+
/**
* Gets the user full name.
*
@@ -39,22 +37,22 @@ public class UserUtil {
*/
public static String getUserFullName(String portalLogin){
// return user.getPortalLogin(); //for testing in eclipse
-
+
// logger.trace("Finding full name for: "+portalLogin);
-
+
if(portalLogin==null)
return "";
-
+
logger.info("Get user full name for: "+portalLogin);
logger.info("Into portal: "+WsUtil.isWithinPortal());
- if ((portalLogin.compareTo(WsUtil.TEST_USER) != 0) && (WsUtil.isWithinPortal())) { //skip test.user
-
+ if (portalLogin.compareTo(WsUtil.TEST_USER) != 0 && WsUtil.isWithinPortal()) { //skip test.user
+
UserModel curr = null;
-
+
try {
try {
curr = um.getUserByScreenName(portalLogin);
-
+
} catch (UserManagementSystemException e) {
logger.error("An error occurred in getUserFullName "+e,e);
} catch (UserRetrievalFault e) {
@@ -67,24 +65,22 @@ public class UserUtil {
logger.warn("Return portal login "+portalLogin);
return portalLogin;
}
-
+
if (curr != null){
-
// logger.trace("Return "+curr.getFullname() +" full name for: "+portalLogin);
return curr.getFullname();
-
}
}else{
-
- logger.info("Return "+WsUtil.TEST_USER_FULL_NAME +" full name for: "+portalLogin);
- return WsUtil.TEST_USER_FULL_NAME;
+
+ logger.info("We are out of portal, returning login portalLogin "+portalLogin+ "as full name");
+ return portalLogin;
}
-
+
logger.info("Return portal login as full name for: "+portalLogin);
return portalLogin;
}
-
-
+
+
/**
* Gets the organization users.
*
@@ -116,7 +112,7 @@ public class UserUtil {
}
return null;
}
-
+
/**
* Gets the list login by info contact model.
*
@@ -124,16 +120,16 @@ public class UserUtil {
* @return the list login by info contact model
*/
public static List getListLoginByInfoContactModel(List listContacts){
-
+
List listUsers = new ArrayList();
-
+
for (InfoContactModel infoContactModel : listContacts) {
listUsers.add(infoContactModel.getLogin());
}
-
+
return listUsers;
}
-
+
/**
* Separate users names to comma.
*
@@ -141,20 +137,20 @@ public class UserUtil {
* @return the string
*/
public static String separateUsersNamesToComma(List listContacts){
-
+
String users = "";
-
+
for (int i = 0; i < listContacts.size()-1; i++) {
users+= listContacts.get(i).getName() + ", ";
}
-
+
if(listContacts.size()>1)
users += listContacts.get(listContacts.size()-1).getName();
-
+
return users;
}
-
-
+
+
/**
* Separate full name to comma for portal login.
*
@@ -162,17 +158,17 @@ public class UserUtil {
* @return the string
*/
public static String separateFullNameToCommaForPortalLogin(List listLogin){
-
+
String users = "";
-
+
for (int i = 0; i < listLogin.size()-1; i++) {
users+= getUserFullName(listLogin.get(i)) + ", ";
}
-
+
if(listLogin.size()>1)
users += getUserFullName(listLogin.get(listLogin.size()-1));
-
+
return users;
}
-
+
}
diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/util/WsUtil.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/util/WsUtil.java
index 978a921..83c4897 100644
--- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/util/WsUtil.java
+++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/util/WsUtil.java
@@ -1,5 +1,5 @@
/**
- *
+ *
*/
package org.gcube.portlets.widgets.workspacesharingwidget.server.util;
@@ -32,7 +32,7 @@ import com.liferay.portal.service.UserLocalServiceUtil;
/**
- *
+ *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Feb 18, 2014
*
@@ -45,11 +45,8 @@ public class WsUtil {
public static final String NOTIFICATION_PRODUCER = "NOTIFICATION_SHARING_PRODUCER";
public static final String WORKSPACE_SCOPE_UTIL = "WORKSPACE_SHARING_SCOPE_UTIL";
public static final String NOTIFICATION_PORTLET_CLASS_ID = "org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl"; //USE THE SAME OF WORKSPACE
-
-
// public static final String TEST_SCOPE = "/gcube/devsec";
// public static final String TEST_USER = "pasquale.pagano";
-
public static final String TEST_SCOPE = "/gcube/devsec";
// public static final String TEST_USER = "federico.defaveri";
// public static final String TEST_USER = "massimiliano.assante";
@@ -60,42 +57,38 @@ public class WsUtil {
public static final String TEST_USER = "test.user";
// public static final String TEST_USER = "antonio.gioia";
public static final String TEST_USER_FULL_NAME = "Test User";
-
-
protected static Logger logger = LoggerFactory.getLogger(WsUtil.class);
-
// public static boolean withoutPortal = false;
-
+
/**
- *
+ *
* @return true if you're running into the portal, false if in development
*/
public static boolean isWithinPortal() {
try {
UserLocalServiceUtil.getService();
return true;
- }
- catch (Exception ex) {
+ }
+ catch (Exception ex) {
logger.info("Development Mode ON");
return false;
- }
+ }
}
-
+
public static ASLSession getAslSession(HttpSession httpSession)
{
String sessionID = httpSession.getId();
String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE);
ASLSession session;
-
+
if (user == null) {
-
+
/*USE ANOTHER ACCOUNT (OTHERWHISE BY TEST_USER) FOR RUNNING
* COMMENT THIS IN DEVELOP ENVIROMENT (UNCOMMENT IN PRODUCTION)*/
user=TEST_USER;
-
+
//UNCOMMENT THIS IN DEVELOP ENVIROMENT
// user = "francesco.mangiacrapa";
-
logger.warn("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND - PORTLETS STARTING WITH FOLLOWING SETTINGS:");
logger.warn("session id: "+sessionID);
logger.warn("TEST_USER: "+user);
@@ -103,38 +96,30 @@ public class WsUtil {
logger.warn("USERNAME_ATTRIBUTE: "+USERNAME_ATTRIBUTE);
session = SessionManager.getInstance().getASLSession(sessionID, user);
session.setScope(TEST_SCOPE);
-
//MANDATORY FOR SOCIAL LIBRARY
session.setUserAvatarId(user + "Avatar");
session.setUserFullName(TEST_USER_FULL_NAME);
session.setUserEmailAddress(user + "@mail.test");
-
//SET HTTP SESSION ATTRIBUTE
httpSession.setAttribute(USERNAME_ATTRIBUTE, user);
-
// withoutPortal = true;
-
return session;
-
+
}else if(user.compareToIgnoreCase(TEST_USER)==0){
-
// withoutPortal = true;
-
//COMMENT THIS IN PRODUCTION ENVIROMENT
// }else if(user.compareToIgnoreCase("francesco.mangiacrapa")==0){
-//
// withoutPortal = false;
// END UNCOMMENT
}else{
-
// withoutPortal = false;
}
-
+
return SessionManager.getInstance().getASLSession(sessionID, user);
}
-
+
/**
- *
+ *
* @param httpSession
* @return true if current username into ASL session is WsUtil.TEST_USER, false otherwise
* @throws Exception
@@ -144,23 +129,23 @@ public class WsUtil {
//READING USERNAME FROM ASL SESSION
String userUsername = getAslSession(httpSession).getUsername();
boolean isTestUser = userUsername.compareTo(WsUtil.TEST_USER)==0;
-
+
//TODO UNCOMMENT THIS FOR RELEASE
logger.info("Is "+WsUtil.TEST_USER+" test user? "+isTestUser);
-
+
if(isTestUser){
logger.error("workspace session is expired! username is: "+WsUtil.TEST_USER);
return true; //is TEST_USER, session is expired
}
logger.info("workspace session is valid! current username is: "+userUsername);
-
+
return false;
-
+
}
-
+
/**
- *
+ *
* @param infrastructure the infrastructure name
* @param startScopes the starting scopes
* @return an arraylist of VO containing their child VREs
@@ -188,30 +173,30 @@ public class WsUtil {
}
return toReturn;
}
-
+
public static Workspace getWorkspace(final HttpSession httpSession) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException
{
-
+
logger.info("Get Workspace");
final ASLSession session = getAslSession(httpSession);
logger.info("ASLSession scope: "+session.getScope() + " username: "+session.getUsername());
ScopeProvider.instance.set(session.getScope());
logger.info("Scope provider instancied");
-
+
Workspace workspace = HomeLibrary.getUserWorkspace(session.getUsername());
if (session.getAttribute(WORKSPACEBUILDER_ATTRIBUTE) == null)
{
logger.info("Initializing the workspace area builder");
-
+
GWTWorkspaceSharingBuilder builder = new GWTWorkspaceSharingBuilder();
-
- //ADDED 03/09/2013
+
+ //ADDED 03/09/2013
//TODO IS GROUP?
builder.setUserLogged(new InfoContactModel(session.getUsername(), session.getUsername(), session.getUserFullName(), false));
-
+
session.setAttribute(WORKSPACEBUILDER_ATTRIBUTE, builder);
}
@@ -221,9 +206,9 @@ public class WsUtil {
public static NotificationsManager getNotificationManager(ASLSession session)
{
-
+
NotificationsManager notifMng = (NotificationsManager) session.getAttribute(NOTIFICATION_MANAGER);
-
+
if (notifMng == null) {
try{
logger.info("Create new NotificationsManager for user: "+session.getUsername());
@@ -234,62 +219,62 @@ public class WsUtil {
logger.error("An error occurred instancing ApplicationNotificationsManager for user: "+session.getUsername(),e);
}
}
-
+
return notifMng;
}
-
+
public static NotificationsProducer getNotificationProducer(ASLSession session)
{
-
+
NotificationsProducer notifProducer = (NotificationsProducer) session.getAttribute(NOTIFICATION_PRODUCER);
-
+
if (notifProducer == null) {
logger.info("Create new Notification Producer for user: "+session.getUsername());
notifProducer = new NotificationsProducer(session);
session.setAttribute(NOTIFICATION_PRODUCER, notifProducer);
}
-
+
return notifProducer;
}
public static String getUserId(HttpSession httpSession) {
-
+
ASLSession session = getAslSession(httpSession);
-
+
return session.getUsername();
}
-
+
public static boolean isVRE(ASLSession session){
-
+
String currentScope = session.getScopeName();
-
+
int slashCount = StringUtils.countMatches(currentScope, "/");
-
+
if(slashCount < 3){
logger.info("currentScope is not VRE");
return false;
}
-
+
logger.info("currentScope is VRE");
return true;
-
+
}
-
+
public static ScopeUtility getScopeUtilFilter(HttpSession httpSession){
-
+
ASLSession session = getAslSession(httpSession);
ScopeUtility scopeUtil = null;
try{
scopeUtil = (ScopeUtility) session.getAttribute(WsUtil.WORKSPACE_SCOPE_UTIL);
-
+
if(scopeUtil==null){
scopeUtil = new ScopeUtility(session.getScopeName());
-
+
}
}catch (Exception e) {
logger.error("an error occurred in getscope filter ",e);
}
-
+
return scopeUtil;
}
@@ -300,16 +285,16 @@ public class WsUtil {
public static GWTWorkspaceSharingBuilder getGWTWorkspaceSharingBuilder(HttpSession httpSession) {
ASLSession session = getAslSession(httpSession);
GWTWorkspaceSharingBuilder builder = null;
-
+
try{
builder = (GWTWorkspaceSharingBuilder) session.getAttribute(WsUtil.WORKSPACEBUILDER_ATTRIBUTE);
-
+
if(builder==null)
return new GWTWorkspaceSharingBuilder();
}catch (Exception e) {
logger.error("an error occurred in get builder ",e);
}
-
+
return new GWTWorkspaceSharingBuilder();
}
}
diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/shared/CredentialModel.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/shared/CredentialModel.java
index 3222389..04ae425 100644
--- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/shared/CredentialModel.java
+++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/shared/CredentialModel.java
@@ -1,61 +1,141 @@
/**
- *
+ *
*/
package org.gcube.portlets.widgets.workspacesharingwidget.shared;
import java.io.Serializable;
+
/**
- * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
- * @Mar 3, 2014
+ * The Class CredentialModel.
*
+ * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
+ * Apr 14, 2016
*/
public class CredentialModel implements Serializable{
-
+
/**
- *
+ *
*/
- private static final long serialVersionUID = -4265499048265553603L;
-
+ private static final long serialVersionUID = 5312392409290548813L;
+
private String id;
private String login;
private boolean isGroup;
-
- public CredentialModel(){
-
- }
+ private String name;
+
/**
- * @param id
- * @param login
- * @param isGroup
+ * Instantiates a new credential model.
+ */
+ public CredentialModel(){
+
+ }
+
+ /**
+ * Instantiates a new credential model.
+ *
+ * @param id the id
+ * @param login the login
+ * @param isGroup the is group
*/
public CredentialModel(String id, String login, boolean isGroup) {
this.id = id;
this.login = login;
this.isGroup = isGroup;
}
-
+
+ /**
+ * Instantiates a new credential model.
+ *
+ * @param id the id
+ * @param login the login
+ * @param name the name
+ * @param isGroup the is group
+ */
+ public CredentialModel(String id, String login, String name, boolean isGroup) {
+ this(id,login,isGroup);
+ this.name = name;
+ }
+
+ /**
+ * Gets the name.
+ *
+ * @return the name
+ */
+ public String getName() {
+
+ return name;
+ }
+
+ /**
+ * Sets the name.
+ *
+ * @param name the name to set
+ */
+ public void setName(String name) {
+
+ this.name = name;
+ }
+
+ /**
+ * Gets the id.
+ *
+ * @return the id
+ */
public String getId() {
return id;
}
+
+ /**
+ * Gets the login.
+ *
+ * @return the login
+ */
public String getLogin() {
return login;
}
+
+ /**
+ * Checks if is group.
+ *
+ * @return true, if is group
+ */
public boolean isGroup() {
return isGroup;
}
+
+ /**
+ * Sets the id.
+ *
+ * @param id the new id
+ */
public void setId(String id) {
this.id = id;
}
+
+ /**
+ * Sets the login.
+ *
+ * @param login the new login
+ */
public void setLogin(String login) {
this.login = login;
}
+
+ /**
+ * Sets the group.
+ *
+ * @param isGroup the new group
+ */
public void setGroup(boolean isGroup) {
this.isGroup = isGroup;
}
-
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
@Override
public String toString() {
+
StringBuilder builder = new StringBuilder();
builder.append("CredentialModel [id=");
builder.append(id);
@@ -63,8 +143,9 @@ public class CredentialModel implements Serializable{
builder.append(login);
builder.append(", isGroup=");
builder.append(isGroup);
+ builder.append(", name=");
+ builder.append(name);
builder.append("]");
return builder.toString();
}
-
}