Implmented share link towards Geoportal Data-Entry facility [#27135]

This commit is contained in:
Francesco Mangiacrapa 2024-04-03 15:58:43 +02:00
parent 89c3f1f435
commit 3edd9b81de
5 changed files with 104 additions and 84 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
@ -18,8 +18,10 @@
<wb-module deploy-name="uri-resolver-2.9.0">
<wb-module deploy-name="uri-resolver-2.10.0-SNAPSHOT">
@ -39,7 +41,8 @@
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
@ -59,7 +62,8 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
@ -79,7 +83,8 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
@ -99,7 +104,8 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
@ -119,7 +125,8 @@
<property name="context-root" value="uri-resolver"/>
@ -139,7 +146,8 @@
<property name="java-output-path" value="/uri-resolver/target/classes"/>
@ -159,7 +167,8 @@
</wb-module>

View File

@ -12,6 +12,8 @@ public class GeoportalCommonConstants {
public static final String GET_GEONA_ITEM_TYPE = "git";
public static final String GET_GEONA_ITEM_ID = "gid";
public static final String GEOPORTAL_DATA_VIEWER_APP = "geoportal-data-viewer-app";
public static final String GEOPORTAL_DATA_VIEWER_APP_ID = "geoportal-data-viewer-app";
public static final String GEOPORTAL_DATA_ENTRY_APP_ID = "geoportal-data-entry-app";
}

View File

@ -3,25 +3,25 @@ package org.gcube.datatransfer.resolver.geoportal;
import java.io.Serializable;
/**
* The Class GeoportalDataViewerConfigProfile.
* The Class GeoportalConfigApplicationProfile.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Dec 21, 2021
* Apr 3, 2024
*/
public class GeoportalDataViewerConfigProfile implements Serializable {
public class GeoportalConfigApplicationProfile implements Serializable {
/**
*
*/
private static final long serialVersionUID = 2968334957258327191L;
private static final long serialVersionUID = 8340275391003882511L;
private String restrictedPortletURL;
private String openPortletURL;
/**
* Instantiates a new geo na data viewer profile.
*/
public GeoportalDataViewerConfigProfile() {
public GeoportalConfigApplicationProfile() {
}
@ -61,15 +61,20 @@ public class GeoportalDataViewerConfigProfile implements Serializable {
this.openPortletURL = openPortletURL;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GeoportalDataViewerConfigProfile [restrictedPortletURL=");
builder.append("GeoportalConfigApplicationProfile [restrictedPortletURL=");
builder.append(restrictedPortletURL);
builder.append(", openPortletURL=");
builder.append(openPortletURL);
builder.append("]");
return builder.toString();
}
}

View File

@ -20,36 +20,35 @@ import org.w3c.dom.Document;
import org.xml.sax.InputSource;
/**
* The Class GeoportalDataViewerConfigProfileReader.
* The Class GeoportalConfigApplicationProfileReader.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Mar 23, 2023
* Apr 3, 2024
*/
public class GeoportalDataViewerConfigProfileReader {
public class GeoportalConfigApplicationProfileReader {
private static Logger LOG = LoggerFactory.getLogger(GeoportalConfigApplicationProfileReader.class);
private static final String RESOURCE_PROFILE_BODY = "/Resource/Profile/Body";
public static final String SECONDARY_TYPE = "ApplicationProfile";
public static final String GENERIC_RESOURCE_NAME = "Geoportal-DataViewer-Configs";
private static Logger LOG = LoggerFactory.getLogger(GeoportalDataViewerConfigProfileReader.class);
private String secondaryType;
private String scope;
private String appID;
private GeoportalDataViewerConfigProfile geoportalDataViewerConfigProfile;
private GeoportalConfigApplicationProfile geoportalConfigAppProfile;
/**
* Instantiates a new geoportal data viewer config profile reader.
* Instantiates a new geoportal config application profile reader.
*
* @param appID the app ID
* @throws Exception the exception
*/
public GeoportalDataViewerConfigProfileReader(String appID) throws Exception {
public GeoportalConfigApplicationProfileReader(String appID) throws Exception {
this.appID = appID;
this.secondaryType = SECONDARY_TYPE;
this.scope = ScopeProvider.instance.get();
this.geoportalDataViewerConfigProfile = readProfileFromInfrastructure();
this.geoportalConfigAppProfile = readProfileFromInfrastructure();
}
/**
@ -58,7 +57,7 @@ public class GeoportalDataViewerConfigProfileReader {
* @return the map
* @throws Exception the exception
*/
private GeoportalDataViewerConfigProfile readProfileFromInfrastructure() throws Exception {
private GeoportalConfigApplicationProfile readProfileFromInfrastructure() throws Exception {
String queryString = getGcubeGenericQueryString(secondaryType, appID);
LOG.info("Scope " + scope + ", trying to perform query: " + queryString);
@ -68,7 +67,7 @@ public class GeoportalDataViewerConfigProfileReader {
if (scope == null)
throw new Exception("Scope is null, set scope into ScopeProvider");
GeoportalDataViewerConfigProfile profile = new GeoportalDataViewerConfigProfile();
GeoportalConfigApplicationProfile profile = new GeoportalConfigApplicationProfile();
LOG.info("Trying to fetch ApplicationProfile in the scope: " + scope + ", SecondaryType: " + secondaryType
+ ", AppId: " + appID);
@ -107,8 +106,8 @@ public class GeoportalDataViewerConfigProfileReader {
}
} catch (Exception e) {
LOG.error("Error while trying to read the " + SECONDARY_TYPE + " with SecondaryType "
+ GENERIC_RESOURCE_NAME + " from scope " + scope, e);
LOG.error("Error while trying to read the SecondaryType " + SECONDARY_TYPE + " with appID " + appID
+ " from scope " + scope, e);
return null;
} finally {
@ -116,8 +115,13 @@ public class GeoportalDataViewerConfigProfileReader {
}
public GeoportalDataViewerConfigProfile getGeoportalDataViewerConfigProfile() {
return geoportalDataViewerConfigProfile;
/**
* Gets the geoportal config app profile.
*
* @return the geoportal config app profile
*/
public GeoportalConfigApplicationProfile getGeoportalConfigAppProfile() {
return geoportalConfigAppProfile;
}
/**
@ -152,17 +156,22 @@ public class GeoportalDataViewerConfigProfileReader {
return scope;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GeoportalDataViewerConfigProfileReader [secondaryType=");
builder.append("GeoportalConfigApplicationProfileReader [secondaryType=");
builder.append(secondaryType);
builder.append(", scope=");
builder.append(scope);
builder.append(", appID=");
builder.append(appID);
builder.append(", geoportalDataViewerConfigProfile=");
builder.append(geoportalDataViewerConfigProfile);
builder.append(", geoportalConfigAppProfile=");
builder.append(geoportalConfigAppProfile);
builder.append("]");
return builder.toString();
}

View File

@ -24,8 +24,8 @@ import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.datatransfer.resolver.ConstantsResolver;
import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache;
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.GeoportalConfigApplicationProfile;
import org.gcube.datatransfer.resolver.geoportal.GeoportalConfigApplicationProfileReader;
import org.gcube.datatransfer.resolver.geoportal.GeoportalRequest;
import org.gcube.datatransfer.resolver.geoportal.TargetAppGeoportalCodes;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
@ -45,7 +45,7 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Mar 23, 2023
* Apr 03, 2024
*/
@Path("/geo")
public class GeoportalResolver {
@ -141,8 +141,7 @@ public class GeoportalResolver {
public Response resolveDataViewerLink(@Context HttpServletRequest req,
@QueryParam(GeoportalRequest.P_GCUBE_SCOPE) String gcubeScope,
@QueryParam(GeoportalRequest.P_ITEM_ID) String itemId,
@QueryParam(GeoportalRequest.P_ITEM_TYPE) String itemType,
@QueryParam(QP_RESOLVE_AS) String resolveAs)
@QueryParam(GeoportalRequest.P_ITEM_TYPE) String itemType, @QueryParam(QP_RESOLVE_AS) String resolveAs)
throws WebApplicationException {
LOG.info(this.getClass().getSimpleName() + " resolveDataViewerLink - GET starts...");
@ -321,21 +320,35 @@ public class GeoportalResolver {
LOG.info("Found RESOLVE_AS_PARAMETER: " + resolveAs);
String originalScope = ScopeProvider.instance.get();
GeoportalDataViewerConfigProfileReader reader;
GeoportalConfigApplicationProfileReader reader;
String itemLink = null;
String appID = null;
// Resolving towards Data-Viewer or Data-Entry Application
switch (resoruceGeoportalCodes) {
case GEO_DE: {
appID = org.gcube.datatransfer.resolver.geoportal.GeoportalCommonConstants.GEOPORTAL_DATA_ENTRY_APP_ID;
break;
}
case GEO_DV:
default: {
appID = org.gcube.datatransfer.resolver.geoportal.GeoportalCommonConstants.GEOPORTAL_DATA_VIEWER_APP_ID;
break;
}
}
try {
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);
reader = new GeoportalConfigApplicationProfileReader(appID);
} catch (Exception e) {
LOG.error("Error on reading the " + GeoportalDataViewerConfigProfileReader.SECONDARY_TYPE
+ " with generic resource name: "
+ GeoportalDataViewerConfigProfileReader.GENERIC_RESOURCE_NAME, e);
throw ExceptionManager.internalErrorException(req,
"Error on reading the " + GeoportalDataViewerConfigProfileReader.SECONDARY_TYPE + " for name "
+ GeoportalDataViewerConfigProfileReader.GENERIC_RESOURCE_NAME
+ ". Please contact the support",
String error = "Error on reading the generic resource with SecondaryType: "
+ GeoportalConfigApplicationProfileReader.SECONDARY_TYPE + " and APP ID: " + appID
+ " in the scope: " + appID;
LOG.error(error, e);
throw ExceptionManager.internalErrorException(req, error + ". Please contact the support",
this.getClass(), helpURI);
} finally {
if (originalScope != null && !originalScope.isEmpty()) {
@ -347,51 +360,33 @@ public class GeoportalResolver {
}
}
// Resolving towards Data-Viewer or Data-Entry Application
String itemLink = null;
GeoportalConfigApplicationProfile geonaDataProfile = reader.getGeoportalConfigAppProfile();
switch (resoruceGeoportalCodes) {
case GEO_DV: {
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: {
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;
}
// 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;
}
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)) {