updated test

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@113478 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2015-03-05 17:47:07 +00:00
parent 500864da5f
commit f47867e50b
2 changed files with 184 additions and 12 deletions

View File

@ -0,0 +1,142 @@
/**
*
*/
package org.gcube.portlets.user.workspace;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.exceptions.UserNotFoundException;
import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
import org.gcube.common.homelibrary.home.workspace.accessmanager.ACLType;
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.portlets.user.workspace.server.util.AclTypeComparator;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Jan 29, 2014
*
*/
public class EditPermissionsTest {
// public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps"; //PRODUCTION
public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
public static String TEST_USER = "francesco.mangiacrapa";
// public static String ITEMID = "63832213-098d-42d1-8774-89b6349764c0"; //Activity T3.4 working drafts/T2-EC-IMAR-HO-14-015 iMarine Sustainability WP - Business Model tools.pdf
// public static String ITEMID = "42fa2601-39d0-4951-aabf-27d2a2f1dca7";
// protected static Logger logger = Logger.getLogger(EditPermissionsTest.class);
public static void main(String[] args) {
ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
ScopeProvider.instance.set(scope.toString());
System.out.println("init HL");
try {
Workspace ws = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
.getHome(TEST_USER)
.getWorkspace();
// a65d0c7a-5ef3-4e61-b12f-715146368b6b shared folder name: My Data owner pasquale.pagano isVRE false ACLOwner: {ADMINISTRATOR=[pasquale.pagano], WRITE_OWNER=[leonardo.candela, francesco.mangiacrapa, giancarlo.panichi]} AclUser: WRITE_OWNER
WorkspaceFolder sharedFolder = (WorkspaceFolder) ws.getItem("a65d0c7a-5ef3-4e61-b12f-715146368b6b");
System.out.println(sharedFolder.getACLOwner());
ArrayList<String> list = new ArrayList<String>();
list.add("francesco.mangiacrapa");
list.add("massimiliano.assante");
list.add("pasquale.pagano");
validateACLToUser(sharedFolder, list, ACLType.WRITE_ALL.toString());
} catch (WorkspaceFolderNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InternalErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (HomeNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UserNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ItemNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void validateACLToUser(WorkspaceFolder folder, List<String> listLogins, String aclType) {
try {
Map<ACLType, List<String>> mapACL = folder.getACLOwner();
ACLType settingACL = ACLType.valueOf(aclType);
System.out.println("Tentative setting: "+settingACL);
AclTypeComparator comparator = new AclTypeComparator();
List<String> admins = mapACL.get(ACLType.ADMINISTRATOR);
for (String admin : admins) {
listLogins.remove(admin);
System.out.println("Reject username: "+admin +" as "+ACLType.ADMINISTRATOR);
}
for (String username : listLogins) {
System.out.println("Checking username: "+username);
for (ACLType aclHL : mapACL.keySet()) {
if(!aclHL.equals(ACLType.ADMINISTRATOR)){
List<String> 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){
//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);
}
}else{
//CHANGE ACL IS VALID
System.out.println("[Login not found], Set ACL: "+settingACL+ " to "+username);
}
}
}
}
} catch (InternalErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@ -4,16 +4,24 @@
package org.gcube.portlets.user.workspace;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.log4j.Logger;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.exceptions.UserNotFoundException;
import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder;
import org.gcube.common.homelibrary.home.workspace.accessmanager.ACLType;
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.portlets.user.workspace.server.util.AclTypeComparator;
/**
*
@ -24,29 +32,52 @@ import org.gcube.common.scope.impl.ScopeBean;
public class ItemRetrieving {
public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps"; //PRODUCTION
// public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
public static String TEST_USER = "leonardo.candela";
// public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps"; //PRODUCTION
public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
public static String TEST_USER = "francesco.mangiacrapa";
// public static String ITEMID = "63832213-098d-42d1-8774-89b6349764c0"; //Activity T3.4 working drafts/T2-EC-IMAR-HO-14-015 iMarine Sustainability WP - Business Model tools.pdf
public static String ITEMID = "42fa2601-39d0-4951-aabf-27d2a2f1dca7";
// public static String ITEMID = "42fa2601-39d0-4951-aabf-27d2a2f1dca7";
protected static Logger logger = Logger.getLogger(ItemRetrieving.class);
public static void main(String[] args) {
ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
ScopeProvider.instance.set(scope.toString());
System.out.println("init HL");
try {
ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
ScopeProvider.instance.set(scope.toString());
System.out.println("init HL");
Workspace ws = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
.getHome(TEST_USER)
.getWorkspace();
//
retrieveFirstLevel(ws);
} catch (WorkspaceFolderNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InternalErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (HomeNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UserNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void retrieveFirstLevel(Workspace ws){
try {
//TEST TIME
Long startTime = System.currentTimeMillis();
Long endTime = System.currentTimeMillis() - startTime;
@ -85,7 +116,7 @@ public class ItemRetrieving {
WorkspaceSharedFolder shared = (WorkspaceSharedFolder) workspaceItem;
System.out.println(++i+") "+shared.getId() +" shared folder name: "+shared.getName() + " owner "+shared.getOwner().getPortalLogin() +" isVRE "+shared.isVreFolder());
System.out.println(++i+") "+shared.getId() +" shared folder name: "+shared.getName() + " owner "+shared.getOwner().getPortalLogin() +" isVRE "+shared.isVreFolder() +" ACLOwner: "+shared.getACLOwner()+" AclUser: "+shared.getACLUser());
// System.out.println(++i+") shared folder name: "+shared.getName() + " owner "+shared.getOwner().getPortalLogin());
sharedFoldersCounter++;
@ -120,5 +151,4 @@ public class ItemRetrieving {
e.printStackTrace();
}
}
}