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:
parent
d5d41a1d2a
commit
eba5ba565b
|
@ -12,6 +12,7 @@ import org.apache.log4j.Logger;
|
||||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.datatransfer.resolver.applicationprofile.GcubeQuery.FIELD_TYPE;
|
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.api.DiscoveryClient;
|
||||||
import org.gcube.resources.discovery.client.queries.api.Query;
|
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||||
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
||||||
|
|
|
@ -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;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -22,7 +22,7 @@ import org.gcube.common.resources.gcore.Resources;
|
||||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileNotFoundException;
|
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.RegistryPublisherFactory;
|
||||||
import org.gcube.informationsystem.publisher.ScopedPublisher;
|
import org.gcube.informationsystem.publisher.ScopedPublisher;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
|
|
|
@ -136,7 +136,7 @@ public class GeonetworkResolver {
|
||||||
ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'mode'", GeonetworkResolver.class, help);
|
ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'mode'", GeonetworkResolver.class, help);
|
||||||
}
|
}
|
||||||
|
|
||||||
scope = ScopeUtil.normalizeScope(scope);
|
scope = ScopeUtil.normalizeScope(scope, "|");
|
||||||
mode = mode.toUpperCase();
|
mode = mode.toUpperCase();
|
||||||
try{
|
try{
|
||||||
MODE.valueOf(mode);
|
MODE.valueOf(mode);
|
||||||
|
@ -267,7 +267,7 @@ public class GeonetworkResolver {
|
||||||
ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'mode'", GeonetworkResolver.class, help);
|
ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'mode'", GeonetworkResolver.class, help);
|
||||||
}
|
}
|
||||||
|
|
||||||
scope = ScopeUtil.normalizeScope(scope);
|
scope = ScopeUtil.normalizeScope(scope, "|");
|
||||||
mode = mode.toUpperCase();
|
mode = mode.toUpperCase();
|
||||||
try{
|
try{
|
||||||
MODE.valueOf(mode);
|
MODE.valueOf(mode);
|
||||||
|
@ -580,7 +580,7 @@ public class GeonetworkResolver {
|
||||||
if(cacheGNInstances==null)
|
if(cacheGNInstances==null)
|
||||||
purgeCacheGeonetworkInstances();
|
purgeCacheGeonetworkInstances();
|
||||||
|
|
||||||
scope = ScopeUtil.normalizeScope(scope);
|
scope = ScopeUtil.normalizeScope(scope, "|");
|
||||||
logger.info("Attempt to get geonetwork instance from GeonetworkInstance cache for scope: "+scope);
|
logger.info("Attempt to get geonetwork instance from GeonetworkInstance cache for scope: "+scope);
|
||||||
GeonetworkInstance geoInstance = cacheGNInstances.get(scope);
|
GeonetworkInstance geoInstance = cacheGNInstances.get(scope);
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.datatransfer.resolver.util;
|
package org.gcube.datatransfer.resolver.util;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class ScopeUtil.
|
* The Class ScopeUtil.
|
||||||
|
@ -12,18 +15,51 @@ package org.gcube.datatransfer.resolver.util;
|
||||||
*/
|
*/
|
||||||
public class ScopeUtil {
|
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.
|
* Normalize scope.
|
||||||
* Add the '/' as prefix and remove all '|'
|
* Add the '/' as prefix and remove all input replaceSepartor
|
||||||
* @param scope the scope
|
* @param scope the scope
|
||||||
|
* @param replaceSepartor the string to replace with {@link ScopeUtil#SCOPE_SEPARATOR}}
|
||||||
* @return the normalized scope
|
* @return the normalized scope
|
||||||
*/
|
*/
|
||||||
public static String normalizeScope(String scope){
|
public static String normalizeScope(String scope, String replaceSepartor){
|
||||||
if(!scope.startsWith("/"))
|
if(!scope.startsWith("/"))
|
||||||
scope="/"+scope;
|
scope="/"+scope;
|
||||||
scope = scope.replaceAll("\\"+SCOPE_SEPARATOR, "/");
|
scope = scope.replaceAll("\\"+replaceSepartor, SCOPE_SEPARATOR);
|
||||||
return scope;
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue