From eba5ba565b8f5af0d0f300482573789c7a3e8936 Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Thu, 8 Nov 2018 14:47:33 +0000 Subject: [PATCH] moved to only one ScopeUtil git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@174057 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../ApplicationProfileReader.java | 1 + .../applicationprofile/ScopeUtil.java | 52 ------------------- ...teApplicationProfileCatalogueResolver.java | 2 +- .../resolver/services/GeonetworkResolver.java | 6 +-- .../datatransfer/resolver/util/ScopeUtil.java | 44 ++++++++++++++-- 5 files changed, 45 insertions(+), 60 deletions(-) delete mode 100644 src/main/java/org/gcube/datatransfer/resolver/applicationprofile/ScopeUtil.java diff --git a/src/main/java/org/gcube/datatransfer/resolver/applicationprofile/ApplicationProfileReader.java b/src/main/java/org/gcube/datatransfer/resolver/applicationprofile/ApplicationProfileReader.java index 90fd0e2..60e5a32 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/applicationprofile/ApplicationProfileReader.java +++ b/src/main/java/org/gcube/datatransfer/resolver/applicationprofile/ApplicationProfileReader.java @@ -12,6 +12,7 @@ import org.apache.log4j.Logger; import org.gcube.common.resources.gcore.utils.XPathHelper; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.datatransfer.resolver.applicationprofile.GcubeQuery.FIELD_TYPE; +import org.gcube.datatransfer.resolver.util.ScopeUtil; import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.queries.api.Query; import org.gcube.resources.discovery.client.queries.impl.QueryBox; diff --git a/src/main/java/org/gcube/datatransfer/resolver/applicationprofile/ScopeUtil.java b/src/main/java/org/gcube/datatransfer/resolver/applicationprofile/ScopeUtil.java deleted file mode 100644 index 128a17e..0000000 --- a/src/main/java/org/gcube/datatransfer/resolver/applicationprofile/ScopeUtil.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * - */ -package org.gcube.datatransfer.resolver.applicationprofile; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * The Class ScopeUtil. - * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * May 16, 2017 - */ -public class ScopeUtil { - - private static final String SCOPE_SEPARATOR = "/"; - public static final Logger logger = LoggerFactory.getLogger(ScopeUtil.class); - - - /** - * Gets the infrastructure name from scope. - * - * @param scope the scope - * @return the infrastructure name from scope - * @throws Exception the exception - */ - public static String getInfrastructureNameFromScope(String scope) throws Exception{ - - if(scope==null || scope.isEmpty()){ - throw new Exception("Scope is null or empty"); - } - - if(!scope.startsWith(SCOPE_SEPARATOR)){ - logger.warn("Input scope: "+scope+" not have / is a really scope?"); - scope = SCOPE_SEPARATOR+scope; - logger.warn("Tentative as scope: "+scope); - } - - String[] splitScope = scope.split(SCOPE_SEPARATOR); - - String rootScope = SCOPE_SEPARATOR + splitScope[1]; - - if(rootScope.length()<2){ - throw new Exception("Infrastructure name not found in "+scope); - } - - return rootScope; - - } -} diff --git a/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/UpdateApplicationProfileCatalogueResolver.java b/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/UpdateApplicationProfileCatalogueResolver.java index d9a3de0..36332eb 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/UpdateApplicationProfileCatalogueResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/UpdateApplicationProfileCatalogueResolver.java @@ -22,7 +22,7 @@ import org.gcube.common.resources.gcore.Resources; import org.gcube.common.resources.gcore.utils.XPathHelper; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileNotFoundException; -import org.gcube.datatransfer.resolver.applicationprofile.ScopeUtil; +import org.gcube.datatransfer.resolver.util.ScopeUtil; import org.gcube.informationsystem.publisher.RegistryPublisherFactory; import org.gcube.informationsystem.publisher.ScopedPublisher; import org.w3c.dom.Document; diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GeonetworkResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GeonetworkResolver.java index 06c84df..1eb2c11 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GeonetworkResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GeonetworkResolver.java @@ -136,7 +136,7 @@ public class GeonetworkResolver { ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'mode'", GeonetworkResolver.class, help); } - scope = ScopeUtil.normalizeScope(scope); + scope = ScopeUtil.normalizeScope(scope, "|"); mode = mode.toUpperCase(); try{ MODE.valueOf(mode); @@ -267,7 +267,7 @@ public class GeonetworkResolver { ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'mode'", GeonetworkResolver.class, help); } - scope = ScopeUtil.normalizeScope(scope); + scope = ScopeUtil.normalizeScope(scope, "|"); mode = mode.toUpperCase(); try{ MODE.valueOf(mode); @@ -580,7 +580,7 @@ public class GeonetworkResolver { if(cacheGNInstances==null) purgeCacheGeonetworkInstances(); - scope = ScopeUtil.normalizeScope(scope); + scope = ScopeUtil.normalizeScope(scope, "|"); logger.info("Attempt to get geonetwork instance from GeonetworkInstance cache for scope: "+scope); GeonetworkInstance geoInstance = cacheGNInstances.get(scope); diff --git a/src/main/java/org/gcube/datatransfer/resolver/util/ScopeUtil.java b/src/main/java/org/gcube/datatransfer/resolver/util/ScopeUtil.java index f968303..c1020b3 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/util/ScopeUtil.java +++ b/src/main/java/org/gcube/datatransfer/resolver/util/ScopeUtil.java @@ -3,6 +3,9 @@ */ package org.gcube.datatransfer.resolver.util; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * The Class ScopeUtil. @@ -12,18 +15,51 @@ package org.gcube.datatransfer.resolver.util; */ public class ScopeUtil { - public static final String SCOPE_SEPARATOR = "|"; + public static final String SCOPE_SEPARATOR = "/"; + public static final Logger logger = LoggerFactory.getLogger(ScopeUtil.class); /** * Normalize scope. - * Add the '/' as prefix and remove all '|' + * Add the '/' as prefix and remove all input replaceSepartor * @param scope the scope + * @param replaceSepartor the string to replace with {@link ScopeUtil#SCOPE_SEPARATOR}} * @return the normalized scope */ - public static String normalizeScope(String scope){ + public static String normalizeScope(String scope, String replaceSepartor){ if(!scope.startsWith("/")) scope="/"+scope; - scope = scope.replaceAll("\\"+SCOPE_SEPARATOR, "/"); + scope = scope.replaceAll("\\"+replaceSepartor, SCOPE_SEPARATOR); return scope; } + + /** + * Gets the infrastructure name from scope. + * + * @param scope the scope + * @return the infrastructure name from scope + * @throws Exception the exception + */ + public static String getInfrastructureNameFromScope(String scope) throws Exception{ + + if(scope==null || scope.isEmpty()){ + throw new Exception("Scope is null or empty"); + } + + if(!scope.startsWith(SCOPE_SEPARATOR)){ + logger.warn("Input scope: "+scope+" not have / is a really scope?"); + scope = SCOPE_SEPARATOR+scope; + logger.warn("Tentative as scope: "+scope); + } + + String[] splitScope = scope.split(SCOPE_SEPARATOR); + + String rootScope = SCOPE_SEPARATOR + splitScope[1]; + + if(rootScope.length()<2){ + throw new Exception("Infrastructure name not found in "+scope); + } + + return rootScope; + + } }