Task #12294: Created new resolver parthenos_registry

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@174363 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-11-26 11:56:51 +00:00
parent 815858c4f3
commit eec7081cc9
8 changed files with 259 additions and 66 deletions

View File

@ -106,7 +106,10 @@
</Changeset>
<Changeset component="org.gcube.data-transfer.uri-resolver.2-0-0"
date="2018-10-23">
<Change>[Task #12740] Developed as web-service by using jersey framework
<Change>[Task #12740] Developed as web-service by using jersey
framework
</Change>
<Change>[Task #12294] Created the resolver 'parthenosregistry'
</Change>
</Changeset>
</ReleaseNotes>

View File

@ -81,6 +81,12 @@ public class LoadingVREsScopeCache {
vresNameToScope.asMap().putAll(map);
logger.info("Cache populated with: "+vresNameToScope.asMap().toString());
//logger.info("Pre-Loaded CatalogueApplicationProfiles cache is: "+catalogueApplicationProfiles.asMap().toString());
//TODO HARD-CODED TO TEST PARTHENOS_REGISTRY
logger.warn("REMOVE THE FOLLOWING HARD-CODE FOR PARTHENOS_REGISTRY");
vresNameToScope.asMap().put("PARTHENOS_Registry", "/d4science.research-infrastructures.eu/ParthenosVO/PARTHENOS_Registry");
}catch(Exception e){
}finally{

View File

@ -0,0 +1,27 @@
/**
*
*/
package org.gcube.datatransfer.resolver.catalogue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
/**
* The Class ItemCatalogueURLs.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Nov 26, 2018
*/
@AllArgsConstructor
@Getter
@Setter
public class ItemCatalogueURLs {
private String itemName;
private boolean isPublicItem;
private String privateCataloguePortletURL;
private String publicCataloguePortletURL;
}

View File

@ -35,11 +35,13 @@ public class UriResolverSmartGearManagerInit implements ApplicationManager {
private static Logger log = LoggerFactory.getLogger(UriResolverSmartGearManagerInit.class);
public static final String GIS_VIEWER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES = "gisviewerappgenericresource.properties";
public static final String GEO_EXPLORER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES = "geoexplorerappgenericresource.properties";
public static final String GIS_VIEWER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES_FILENAME = "gisviewerappgenericresource.properties";
public static final String GEO_EXPLORER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES_FILENAME = "geoexplorerappgenericresource.properties";
public static final String PARTHENOS_VRE_PROPERTIES_FILENAME = "parthenosvre.properties";
protected static final String SECONDARY_TYPE = "SECONDARY_TYPE";
protected static final String APP_ID = "APP_ID";
protected static final String VRE_NAME = "VRE_NAME";
public static final String ENV_SCOPE = "SCOPE"; //Environment Variable
@ -47,6 +49,7 @@ public class UriResolverSmartGearManagerInit implements ApplicationManager {
private static ApplicationProfilePropertyReader gisViewerProfile;
private static ApplicationProfilePropertyReader geoExplorerProfile;
private static String parthenosVREName;
/* (non-Javadoc)
@ -76,10 +79,12 @@ public class UriResolverSmartGearManagerInit implements ApplicationManager {
//JUST ONCE AND TO BE SURE WITH THE ROOT SCOPE INITIALIZED
if(initRootContextPerformed && (gisViewerProfile==null || geoExplorerProfile==null)){
log.info("init Profiles...");
gisViewerProfile = loadApplicationProfile(UriResolverServletContextListener.getServletContext(), GIS_VIEWER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES);
geoExplorerProfile = loadApplicationProfile(UriResolverServletContextListener.getServletContext(), GEO_EXPLORER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES);
log.info("GisViewerProfile [ID: "+gisViewerProfile.getAppId() + ", Generic Resource Type: "+gisViewerProfile.getGenericResource()+"]");
log.info("GeoExplorerProfile [ID: "+geoExplorerProfile. getAppId() + ", Generic Resource Type: "+geoExplorerProfile.getGenericResource()+"]");
gisViewerProfile = loadApplicationProfile(UriResolverServletContextListener.getServletContext(), GIS_VIEWER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES_FILENAME);
geoExplorerProfile = loadApplicationProfile(UriResolverServletContextListener.getServletContext(), GEO_EXPLORER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES_FILENAME);
parthenosVREName = loadPartheosVREName(UriResolverServletContextListener.getServletContext(), PARTHENOS_VRE_PROPERTIES_FILENAME);
log.info("GisViewerProfile [ID: "+gisViewerProfile.getAppId() + ", Generic Resource Type: "+gisViewerProfile.getGenericResource()+"] loaded from "+GIS_VIEWER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES_FILENAME);
log.info("GeoExplorerProfile [ID: "+geoExplorerProfile. getAppId() + ", Generic Resource Type: "+geoExplorerProfile.getGenericResource()+"] loaded from "+GEO_EXPLORER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES_FILENAME);
log.info("PARTHENOS "+VRE_NAME+" is '"+parthenosVREName+ "' loaded from "+PARTHENOS_VRE_PROPERTIES_FILENAME);
}
//JUST ONCE AND TO BE SURE WITH THE ROOT SCOPE INITIALIZED
@ -123,17 +128,40 @@ public class UriResolverSmartGearManagerInit implements ApplicationManager {
String contextPath = "/WEB-INF/property/"+propertyFileName;
String realPath = context.getRealPath(contextPath);
try {
Properties props = new Properties();
props.load(new FileInputStream(new File(realPath)));
return new ApplicationProfilePropertyReader(new FileInputStream(new File(realPath)));
} catch (PropertyFileNotFoundException | FileNotFoundException ex) {
log.error("PropertyFileNotFoundException: "+contextPath, ex);
}
return null;
}
/**
* Load partheos vre name.
*
* @param context the context
* @param propertyFileName the property file name
*/
private static String loadPartheosVREName(ServletContext context, String propertyFileName) {
String contextPath = "/WEB-INF/property/"+propertyFileName;
String realPath = context.getRealPath(contextPath);
try {
Properties props = new Properties();
props.load(new FileInputStream(new File(realPath)));
parthenosVREName = props.getProperty(VRE_NAME);
return parthenosVREName;
} catch (FileNotFoundException ex) {
log.error("PropertyFileNotFoundException: "+contextPath, ex);
}catch (IOException e) {
log.error("Error on loading property from: "+contextPath, e);
}
return null;
}
@ -178,6 +206,17 @@ public class UriResolverSmartGearManagerInit implements ApplicationManager {
}
/**
* Gets the parthenos vre name.
*
* @return the parthenosVREName
*/
public static String getParthenosVREName() {
return parthenosVREName;
}
/**
* Gets the root context scope.
*

View File

@ -0,0 +1,49 @@
/**
*
*/
package org.gcube.datatransfer.resolver.parthenos;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Nov 26, 2018
*/
public class ParthenosRequest {
private String entity_name;
/**
* @return the entity_name
*/
public String getEntity_name() {
return entity_name;
}
/**
* @param entity_name the entity_name to set
*/
public void setEntity_name(String entity_name) {
this.entity_name = entity_name;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ParthenosRequest [entity_name=");
builder.append(entity_name);
builder.append("]");
return builder.toString();
}
}

View File

@ -17,6 +17,7 @@ import javax.ws.rs.core.Response;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.caches.LoadingVREsScopeCache;
import org.gcube.datatransfer.resolver.catalogue.CatalogueRequest;
import org.gcube.datatransfer.resolver.catalogue.ItemCatalogueURLs;
import org.gcube.datatransfer.resolver.catalogue.ResourceCatalogueCodes;
import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigurationsReader;
import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference;
@ -55,7 +56,18 @@ public class CatalogueResolver {
InnerMethodName.instance.set("resolveCataloguePublicLink");
logger.info(CatalogueResolver.class.getSimpleName()+" GET starts...");
try {
String itemCatalogueURL = getItemCatalogueURL(vreName, entityContext, entityName);
ItemCatalogueURLs itemCatalogueURLs = getItemCatalogueURLs(vreName, entityContext, entityName);
String itemCatalogueURL;
if(itemCatalogueURLs.isPublicItem()){
itemCatalogueURL = itemCatalogueURLs.getPublicCataloguePortletURL();
logger.info("The dataset "+itemCatalogueURLs.getItemName()+" is a public item so using public access to CKAN portlet: "+itemCatalogueURL);
}else{
itemCatalogueURL = itemCatalogueURLs.getPrivateCataloguePortletURL();
logger.info("The dataset "+itemCatalogueURLs.getItemName()+" is a private item so using protected access to CKAN portlet: "+itemCatalogueURL);
}
return Response.seeOther(new URL(itemCatalogueURL).toURI()).build();
}catch (Exception e) {
logger.error("error resolving catalogue link",e);
@ -116,6 +128,7 @@ public class CatalogueResolver {
return Response.ok(linkURL).header("Location", linkURL).build();
}
/**
* Gets the item catalogue url.
*
@ -125,7 +138,7 @@ public class CatalogueResolver {
* @return the item catalogue url
* @throws Exception the exception
*/
protected static String getItemCatalogueURL(String vreName, String entityContext, String entityName) throws Exception{
protected static ItemCatalogueURLs getItemCatalogueURLs(String vreName, String entityContext, String entityName) throws Exception{
try {
String entityContextValue = ResourceCatalogueCodes.valueOfCodeId(entityContext).getValue();
@ -143,24 +156,26 @@ public class CatalogueResolver {
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;
boolean isPublicItem = false;
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);
isPublicItem = true;
//ckanPorltetUrl = ckanCatalogueReference.getPublicPortletURL();
logger.info("The dataset "+datasetName+" is a public item");
}
}catch(Exception e){
logger.warn("Error on checking if dataset: "+datasetName+" is private or not", e);
ckanPorltetUrl = ckanCatalogueReference.getPublicPortletURL();
isPublicItem = true;
}
}
return String.format("%s?path=/%s/%s",ckanPorltetUrl,entityContextValue, entityName);
String publicPorltetURL = String.format("%s?path=/%s/%s",ckanCatalogueReference.getPublicPortletURL(),entityContextValue, entityName);
String privatePortletURL = String.format("%s?path=/%s/%s",ckanCatalogueReference.getPrivatePortletURL(),entityContextValue, entityName);
return new ItemCatalogueURLs(entityName, isPublicItem, privatePortletURL, publicPorltetURL);
}catch (Exception e) {
logger.error("error resolving catalogue link",e);
throw e;

View File

@ -19,7 +19,10 @@ 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.catalogue.ItemCatalogueURLs;
import org.gcube.datatransfer.resolver.catalogue.ResourceCatalogueCodes;
import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit;
import org.gcube.datatransfer.resolver.parthenos.ParthenosRequest;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -31,13 +34,13 @@ import org.slf4j.LoggerFactory;
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Nov 16, 2018
*/
@Path("parthenos_registry")
@Path("parthenosregistry")
public class PartheosRegistryResolver {
/**
*
*/
private static final String PARTHENOS_REGISTRY_VRE_NAME = "PARTHENOS_Registry";
//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";
@ -53,23 +56,32 @@ public class PartheosRegistryResolver {
@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...");
logger.info(this.getClass().getSimpleName()+" GET starts...");
String remainPathParthenosURL = null;
try {
logger.debug("provider is: "+provider);
logger.debug("path is: "+path);
logger.debug("remainPath is: "+remainPath);
remainPathParthenosURL = String.format("%s/%s",provider,path);
if(remainPath!=null && !remainPath.isEmpty()){
remainPathParthenosURL+="/"+remainPath;
remainPathParthenosURL+=remainPath.startsWith("/")?remainPath:"/"+remainPath;
}
logger.info("Resolving parthenos URL: "+remainPathParthenosURL);
//APPLYING URL DECODING
remainPathParthenosURL = URLDecoder.decode(remainPathParthenosURL, "UTF-8");
//APPLYING NAME TRANSFORMATION
String normalizedEntityName = toNameForCatalogue(remainPathParthenosURL);
String itemCatalogueURL = CatalogueResolver.getItemCatalogueURL(PARTHENOS_REGISTRY_VRE_NAME, "dataset", normalizedEntityName);
return Response.seeOther(new URL(itemCatalogueURL).toURI()).build();
logger.info("Trying to resolve with Catalogue EntityName: "+normalizedEntityName);
ItemCatalogueURLs itemCatalogueURLs = CatalogueResolver.getItemCatalogueURLs(UriResolverSmartGearManagerInit.getParthenosVREName(), ResourceCatalogueCodes.CTLGD.getId(), normalizedEntityName);
return Response.seeOther(new URL(itemCatalogueURLs.getPrivateCataloguePortletURL()).toURI()).build();
}catch (Exception e) {
logger.error("Exception:", e);
String error = "Error occurred on resolving the path "+remainPathParthenosURL+". Please, contact support!";
String error = "Error occurred on resolving the path "+remainPathParthenosURL+". Please, contact the support!";
ExceptionManager.throwInternalErrorException(req, error, this.getClass(), helpURI);
return null;
}
@ -87,60 +99,93 @@ public class PartheosRegistryResolver {
@Path("/")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public Response postCatalogue(@Context HttpServletRequest req, CatalogueRequest jsonRequest) {
public Response postCatalogue(@Context HttpServletRequest req, ParthenosRequest jsonRequest) {
logger.info(this.getClass().getSimpleName()+" POST starts...");
//TODO
return null;
/*InnerMethodName.instance.set("postCataloguePublicLink");
logger.info(CatalogueResolver.class.getSimpleName()+" POST starts...");
try{
String entityName = jsonRequest.getEntity_name();
logger.info("The body contains the request: "+jsonRequest.toString());
//final CatalogueEntityRequest cer = new CatalogueEntityRequest();
if(entityName==null || entityName.isEmpty()){
logger.error("Entity Name Parameter like 'entity_name' not found or empty");
ExceptionManager.throwBadRequestException(req, "Mandatory body parameter 'entity_name' not found or empty", this.getClass(), helpURI);
}
//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;
//REMOVING FIRST '/' IF EXISTS
entityName = entityName.startsWith("/")?entityName.substring(1,entityName.length()):entityName;
//APPLYING NAME TRANSFORMATION
String normalizedEntityName = toNameForCatalogue(entityName);
ItemCatalogueURLs itemCatalogueURLs = CatalogueResolver.getItemCatalogueURLs(UriResolverSmartGearManagerInit.getParthenosVREName(), ResourceCatalogueCodes.CTLGD.getId(), normalizedEntityName);
logger.info("Returining Catalogue URL: "+itemCatalogueURLs.getPrivateCataloguePortletURL());
return Response.ok(normalizedEntityName).header("Location", itemCatalogueURLs.getPrivateCataloguePortletURL()).build();
//TODO
/*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();*/
}catch (Exception e) {
logger.error("Exception:", e);
String error = "Error occurred on transforming the "+jsonRequest+". Please, contact the support!";
ExceptionManager.throwInternalErrorException(req, error, this.getClass(), helpURI);
return null;
}
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.
*
* this method applyes a fuction to transform a parthenos URL to acceptable catalogue name (that is URL)
* @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]", "_");
String name = StringUtils.replaceChars(URLDecoder.decode(remainPathParthenosURL,"UTF-8"),"/ .:", "_").toLowerCase().replaceAll("[^A-Za-z0-9]", "_");
//TO LOWERCASE FOR CKAN SUPPORTING
return name.toLowerCase();
}
// public static void main(String[] args) throws UnsupportedEncodingException {
//
// String remainPathParthenosURL = "Culturalitalia/unknown/Dataset/oai%3Aculturaitalia.it%3Aoai%3Aculturaitalia.it%3Amuseiditalia-mus_11953";
// System.out.println(URLDecoder.decode(remainPathParthenosURL, "UTF-8"));
//
// }
}

View File

@ -0,0 +1,9 @@
# Property files
#
# author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
# created 11/2018
#
# The name of Parthenos Registry VRE
#
VRE_NAME = PARTHENOS_Registry