Updated Geoportal Resolver

This commit is contained in:
Francesco Mangiacrapa 2023-03-24 09:49:57 +01:00
parent 1107c69b47
commit c6694cd856
3 changed files with 113 additions and 78 deletions

View File

@ -18,7 +18,7 @@ import lombok.extern.slf4j.Slf4j;
public class GeoportalRequest { public class GeoportalRequest {
public static final String P_GCUBE_SCOPE = "gcube_scope"; public static final String P_GCUBE_SCOPE = "gcube_scope";
public static final String P_TARGET_APP = "target_app"; public static final String P_TARGET_APP = "target_app_name";
public static final String P_ITEM_TYPE = "item_type"; public static final String P_ITEM_TYPE = "item_type";
public static final String P_ITEM_ID = "item_id"; public static final String P_ITEM_ID = "item_id";
public static final String P_QUERY_STRING = "query_string"; public static final String P_QUERY_STRING = "query_string";

View File

@ -8,30 +8,31 @@ import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* The Enum ResourceGeoportalCodes. * The Enum TargetAppGeoportalCodes.
* *
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
* *
* Mar 23, 2023 * Mar 24, 2023
*/ */
public enum ResourceGeoportalCodes { public enum TargetAppGeoportalCodes {
GEO("geo", "geoportal-viewer", "Geoportal Viewer"), GEO_V("geo-v", "data-viewer", "Geoportal Viewer"); GEO("geo", "geoportal", "Geoportal"), GEO_DV("geo-dv", "data-viewer", "Geoportal Viewer"),
GEO_DE("geo-de", "data-entry", "Geoportal Entry");
private String id; // the code id private String id; // the code id
private String target_app; // the code value private String name; // the code value
private String description; private String description;
/** /**
* Instantiates a new resource catalogue codes. * Instantiates a new resource catalogue codes.
* *
* @param id the id * @param id the id
* @param target_app the target app * @param name the target app
* @param description the description * @param description the description
*/ */
private ResourceGeoportalCodes(String id, String target_app, String description) { private TargetAppGeoportalCodes(String id, String name, String description) {
this.id = id; this.id = id;
this.target_app = target_app; this.name = name;
this.description = description; this.description = description;
} }
@ -51,7 +52,7 @@ public enum ResourceGeoportalCodes {
* @return the target app * @return the target app
*/ */
public String getTarget_app() { public String getTarget_app() {
return target_app; return name;
} }
/** /**
@ -71,21 +72,21 @@ public enum ResourceGeoportalCodes {
*/ */
public static List<String> codes() { public static List<String> codes() {
return Arrays.asList(ResourceGeoportalCodes.values()).stream().map(ResourceGeoportalCodes::getId) return Arrays.asList(TargetAppGeoportalCodes.values()).stream().map(TargetAppGeoportalCodes::getId)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
/** /**
* Value of code id. * Value of id.
* *
* @param id the id * @param id the id
* @return the resource geoportal codes * @return the target app geoportal codes
*/ */
public static ResourceGeoportalCodes valueOfCodeId(String id) { public static TargetAppGeoportalCodes valueOfId(String id) {
if (id == null || id.isEmpty()) if (id == null || id.isEmpty())
return null; return null;
List<ResourceGeoportalCodes> codes = Arrays.asList(ResourceGeoportalCodes.values()).stream() List<TargetAppGeoportalCodes> codes = Arrays.asList(TargetAppGeoportalCodes.values()).stream()
.filter(value -> value.getId().compareTo(id) == 0).collect(Collectors.toList()); .filter(value -> value.getId().compareTo(id) == 0).collect(Collectors.toList());
if (codes == null || codes.isEmpty()) if (codes == null || codes.isEmpty())
@ -96,17 +97,17 @@ public enum ResourceGeoportalCodes {
} }
/** /**
* Value of target app. * Value of name.
* *
* @param targetApp the target app * @param name the name
* @return the resource geoportal codes * @return the target app geoportal codes
*/ */
public static ResourceGeoportalCodes valueOfTargetApp(String targetApp) { public static TargetAppGeoportalCodes valueOfName(String name) {
if (targetApp == null || targetApp.isEmpty()) if (name == null || name.isEmpty())
return null; return null;
List<ResourceGeoportalCodes> codes = Arrays.asList(ResourceGeoportalCodes.values()).stream() List<TargetAppGeoportalCodes> codes = Arrays.asList(TargetAppGeoportalCodes.values()).stream()
.filter(value -> value.getTarget_app().compareTo(targetApp) == 0).collect(Collectors.toList()); .filter(value -> value.getTarget_app().compareTo(name) == 0).collect(Collectors.toList());
if (codes == null || codes.isEmpty()) if (codes == null || codes.isEmpty())
return null; return null;

View File

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