starting work on Parthenos Resolver
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@174355 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
23deec6648
commit
815858c4f3
|
@ -0,0 +1,17 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.datatransfer.resolver.catalogue;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Nov 16, 2018
|
||||
*
|
||||
* Binding the body of ParthenosPostRequest as JSON
|
||||
*/
|
||||
public class ParthenosPostRequest {
|
||||
|
||||
String parthenosURL;
|
||||
}
|
|
@ -10,11 +10,9 @@ import javax.ws.rs.POST;
|
|||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.datatransfer.resolver.caches.LoadingVREsScopeCache;
|
||||
|
@ -30,64 +28,49 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import eu.trentorise.opendata.jackan.model.CkanDataset;
|
||||
|
||||
/**
|
||||
* The Class CatalogueResolver.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Nov 16, 2018
|
||||
*/
|
||||
@Path("/")
|
||||
public class CatalogueResolver {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(CatalogueResolver.class);
|
||||
private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#CATALOGUE_Resolver";
|
||||
|
||||
/** The scope to enc decr. */
|
||||
//private String scopeToEncDecr = null;
|
||||
|
||||
//ApplicationProfileReaderForCatalogueResolver appPrCatResolver;
|
||||
|
||||
/**
|
||||
* Resolve catalogue.
|
||||
*
|
||||
* @param req the req
|
||||
* @param entityName the entity name
|
||||
* @param vreName the vre name
|
||||
* @param entityContext the entity context
|
||||
* @return the response
|
||||
*/
|
||||
@GET
|
||||
@Path("{entityContext:ctlg(-(o|g|p|d))?}/{vreName}/{entityName}")
|
||||
public Response resolveCatalogue(@PathParam("entityName") String entityName, @PathParam("vreName") String vreName, @PathParam("entityContext") String entityContext) {
|
||||
public Response resolveCatalogue(@Context HttpServletRequest req, @PathParam("entityName") String entityName, @PathParam("vreName") String vreName, @PathParam("entityContext") String entityContext) {
|
||||
InnerMethodName.instance.set("resolveCataloguePublicLink");
|
||||
logger.info(CatalogueResolver.class.getSimpleName()+" GET starts...");
|
||||
try {
|
||||
String entityContextValue = ResourceCatalogueCodes.valueOfCodeId(entityContext).getValue();
|
||||
|
||||
//ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(vreName, true);
|
||||
|
||||
String fullScope = LoadingVREsScopeCache.getCache().get(vreName);
|
||||
logger.info("Read fullScope: "+fullScope + " for VRE_NAME: "+vreName +" from cache created by: "+GetAllInfrastructureVREs.class.getSimpleName());
|
||||
|
||||
//String fullScope = appPrCatResolver.getHashVreNameScope().get(vreName);
|
||||
|
||||
ScopeProvider.instance.set(fullScope);
|
||||
GatewayCKANCatalogueReference ckanCatalogueReference = CkanCatalogueConfigurationsReader.loadCatalogueEndPoints();
|
||||
|
||||
logger.info("For scope "+fullScope+" loaded end points: "+ckanCatalogueReference);
|
||||
|
||||
//IS THE PRODUCT PLUBLIC OR PRIVATE?
|
||||
//USING ACCESS TO PUBLIC PORTLET IF THE ITEM IS PUBLIC, OTHERWISE ACCESS TO PRIVATE PORTLET
|
||||
String ckanPorltetUrl = ckanCatalogueReference.getPrivatePortletURL();
|
||||
String datasetName = entityName;
|
||||
if(ckanCatalogueReference.getCkanURL()!=null){
|
||||
try{
|
||||
CkanDataset dataset = CkanCatalogueConfigurationsReader.getDataset(datasetName, ckanCatalogueReference.getCkanURL());
|
||||
if(dataset!=null){
|
||||
ckanPorltetUrl = ckanCatalogueReference.getPublicPortletURL();
|
||||
logger.info("The dataset "+datasetName+" is a public item using public access to CKAN portlet: "+ckanPorltetUrl);
|
||||
}
|
||||
}catch(Exception e){
|
||||
logger.warn("Error on checking if dataset: "+datasetName+" is private or not", e);
|
||||
ckanPorltetUrl = ckanCatalogueReference.getPublicPortletURL();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String url = String.format("%s?path=/%s/%s",ckanPorltetUrl,entityContextValue, entityName);
|
||||
|
||||
return Response.seeOther(new URL(url).toURI()).build();
|
||||
String itemCatalogueURL = getItemCatalogueURL(vreName, entityContext, entityName);
|
||||
return Response.seeOther(new URL(itemCatalogueURL).toURI()).build();
|
||||
}catch (Exception e) {
|
||||
logger.error("error resolving catalogue link",e);
|
||||
throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
|
||||
ExceptionManager.throwInternalErrorException(req, "Error occurred resolving catalogue link", this.getClass(), helpURI);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Post catalogue.
|
||||
*
|
||||
* @param req the req
|
||||
* @param jsonRequest the json request
|
||||
* @return the response
|
||||
*/
|
||||
@POST
|
||||
@Path("catalogue")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
|
@ -128,31 +111,63 @@ public class CatalogueResolver {
|
|||
//throw new WebApplicationException("Entity context is null/malformed", Status.BAD_REQUEST);
|
||||
}
|
||||
|
||||
|
||||
String linkURL = String.format("%s/%s/%s/%s", serverUrl, rc.getId(), vreName, jsonRequest.getEntity_name());
|
||||
|
||||
logger.info("Returining Catalogue URL: "+linkURL);
|
||||
|
||||
//IT'S GOING TO UPDATE THE GENERIC RESOURCE IF IS NEEDED
|
||||
/*final String fullscope = scope;
|
||||
new Thread(){
|
||||
public void run() {
|
||||
try {
|
||||
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);
|
||||
}
|
||||
catch (ApplicationProfileNotFoundException e) {
|
||||
logger.error("Error during validating Application Profile", e);
|
||||
}
|
||||
};
|
||||
}.start();*/
|
||||
|
||||
|
||||
return Response.ok(linkURL).header("Location", linkURL).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the item catalogue url.
|
||||
*
|
||||
* @param vreName the vre name
|
||||
* @param entityContext the entity context
|
||||
* @param entityName the entity name
|
||||
* @return the item catalogue url
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
protected static String getItemCatalogueURL(String vreName, String entityContext, String entityName) throws Exception{
|
||||
|
||||
try {
|
||||
String entityContextValue = ResourceCatalogueCodes.valueOfCodeId(entityContext).getValue();
|
||||
|
||||
//ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(vreName, true);
|
||||
|
||||
String fullScope = LoadingVREsScopeCache.getCache().get(vreName);
|
||||
logger.info("Read fullScope: "+fullScope + " for VRE_NAME: "+vreName +" from cache created by: "+GetAllInfrastructureVREs.class.getSimpleName());
|
||||
|
||||
//String fullScope = appPrCatResolver.getHashVreNameScope().get(vreName);
|
||||
|
||||
ScopeProvider.instance.set(fullScope);
|
||||
GatewayCKANCatalogueReference ckanCatalogueReference = CkanCatalogueConfigurationsReader.loadCatalogueEndPoints();
|
||||
|
||||
logger.info("For scope "+fullScope+" loaded end points: "+ckanCatalogueReference);
|
||||
|
||||
//IS THE PRODUCT PLUBLIC OR PRIVATE?
|
||||
//USING ACCESS TO PUBLIC PORTLET IF THE ITEM IS PUBLIC, OTHERWISE ACCESS TO PRIVATE PORTLET
|
||||
String ckanPorltetUrl = ckanCatalogueReference.getPrivatePortletURL();
|
||||
String datasetName = entityName;
|
||||
if(ckanCatalogueReference.getCkanURL()!=null){
|
||||
try{
|
||||
CkanDataset dataset = CkanCatalogueConfigurationsReader.getDataset(datasetName, ckanCatalogueReference.getCkanURL());
|
||||
if(dataset!=null){
|
||||
ckanPorltetUrl = ckanCatalogueReference.getPublicPortletURL();
|
||||
logger.info("The dataset "+datasetName+" is a public item using public access to CKAN portlet: "+ckanPorltetUrl);
|
||||
}
|
||||
}catch(Exception e){
|
||||
logger.warn("Error on checking if dataset: "+datasetName+" is private or not", e);
|
||||
ckanPorltetUrl = ckanCatalogueReference.getPublicPortletURL();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return String.format("%s?path=/%s/%s",ckanPorltetUrl,entityContextValue, entityName);
|
||||
}catch (Exception e) {
|
||||
logger.error("error resolving catalogue link",e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server url.
|
||||
*
|
||||
|
|
|
@ -129,12 +129,12 @@ public class GeonetworkResolver {
|
|||
|
||||
if(scope==null || scope.isEmpty()){
|
||||
logger.error("Path Parameter 'scope' not found");
|
||||
ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'scope'", GeonetworkResolver.class, help);
|
||||
ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'scope'", this.getClass(), help);
|
||||
}
|
||||
|
||||
if(mode==null || mode.isEmpty()){
|
||||
logger.error("Path Parameter 'scope' not found");
|
||||
ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'mode'", GeonetworkResolver.class, help);
|
||||
ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'mode'", this.getClass(), help);
|
||||
}
|
||||
|
||||
scope = ScopeUtil.normalizeScope(scope, "|");
|
||||
|
@ -144,12 +144,12 @@ public class GeonetworkResolver {
|
|||
}catch(Exception e){
|
||||
List<MODE> toPrint = Arrays.asList(MODE.values());
|
||||
logger.error("The 'mode' parameter is wrong, Have you pass a valid parameter MODE like "+toPrint+"?");
|
||||
ExceptionManager.throwWrongParameterException(req, "The 'mode' parameter must be value of "+toPrint, GeonetworkResolver.class, help);
|
||||
ExceptionManager.throwWrongParameterException(req, "The 'mode' parameter must be value of "+toPrint, this.getClass(), help);
|
||||
}
|
||||
|
||||
if(visibility==null){
|
||||
logger.error("Path Parameter 'visibility' not found");
|
||||
ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'visibility'", GeonetworkResolver.class, help);
|
||||
ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'visibility'", this.getClass(), help);
|
||||
}
|
||||
|
||||
visibility = visibility.toUpperCase();
|
||||
|
@ -158,7 +158,7 @@ public class GeonetworkResolver {
|
|||
}catch (Exception e) {
|
||||
List<VISIBILITY> toPrint = Arrays.asList(VISIBILITY.values());
|
||||
logger.error("The 'visibility' parameter is wrong, Have you pass a valid parameter VISIBILITY like "+toPrint+"?");
|
||||
ExceptionManager.throwWrongParameterException(req, "The 'visibility' parameter must be value of "+toPrint, GeonetworkResolver.class, help);
|
||||
ExceptionManager.throwWrongParameterException(req, "The 'visibility' parameter must be value of "+toPrint, this.getClass(), help);
|
||||
}
|
||||
|
||||
if(resetCache!=null && Boolean.parseBoolean(resetCache)){
|
||||
|
@ -203,23 +203,23 @@ public class GeonetworkResolver {
|
|||
return responseBuilder.build();
|
||||
|
||||
case HttpServletResponse.SC_FORBIDDEN:
|
||||
ExceptionManager.throwForbiddenException(req, "You are not authorized to perform the request "+gnGetlURL, GeonetworkResolver.class, help);
|
||||
ExceptionManager.throwForbiddenException(req, "You are not authorized to perform the request "+gnGetlURL, this.getClass(), help);
|
||||
break;
|
||||
|
||||
default:
|
||||
ExceptionManager.throwInternalErrorException(req, "Sorry, an error occurred performing the geonetwork request "+gnGetlURL+" with scope "+scope, GeonetworkResolver.class, help);
|
||||
ExceptionManager.throwInternalErrorException(req, "Sorry, an error occurred performing the geonetwork request "+gnGetlURL+" with scope "+scope, this.getClass(), help);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Exception:", e);
|
||||
String error = "Sorry, an error occurred on resolving geonetwork request with scope "+scope+". Please, contact support!";
|
||||
ExceptionManager.throwInternalErrorException(req, error, GeonetworkResolver.class, help);
|
||||
ExceptionManager.throwInternalErrorException(req, error, this.getClass(), help);
|
||||
}
|
||||
|
||||
//An error occurred
|
||||
try {
|
||||
|
||||
throw new InternalServerException(req, javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR, "Error during perform GET operation to: "+gnGetlURL, GeonetworkResolver.class, new URI(help));
|
||||
throw new InternalServerException(req, javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR, "Error during perform GET operation to: "+gnGetlURL, this.getClass(), new URI(help));
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
//silent
|
||||
|
@ -260,12 +260,12 @@ public class GeonetworkResolver {
|
|||
|
||||
if(scope==null || scope.isEmpty()){
|
||||
logger.error("Path Parameter 'scope' not found");
|
||||
ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'scope'", GeonetworkResolver.class, help);
|
||||
ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'scope'", this.getClass(), help);
|
||||
}
|
||||
|
||||
if(mode==null || mode.isEmpty()){
|
||||
logger.error("Path Parameter 'scope' not found");
|
||||
ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'mode'", GeonetworkResolver.class, help);
|
||||
ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'mode'", this.getClass(), help);
|
||||
}
|
||||
|
||||
scope = ScopeUtil.normalizeScope(scope, "|");
|
||||
|
@ -275,12 +275,12 @@ public class GeonetworkResolver {
|
|||
}catch(Exception e){
|
||||
List<MODE> toPrint = Arrays.asList(MODE.values());
|
||||
logger.error("The 'mode' parameter is wrong, Have you pass a valid parameter MODE like "+toPrint+"?");
|
||||
ExceptionManager.throwWrongParameterException(req, "The 'mode' parameter must be value of "+toPrint, GeonetworkResolver.class, help);
|
||||
ExceptionManager.throwWrongParameterException(req, "The 'mode' parameter must be value of "+toPrint, this.getClass(), help);
|
||||
}
|
||||
|
||||
if(visibility==null){
|
||||
logger.error("Path Parameter 'visibility' not found");
|
||||
ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'visibility'", GeonetworkResolver.class, help);
|
||||
ExceptionManager.throwBadRequestException(req, "Missing mandatory path parameter 'visibility'", this.getClass(), help);
|
||||
}
|
||||
|
||||
visibility = visibility.toUpperCase();
|
||||
|
@ -289,7 +289,7 @@ public class GeonetworkResolver {
|
|||
}catch (Exception e) {
|
||||
List<VISIBILITY> toPrint = Arrays.asList(VISIBILITY.values());
|
||||
logger.error("The 'visibility' parameter is wrong, Have you pass a valid parameter VISIBILITY like "+toPrint+"?");
|
||||
ExceptionManager.throwWrongParameterException(req, "The 'visibility' parameter must be value of "+toPrint, GeonetworkResolver.class, help);
|
||||
ExceptionManager.throwWrongParameterException(req, "The 'visibility' parameter must be value of "+toPrint, this.getClass(), help);
|
||||
}
|
||||
|
||||
//HOW TO PASS MORE THAN ONE?
|
||||
|
@ -390,7 +390,7 @@ public class GeonetworkResolver {
|
|||
|
||||
if(in==null){
|
||||
logger.warn("Input stream returned is null, sending "+HttpServletResponse.SC_NOT_FOUND);
|
||||
ExceptionManager.throwNotFoundException(req, "Input stream is null to the request "+gnCSWlURL+ " with body: "+byteArray.toString(), GeonetworkResolver.class, help);
|
||||
ExceptionManager.throwNotFoundException(req, "Input stream is null to the request "+gnCSWlURL+ " with body: "+byteArray.toString(), this.getClass(), help);
|
||||
}
|
||||
|
||||
try{
|
||||
|
@ -453,25 +453,25 @@ public class GeonetworkResolver {
|
|||
|
||||
}catch(Exception e){
|
||||
logger.error("Error on copy the response to send to client: ", e);
|
||||
ExceptionManager.throwInternalErrorException(req, "Error on copy the response!", GeonetworkResolver.class, help);
|
||||
ExceptionManager.throwInternalErrorException(req, "Error on copy the response!", this.getClass(), help);
|
||||
}finally{
|
||||
IOUtils.closeQuietly(in);
|
||||
}
|
||||
|
||||
} catch (IllegalArgumentException e){
|
||||
logger.error("IllegalArgumentException:", e);
|
||||
ExceptionManager.throwBadRequestException(req, "Illegal argument to carry out the request!", GeonetworkResolver.class, help);
|
||||
ExceptionManager.throwBadRequestException(req, "Illegal argument to carry out the request!", this.getClass(), help);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Exception:", e);
|
||||
String error = "Sorry, an error occurred on resolving geonetwork request with scope "+scope+". Please, contact support!";
|
||||
ExceptionManager.throwInternalErrorException(req, error, GeonetworkResolver.class, help);
|
||||
ExceptionManager.throwInternalErrorException(req, error, this.getClass(), help);
|
||||
}
|
||||
|
||||
//An error occurred
|
||||
try {
|
||||
|
||||
throw new InternalServerException(req, javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR, "Error during perform POST operation to: "+gnCSWlURL, GeonetworkResolver.class, new URI(help));
|
||||
throw new InternalServerException(req, javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR, "Error during perform POST operation to: "+gnCSWlURL, this.getClass(), new URI(help));
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
//silent
|
||||
|
@ -480,32 +480,6 @@ public class GeonetworkResolver {
|
|||
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Purge remain from query string.
|
||||
// *
|
||||
// * @param remain_value the scope
|
||||
// * @param queryString the query string
|
||||
// * @return the string
|
||||
// */
|
||||
// private static String purgeRemainFromQueryString(String remain_value, String queryString){
|
||||
//// SCOPE is: /gcube/devsec/devVRE
|
||||
//// [INFO ] 2016-04-05 15:01:42,808 org.gcube.datatransfer.resolver.gis.geonetwork.GeonetworkResolver -
|
||||
//// Query String is: scope=/gcube/devsec/devVRE&version=2.0.2&request=GetCapabilities&service=CSW
|
||||
// int start = queryString.indexOf(PATH_PARAM_REMAINPATH+"=");
|
||||
//
|
||||
// if(start>=0){
|
||||
// int end = queryString.indexOf("&", start);
|
||||
//
|
||||
// if(end==-1 && queryString.length()==(PATH_PARAM_REMAINPATH+"="+remain_value).length()){ //SCOPE IS THE UNIQUE PARAMETER INTO QUETY STRING
|
||||
// logger.debug("Scope is the unique parameter, returning empty query string");
|
||||
// return "";
|
||||
// }else if(end<queryString.length())
|
||||
// return queryString.substring(end+1, queryString.length());
|
||||
// }
|
||||
//
|
||||
// return queryString;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Discovery geonetwork instance.
|
||||
*
|
||||
|
@ -519,33 +493,6 @@ public class GeonetworkResolver {
|
|||
return gntwAccess.getGeonetworkInstance(true, null);
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * Purge scope from query string.
|
||||
// *
|
||||
// * @param scope_value the scope_value
|
||||
// * @param queryString the query string
|
||||
// * @return the string
|
||||
// */
|
||||
// private static String purgeScopeFromQueryString(String scope_value, String queryString){
|
||||
//// SCOPE is: /gcube/devsec/devVRE
|
||||
//// [INFO ] 2016-04-05 15:01:42,808 org.gcube.datatransfer.resolver.gis.geonetwork.GeonetworkResolver -
|
||||
//// Query String is: scope=/gcube/devsec/devVRE&version=2.0.2&request=GetCapabilities&service=CSW
|
||||
// int start = queryString.indexOf(PATH_PARAM_SCOPE+"=");
|
||||
//
|
||||
// if(start>=0){
|
||||
// int end = queryString.indexOf("&", start);
|
||||
//
|
||||
// if(end==-1 && queryString.length()==(PATH_PARAM_SCOPE+"="+scope_value).length()){ //SCOPE IS THE UNIQUE PARAMETER INTO QUETY STRING
|
||||
// logger.debug("Scope is the unique parameter, returning empty query string");
|
||||
// return "";
|
||||
// }else if(end<queryString.length())
|
||||
// return queryString.substring(end+1, queryString.length());
|
||||
// }
|
||||
//
|
||||
// return queryString;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Reset geonetowork instance cache for scope.
|
||||
*
|
||||
|
|
|
@ -0,0 +1,146 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.datatransfer.resolver.services;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.gcube.datatransfer.resolver.catalogue.CatalogueRequest;
|
||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* The Class PartheosRegistryResolver.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Nov 16, 2018
|
||||
*/
|
||||
@Path("parthenos_registry")
|
||||
public class PartheosRegistryResolver {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final String PARTHENOS_REGISTRY_VRE_NAME = "PARTHENOS_Registry";
|
||||
private static Logger logger = LoggerFactory.getLogger(PartheosRegistryResolver.class);
|
||||
private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver";
|
||||
|
||||
/**
|
||||
* Resolve parthenos url.
|
||||
*
|
||||
* @param req the req
|
||||
* @param provider the provider
|
||||
* @param path the path
|
||||
* @param remainPath the remain path
|
||||
* @return the response
|
||||
*/
|
||||
@GET
|
||||
@Path("/{provider}/{path}{remainPath:(/[^?$]+)?}")
|
||||
public Response resolveParthenosURL(@Context HttpServletRequest req,@PathParam("provider") String provider, @PathParam("path") String path, @PathParam("remainPath") String remainPath) {
|
||||
logger.info(PartheosRegistryResolver.class.getSimpleName()+" GET starts...");
|
||||
|
||||
String remainPathParthenosURL = null;
|
||||
try {
|
||||
|
||||
remainPathParthenosURL = String.format("%s/%s",provider,path);
|
||||
|
||||
if(remainPath!=null && !remainPath.isEmpty()){
|
||||
remainPathParthenosURL+="/"+remainPath;
|
||||
}
|
||||
|
||||
String normalizedEntityName = toNameForCatalogue(remainPathParthenosURL);
|
||||
String itemCatalogueURL = CatalogueResolver.getItemCatalogueURL(PARTHENOS_REGISTRY_VRE_NAME, "dataset", normalizedEntityName);
|
||||
return Response.seeOther(new URL(itemCatalogueURL).toURI()).build();
|
||||
}catch (Exception e) {
|
||||
logger.error("Exception:", e);
|
||||
String error = "Error occurred on resolving the path "+remainPathParthenosURL+". Please, contact support!";
|
||||
ExceptionManager.throwInternalErrorException(req, error, this.getClass(), helpURI);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Post catalogue.
|
||||
*
|
||||
* @param req the req
|
||||
* @param jsonRequest the json request
|
||||
* @return the response
|
||||
*/
|
||||
@POST
|
||||
@Path("/")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public Response postCatalogue(@Context HttpServletRequest req, CatalogueRequest jsonRequest) {
|
||||
|
||||
//TODO
|
||||
return null;
|
||||
/*InnerMethodName.instance.set("postCataloguePublicLink");
|
||||
logger.info(CatalogueResolver.class.getSimpleName()+" POST starts...");
|
||||
|
||||
logger.info("The body contains the request: "+jsonRequest.toString());
|
||||
//final CatalogueEntityRequest cer = new CatalogueEntityRequest();
|
||||
|
||||
//CHECK IF INPUT SCOPE IS VALID
|
||||
String scope = jsonRequest.getGcube_scope();
|
||||
if(!scope.startsWith("/")){
|
||||
logger.info("Scope not start with char '/' adding it");
|
||||
scope+="/"+scope;
|
||||
}
|
||||
|
||||
String serverUrl = getServerURL(req);
|
||||
|
||||
final String vreName = scope.substring(scope.lastIndexOf("/")+1, scope.length());
|
||||
String fullScope = null;
|
||||
//CHECK IF THE vreName has a valid scope, so it is a valid VRE
|
||||
try {
|
||||
fullScope = LoadingVREsScopeCache.getCache().get(vreName);
|
||||
}
|
||||
catch (ExecutionException e1) {
|
||||
logger.error("Error on getting full scope for vre name: "+vreName, e1);
|
||||
}
|
||||
|
||||
if(fullScope==null)
|
||||
ExceptionManager.throwNotFoundException(req, "The scope '"+scope+"' does not matching any scope in the infrastructure. Is it valid?", this.getClass(), helpURI);
|
||||
|
||||
ResourceCatalogueCodes rc = ResourceCatalogueCodes.valueOfCodeValue(jsonRequest.getEntity_context());
|
||||
if(rc==null){
|
||||
logger.error("Entity context is null/malformed");
|
||||
ExceptionManager.throwBadRequestException(req, "Entity context is null/malformed", this.getClass(), helpURI);
|
||||
//throw new WebApplicationException("Entity context is null/malformed", Status.BAD_REQUEST);
|
||||
}
|
||||
|
||||
String linkURL = String.format("%s/%s/%s/%s", serverUrl, rc.getId(), vreName, jsonRequest.getEntity_name());
|
||||
logger.info("Returining Catalogue URL: "+linkURL);
|
||||
return Response.ok(linkURL).header("Location", linkURL).build();*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* To name for catalogue.
|
||||
*
|
||||
* @param remainPathParthenosURL the remain path parthenos url
|
||||
* @return the string
|
||||
* @throws UnsupportedEncodingException the unsupported encoding exception
|
||||
*/
|
||||
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
|
||||
return StringUtils.replaceChars(URLDecoder.decode(remainPathParthenosURL,"UTF-8"),"/ .:", "_").toLowerCase().replaceAll("[^A-Za-z0-9]", "_");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue