#24476 #10
|
@ -2,15 +2,23 @@ package org.gcube.application.geoportal.clients;
|
||||||
|
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.gcube.application.cms.tests.TokenSetter;
|
import org.gcube.application.cms.tests.TokenSetter;
|
||||||
|
import org.gcube.application.geoportal.client.utils.Serialization;
|
||||||
|
import org.gcube.application.geoportal.common.model.document.accounting.User;
|
||||||
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
||||||
|
import org.gcube.application.geoportal.common.model.useCaseDescriptor.DataAccessPolicy;
|
||||||
|
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||||
import org.gcube.application.geoportal.common.rest.UseCaseDescriptorsI;
|
import org.gcube.application.geoportal.common.rest.UseCaseDescriptorsI;
|
||||||
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.useCaseDescriptors;
|
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.useCaseDescriptors;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assume.assumeTrue;
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
|
||||||
public class UCDTests{
|
public class UCDTests{
|
||||||
|
@ -26,6 +34,7 @@ public class UCDTests{
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void query() throws Exception {
|
public void query() throws Exception {
|
||||||
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||||
UseCaseDescriptorsI client =getClient();
|
UseCaseDescriptorsI client =getClient();
|
||||||
QueryRequest request = new QueryRequest();
|
QueryRequest request = new QueryRequest();
|
||||||
// All
|
// All
|
||||||
|
@ -40,6 +49,7 @@ public class UCDTests{
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getByIdAll() throws Exception {
|
public void getByIdAll() throws Exception {
|
||||||
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||||
UseCaseDescriptorsI client =getClient();
|
UseCaseDescriptorsI client =getClient();
|
||||||
|
|
||||||
QueryRequest request = new QueryRequest();
|
QueryRequest request = new QueryRequest();
|
||||||
|
@ -57,8 +67,26 @@ public class UCDTests{
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getById() throws Exception {
|
public void getById() throws Exception {
|
||||||
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||||
UseCaseDescriptorsI client =getClient();
|
UseCaseDescriptorsI client =getClient();
|
||||||
|
|
||||||
System.out.println(client.getById("profiledConcessioni"));
|
System.out.println(client.getById("profiledConcessioni"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkPolicies() throws Exception {
|
||||||
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||||
|
UseCaseDescriptorsI client =getClient();
|
||||||
|
UseCaseDescriptor ucd = client.getById("profiledConcessioni");
|
||||||
|
System.out.println(Serialization.write(ucd));
|
||||||
|
User u = new User();
|
||||||
|
u.setRoles(new HashSet<>());
|
||||||
|
u.getRoles().addAll(Arrays.asList("Members","Data-Manager"));
|
||||||
|
|
||||||
|
DataAccessPolicy p = ucd.getMatching(u);
|
||||||
|
System.out.println("Evaluated policy : "+Serialization.write(p));
|
||||||
|
assertEquals(p.getPolicy().getRead(), DataAccessPolicy.Policy.Type.any);
|
||||||
|
assertEquals(p.getPolicy().getWrite(), DataAccessPolicy.Policy.Type.any);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,6 +121,8 @@ public class UseCaseDescriptor implements Serializable {
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public DataAccessPolicy getMatching(User u){
|
public DataAccessPolicy getMatching(User u){
|
||||||
|
// TODO Evaluate higher permits
|
||||||
|
|
||||||
DataAccessPolicy defaultPolicy = null;
|
DataAccessPolicy defaultPolicy = null;
|
||||||
if(dataAccessPolicies!=null)
|
if(dataAccessPolicies!=null)
|
||||||
for (DataAccessPolicy dataAccessPolicy : dataAccessPolicies) {
|
for (DataAccessPolicy dataAccessPolicy : dataAccessPolicies) {
|
||||||
|
|
|
@ -17,7 +17,7 @@ public class GCubeTest {
|
||||||
|
|
||||||
testContext = "/pred4s/preprod/preVRE";
|
testContext = "/pred4s/preprod/preVRE";
|
||||||
// testContext = "/d4science.research-infrastructures.eu/D4OS/GNA";
|
// testContext = "/d4science.research-infrastructures.eu/D4OS/GNA";
|
||||||
// testContext= "/gcube/devsec/devVRE";
|
// testContext= "/gcube/devsec/devVRE";
|
||||||
|
|
||||||
System.out.println("TEST CONTEXT = "+testContext);
|
System.out.println("TEST CONTEXT = "+testContext);
|
||||||
return testContext;
|
return testContext;
|
||||||
|
|
|
@ -18,12 +18,16 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"_dataAccessPolicies" : [
|
"_dataAccessPolicies": [
|
||||||
{"_policy" : {"_read" : "own", "_write" : "own"}, "_roles":[]},
|
{"_policy": {"_read": "any","_write": "any"},
|
||||||
{"_policy" : {"_read" : "any", "_write" : "none"}, "_roles":["Guest"],
|
"_roles": ["Data-Manager"]},
|
||||||
"_enforcer": {"_filter" : "{\"_lifecycleInformation._phase\" : {\"$eq\" : \"PUBLISHED\"}}"}},
|
{"_policy": {"_read": "own","_write": "own"},
|
||||||
{"_policy" : {"_read" : "any", "_write" : "none"}, "_roles":["Editor"]},
|
"_roles": ["Data-Editor"]},
|
||||||
{"_policy" : {"_read" : "any", "_write" : "any"}, "_roles":["Admin"]}
|
{"_policy": {"_read": "any","_write": "none"},
|
||||||
|
"_roles": ["Member"],
|
||||||
|
"_enforcer": {"_filter": "{\"_lifecycleInformation._phase\" : {\"$eq\" : \"Published\"}}"}},
|
||||||
|
{"_policy": {"_read": "none","_write": "none"},
|
||||||
|
"_roles": []}
|
||||||
],
|
],
|
||||||
|
|
||||||
"_relationshipDefinitions" : [
|
"_relationshipDefinitions" : [
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class ExportConcessioniAsProjects {
|
||||||
File dir= new File("/Users/fabioisti/git/gcube-cms-suite/import1669889538860");
|
File dir= new File("/Users/fabioisti/git/gcube-cms-suite/import1669889538860");
|
||||||
|
|
||||||
// select only cluster
|
// select only cluster
|
||||||
// dir = new File(dir,"cluster_1");
|
dir = new File(dir,"61d5ec7495184b186ad0c2e4");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue