added scope filter (ids was displayed without root infrastructure)
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@71863 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
79d79230b2
commit
568a838682
|
@ -1,5 +1,6 @@
|
|||
package org.gcube.portlets.user.workspace.client.event;
|
||||
|
||||
import org.gcube.portlets.user.workspace.client.constant.WorkspaceOperation;
|
||||
import org.gcube.portlets.user.workspace.client.model.FileModel;
|
||||
|
||||
import com.google.gwt.event.shared.GwtEvent;
|
||||
|
@ -11,6 +12,12 @@ public class OpenContextMenuTreeEvent extends GwtEvent<OpenContextMenuTreeEventH
|
|||
private int clientX;
|
||||
private int clientY;
|
||||
|
||||
private WorkspaceOperation wsOperation;
|
||||
|
||||
public WorkspaceOperation getWsOperation() {
|
||||
return wsOperation;
|
||||
}
|
||||
|
||||
public OpenContextMenuTreeEvent(FileModel targetFileModel, int clientX, int clientY) {
|
||||
this.targetFileModel = targetFileModel;
|
||||
this.clientX = clientX;
|
||||
|
|
|
@ -128,4 +128,6 @@ public interface GWTWorkspaceService extends RemoteService{
|
|||
|
||||
Date loadLastModificationDateById(String itemId) throws Exception;
|
||||
|
||||
FileModel getParentByItemId(String identifier) throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
@ -137,5 +137,8 @@ public interface GWTWorkspaceServiceAsync {
|
|||
void loadLastModificationDateById(String itemId,
|
||||
AsyncCallback<Date> callback);
|
||||
|
||||
void getParentByItemId(String identifier,
|
||||
AsyncCallback<FileModel> asyncCallback);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -29,11 +29,13 @@ import org.gcube.portlets.user.workspace.client.resources.Resources;
|
|||
|
||||
import com.extjs.gxt.ui.client.event.MenuEvent;
|
||||
import com.extjs.gxt.ui.client.event.SelectionListener;
|
||||
import com.extjs.gxt.ui.client.widget.Info;
|
||||
import com.extjs.gxt.ui.client.widget.menu.Menu;
|
||||
import com.extjs.gxt.ui.client.widget.menu.MenuItem;
|
||||
import com.extjs.gxt.ui.client.widget.menu.SeparatorMenuItem;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.shared.HandlerManager;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
|
||||
public class ContextMenuTree {
|
||||
|
||||
|
@ -500,27 +502,62 @@ public class ContextMenuTree {
|
|||
* @param posX
|
||||
* @param posY
|
||||
*/
|
||||
public void openContextMenuOnItem(FileModel targetFileModel, int posX, int posY) {
|
||||
public void openContextMenuOnItem(final FileModel targetFileModel, final int posX, final int posY) {
|
||||
clearListSelectedItems();
|
||||
listSelectedItems.add(0, targetFileModel);
|
||||
|
||||
printSelected();
|
||||
|
||||
|
||||
|
||||
if(targetFileModel!=null){
|
||||
contextMenuSwitch(targetFileModel);
|
||||
contextMenu.getItemByItemId(WorkspaceOperation.INSERT_FOLDER.getId()).setVisible(false); //set invisible create folder
|
||||
contextMenu.getItemByItemId(WorkspaceOperation.INSERT_SHARED_FOLDER.getId()).setVisible(false); //set invisible create shared folder
|
||||
contextMenu.getItemByItemId(WorkspaceOperation.WEBDAV_URL.getId()).setVisible(false); //set invisible webdav url
|
||||
contextMenu.getItemByItemId(WorkspaceOperation.UPLOAD_FILE.getId()).setVisible(false); //set invisible upload file
|
||||
contextMenu.getItemByItemId(WorkspaceOperation.UPLOAD_ARCHIVE.getId()).setVisible(false); //set invisible upload archive
|
||||
contextMenu.getItemByItemId(WorkspaceOperation.ADD_URL.getId()).setVisible(false); //set invisible add url
|
||||
contextMenu.getItemByItemId(WorkspaceOperation.REFRESH_FOLDER.getId()).setVisible(false); //set invisible refresh
|
||||
contextMenu.getItemByItemId(WorkspaceOperation.SHARE.getId()).setVisible(false); //set invisible share
|
||||
contextMenu.getItemByItemId(WorkspaceOperation.UNSHARE.getId()).setVisible(false); //set invisible unshare
|
||||
contextMenu.showAt(posX, posY);
|
||||
|
||||
if(targetFileModel.getParentFileModel()==null){
|
||||
|
||||
Info.display("Wait", "loading available operations..");
|
||||
|
||||
AppControllerExplorer.rpcWorkspaceService.getParentByItemId(targetFileModel.getIdentifier(), new AsyncCallback<FileModel>() {
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
Info.display("Error", "sorry an error occurrend on loading available operations");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(FileModel result) {
|
||||
if(result!=null){
|
||||
targetFileModel.setParentFileModel(result);
|
||||
viewContextMenu(targetFileModel, posX, posY);
|
||||
}
|
||||
else
|
||||
Info.display("Error", "sorry an error occurrend on loading available operations");
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
else
|
||||
viewContextMenu(targetFileModel, posX, posY);
|
||||
|
||||
}
|
||||
// treePanel.fireEvent(Events.ContextMenu);
|
||||
}
|
||||
|
||||
|
||||
private void viewContextMenu(FileModel targetFileModel, int posX, int posY){
|
||||
|
||||
contextMenuSwitch(targetFileModel);
|
||||
contextMenu.getItemByItemId(WorkspaceOperation.INSERT_FOLDER.getId()).setVisible(false); //set invisible create folder
|
||||
contextMenu.getItemByItemId(WorkspaceOperation.INSERT_SHARED_FOLDER.getId()).setVisible(false); //set invisible create shared folder
|
||||
contextMenu.getItemByItemId(WorkspaceOperation.WEBDAV_URL.getId()).setVisible(false); //set invisible webdav url
|
||||
contextMenu.getItemByItemId(WorkspaceOperation.UPLOAD_FILE.getId()).setVisible(false); //set invisible upload file
|
||||
contextMenu.getItemByItemId(WorkspaceOperation.UPLOAD_ARCHIVE.getId()).setVisible(false); //set invisible upload archive
|
||||
contextMenu.getItemByItemId(WorkspaceOperation.ADD_URL.getId()).setVisible(false); //set invisible add url
|
||||
contextMenu.getItemByItemId(WorkspaceOperation.REFRESH_FOLDER.getId()).setVisible(false); //set invisible refresh
|
||||
// contextMenu.getItemByItemId(WorkspaceOperation.SHARE.getId()).setVisible(false); //set invisible share
|
||||
// contextMenu.getItemByItemId(WorkspaceOperation.UNSHARE.getId()).setVisible(false); //set invisible unshare
|
||||
contextMenu.showAt(posX, posY);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -78,7 +78,6 @@ import org.gcube.portlets.user.workspace.client.workspace.folder.item.gcube.GWTI
|
|||
import org.gcube.portlets.user.workspace.client.workspace.folder.item.gcube.GWTMetadata;
|
||||
import org.gcube.portlets.user.workspace.client.workspace.folder.item.gcube.GWTPDFDocument;
|
||||
import org.gcube.portlets.user.workspace.client.workspace.folder.item.gcube.GWTUrlDocument;
|
||||
import org.gcube.portlets.user.workspace.server.util.AllScope;
|
||||
import org.gcube.portlets.user.workspace.server.util.UserUtil;
|
||||
import org.gcube.portlets.user.workspace.server.util.Util;
|
||||
|
||||
|
@ -1428,14 +1427,14 @@ public class GWTWorkspaceBuilder {
|
|||
return smartFolderModel;
|
||||
}
|
||||
|
||||
public List<ScopeModel> buildGXTListScopeModel(List<String> listScopes) {
|
||||
public List<ScopeModel> buildGXTListScopeModel(List<String> listFilteredScopes, Map<String, String> mapPortalScopes) {
|
||||
|
||||
List<ScopeModel> listScopeModel = new ArrayList<ScopeModel>();
|
||||
|
||||
listScopeModel.add(AllScope.getScopeModel());
|
||||
// listScopeModel.add(AllScope.getScopeModel());
|
||||
|
||||
for(String scope: listScopes)
|
||||
listScopeModel.add(new ScopeModel(scope, scope));
|
||||
for(String scope: listFilteredScopes)
|
||||
listScopeModel.add(new ScopeModel(mapPortalScopes.get(scope),scope));
|
||||
|
||||
// listScopeModel.add(new ScopeModel("1", "Aquamaps"));
|
||||
// listScopeModel.add(new ScopeModel("2", "VTI"));
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.apache.log4j.Logger;
|
|||
import org.gcube.application.framework.core.session.ASLSession;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.common.core.utils.logging.GCUBEClientLog;
|
||||
import org.gcube.portlets.user.homelibrary.home.Home;
|
||||
import org.gcube.portlets.user.homelibrary.home.HomeLibrary;
|
||||
import org.gcube.portlets.user.homelibrary.home.exceptions.HomeNotFoundException;
|
||||
import org.gcube.portlets.user.homelibrary.home.exceptions.InternalErrorException;
|
||||
|
@ -47,9 +48,9 @@ import org.gcube.portlets.user.workspace.client.model.SubTree;
|
|||
import org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService;
|
||||
import org.gcube.portlets.user.workspace.client.workspace.GWTWorkspaceItem;
|
||||
import org.gcube.portlets.user.workspace.server.notifications.NotificationsProducer;
|
||||
import org.gcube.portlets.user.workspace.server.util.AllScope;
|
||||
import org.gcube.portlets.user.workspace.server.util.UserUtil;
|
||||
import org.gcube.portlets.user.workspace.server.util.Util;
|
||||
import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter;
|
||||
import org.gcube.portlets.user.workspaceapplicationhandler.ApplicationReaderFromGenericResource;
|
||||
|
||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||
|
@ -86,6 +87,11 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|||
return Util.getNotificationProducer(Util.getAslSession(this.getThreadLocalRequest().getSession()));
|
||||
}
|
||||
|
||||
protected ScopeUtilFilter getScopeUtilFilter(){
|
||||
|
||||
return Util.getScopeUtilFilter(this.getThreadLocalRequest().getSession());
|
||||
}
|
||||
|
||||
protected boolean isTestMode(){
|
||||
return Util.withoutPortal;
|
||||
}
|
||||
|
@ -145,7 +151,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|||
|
||||
GCUBEScope gcubeScope = null;
|
||||
|
||||
if(!scopeId.equals(AllScope.IDALLSCOPE)){
|
||||
if(scopeId.compareTo(ScopeUtilFilter.IDALLSCOPE)!=0){
|
||||
gcubeScope = GCUBEScope.getScope(scopeId);
|
||||
}
|
||||
WorkspaceFolder root = workspace.getRoot(gcubeScope);
|
||||
|
@ -1017,17 +1023,20 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|||
|
||||
GCUBEClientLog logger = new GCUBEClientLog(GWTWorkspaceServiceImpl.class);
|
||||
logger.trace("get all scope");
|
||||
|
||||
// WorkspaceItem parent = workspace.getItem(parentFileModel.getIdentifier()); //get item from workspace
|
||||
// workspace.getAllScope();
|
||||
|
||||
|
||||
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder();
|
||||
|
||||
|
||||
// return builder.buildGXTListScopeModel(HomeLibrary.getHomeManagerFactory().listScopes()); //TODO passare list items
|
||||
|
||||
return builder.buildGXTListScopeModel(workspace.getHome().listScopes()); //TODO passare list items
|
||||
|
||||
|
||||
ScopeUtilFilter scopeUtilFilter = getScopeUtilFilter();
|
||||
|
||||
Home home = workspace.getHome();
|
||||
if(home!=null){
|
||||
List<String> listIdFilterdScope = scopeUtilFilter.convertListScopeToPortlet(home.listScopes());
|
||||
return builder.buildGXTListScopeModel(listIdFilterdScope, scopeUtilFilter.getHashScopesFiltered());
|
||||
}else{
|
||||
workspaceLogger.error("workspace.getHome() is null");
|
||||
throw new Exception("Sorry, an error occurred on getting all scope. Please try later");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
workspaceLogger.error("Error in server get all scope ", e);
|
||||
e.printStackTrace();
|
||||
|
@ -1723,6 +1732,8 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|||
|
||||
WorkspaceItem wsItem = workspace.getItem(folderSharedId);
|
||||
|
||||
workspaceLogger.trace("workspace return an item with name "+wsItem.getName());
|
||||
|
||||
if(wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)){
|
||||
|
||||
WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) wsItem;
|
||||
|
@ -1802,7 +1813,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|||
workspaceLogger.trace("list parents return size: "+listParents.size());
|
||||
|
||||
} catch (Exception e) {
|
||||
workspaceLogger.error("Erron in get List Parents By Item Identifier ", e);
|
||||
workspaceLogger.error("Error in get List Parents By Item Identifier ", e);
|
||||
e.printStackTrace();
|
||||
throw new Exception(e.getMessage());
|
||||
}
|
||||
|
@ -1945,4 +1956,33 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|||
throw new Exception(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileModel getParentByItemId(String identifier) throws Exception {
|
||||
|
||||
workspaceLogger.trace("get Parent By Item Identifier "+ identifier);
|
||||
try {
|
||||
Workspace workspace = getWorkspace();
|
||||
|
||||
WorkspaceItem wsItem = workspace.getItem(identifier);
|
||||
|
||||
workspaceLogger.trace("workspace retrieve item name: "+wsItem.getName());
|
||||
|
||||
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder();
|
||||
|
||||
while(wsItem!=null && wsItem.getParent()!=null){
|
||||
|
||||
WorkspaceFolder wsFolder = wsItem.getParent();
|
||||
workspaceLogger.trace("parent was found "+wsFolder.getName()+ " retuning");
|
||||
return builder.buildGXTFolderModelItem(wsFolder, null);
|
||||
}
|
||||
workspaceLogger.trace("parent not found - retuning");
|
||||
return null;
|
||||
|
||||
} catch (Exception e) {
|
||||
workspaceLogger.error("Error in get Parent By Item Identifier", e);
|
||||
e.printStackTrace();
|
||||
throw new Exception(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
package org.gcube.portlets.user.workspace.server;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Calendar;
|
||||
|
@ -23,7 +21,6 @@ import org.apache.commons.fileupload.FileUploadException;
|
|||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
import org.gcube.portlets.user.homelibrary.home.exceptions.InternalErrorException;
|
||||
import org.gcube.portlets.user.homelibrary.home.workspace.Workspace;
|
||||
|
@ -36,7 +33,6 @@ import org.gcube.portlets.user.homelibrary.home.workspace.exceptions.ItemNotFoun
|
|||
import org.gcube.portlets.user.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
||||
import org.gcube.portlets.user.homelibrary.home.workspace.exceptions.WrongDestinationException;
|
||||
import org.gcube.portlets.user.homelibrary.home.workspace.folder.FolderItem;
|
||||
import org.gcube.portlets.user.homelibrary.home.workspace.folder.items.ExternalFile;
|
||||
import org.gcube.portlets.user.homelibrary.home.workspace.folder.items.Report;
|
||||
import org.gcube.portlets.user.homelibrary.home.workspace.folder.items.ReportTemplate;
|
||||
import org.gcube.portlets.user.homelibrary.util.Extensions;
|
||||
|
@ -251,20 +247,7 @@ public class UploadServlet extends HttpServlet {
|
|||
|
||||
//we need to recalculate the item name
|
||||
itemName = WorkspaceUtil.getUniqueName(uploadItem.getName(), destinationFolder);
|
||||
|
||||
System.out.println("contentType "+contentType);
|
||||
|
||||
FolderItem createdItem = WorkspaceUtil.createExternalFile(destinationFolder, itemName, "", contentType, uploadItem.getInputStream());
|
||||
|
||||
File file = new File("/home/francesco-mangiacrapa/testhl");
|
||||
|
||||
IOUtils.copy(uploadItem.getInputStream(), new FileOutputStream(file));
|
||||
|
||||
|
||||
File file2 = new File("/home/francesco-mangiacrapa/createdItem");
|
||||
|
||||
IOUtils.copy(((ExternalFile) createdItem).getData(), new FileOutputStream(file2));
|
||||
|
||||
sendMessage(response, "File "+createdItem.getName()+" imported correctly in "+destinationFolder.getPath());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
package org.gcube.portlets.user.workspace.server.util;
|
||||
|
||||
import org.gcube.portlets.user.workspace.client.model.ScopeModel;
|
||||
|
||||
public class AllScope {
|
||||
|
||||
public static final String ALLSCOPE = "All spaces";
|
||||
public static final String IDALLSCOPE = "ID All spaces";
|
||||
private static ScopeModel allScope = null;
|
||||
|
||||
public static ScopeModel getScopeModel(){
|
||||
if(allScope==null)
|
||||
allScope = new ScopeModel(IDALLSCOPE, ALLSCOPE);
|
||||
|
||||
return allScope;
|
||||
}
|
||||
|
||||
}
|
|
@ -22,6 +22,7 @@ import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceItemType;
|
|||
import org.gcube.portlets.user.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
||||
import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder;
|
||||
import org.gcube.portlets.user.workspace.server.notifications.NotificationsProducer;
|
||||
import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -38,7 +39,7 @@ public class Util {
|
|||
public static final String NOTIFICATION_MANAGER = "NOTIFICATIONMANAGER";
|
||||
public static final String NOTIFICATION_PRODUCER = "NOTIFICATIONMANAGER";
|
||||
public static final String WS_RUN_IN_TEST_MODE = "WS_RUN_IN_TEST_MODE";
|
||||
|
||||
public static final String WORKSPACE_SCOPE_UTIL = "WORKSPACE_SCOPE_UTIL";
|
||||
public static final String NOTIFICATION_PORTLET_CLASS_ID = "org.gcube.portlets.user.wsmail.server.WsMailServiceImpl"; //IN DEV
|
||||
|
||||
// public static final String TEST_SCOPE = "/gcube/devsec";
|
||||
|
@ -54,7 +55,8 @@ public class Util {
|
|||
public static final String TEST_USER = "test.user";
|
||||
public static final String TEST_USER_FULL_NAME = "Test User";
|
||||
|
||||
public static GCUBEClientLog defaultLogger = new GCUBEClientLog("WorkspacePortlet");
|
||||
|
||||
public static GCUBEClientLog defaultLogger = new GCUBEClientLog(Util.class);
|
||||
|
||||
public static boolean withoutPortal = false;
|
||||
|
||||
|
@ -65,28 +67,39 @@ public class Util {
|
|||
ASLSession session;
|
||||
|
||||
if (user == null) {
|
||||
|
||||
//for test only
|
||||
// httpSession.setAttribute(USERNAME_ATTRIBUTE, TEST_USER);
|
||||
session = SessionManager.getInstance().getASLSession(sessionID, TEST_USER);
|
||||
|
||||
user=TEST_USER;
|
||||
|
||||
defaultLogger.warn("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND - PORTLETS STARTING WITH FOLLOWING SETTINGS:");
|
||||
defaultLogger.warn("session id: "+sessionID);
|
||||
defaultLogger.warn("TEST_USER: "+user);
|
||||
defaultLogger.warn("TEST_SCOPE: "+TEST_SCOPE);
|
||||
defaultLogger.warn("USERNAME_ATTRIBUTE: "+USERNAME_ATTRIBUTE);
|
||||
session = SessionManager.getInstance().getASLSession(sessionID, user);
|
||||
session.setScope(TEST_SCOPE);
|
||||
if(!withoutPortal){ //TEMPORARY SOLUTION
|
||||
defaultLogger.error("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND");
|
||||
session.setUserAvatarId(TEST_USER + "Avatar");
|
||||
session.setUserFullName(TEST_USER_FULL_NAME);
|
||||
session.setUserEmailAddress(TEST_USER + "@mail.test");
|
||||
// httpSession.setAttribute(USERNAME_ATTRIBUTE, user);
|
||||
}
|
||||
|
||||
//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;
|
||||
|
||||
}else{
|
||||
|
||||
session = SessionManager.getInstance().getASLSession(sessionID, user);
|
||||
|
||||
withoutPortal = false;
|
||||
}
|
||||
|
||||
return session;
|
||||
return SessionManager.getInstance().getASLSession(sessionID, user);
|
||||
}
|
||||
|
||||
|
||||
|
@ -241,5 +254,23 @@ public class Util {
|
|||
return wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ScopeUtilFilter getScopeUtilFilter(HttpSession httpSession){
|
||||
|
||||
ASLSession session = getAslSession(httpSession);
|
||||
ScopeUtilFilter scopeUtil = null;
|
||||
try{
|
||||
scopeUtil = (ScopeUtilFilter) session.getAttribute(Util.WORKSPACE_SCOPE_UTIL);
|
||||
|
||||
if(scopeUtil==null){
|
||||
scopeUtil = new ScopeUtilFilter(session.getScopeName());
|
||||
|
||||
}
|
||||
}catch (Exception e) {
|
||||
defaultLogger.error("an error occurred in getscope filter "+e);
|
||||
}
|
||||
|
||||
return scopeUtil;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,149 @@
|
|||
package org.gcube.portlets.user.workspace.server.util.scope;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.core.utils.logging.GCUBEClientLog;
|
||||
|
||||
|
||||
public class ScopeUtilFilter {
|
||||
|
||||
private static final String SCOPE_SEPARATOR = "/";
|
||||
private String scopeRoot = null;
|
||||
public static GCUBEClientLog logger = new GCUBEClientLog(ScopeUtilFilter.class);
|
||||
public Map<String, String> hashScopesFiltered = new HashMap<String, String>();
|
||||
|
||||
public static final String ALLSCOPE = "All spaces";
|
||||
public static final String IDALLSCOPE = "ID All spaces";
|
||||
|
||||
public ScopeUtilFilter(String scopeName) {
|
||||
|
||||
if(scopeName!=null){
|
||||
String[] scopes = scopeName.split(SCOPE_SEPARATOR);
|
||||
|
||||
if(scopes!=null && scopes.length>1){
|
||||
scopeRoot = SCOPE_SEPARATOR+scopes[1];
|
||||
logger.trace("found root "+scopeRoot);
|
||||
}
|
||||
else{
|
||||
logger.warn("root scope not found!");
|
||||
scopeRoot = SCOPE_SEPARATOR;
|
||||
}
|
||||
|
||||
hashScopesFiltered.put(ALLSCOPE, IDALLSCOPE); //PUT DEFAULT ID ALL SCOPE
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> convertListScopeToPortlet(List<String> listScopes){
|
||||
|
||||
logger.trace("Scope converting...");
|
||||
|
||||
List<String> scopesConverted = new ArrayList<String>();
|
||||
scopesConverted.add(ALLSCOPE);
|
||||
|
||||
if(scopeRoot.compareTo(SCOPE_SEPARATOR)==0){
|
||||
|
||||
logger.warn("root scope is '"+SCOPE_SEPARATOR+"' return list scopes passed in input");
|
||||
return listScopes;
|
||||
}
|
||||
|
||||
for (String scope : listScopes) {
|
||||
|
||||
if(scope.compareTo(scopeRoot)==0){ //CASE SCOPE IS ROOT
|
||||
|
||||
logger.trace("found scope root "+scope+" added to list without converting");
|
||||
|
||||
hashScopesFiltered.put(scopeRoot, scopeRoot);
|
||||
scopesConverted.add(scopeRoot);
|
||||
|
||||
} else{
|
||||
|
||||
int index = scope.indexOf(scopeRoot,0);
|
||||
int start = index+scopeRoot.length();
|
||||
int end = scope.length();
|
||||
//DEBUG
|
||||
// System.out.println("\n\n ");
|
||||
// System.out.println("index "+index);
|
||||
// System.out.println("start "+start);
|
||||
// System.out.println("end "+end);
|
||||
|
||||
if(index!=-1){ //CASE SCOPE ROOT IS FOUND
|
||||
|
||||
String filerString = scope.substring(index+start, scope.length());
|
||||
|
||||
hashScopesFiltered.put(filerString, scope);
|
||||
|
||||
scopesConverted.add(filerString);
|
||||
|
||||
logger.trace("scope "+scope+ " is converted in: "+filerString);
|
||||
|
||||
}else{ //CASE SCOPE ROOT NOT IS FOUND
|
||||
logger.warn("scope "+scope + " was reject from filter");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.trace("Scope converting was completed");
|
||||
|
||||
return scopesConverted;
|
||||
}
|
||||
|
||||
|
||||
public String getPortalScopeFromFilteredScope(String scope){
|
||||
|
||||
String portalScope = hashScopesFiltered.get(scope);
|
||||
|
||||
if(portalScope==null){
|
||||
logger.warn("scope not found in scope fiter, return root scope "+scopeRoot);
|
||||
return scopeRoot;
|
||||
}
|
||||
|
||||
return portalScope;
|
||||
}
|
||||
|
||||
public Map<String, String> getHashScopesFiltered() {
|
||||
return hashScopesFiltered;
|
||||
}
|
||||
|
||||
|
||||
//TEST
|
||||
private void printScopeName(String scopeName){
|
||||
|
||||
String[] scopes = scopeName.split(SCOPE_SEPARATOR);
|
||||
|
||||
for (String scope : scopes) {
|
||||
System.out.println("scope split: "+scope);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void printScopes(){
|
||||
|
||||
for (String key : hashScopesFiltered.keySet()) {
|
||||
|
||||
System.out.println("Scope found: "+ hashScopesFiltered.get(key) +" with key: "+ key);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String scope = "/gcube";
|
||||
|
||||
List<String> listTest = Arrays.asList(new String[]{"/gcube/devsec/devre", "/gcube/devsec","/gcube/devsec/devNEXT", "/", "/gcub", "/gcube"});
|
||||
|
||||
ScopeUtilFilter filter = new ScopeUtilFilter(scope);
|
||||
|
||||
filter.convertListScopeToPortlet(listTest);
|
||||
|
||||
|
||||
System.out.println("get portal scope "+filter.getPortalScopeFromFilteredScope("/devsec"));
|
||||
|
||||
filter.printScopes();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue