Geonetwork Resolver porting to Geonetwork Library

Added property to compile with java 1.8

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@148692 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2017-05-15 14:59:27 +00:00
parent 4126af6282
commit 804a274a31
3 changed files with 50 additions and 42 deletions

View File

@ -20,7 +20,10 @@
<properties>
<distroDirectory>distro</distroDirectory>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<!-- <dependency> -->

View File

@ -59,7 +59,7 @@ public class GeonetworkInstance {
public GeonetworkInstance(boolean authenticate, LoginLevel level) throws Exception {
try {
this.level = level;
createInstanceGeonetworkPublisher(authenticate);
createInstanceGeonetworkPublisher(authenticate, level);
} catch (Exception e) {
logger.error("Sorry, an error occurred in getting geonetwork instance",e);
throw new Exception("Sorry, an error occurred in getting geonetwork instance",e);
@ -86,7 +86,7 @@ public class GeonetworkInstance {
try {
ScopeProvider.instance.set(scope);
logger.info("setting scope "+scope);
createInstanceGeonetworkPublisher(authenticate);
createInstanceGeonetworkPublisher(authenticate, level);
if(this.type!=null){
Configuration config = geonetworkPublisher.getConfiguration();
this.account=config.getScopeConfiguration().getAccounts().get(type);
@ -115,11 +115,11 @@ public class GeonetworkInstance {
* @param type the type
* @throws Exception the exception
*/
private void createInstanceGeonetworkPublisher(boolean authenticate) throws Exception {
private void createInstanceGeonetworkPublisher(boolean authenticate, LoginLevel level) throws Exception {
logger.debug("creating new geonetworkPublisher..");
this.geonetworkPublisher = GeoNetwork.get();
if(authenticate && this.level!=null)
authenticateOnGeoenetwork(this.level);
authenticateOnGeoenetwork(level);
}
/**

View File

@ -24,12 +24,10 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.UriResolverRewriteFilter;
import org.gcube.datatransfer.resolver.gis.GeoRuntimeReader;
import org.gcube.datatransfer.resolver.gis.GeoRuntimeReader.GEO_SERVICE;
import org.gcube.datatransfer.resolver.gis.GeonetworkAccessParameter;
import org.gcube.datatransfer.resolver.gis.GeonetworkInstance;
import org.gcube.datatransfer.resolver.gis.GeonetworkServiceInterface;
import org.gcube.datatransfer.resolver.gis.entity.ServerParameters;
import org.gcube.datatransfer.resolver.gis.exception.GeonetworkInstanceException;
import org.gcube.datatransfer.resolver.gis.exception.IllegalArgumentException;
import org.gcube.datatransfer.resolver.gis.geonetwork.HTTPCallsUtils.HttpResponse;
import org.gcube.datatransfer.resolver.gis.util.GetResponseRecordFilter;
@ -79,7 +77,7 @@ public class GeonetworkResolver extends HttpServlet{
/** The logger. */
private static final Logger logger = LoggerFactory.getLogger(GeonetworkResolver.class);
protected Map<String, ServerParameters> cacheGNServerParams; //A cache: scope - geonetwork parameters
protected Map<String, GeonetworkInstance> cacheGNInstances; //A cache: scope - GeonetworkInstance
private Timer timer;
@ -100,7 +98,7 @@ public class GeonetworkResolver extends HttpServlet{
@Override
public void run() {
logger.info("Resetting Geonetwork configuratiors cache...");
resetCacheServerParameters();
resetCacheGeonetworkInstances();
}
}, CACHE_RESET_DELAY, CACHE_RESET_TIME);
}
@ -124,7 +122,7 @@ public class GeonetworkResolver extends HttpServlet{
}
if(resetCache!=null && Boolean.parseBoolean(resetCache)){
resetCacheServerParameters();
resetCacheGeonetworkInstances();
}
if(resetScope!=null && Boolean.parseBoolean(resetScope)){
@ -135,8 +133,9 @@ public class GeonetworkResolver extends HttpServlet{
try {
// ServerParameters geonetworkParams = getGeonetworkCachedServerParameters(scopeValue);
GeonetworkServiceInterface gntwAccess = new GeonetworkAccessParameter(scopeValue);
GeonetworkInstance gnInstance = gntwAccess.getGeonetworkInstance();
GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scopeValue);
// GeonetworkServiceInterface gntwAccess = new GeonetworkAccessParameter(scopeValue);
// GeonetworkInstance gnInstance = gntwAccess.getGeonetworkInstance();
HTTPCallsUtils httpUtils = new HTTPCallsUtils();
Configuration config = gnInstance.getGeonetworkPublisher().getConfiguration();
String geonetworkUrl = config.getGeoNetworkEndpoint();
@ -180,11 +179,6 @@ public class GeonetworkResolver extends HttpServlet{
sendError(resp, response.getStatus(), "Sorry, an error occurred on resolving geonetwork request with scope "+scopeValue);
}
} catch (IllegalArgumentException e){
logger.error("IllegalArgumentException:", e);
sendError(resp, HttpServletResponse.SC_BAD_REQUEST, "Illegal argument to carry out the request!");
return;
} catch (Exception e) {
logger.error("Exception:", e);
String error = "Sorry, an error occurred on resolving geonetwork request with scope "+scopeValue+". Please, contact support!";
@ -400,40 +394,51 @@ public class GeonetworkResolver extends HttpServlet{
}
}
/**
* Gets the geonetwork cached server parameters.
* Gets the geonetwork instance for scope.
*
* @param scope the scope
* @return the geonetwork cached server parameters
* @return the geonetwork instance for scope
* @throws Exception the exception
*/
protected ServerParameters getGeonetworkCachedServerParameters(String scope) throws Exception{
protected GeonetworkInstance getGeonetworkInstanceForScope(String scope) throws Exception{
if(cacheGNServerParams==null)
resetCacheServerParameters();
if(cacheGNInstances==null)
resetCacheGeonetworkInstances();
logger.info("Tentative for recovering geonetwork server parameters from cache with scope: "+scope);
ServerParameters serverParam = cacheGNServerParams.get(scope);
logger.info("Attempt to get geonetwork instance from GeonetworkInstance cache for scope: "+scope);
GeonetworkInstance geoInstance = cacheGNInstances.get(scope);
if(serverParam==null || serverParam.getPassword()!=null){
logger.info("Cache having null Geonetwork server parameters or password 'null', reading from IS..");
GeoRuntimeReader reader = new GeoRuntimeReader();
if(geoInstance==null){
logger.info("Cache having null GeonetworkInstance for scope "+scope+", reading by Geonetwork library...");
try {
serverParam = reader.retrieveGisParameters(scope, GEO_SERVICE.GEONETWORK);
cacheGNServerParams.put(scope, serverParam);
logger.info("Updated Cache for Geonetwork server parameters! Scope "+scope+" linking "+serverParam);
geoInstance = discoveryGeonetworkInstance(scope);
cacheGNInstances.put(scope, geoInstance);
logger.info("Updated GeonetworkInstance Cache adding couple: Scope "+scope+" - GeonetworkInstance "+geoInstance);
} catch (Exception e) {
logger.error("An error occurred on reading application profile to "+GEO_SERVICE.GEONETWORK, e);
throw new Exception("Sorry, An error occurred on reading configuration to "+GEO_SERVICE.GEONETWORK);
logger.error("An error occurred on reading GeonetworkInstance for scope "+scope, e);
throw new Exception("Sorry, An error occurred on reading GeonetworkInstance for scope "+scope);
}
}else
logger.info("Cache gis server param is not null using it");
logger.info("GeonetworkInstance cache for scope: "+scope+" is not null using it: "+geoInstance);
logger.info("returning geonetworkParams "+serverParam);
return serverParam;
return geoInstance;
}
/**
* Discovery geonetwork instance.
*
* @param scope the scope
* @return the geonetwork instance
* @throws GeonetworkInstanceException the geonetwork instance exception
*/
private GeonetworkInstance discoveryGeonetworkInstance(String scope) throws GeonetworkInstanceException{
GeonetworkAccessParameter gntwAccess = new GeonetworkAccessParameter(scope);
return gntwAccess.getGeonetworkInstance(true, null);
}
/**
@ -442,8 +447,8 @@ public class GeonetworkResolver extends HttpServlet{
* @param scope the scope
*/
private void resetCacheServerParameterForScope(String scope){
if(cacheGNServerParams!=null && cacheGNServerParams.get(scope)!=null){
cacheGNServerParams.remove(scope);
if(cacheGNInstances!=null && cacheGNInstances.get(scope)!=null){
cacheGNInstances.remove(scope);
logger.info("Reset of "+scope+" in Cache Geonetwork server params perfomed!");
}else
logger.info("Reset of "+scope+" in Cache Geonetwork skipped, scope not exists!");
@ -451,11 +456,11 @@ public class GeonetworkResolver extends HttpServlet{
/**
* Reset cache server parameters.
* Reset cache geonetwork instances.
*/
private void resetCacheServerParameters(){
cacheGNServerParams = new HashMap<String, ServerParameters>();
logger.info("Reset of Cache Geonetwork server params perfomed!");
private void resetCacheGeonetworkInstances(){
cacheGNInstances = new HashMap<String, GeonetworkInstance>();
logger.info("Reset of Cache GeonetworkInstance perfomed!");
}
/**