fixing GeonetworkResolver
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@173916 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
9b11cb352c
commit
b5e73449fe
|
@ -22,6 +22,8 @@ public class ScopeUtil {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ScopeUtil.class);
|
private static final Logger logger = LoggerFactory.getLogger(ScopeUtil.class);
|
||||||
|
|
||||||
|
public static final String SCOPE_SEPARATOR = "|";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the scope from environment.
|
* Gets the scope from environment.
|
||||||
|
@ -40,4 +42,17 @@ public class ScopeUtil {
|
||||||
logger.info("Read scope: "+scopeFromEnv+" from Environment Variable: "+ENV_SCOPE);
|
logger.info("Read scope: "+scopeFromEnv+" from Environment Variable: "+ENV_SCOPE);
|
||||||
return scopeFromEnv;
|
return scopeFromEnv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize scope.
|
||||||
|
* Add the '/' as prefix and remove all '|'
|
||||||
|
* @param scope the scope
|
||||||
|
* @return the normalized scope
|
||||||
|
*/
|
||||||
|
public static String normalizeScope(String scope){
|
||||||
|
if(!scope.startsWith("/"))
|
||||||
|
scope="/"+scope;
|
||||||
|
scope = scope.replaceAll("\\"+SCOPE_SEPARATOR, "/");
|
||||||
|
return scope;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -40,6 +39,7 @@ import org.gcube.datatransfer.resolver.gis.geonetwork.HTTPCallsUtils;
|
||||||
import org.gcube.datatransfer.resolver.gis.geonetwork.HTTPCallsUtils.HttpResponse;
|
import org.gcube.datatransfer.resolver.gis.geonetwork.HTTPCallsUtils.HttpResponse;
|
||||||
import org.gcube.datatransfer.resolver.gis.geonetwork.ReusableInputStream;
|
import org.gcube.datatransfer.resolver.gis.geonetwork.ReusableInputStream;
|
||||||
import org.gcube.datatransfer.resolver.gis.util.GetResponseRecordFilter;
|
import org.gcube.datatransfer.resolver.gis.util.GetResponseRecordFilter;
|
||||||
|
import org.gcube.datatransfer.resolver.scope.ScopeUtil;
|
||||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||||
import org.gcube.datatransfer.resolver.services.exceptions.InternalServerException;
|
import org.gcube.datatransfer.resolver.services.exceptions.InternalServerException;
|
||||||
import org.gcube.spatial.data.geonetwork.configuration.Configuration;
|
import org.gcube.spatial.data.geonetwork.configuration.Configuration;
|
||||||
|
@ -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 = scope.replaceAll("\\"+SCOPE_SEPARATOR, "/");
|
scope = ScopeUtil.normalizeScope(scope);
|
||||||
mode = mode.toUpperCase();
|
mode = mode.toUpperCase();
|
||||||
try{
|
try{
|
||||||
MODE.valueOf(mode);
|
MODE.valueOf(mode);
|
||||||
|
@ -305,7 +305,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 = scope.replaceAll("\\"+SCOPE_SEPARATOR, "/");
|
scope = ScopeUtil.normalizeScope(scope);
|
||||||
mode = mode.toUpperCase();
|
mode = mode.toUpperCase();
|
||||||
try{
|
try{
|
||||||
MODE.valueOf(mode);
|
MODE.valueOf(mode);
|
||||||
|
@ -362,11 +362,11 @@ public class GeonetworkResolver {
|
||||||
Account account = config.getScopeConfiguration().getAccounts().get(Type.CKAN);
|
Account account = config.getScopeConfiguration().getAccounts().get(Type.CKAN);
|
||||||
logger.info("CKAN user owner is: "+account.getUser());
|
logger.info("CKAN user owner is: "+account.getUser());
|
||||||
|
|
||||||
logger.info("Parameters..");
|
// logger.info("Parameters..");
|
||||||
for (Enumeration<String> e = req.getParameterNames(); e.hasMoreElements();){
|
// for (Enumeration<String> e = req.getParameterNames(); e.hasMoreElements();){
|
||||||
String p = e.nextElement();
|
// String p = e.nextElement();
|
||||||
logger.debug("param "+p + " value "+Arrays.toString(req.getParameterValues(p)));
|
// logger.debug("param "+p + " value "+Arrays.toString(req.getParameterValues(p)));
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
//DEBUG BODY
|
//DEBUG BODY
|
||||||
|
@ -390,12 +390,13 @@ public class GeonetworkResolver {
|
||||||
logger.debug("Writing "+data +" into byte array");
|
logger.debug("Writing "+data +" into byte array");
|
||||||
byteArray.write(data.getBytes());
|
byteArray.write(data.getBytes());
|
||||||
}else
|
}else
|
||||||
IOUtils.copy(req.getReader(), byteArray);
|
IOUtils.copy(req.getInputStream(), byteArray);
|
||||||
}else
|
}else
|
||||||
IOUtils.copy(req.getReader(), byteArray);
|
IOUtils.copy(req.getInputStream(), byteArray);
|
||||||
}else{
|
}else{
|
||||||
gnCSWlURL = remainPath==null ||remainPath.isEmpty()?geonetworkUrl+"/"+CSW_SERVER:geonetworkUrl+"/"+CSW_SERVER+remainPath;
|
logger.info("IS NOT A REQUEST TO "+SRV_EN_MEF_EXPORT);
|
||||||
IOUtils.copy(req.getReader(), byteArray);
|
gnCSWlURL = remainPath==null || remainPath.isEmpty()?geonetworkUrl+"/"+CSW_SERVER:geonetworkUrl+"/"+CSW_SERVER+remainPath;
|
||||||
|
IOUtils.copy(req.getInputStream(), byteArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
//filterPublicMetadata = theVisibility.equals(VISIBILITY.PRV)?true:false;
|
//filterPublicMetadata = theVisibility.equals(VISIBILITY.PRV)?true:false;
|
||||||
|
@ -404,10 +405,10 @@ public class GeonetworkResolver {
|
||||||
|
|
||||||
//PRIVATE LAYERS
|
//PRIVATE LAYERS
|
||||||
if(visibility.equals(VISIBILITY.PRV)){
|
if(visibility.equals(VISIBILITY.PRV)){
|
||||||
logger.debug("Visibility: "+VISIBILITY.PRV+" getting private layers..");
|
logger.info("Visibility: "+VISIBILITY.PRV+" getting private layers..");
|
||||||
//VRE LAYERS
|
//VRE LAYERS
|
||||||
if(mode.equals(MODE.VRE)){
|
if(mode.equals(MODE.VRE)){
|
||||||
logger.debug("Getting "+MODE.VRE+" layers..");
|
logger.info("Getting "+MODE.VRE+" layers..");
|
||||||
|
|
||||||
//HARVESTED LAYERS
|
//HARVESTED LAYERS
|
||||||
}else{
|
}else{
|
||||||
|
@ -419,21 +420,21 @@ public class GeonetworkResolver {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
filters.put("isHarvested", "y");
|
filters.put("isHarvested", "y");
|
||||||
logger.debug("Getting "+MODE.HARVEST+" layers, I'm using filters ["+filters+"]");
|
logger.info("Getting "+MODE.HARVEST+" layers, I added 'isHarvested = y' to the filters ["+filters+"]");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(account.getUser()!=null){
|
if(account.getUser()!=null){
|
||||||
boolean authorized = GNAuthentication.login(httpUtils, geonetworkUrl, account.getUser(), account. getPassword());
|
boolean authorized = GNAuthentication.login(httpUtils, geonetworkUrl, account.getUser(), account. getPassword());
|
||||||
logger.trace("Authorized on "+geonetworkUrl +" ? "+authorized);
|
logger.info("Authorized on "+geonetworkUrl +" ? "+authorized);
|
||||||
}else
|
}else
|
||||||
logger.info("Skipping authentication, ckan user (the owner) is null");
|
logger.info("Skipping authentication, ckan user (the owner) is null");
|
||||||
|
|
||||||
//PUBLIC LAYERS
|
//PUBLIC LAYERS
|
||||||
}else{
|
}else{
|
||||||
logger.debug("Visibility: "+VISIBILITY.PUB+" getting public layers..");
|
logger.info("Visibility: "+VISIBILITY.PUB+" getting public layers..");
|
||||||
//VRE LAYERS
|
//VRE LAYERS
|
||||||
if(mode.equals(MODE.VRE)){
|
if(mode.equals(MODE.VRE)){
|
||||||
logger.debug("Getting "+MODE.VRE+" layers, the VRE account: "+account.getUser() +" will be used as owner user for filtering... Is it right?");
|
logger.info("Getting "+MODE.VRE+" layers, the VRE account: "+account.getUser() +" will be used as owner user for filtering... Is it right?");
|
||||||
filters.put("ownername", account.getUser());
|
filters.put("ownername", account.getUser());
|
||||||
|
|
||||||
//HARVESTED LAYERS
|
//HARVESTED LAYERS
|
||||||
|
@ -444,13 +445,13 @@ public class GeonetworkResolver {
|
||||||
// logger.error(error);
|
// logger.error(error);
|
||||||
// ExceptionManager.throwBadRequestException(req, error, GeonetworkResolver.class, help);
|
// ExceptionManager.throwBadRequestException(req, error, GeonetworkResolver.class, help);
|
||||||
// }
|
// }
|
||||||
filters.put("isHarvested", "y");
|
//filters.put("isHarvested", "y");
|
||||||
logger.debug("Getting "+MODE.HARVEST+" layers, I added 'isHarvested = y' to filters ["+filters+"]");
|
logger.info("Getting "+MODE.HARVEST+" layers, I'm applying the filters ["+filters+"]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("Sending CSW POST request to URL: "+gnCSWlURL);
|
logger.info("Sending CSW POST request to URL: "+gnCSWlURL);
|
||||||
logger.debug("Content-Type: "+req.getContentType());
|
logger.info("Content-Type: "+req.getContentType());
|
||||||
|
|
||||||
|
|
||||||
//DEBUG
|
//DEBUG
|
||||||
|
@ -511,7 +512,9 @@ public class GeonetworkResolver {
|
||||||
String value = GetResponseRecordFilter.getMetadataValueByFileIdentifier(fileId, config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(), config.getAdminAccount().getPassword(), fkey);
|
String value = GetResponseRecordFilter.getMetadataValueByFileIdentifier(fileId, config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(), config.getAdminAccount().getPassword(), fkey);
|
||||||
//String own = GetResponseRecordFilter.getMetaOwnerNameByFileIdentifier(fileId, config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(), config.getAdminAccount().getPassword());
|
//String own = GetResponseRecordFilter.getMetaOwnerNameByFileIdentifier(fileId, config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(), config.getAdminAccount().getPassword());
|
||||||
String fValue = filters.get(fkey);
|
String fValue = filters.get(fkey);
|
||||||
if(value!=null && value.compareTo(fValue)!=0){
|
//Either the filter KEY doesn't matching any geonet:info (value==null)
|
||||||
|
//or the value of filterKey in geonet:info doesn't matching the passed filterValue (value.compareTo(fValue)!=0)
|
||||||
|
if(value==null || value.compareTo(fValue)!=0){
|
||||||
logger.trace(fkey +" of File Identifier "+fileId+" not matching the filter: "+fkey+" with value: "+fValue+", adding it to list to remove file identifier and exit from loop..");
|
logger.trace(fkey +" of File Identifier "+fileId+" not matching the filter: "+fkey+" with value: "+fValue+", adding it to list to remove file identifier and exit from loop..");
|
||||||
noMatchingFilter.add(fileId);
|
noMatchingFilter.add(fileId);
|
||||||
//WHEN I ADD THE FILE IDENTIFIER TO FILTERED ID, I CAN EXIT FROM CKECKING FILTERS LOOP
|
//WHEN I ADD THE FILE IDENTIFIER TO FILTERED ID, I CAN EXIT FROM CKECKING FILTERS LOOP
|
||||||
|
@ -536,7 +539,7 @@ public class GeonetworkResolver {
|
||||||
ReusableInputStream reusIs = new ReusableInputStream(in);
|
ReusableInputStream reusIs = new ReusableInputStream(in);
|
||||||
|
|
||||||
//END DEBUG
|
//END DEBUG
|
||||||
logger.debug("Response return Content-Type: "+httpUtils.getLastContentType());
|
logger.info("Response return Content-Type: "+httpUtils.getLastContentType());
|
||||||
return Response
|
return Response
|
||||||
.ok(reusIs)
|
.ok(reusIs)
|
||||||
//.header(ConstantsResolver.CONTENT_DISPOSITION,"attachment; filename = \""+fileName+"\"")
|
//.header(ConstantsResolver.CONTENT_DISPOSITION,"attachment; filename = \""+fileName+"\"")
|
||||||
|
@ -672,9 +675,7 @@ public class GeonetworkResolver {
|
||||||
if(cacheGNInstances==null)
|
if(cacheGNInstances==null)
|
||||||
purgeCacheGeonetworkInstances();
|
purgeCacheGeonetworkInstances();
|
||||||
|
|
||||||
if(!scope.startsWith("/"))
|
scope = ScopeUtil.normalizeScope(scope);
|
||||||
scope="/"+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);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue