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
This commit is contained in:
Francesco Mangiacrapa 2018-11-08 14:47:33 +00:00
parent d5d41a1d2a
commit eba5ba565b
5 changed files with 45 additions and 60 deletions

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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);

View File

@ -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;
}
}