Updated documentation

This commit is contained in:
Francesco Mangiacrapa 2022-03-31 10:52:52 +02:00
parent dee5beeadf
commit b8992a0124
16 changed files with 568 additions and 396 deletions

View File

@ -19,7 +19,11 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" path="src/main/resources"/> <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>

View File

@ -57,8 +57,14 @@ import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
/** /**
* The Class AnalyticsCreateResolver. * The AnalyticsCreateResolver provides a method to get the Analytics URLs (that
* * are simply URLs) by which is possible to invoke through the DataMiner
* Executor the run of an algorithm stored in a certain VRE. By the DataMiner
* Executor then the user is able to monitoring the algorithm execution.
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Analytics_Resolver
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Dec 12, 2018 * Dec 12, 2018
*/ */
@ -79,7 +85,12 @@ public class AnalyticsCreateResolver {
/** /**
* Creates the analytics url. * Creates the analytics url.
* *
* Request format: [URI_RESOLVER_SERVICE_ENDPOINT]/analytics/create
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#HTTP_POST:_Create_an_Analytics_URL
*
* @param req the req * @param req the req
* @param body the body * @param body the body
* @return the response * @return the response

View File

@ -24,7 +24,13 @@ import org.slf4j.LoggerFactory;
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
/** /**
* The Class AnalyticsGetResolver. * The AnalyticsGetResolver to resolve an Analytics URL
*
* Request format
* [URI_RESOLVER_SERVICE_ENDPOINT]/analytics/get/[VRE_NAME]?dim=[PUBLIC_URL_TO_DATAMIER_INVOCATION_FILE_GENERATED_BY_POST_REQUEST]
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Analytics_Resolver
* *
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
* *
@ -46,6 +52,9 @@ public class AnalyticsGetResolver {
/** /**
* Resolve analytics url. * Resolve analytics url.
* *
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#HTTP_GET:_Resolve_an_Analytics_URL
*
* @param req the req * @param req the req
* @param vreName the vre name * @param vreName the vre name
* @return the response * @return the response

View File

@ -44,8 +44,14 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
import eu.trentorise.opendata.jackan.model.CkanDataset; import eu.trentorise.opendata.jackan.model.CkanDataset;
/** /**
* The Class CatalogueResolver. * The CatalogueResolver is able to get/resolve a link to a "Catalogue Entity"
* stored in one of the gCube Data Catalogue's instances. A Catalogue Entity is
* either a "group" or an "organization" or a "product" of D4Science Data
* Catalogue.
* *
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#CATALOGUE_Resolver
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Nov 16, 2018 * Nov 16, 2018
*/ */
@ -67,7 +73,10 @@ public class CatalogueResolver {
} }
/** /**
* Resolve catalogue. * Resolve an entity of the Catalogue
*
* Request format:
* [URI_RESOLVER_SERVICE_ENDPOINT]/[ctlg|ctlg-d|ctlg-o|ctlg-g]/[VRE_NAME]/[entity_name]
* *
* @param req the req * @param req the req
* @param entityName the entity name * @param entityName the entity name
@ -126,7 +135,8 @@ public class CatalogueResolver {
} }
/** /**
* Post catalogue. * Create a Catalogue Link
*
* *
* @param req the req * @param req the req
* @param jsonRequest the json request * @param jsonRequest the json request

View File

@ -48,10 +48,17 @@ import org.slf4j.LoggerFactory;
import org.w3c.dom.Document; import org.w3c.dom.Document;
/** /**
* The Class GeonetworkResolver. * The GeonetworkResolver is a "middle tier" (like a Proxy) to perform queries
* on D4Science Geonetwork services.
*
* Request format
* http[s]://[GEONETWORK_RESOLVER_BASE_URL]/[SCOPE]/[MODE]/[VISIBILITY]/[FILTER_KEY]/[FILTER_VALUE]/$$
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Geonetwork_Resolver
* *
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Oct 23, 2018 * Oct 23, 2018
*/ */
@Path("geonetwork") @Path("geonetwork")
public class GeonetworkResolver { public class GeonetworkResolver {
@ -60,7 +67,8 @@ public class GeonetworkResolver {
* *
*/ */
public static final String REPLACED_A_PUBLIC_UUID_PLEASE_IGNORE = "Replaced a public UUID, please ignore"; public static final String REPLACED_A_PUBLIC_UUID_PLEASE_IGNORE = "Replaced a public UUID, please ignore";
public static final String REPLACED_UUID_BY_FILTER_PLEASE_IGNORE = "Replaced UUID by "+GeonetworkResolver.class.getSimpleName()+" filters, please ignore"; public static final String REPLACED_UUID_BY_FILTER_PLEASE_IGNORE = "Replaced UUID by "
+ GeonetworkResolver.class.getSimpleName() + " filters, please ignore";
private static Logger logger = LoggerFactory.getLogger(GeonetworkResolver.class); private static Logger logger = LoggerFactory.getLogger(GeonetworkResolver.class);
@ -78,180 +86,196 @@ public class GeonetworkResolver {
public static final String QUERY_PARAM_RESET_CACHE_PARAM = "resetcache"; public static final String QUERY_PARAM_RESET_CACHE_PARAM = "resetcache";
public static final String QUERY_PARAM_RESET_CACHED_SCOPE_PARAM = "resetcachedscope"; public static final String QUERY_PARAM_RESET_CACHED_SCOPE_PARAM = "resetcachedscope";
public static final String SRV_EN_MEF_EXPORT = "/srv/en/mef.export"; //MEF Geonetwork service public static final String SRV_EN_MEF_EXPORT = "/srv/en/mef.export"; // MEF Geonetwork service
public static final String UUID = "uuid"; public static final String UUID = "uuid";
public static final String SCOPE_SEPARATOR = "|"; public static final String SCOPE_SEPARATOR = "|";
//protected Map<String, GeonetworkInstance> cacheGNInstances; // protected Map<String, GeonetworkInstance> cacheGNInstances;
private String helpURI = "https://wiki.gcube-system.org/gcube/GCube_Resource_Catalogue#Geonetwork_Resolver"; private String helpURI = "https://wiki.gcube-system.org/gcube/GCube_Resource_Catalogue#Geonetwork_Resolver";
/** /**
* Gets the geonetwork request criteria. * Gets the geonetwork request criteria. Creates a request criteria from input
* Creates a request criteria from input parameter pathWithoutGN * parameter pathWithoutGN The parameter pathWithoutGN should be an ordered
* The parameter pathWithoutGN should be an ordered string (like REST request): * string (like REST request): SCOPE/MODE/VISIBILITY/OWNER/$$ SCOPE must be:
* SCOPE/MODE/VISIBILITY/OWNER/$$ * ROOT|VO|VRE MODE must be: {@link MODE} VISIBILITY must be: {@link VISIBILITY}
* SCOPE must be: ROOT|VO|VRE
* MODE must be: {@link MODE}
* VISIBILITY must be: {@link VISIBILITY}
* OWNER (is optional): filter by owner * OWNER (is optional): filter by owner
* *
* @param req the req * @param req the req
* @param scope the scope * @param scope the scope
* @param mode the mode * @param mode the mode
* @param visibility the visibility * @param visibility the visibility
* @param filterKey the filter key * @param filterKey the filter key
* @param filterValue the filter value * @param filterValue the filter value
* @param remainPath the remain path * @param remainPath the remain path
* @param resetCache the reset cache * @param resetCache the reset cache
* @param resetScope the reset scope * @param resetScope the reset scope
* @return the geonetwork request criteria * @return the geonetwork request criteria
* @throws WebApplicationException the web application exception * @throws WebApplicationException the web application exception
*/ */
@GET @GET
@Path("/{"+PATH_PARAM_SCOPE+"}/{"+PATH_PARAM_MODE+"}/{"+PATH_PARAM_VISIBILITY+"}/{filterKey}/{filterValue}/$${"+PATH_PARAM_REMAINPATH+":(/[^?$]+)?}") @Path("/{" + PATH_PARAM_SCOPE + "}/{" + PATH_PARAM_MODE + "}/{" + PATH_PARAM_VISIBILITY
public Response submitGet(@Context HttpServletRequest req, + "}/{filterKey}/{filterValue}/$${" + PATH_PARAM_REMAINPATH + ":(/[^?$]+)?}")
@PathParam(PATH_PARAM_SCOPE) @Nullable String scope, public Response submitGet(@Context HttpServletRequest req, @PathParam(PATH_PARAM_SCOPE) @Nullable String scope,
@PathParam(PATH_PARAM_MODE) @Nullable String mode, @PathParam(PATH_PARAM_MODE) @Nullable String mode,
@PathParam(PATH_PARAM_VISIBILITY) @Nullable String visibility, @PathParam(PATH_PARAM_VISIBILITY) @Nullable String visibility,
@PathParam("filterKey") @Nullable String filterKey, @PathParam("filterKey") @Nullable String filterKey, @PathParam("filterValue") @Nullable String filterValue,
@PathParam("filterValue") @Nullable String filterValue, @PathParam(PATH_PARAM_REMAINPATH) @Nullable String remainPath,
@PathParam(PATH_PARAM_REMAINPATH) @Nullable String remainPath, @QueryParam(QUERY_PARAM_RESET_CACHE_PARAM) @Nullable String resetCache,
@QueryParam(QUERY_PARAM_RESET_CACHE_PARAM) @Nullable String resetCache, @QueryParam(QUERY_PARAM_RESET_CACHED_SCOPE_PARAM) @Nullable String resetScope)
@QueryParam(QUERY_PARAM_RESET_CACHED_SCOPE_PARAM) @Nullable String resetScope) throws WebApplicationException{ throws WebApplicationException {
logger.info(this.getClass().getSimpleName()+" GET starts..."); logger.info(this.getClass().getSimpleName() + " GET starts...");
String gnGetlURL = null; String gnGetlURL = null;
try { try {
logger.info("Params are [mode: "+mode+", scope: "+scope+", visibility: "+visibility+", filterKey: "+filterKey+", filterValue: "+filterValue+", remainPath: "+remainPath+"]"); logger.info(
"Params are [mode: " + mode + ", scope: " + scope + ", visibility: " + visibility + ", filterKey: "
+ filterKey + ", filterValue: " + filterValue + ", remainPath: " + remainPath + "]");
if(scope==null || scope.isEmpty()){ if (scope == null || scope.isEmpty()) {
logger.error("Path Parameter 'scope' not found"); logger.error("Path Parameter 'scope' not found");
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'scope'", this.getClass(), helpURI); throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'scope'",
this.getClass(), helpURI);
} }
if(mode==null || mode.isEmpty()){ if (mode == null || mode.isEmpty()) {
logger.error("Path Parameter 'scope' not found"); logger.error("Path Parameter 'scope' not found");
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'mode'", this.getClass(), helpURI); throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'mode'",
this.getClass(), helpURI);
} }
scope = ScopeUtil.normalizeScope(scope, "|"); scope = ScopeUtil.normalizeScope(scope, "|");
mode = mode.toUpperCase(); mode = mode.toUpperCase();
try{ try {
MODE.valueOf(mode); MODE.valueOf(mode);
}catch(Exception e){ } catch (Exception e) {
List<MODE> toPrint = Arrays.asList(MODE.values()); List<MODE> toPrint = Arrays.asList(MODE.values());
logger.error("The 'mode' parameter is wrong, Have you pass a valid parameter MODE like "+toPrint+"?"); logger.error(
throw ExceptionManager.wrongParameterException(req, "The 'mode' parameter must be value of "+toPrint, this.getClass(), helpURI); "The 'mode' parameter is wrong, Have you pass a valid parameter MODE like " + toPrint + "?");
throw ExceptionManager.wrongParameterException(req, "The 'mode' parameter must be value of " + toPrint,
this.getClass(), helpURI);
} }
if(visibility==null){ if (visibility == null) {
logger.error("Path Parameter 'visibility' not found"); logger.error("Path Parameter 'visibility' not found");
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'visibility'", this.getClass(), helpURI); throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'visibility'",
this.getClass(), helpURI);
} }
visibility = visibility.toUpperCase(); visibility = visibility.toUpperCase();
try{ try {
VISIBILITY.valueOf(visibility); VISIBILITY.valueOf(visibility);
}catch (Exception e) { } catch (Exception e) {
List<VISIBILITY> toPrint = Arrays.asList(VISIBILITY.values()); List<VISIBILITY> toPrint = Arrays.asList(VISIBILITY.values());
logger.error("The 'visibility' parameter is wrong, Have you pass a valid parameter VISIBILITY like "+toPrint+"?"); logger.error("The 'visibility' parameter is wrong, Have you pass a valid parameter VISIBILITY like "
throw ExceptionManager.wrongParameterException(req, "The 'visibility' parameter must be value of "+toPrint, this.getClass(), helpURI); + toPrint + "?");
throw ExceptionManager.wrongParameterException(req,
"The 'visibility' parameter must be value of " + toPrint, this.getClass(), helpURI);
} }
logger.info("Remaining path is: "+remainPath); logger.info("Remaining path is: " + remainPath);
try { try {
//I'M LOADING GN CONFIGURATIONS (ENDPOINT, USER, PWD AND SO ON..) FOR PASSED SCOPE FROM GN LIBRARY BY A GENERAL METHOD WITHOUT TO PERFORM AUTHENTICATION ON GN, // I'M LOADING GN CONFIGURATIONS (ENDPOINT, USER, PWD AND SO ON..) FOR PASSED
//AFTER THAT I'M USING THEM TO PERFORM AUTHENTICATION ON GN VIA HTTP_CLIENTS IF NEEDED // SCOPE FROM GN LIBRARY BY A GENERAL METHOD WITHOUT TO PERFORM AUTHENTICATION
// ON GN,
// AFTER THAT I'M USING THEM TO PERFORM AUTHENTICATION ON GN VIA HTTP_CLIENTS IF
// NEEDED
GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope); GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope);
logger.info("set scope provider "+scope); logger.info("set scope provider " + scope);
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
Account account = gnInstance.getAccount(); Account account = gnInstance.getAccount();
Version version = gnInstance.getVersion(); Version version = gnInstance.getVersion();
String geonetworkUrl = gnInstance.getEndPoint(); String geonetworkUrl = gnInstance.getEndPoint();
Configuration config = gnInstance.getConfig()!=null?gnInstance.getConfig():null; Configuration config = gnInstance.getConfig() != null ? gnInstance.getConfig() : null;
if(account==null || account.getUser()==null || account.getPassword()==null || config==null) { if (account == null || account.getUser() == null || account.getPassword() == null || config == null) {
logger.info("Loading GN instance and configurations via Geonetwork Library..."); logger.info("Loading GN instance and configurations via Geonetwork Library...");
config = gnInstance.getGeonetworkPublisher().getConfiguration(); config = gnInstance.getGeonetworkPublisher().getConfiguration();
account = config.getScopeConfiguration().getAccounts().get(Type.CKAN); account = config.getScopeConfiguration().getAccounts().get(Type.CKAN);
version = config.getGeoNetworkVersion(); version = config.getGeoNetworkVersion();
geonetworkUrl = config.getGeoNetworkEndpoint(); geonetworkUrl = config.getGeoNetworkEndpoint();
} }
logger.info("SCOPE: {}, CKAN user used is: {}, GN EndPoint: {}",scope, account.getUser(), geonetworkUrl); logger.info("SCOPE: {}, CKAN user used is: {}, GN EndPoint: {}", scope, account.getUser(),
geonetworkUrl);
HTTPCallsUtils httpUtils = new HTTPCallsUtils(); HTTPCallsUtils httpUtils = new HTTPCallsUtils();
if(visibility.equals(VISIBILITY.PRV.name())){ if (visibility.equals(VISIBILITY.PRV.name())) {
if(account.getUser()!=null){ if (account.getUser() != null) {
switch (version) { switch (version) {
case DUE: case DUE:
boolean authorized = GNAuthentication.login(httpUtils, geonetworkUrl, account.getUser(), account.getPassword()); boolean authorized = GNAuthentication.login(httpUtils, geonetworkUrl, account.getUser(),
logger.info("Authorized on GN2 "+geonetworkUrl +" ? "+authorized); account.getPassword());
logger.info("Authorized on GN2 " + geonetworkUrl + " ? " + authorized);
break; break;
default: default:
httpUtils = new HTTPCallsUtils(account.getUser(), account.getPassword()); httpUtils = new HTTPCallsUtils(account.getUser(), account.getPassword());
logger.info("Authorized on GN3 via HTTCallsUtils..."); logger.info("Authorized on GN3 via HTTCallsUtils...");
break; break;
} }
}else { } else {
logger.warn("I'm not able to perform authentication, the user read from config with "+Type.CKAN+" is null"); logger.warn("I'm not able to perform authentication, the user read from config with "
+ Type.CKAN + " is null");
} }
} }
String baseURL = remainPath==null ||remainPath.isEmpty()?geonetworkUrl+"/"+CSW_SERVER:geonetworkUrl+"/"+CSW_SERVER+remainPath; String baseURL = remainPath == null || remainPath.isEmpty() ? geonetworkUrl + "/" + CSW_SERVER
logger.info("The base URL is: "+baseURL); : geonetworkUrl + "/" + CSW_SERVER + remainPath;
String queryString = req.getQueryString()==null || req.getQueryString().isEmpty()?"":"?"+req.getQueryString(); logger.info("The base URL is: " + baseURL);
gnGetlURL = baseURL+queryString; String queryString = req.getQueryString() == null || req.getQueryString().isEmpty() ? ""
logger.info("Sending get request to URL: "+gnGetlURL); : "?" + req.getQueryString();
gnGetlURL = baseURL + queryString;
logger.info("Sending get request to URL: " + gnGetlURL);
HttpResponse proxedGNResponse = httpUtils.get(gnGetlURL); HttpResponse proxedGNResponse = httpUtils.get(gnGetlURL);
switch(proxedGNResponse.getStatus()){ switch (proxedGNResponse.getStatus()) {
case HttpServletResponse.SC_OK: case HttpServletResponse.SC_OK:
//Building the response // Building the response
InputStream streamToWrite = IOUtils.toInputStream(proxedGNResponse.getResponse()); InputStream streamToWrite = IOUtils.toInputStream(proxedGNResponse.getResponse());
StreamingOutput so = new SingleFileStreamingOutput(streamToWrite); StreamingOutput so = new SingleFileStreamingOutput(streamToWrite);
logger.info("Response return Content-Type: "+httpUtils.getLastContentType()); logger.info("Response return Content-Type: " + httpUtils.getLastContentType());
ResponseBuilder responseBuilder = Response ResponseBuilder responseBuilder = Response.ok(so).header(ConstantsResolver.CONTENT_TYPE,
.ok(so) httpUtils.getLastContentType());
.header(ConstantsResolver.CONTENT_TYPE, httpUtils.getLastContentType());
return responseBuilder.build(); return responseBuilder.build();
case HttpServletResponse.SC_FORBIDDEN: case HttpServletResponse.SC_FORBIDDEN:
throw ExceptionManager.forbiddenException(req, "You are not authorized to perform the request "+gnGetlURL, this.getClass(), helpURI); throw ExceptionManager.forbiddenException(req,
"You are not authorized to perform the request " + gnGetlURL, this.getClass(), helpURI);
default: default:
throw ExceptionManager.internalErrorException(req, "Sorry, an error occurred performing the geonetwork request "+gnGetlURL+" with scope "+scope, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req,
"Sorry, an error occurred performing the geonetwork request " + gnGetlURL + " with scope "
+ scope,
this.getClass(), helpURI);
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("Exception:", e); logger.error("Exception:", e);
String error = "Sorry, an error occurred on resolving geonetwork request with scope "+scope+". Please, contact support!"; String error = "Sorry, an error occurred on resolving geonetwork request with scope " + scope
+ ". Please, contact support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }
} catch (Exception e) {
}catch (Exception e) { if (!(e instanceof WebApplicationException)) {
// UNEXPECTED EXCEPTION managing it as WebApplicationException
if(!(e instanceof WebApplicationException)){ String error = "Error during perform GET operation to: " + gnGetlURL + ". Please, contact the support!";
//UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error during perform GET operation to: "+gnGetlURL+". Please, contact the support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }
//ALREADY MANAGED AS WebApplicationException // ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }
@ -261,157 +285,172 @@ public class GeonetworkResolver {
/** /**
* Submit post. * Submit post.
* *
* @param req the req * @param req the req
* @param scope the scope * @param scope the scope
* @param mode the mode * @param mode the mode
* @param visibility the visibility * @param visibility the visibility
* @param filterKey the filter key * @param filterKey the filter key
* @param filterValue the filter value * @param filterValue the filter value
* @param remainPath the remain path * @param remainPath the remain path
* @param resetCache the reset cache * @param resetCache the reset cache
* @param resetScope the reset scope * @param resetScope the reset scope
* @return the response * @return the response
* @throws WebApplicationException the web application exception * @throws WebApplicationException the web application exception
*/ */
@POST @POST
@Path("/{"+PATH_PARAM_SCOPE+"}/{"+PATH_PARAM_MODE+"}/{"+PATH_PARAM_VISIBILITY+"}/{filterKey}/{filterValue}/$${"+PATH_PARAM_REMAINPATH+":(/[^?$]+)?}") @Path("/{" + PATH_PARAM_SCOPE + "}/{" + PATH_PARAM_MODE + "}/{" + PATH_PARAM_VISIBILITY
public Response submitPost(@Context HttpServletRequest req, + "}/{filterKey}/{filterValue}/$${" + PATH_PARAM_REMAINPATH + ":(/[^?$]+)?}")
@PathParam(PATH_PARAM_SCOPE) @Nullable String scope, public Response submitPost(@Context HttpServletRequest req, @PathParam(PATH_PARAM_SCOPE) @Nullable String scope,
@PathParam(PATH_PARAM_MODE) @Nullable String mode, @PathParam(PATH_PARAM_MODE) @Nullable String mode,
@PathParam(PATH_PARAM_VISIBILITY) @Nullable String visibility, @PathParam(PATH_PARAM_VISIBILITY) @Nullable String visibility,
@PathParam("filterKey") @Nullable String filterKey, @PathParam("filterKey") @Nullable String filterKey, @PathParam("filterValue") @Nullable String filterValue,
@PathParam("filterValue") @Nullable String filterValue, @PathParam(PATH_PARAM_REMAINPATH) @Nullable String remainPath,
@PathParam(PATH_PARAM_REMAINPATH) @Nullable String remainPath, @QueryParam(QUERY_PARAM_RESET_CACHE_PARAM) @Nullable String resetCache,
@QueryParam(QUERY_PARAM_RESET_CACHE_PARAM) @Nullable String resetCache, @QueryParam(QUERY_PARAM_RESET_CACHED_SCOPE_PARAM) @Nullable String resetScope)
@QueryParam(QUERY_PARAM_RESET_CACHED_SCOPE_PARAM) @Nullable String resetScope) throws WebApplicationException{ throws WebApplicationException {
logger.info(this.getClass().getSimpleName()+" POST starts..."); logger.info(this.getClass().getSimpleName() + " POST starts...");
String gnCSWlURL = null; String gnCSWlURL = null;
try{ try {
logger.info("Params are [mode: "+mode+", scope: "+scope+", visibility: "+visibility+", filterKey: "+filterKey+", filterValue: "+filterValue+", remainPath: "+remainPath+"]"); logger.info(
"Params are [mode: " + mode + ", scope: " + scope + ", visibility: " + visibility + ", filterKey: "
+ filterKey + ", filterValue: " + filterValue + ", remainPath: " + remainPath + "]");
if(scope==null || scope.isEmpty()){ if (scope == null || scope.isEmpty()) {
logger.error("Path Parameter 'scope' not found"); logger.error("Path Parameter 'scope' not found");
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'scope'", this.getClass(), helpURI); throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'scope'",
this.getClass(), helpURI);
} }
if(mode==null || mode.isEmpty()){ if (mode == null || mode.isEmpty()) {
logger.error("Path Parameter 'scope' not found"); logger.error("Path Parameter 'scope' not found");
ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'mode'", this.getClass(), helpURI); ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'mode'", this.getClass(),
helpURI);
} }
scope = ScopeUtil.normalizeScope(scope, "|"); scope = ScopeUtil.normalizeScope(scope, "|");
mode = mode.toUpperCase(); mode = mode.toUpperCase();
try{ try {
MODE.valueOf(mode); MODE.valueOf(mode);
}catch(Exception e){ } catch (Exception e) {
List<MODE> toPrint = Arrays.asList(MODE.values()); List<MODE> toPrint = Arrays.asList(MODE.values());
logger.error("The 'mode' parameter is wrong, Have you pass a valid parameter MODE like "+toPrint+"?"); logger.error(
throw ExceptionManager.wrongParameterException(req, "The 'mode' parameter must be value of "+toPrint, this.getClass(), helpURI); "The 'mode' parameter is wrong, Have you pass a valid parameter MODE like " + toPrint + "?");
throw ExceptionManager.wrongParameterException(req, "The 'mode' parameter must be value of " + toPrint,
this.getClass(), helpURI);
} }
if(visibility==null){ if (visibility == null) {
logger.error("Path Parameter 'visibility' not found"); logger.error("Path Parameter 'visibility' not found");
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'visibility'", this.getClass(), helpURI); throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter 'visibility'",
this.getClass(), helpURI);
} }
visibility = visibility.toUpperCase(); visibility = visibility.toUpperCase();
try{ try {
VISIBILITY.valueOf(visibility); VISIBILITY.valueOf(visibility);
}catch (Exception e) { } catch (Exception e) {
List<VISIBILITY> toPrint = Arrays.asList(VISIBILITY.values()); List<VISIBILITY> toPrint = Arrays.asList(VISIBILITY.values());
logger.error("The 'visibility' parameter is wrong, Have you pass a valid parameter VISIBILITY like "+toPrint+"?"); logger.error("The 'visibility' parameter is wrong, Have you pass a valid parameter VISIBILITY like "
throw ExceptionManager.wrongParameterException(req, "The 'visibility' parameter must be value of "+toPrint, this.getClass(), helpURI); + toPrint + "?");
throw ExceptionManager.wrongParameterException(req,
"The 'visibility' parameter must be value of " + toPrint, this.getClass(), helpURI);
} }
//HOW TO PASS ANY FILTER? // HOW TO PASS ANY FILTER?
//TODO INVESTIGATE ON HOW TO PASS MORE THAN ONE FILTER... // TODO INVESTIGATE ON HOW TO PASS MORE THAN ONE FILTER...
Map<String,String> filters = new HashMap<String, String>(); Map<String, String> filters = new HashMap<String, String>();
if(filterKey!=null && filterValue!=null){ if (filterKey != null && filterValue != null) {
//IGNORING THE EMPTY FILTER 'null|null' // IGNORING THE EMPTY FILTER 'null|null'
if(filterKey.compareToIgnoreCase("null")!=0){ if (filterKey.compareToIgnoreCase("null") != 0) {
filters.put(filterKey, filterValue); filters.put(filterKey, filterValue);
logger.debug("Added filter parmas to map filters: "+filters); logger.debug("Added filter parmas to map filters: " + filters);
} }
} }
try { try {
//I'M LOADING GN CONFIGURATIONS (ENDPOINT, USER, PWD AND SO ON..) FOR PASSED SCOPE FROM GN LIBRARY BY A GENERAL METHOD WITHOUT TO PERFORM AUTHENTICATION ON GN, // I'M LOADING GN CONFIGURATIONS (ENDPOINT, USER, PWD AND SO ON..) FOR PASSED
//AFTER THAT I'M USING THEM TO PERFORM AUTHENTICATION ON GN VIA HTTP_CLIENTS IF NEEDED // SCOPE FROM GN LIBRARY BY A GENERAL METHOD WITHOUT TO PERFORM AUTHENTICATION
// ON GN,
// AFTER THAT I'M USING THEM TO PERFORM AUTHENTICATION ON GN VIA HTTP_CLIENTS IF
// NEEDED
GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope); GeonetworkInstance gnInstance = getGeonetworkInstanceForScope(scope);
logger.info("set scope provider "+scope); logger.info("set scope provider " + scope);
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
Account account = gnInstance.getAccount(); Account account = gnInstance.getAccount();
Version version = gnInstance.getVersion(); Version version = gnInstance.getVersion();
String geonetworkUrl = gnInstance.getEndPoint(); String geonetworkUrl = gnInstance.getEndPoint();
Configuration config = gnInstance.getConfig()!=null?gnInstance.getConfig():null; Configuration config = gnInstance.getConfig() != null ? gnInstance.getConfig() : null;
if(account==null || account.getUser()==null || account.getPassword()==null || config==null) { if (account == null || account.getUser() == null || account.getPassword() == null || config == null) {
logger.info("Loading GN instance and configurations via Geonetwork Library..."); logger.info("Loading GN instance and configurations via Geonetwork Library...");
config = gnInstance.getGeonetworkPublisher().getConfiguration(); config = gnInstance.getGeonetworkPublisher().getConfiguration();
account = config.getScopeConfiguration().getAccounts().get(Type.CKAN); account = config.getScopeConfiguration().getAccounts().get(Type.CKAN);
version = config.getGeoNetworkVersion(); version = config.getGeoNetworkVersion();
geonetworkUrl = config.getGeoNetworkEndpoint(); geonetworkUrl = config.getGeoNetworkEndpoint();
} }
logger.info("SCOPE: {}, CKAN user used is: {}, GN EndPoint: {}",scope, account.getUser(), geonetworkUrl); logger.info("SCOPE: {}, CKAN user used is: {}, GN EndPoint: {}", scope, account.getUser(),
geonetworkUrl);
// 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
// String readBody = IOUtils.toString(req.getReader()); // String readBody = IOUtils.toString(req.getReader());
// logger.debug("doPost read body request: "+readBody); // logger.debug("doPost read body request: "+readBody);
ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
// SPECIFIC HANDLER FOR GEONETWORK REQUEST: /srv/en/mef.export // SPECIFIC HANDLER FOR GEONETWORK REQUEST: /srv/en/mef.export
if(remainPath!=null && remainPath.compareTo(SRV_EN_MEF_EXPORT)==0){ if (remainPath != null && remainPath.compareTo(SRV_EN_MEF_EXPORT) == 0) {
logger.info("In case of mef.export, perfoming a custom handler"); logger.info("In case of mef.export, perfoming a custom handler");
gnCSWlURL = geonetworkUrl + SRV_EN_MEF_EXPORT; gnCSWlURL = geonetworkUrl + SRV_EN_MEF_EXPORT;
String[] uuidValues = req.getParameterValues(UUID); String[] uuidValues = req.getParameterValues(UUID);
if(uuidValues!=null){ if (uuidValues != null) {
String data = null; String data = null;
for (String uuid : uuidValues) { for (String uuid : uuidValues) {
data = UUID+"="+uuid; data = UUID + "=" + uuid;
} }
if(data!=null){ if (data != null) {
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.getInputStream(), byteArray); IOUtils.copy(req.getInputStream(), byteArray);
}else } else
IOUtils.copy(req.getInputStream(), byteArray); IOUtils.copy(req.getInputStream(), byteArray);
}else{ } else {
logger.debug("IS NOT A REQUEST TO "+SRV_EN_MEF_EXPORT); logger.debug("IS NOT A REQUEST TO " + SRV_EN_MEF_EXPORT);
gnCSWlURL = remainPath==null || remainPath.isEmpty()?geonetworkUrl+"/"+CSW_SERVER:geonetworkUrl+"/"+CSW_SERVER+remainPath; gnCSWlURL = remainPath == null || remainPath.isEmpty() ? geonetworkUrl + "/" + CSW_SERVER
: geonetworkUrl + "/" + CSW_SERVER + remainPath;
IOUtils.copy(req.getInputStream(), byteArray); IOUtils.copy(req.getInputStream(), byteArray);
} }
HTTPCallsUtils httpUtils = new HTTPCallsUtils(); HTTPCallsUtils httpUtils = new HTTPCallsUtils();
//PRIVATE LAYERS // PRIVATE LAYERS
if(visibility.equals(VISIBILITY.PRV.name())){ if (visibility.equals(VISIBILITY.PRV.name())) {
logger.info("Visibility: "+VISIBILITY.PRV+" getting private layers.."); logger.info("Visibility: " + VISIBILITY.PRV + " getting private layers..");
//VRE LAYERS // VRE LAYERS
if(mode.equals(MODE.VRE.name())){ if (mode.equals(MODE.VRE.name())) {
logger.info("Getting "+MODE.VRE+" layers.."); logger.info("Getting " + MODE.VRE + " layers..");
//HARVESTED LAYERS // HARVESTED LAYERS
}else{ } else {
filters.put("isHarvested", "y"); filters.put("isHarvested", "y");
logger.info("Getting "+MODE.HARVEST+" layers, I added 'isHarvested = y' to the filters ["+filters+"]"); logger.info("Getting " + MODE.HARVEST + " layers, I added 'isHarvested = y' to the filters ["
+ filters + "]");
} }
if(account.getUser()!=null){ if (account.getUser() != null) {
switch (version) { switch (version) {
case DUE: case DUE:
boolean authorized = GNAuthentication.login(httpUtils, geonetworkUrl, account.getUser(), account.getPassword()); boolean authorized = GNAuthentication.login(httpUtils, geonetworkUrl, account.getUser(),
logger.info("Authorized on GN2 "+geonetworkUrl +" ? "+authorized); account.getPassword());
logger.info("Authorized on GN2 " + geonetworkUrl + " ? " + authorized);
break; break;
default: default:
@ -419,81 +458,101 @@ public class GeonetworkResolver {
logger.info("Authorized on GN3 via HTTCallsUtils..."); logger.info("Authorized on GN3 via HTTCallsUtils...");
break; break;
} }
}else { } else {
logger.warn("I'm not able to perform authentication, the user read from config with "+Type.CKAN+" is null"); logger.warn("I'm not able to perform authentication, the user read from config with "
+ Type.CKAN + " is null");
} }
//PUBLIC LAYERS // PUBLIC LAYERS
}else{ } else {
logger.info("Visibility: "+VISIBILITY.PUB+" getting public layers.."); logger.info("Visibility: " + VISIBILITY.PUB + " getting public layers..");
//VRE LAYERS // VRE LAYERS
if(mode.equals(MODE.VRE.name())){ if (mode.equals(MODE.VRE.name())) {
logger.info("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
}else{ } else {
//filters.put("isHarvested", "y"); // filters.put("isHarvested", "y");
logger.info("Getting "+MODE.HARVEST+" layers, I'm applying the 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.debug("Content-Type: " + req.getContentType());
//DEBUG // DEBUG
//logger.debug("POST - BODY : "+byteArray.toString()); // logger.debug("POST - BODY : "+byteArray.toString());
InputStream in = httpUtils.post(gnCSWlURL, new ByteArrayInputStream(byteArray.toByteArray()), req.getContentType(), req.getParameterMap()); InputStream in = httpUtils.post(gnCSWlURL, new ByteArrayInputStream(byteArray.toByteArray()),
req.getContentType(), req.getParameterMap());
if(in==null){ if (in == null) {
logger.warn("Input stream returned is null, sending "+HttpServletResponse.SC_NOT_FOUND); logger.warn("Input stream returned is null, sending " + HttpServletResponse.SC_NOT_FOUND);
throw ExceptionManager.notFoundException(req, "Input stream is null to the request "+gnCSWlURL+ " with body: "+byteArray.toString(), this.getClass(), helpURI); throw ExceptionManager.notFoundException(req,
"Input stream is null to the request " + gnCSWlURL + " with body: " + byteArray.toString(),
this.getClass(), helpURI);
} }
try{ try {
ReusableInputStream reus = new ReusableInputStream(in); ReusableInputStream reus = new ReusableInputStream(in);
if(visibility.equals(VISIBILITY.PRV.name())){ if (visibility.equals(VISIBILITY.PRV.name())) {
logger.info("Private VISIBILITY requested, retrieving public file identifiers to apply filtering.."); logger.info(
"Private VISIBILITY requested, retrieving public file identifiers to apply filtering..");
FilterGetRecords filterGetRecords = new FilterGetRecords(byteArray.toString(), geonetworkUrl); FilterGetRecords filterGetRecords = new FilterGetRecords(byteArray.toString(), geonetworkUrl);
if(filterGetRecords.getFoundPublicIds()!=null && filterGetRecords.getFoundPublicIds().size()>0){ if (filterGetRecords.getFoundPublicIds() != null
logger.info("I'm removing list of public IDs with "+filterGetRecords.getFoundPublicIds().size() +" item/s. Is it right?"); && filterGetRecords.getFoundPublicIds().size() > 0) {
in = GetResponseRecordFilter.overrideResponseIdsByListIds(reus, filterGetRecords.getFoundPublicIds(), REPLACED_A_PUBLIC_UUID_PLEASE_IGNORE); logger.info("I'm removing list of public IDs with "
+ filterGetRecords.getFoundPublicIds().size() + " item/s. Is it right?");
in = GetResponseRecordFilter.overrideResponseIdsByListIds(reus,
filterGetRecords.getFoundPublicIds(), REPLACED_A_PUBLIC_UUID_PLEASE_IGNORE);
} }
} }
if(filters.size()>0){ if (filters.size() > 0) {
logger.info("Applying filtering on geonet:info... filter/s used: "+filters); logger.info("Applying filtering on geonet:info... filter/s used: " + filters);
Document doc = GetResponseRecordFilter.inputStreamToW3CDocument(reus); Document doc = GetResponseRecordFilter.inputStreamToW3CDocument(reus);
List<String> fileIdentifiers = GetResponseRecordFilter.getTextContentStringsForTagName(doc, "gmd:fileIdentifier"); List<String> fileIdentifiers = GetResponseRecordFilter.getTextContentStringsForTagName(doc,
"gmd:fileIdentifier");
List<String> noMatchingFilter = new ArrayList<String>(); List<String> noMatchingFilter = new ArrayList<String>();
for (String fileId : fileIdentifiers) { for (String fileId : fileIdentifiers) {
//CKECKING THE FILTERS // CKECKING THE FILTERS
for (String fkey : filters.keySet()) { for (String fkey : filters.keySet()) {
String value = GetResponseRecordFilter.getMetadataValueByFileIdentifier(fileId, config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(), config.getAdminAccount().getPassword(), fkey); String value = GetResponseRecordFilter.getMetadataValueByFileIdentifier(fileId,
//String own = GetResponseRecordFilter.getMetaOwnerNameByFileIdentifier(fileId, config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(), config.getAdminAccount().getPassword()); config.getGeoNetworkEndpoint(), config.getAdminAccount().getUser(),
String fValue = filters.get(fkey); config.getAdminAccount().getPassword(), fkey);
//Either the filter KEY doesn't matching any geonet:info (value==null) // String own = GetResponseRecordFilter.getMetaOwnerNameByFileIdentifier(fileId,
//or the value of filterKey in geonet:info doesn't matching the passed filterValue (value.compareTo(fValue)!=0) // config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(),
if(value==null || value.compareTo(fValue)!=0){ // config.getAdminAccount().getPassword());
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.."); String fValue = filters.get(fkey);
noMatchingFilter.add(fileId); // Either the filter KEY doesn't matching any geonet:info (value==null)
//WHEN I ADD THE FILE IDENTIFIER TO FILTERED ID, I CAN EXIT FROM CKECKING FILTERS LOOP // or the value of filterKey in geonet:info doesn't matching the passed
break; // 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..");
noMatchingFilter.add(fileId);
// WHEN I ADD THE FILE IDENTIFIER TO FILTERED ID, I CAN EXIT FROM CKECKING
// FILTERS LOOP
break;
}
} }
} }
if(noMatchingFilter.size()>0){ if (noMatchingFilter.size() > 0) {
logger.info("Removing "+noMatchingFilter.size()+" layer/s that not macthing the filters: "+filters); logger.info("Removing " + noMatchingFilter.size()
//Document doc2 = GetResponseRecordFilter.inputStreamToW3CDocument(reus); + " layer/s that not macthing the filters: " + filters);
in = GetResponseRecordFilter.overrideResponseIdsByListIds(reus, noMatchingFilter, REPLACED_UUID_BY_FILTER_PLEASE_IGNORE); // Document doc2 = GetResponseRecordFilter.inputStreamToW3CDocument(reus);
//in = GetResponseRecordFilter.w3CDocumentToInputStream(doc); in = GetResponseRecordFilter.overrideResponseIdsByListIds(reus, noMatchingFilter,
REPLACED_UUID_BY_FILTER_PLEASE_IGNORE);
// in = GetResponseRecordFilter.w3CDocumentToInputStream(doc);
}else{ } else {
logger.info("No replace on UUIDs was applied from filters: "+filters); logger.info("No replace on UUIDs was applied from filters: " + filters);
in = reus; in = reus;
} }
@ -501,46 +560,49 @@ public class GeonetworkResolver {
ReusableInputStream reusIs = new ReusableInputStream(in); ReusableInputStream reusIs = new ReusableInputStream(in);
//END DEBUG // END DEBUG
logger.info("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 =
//.header(ConstantsResolver.CONTENT_DISPOSITION,"attachment; filename = \""+fileName+"\"") // \""+fileName+"\"")
.header(ConstantsResolver.CONTENT_TYPE, httpUtils.getLastContentType()).build(); .header(ConstantsResolver.CONTENT_TYPE, httpUtils.getLastContentType()).build();
}catch(Exception e){ } catch (Exception e) {
logger.error("Error on copy the response to send to client: ", e); logger.error("Error on copy the response to send to client: ", e);
throw ExceptionManager.internalErrorException(req, "Error on copy the response!", this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, "Error on copy the response!", this.getClass(),
}finally{ helpURI);
} finally {
IOUtils.closeQuietly(in); IOUtils.closeQuietly(in);
} }
} catch (IllegalArgumentException e){ } catch (IllegalArgumentException e) {
logger.error("IllegalArgumentException:", e); logger.error("IllegalArgumentException:", e);
throw ExceptionManager.badRequestException(req, "Illegal argument to carry out the request!", this.getClass(), helpURI); throw ExceptionManager.badRequestException(req, "Illegal argument to carry out the request!",
this.getClass(), helpURI);
} catch (Exception e) { } catch (Exception e) {
logger.error("Exception:", e); logger.error("Exception:", e);
String error = "Sorry, an error occurred on resolving geonetwork request with scope "+scope+". Please, contact support!"; String error = "Sorry, an error occurred on resolving geonetwork request with scope " + scope
+ ". Please, contact support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }
}catch (Exception e) { } catch (Exception e) {
if(!(e instanceof WebApplicationException)){ if (!(e instanceof WebApplicationException)) {
//UNEXPECTED EXCEPTION managing it as WebApplicationException // UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error during perform POST operation to: "+gnCSWlURL+". Please, contact the support!"; String error = "Error during perform POST operation to: " + gnCSWlURL
if(e.getCause()!=null) + ". Please, contact the support!";
error+="\n\nCaused: "+e.getCause().getMessage(); if (e.getCause() != null)
error += "\n\nCaused: " + e.getCause().getMessage();
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }
//ALREADY MANAGED AS WebApplicationException // ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }
} }
/** /**
* Gets the geonetwork instance for scope. * Gets the geonetwork instance for scope.
@ -549,15 +611,15 @@ public class GeonetworkResolver {
* @return the geonetwork instance for scope * @return the geonetwork instance for scope
* @throws Exception the exception * @throws Exception the exception
*/ */
protected GeonetworkInstance getGeonetworkInstanceForScope(String scope) throws Exception{ protected GeonetworkInstance getGeonetworkInstanceForScope(String scope) throws Exception {
logger.info("Trying to read the {} from cache for scope: {}",GeonetworkInstance.class.getSimpleName(), scope); logger.info("Trying to read the {} from cache for scope: {}", GeonetworkInstance.class.getSimpleName(), scope);
GeonetworkInstance geoInstance; GeonetworkInstance geoInstance;
try { try {
geoInstance = LoadingGeonetworkInstanceCache.get(scope); geoInstance = LoadingGeonetworkInstanceCache.get(scope);
}catch (Exception e) { } catch (Exception e) {
logger.error("An error occurred on reading GeonetworkInstance for scope "+scope, e); 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); throw new Exception("Sorry, An error occurred on reading GeonetworkInstance for scope " + scope);
} }
return geoInstance; return geoInstance;

View File

@ -33,8 +33,17 @@ import org.slf4j.LoggerFactory;
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
/** /**
* The Class GisResolver. * The GisResolver is able to resolve GIS Links (as a redirect to Gis Viewer
* Application) in order to display and navigate on web-map the gis layers
* stored in D4Science Geonetwork
* (e.g. http://wiki.i-marine.eu/index.php/Blue_Hackathon_iMarine_Data_Challenges#iMarine_GeoNetwork)
* *
* Request format
* [URI_RESOLVER_SERVICE_ENDPOINT]/gis?gis-UUID=[UUID]&scope=[SCOPE]
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#GIS_Resolver
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Dec 14, 2018 * Dec 14, 2018
*/ */

View File

@ -24,8 +24,14 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The Class KnimeCreateResolver. * The KnimeCreateResolver is able to create a KNIME URL.
* *
* Request format
* [URI_RESOLVER_SERVICE_ENDPOINT]/knime/create?[QUERY_STRING_TO_INVOKE_A_KNIME_MODEL]
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#KNIME_Resolver
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
* *
* Mar 24, 2022 * Mar 24, 2022
@ -38,7 +44,11 @@ public class KnimeCreateResolver {
private static String helpURI = "https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#KNIME_Resolver"; private static String helpURI = "https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#KNIME_Resolver";
/** /**
* Creates the knime URL. * Creates the KNIME URL. Generate a Knime URL (then resolved by the /get path)
* for a KNIME Model Simulation passed by query string.
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#HTTP_POST:_Create_a_KNIME_URL
* *
* @param req the req * @param req the req
* @return the response * @return the response

View File

@ -23,12 +23,14 @@ import org.slf4j.LoggerFactory;
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
/** /**
* The Class KnimeGetResolver. * The KnimeGetResolver provides a method to get the Knime URLs (that are simply
* URLs) by which is possible to invoke the KNIME Model Simulation Application.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * See more at
* Dec 13, 2018 * https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#KNIME_Resolver
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Dec 13, 2018
*/ */
@Path("knime") @Path("knime")
public class KnimeGetResolver { public class KnimeGetResolver {
@ -37,8 +39,7 @@ public class KnimeGetResolver {
private static String helpURI = "https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#KNIME_Resolver"; private static String helpURI = "https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#KNIME_Resolver";
private static final String ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL = private static final String ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL = "org.gcube.portlets.user.model-simulation-configuration.server.KnimeModelSimulationManagerServiceImpl";
"org.gcube.portlets.user.model-simulation-configuration.server.KnimeModelSimulationManagerServiceImpl";
private static final String APPLICATION_PROFILE = "ApplicationProfile"; private static final String APPLICATION_PROFILE = "ApplicationProfile";
@ -47,55 +48,62 @@ public class KnimeGetResolver {
/** /**
* Resolve knime url. * Resolve knime url.
* *
* @param req the req * @param req the req
* @param vreName the vre name * @param vreName the vre name
* @return the response * @return the response
*/ */
@GET @GET
@Path("/get/{vreName}") @Path("/get/{vreName}")
public Response resolveKnimeURL(@Context HttpServletRequest req, @PathParam("vreName") String vreName) { public Response resolveKnimeURL(@Context HttpServletRequest req, @PathParam("vreName") String vreName) {
logger.info(this.getClass().getSimpleName()+" GET starts..."); logger.info(this.getClass().getSimpleName() + " GET starts...");
try { try {
if(vreName==null || vreName.isEmpty()){ if (vreName == null || vreName.isEmpty()) {
logger.error("The path parameter 'vreName' not found or empty in the path"); logger.error("The path parameter 'vreName' not found or empty in the path");
throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty", this.getClass(), helpURI); throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty",
this.getClass(), helpURI);
} }
ScopeBean scopeBean = null; ScopeBean scopeBean = null;
try{ try {
scopeBean = LoadingMapOfScopeCache.get(vreName); scopeBean = LoadingMapOfScopeCache.get(vreName);
}catch(ExecutionException | InvalidCacheLoadException e){ } catch (ExecutionException | InvalidCacheLoadException e) {
logger.error("Error on getting the fullscope from cache for vreName "+vreName, e); logger.error("Error on getting the fullscope from cache for vreName " + vreName, e);
throw ExceptionManager.wrongParameterException(req, "Error on getting full scope for the VRE name "+vreName+". Is it registered as VRE in the D4Science Infrastructure System?", this.getClass(), helpURI); throw ExceptionManager.wrongParameterException(req,
"Error on getting full scope for the VRE name " + vreName
+ ". Is it registered as VRE in the D4Science Infrastructure System?",
this.getClass(), helpURI);
} }
ApplicationProfileReader reader = null; ApplicationProfileReader reader = null;
String fullScope = scopeBean.toString(); String fullScope = scopeBean.toString();
try{ try {
reader = new ApplicationProfileReader(fullScope, APPLICATION_PROFILE, ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL, false); reader = new ApplicationProfileReader(fullScope, APPLICATION_PROFILE,
}catch(Exception e){ ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL, false);
logger.error("Error on reading the "+APPLICATION_PROFILE+" with APPID: "+ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL, e); } catch (Exception e) {
throw ExceptionManager.internalErrorException(req, "Error on reading the Application Profile for the "+KNIME_EXECUTOR_APPLICATION+". Please contact the support", this.getClass(), helpURI); logger.error("Error on reading the " + APPLICATION_PROFILE + " with APPID: "
+ ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL, e);
throw ExceptionManager.internalErrorException(req, "Error on reading the Application Profile for the "
+ KNIME_EXECUTOR_APPLICATION + ". Please contact the support", this.getClass(), helpURI);
} }
//READ THE KNIME URL PORTLET FROM APPLICATION PROFRILE IN THE SCOPE fullScope // READ THE KNIME URL PORTLET FROM APPLICATION PROFRILE IN THE SCOPE fullScope
String knimeExecutorEndPoint = reader.getApplicationProfile().getUrl(); String knimeExecutorEndPoint = reader.getApplicationProfile().getUrl();
//CHECKING THE QUERY STRING // CHECKING THE QUERY STRING
String queryString = req.getQueryString()!=null?req.getQueryString():""; String queryString = req.getQueryString() != null ? req.getQueryString() : "";
String knimeExecutorURL = String.format("%s?%s", knimeExecutorEndPoint, queryString); String knimeExecutorURL = String.format("%s?%s", knimeExecutorEndPoint, queryString);
logger.info("Resolving the Knime URL with: "+knimeExecutorURL); logger.info("Resolving the Knime URL with: " + knimeExecutorURL);
return Response.seeOther(new URI(knimeExecutorURL)).build(); return Response.seeOther(new URI(knimeExecutorURL)).build();
}catch (Exception e) { } catch (Exception e) {
if(!(e instanceof WebApplicationException)){ if (!(e instanceof WebApplicationException)) {
//UNEXPECTED EXCEPTION managing it as WebApplicationException // UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Sorry, an error occurred on resolving the Knime URL. Please, contact the support!"; String error = "Sorry, an error occurred on resolving the Knime URL. Please, contact the support!";
if(e.getCause()!=null) if (e.getCause() != null)
error+="\n\nCaused: "+e.getCause().getMessage(); error += "\n\nCaused: " + e.getCause().getMessage();
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }
//ALREADY MANAGED AS WebApplicationException // ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }

View File

@ -28,12 +28,13 @@ import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The Class PartheosRegistryResolver. * The PartheosRegistryResolver.
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Parthenos_URL_Resolver
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Nov 16, 2018
* Nov 16, 2018
*/ */
@Path("parthenos_registry") @Path("parthenos_registry")
public class PartheosRegistryResolver { public class PartheosRegistryResolver {
@ -43,65 +44,70 @@ public class PartheosRegistryResolver {
/** /**
* Resolve parthenos url. * Resolve parthenos url.
*
* To resolve an "item" from a Parthenos URL stored in the Parthenos Catalogue
* at https://ckan-parthenos.d4science.org/
* *
* @param req the req * @param req the req
* @param provider the provider * @param provider the provider
* @param path the path * @param path the path
* @param remainPath the remain path * @param remainPath the remain path
* @return the response * @return the response
*/ */
@GET @GET
@Path("/{provider}/{path}{remainPath:(/[^?$]+)?}") @Path("/{provider}/{path}{remainPath:(/[^?$]+)?}")
public Response resolveParthenosURL(@Context HttpServletRequest req, public Response resolveParthenosURL(@Context HttpServletRequest req, @PathParam("provider") String provider,
@PathParam("provider") String provider, @PathParam("path") String path, @PathParam("remainPath") String remainPath) throws WebApplicationException {
@PathParam("path") String path,
@PathParam("remainPath") String remainPath) throws WebApplicationException {
logger.info(this.getClass().getSimpleName()+" GET starts..."); logger.info(this.getClass().getSimpleName() + " GET starts...");
String remainPathParthenosURL = null; String remainPathParthenosURL = null;
try { try {
logger.debug("provider is: "+provider); logger.debug("provider is: " + provider);
logger.debug("path is: "+path); logger.debug("path is: " + path);
logger.debug("remainPath is: "+remainPath); logger.debug("remainPath is: " + remainPath);
remainPathParthenosURL = String.format("%s/%s",provider,path); remainPathParthenosURL = String.format("%s/%s", provider, path);
if(remainPath!=null && !remainPath.isEmpty()){ if (remainPath != null && !remainPath.isEmpty()) {
remainPathParthenosURL+=remainPath.startsWith("/")?remainPath:"/"+remainPath; remainPathParthenosURL += remainPath.startsWith("/") ? remainPath : "/" + remainPath;
} }
logger.info("Resolving parthenos URL: "+remainPathParthenosURL); logger.info("Resolving parthenos URL: " + remainPathParthenosURL);
//APPLYING URL DECODING // APPLYING URL DECODING
remainPathParthenosURL = URLDecoder.decode(remainPathParthenosURL, "UTF-8"); remainPathParthenosURL = URLDecoder.decode(remainPathParthenosURL, "UTF-8");
//APPLYING NAME TRANSFORMATION // APPLYING NAME TRANSFORMATION
String normalizedEntityName = toNameForCatalogue(remainPathParthenosURL); String normalizedEntityName = toNameForCatalogue(remainPathParthenosURL);
logger.info("Trying to resolve with Catalogue EntityName: "+normalizedEntityName); logger.info("Trying to resolve with Catalogue EntityName: " + normalizedEntityName);
ItemCatalogueURLs itemCatalogueURLs = CatalogueResolver.getItemCatalogueURLs(req, UriResolverSmartGearManagerInit.getParthenosVREName(), ResourceCatalogueCodes.CTLGD.getId(), normalizedEntityName); ItemCatalogueURLs itemCatalogueURLs = CatalogueResolver.getItemCatalogueURLs(req,
UriResolverSmartGearManagerInit.getParthenosVREName(), ResourceCatalogueCodes.CTLGD.getId(),
normalizedEntityName);
return Response.seeOther(new URL(itemCatalogueURLs.getPrivateVRECataloguePortletURL()).toURI()).build(); return Response.seeOther(new URL(itemCatalogueURLs.getPrivateVRECataloguePortletURL()).toURI()).build();
}catch (Exception e) { } catch (Exception e) {
if(!(e instanceof WebApplicationException)){ if (!(e instanceof WebApplicationException)) {
//UNEXPECTED EXCEPTION managing it as WebApplicationException // UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error occurred on resolving the path "+remainPathParthenosURL+". Please, contact the support!"; String error = "Error occurred on resolving the path " + remainPathParthenosURL
if(e.getCause()!=null) + ". Please, contact the support!";
error+="\n\nCaused: "+e.getCause().getMessage(); if (e.getCause() != null)
error += "\n\nCaused: " + e.getCause().getMessage();
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }
//ALREADY MANAGED AS WebApplicationException // ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }
} }
/** /**
* Post catalogue. * To get a normalized item name from a Parthenos URL. It applies a
* normalization function to get from an input Parthenos URL an item name that
* is catalogue compliant.
* *
* @param req the req * @param req the req
* @param jsonRequest the json request * @param jsonRequest the json request
* @return the response * @return the response
* @throws Exception the exception * @throws Exception the exception
@ -110,59 +116,67 @@ public class PartheosRegistryResolver {
@Path("") @Path("")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN)
public Response postCatalogue(@Context HttpServletRequest req, ParthenosRequest jsonRequest) throws WebApplicationException{ public Response postCatalogue(@Context HttpServletRequest req, ParthenosRequest jsonRequest)
logger.info(this.getClass().getSimpleName()+" POST starts..."); throws WebApplicationException {
logger.info(this.getClass().getSimpleName() + " POST starts...");
try{ try {
String entityName = jsonRequest.getEntity_name(); String entityName = jsonRequest.getEntity_name();
if(entityName==null || entityName.isEmpty()){ if (entityName == null || entityName.isEmpty()) {
logger.error("Entity Name Parameter like 'entity_name' not found or empty"); logger.error("Entity Name Parameter like 'entity_name' not found or empty");
throw ExceptionManager.badRequestException(req, "Mandatory body parameter 'entity_name' not found or empty", this.getClass(), helpURI); throw ExceptionManager.badRequestException(req,
"Mandatory body parameter 'entity_name' not found or empty", this.getClass(), helpURI);
} }
//REMOVING FIRST '/' IF EXISTS // REMOVING FIRST '/' IF EXISTS
entityName = entityName.startsWith("/")?entityName.substring(1,entityName.length()):entityName; entityName = entityName.startsWith("/") ? entityName.substring(1, entityName.length()) : entityName;
//APPLYING NAME TRANSFORMATION // APPLYING NAME TRANSFORMATION
String normalizedEntityName = toNameForCatalogue(entityName); String normalizedEntityName = toNameForCatalogue(entityName);
ItemCatalogueURLs itemCatalogueURLs = CatalogueResolver.getItemCatalogueURLs(req, UriResolverSmartGearManagerInit.getParthenosVREName(), ResourceCatalogueCodes.CTLGD.getId(), normalizedEntityName); ItemCatalogueURLs itemCatalogueURLs = CatalogueResolver.getItemCatalogueURLs(req,
logger.info("Returining Catalogue URL: "+itemCatalogueURLs.getPrivateVRECataloguePortletURL()); UriResolverSmartGearManagerInit.getParthenosVREName(), ResourceCatalogueCodes.CTLGD.getId(),
return Response.ok(normalizedEntityName).header("Location", itemCatalogueURLs.getPrivateVRECataloguePortletURL()).build(); normalizedEntityName);
logger.info("Returining Catalogue URL: " + itemCatalogueURLs.getPrivateVRECataloguePortletURL());
return Response.ok(normalizedEntityName)
.header("Location", itemCatalogueURLs.getPrivateVRECataloguePortletURL()).build();
}catch (Exception e) { } catch (Exception e) {
if(!(e instanceof WebApplicationException)){ if (!(e instanceof WebApplicationException)) {
//UNEXPECTED EXCEPTION managing it as WebApplicationException // UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error occurred on transforming the "+jsonRequest+". Please, contact the support!"; String error = "Error occurred on transforming the " + jsonRequest + ". Please, contact the support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI); throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
} }
//ALREADY MANAGED AS WebApplicationException // ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }
} }
/** /**
* To name for catalogue. * To name for catalogue. this method applyes a fuction to transform a parthenos
* this method applyes a fuction to transform a parthenos URL to acceptable catalogue name (that is URL) * URL to acceptable catalogue name (that is URL)
*
* @param remainPathParthenosURL the remain path parthenos url * @param remainPathParthenosURL the remain path parthenos url
* @return the string * @return the string
* @throws UnsupportedEncodingException the unsupported encoding exception * @throws UnsupportedEncodingException the unsupported encoding exception
*/ */
protected String toNameForCatalogue(final String remainPathParthenosURL) throws UnsupportedEncodingException { protected String toNameForCatalogue(final String remainPathParthenosURL) throws UnsupportedEncodingException {
//need to double decode for URLs like: http://parthenos.d4science.org/handle/Parthenos/REG/Dataset/Appellation/Isidore%2520Dataset // need to double decode for URLs like:
String name = StringUtils.replaceChars(URLDecoder.decode(remainPathParthenosURL,"UTF-8"),"/ .:", "_").toLowerCase().replaceAll("[^A-Za-z0-9]", "_"); // http://parthenos.d4science.org/handle/Parthenos/REG/Dataset/Appellation/Isidore%2520Dataset
//TO LOWERCASE FOR CKAN SUPPORTING String name = StringUtils.replaceChars(URLDecoder.decode(remainPathParthenosURL, "UTF-8"), "/ .:", "_")
.toLowerCase().replaceAll("[^A-Za-z0-9]", "_");
// TO LOWERCASE FOR CKAN SUPPORTING
return name.toLowerCase(); return name.toLowerCase();
} }
//TO TEST // TO TEST
// public static void main(String[] args) throws UnsupportedEncodingException { // public static void main(String[] args) throws UnsupportedEncodingException {
// //
// String remainPathParthenosURL = "Culturalitalia/unknown/Dataset/oai%3Aculturaitalia.it%3Aoai%3Aculturaitalia.it%3Amuseiditalia-mus_11953"; // String remainPathParthenosURL =
// System.out.println(URLDecoder.decode(remainPathParthenosURL, "UTF-8")); // "Culturalitalia/unknown/Dataset/oai%3Aculturaitalia.it%3Aoai%3Aculturaitalia.it%3Amuseiditalia-mus_11953";
// System.out.println(URLDecoder.decode(remainPathParthenosURL, "UTF-8"));
// //
// } // }
} }

View File

@ -20,8 +20,14 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The Class SMPIDResolver. * The SMPIDResolver is able to give HTTP resolution to storage resource by ID.
* *
* Request format
* [URI_RESOLVER_SERVICE_ENDPOINT]/id?smp-id=[STORAGE_SMP_ID]&fileName=[FILENAME]&contentType=[CONTENT_TYPE]
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#SMP-ID_Resolver
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
* *
* Mar 24, 2022 * Mar 24, 2022

View File

@ -20,8 +20,14 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The Class SMPResolver. * The SMPResolver is able to give HTTP resolution to SMP protocol URIs
*
* Request format
* [URI_RESOLVER_SERVICE_ENDPOINT]/smp?smp-uri=smp://.....
* *
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#SMP_Resolver
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
* *
* Mar 24, 2022 * Mar 24, 2022

View File

@ -25,10 +25,17 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The Class StorageHubResolver. * The StorageHubResolver provides the methods either to download a gCube
* * Workspace file or to get its metadata.
*
* Request format
* [URI_RESOLVER_SERVICE_ENDPOINT]/shub/[STORAGE_HUB_FILE_ID]
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-HUB_Resolver
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Dec 14, 2018 * Dec 14, 2018
*/ */
@Path("shub") @Path("shub")
public class StorageHubResolver { public class StorageHubResolver {
@ -46,7 +53,6 @@ public class StorageHubResolver {
@PathParam(STORAGE_HUB_ID) @PathParam(STORAGE_HUB_ID)
String id; String id;
/** /**
* Gets the metadata. * Gets the metadata.
* *
@ -56,45 +62,47 @@ public class StorageHubResolver {
@HEAD @HEAD
@Path("/{id}") @Path("/{id}")
public Response getMetadata(@Context HttpServletRequest req) { public Response getMetadata(@Context HttpServletRequest req) {
logger.info(this.getClass().getSimpleName()+" HEAD getMetadata called"); logger.info(this.getClass().getSimpleName() + " HEAD getMetadata called");
try{ try {
//TODO Do we need to check the token? // TODO Do we need to check the token?
//Checking mandatory parameter id // Checking mandatory parameter id
if(id==null || id.isEmpty()){ if (id == null || id.isEmpty()) {
logger.error("Path Parameter "+STORAGE_HUB_ID+" not found"); logger.error("Path Parameter " + STORAGE_HUB_ID + " not found");
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter "+STORAGE_HUB_ID, this.getClass(), help); throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter " + STORAGE_HUB_ID,
this.getClass(), help);
} }
try{ try {
ItemManagerClient client = AbstractPlugin.item().build(); ItemManagerClient client = AbstractPlugin.item().build();
StreamDescriptor descriptor = client.resolvePublicLink(id); StreamDescriptor descriptor = client.resolvePublicLink(id);
ResponseBuilder response = Response.ok(); ResponseBuilder response = Response.ok();
response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id, CONTENT_DISPOSITION_VALUE.attachment); response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id,
CONTENT_DISPOSITION_VALUE.attachment);
return response.build(); return response.build();
}catch(Exception e){ } catch (Exception e) {
logger.error("Error on getting metadata for file with "+id, e); logger.error("Error on getting metadata for file with " + id, e);
String errorMsg = "Error on getting metadata for file with hub id '"+id+"'. "+e.getMessage(); String errorMsg = "Error on getting metadata for file with hub id '" + id + "'. " + e.getMessage();
throw ExceptionManager.internalErrorException(req, errorMsg, this.getClass(), help); throw ExceptionManager.internalErrorException(req, errorMsg, this.getClass(), help);
} }
}catch (Exception e) { } catch (Exception e) {
if(!(e instanceof WebApplicationException)){ if (!(e instanceof WebApplicationException)) {
//UNEXPECTED EXCEPTION managing it as WebApplicationException // UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error occurred on resolving the StorageHub URL with id: "+id+". Please, contact the support!"; String error = "Error occurred on resolving the StorageHub URL with id: " + id
+ ". Please, contact the support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), help); throw ExceptionManager.internalErrorException(req, error, this.getClass(), help);
} }
//ALREADY MANAGED as WebApplicationException // ALREADY MANAGED as WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }
} }
/** /**
* Download. * Download.
* *
@ -103,46 +111,50 @@ public class StorageHubResolver {
*/ */
@GET @GET
@Path("/{id}") @Path("/{id}")
public Response download(@Context HttpServletRequest req, @QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition) { public Response download(@Context HttpServletRequest req,
logger.info(this.getClass().getSimpleName()+" GET download called"); @QueryParam(ConstantsResolver.QUERY_PARAM_CONTENTDISPOSITION) String contentDisposition) {
logger.info(this.getClass().getSimpleName() + " GET download called");
try{ try {
InnerMethodName.instance.set("resolveStorageHubPublicLink"); InnerMethodName.instance.set("resolveStorageHubPublicLink");
//Checking mandatory parameter "id" // Checking mandatory parameter "id"
if(id==null || id.isEmpty()){ if (id == null || id.isEmpty()) {
logger.error("Path Parameter "+STORAGE_HUB_ID+" not found"); logger.error("Path Parameter " + STORAGE_HUB_ID + " not found");
throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter "+STORAGE_HUB_ID, StorageHubResolver.class, help); throw ExceptionManager.badRequestException(req, "Missing mandatory path parameter " + STORAGE_HUB_ID,
StorageHubResolver.class, help);
} }
//Checking the optional parameter "Content-Disposition" // Checking the optional parameter "Content-Disposition"
CONTENT_DISPOSITION_VALUE dispositionValue = CONTENT_DISPOSITION_VALUE.attachment; CONTENT_DISPOSITION_VALUE dispositionValue = CONTENT_DISPOSITION_VALUE.attachment;
//Validating the Content-Disposition value // Validating the Content-Disposition value
dispositionValue = ValidateContentDisposition.validValue(req, this.getClass(), help, contentDisposition); dispositionValue = ValidateContentDisposition.validValue(req, this.getClass(), help, contentDisposition);
try{ try {
ItemManagerClient client = AbstractPlugin.item().build(); ItemManagerClient client = AbstractPlugin.item().build();
StreamDescriptor descriptor = client.resolvePublicLink(id); StreamDescriptor descriptor = client.resolvePublicLink(id);
ResponseBuilder response = Response.ok(descriptor.getStream()); ResponseBuilder response = Response.ok(descriptor.getStream());
response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id, dispositionValue); response = new StorageHubMetadataResponseBuilder(req, response).fillMetadata(descriptor, id,
dispositionValue);
return response.build(); return response.build();
}catch(Exception e){ } catch (Exception e) {
logger.error("Error on getting file with "+id, e); logger.error("Error on getting file with " + id, e);
String errorMsg = "Error on getting file with hub id '"+id+"'. "+e.getMessage(); String errorMsg = "Error on getting file with hub id '" + id + "'. " + e.getMessage();
throw ExceptionManager.internalErrorException(req, errorMsg, StorageHubResolver.class, help); throw ExceptionManager.internalErrorException(req, errorMsg, StorageHubResolver.class, help);
} }
}catch (Exception e) { } catch (Exception e) {
if(!(e instanceof WebApplicationException)){ if (!(e instanceof WebApplicationException)) {
//UNEXPECTED EXCEPTION managing it as WebApplicationException // UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = "Error occurred on resolving the StorageHub URL with id: "+id+". Please, contact the support!"; String error = "Error occurred on resolving the StorageHub URL with id: " + id
+ ". Please, contact the support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), help); throw ExceptionManager.internalErrorException(req, error, this.getClass(), help);
} }
//ALREADY MANAGED AS WebApplicationException // ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e); logger.error("Exception:", e);
throw (WebApplicationException) e; throw (WebApplicationException) e;
} }

View File

@ -36,8 +36,14 @@ import org.slf4j.LoggerFactory;
/** /**
* The Class StorageIDResolver. * The StorageIDResolver is able to give HTTP resolution to storage resource by ID
* *
* Request Format
* [URI_RESOLVER_SERVICE_ENDPOINT]/[STORAGE_ID]
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-ID_Resolver
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Dec 14, 2018 * Dec 14, 2018
*/ */

View File

@ -10,17 +10,15 @@ import java.io.InputStream;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException; import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager; import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The Class UriResolverDocs. * The UriResolverDocs provides the URI Resolver API Documentation
* *
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
* *

View File

@ -14,7 +14,7 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
/** /**
* The Class UriResolverInfo. * The UriResolverInfo get index.
* *
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
* *

View File

@ -36,7 +36,14 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The Class WekeoResolver. * The WekeoResolver provides a method to wrap the basic authentication from
* D4Science account to WekeoBroker service.
*
* Request format
* [URI_RESOLVER_SERVICE_ENDPOINT]/wekeo/gettoken?gcube-token=[YOUR_GCUBE_TOKEN]
*
* See more at
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Wekeo_Resolver
* *
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
* *