fixing bug on CatalogueResolver

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@174008 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-11-06 16:09:38 +00:00
parent 7983745cf6
commit 89076f4faf
8 changed files with 74 additions and 55 deletions

View File

@ -18,7 +18,7 @@ import java.util.List;
public enum ResourceCatalogueCodes {
CTLG("ctlg","dataset", "Catalogue Product/Dataset"),
CTLGP("ctlg-p","dataset", "Catalogue Product"),
CTLGP("ctlg-p","product", "Catalogue Product"),
CTLGD("ctlg-d","dataset", "Catalogue Dataset"),
CTLGO("ctlg-o","organization", "Catalogue Organization"),
CTLGG("ctlg-g","group", "Catalogue Group");

View File

@ -63,11 +63,11 @@ public class LoadingCatalogueApplicationProfilesCache {
try{
//PRE-POPULATE CACHE
logger.info("Trying to pre-poluate catalogue resolver cache");
ScopeProvider.instance.set(UriResolverStartupListener.getContextScope());
ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(UriResolverStartupListener.getContextScope(), true);
ScopeProvider.instance.set(UriResolverStartupListener.getRootContextScope());
ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(UriResolverStartupListener.getRootContextScope(), true);
catalogueApplicationProfiles.asMap().putAll(appPrCatResolver.getHashVreNameScope());
logger.info(LoadingCatalogueApplicationProfilesCache.class.getSimpleName() +" instancied");
logger.info("cache instancied");
logger.info("Pre-Loaded CatalogueApplicationProfiles cache is: "+catalogueApplicationProfiles.asMap().toString());
}catch(Exception e){
@ -107,7 +107,7 @@ public class LoadingCatalogueApplicationProfilesCache {
if(fullScope==null){
logger.debug("FullScope is null for VRE_NAME: "+vreName+" into Application Profile: "+ApplicationProfileReaderForCatalogueResolver.RESOURCE_NAME+", reading profile again");
ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(UriResolverStartupListener.getContextScope(), true);
ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(UriResolverStartupListener.getRootContextScope(), true);
catalogueApplicationProfiles.asMap().putAll(appPrCatResolver.getHashVreNameScope());
}

View File

@ -42,5 +42,21 @@ public class CatalogueRequest {
return entity_name;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("CatalogueRequest [gcube_scope=");
builder.append(gcube_scope);
builder.append(", entity_context=");
builder.append(entity_context);
builder.append(", entity_name=");
builder.append(entity_name);
builder.append("]");
return builder.toString();
}
}

View File

@ -52,7 +52,7 @@ public class UriResolverStartupListener implements ServletContextListener {
public static final String ENV_SCOPE = "SCOPE"; //Environment Variable
private static String contextScope = null;
private static String rootContextScope = null;
private static ApplicationProfileGenericResourceReader gisViewerProfile;
private static ApplicationProfileGenericResourceReader geoExplorerProfile;
@ -64,7 +64,7 @@ public class UriResolverStartupListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
try {
contextScope = loadScopeFromEnvironment();
rootContextScope = loadScopeFromEnvironment();
ApplicationContext ctx = ContextProvider.get();
String rootScope = ctx.container().configuration().infrastructure();
logger.info("The ContextProvider returned the infrastructure name: "+rootScope);
@ -82,7 +82,7 @@ public class UriResolverStartupListener implements ServletContextListener {
new LoadingCatalogueApplicationProfilesCache();
logger.info("Context initialized with: ");
logger.info("Scope: "+contextScope);
logger.info("Scope: "+rootContextScope);
logger.info("GisViewerProfile [ID: "+gisViewerProfile.getAppId() + ", Generic Resource Type: "+gisViewerProfile.getGenericResource()+"]");
logger.info("GeoExplorerProfile [ID: "+geoExplorerProfile. getAppId() + ", Generic Resource Type: "+geoExplorerProfile.getGenericResource()+"]");
}
@ -163,13 +163,13 @@ public class UriResolverStartupListener implements ServletContextListener {
/**
* Gets the context scope.
* Gets the root context scope.
*
* @return the contextScope
* @return the root context scope
*/
public static String getContextScope() {
public static String getRootContextScope() {
return contextScope;
return rootContextScope;
}

View File

@ -122,7 +122,7 @@ public class CatalogueResolver {
new Thread(){
public void run() {
try {
boolean endPointUpdated = UpdateApplicationProfileCatalogueResolver.validateEndPoint(UriResolverStartupListener.getContextScope(), vreName, fullscope);
boolean endPointUpdated = UpdateApplicationProfileCatalogueResolver.validateEndPoint(UriResolverStartupListener.getRootContextScope(), vreName, fullscope);
logger.info("Is the Application profile for Catalogue Resolver updated? "+endPointUpdated);
// if(endPointUpdated)
// appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(fullscope, true);

View File

@ -130,7 +130,7 @@ public class GisResolver {
}catch (InvalidCacheLoadException e) {
logger.error("Error on getting GisViewer Portlet URL for scope: "+scope, e);
ExceptionManager.throwNotFoundException(req, "GisViewer Portlet URL not found in the scope: "+scope +". Please add it or contact the support", this.getClass(), help);
//ExceptionManager.throwNotFoundException(req, "GisViewer Portlet URL not found in the scope: "+scope +". Please add it or contact the support", this.getClass(), help);
}
}
@ -149,7 +149,7 @@ public class GisResolver {
return Response.seeOther(new URI(geoExplorerPortletUrl)).build();
}catch (InvalidCacheLoadException e) {
logger.error("Error on getting GeoExplorer Portlet URL for scope: "+scope, e);
ExceptionManager.throwNotFoundException(req, "GeoExplorer Portlet URL not found in the scope: "+scope +". Please add it or contact the support", this.getClass(), help);
//ExceptionManager.throwNotFoundException(req, "GeoExplorer Portlet URL not found in the scope: "+scope +". Please add it or contact the support", this.getClass(), help);
}
}

View File

@ -429,7 +429,7 @@ public class HTTPCallsUtils {
+ message
);
if(logger.isDebugEnabled())
logger.debug("GeoNetwork response:\n"+badresponse);
logger.debug("Response is:\n"+badresponse);
return null;
}
} catch (ConnectException e) {

View File

@ -17,6 +17,8 @@ import java.util.Map;
import org.apache.commons.io.FilenameUtils;
import org.apache.http.HttpStatus;
import org.gcube.datatransfer.resolver.util.HTTPCallsUtils;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -160,46 +162,47 @@ public class TestResolvers {
}
}
// /**
// * Storage hub test.
// * @throws Exception
// */
// @Test
// public void createCatalogueURLTest() throws Exception{
//
// String entityName = "sarda-sarda";
// String entityContext = "ctlg";
// String vreName = "devVRE";
//
// String url = String.format("%s/%s/%s/%s",URI_RESOLVER_SERVICE_ENDPOINT,entityContext, vreName, entityName);
// logger.info("Request to URL: "+url);
// URL toURL;
// int status;
// try {
// toURL = new URL(url);
// HttpURLConnection con = (HttpURLConnection) toURL.openConnection();
// con.setRequestMethod("GET");
// con.connect();
// status = con.getResponseCode();
// System.out.println("Response status is: "+status);
// if(status==HttpStatus.SC_OK){
// System.out.println("Response: \n"+getContentReponse(con.getInputStream()));
// }else{
// System.out.println("\nError on resolving the Catalogue URL: "+toURL);
// System.out.println("Response: \n"+getContentReponse(con.getInputStream()));
// }
// //con.setRequestProperty("Content-Type", "application/json");
// //con.setConnectTimeout(5000);
// //con.setReadTimeout(5000)
//
// }
// catch (Exception e) {
// // TODO Auto-generated catch block
// logger.error("Error: ",e);
// throw e;
// }
// }
/**
* Storage hub test.
* @throws Exception
*/
@Test
public void catalogueResolverCreateItemURLTest() throws Exception{
String entityName = "sarda-sarda";
String entityContext = "product";
String scope = "/gcube/devsec/devVRE";
String url = String.format("%s/%s",URI_RESOLVER_SERVICE_ENDPOINT,"catalogue");
logger.info("POST Request to URL: "+url);
try {
HTTPCallsUtils httCaller = new HTTPCallsUtils(null, null);
String jsonString =
"{" +
"\"gcube_scope\":\""+scope+"\"," +
"\"entity_context\":\""+entityContext+"\"," +
"\"entity_name\":\""+entityName+"\"" +
"}";
System.out.println("Sending JSON: "+jsonString);
// JSONObject json = new JSONObject();
// json.append("gcube_scope", scope);
// json.append("entity_context", entityContext);
// json.append("entity_name", entityName);
// System.out.println("Sending json object: "+json.toString());
InputStream response = httCaller.post(url, jsonString, "application/json");
System.out.println("Response: \n"+getContentReponse(response));
//con.setRequestProperty("Content-Type", "application/json");
//con.setConnectTimeout(5000);
//con.setReadTimeout(5000)
}
catch (Exception e) {
// TODO Auto-generated catch block
logger.error("Error: ",e);
throw e;
}
}
/**
* Gets the content reponse.
*