2018-10-12 16:20:46 +02:00
|
|
|
package org.gcube.datatransfer.resolver.services;
|
|
|
|
|
2020-06-18 15:48:47 +02:00
|
|
|
import java.net.URI;
|
2018-10-12 16:20:46 +02:00
|
|
|
import java.net.URL;
|
2022-04-21 09:44:18 +02:00
|
|
|
import java.net.URLEncoder;
|
2020-06-18 15:48:47 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2018-11-09 12:05:53 +01:00
|
|
|
import java.util.concurrent.ExecutionException;
|
2018-10-12 16:20:46 +02:00
|
|
|
|
|
|
|
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;
|
2018-12-14 12:28:59 +01:00
|
|
|
import javax.ws.rs.WebApplicationException;
|
2018-10-12 16:20:46 +02:00
|
|
|
import javax.ws.rs.core.Context;
|
|
|
|
import javax.ws.rs.core.MediaType;
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
2019-05-16 12:54:20 +02:00
|
|
|
import org.gcube.common.scope.impl.ScopeBean;
|
|
|
|
import org.gcube.common.scope.impl.ScopeBean.Type;
|
2020-04-06 16:11:55 +02:00
|
|
|
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueRunningCluster.ACCESS_LEVEL_TO_CATALOGUE_PORTLET;
|
2019-05-16 14:56:48 +02:00
|
|
|
import org.gcube.datatransfer.resolver.ConstantsResolver;
|
2020-06-18 15:48:47 +02:00
|
|
|
import org.gcube.datatransfer.resolver.caches.LoadingMapOfDetachedVRE;
|
2019-05-21 16:27:58 +02:00
|
|
|
import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache;
|
2018-10-12 16:20:46 +02:00
|
|
|
import org.gcube.datatransfer.resolver.catalogue.CatalogueRequest;
|
2018-11-26 12:56:51 +01:00
|
|
|
import org.gcube.datatransfer.resolver.catalogue.ItemCatalogueURLs;
|
2018-11-15 12:18:03 +01:00
|
|
|
import org.gcube.datatransfer.resolver.catalogue.ResourceCatalogueCodes;
|
2020-06-18 15:48:47 +02:00
|
|
|
import org.gcube.datatransfer.resolver.catalogue.resource.CatalogueStaticConfigurations;
|
2018-10-12 16:20:46 +02:00
|
|
|
import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigurationsReader;
|
|
|
|
import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference;
|
2019-05-16 12:54:20 +02:00
|
|
|
import org.gcube.datatransfer.resolver.catalogue.resource.GetAllInfrastructureScopes;
|
2018-11-09 12:05:53 +01:00
|
|
|
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
2022-04-21 09:44:18 +02:00
|
|
|
import org.gcube.datatransfer.resolver.util.UrlEncoderUtil;
|
2018-11-30 12:51:17 +01:00
|
|
|
import org.gcube.datatransfer.resolver.util.Util;
|
2020-06-18 15:48:47 +02:00
|
|
|
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE;
|
2018-10-24 10:09:09 +02:00
|
|
|
import org.gcube.smartgears.utils.InnerMethodName;
|
2018-10-12 16:20:46 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2018-12-17 15:52:31 +01:00
|
|
|
import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
|
|
|
|
|
2018-10-12 16:20:46 +02:00
|
|
|
import eu.trentorise.opendata.jackan.model.CkanDataset;
|
|
|
|
|
2018-11-23 15:45:33 +01:00
|
|
|
/**
|
2022-03-31 10:52:52 +02:00
|
|
|
* The CatalogueResolver is able to get/resolve a link to a "Catalogue Entity"
|
2022-03-31 10:57:38 +02:00
|
|
|
* stored in one of the D4Science Catalogue's instances. A Catalogue Entity is
|
2022-03-31 10:52:52 +02:00
|
|
|
* either a "group" or an "organization" or a "product" of D4Science Data
|
|
|
|
* Catalogue.
|
2018-11-23 15:45:33 +01:00
|
|
|
*
|
2022-03-31 10:52:52 +02:00
|
|
|
* See more at
|
|
|
|
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#CATALOGUE_Resolver
|
|
|
|
*
|
2018-11-23 15:45:33 +01:00
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
2022-03-24 17:33:54 +01:00
|
|
|
* Nov 16, 2018
|
2018-11-23 15:45:33 +01:00
|
|
|
*/
|
2019-02-19 15:18:19 +01:00
|
|
|
@Path("{entityContext:ctlg(-(o|g|p|d))?}")
|
2018-10-23 14:58:46 +02:00
|
|
|
public class CatalogueResolver {
|
2018-10-12 16:20:46 +02:00
|
|
|
|
2018-10-23 14:58:46 +02:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(CatalogueResolver.class);
|
2018-11-09 12:05:53 +01:00
|
|
|
private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#CATALOGUE_Resolver";
|
2022-03-24 17:33:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Enum SCOPE_STATUS.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
|
|
|
*
|
|
|
|
* Mar 24, 2022
|
|
|
|
*/
|
|
|
|
private static enum SCOPE_STATUS {
|
|
|
|
ACTIVE, DETACHED
|
|
|
|
}
|
2018-10-12 16:20:46 +02:00
|
|
|
|
2018-11-23 15:45:33 +01:00
|
|
|
/**
|
2022-03-31 10:52:52 +02:00
|
|
|
* Resolve an entity of the Catalogue
|
2018-11-23 15:45:33 +01:00
|
|
|
*
|
2022-03-24 17:33:54 +01:00
|
|
|
* @param req the req
|
|
|
|
* @param entityName the entity name
|
|
|
|
* @param vreName the vre name
|
2018-11-23 15:45:33 +01:00
|
|
|
* @param entityContext the entity context
|
|
|
|
* @return the response
|
2022-03-24 17:33:54 +01:00
|
|
|
* @throws WebApplicationException the web application exception
|
2018-11-23 15:45:33 +01:00
|
|
|
*/
|
2018-10-12 16:20:46 +02:00
|
|
|
@GET
|
2019-02-19 15:18:19 +01:00
|
|
|
@Path("/{vreName}/{entityName}")
|
2022-03-24 17:33:54 +01:00
|
|
|
public Response resolveCatalogue(@Context HttpServletRequest req, @PathParam("entityName") String entityName,
|
|
|
|
@PathParam("vreName") String vreName, @PathParam("entityContext") String entityContext)
|
|
|
|
throws WebApplicationException {
|
2018-12-14 12:28:59 +01:00
|
|
|
|
2022-03-24 17:33:54 +01:00
|
|
|
logger.info(this.getClass().getSimpleName() + " GET starts...");
|
2018-12-14 12:28:59 +01:00
|
|
|
|
2018-10-12 16:20:46 +02:00
|
|
|
try {
|
2018-12-14 12:28:59 +01:00
|
|
|
InnerMethodName.instance.set("resolveCataloguePublicLink");
|
2018-12-17 11:48:18 +01:00
|
|
|
ItemCatalogueURLs itemCatalogueURLs = getItemCatalogueURLs(req, vreName, entityContext, entityName);
|
2018-11-26 12:56:51 +01:00
|
|
|
|
|
|
|
String itemCatalogueURL;
|
|
|
|
|
2022-03-24 17:33:54 +01:00
|
|
|
if (itemCatalogueURLs.isPublicItem()) {
|
|
|
|
logger.info("The dataset " + itemCatalogueURLs.getItemName()
|
|
|
|
+ " was detected as public item (not private to VRE)");
|
|
|
|
if (itemCatalogueURLs.getPublicVRECataloguePortletURL() != null
|
|
|
|
&& !itemCatalogueURLs.getPublicVRECataloguePortletURL().isEmpty()) {
|
2019-11-12 18:18:22 +01:00
|
|
|
itemCatalogueURL = itemCatalogueURLs.getPublicVRECataloguePortletURL();
|
2022-03-24 17:33:54 +01:00
|
|
|
logger.info(
|
|
|
|
"I found the public VRE catalogue URL, so using public access to it: " + itemCatalogueURL);
|
|
|
|
} else {
|
2019-11-12 18:18:22 +01:00
|
|
|
itemCatalogueURL = itemCatalogueURLs.getPublicGatewayCataloguePortletURL();
|
2022-03-24 17:33:54 +01:00
|
|
|
logger.info("No public VRE catalogue URL found, so using public access to gateway CKAN portlet: "
|
|
|
|
+ itemCatalogueURL);
|
2019-11-12 18:18:22 +01:00
|
|
|
}
|
2022-03-24 17:33:54 +01:00
|
|
|
} else {
|
2019-11-12 18:18:22 +01:00
|
|
|
itemCatalogueURL = itemCatalogueURLs.getPrivateVRECataloguePortletURL();
|
2022-03-24 17:33:54 +01:00
|
|
|
logger.info("The dataset " + itemCatalogueURLs.getItemName()
|
|
|
|
+ " is a private item (to VRE) so using protected access to CKAN portlet: " + itemCatalogueURL);
|
2018-11-26 12:56:51 +01:00
|
|
|
}
|
|
|
|
|
2022-04-21 09:44:18 +02:00
|
|
|
String queryString = req.getQueryString();
|
|
|
|
if (queryString != null) {
|
|
|
|
logger.debug("Query string found: " + queryString);
|
|
|
|
String qsEnc = URLEncoder.encode(queryString, "UTF-8");
|
|
|
|
logger.info("Adding encoded query string " + qsEnc + " to Catalogue URL response");
|
|
|
|
|
|
|
|
itemCatalogueURL += "?" + qsEnc;
|
|
|
|
}
|
|
|
|
|
2018-11-23 15:45:33 +01:00
|
|
|
return Response.seeOther(new URL(itemCatalogueURL).toURI()).build();
|
2022-03-24 17:33:54 +01:00
|
|
|
} catch (Exception e) {
|
2018-12-14 12:28:59 +01:00
|
|
|
|
2022-03-24 17:33:54 +01:00
|
|
|
if (!(e instanceof WebApplicationException)) {
|
|
|
|
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
2018-12-14 14:26:37 +01:00
|
|
|
String error = "Error occurred on resolving the Catalgoue URL. Please, contact the support!";
|
2022-03-24 17:33:54 +01:00
|
|
|
if (e.getCause() != null)
|
|
|
|
error += "\n\nCaused: " + e.getCause().getMessage();
|
2018-12-14 12:28:59 +01:00
|
|
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
|
|
|
}
|
2022-03-24 17:33:54 +01:00
|
|
|
// ALREADY MANAGED AS WebApplicationException
|
2018-12-14 12:28:59 +01:00
|
|
|
logger.error("Exception:", e);
|
|
|
|
throw (WebApplicationException) e;
|
2018-10-12 16:20:46 +02:00
|
|
|
}
|
|
|
|
}
|
2022-03-24 17:33:54 +01:00
|
|
|
|
2018-11-23 15:45:33 +01:00
|
|
|
/**
|
2022-03-31 10:52:52 +02:00
|
|
|
* Create a Catalogue Link
|
|
|
|
*
|
2018-11-23 15:45:33 +01:00
|
|
|
*
|
2022-03-24 17:33:54 +01:00
|
|
|
* @param req the req
|
2018-11-23 15:45:33 +01:00
|
|
|
* @param jsonRequest the json request
|
|
|
|
* @return the response
|
2022-03-24 17:33:54 +01:00
|
|
|
* @throws WebApplicationException the web application exception
|
2018-11-23 15:45:33 +01:00
|
|
|
*/
|
2018-10-12 16:20:46 +02:00
|
|
|
@POST
|
2019-02-19 15:18:19 +01:00
|
|
|
@Path("")
|
2018-10-12 16:20:46 +02:00
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
@Produces(MediaType.TEXT_PLAIN)
|
2022-03-24 17:33:54 +01:00
|
|
|
public Response postCatalogue(@Context HttpServletRequest req, CatalogueRequest jsonRequest)
|
|
|
|
throws WebApplicationException {
|
|
|
|
logger.info(this.getClass().getSimpleName() + " POST starts...");
|
2018-10-12 16:20:46 +02:00
|
|
|
|
2022-03-24 17:33:54 +01:00
|
|
|
try {
|
2018-10-12 16:20:46 +02:00
|
|
|
|
2018-12-14 12:28:59 +01:00
|
|
|
InnerMethodName.instance.set("postCataloguePublicLink");
|
2022-03-24 17:33:54 +01:00
|
|
|
logger.info("The body contains the request: " + jsonRequest.toString());
|
2018-11-09 12:05:53 +01:00
|
|
|
|
2022-03-24 17:33:54 +01:00
|
|
|
// CHECK IF INPUT SCOPE IS VALID
|
2018-12-14 12:28:59 +01:00
|
|
|
String scope = jsonRequest.getGcube_scope();
|
2022-03-24 17:33:54 +01:00
|
|
|
if (!scope.startsWith(ConstantsResolver.SCOPE_SEPARATOR)) {
|
|
|
|
logger.info("Scope not start with char '{}' adding it", ConstantsResolver.SCOPE_SEPARATOR);
|
|
|
|
scope += ConstantsResolver.SCOPE_SEPARATOR + scope;
|
2018-12-14 12:28:59 +01:00
|
|
|
}
|
2018-10-12 16:20:46 +02:00
|
|
|
|
2018-12-14 12:28:59 +01:00
|
|
|
String serverUrl = Util.getServerURL(req);
|
2018-10-12 16:20:46 +02:00
|
|
|
|
2022-03-24 17:33:54 +01:00
|
|
|
final String vreName = scope.substring(scope.lastIndexOf(ConstantsResolver.SCOPE_SEPARATOR) + 1,
|
|
|
|
scope.length());
|
2019-05-16 12:54:20 +02:00
|
|
|
ScopeBean fullScope = null;
|
2018-12-17 11:48:18 +01:00
|
|
|
|
2022-03-24 17:33:54 +01:00
|
|
|
// CHECK IF THE vreName has a valid scope, so it is a valid VRE
|
2018-12-14 12:28:59 +01:00
|
|
|
try {
|
2019-05-16 12:54:20 +02:00
|
|
|
fullScope = LoadingMapOfScopeCache.get(vreName);
|
2022-03-24 17:33:54 +01:00
|
|
|
} catch (ExecutionException 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);
|
2018-12-14 12:28:59 +01:00
|
|
|
}
|
|
|
|
|
2022-03-24 17:33:54 +01:00
|
|
|
if (fullScope == null)
|
|
|
|
throw ExceptionManager.notFoundException(req,
|
|
|
|
"The scope '" + scope + "' does not matching any scope in the infrastructure. Is it valid?",
|
|
|
|
this.getClass(), helpURI);
|
2018-12-14 12:28:59 +01:00
|
|
|
|
|
|
|
ResourceCatalogueCodes rc = ResourceCatalogueCodes.valueOfCodeValue(jsonRequest.getEntity_context());
|
2022-03-24 17:33:54 +01:00
|
|
|
if (rc == null) {
|
2018-12-14 12:28:59 +01:00
|
|
|
logger.error("Entity context is null/malformed");
|
2022-03-24 17:33:54 +01:00
|
|
|
throw ExceptionManager.badRequestException(req, "Entity context is null/malformed", this.getClass(),
|
|
|
|
helpURI);
|
2018-12-14 12:28:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
String linkURL = String.format("%s/%s/%s/%s", serverUrl, rc.getId(), vreName, jsonRequest.getEntity_name());
|
2022-04-21 09:44:18 +02:00
|
|
|
|
|
|
|
if (jsonRequest.getQuery_string() != null) {
|
|
|
|
String qsEnc = URLEncoder.encode(jsonRequest.getQuery_string(), "UTF-8");
|
|
|
|
linkURL += "?" + qsEnc;
|
|
|
|
}
|
|
|
|
|
2022-03-24 17:33:54 +01:00
|
|
|
logger.info("Returining Catalogue URL: " + linkURL);
|
2018-12-14 12:28:59 +01:00
|
|
|
return Response.ok(linkURL).header("Location", linkURL).build();
|
|
|
|
|
2022-03-24 17:33:54 +01:00
|
|
|
} catch (Exception e) {
|
2018-12-14 12:28:59 +01:00
|
|
|
|
2022-03-24 17:33:54 +01:00
|
|
|
if (!(e instanceof WebApplicationException)) {
|
|
|
|
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
2018-12-14 12:28:59 +01:00
|
|
|
String error = "Error occurred on resolving the Analytics URL. Please, contact the support!";
|
|
|
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
|
|
|
}
|
2022-03-24 17:33:54 +01:00
|
|
|
// ALREADY MANAGED AS WebApplicationExceptiongetItemCatalogueURLs
|
2018-12-14 12:28:59 +01:00
|
|
|
logger.error("Exception:", e);
|
|
|
|
throw (WebApplicationException) e;
|
|
|
|
}
|
2018-11-23 15:45:33 +01:00
|
|
|
}
|
2018-10-12 16:20:46 +02:00
|
|
|
|
2018-11-23 15:45:33 +01:00
|
|
|
/**
|
2019-05-16 12:54:20 +02:00
|
|
|
* Gets the item catalogue UR ls.
|
2018-11-23 15:45:33 +01:00
|
|
|
*
|
2022-03-24 17:33:54 +01:00
|
|
|
* @param req the req
|
|
|
|
* @param scopeName the scope name
|
2018-11-23 15:45:33 +01:00
|
|
|
* @param entityContext the entity context
|
2022-03-24 17:33:54 +01:00
|
|
|
* @param entityName the entity name
|
2019-05-16 12:54:20 +02:00
|
|
|
* @return the item catalogue UR ls
|
2018-11-23 15:45:33 +01:00
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2022-03-24 17:33:54 +01:00
|
|
|
protected static ItemCatalogueURLs getItemCatalogueURLs(HttpServletRequest req, String scopeName,
|
|
|
|
String entityContext, String entityName) throws Exception {
|
2018-11-23 15:45:33 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
String entityContextValue = ResourceCatalogueCodes.valueOfCodeId(entityContext).getValue();
|
2019-05-16 12:54:20 +02:00
|
|
|
ScopeBean scopeBean = null;
|
2020-06-18 15:48:47 +02:00
|
|
|
SCOPE_STATUS scopeStatus = SCOPE_STATUS.ACTIVE;
|
|
|
|
VRE vreDetached = null;
|
2022-03-24 17:33:54 +01:00
|
|
|
try {
|
2019-05-16 12:54:20 +02:00
|
|
|
scopeBean = LoadingMapOfScopeCache.get(scopeName);
|
2022-03-24 17:33:54 +01:00
|
|
|
} catch (ExecutionException | InvalidCacheLoadException e) {
|
|
|
|
logger.error(
|
|
|
|
"Error on getting the fullscope from cache for scopeName {}. Tryng to load it from DetachedRE",
|
|
|
|
scopeName);
|
|
|
|
|
2020-06-18 15:48:47 +02:00
|
|
|
boolean isScopeDetached = false;
|
|
|
|
try {
|
|
|
|
vreDetached = LoadingMapOfDetachedVRE.get(scopeName);
|
|
|
|
scopeBean = new ScopeBean(vreDetached.getScope());
|
|
|
|
scopeStatus = SCOPE_STATUS.DETACHED;
|
|
|
|
logger.info("I loaded a valid VRE obj for scope name {}", scopeName);
|
|
|
|
isScopeDetached = true;
|
2022-03-24 17:33:54 +01:00
|
|
|
} catch (Exception e1) {
|
|
|
|
logger.warn("I was not able to load a detached VRE for vreName {}. Going to error for wrong scope",
|
|
|
|
scopeName);
|
2020-06-18 15:48:47 +02:00
|
|
|
}
|
2022-03-24 17:33:54 +01:00
|
|
|
|
|
|
|
// If is not a cas of scope detached, going to error for wrong scope
|
|
|
|
if (!isScopeDetached) {
|
|
|
|
logger.error("Error on getting the fullscope from cache for scopeName " + scopeName, e);
|
|
|
|
throw ExceptionManager.wrongParameterException(req,
|
|
|
|
"Error on getting full scope for the scope name '" + scopeName
|
|
|
|
+ "'. Is it registered as a valid Scope in the D4Science Infrastructure System?",
|
|
|
|
CatalogueResolver.class, helpURI);
|
2020-06-18 15:48:47 +02:00
|
|
|
}
|
2019-05-16 12:54:20 +02:00
|
|
|
}
|
2022-03-24 17:33:54 +01:00
|
|
|
|
2019-05-16 12:54:20 +02:00
|
|
|
String fullScope = scopeBean.toString();
|
2022-03-24 17:33:54 +01:00
|
|
|
logger.info("Read fullScope: " + fullScope + " for SCOPE name: " + scopeName + " from cache created by: "
|
|
|
|
+ GetAllInfrastructureScopes.class.getSimpleName());
|
|
|
|
|
|
|
|
if (scopeBean.is(Type.VO)) {
|
2019-05-16 12:54:20 +02:00
|
|
|
logger.info("It is a {} scope", Type.VO);
|
2022-03-24 17:33:54 +01:00
|
|
|
logger.warn("The Catalogue can't work at {} level, I'm overriding the scope to {} level", Type.VO,
|
|
|
|
Type.INFRASTRUCTURE);
|
2019-05-16 14:56:48 +02:00
|
|
|
String[] splitScope = fullScope.split(ConstantsResolver.SCOPE_SEPARATOR);
|
2022-03-24 17:33:54 +01:00
|
|
|
fullScope = ConstantsResolver.SCOPE_SEPARATOR + splitScope[1]; // THIS IS THE INFRASTRUCTURE SCOPE
|
|
|
|
logger.info("Overriden the input scope {} with {} as type: {}", scopeBean.toString(),
|
|
|
|
Type.INFRASTRUCTURE, fullScope);
|
2018-12-17 11:48:18 +01:00
|
|
|
}
|
2018-11-23 15:45:33 +01:00
|
|
|
|
|
|
|
ScopeProvider.instance.set(fullScope);
|
2020-06-18 15:48:47 +02:00
|
|
|
GatewayCKANCatalogueReference ckanCatalogueReference = null;
|
2022-03-24 17:33:54 +01:00
|
|
|
logger.info("Managing scope status: {}", scopeStatus);
|
|
|
|
|
2020-06-18 15:48:47 +02:00
|
|
|
switch (scopeStatus) {
|
|
|
|
case DETACHED:
|
2022-03-24 17:33:54 +01:00
|
|
|
|
2020-06-18 15:48:47 +02:00
|
|
|
String privatePortletURL = vreDetached.getCatalogPortletURL();
|
2022-03-24 17:33:54 +01:00
|
|
|
// The private portlet URL
|
|
|
|
Map<ACCESS_LEVEL_TO_CATALOGUE_PORTLET, String> mapAccessURLToCatalogue = new HashMap<ACCESS_LEVEL_TO_CATALOGUE_PORTLET, String>(
|
|
|
|
3);
|
|
|
|
mapAccessURLToCatalogue.put(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PRIVATE_VRE, privatePortletURL);
|
|
|
|
|
|
|
|
// Building the gateway catalogue public URL from private VRE Portlet URL
|
2020-06-18 15:48:47 +02:00
|
|
|
URI toURL = new URI(privatePortletURL);
|
2022-03-24 17:33:54 +01:00
|
|
|
String publicURL = privatePortletURL.startsWith("https://") ? "https://" + toURL.getHost()
|
|
|
|
: "http://" + toURL.getHost();
|
|
|
|
// It returns the string "catalogue"
|
2020-06-18 15:48:47 +02:00
|
|
|
CatalogueStaticConfigurations staticConf = new CatalogueStaticConfigurations();
|
2022-03-24 17:33:54 +01:00
|
|
|
// Replacing for example "ckan-bb" with "[PREFIXES-TO-CATALOGUE-URL]-bb" (e.g
|
|
|
|
// catalogue-bb)
|
|
|
|
String relativeURLWithCatalogueName = staticConf
|
|
|
|
.buildRelativeURLToPublicCatalogueGateway(vreDetached.getCatalogUrl());
|
2020-06-18 15:48:47 +02:00
|
|
|
String toGatewayPortletURL = String.format("%s/%s", publicURL, relativeURLWithCatalogueName);
|
2022-03-24 17:33:54 +01:00
|
|
|
mapAccessURLToCatalogue.put(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_GATEWAY, toGatewayPortletURL);
|
|
|
|
|
|
|
|
ckanCatalogueReference = new GatewayCKANCatalogueReference(fullScope, vreDetached.getCatalogUrl(),
|
|
|
|
mapAccessURLToCatalogue);
|
2020-06-18 15:48:47 +02:00
|
|
|
break;
|
|
|
|
case ACTIVE:
|
|
|
|
default:
|
2022-03-24 17:33:54 +01:00
|
|
|
|
|
|
|
ckanCatalogueReference = CkanCatalogueConfigurationsReader.loadCatalogueEndPoints();
|
2020-06-18 15:48:47 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-11-23 15:45:33 +01:00
|
|
|
|
2022-03-24 17:33:54 +01:00
|
|
|
logger.info("For scope " + fullScope + " loaded end points: " + ckanCatalogueReference);
|
2018-11-23 15:45:33 +01:00
|
|
|
|
2022-03-24 17:33:54 +01:00
|
|
|
// IS THE PRODUCT PLUBLIC OR PRIVATE?
|
2018-11-23 15:45:33 +01:00
|
|
|
String datasetName = entityName;
|
2018-11-26 12:56:51 +01:00
|
|
|
boolean isPublicItem = false;
|
2022-03-24 17:33:54 +01:00
|
|
|
if (ckanCatalogueReference.getCkanURL() != null) {
|
|
|
|
try {
|
|
|
|
CkanDataset dataset = CkanCatalogueConfigurationsReader.getDataset(datasetName,
|
|
|
|
ckanCatalogueReference.getCkanURL());
|
|
|
|
if (dataset != null) {
|
2018-11-26 12:56:51 +01:00
|
|
|
isPublicItem = true;
|
2022-03-24 17:33:54 +01:00
|
|
|
// ckanPorltetUrl = ckanCatalogueReference.getPublicPortletURL();
|
|
|
|
logger.info("The dataset " + datasetName + " is a public item");
|
2018-11-23 15:45:33 +01:00
|
|
|
}
|
2022-03-24 17:33:54 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.warn("Error on checking if dataset: " + datasetName + " is private or not", e);
|
2018-11-26 12:56:51 +01:00
|
|
|
isPublicItem = true;
|
2018-10-12 16:20:46 +02:00
|
|
|
}
|
2018-11-23 15:45:33 +01:00
|
|
|
}
|
2018-10-12 16:20:46 +02:00
|
|
|
|
2020-04-06 16:11:55 +02:00
|
|
|
String publicGatewayPorltetURL = String.format("%s?path=/%s/%s",
|
|
|
|
ckanCatalogueReference.getCatalogueURL(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_GATEWAY),
|
2022-03-24 17:33:54 +01:00
|
|
|
entityContextValue, entityName);
|
|
|
|
|
2020-04-06 16:11:55 +02:00
|
|
|
String privateVREPortletURL = String.format("%s?path=/%s/%s",
|
|
|
|
ckanCatalogueReference.getCatalogueURL(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PRIVATE_VRE),
|
2022-03-24 17:33:54 +01:00
|
|
|
entityContextValue, entityName);
|
|
|
|
|
|
|
|
// Checking if the public VRE portlet URL is available (so it was read from GR)
|
2019-11-14 10:41:08 +01:00
|
|
|
String publicVREPortletURL = null;
|
2022-03-24 17:33:54 +01:00
|
|
|
String toCheckPublicVREPortletURL = ckanCatalogueReference
|
|
|
|
.getCatalogueURL(ACCESS_LEVEL_TO_CATALOGUE_PORTLET.PUBLIC_VRE);
|
|
|
|
if (toCheckPublicVREPortletURL != null && !toCheckPublicVREPortletURL.isEmpty()) {
|
|
|
|
// here the catalogue is available/deployed as public at VRE level
|
|
|
|
publicVREPortletURL = String.format("%s?path=/%s/%s", toCheckPublicVREPortletURL, entityContextValue,
|
2020-04-06 16:11:55 +02:00
|
|
|
entityName);
|
2019-11-14 10:41:08 +01:00
|
|
|
}
|
2022-03-24 17:33:54 +01:00
|
|
|
return new ItemCatalogueURLs(entityName, isPublicItem, privateVREPortletURL, publicVREPortletURL,
|
|
|
|
publicGatewayPorltetURL);
|
|
|
|
} catch (Exception e) {
|
2018-12-14 12:28:59 +01:00
|
|
|
logger.error("Error when resolving CatalogueURL:", e);
|
2018-11-23 15:45:33 +01:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
2018-10-12 16:20:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|