diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java b/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java index 5426e1f..448b1ac 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java @@ -141,6 +141,7 @@ import org.gcube.portlets.user.workspace.client.workspace.folder.item.GWTExterna import org.gcube.portlets.user.workspace.client.workspace.folder.item.GWTExternalUrl; import org.gcube.portlets.user.workspace.client.workspace.folder.item.gcube.GWTImageDocument; import org.gcube.portlets.user.workspace.client.workspace.folder.item.gcube.GWTUrlDocument; +import org.gcube.portlets.user.workspace.shared.ReportAssignmentACL; import org.gcube.portlets.user.workspace.shared.SessionExpiredException; import org.gcube.portlets.user.workspace.shared.UserBean; import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField; @@ -2213,37 +2214,63 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt final List logins = new ArrayList(targets.size()); - String names = ""; for (org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel infoContactModel : targets) { GWT.log(infoContactModel.toString()); logins.add(infoContactModel.getLogin()); - String name = infoContactModel.getName()!=null? infoContactModel.getName():infoContactModel.getLogin(); - names+="
  • "+name +";
  • "; } - -// GWT.log("names "+names); - - String msg = "Setting permission '"+multiDragContact.getSelectedAcl().getLabel() +"' for: confirm?"; - - MessageBoxConfirm confirm = new MessageBoxConfirm("Setting new permissions to "+file.getName() +"?", msg); - - confirm.getMessageBoxConfirm().addCallback(new Listener() { - public void handleEvent(MessageBoxEvent be) { + rpcWorkspaceService.validateACLToUser(file.getIdentifier(), logins, multiDragContact.getSelectedAclID(), new AsyncCallback() { - //IF NOT CANCELLED - String clickedButton = be.getButtonClicked().getItemId(); - if(clickedButton.equals(Dialog.YES)){ -// doAddAdministratorToFolderId(file, logins); - setACLToFolderId(file.getIdentifier(), logins, multiDragContact.getSelectedAclID()); - multidrag.hide(); - }else if(clickedButton.equals(Dialog.CANCEL)){ - multidrag.hide(); + @Override + public void onFailure(Throwable caught) { + new MessageBoxAlert("Error", caught.getMessage(), null); + + } + + @Override + public void onSuccess(ReportAssignmentACL result) { + + String msg = ""; + + if(result.getErrors().size()>0){ + for (String error : result.getErrors()){ + msg+="
  • "+error +";

  • "; + + } + + new MessageBoxAlert("Warning!!", msg, null); + return; } + String names = ""; + for (String name : result.getValidLogins()) { +// String name = infoContactModel.getName()!=null? infoContactModel.getName():infoContactModel.getLogin(); + names+="
  • "+name +";
  • "; + } + + msg+= "Setting permission '"+multiDragContact.getSelectedAcl().getLabel() +"' for:
      "+names+"
    confirm?"; + + MessageBoxConfirm confirm = new MessageBoxConfirm("Setting new permissions to "+file.getName() +"?", msg); + confirm.getMessageBoxConfirm().addCallback(new Listener() { + + public void handleEvent(MessageBoxEvent be) { + + //IF NOT CANCELLED + String clickedButton = be.getButtonClicked().getItemId(); + if(clickedButton.equals(Dialog.YES)){ +// doAddAdministratorToFolderId(file, logins); + setACLToFolderId(file.getIdentifier(), logins, multiDragContact.getSelectedAclID()); + multidrag.hide(); + }else if(clickedButton.equals(Dialog.CANCEL)){ + multidrag.hide(); + } + + } + }); + } }); - + } } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceService.java b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceService.java index 80c85ce..ba7b024 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceService.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceService.java @@ -17,6 +17,7 @@ import org.gcube.portlets.user.workspace.client.model.SmartFolderModel; import org.gcube.portlets.user.workspace.client.model.SubTree; import org.gcube.portlets.user.workspace.client.workspace.GWTWorkspaceItem; import org.gcube.portlets.user.workspace.shared.ExtendedWorkspaceACL; +import org.gcube.portlets.user.workspace.shared.ReportAssignmentACL; import org.gcube.portlets.user.workspace.shared.SessionExpiredException; import org.gcube.portlets.user.workspace.shared.TrashContent; import org.gcube.portlets.user.workspace.shared.TrashOperationContent; @@ -281,4 +282,14 @@ public interface GWTWorkspaceService extends RemoteService{ */ String getItemDescriptionById(String identifier) throws Exception; + /** + * @param folderId + * @param listLogins + * @param aclType + * @return + * @throws Exception + */ + ReportAssignmentACL validateACLToUser(String folderId, + List listLogins, String aclType) throws Exception; + } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java index cdc5052..afbb22f 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java @@ -17,6 +17,7 @@ import org.gcube.portlets.user.workspace.client.model.SmartFolderModel; import org.gcube.portlets.user.workspace.client.model.SubTree; import org.gcube.portlets.user.workspace.client.workspace.GWTWorkspaceItem; import org.gcube.portlets.user.workspace.shared.ExtendedWorkspaceACL; +import org.gcube.portlets.user.workspace.shared.ReportAssignmentACL; import org.gcube.portlets.user.workspace.shared.TrashContent; import org.gcube.portlets.user.workspace.shared.TrashOperationContent; import org.gcube.portlets.user.workspace.shared.UserBean; @@ -226,4 +227,7 @@ public interface GWTWorkspaceServiceAsync { void getItemDescriptionById(String identifier, AsyncCallback callback); + void validateACLToUser(String folderId, List listLogins, + String aclType, AsyncCallback callback); + } diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java index c8c8bcd..34c4d2a 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java @@ -921,6 +921,7 @@ public class GWTWorkspaceBuilder { return new InfoContactModel(portalLogin, portalLogin, UserUtil.getUserFullName(portalLogin), false); } + /** * Used in test mode diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java index 582b5b1..fe03727 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java @@ -62,6 +62,7 @@ import org.gcube.portlets.user.workspace.server.notifications.NotificationsProdu import org.gcube.portlets.user.workspace.server.notifications.NotificationsUtil; import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameter; import org.gcube.portlets.user.workspace.server.shortener.UrlShortener; +import org.gcube.portlets.user.workspace.server.util.AclTypeComparator; import org.gcube.portlets.user.workspace.server.util.DiffereceBeetweenInfoContactModel; import org.gcube.portlets.user.workspace.server.util.HttpRequestUtil; import org.gcube.portlets.user.workspace.server.util.StringUtil; @@ -70,6 +71,7 @@ import org.gcube.portlets.user.workspace.server.util.WsUtil; import org.gcube.portlets.user.workspace.server.util.resource.PropertySpecialFolderReader; import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter; import org.gcube.portlets.user.workspace.shared.ExtendedWorkspaceACL; +import org.gcube.portlets.user.workspace.shared.ReportAssignmentACL; import org.gcube.portlets.user.workspace.shared.SessionExpiredException; import org.gcube.portlets.user.workspace.shared.TrashContent; import org.gcube.portlets.user.workspace.shared.TrashOperationContent; @@ -92,8 +94,9 @@ import com.liferay.portal.service.UserLocalServiceUtil; /** - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * The Class GWTWorkspaceServiceImpl. * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it */ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWTWorkspaceService{ @@ -113,46 +116,89 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT protected Logger workspaceLogger = Logger.getLogger(GWTWorkspaceServiceImpl.class); + /** + * Gets the GWT workspace builder. + * + * @return the GWT workspace builder + */ protected GWTWorkspaceBuilder getGWTWorkspaceBuilder() { return WsUtil.getGWTWorkspaceBuilder(this.getThreadLocalRequest().getSession()); } + /** + * Gets the workspace. + * + * @return the workspace + * @throws InternalErrorException the internal error exception + * @throws HomeNotFoundException the home not found exception + * @throws WorkspaceFolderNotFoundException the workspace folder not found exception + */ protected Workspace getWorkspace() throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException { 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 ScopeUtilFilter getScopeUtilFilter(){ return WsUtil.getScopeUtilFilter(this.getThreadLocalRequest().getSession()); } + /** + * Checks if is test mode. + * + * @return true, if is test mode + */ protected boolean isTestMode(){ return !WsUtil.isWithinPortal(); } + /** + * Gets the url shortener. + * + * @return the url shortener + */ protected UrlShortener getUrlShortener() { return WsUtil.getUrlShortener(this.getThreadLocalRequest().getSession()); } + /** + * Gets the uri resolver. + * + * @return the uri resolver + */ protected UriResolverReaderParameter getUriResolver() { return WsUtil.getUriResolver(this.getThreadLocalRequest().getSession()); } + /** + * Gets the property special folder reader. + * + * @return the property special folder reader + */ protected PropertySpecialFolderReader getPropertySpecialFolderReader() { String absolutePathProperty = getSpecialFolderPath(); return WsUtil.getPropertySpecialFolderReader(this.getThreadLocalRequest().getSession(),absolutePathProperty); } /** - * - * @param type the type to look for + * Gets the special folder path. + * * @return the Category if there is correspondance, null otherwise */ private String getSpecialFolderPath() { @@ -163,6 +209,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getRootForTree() + */ @Override public FolderModel getRootForTree() throws Exception { @@ -196,6 +245,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getRootForTree(java.lang.String) + */ @Override public FolderModel getRootForTree(String scopeId) throws Exception { @@ -236,6 +288,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getItemsBySearchName(java.lang.String) + */ @Override public List getItemsBySearchName(String text) throws Exception { @@ -266,6 +321,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getFolderChildren(org.gcube.portlets.user.workspace.client.model.FolderModel) + */ @Override public List getFolderChildren(FolderModel folder) throws Exception, SessionExpiredException{ @@ -323,6 +381,11 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /** + * Gets the name for special folder. + * + * @return the name for special folder + */ private String getNameForSpecialFolder(){ PropertySpecialFolderReader sfReader = getPropertySpecialFolderReader(); @@ -338,6 +401,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getFolderChildrenForFileGrid(org.gcube.portlets.user.workspace.client.model.FileModel) + */ @Override public List getFolderChildrenForFileGrid(FileModel folder) throws Exception, SessionExpiredException { @@ -404,6 +470,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getFolderChildrenForFileGridById(java.lang.String) + */ @Override public List getFolderChildrenForFileGridById(String folderId) throws Exception, SessionExpiredException { @@ -483,6 +552,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getItemForFileGrid(java.lang.String) + */ @Override public FileGridModel getItemForFileGrid(String itemId) throws Exception { @@ -522,6 +594,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#moveItem(java.lang.String, java.lang.String) + */ @Override public Boolean moveItem(String itemId, String destinationId) throws Exception { workspaceLogger.trace("moveItem itemId: "+itemId+" destination: "+destinationId); @@ -584,6 +659,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#moveItems(java.util.List, java.lang.String) + */ @Override public Boolean moveItems(List ids, String destinationId) throws Exception { workspaceLogger.trace("moveItems "+ids.size()+ ", destination: "+destinationId); @@ -656,6 +734,13 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /** + * 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) { workspaceLogger.trace("checkNotifyAddItemToShare"); @@ -709,6 +794,14 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /** + * 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) { workspaceLogger.trace("checkNotifyMoveItemFromShare:"); @@ -763,6 +856,11 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } //DEBUG + /** + * Prints the contacts. + * + * @param listContacts the list contacts + */ private void printContacts(List listContacts){ workspaceLogger.trace("Contacts:"); @@ -773,6 +871,11 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT //DEBUG + /** + * Prints the list. + * + * @param list the list + */ private void printList(List list){ for (String string : list) { @@ -780,6 +883,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#removeItem(java.lang.String) + */ @Override public Boolean removeItem(String itemId) throws Exception { @@ -831,6 +937,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#renameItem(java.lang.String, java.lang.String, java.lang.String) + */ @Override public Boolean renameItem(String itemId, String newName, String previousName) throws Exception { @@ -896,6 +1005,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#createFolder(java.lang.String, java.lang.String, org.gcube.portlets.user.workspace.client.model.FileModel) + */ @Override public FolderModel createFolder(String nameFolder, String description, FileModel parent) throws Exception { @@ -934,6 +1046,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getDetailsFile(org.gcube.portlets.user.workspace.client.model.FileModel) + */ @Override public FileDetailsModel getDetailsFile(FileModel folder) throws Exception { @@ -958,6 +1073,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getChildrenSubTreeToRootByIdentifier(java.lang.String) + */ @Override public ArrayList getChildrenSubTreeToRootByIdentifier(String itemIdentifier) throws Exception { @@ -984,6 +1102,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT return listSubTree; } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getSmartFolderResultsByCategory(java.lang.String) + */ @Override public List getSmartFolderResultsByCategory(String category) throws Exception { @@ -1051,6 +1172,14 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /** + * Gets the lists children by parents. + * + * @param listSubTree the list sub tree + * @param item the item + * @return the lists children by parents + * @throws Exception the exception + */ private void getListsChildrenByParents(ArrayList listSubTree, WorkspaceItem item) throws Exception{ if(item==null || item.getParent()==null){ @@ -1069,6 +1198,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT getListsChildrenByParents(listSubTree, item.getParent()); } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#createSmartFolder(java.lang.String, java.lang.String, java.lang.String) + */ @Override public SmartFolderModel createSmartFolder(String name, String description, String query) throws Exception { @@ -1097,6 +1229,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#removeSmartFolder(java.lang.String, java.lang.String) + */ @Override public Boolean removeSmartFolder(String itemId, String name) throws Exception { @@ -1119,6 +1254,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getAllSmartFolders() + */ @Override public List getAllSmartFolders() throws Exception{ @@ -1144,6 +1282,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getSmartFolderResultsById(java.lang.String) + */ @Override public List getSmartFolderResultsById(String folderId) throws Exception { @@ -1172,6 +1313,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getImageById(java.lang.String, boolean, boolean) + */ @Override public GWTWorkspaceItem getImageById(String identifier, boolean isInteralImage, boolean fullDetails) throws Exception { @@ -1198,6 +1342,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getTimeSeriesById(java.lang.String) + */ @Override public GWTWorkspaceItem getTimeSeriesById(String identifier) throws Exception { @@ -1224,6 +1371,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getUrlById(java.lang.String, boolean, boolean) + */ @Override public GWTWorkspaceItem getUrlById(String identifier, boolean isInternalUrl, boolean fullDetails) throws Exception { @@ -1254,6 +1404,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#createExternalUrl(org.gcube.portlets.user.workspace.client.model.FileModel, java.lang.String, java.lang.String, java.lang.String) + */ @Override public FileModel createExternalUrl(FileModel parentFileModel, String name, String description, String url) throws Exception { @@ -1290,6 +1443,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getURLFromApplicationProfile(java.lang.String) + */ @Override public String getURLFromApplicationProfile(String oid) throws Exception { @@ -1340,6 +1496,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT return urlPortlet; } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#setValueInSession(java.lang.String, java.lang.String) + */ @Override public void setValueInSession(String name, String value) throws Exception { @@ -1358,6 +1517,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getAllScope() + */ @Override public List getAllScope() throws Exception { @@ -1389,6 +1551,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getAllContacts() + */ @Override public List getAllContacts() throws Exception { @@ -1480,7 +1645,10 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT // } // } - @Override + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#sendToById(java.util.List, java.util.List, java.lang.String, java.lang.String) + */ +@Override public boolean sendToById(List listContactsId, List listAttachmentsId, String subject, String body) throws Exception { try { @@ -1509,6 +1677,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getAllMessagesSent() + */ @Override public List getAllMessagesSent() throws Exception { try { @@ -1530,6 +1701,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getAllMessagesReceived() + */ @Override public List getAllMessagesReceived() throws Exception { @@ -1552,6 +1726,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getMessageById(java.lang.String, java.lang.String) + */ @Override public MessageModel getMessageById(String messageIdentifier, String messageType) throws Exception { @@ -1583,6 +1760,15 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /** + * Gets the list workspace item by id. + * + * @param workspace the workspace + * @param listItemsId the list items id + * @return the list workspace item by id + * @throws ItemNotFoundException the item not found exception + * @throws InternalErrorException the internal error exception + */ private List getListWorkspaceItemById(Workspace workspace, List listItemsId) throws ItemNotFoundException, InternalErrorException{ List listWorkspaceItem = new ArrayList(); @@ -1602,6 +1788,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getListFolderBulkCreator() + */ @Override public List getListFolderBulkCreator() throws Exception { @@ -1625,6 +1814,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT return null; } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#sentToByMessageModel(org.gcube.portlets.user.workspace.client.model.MessageModel) + */ @Override @Deprecated /** @@ -1635,6 +1827,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#saveAttachments(java.lang.String, java.lang.String) + */ @Override @Deprecated /** @@ -1662,6 +1857,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#saveAttach(java.lang.String) + */ @Override @Deprecated /** @@ -1672,6 +1870,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT return false; } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#markMessage(java.lang.String, java.lang.String, boolean, java.lang.String) + */ @Override public boolean markMessage(String messageIdentifier, String messageType, boolean boolMark, String markType) throws Exception { @@ -1722,6 +1923,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#deleteMessage(java.lang.String, java.lang.String) + */ @Override @Deprecated /** @@ -1750,6 +1954,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getNewMessagesReceived() + */ @Override @Deprecated /** @@ -1780,6 +1987,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#searchInSentMessagesByText(java.lang.String) + */ @Override @Deprecated /** @@ -1806,6 +2016,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#searchInReceivedMessagesByText(java.lang.String) + */ @Override @Deprecated /** @@ -1833,6 +2046,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#copyItem(java.lang.String, java.lang.String) + */ @Override public boolean copyItem(String itemId, String destinationFolderId) throws Exception { @@ -1873,6 +2089,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#copyItems(java.util.List, java.lang.String) + */ @Override public boolean copyItems(List idsItem, String destinationFolderId) throws Exception { @@ -1922,6 +2141,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#deleteBulk(java.lang.String) + */ @Override public boolean deleteBulk(String bulkId) throws Exception { @@ -1942,6 +2164,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getUrlWebDav(java.lang.String) + */ @Override public String getUrlWebDav(String itemId) throws Exception { @@ -1959,6 +2184,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#shareFolder(org.gcube.portlets.user.workspace.client.model.FileModel, java.util.List, boolean, org.gcube.portlets.user.workspace.shared.WorkspaceACL) + */ @Override public boolean shareFolder(FileModel folder, List listContacts, boolean isNewFolder, WorkspaceACL acl) throws Exception { @@ -2047,6 +2275,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getListUserSharedByFolderSharedId(java.lang.String) + */ @Override public List getListUserSharedByFolderSharedId(String folderSharedId) throws Exception{ @@ -2080,6 +2311,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getListUserSharedBySharedItem(java.lang.String) + */ @Override public List getListUserSharedBySharedItem(String sharedItemId) throws Exception{ workspaceLogger.trace("Get ListUserSharedBySharedItem "+ sharedItemId); @@ -2112,6 +2346,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#unSharedFolderByFolderSharedId(java.lang.String) + */ @Override public boolean unSharedFolderByFolderSharedId(String folderSharedId) throws Exception{ @@ -2178,11 +2415,12 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } /** - * - * @param itemIdentifier + * Gets the list parents by item identifier. + * + * @param itemIdentifier the item identifier * @param includeItemAsParent - if parameter is true and item passed in input is a folder, the folder is included in path returned as last parent - * @return - * @throws Exception + * @return the list parents by item identifier + * @throws Exception the exception */ @Override public List getListParentsByItemIdentifier(String itemIdentifier, boolean includeItemAsParent) throws Exception { @@ -2234,6 +2472,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT return listParents; } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getOwnerByItemId(java.lang.String) + */ @Override public InfoContactModel getOwnerByItemId(String itemId) throws Exception { @@ -2260,6 +2501,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getUsersManagerToSharedFolder(java.lang.String) + */ @Override public List getUsersManagerToSharedFolder(String folderId) throws Exception{ @@ -2316,6 +2560,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#itemExistsInWorkpaceFolder(java.lang.String, java.lang.String) + */ @Override public String itemExistsInWorkpaceFolder(String parentId, String itemName) throws Exception { @@ -2350,6 +2597,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getItemCreationDateById(java.lang.String) + */ @Override public Date getItemCreationDateById(String itemId) throws Exception { workspaceLogger.trace("get Item Creation Date By ItemId "+ itemId); @@ -2370,6 +2620,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#loadSizeByItemId(java.lang.String) + */ @Override public Long loadSizeByItemId(String itemId) throws Exception { @@ -2400,6 +2653,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#loadLastModificationDateById(java.lang.String) + */ @Override public Date loadLastModificationDateById(String itemId) throws Exception { @@ -2427,6 +2683,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getParentByItemId(java.lang.String) + */ @Override public FileModel getParentByItemId(String identifier) throws Exception { @@ -2456,6 +2715,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getAccountingReaders(java.lang.String) + */ @Override public List getAccountingReaders(String identifier) throws Exception { @@ -2482,6 +2744,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getAccountingHistory(java.lang.String) + */ @Override public List getAccountingHistory(String identifier) throws Exception { @@ -2531,10 +2796,12 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } /** - * - * @param itemId - * @param shortenUrl - * @return + * Gets the public link for folder item id. + * + * @param itemId the item id + * @param shortenUrl the shorten url + * @return the public link for folder item id + * @throws Exception the exception */ @Override public String getPublicLinkForFolderItemId(String itemId, boolean shortenUrl) throws Exception{ @@ -2658,12 +2925,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } - /** - * - * @param folderId - * @param listUserIds - * @param aclType - * @throws Exception + + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#setACLs(java.lang.String, java.util.List, java.lang.String) */ @Override public void setACLs(String folderId, List listLogins, String aclType) throws Exception{ @@ -2696,6 +2960,8 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT // ite = (WorkspaceSharedFolder) workspace.getItem(wsItem.getIdSharedFolder()); } +// validateACLToUser(ite, listLogins, aclType); + ite.setACL(listLogins, ACLType.valueOf(aclType)); }else throw new Exception("Source item is not shared or shared folder"); @@ -2709,9 +2975,113 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } /** - * - * @return - * @throws Exception + * Validate acl to user. + * + * @param folderId 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 folderId, List listLogins, String aclType) throws Exception { + + 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"); + + if(isASharedFolder(folderId, false)){ + + try{ + Workspace workspace = getWorkspace(); + WorkspaceFolder folder = (WorkspaceFolder) workspace.getItem(folderId); + + Map> mapACL = folder.getACLOwner(); + + ACLType settingACL = ACLType.valueOf(aclType); + + workspaceLogger.info("Validating assignment: "+settingACL); + workspaceLogger.info("To logins: "+listLogins); + + AclTypeComparator comparator = new AclTypeComparator(); + + //TO REMOVE ADMINS + List admins = mapACL.get(ACLType.ADMINISTRATOR); + for (String admin : admins) { + listLogins.remove(admin); + workspaceLogger.info("Reject username: "+admin +" as "+ACLType.ADMINISTRATOR); + } + + //TO COMPLETE REPORT + List validLogins = new ArrayList(listLogins); + List errors = new ArrayList(); + ReportAssignmentACL reportValidation = new ReportAssignmentACL(); + + for (String username : listLogins) { + workspaceLogger.trace("\nChecking username: "+username); + for (ACLType aclHL : mapACL.keySet()) { + + if(!aclHL.equals(ACLType.ADMINISTRATOR)){ + List loginsHL = mapACL.get(aclHL); + workspaceLogger.trace("to ACLType: "+aclHL +", logins found: "+loginsHL); + + if(loginsHL.contains(username)){ + int cmp = comparator.compare(settingACL, aclHL); + workspaceLogger.trace("Compare result between "+aclHL + " and "+settingACL +": "+cmp); + String fullname = isTestMode()?username: UserUtil.getUserFullName(username); + if(cmp==-1){ + //CHANGE ACL IS NOT VALID + workspaceLogger.trace("Reject ACL: "+settingACL+ " to "+username); + validLogins.remove(username); + errors.add("Unable to grant the privilege '"+settingACL+" for "+fullname+", it's lower than (already assigned) "+ aclHL); + break; + }else if(cmp==0){ + //SAME ACL + workspaceLogger.trace("Skipping ACL: "+settingACL+ " to "+username); + errors.add("Ignore to grant the privilege '"+settingACL+" for "+fullname+", it's already assigned"); + validLogins.remove(username); + break; + }else if(cmp==1){ + //CHANGE ACL IS VALID + workspaceLogger.trace("Valid ACL: "+settingACL+ " to "+username); + } + }else{ + //CHANGE ACL IS VALID + workspaceLogger.trace("[Login not found], Set ACL: "+settingACL+ " to "+username); + } + } + } + } + /* + System.out.println("\n"); + for (String username : validLogins) { + workspaceLogger.trace("Set ACL: "+settingACL+ " to "+username); + } + + System.out.println("\n"); + for (String error : errors) { + workspaceLogger.trace(error); + }*/ + + reportValidation.setAclType(aclType); + reportValidation.setErrors(errors); + reportValidation.setValidLogins(validLogins); + return reportValidation; + + } catch (InternalErrorException e) { + throw new Exception("Sorry, an error occurred when validating ACL assignment, try again later"); + } + }else + throw new WorkspaceHandledException("the item with "+folderId +" is not a base shared folder!"); + } + + /** + * Gets the AC ls. + * + * @return the AC ls + * @throws Exception the exception */ @Override public List getACLs() throws Exception{ @@ -2727,7 +3097,8 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } /** - * + * Checks if is within portal. + * * @return true if you're running into the portal, false if in development */ private boolean isWithinPortal() { @@ -2741,6 +3112,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getMyLogin() + */ @Override public UserBean getMyLogin(){ ASLSession asl = WsUtil.getAslSession(this.getThreadLocalRequest().getSession()); @@ -2766,11 +3140,11 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } /** - * - * @param folderId - * @param listUserIds - * @param aclType - * @throws Exception + * 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{ @@ -2806,9 +3180,11 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT /** - * - * @return - * @throws Exception + * Gets the user acl for folder id. + * + * @param folderId the folder id + * @return the user acl for folder id + * @throws Exception the exception */ @Override public List getUserACLForFolderId(String folderId) throws Exception{ @@ -2836,9 +3212,11 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } /** - * + * Gets the AC ls description for shared folder id. + * + * @param folderId the folder id * @return Formatted HTML DIV containing ACLs description for folderId - * @throws Exception + * @throws Exception the exception */ @Override public String getACLsDescriptionForSharedFolderId(String folderId) throws Exception{ @@ -2855,10 +3233,11 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } /** - * - * @param folderId - * @return - * @throws Exception + * Gets the shared workspace folder for id. + * + * @param folderId the folder id + * @return the shared workspace folder for id + * @throws Exception the exception */ private WorkspaceFolder getSharedWorkspaceFolderForId(String folderId) throws Exception{ @@ -2899,10 +3278,11 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } /** - * - * @param itemID + * Checks if is a shared folder. + * + * @param itemID the item id * @param asRoot true check if itemID is root, not otherwise - * @return + * @return true, if is a shared folder */ public boolean isASharedFolder(String itemID, boolean asRoot){ @@ -2923,10 +3303,12 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } /** + * Checks if is a shared folder. + * + * @param item the item + * @param asRoot the as root + * @return true, if is a shared folder * @see #isASharedFolder(String, boolean) - * @param item - * @param asRoot - * @return */ public boolean isASharedFolder(WorkspaceItem item, boolean asRoot){ try { @@ -2947,9 +3329,10 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT /** - * - * @return - * @throws Exception + * Gets the trash content. + * + * @return the trash content + * @throws Exception the exception */ @Override public List getTrashContent() throws Exception{ @@ -2972,9 +3355,11 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } /** - * - * @return - * @throws Exception + * Update trash content. + * + * @param operation the operation + * @return the trash content + * @throws Exception the exception */ @Override public TrashContent updateTrashContent(WorkspaceTrashOperation operation) throws Exception{ @@ -3028,8 +3413,8 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } - /** - * + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#executeOperationOnTrash(java.util.List, org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation) */ @Override public TrashOperationContent executeOperationOnTrash(List listTrashItemIds, WorkspaceTrashOperation operation) throws Exception{ @@ -3221,6 +3606,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getItemDescriptionById(java.lang.String) + */ @Override public String getItemDescriptionById(String identifier) throws Exception { @@ -3287,6 +3675,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getUserWorkspaceQuote() + */ @Override public WorkspaceUserQuote getUserWorkspaceQuote() throws Exception { try{ @@ -3309,6 +3700,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getUserWorkspaceSize() + */ @Override public String getUserWorkspaceSize() throws Exception { try{ @@ -3327,6 +3721,9 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + /* (non-Javadoc) + * @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#getUserWorkspaceTotalItems() + */ @Override public long getUserWorkspaceTotalItems() throws Exception { try{ diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/util/AclTypeComparator.java b/src/main/java/org/gcube/portlets/user/workspace/server/util/AclTypeComparator.java new file mode 100644 index 0000000..49bf249 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/server/util/AclTypeComparator.java @@ -0,0 +1,106 @@ +/** + * + */ +package org.gcube.portlets.user.workspace.server.util; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.gcube.common.homelibrary.home.workspace.accessmanager.ACLType; + +/** + * The Class AclTypeComparator. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Mar 5, 2015 + */ +public class AclTypeComparator implements Comparator{ + + + public static final Map aclTypeOrder; + static + { + aclTypeOrder = new LinkedHashMap(); + aclTypeOrder.put(ACLType.READ_ONLY, 0); + aclTypeOrder.put(ACLType.WRITE_OWNER, 1); + aclTypeOrder.put(ACLType.WRITE_ALL, 2); +// aclTypeOrder.put(ACLType.ADMINISTRATOR, 3); + } + + + /* (non-Javadoc) + * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) + */ + @Override + public int compare(ACLType o1, ACLType o2) { + if(o1==null) + return -1; + if(o2==null) + return 1; + + Integer order1 = aclTypeOrder.get(o1); + Integer order2 = aclTypeOrder.get(o2); + + if(order1==null) + return -1; + + if(order2==null) + return 1; + + if(order1==order2) + return 0; + + return order1 getAllowed(ACLType aclType, boolean includeEqual) { + + List allowed = new ArrayList(); + + if(aclType==null) + return allowed; + + //IF MAP DOES NOT CONTAINS ACT TYPE IT IS NOT COMPARABLE + if(aclTypeOrder.get(aclType)==null) + return allowed; + + for (ACLType aMap : aclTypeOrder.keySet()) { + int comparator = compare(aMap, aclType); + if(comparator==1) + allowed.add(aMap); + else if(includeEqual && comparator==0) + allowed.add(aMap); + } + + return allowed; + } + + + /** + * The main method. + * + * @param args the arguments + */ + public static void main(String[] args) { + + AclTypeComparator comparator = new AclTypeComparator(); + + List allowed = comparator.getAllowed(ACLType.WRITE_ALL, false); + + System.out.println(allowed); + + } + + +} diff --git a/src/main/java/org/gcube/portlets/user/workspace/shared/ReportAssignmentACL.java b/src/main/java/org/gcube/portlets/user/workspace/shared/ReportAssignmentACL.java new file mode 100644 index 0000000..cd8fd06 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/shared/ReportAssignmentACL.java @@ -0,0 +1,88 @@ +/** + * + */ +package org.gcube.portlets.user.workspace.shared; + +import java.io.Serializable; +import java.util.List; + +/** + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Mar 6, 2015 + */ +public class ReportAssignmentACL implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = -7218122043660957432L; + + private List validLogins; + private List errors; + private String aclType; + + /** + * + */ + public ReportAssignmentACL() { + } + + /** + * @return the validLogins + */ + public List getValidLogins() { + return validLogins; + } + + /** + * @param validLogins the validLogins to set + */ + public void setValidLogins(List validLogins) { + this.validLogins = validLogins; + } + + /** + * @return the errors + */ + public List getErrors() { + return errors; + } + + /** + * @param errors the errors to set + */ + public void setErrors(List errors) { + this.errors = errors; + } + + /** + * @return the aclType + */ + public String getAclType() { + return aclType; + } + + /** + * @param aclType the aclType to set + */ + public void setAclType(String aclType) { + this.aclType = aclType; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("ReportValidationACL [validLogins="); + builder.append(validLogins); + builder.append(", errors="); + builder.append(errors); + builder.append(", aclType="); + builder.append(aclType); + builder.append("]"); + return builder.toString(); + } +} diff --git a/src/test/java/org/gcube/portlets/user/workspace/EditPermissionsTest.java b/src/test/java/org/gcube/portlets/user/workspace/EditPermissionsTest.java index e371c9b..1f70a81 100644 --- a/src/test/java/org/gcube/portlets/user/workspace/EditPermissionsTest.java +++ b/src/test/java/org/gcube/portlets/user/workspace/EditPermissionsTest.java @@ -19,6 +19,7 @@ import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNot import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.impl.ScopeBean; import org.gcube.portlets.user.workspace.server.util.AclTypeComparator; +import org.gcube.portlets.user.workspace.shared.ReportAssignmentACL; /** * @@ -60,8 +61,9 @@ public class EditPermissionsTest { list.add("francesco.mangiacrapa"); list.add("massimiliano.assante"); list.add("pasquale.pagano"); + list.add("valentina.marioli"); - validateACLToUser(sharedFolder, list, ACLType.WRITE_ALL.toString()); + validateACLToUser(sharedFolder, list, ACLType.READ_ONLY.toString()); } catch (WorkspaceFolderNotFoundException e) { // TODO Auto-generated catch block @@ -78,19 +80,26 @@ public class EditPermissionsTest { } catch (ItemNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); } } - private static void validateACLToUser(WorkspaceFolder folder, List listLogins, String aclType) { + private static ReportAssignmentACL validateACLToUser(WorkspaceFolder folder, List listLogins, String aclType) throws Exception { + + ReportAssignmentACL reportValidation = new ReportAssignmentACL(); try { + Map> mapACL = folder.getACLOwner(); ACLType settingACL = ACLType.valueOf(aclType); System.out.println("Tentative setting: "+settingACL); + System.out.println("For Logins: "+listLogins); AclTypeComparator comparator = new AclTypeComparator(); @@ -100,39 +109,66 @@ public class EditPermissionsTest { listLogins.remove(admin); System.out.println("Reject username: "+admin +" as "+ACLType.ADMINISTRATOR); } - + + List validLogins = new ArrayList(listLogins); + List errors = new ArrayList(); + + for (String username : listLogins) { System.out.println("\nChecking username: "+username); for (ACLType aclHL : mapACL.keySet()) { - - - List loginsHL = mapACL.get(aclHL); - System.out.println("to ACLType: "+aclHL +", logins found: "+loginsHL); - - if(loginsHL.contains(username)){ - int cmp = comparator.compare(settingACL, aclHL); - System.out.println("Compare result between "+aclHL + " and "+settingACL +": "+cmp); - if(cmp==-1){ - System.out.println("Reject ACL: "+settingACL+ " to "+username); - //CHANGE ACL IS NOT VALID - }else if(cmp==1){ + + if(!aclHL.equals(ACLType.ADMINISTRATOR)){ + List loginsHL = mapACL.get(aclHL); + System.out.println("to ACLType: "+aclHL +", logins found: "+loginsHL); + + if(loginsHL.contains(username)){ + int cmp = comparator.compare(settingACL, aclHL); + System.out.println("Compare result between "+aclHL + " and "+settingACL +": "+cmp); + if(cmp==-1){ + //CHANGE ACL IS NOT VALID + System.out.println("Reject ACL: "+settingACL+ " to "+username); + validLogins.remove(username); + //TODO FULL NAME + errors.add("Unable for "+username+ " the grant of the privilege '"+settingACL+", it's lower than (already assigned) "+ aclHL); + break; + }else if(cmp==0){ + //SAME ACL + System.out.println("Skipping ACL: "+settingACL+ " to "+username); + //TODO FULL NAME + errors.add("Ignoring for "+username+ " the grant of the privilege '"+settingACL+", it's already assigned"); + validLogins.remove(username); + break; + }else if(cmp==1){ + //CHANGE ACL IS VALID + System.out.println("Valid ACL: "+settingACL+ " to "+username); + } + }else{ //CHANGE ACL IS VALID - System.out.println("Set ACL: "+settingACL+ " to "+username); - }else if(cmp==0){ - //SAME ACL - System.out.println("Skipping ACL: "+settingACL+ " to "+username); + System.out.println("[Login not found], Set ACL: "+settingACL+ " to "+username); } - }else{ - //CHANGE ACL IS VALID - System.out.println("[Login not found], Set ACL: "+settingACL+ " to "+username); } } } + + System.out.println("\n"); + for (String username : validLogins) { + System.out.println("Set ACL: "+settingACL+ " to "+username); + } + + + System.out.println("\n"); + for (String error : errors) { + System.out.println(error); + } + reportValidation.setAclType(aclType); + reportValidation.setErrors(errors); + reportValidation.setValidLogins(validLogins); + return reportValidation; + } catch (InternalErrorException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + throw new Exception("Sorry, an error occurred when validating ACL assignment, try again later"); } - } }