enhancements on ACL

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@91840 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2014-02-18 13:40:19 +00:00
parent 8672c7af9f
commit 1ab8d725a2
6 changed files with 172 additions and 32 deletions

View File

@ -211,7 +211,7 @@ public interface GWTWorkspaceService extends RemoteService{
* @return
* @throws Exception
*/
List<WorkspaceACL> getACLForFolderId(String folderId) throws Exception;
List<WorkspaceACL> getUserACLForFolderId(String folderId) throws Exception;
/**
* @return
@ -228,4 +228,11 @@ public interface GWTWorkspaceService extends RemoteService{
TrashOperationResult executeOperationOnTrash(String trashItemId,
WorkspaceTrashOperation operation) throws Exception;
/**
* @param folderId
* @return
* @throws Exception
*/
String getACLsDescriptionForFolderId(String folderId) throws Exception;
}

View File

@ -185,7 +185,7 @@ public interface GWTWorkspaceServiceAsync {
void setACLForVRE(String folderId, String aclType,
AsyncCallback<Void> callback);
void getACLForFolderId(String folderId,
void getUserACLForFolderId(String folderId,
AsyncCallback<List<WorkspaceACL>> callback);
void getTrashContent(AsyncCallback<List<FileTrashedModel>> callback);
@ -194,4 +194,7 @@ public interface GWTWorkspaceServiceAsync {
WorkspaceTrashOperation operation,
AsyncCallback<TrashOperationResult> callback);
void getACLsDescriptionForFolderId(String folderId,
AsyncCallback<String> callback);
}

View File

@ -10,9 +10,13 @@ import org.gcube.portlets.user.workspace.client.model.FileModel;
import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Html;
import com.extjs.gxt.ui.client.widget.Label;
import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
@ -39,7 +43,8 @@ public class DialogGetInfo extends Dialog {
private TextField<String> txtSize = new TextField<String>();
private TextField<String> txtLocation = new TextField<String>();
private TextField<String> txtShared = new TextField<String>();
private TextArea textAreaSharedWith = new TextArea();
// private TextArea textAreaSharedWith = new TextArea();
private Html htmlUsersWidget = new Html();
private final NumberFormat number = ConstantsExplorer.numberFormatterKB;
@ -150,11 +155,25 @@ public class DialogGetInfo extends Dialog {
if(fileModel.isShared()){
HorizontalPanel hp = new HorizontalPanel();
hp.setStyleAttribute("padding-top", "6px");
Label label = new Label("Shared with");
label.setStyleAttribute("padding-right", "39px");
hp.add(label);
/*
textAreaSharedWith.setFieldLabel("Shared with");
textAreaSharedWith.setHeight(heightTextArea);
textAreaSharedWith.setReadOnly(true);
loadListSharedContacts(fileModel.getIdentifier());
add(textAreaSharedWith);
*/
// htmlUsersWidget.setStyleAttribute("border", "1px solid #B5B8C8");
loadListSharedContacts(fileModel.getIdentifier());
htmlUsersWidget.setHeight(heightTextArea);
htmlUsersWidget.setWidth("297px");
hp.add(htmlUsersWidget);
hp.setScrollMode(Scroll.AUTOY);
add(hp);
}
@ -269,35 +288,58 @@ public class DialogGetInfo extends Dialog {
});
}
// private void loadListSharedContacts(String sharedId){
//
// textAreaSharedWith.mask();
//
// AppControllerExplorer.rpcWorkspaceService.getListUserSharedBySharedItem(sharedId, new AsyncCallback<List<InfoContactModel>>() {
//
// @Override
// public void onFailure(Throwable caught) {
// textAreaSharedWith.unmask();
//
// }
//
// @Override
// public void onSuccess(List<InfoContactModel> result) {
//
// String users = "";
//
// for (int i = 0; i < result.size()-1; i++) {
// users+= result.get(i).getName() + ", ";
// }
//
// if(result.size()>1)
// users += result.get(result.size()-1).getName();
//
// textAreaSharedWith.setValue(users);
//
// textAreaSharedWith.unmask();
// }
// });
// }
private void loadListSharedContacts(String sharedId){
textAreaSharedWith.mask();
htmlUsersWidget.mask();
AppControllerExplorer.rpcWorkspaceService.getListUserSharedBySharedItem(sharedId, new AsyncCallback<List<InfoContactModel>>() {
AppControllerExplorer.rpcWorkspaceService.getACLsDescriptionForFolderId(sharedId, new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
textAreaSharedWith.unmask();
htmlUsersWidget.unmask();
htmlUsersWidget.setHtml("Error on recovering users");
}
@Override
public void onSuccess(List<InfoContactModel> result) {
public void onSuccess(String result) {
htmlUsersWidget.unmask();
htmlUsersWidget.setHtml(result);
String users = "";
for (int i = 0; i < result.size()-1; i++) {
users+= result.get(i).getName() + ", ";
}
if(result.size()>1)
users += result.get(result.size()-1).getName();
textAreaSharedWith.setValue(users);
textAreaSharedWith.unmask();
}
});
}
private String getFormattedSize(long value){

View File

@ -2181,4 +2181,32 @@ public class GWTWorkspaceBuilder {
return null;
}
/**
* @param aclOwner
* @return
*/
public String getFormattedHtmlACLFromACLs(Map<ACLType, List<String>> aclOwner) {
String html = "<div style=\"width: 100%; text-align:left; font-size: 10px;\">";
for (ACLType type : aclOwner.keySet()) {
List<String> listLogins = aclOwner.get(type);
html+="<span style=\"font-weight:bold; padding-top: 5px;\">"+type+": </span>";
html+="<span style=\"font-weight:normal;\">";
for (String login : listLogins) {
String fullName = UserUtil.getUserFullName(login);
if(fullName!=null && !fullName.isEmpty())
html+=fullName+"; ";
else
html+=login+"; ";
}
html+="</span>";
}
html+="</div>";
return html;
}
}

View File

@ -2576,7 +2576,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
* @throws Exception
*/
@Override
public List<WorkspaceACL> getACLForFolderId(String folderId) throws Exception{
public List<WorkspaceACL> getUserACLForFolderId(String folderId) throws Exception{
try {
if(folderId == null)
@ -2588,13 +2588,66 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
WorkspaceItem wsItem = workspace.getItem(folderId);
if(wsItem.isShared() && (wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER))){
workspaceLogger.trace("Get ACLByFolderId folder id is shared folder");
WorkspaceSharedFolder ite = (WorkspaceSharedFolder) workspace.getItemByPath(wsItem.getPath());
if(ite.getIdSharedFolder()!=null && ite.getId().compareTo(ite.getIdSharedFolder())!=0){//IS SHARED FOLDER IS NOT BASE
ite = (WorkspaceSharedFolder) workspace.getItem(ite.getIdSharedFolder());
}
workspaceLogger.trace("Get ACLByFolderId shared folder name is: "+ite.getName());
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder();
//DEBUG //TODO REMOVE THIS FOR PRODUCTION
workspaceLogger.trace("Get ACLByFolderId ACL user returned is : "+ite.getACLUser());
return builder.getWorkspaceACLFromACLs(Arrays.asList(ite.getACLUser()));
}else
}else{
workspaceLogger.trace("Source item is not shared or shared folder, throw exceptio");
throw new Exception("Source item is not shared or shared folder");
}
} catch (Exception e) {
workspaceLogger.error("Error in server get getACLForFolderId", e);
String error = ConstantsExplorer.SERVER_ERROR +" get ACL rules for selected folder. "+e.getMessage();
throw new Exception(error);
}
}
/**
*
* @return Formatted HTML DIV containing ACLs description for folderId
* @throws Exception
*/
@Override
public String getACLsDescriptionForFolderId(String folderId) throws Exception{
try {
if(folderId == null)
throw new Exception("Folder id is null");
workspaceLogger.trace("Get ACLsDescriptionForFolderId folder id: "+folderId);
Workspace workspace = getWorkspace();
WorkspaceItem wsItem = workspace.getItem(folderId);
if(wsItem.isShared() && (wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER))){
workspaceLogger.trace("Get ACLsDescriptionForFolderId folder id is shared folder");
WorkspaceSharedFolder ite = (WorkspaceSharedFolder) workspace.getItemByPath(wsItem.getPath());
if(ite.getIdSharedFolder()!=null && ite.getId().compareTo(ite.getIdSharedFolder())!=0){//IS SHARED FOLDER IS NOT BASE
ite = (WorkspaceSharedFolder) workspace.getItem(ite.getIdSharedFolder());
}
workspaceLogger.trace("Get ACLsDescriptionForFolderId shared folder name is: "+ite.getName());
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder();
return builder.getFormattedHtmlACLFromACLs(ite.getACLOwner());
}else{
workspaceLogger.trace("Source item is not shared or shared folder, throw exceptio");
throw new Exception("Source item is not shared or shared folder");
}
} catch (Exception e) {
workspaceLogger.error("Error in server get getACLForFolderId", e);
String error = ConstantsExplorer.SERVER_ERROR +" get ACL rules for selected folder. "+e.getMessage();

View File

@ -20,6 +20,7 @@ import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder;
import org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl;
import org.gcube.portlets.user.workspace.server.notifications.NotificationsProducer;
import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameter;
import org.gcube.portlets.user.workspace.server.shortener.UrlShortener;
@ -27,7 +28,9 @@ import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter;
/**
* @author Federico De Faveri defaveri@isti.cnr.it
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Feb 18, 2014
*
*/
public class WsUtil {
@ -43,7 +46,7 @@ public class WsUtil {
public static final String WORKSPACE_SCOPE_UTIL = "WORKSPACE_SCOPE_UTIL";
public static final String URL_SHORTENER_SERVICE = "URL_SHORTENER_SERVICE";
public static final String URI_RESOLVER_SERVICE = "URI_RESOLVER_SERVICE";
public static final String NOTIFICATION_PORTLET_CLASS_ID = "org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl"; //IN DEV
public static final String NOTIFICATION_PORTLET_CLASS_ID = GWTWorkspaceServiceImpl.class.toString(); //IN DEV
// public static final String TEST_SCOPE = "/gcube/devsec";
// public static final String TEST_USER = "pasquale.pagano";
@ -74,10 +77,10 @@ public class WsUtil {
/*USE ANOTHER ACCOUNT (OTHERWHISE BY TEST_USER) FOR RUNNING
* COMMENT THIS IN DEVELOP ENVIROMENT (UNCOMMENT IN PRODUCTION)*/
// user=TEST_USER;
user=TEST_USER;
//UNCOMMENT THIS IN DEVELOP ENVIROMENT
user = "francesco.mangiacrapa";
// user = "francesco.mangiacrapa";
logger.warn("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND - PORTLETS STARTING WITH FOLLOWING SETTINGS:");
logger.warn("session id: "+sessionID);
@ -105,10 +108,10 @@ public class WsUtil {
withoutPortal = true;
//COMMENT THIS IN PRODUCTION ENVIROMENT
}else if(user.compareToIgnoreCase("francesco.mangiacrapa")==0){
withoutPortal = true;
//END UNCOMMENT
// }else if(user.compareToIgnoreCase("francesco.mangiacrapa")==0){
//
// withoutPortal = true;
// //END UNCOMMENT
}else{
withoutPortal = false;
@ -240,9 +243,13 @@ public class WsUtil {
NotificationsManager notifMng = (NotificationsManager) session.getAttribute(NOTIFICATION_MANAGER);
if (notifMng == null) {
logger.trace("Create new NotificationsManager for user: "+session.getUsername());
notifMng = new ApplicationNotificationsManager(session, NOTIFICATION_PORTLET_CLASS_ID);
session.setAttribute(NOTIFICATION_MANAGER, notifMng);
try{
logger.trace("Create new NotificationsManager for user: "+session.getUsername());
notifMng = new ApplicationNotificationsManager(session, NOTIFICATION_PORTLET_CLASS_ID);
session.setAttribute(NOTIFICATION_MANAGER, notifMng);
}catch (Exception e) {
logger.error("An error occurred instancing ApplicationNotificationsManager for user: "+session.getUsername(),e);
}
}
return notifMng;