fixed VO name
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-sharing-widget@98777 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
85dd5b6d9e
commit
a769cb4668
|
@ -1,3 +1,2 @@
|
|||
#Thu Jun 16 10:18:26 CEST 2011
|
||||
eclipse.preferences.version=1
|
||||
filesCopiedToWebInfLib=
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.gcube.portlets.widgets.workspacesharingwidget.client.ConstantsSharing
|
|||
import org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService;
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.server.notifications.NotificationsProducer;
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.server.notifications.NotificationsUtil;
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.ScopeUtilFilter;
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.ScopeUtility;
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.UserUtil;
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.WsUtil;
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.shared.CredentialModel;
|
||||
|
@ -68,7 +68,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
|
|||
return WsUtil.getNotificationProducer(WsUtil.getAslSession(this.getThreadLocalRequest().getSession()));
|
||||
}
|
||||
|
||||
protected ScopeUtilFilter getScopeUtilFilter(){
|
||||
protected ScopeUtility getScopeUtilFilter(){
|
||||
|
||||
return WsUtil.getScopeUtilFilter(this.getThreadLocalRequest().getSession());
|
||||
}
|
||||
|
@ -135,9 +135,20 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
|
|||
PortalContext context = PortalContext.getConfiguration();
|
||||
logger.info("context.getInfrastructureName(): "+context.getInfrastructureName());
|
||||
logger.info("aslSession.getGroupName(): "+ aslSession.getGroupName());
|
||||
List<VO> lsVOs = WsUtil.getVresFromInfrastructure(context.getInfrastructureName(), aslSession.getGroupName());
|
||||
String vrePath = ConstantsSharing.PATH_SEPARATOR+context.getInfrastructureName() + ConstantsSharing.PATH_SEPARATOR + aslSession.getGroupName() + ConstantsSharing.PATH_SEPARATOR;
|
||||
listContactsModel.addAll(builder.buildGXTListContactsModelFromVOs(lsVOs, vrePath));
|
||||
try{
|
||||
ScopeUtility scopeUtility = new ScopeUtility(aslSession.getGroupName());
|
||||
|
||||
if(scopeUtility.getVo()!=null){
|
||||
logger.info("VO is not null, trying to calculate List VO");
|
||||
List<VO> lsVOs = WsUtil.getVresFromInfrastructure(context.getInfrastructureName(), aslSession.getGroupName());
|
||||
String vrePath = ConstantsSharing.PATH_SEPARATOR+context.getInfrastructureName() + ConstantsSharing.PATH_SEPARATOR + aslSession.getGroupName() + ConstantsSharing.PATH_SEPARATOR;
|
||||
listContactsModel.addAll(builder.buildGXTListContactsModelFromVOs(lsVOs, vrePath));
|
||||
}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());
|
||||
|
@ -150,6 +161,8 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<InfoContactModel> getListUserSharedByFolderSharedId(String folderSharedId) throws Exception{
|
||||
|
||||
|
|
|
@ -1,156 +0,0 @@
|
|||
package org.gcube.portlets.widgets.workspacesharingwidget.server.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class ScopeUtilFilter {
|
||||
|
||||
private static final String SCOPE_SEPARATOR = "/";
|
||||
private String scopeRoot = null;
|
||||
public static Logger logger = LoggerFactory.getLogger(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.info("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.info("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.info("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.info("scope "+scope+ " is converted in: "+filerString);
|
||||
|
||||
}else{ //CASE SCOPE ROOT NOT IS FOUND
|
||||
logger.warn("scope "+scope + " was reject from filter");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("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 String getScopeRoot() {
|
||||
return scopeRoot;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
System.out.println("scope root is: "+filter.getScopeRoot());
|
||||
|
||||
filter.convertListScopeToPortlet(listTest);
|
||||
|
||||
|
||||
System.out.println("get portal scope "+filter.getPortalScopeFromFilteredScope("/devsec"));
|
||||
|
||||
filter.printScopes();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
package org.gcube.portlets.widgets.workspacesharingwidget.server.util;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class ScopeUtility {
|
||||
|
||||
private static final String SCOPE_SEPARATOR = "/";
|
||||
private String root;
|
||||
private String vo;
|
||||
private String vre;
|
||||
public static Logger logger = LoggerFactory.getLogger(ScopeUtility.class);
|
||||
|
||||
|
||||
public ScopeUtility(String scopeName) throws Exception {
|
||||
|
||||
if(scopeName!=null){
|
||||
String[] scopes = scopeName.split(SCOPE_SEPARATOR);
|
||||
|
||||
if(scopes==null)
|
||||
return;
|
||||
|
||||
for (int i=0; i<scopes.length; i++) {
|
||||
logger.info("splitted scope is "+scopes[i]);
|
||||
}
|
||||
|
||||
if(scopes!=null && scopes.length>1){
|
||||
|
||||
if(scopes[0]==null || scopes[0].isEmpty())
|
||||
setScopeLevels(scopes, 1);
|
||||
else
|
||||
setScopeLevels(scopes, 0);
|
||||
}
|
||||
else{
|
||||
logger.warn("root scope not found!");
|
||||
root = SCOPE_SEPARATOR;
|
||||
throw new Exception("Root scope not found");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void setScopeLevels(String[] scopes, int startIndex){
|
||||
try{
|
||||
logger.info("splitted scopes legth is "+scopes.length);
|
||||
root = SCOPE_SEPARATOR+scopes[startIndex];
|
||||
logger.info("root is "+root);
|
||||
|
||||
int voIndex = startIndex+1;
|
||||
// logger.info("vo index is "+voIndex);
|
||||
if(scopes.length > voIndex)
|
||||
vo = root+SCOPE_SEPARATOR+scopes[voIndex];
|
||||
|
||||
int vreIndex = startIndex+2;
|
||||
// logger.info("vre index is "+vreIndex);
|
||||
if(scopes.length > vreIndex)
|
||||
vre = vo + SCOPE_SEPARATOR + scopes[vreIndex];
|
||||
|
||||
logger.info("vo is "+vo);
|
||||
logger.info("vre is "+vre);
|
||||
}catch(Exception e){
|
||||
logger.error("Error occurred when calculating scope levels: ",e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getScopeRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
public String getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
public String getVo() {
|
||||
return vo;
|
||||
}
|
||||
|
||||
public String getVre() {
|
||||
return vre;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("ScopeUtility [root=");
|
||||
builder.append(root);
|
||||
builder.append(", vo=");
|
||||
builder.append(vo);
|
||||
builder.append(", vre=");
|
||||
builder.append(vre);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String scope = "/gcube/devsec/devNEXT";
|
||||
|
||||
try {
|
||||
ScopeUtility filter = new ScopeUtility(scope);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -258,15 +258,15 @@ public class WsUtil {
|
|||
|
||||
}
|
||||
|
||||
public static ScopeUtilFilter getScopeUtilFilter(HttpSession httpSession){
|
||||
public static ScopeUtility getScopeUtilFilter(HttpSession httpSession){
|
||||
|
||||
ASLSession session = getAslSession(httpSession);
|
||||
ScopeUtilFilter scopeUtil = null;
|
||||
ScopeUtility scopeUtil = null;
|
||||
try{
|
||||
scopeUtil = (ScopeUtilFilter) session.getAttribute(WsUtil.WORKSPACE_SCOPE_UTIL);
|
||||
scopeUtil = (ScopeUtility) session.getAttribute(WsUtil.WORKSPACE_SCOPE_UTIL);
|
||||
|
||||
if(scopeUtil==null){
|
||||
scopeUtil = new ScopeUtilFilter(session.getScopeName());
|
||||
scopeUtil = new ScopeUtility(session.getScopeName());
|
||||
|
||||
}
|
||||
}catch (Exception e) {
|
||||
|
|
Loading…
Reference in New Issue