From 085074740a6e8e4864b9f6f716e0a36971182a41 Mon Sep 17 00:00:00 2001 From: Fabio Sinibaldi Date: Wed, 30 Mar 2022 18:39:10 +0200 Subject: [PATCH] Bugfixing --- .../application/cms/caches/TimedMap.java | 4 +- .../ImplementationProvider.java | 9 + .../AbstractLifeCycleManager.java | 1 + .../plugins/reports/EventExecutionReport.java | 1 + .../useCaseDescriptor/UseCaseDescriptor.java | 16 +- .../geoportal/common/utils/ContextUtils.java | 8 +- .../common/utils/tests/GCubeTest.java | 2 +- .../geoportal/service/GeoPortalService.java | 22 +- .../service/engine/mongo/MongoManager.java | 6 +- .../ucd/LocalFolderProfileMapCache.java | 35 ++- .../engine/providers/ucd/UCDManager.java | 10 +- .../geoportal/service/rest/GuardedMethod.java | 4 +- .../geoportal/service/utils/UserUtils.java | 4 +- .../service/BasicServiceTestUnit.java | 24 +- .../InexistentUseCaseDescriptorTests.java | 22 +- .../service/engine/mongo/LockTests.java | 4 +- .../service/engine/profiles/UCDCalls.java | 2 +- .../engine/providers/ucd/UCDLoadingTest.java | 10 +- .../AbstractProfiledDocumentsTests.java | 2 +- .../service/profiledDocuments/RolesTests.java | 2 +- .../src/test/resources/logback.xml | 2 +- .../test/resources/profiles/rolesTesting.json | 6 +- .../profiles/profiledConcessioni.json | 215 ++++++++++++++++++ .../profiles/rolesTesting.json | 20 ++ 24 files changed, 373 insertions(+), 58 deletions(-) create mode 100644 test-data/profiledDocuments/profiles/profiledConcessioni.json create mode 100644 test-data/profiledDocuments/profiles/rolesTesting.json diff --git a/cms-plugin-framework/src/main/java/org/gcube/application/cms/caches/TimedMap.java b/cms-plugin-framework/src/main/java/org/gcube/application/cms/caches/TimedMap.java index ad37383..fa17a6f 100644 --- a/cms-plugin-framework/src/main/java/org/gcube/application/cms/caches/TimedMap.java +++ b/cms-plugin-framework/src/main/java/org/gcube/application/cms/caches/TimedMap.java @@ -48,8 +48,8 @@ public abstract class TimedMap implements Cache { scopeMap.put(key, newer); found=scopeMap.get(key); } - }else {log.debug(name+" : TTL is null, never disposing..");} - log.debug(name+"Returning {} ",found); + }else {log.trace(name+" : TTL is null, never disposing..");} + log.trace(name+"Returning {} ",found); return found.getTheObject(); } diff --git a/cms-plugin-framework/src/main/java/org/gcube/application/cms/implementations/ImplementationProvider.java b/cms-plugin-framework/src/main/java/org/gcube/application/cms/implementations/ImplementationProvider.java index fd51ec9..455584d 100644 --- a/cms-plugin-framework/src/main/java/org/gcube/application/cms/implementations/ImplementationProvider.java +++ b/cms-plugin-framework/src/main/java/org/gcube/application/cms/implementations/ImplementationProvider.java @@ -6,6 +6,8 @@ import org.gcube.application.cms.caches.Cache; import org.gcube.application.cms.caches.Engine; import org.gcube.application.geoportal.common.model.rest.ConfigurationException; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; public class ImplementationProvider { @@ -36,4 +38,11 @@ public class ImplementationProvider { //Defaults setEngine(new DefaultISProvider(),ISInterface.class); } + public Map getManagerList(){ + HashMap toReturn=new HashMap<>(); + implementationsRegistry.forEach( + (aClass, engine) -> {toReturn.put(engine.getClass(),aClass.getCanonicalName());} + ); + return toReturn; + } } diff --git a/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/implementations/AbstractLifeCycleManager.java b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/implementations/AbstractLifeCycleManager.java index 56e64e0..771bba3 100644 --- a/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/implementations/AbstractLifeCycleManager.java +++ b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/implementations/AbstractLifeCycleManager.java @@ -177,6 +177,7 @@ public abstract class AbstractLifeCycleManager extends AbstractPlugin implements @Override public EventExecutionReport onEvent(EventExecutionRequest request) throws EventException, InvalidPluginRequestException { EventExecutionReport report=new EventExecutionReport(request); + report.getToSetLifecycleInformation().addEventReport(new TriggeredEvents()); TriggeredEvents info = report.getToSetLifecycleInformation().getLastEvent(); try { if(!registeredEvent.containsKey(request.getEvent())) diff --git a/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/reports/EventExecutionReport.java b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/reports/EventExecutionReport.java index 018ab64..21c62a8 100644 --- a/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/reports/EventExecutionReport.java +++ b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/reports/EventExecutionReport.java @@ -11,6 +11,7 @@ public class EventExecutionReport extends DocumentHandlingReport Handler Declaration * @return */ - @JsonIgnore public Map> getHandlersMapByType(){ HashMap> toReturn=new HashMap<>(); @@ -100,13 +99,14 @@ public class UseCaseDescriptor { @JsonIgnore public DataAccessPolicy getMatching(User u){ DataAccessPolicy defaultPolicy = null; - for (DataAccessPolicy dataAccessPolicy : dataAccessPolicies) { - if(dataAccessPolicy.getRoles()==null||dataAccessPolicy.getRoles().isEmpty()) - defaultPolicy= dataAccessPolicy; - for (String r : dataAccessPolicy.getRoles()) - if (u.getRoles().contains(r)) - return dataAccessPolicy; - } + if(dataAccessPolicies!=null) + for (DataAccessPolicy dataAccessPolicy : dataAccessPolicies) { + if(dataAccessPolicy.getRoles()==null||dataAccessPolicy.getRoles().isEmpty()) + defaultPolicy= dataAccessPolicy; + for (String r : dataAccessPolicy.getRoles()) + if (u.getRoles().contains(r)) + return dataAccessPolicy; + } return defaultPolicy; } diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/utils/ContextUtils.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/utils/ContextUtils.java index 6adb30a..fe15a18 100644 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/utils/ContextUtils.java +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/utils/ContextUtils.java @@ -15,12 +15,12 @@ public class ContextUtils { public static String getCurrentScope(){ try{ String token=SecurityTokenProvider.instance.get(); - log.debug("Token is : "+token.substring(0,2)+"..."+token.substring(token.length()-3)); + log.trace("Token is : "+token.substring(0,2)+"..."+token.substring(token.length()-3)); if(token==null) throw new Exception("Security Token is null"); AuthorizationEntry entry = authorizationService().get(token); return entry.getContext(); }catch(Exception e ){ - log.debug("Unable to resolve token, checking scope provider..",e); + log.trace("Unable to resolve token, checking scope provider..",e); return ScopeProvider.instance.get(); } } @@ -29,12 +29,12 @@ public class ContextUtils { public static String getCurrentCaller(){ try{ String token=SecurityTokenProvider.instance.get(); - log.debug("Token is : "+token.substring(0,2)+"..."+token.substring(token.length()-3)); + log.trace("Token is : "+token.substring(0,2)+"..."+token.substring(token.length()-3)); if(token==null) throw new Exception("Security Token is null"); AuthorizationEntry entry = authorizationService().get(token); return entry.getClientInfo().getId(); }catch(Exception e ){ - log.debug("Unable to resolve token, checking scope provider..",e); + log.trace("Unable to resolve token, checking scope provider..",e); return "Unidentified data-transfer user"; } } diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/utils/tests/GCubeTest.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/utils/tests/GCubeTest.java index bd9c3c5..172836a 100644 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/utils/tests/GCubeTest.java +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/utils/tests/GCubeTest.java @@ -11,7 +11,7 @@ public class GCubeTest { } - // testContext = "/pred4s/preprod/preVRE"; +// testContext = "/pred4s/preprod/preVRE"; testContext = "/gcube/devsec/devVRE"; diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java index 95e7500..255c948 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/GeoPortalService.java @@ -2,6 +2,7 @@ package org.gcube.application.geoportal.service; import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; import lombok.extern.slf4j.Slf4j; +import org.gcube.application.cms.caches.Engine; import org.gcube.application.cms.implementations.ImplementationProvider; import org.gcube.application.geoportal.common.rest.InterfaceConstants; import org.gcube.application.geoportal.common.utils.StorageUtils; @@ -20,20 +21,25 @@ import org.gcube.application.geoportal.service.rest.ProfiledDocuments; import org.gcube.application.cms.serialization.Serialization; import org.gcube.application.geoportal.service.rest.UseCaseDescriptors; import org.gcube.common.storagehub.client.dsl.StorageHubClient; +import org.geotoolkit.internal.sql.table.Entry; import org.glassfish.jersey.server.ResourceConfig; import javax.ws.rs.ApplicationPath; +import java.util.Collections; +import java.util.Map; @ApplicationPath(InterfaceConstants.APPLICATION_PATH) @Slf4j public class GeoPortalService extends ResourceConfig{ - + public Map,Class> customImplementations(){ + return Collections.EMPTY_MAP; + } public GeoPortalService() { super(); //Register interrfaces -// registerClasses(Concessioni.class); + registerClasses(ConcessioniOverMongo.class); registerClasses(ProfiledDocuments.class); @@ -44,7 +50,6 @@ public class GeoPortalService extends ResourceConfig{ ImplementationProvider.get().setEngine(new MongoClientProvider(), Mongo.class); ImplementationProvider.get().setEngine(new StorageClientProvider(), StorageUtils.class); ImplementationProvider.get().setEngine(new PostgisConnectionProvider(), PostgisDBManager.class); -// ImplementationProvider.get().setEngine(new LocalFolderProfileMapCache(), ProfileMap.class); ImplementationProvider.get().setEngine(new SingleISResourceUCDProvider(), ProfileMap.class); ImplementationProvider.get().setEngine(new PluginManager(), PluginManager.PluginMap.class); ImplementationProvider.get().setEngine(new StorageHubProvider(), StorageHubClient.class); @@ -52,6 +57,17 @@ public class GeoPortalService extends ResourceConfig{ ImplementationProvider.get().setEngine(new ConfigurationCache(), ConfigurationCache.ConfigurationMap.class); + for(Map.Entry, Class> entry : customImplementations().entrySet()){ + log.warn("LOADING CUSTOM ENGINE : {} serving {}",entry.getKey(),entry.getValue()); + ImplementationProvider.get().setEngine(entry.getKey(), entry.getValue()); + } + + log.debug("ENGINES ARE : "); + ImplementationProvider.get().getManagerList().forEach( + (aClass, s) -> log.debug("{} serving {} ",aClass,s)); + + + log.info("Initializing serialization"); JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider(); provider.setMapper(Serialization.mapper); register(provider); diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/MongoManager.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/MongoManager.java index 3100a29..38dc87d 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/MongoManager.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/MongoManager.java @@ -39,7 +39,7 @@ public abstract class MongoManager { public MongoManager() throws ConfigurationException { client=ImplementationProvider.get().getEngineByManagedClass(Mongo.class); - log.debug("Cached client is {} ",client); + log.trace("Cached client is {} ",client); } protected void init(String collectionName){ @@ -92,9 +92,9 @@ public abstract class MongoManager { public FindIterable iterateDoc(Document filter, Document projection) { MongoCollection coll=getCollection(); if(filter == null) filter=new Document(); - log.debug("Applying Filter "+filter.toJson()); + log.trace("Applying Filter "+filter.toJson()); if(projection != null ) { - log.debug("Applying projection "+projection.toJson()); + log.trace("Applying projection "+projection.toJson()); return coll.find(filter).projection(projection); }else return coll.find(filter); } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/ucd/LocalFolderProfileMapCache.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/ucd/LocalFolderProfileMapCache.java index 652a970..e343f39 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/ucd/LocalFolderProfileMapCache.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/ucd/LocalFolderProfileMapCache.java @@ -1,6 +1,7 @@ package org.gcube.application.geoportal.service.engine.providers.ucd; import com.fasterxml.jackson.core.JsonProcessingException; +import com.mongodb.util.JSON; import lombok.extern.slf4j.Slf4j; import org.gcube.application.cms.caches.AbstractScopedMap; import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; @@ -8,14 +9,19 @@ import org.gcube.application.geoportal.common.utils.Files; import org.gcube.application.geoportal.common.model.rest.ConfigurationException; import org.gcube.application.cms.serialization.Serialization; +import java.io.File; +import java.io.FileFilter; import java.io.IOException; import java.nio.charset.Charset; @Slf4j public class LocalFolderProfileMapCache extends AbstractScopedMap { - public LocalFolderProfileMapCache() { + String folderPath = null; + + public LocalFolderProfileMapCache(String folderPath) { super("Local Profiles CACHE"); + this.folderPath=folderPath; } @Override @@ -26,7 +32,8 @@ public class LocalFolderProfileMapCache extends AbstractScopedMap { protected void dispose(ProfileMap toDispose) { } - + + @Override protected ProfileMap retrieveObject(String context) throws ConfigurationException { @@ -35,17 +42,23 @@ public class LocalFolderProfileMapCache extends AbstractScopedMap { ProfileMap toReturn=new ProfileMap(); try { - UseCaseDescriptor p=Serialization.read(Files. - readFileAsString(Files.getFileFromResources("profiles/profiledConcessioni.json").getAbsolutePath(), Charset.defaultCharset()), UseCaseDescriptor.class); - log.debug("Loaded "+p.getName()+" ID "+p.getId()); - toReturn.put(p.getId(),p); + log.debug("Loading from {} ",folderPath); + File baseFolder = new File (folderPath); + for (File file : baseFolder.listFiles(pathname -> pathname.getName().endsWith(".json"))) { + try { + UseCaseDescriptor p = Serialization.read(Files.readFileAsString(file.getAbsolutePath(), Charset.defaultCharset()), UseCaseDescriptor.class); + toReturn.put(p.getId(),p); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } - - }catch (JsonProcessingException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); + }catch(Throwable t){ + t.printStackTrace(); } + return toReturn; } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/ucd/UCDManager.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/ucd/UCDManager.java index 7ef69a7..e356fa2 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/ucd/UCDManager.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/ucd/UCDManager.java @@ -97,17 +97,17 @@ public class UCDManager extends AbstractScopedMap implements UCDMan private void forceUpdateCache() throws ConfigurationException { - log.trace("UPDATING PROFILE CACHE.."); + log.info("UPDATING PROFILE CACHE.."); final UCDMongoManager manager = getMongoManager(); final AtomicLong counter= new AtomicLong(0l); - for (Map.Entry entry : getLiveMap().entrySet()) { - String s = entry.getKey(); + ProfileMap liveMap=getLiveMap(); + log.debug("LiveMap size is {} ",liveMap.size()); + for (Map.Entry entry : liveMap.entrySet()) { UseCaseDescriptor useCaseDescriptor = entry.getValue(); try { - log.info("Updateing cache with {} ", useCaseDescriptor.getId()); + log.debug("Updateing cache with {} ", useCaseDescriptor.getId()); // insert/update into DB manager.put(useCaseDescriptor); - } catch (RegistrationException e) { log.warn("Unable to cache UCD {}",entry.getKey(),e); } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GuardedMethod.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GuardedMethod.java index bf0b6ee..9e4d7a6 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GuardedMethod.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/GuardedMethod.java @@ -27,11 +27,11 @@ public abstract class GuardedMethod { public GuardedMethod execute() throws WebApplicationException{ try { if(!preoperations.isEmpty()) { - log.debug("Running preops (size : {} )", preoperations.size()); + log.trace("Running preops (size : {} )", preoperations.size()); for (Runnable r : preoperations) r.run(); } - log.debug("Executing actual method.."); + log.trace("Executing actual method.."); result=run(); return this; }catch(WebApplicationException e) { diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/utils/UserUtils.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/utils/UserUtils.java index 664a3eb..922f9e5 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/utils/UserUtils.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/utils/UserUtils.java @@ -13,6 +13,7 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.api.ScopeProvider; import java.time.LocalDateTime; +import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -85,7 +86,8 @@ public class UserUtils { }catch(Exception e){ log.warn("Unable to determine user id, using FAKE"); user.setUsername("FAKE"); - user.setRoles(Collections.EMPTY_SET); + user.setRoles(new HashSet<>()); + user.getRoles().addAll(Arrays.asList(new String[] {"FakeUser","FakeAdmin","FakeEditor"})); } info.setUser(user); diff --git a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/BasicServiceTestUnit.java b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/BasicServiceTestUnit.java index 65e65d6..522e003 100644 --- a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/BasicServiceTestUnit.java +++ b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/BasicServiceTestUnit.java @@ -1,7 +1,9 @@ package org.gcube.application.geoportal.service; import lombok.extern.slf4j.Slf4j; +import org.gcube.application.cms.caches.Engine; import org.gcube.application.cms.implementations.ImplementationProvider; +import org.gcube.application.cms.tests.TestProfiles; import org.gcube.application.cms.tests.TokenSetter; import org.gcube.application.geoportal.common.utils.tests.GCubeTest; import org.gcube.application.geoportal.service.engine.providers.ucd.LocalFolderProfileMapCache; @@ -10,34 +12,48 @@ import org.gcube.application.geoportal.service.rest.GuardedMethod; import org.gcube.application.cms.serialization.Serialization; import org.glassfish.jersey.test.JerseyTest; import org.junit.BeforeClass; +import org.opengis.annotation.Profile; import javax.ws.rs.core.Application; import javax.ws.rs.core.Response; +import java.util.Collections; +import java.util.Map; + import static org.junit.Assume.assumeTrue; @Slf4j public class BasicServiceTestUnit extends JerseyTest { + + @Override protected Application configure() { - return new GeoPortalService(); + return new GeoPortalService(){ + @Override + public Map, Class> customImplementations() { + return Collections.singletonMap((Engine) + new LocalFolderProfileMapCache(TestProfiles.BASE_FOLDER.getAbsolutePath()),ProfileMap.class); + } + }; } - + + // Loads UCDs from local folder + @BeforeClass public static void init() { GuardedMethod.addPreoperation(new Runnable() { @Override public void run() { + String context = GCubeTest.getContext(); log.debug("TEST IMPL : Setting context "+context+" in received call"); TokenSetter.set(context); } }); - // Loads UCDs from local folder - ImplementationProvider.get().setEngine(new LocalFolderProfileMapCache(), ProfileMap.class); + } diff --git a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/InexistentUseCaseDescriptorTests.java b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/InexistentUseCaseDescriptorTests.java index d0203d8..d2f83bd 100644 --- a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/InexistentUseCaseDescriptorTests.java +++ b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/InexistentUseCaseDescriptorTests.java @@ -5,17 +5,23 @@ import org.gcube.application.geoportal.common.utils.tests.GCubeTest; import org.gcube.application.geoportal.service.profiledDocuments.AbstractProfiledDocumentsTests; import org.junit.Test; +import javax.ws.rs.InternalServerErrorException; +import javax.ws.rs.WebApplicationException; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.Response; +import java.util.UUID; + import static org.junit.Assert.assertEquals; import static org.junit.Assume.assumeTrue; public class InexistentUseCaseDescriptorTests extends AbstractProfiledDocumentsTests { + private static String inexistentUCID= UUID.randomUUID().toString(); + @Override protected WebTarget baseTarget() { - String testProfileId="profiledConcessioni"; + String testProfileId=inexistentUCID; return target(InterfaceConstants.Methods.PROJECTS).path(testProfileId); } @@ -24,7 +30,19 @@ public class InexistentUseCaseDescriptorTests extends AbstractProfiledDocumentsT public void testMissingProfile(){ assumeTrue(GCubeTest.isTestInfrastructureEnabled()); Response resp = target(InterfaceConstants.Methods.PROJECTS) - .path("non-existent-useCaseDescriptor").request().get(); + .path(inexistentUCID).request().get(); assertEquals(404,resp.getStatus()); } + + @Override + @Test(expected = Exception.class) + public void getAll() { + super.getAll(); + } + + @Override + @Test(expected = Exception.class) + public void getByID() { + super.getByID(); + } } diff --git a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/engine/mongo/LockTests.java b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/engine/mongo/LockTests.java index 891918f..2109c07 100644 --- a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/engine/mongo/LockTests.java +++ b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/engine/mongo/LockTests.java @@ -29,7 +29,7 @@ import static org.junit.Assume.assumeTrue; public class LockTests extends BasicServiceTestUnit { - String profileID = "profiledConcessioni"; + String profileID = "rolesTesting"; ProfiledMongoManager manager= null; @Before @@ -40,7 +40,7 @@ public class LockTests extends BasicServiceTestUnit { } @Test - public void testLocking() throws StepException, EventException, IOException, ProjectLockedException, ProjectNotFoundException, InvalidLockException { + public void testLocking() throws StepException, EventException, IOException, ProjectLockedException, ProjectNotFoundException, InvalidLockException, InvalidUserRoleException, UnauthorizedAccess { assumeTrue(GCubeTest.isTestInfrastructureEnabled()); Project p = manager.registerNew(new Document("dummyField","dummyValue")); // lock diff --git a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/engine/profiles/UCDCalls.java b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/engine/profiles/UCDCalls.java index 478d8f1..4c65d01 100644 --- a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/engine/profiles/UCDCalls.java +++ b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/engine/profiles/UCDCalls.java @@ -55,7 +55,7 @@ public class UCDCalls extends BasicServiceTestUnit { public void getByWrongID() throws Exception { String testProfileId="gnegne"; - assertEquals(baseTarget().path(testProfileId).request(MediaType.APPLICATION_JSON_TYPE).get().getStatus(), Response.Status.NOT_FOUND); + assertEquals(baseTarget().path(testProfileId).request(MediaType.APPLICATION_JSON_TYPE).get().getStatus(), Response.Status.NOT_FOUND.getStatusCode()); } } diff --git a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/engine/providers/ucd/UCDLoadingTest.java b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/engine/providers/ucd/UCDLoadingTest.java index 4df6c89..238458a 100644 --- a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/engine/providers/ucd/UCDLoadingTest.java +++ b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/engine/providers/ucd/UCDLoadingTest.java @@ -1,5 +1,6 @@ package org.gcube.application.geoportal.service.engine.providers.ucd; +import org.gcube.application.cms.tests.TestProfiles; import org.gcube.application.cms.tests.TokenSetter; import org.gcube.application.geoportal.common.model.rest.ConfigurationException; import org.gcube.application.geoportal.common.utils.tests.GCubeTest; @@ -33,13 +34,16 @@ public class UCDLoadingTest { } @Test - public void testLoading() throws ConfigurationException { + public void testLoadingFromIS() throws ConfigurationException { assumeTrue(GCubeTest.isTestInfrastructureEnabled()); TokenSetter.set(GCubeTest.getContext()); SingleISResourceUCDProvider provider = new SingleISResourceUCDProvider(); ProfileMap map = provider.getObject(); - System.out.println("loaded "+map.size()+" ucds"); - assertTrue(map.size()>0); + System.out.println("UCIDs IN "+GCubeTest.getContext()+": "+map.keySet()); + } + @Test + public void testLocalLoading() throws ConfigurationException { + assertTrue(new LocalFolderProfileMapCache(TestProfiles.BASE_FOLDER.getAbsolutePath()).getObject().size()>0); } } diff --git a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/profiledDocuments/AbstractProfiledDocumentsTests.java b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/profiledDocuments/AbstractProfiledDocumentsTests.java index 291fc67..3f933a9 100644 --- a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/profiledDocuments/AbstractProfiledDocumentsTests.java +++ b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/profiledDocuments/AbstractProfiledDocumentsTests.java @@ -93,7 +93,7 @@ public abstract class AbstractProfiledDocumentsTests extends BasicServiceTestUni Project doc =check(baseTarget().request(MediaType.APPLICATION_JSON). post(Entity.entity(content, MediaType.APPLICATION_JSON)), Project.class); validate(doc); - assertTrue(doc.getLifecycleInformation().getPhase().equals(LifecycleInformation.DRAFT_PHASE)); + assertTrue(doc.getLifecycleInformation().getPhase().equals(LifecycleInformation.CommonPhases.DRAFT_PHASE)); return doc; } diff --git a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/profiledDocuments/RolesTests.java b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/profiledDocuments/RolesTests.java index 81aa564..40a8784 100644 --- a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/profiledDocuments/RolesTests.java +++ b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/profiledDocuments/RolesTests.java @@ -17,7 +17,7 @@ public class RolesTests extends AbstractProfiledDocumentsTests{ @Test - private void testRoles(){ + public void testRoles(){ // Insert for each } diff --git a/geoportal-service/src/test/resources/logback.xml b/geoportal-service/src/test/resources/logback.xml index 13c9645..8ec1f7c 100644 --- a/geoportal-service/src/test/resources/logback.xml +++ b/geoportal-service/src/test/resources/logback.xml @@ -7,7 +7,7 @@ - + diff --git a/geoportal-service/src/test/resources/profiles/rolesTesting.json b/geoportal-service/src/test/resources/profiles/rolesTesting.json index 1242e9a..f4dbbef 100644 --- a/geoportal-service/src/test/resources/profiles/rolesTesting.json +++ b/geoportal-service/src/test/resources/profiles/rolesTesting.json @@ -11,10 +11,10 @@ }, "_data_access_policy" : [ {"_policy" : {"_read" : "own", "_write" : "own"}, "_roles":[]}, - {"_policy" : {"_read" : "any", "_write" : "none"}, "_roles":["Guest"], + {"_policy" : {"_read" : "any", "_write" : "none"}, "_roles":["FakeUser"], "_enforcer": {"_filter" : {"_lifecycleInformation._phase" : {"$eq" : "Published"}}}}, - {"_policy" : {"_read" : "any", "_write" : "none"}, "_roles":["Admin"]}, - {"_policy" : {"_read" : "any", "_write" : "any"}, "_roles":["Data-Manager"]} + {"_policy" : {"_read" : "any", "_write" : "none"}, "_roles":["FakeEditor"]}, + {"_policy" : {"_read" : "any", "_write" : "any"}, "_roles":["FakeAdmin"]} ], "_handlers" : [] } \ No newline at end of file diff --git a/test-data/profiledDocuments/profiles/profiledConcessioni.json b/test-data/profiledDocuments/profiles/profiledConcessioni.json new file mode 100644 index 0000000..c772870 --- /dev/null +++ b/test-data/profiledDocuments/profiles/profiledConcessioni.json @@ -0,0 +1,215 @@ +{ + "_id" : "profiledConcessioni", + "_version" : "1.0.0", + "_name" : "Concessione", + + "_schema" : { + "abstractRelazione" : { "_min" : 1, + "_children" : [ + {"filesetIta" :{"_type" : "RegisteredFileSet", "_min": 1}}, + {"filesetEng" :{"_type" : "RegisteredFileSet"}}, + {"title" : {"_min" : 1}} + ] + }, + "relazioneScavo" : { "_max" : 1, "_min" : 1, + "_children" : [ + {"fileset" :{"_type" : "RegisteredFileSet", "_min": 1}}, + {"title" : {"_min" : 1}} + ] + }, + "immaginiRappresentative" : { + "_max" : 8, + "_children" : [ + {"fileset" :{"_type" : "RegisteredFileSet","_min": 1}}, + {"title" : {"_min" : 1}} + ] + }, + "posizionamentoScavo" : { "_max" : 1, "_min" : 1, + "_children" : [ + {"fileset" :{"_type" : "RegisteredFileSet","_min": 1}}, + {"title" : {"_min" : 1}} + ] + }, + "pianteFineScavo" : { "_max" : -1, + "_children" : [ + {"fileset" :{"_type" : "RegisteredFileSet","_min": 1}}, + {"title" : {"_min" : 1}} + ] + } + }, + + + "_description" : "Embedded profile for concessioni [mibac] management", + "_creationInfo": { + "_user" : { + "_username": "fabio.sinibaldi" + } + }, + + "_data_access_policy" : [ + {"_policy" : {"_read" : "own", "_write" : "own"}, "_roles":[]}, + {"_policy" : {"_read" : "any", "_write" : "none"}, "_roles":["Guest"], + "_enforcer": {"_filter" : {"_lifecycleInformation._phase" : {"$eq" : "Published"}}}}, + {"_policy" : {"_read" : "any", "_write" : "none"}, "_roles":["Admin"]}, + {"_policy" : {"_read" : "any", "_write" : "any"}, "_roles":["Data-Manager"]} + ], + + "_handlers" : [ + { + "_id" : "GNA-CONCESSIONI-LC", + "_type" : "LifecycleManagement", + "_configuration" : { + "step_access" : [ + {"STEP" : "PUBLISH", "roles" :[ "DataManager"]} + ] + } + }, + + { + "_id" : "SDI-Default-Materializer", + "_type" : "Materializer", + "_configuration" : { + "registeredFileSetPaths" : [ + {"schemaField" : "pianteFineScavo","documentPath" : "pianteFineScavo[*].fileset"}, + {"schemaField" : "posizionamentoScavo","documentPath" : "posizionamentoScavo.fileset"} + ] + } + }, + + + + { + "_id" : "SDI-Indexer-Plugin", + "_type" : "Indexer", + "_configuration" : { + "bboxEvaluation" : ["$..posizionamentoScavo.._bbox"], + "explicitFieldMapping" : [ + {"name" : "titolo", "path" : "$._theDocument.title", "type" : "TEXT"} + ], + "jslt" : {}, + "additionalLayers" : [ + {"source" : {"url" : "..."},"toSetTitle":""} + ] + } + }, + + { + "_id": "org.gcube.portlets.user.geoportal-data-entry-app", + "_type": "DATA_ENTRY_GUI", + "_item_type": "Concessione", + "_configuration": { + "gcubeProfiles": [ + { + "gcubeSecondaryType": "GeoNaMetadata", + "gcubeName": "Informazioni_di_progetto", + "sectionName": "$.", + "sectionTitle": "Informazioni di Progetto" + }, + { + "gcubeSecondaryType": "GeoNaMetadata", + "gcubeName": "Abstract_Relazione_di_Scavo", + "sectionName": "abstractRelazione", + "sectionTitle": "Abstract Relazione Scavo", + "parentName": "$.", + "filePaths": [ + { + "gcubeProfileFieldName": "Carica Abstract Ita (in PDF)", + "fieldDefinition": "abstractRelazione.children[?(@.filesetIta)]", + "fieldName": "filesetIta" + }, + { + "gcubeProfileFieldName": "Carica Abstract Eng (in PDF)", + "fieldDefinition": "abstractRelazione.children[?(@.filesetEng)]", + "fieldName": "filesetEng" + } + ] + }, + { + "gcubeSecondaryType": "GeoNaMetadata", + "gcubeName": "Relazione_di_Scavo", + "sectionName": "relazioneScavo", + "sectionTitle": "Relazione di Scavo", + "parentName": "$.", + "filePaths": [ + { + "gcubeProfileFieldName": "Relazione di fine scavo (in PDF)", + "fieldDefinition": "relazioneScavo.children[?(@.fileset)]", + "fieldName": "fileset" + } + ] + }, + { + "gcubeSecondaryType": "GeoNaMetadata", + "gcubeName": "Immagine_Rappresentativa_di_Scavo", + "sectionName": "immaginiRappresentative", + "sectionTitle": "Immagini Rappresentative", + "minOccurs": 1, + "maxOccurs": 8, + "parentName": "$.", + "filePaths": [ + { + "gcubeProfileFieldName": "Immagine", + "fieldDefinition": "immaginiRappresentative.children[?(@.fileset)]", + "fieldName": "fileset" + } + ] + }, + { + "gcubeSecondaryType": "GeoNaMetadata", + "gcubeName": "Posizionamento_dell_area_di_indagine", + "sectionName": "posizionamentoScavo", + "sectionTitle": "Posizionamento dell'Area di Indagine", + "parentName": "$.", + "filePaths": [ + { + "gcubeProfileFieldName": "File", + "fieldDefinition": "posizionamentoScavo.children[?(@.fileset)]", + "fieldName": "fileset" + } + ] + }, + { + "gcubeSecondaryType": "GeoNaMetadata", + "gcubeName": "Pianta_di_fine_Scavo", + "sectionName": "pianteFineScavo", + "sectionTitle": "Piante di fine Scavo", + "parentName": "$.", + "minOccurs": 0, + "maxOccurs": 0, + "filePaths": [ + { + "gcubeProfileFieldName": "File", + "fieldDefinition": "pianteFineScavo.children[?(@.fileset)]", + "fieldName": "fileset" + } + ] + } + ], + "saveStep": "SUBMIT-FOR-REVIEW" + } + }, + + { + "_id" : "org.gcubegeoportal-data-list", + "_type" : "DATA_LIST_GUI", + "_case" : "smallList", + "_configuration" : { + "projection" : "{\"nome\" : 1, \"lifecycleInformation.phase\" : 1}", + "orderPaths":[ + {"label" : "author", "path" : "info.creationInfo.user.username"}], + "searchPaths":[ + {"label" : "author", "path" : "info.creationInfo.user.username"}], + "actions" :[ + { "status" : "OK", + "phase" : "VALIDATE_DRAFT", + "butoonsDefintion" : [ + {"id" : "report_forward","action" : "STEP", "label" : "Sottometti"}, + {"id" : "list_back_workflow", "action" : "STEP" , "label" : "Rifiuta"}, + {"id" : "report_backward", "action" : "STEP" , "label" : "Rifiuta"} + ]} + ], + "implicit_filter":"{\"nome\" : {\"$eq\" : \"ciao\" }}" + } + } + ] +} \ No newline at end of file diff --git a/test-data/profiledDocuments/profiles/rolesTesting.json b/test-data/profiledDocuments/profiles/rolesTesting.json new file mode 100644 index 0000000..f4dbbef --- /dev/null +++ b/test-data/profiledDocuments/profiles/rolesTesting.json @@ -0,0 +1,20 @@ +{ + "_id" : "rolesTesting", + "_version" : "1.0.0", + "_name" : "Roles Testing", + "_description" : "Simple uC for roles management testing", + "_schema" : {}, + "_creationInfo": { + "_user" : { + "_username": "fabio.sinibaldi" + } + }, + "_data_access_policy" : [ + {"_policy" : {"_read" : "own", "_write" : "own"}, "_roles":[]}, + {"_policy" : {"_read" : "any", "_write" : "none"}, "_roles":["FakeUser"], + "_enforcer": {"_filter" : {"_lifecycleInformation._phase" : {"$eq" : "Published"}}}}, + {"_policy" : {"_read" : "any", "_write" : "none"}, "_roles":["FakeEditor"]}, + {"_policy" : {"_read" : "any", "_write" : "any"}, "_roles":["FakeAdmin"]} + ], + "_handlers" : [] +} \ No newline at end of file