|
|
|
@ -27,7 +27,7 @@ import org.gcube.datatransfer.resolver.geoportal.GeoportalCommonConstants;
|
|
|
|
|
import org.gcube.datatransfer.resolver.geoportal.GeoportalDataViewerConfigProfile;
|
|
|
|
|
import org.gcube.datatransfer.resolver.geoportal.GeoportalDataViewerConfigProfileReader;
|
|
|
|
|
import org.gcube.datatransfer.resolver.geoportal.GeoportalRequest;
|
|
|
|
|
import org.gcube.datatransfer.resolver.geoportal.ResourceGeoportalCodes;
|
|
|
|
|
import org.gcube.datatransfer.resolver.geoportal.TargetAppGeoportalCodes;
|
|
|
|
|
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
|
|
|
|
import org.gcube.datatransfer.resolver.util.Util;
|
|
|
|
|
import org.gcube.smartgears.utils.InnerMethodName;
|
|
|
|
@ -46,12 +46,14 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
|
|
|
|
|
*
|
|
|
|
|
* Mar 23, 2023
|
|
|
|
|
*/
|
|
|
|
|
@Path("{targetApp:geo(-(v))?}")
|
|
|
|
|
@Path("{targetAppId:geo(-(dv|-de))?}")
|
|
|
|
|
public class GeoportalResolver {
|
|
|
|
|
|
|
|
|
|
private static final String PROJECT_ID = "project_id";
|
|
|
|
|
private static final String USECASE_ID = "usecase_id";
|
|
|
|
|
private static final String VRE_NAME = "vreName";
|
|
|
|
|
private static final String QP_RESOLVE_AS = "res";
|
|
|
|
|
private static final String PATH_PROJECT_ID = "project_id";
|
|
|
|
|
private static final String PATH_USECASE_ID = "usecase_id";
|
|
|
|
|
private static final String PATH_VRE_NAME = "vre_name";
|
|
|
|
|
private static final String PATH_TARGET_APP = "targetAppId";
|
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(GeoportalResolver.class);
|
|
|
|
|
private static String helpURI = "https://wiki.gcube-system.org/gcube/URI_Resolver#Geoportal_Resolver";
|
|
|
|
|
|
|
|
|
@ -59,44 +61,48 @@ public class GeoportalResolver {
|
|
|
|
|
PUBLIC, PRIVATE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Path("/{vreName}/{usecase_id}/{project_id}")
|
|
|
|
|
public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(VRE_NAME) String vreName,
|
|
|
|
|
@PathParam(USECASE_ID) String ucdID, @PathParam(PROJECT_ID) String projectID,
|
|
|
|
|
@QueryParam("r") String resolve) throws WebApplicationException {
|
|
|
|
|
@Path("/{vre_name}/{usecase_id}/{project_id}")
|
|
|
|
|
public Response resolveGeoportal(@Context HttpServletRequest req, @PathParam(PATH_TARGET_APP) String targetAppId,
|
|
|
|
|
@PathParam(PATH_VRE_NAME) String vreName, @PathParam(PATH_USECASE_ID) String ucdID,
|
|
|
|
|
@PathParam(PATH_PROJECT_ID) String projectID, @QueryParam(QP_RESOLVE_AS) String resolveAs)
|
|
|
|
|
throws WebApplicationException {
|
|
|
|
|
|
|
|
|
|
LOG.info(this.getClass().getSimpleName() + " GET starts...");
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
InnerMethodName.instance.set("resolveGeoportalPublicLink");
|
|
|
|
|
|
|
|
|
|
TargetAppGeoportalCodes resoruceGeoportalCodes = TargetAppGeoportalCodes.valueOfId(targetAppId);
|
|
|
|
|
|
|
|
|
|
LOG.info("Found target app: " + resoruceGeoportalCodes);
|
|
|
|
|
|
|
|
|
|
if (resoruceGeoportalCodes == null) {
|
|
|
|
|
LOG.error("The path parameter '" + PATH_TARGET_APP + "' not found or empty in the path");
|
|
|
|
|
throw ExceptionManager.badRequestException(req,
|
|
|
|
|
"Mandatory path parameter '" + PATH_TARGET_APP + "' not found or empty", this.getClass(),
|
|
|
|
|
helpURI);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (vreName == null || vreName.isEmpty()) {
|
|
|
|
|
LOG.error("The path parameter '" + VRE_NAME + "' not found or empty in the path");
|
|
|
|
|
throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty",
|
|
|
|
|
this.getClass(), helpURI);
|
|
|
|
|
LOG.error("The path parameter '" + PATH_VRE_NAME + "' not found or empty in the path");
|
|
|
|
|
throw ExceptionManager.badRequestException(req,
|
|
|
|
|
"Mandatory path parameter '" + PATH_VRE_NAME + "' not found or empty", this.getClass(),
|
|
|
|
|
helpURI);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ucdID == null) {
|
|
|
|
|
LOG.error("The path parameter '" + USECASE_ID + "' not found or empty in the path");
|
|
|
|
|
throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty",
|
|
|
|
|
this.getClass(), helpURI);
|
|
|
|
|
LOG.error("The path parameter '" + PATH_USECASE_ID + "' not found or empty in the path");
|
|
|
|
|
throw ExceptionManager.badRequestException(req,
|
|
|
|
|
"Mandatory path parameter '" + PATH_USECASE_ID + "' not found or empty", this.getClass(),
|
|
|
|
|
helpURI);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (projectID == null) {
|
|
|
|
|
LOG.error("The path parameter '" + PROJECT_ID + "' not found or empty in the path");
|
|
|
|
|
throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty",
|
|
|
|
|
this.getClass(), helpURI);
|
|
|
|
|
LOG.error("The path parameter '" + PATH_PROJECT_ID + "' not found or empty in the path");
|
|
|
|
|
throw ExceptionManager.badRequestException(req,
|
|
|
|
|
"Mandatory path parameter '" + PATH_PROJECT_ID + "' not found or empty", this.getClass(),
|
|
|
|
|
helpURI);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ScopeBean fullScopeBean = null;
|
|
|
|
@ -113,8 +119,8 @@ public class GeoportalResolver {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RESOLVE_AS resolveTO = RESOLVE_AS.PUBLIC;
|
|
|
|
|
if (resolve != null) {
|
|
|
|
|
switch (resolve.toLowerCase()) {
|
|
|
|
|
if (resolveAs != null) {
|
|
|
|
|
switch (resolveAs.toLowerCase()) {
|
|
|
|
|
case "public":
|
|
|
|
|
resolveTO = RESOLVE_AS.PUBLIC;
|
|
|
|
|
break;
|
|
|
|
@ -124,11 +130,14 @@ public class GeoportalResolver {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG.info("Found RESOLVE_AS: " + resolveAs);
|
|
|
|
|
|
|
|
|
|
String originalScope = ScopeProvider.instance.get();
|
|
|
|
|
GeoportalDataViewerConfigProfileReader reader;
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
ScopeProvider.instance.set(fullScopeBean.toString());
|
|
|
|
|
String theScope = fullScopeBean.toString();
|
|
|
|
|
LOG.info("Full scope is: " + theScope);
|
|
|
|
|
ScopeProvider.instance.set(theScope);
|
|
|
|
|
reader = new GeoportalDataViewerConfigProfileReader(
|
|
|
|
|
org.gcube.datatransfer.resolver.geoportal.GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
@ -150,34 +159,58 @@ public class GeoportalResolver {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GeoportalDataViewerConfigProfile geonaDataProfile = reader.getGeoportalDataViewerConfigProfile();
|
|
|
|
|
// Resolving towards Data-Viewer or Data-Entry Application
|
|
|
|
|
String itemLink = null;
|
|
|
|
|
switch (resolveTO) {
|
|
|
|
|
case PUBLIC:
|
|
|
|
|
// Open Link
|
|
|
|
|
itemLink = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getOpenPortletURL(),
|
|
|
|
|
GeoportalCommonConstants.GET_GEONA_ITEM_ID, projectID,
|
|
|
|
|
GeoportalCommonConstants.GET_GEONA_ITEM_TYPE, ucdID);
|
|
|
|
|
break;
|
|
|
|
|
case PRIVATE:
|
|
|
|
|
|
|
|
|
|
// Restricted Link
|
|
|
|
|
String link = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getRestrictedPortletURL(),
|
|
|
|
|
GeoportalCommonConstants.GET_GEONA_ITEM_ID, projectID,
|
|
|
|
|
GeoportalCommonConstants.GET_GEONA_ITEM_TYPE, ucdID);
|
|
|
|
|
switch (resoruceGeoportalCodes) {
|
|
|
|
|
case GEO:
|
|
|
|
|
case GEO_DV: {
|
|
|
|
|
|
|
|
|
|
GeoportalDataViewerConfigProfile geonaDataProfile = reader.getGeoportalDataViewerConfigProfile();
|
|
|
|
|
|
|
|
|
|
switch (resolveTO) {
|
|
|
|
|
case PUBLIC:
|
|
|
|
|
// Open Link
|
|
|
|
|
itemLink = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getOpenPortletURL(),
|
|
|
|
|
GeoportalCommonConstants.GET_GEONA_ITEM_ID, projectID,
|
|
|
|
|
GeoportalCommonConstants.GET_GEONA_ITEM_TYPE, ucdID);
|
|
|
|
|
break;
|
|
|
|
|
case PRIVATE:
|
|
|
|
|
|
|
|
|
|
// Restricted Link
|
|
|
|
|
itemLink = String.format("%s?%s=%s&%s=%s", geonaDataProfile.getRestrictedPortletURL(),
|
|
|
|
|
GeoportalCommonConstants.GET_GEONA_ITEM_ID, projectID,
|
|
|
|
|
GeoportalCommonConstants.GET_GEONA_ITEM_TYPE, ucdID);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case GEO_DE: {
|
|
|
|
|
|
|
|
|
|
LOG.error("The Resolver towards '" + resoruceGeoportalCodes + "' not implemented yet");
|
|
|
|
|
throw ExceptionManager.internalErrorException(req,
|
|
|
|
|
"The Resolver towards '" + resoruceGeoportalCodes + "' not implemented yet", this.getClass(),
|
|
|
|
|
helpURI);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG.info("Returning link: " + itemLink);
|
|
|
|
|
return Response.seeOther(new URL(itemLink).toURI()).build();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
|
|
if (!(e instanceof WebApplicationException)) {
|
|
|
|
|
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
|
|
|
|
String error = "Error occurred on resolving the "+GeoportalResolver.class.getSimpleName()+" URL. Please, contact the support!";
|
|
|
|
|
String error = "Error occurred on resolving the " + GeoportalResolver.class.getSimpleName()
|
|
|
|
|
+ " URL. Please, contact the support!";
|
|
|
|
|
if (e.getCause() != null)
|
|
|
|
|
error += "\n\nCaused: " + e.getCause().getMessage();
|
|
|
|
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
|
|
|
@ -252,16 +285,16 @@ public class GeoportalResolver {
|
|
|
|
|
"The scope '" + scope + "' does not matching any scope in the infrastructure. Is it valid?",
|
|
|
|
|
this.getClass(), helpURI);
|
|
|
|
|
|
|
|
|
|
ResourceGeoportalCodes resoruceGeoportalCodes = ResourceGeoportalCodes
|
|
|
|
|
.valueOfTargetApp(jsonRequest.getTargetApp());
|
|
|
|
|
TargetAppGeoportalCodes resoruceGeoportalCodes = TargetAppGeoportalCodes
|
|
|
|
|
.valueOfName(jsonRequest.getTargetApp());
|
|
|
|
|
|
|
|
|
|
if (resoruceGeoportalCodes == null) {
|
|
|
|
|
LOG.error("Target application is null/malformed");
|
|
|
|
|
resoruceGeoportalCodes = ResourceGeoportalCodes.GEO;
|
|
|
|
|
LOG.info("Target application using default: "+resoruceGeoportalCodes);
|
|
|
|
|
}else {
|
|
|
|
|
List<String> targetApps = Arrays.asList(ResourceGeoportalCodes.values()).stream()
|
|
|
|
|
.map(ResourceGeoportalCodes::getTarget_app).collect(Collectors.toList());
|
|
|
|
|
LOG.error("Target application parameter is null/malformed");
|
|
|
|
|
resoruceGeoportalCodes = TargetAppGeoportalCodes.GEO;
|
|
|
|
|
LOG.info("Target application using default: " + resoruceGeoportalCodes);
|
|
|
|
|
} else {
|
|
|
|
|
List<String> targetApps = Arrays.asList(TargetAppGeoportalCodes.values()).stream()
|
|
|
|
|
.map(TargetAppGeoportalCodes::getTarget_app).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
throw ExceptionManager.badRequestException(req,
|
|
|
|
|
"Target application is null/malformed. It must be: " + targetApps, this.getClass(), helpURI);
|
|
|
|
@ -281,7 +314,8 @@ public class GeoportalResolver {
|
|
|
|
|
|
|
|
|
|
if (!(e instanceof WebApplicationException)) {
|
|
|
|
|
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
|
|
|
|
String error = "Error occurred on creating the "+GeoportalResolver.class.getSimpleName()+" URL. Please, contact the support!";
|
|
|
|
|
String error = "Error occurred on creating the " + GeoportalResolver.class.getSimpleName()
|
|
|
|
|
+ " URL. Please, contact the support!";
|
|
|
|
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
|
|
|
|
}
|
|
|
|
|
// ALREADY MANAGED AS WebApplicationExceptiongetItemCatalogueURLs
|
|
|
|
|