Merge pull request 'task_24792' (!3) from task_24792 into master
Reviewed-on: #3
This commit is contained in:
commit
873a0b63ed
|
@ -3,6 +3,10 @@
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [v1.7.0-SNAPSHOT]
|
||||||
|
|
||||||
|
- [#24842] Integrated the new Geoportal-Resolver
|
||||||
|
|
||||||
## [v1.6.0] - 2022-07-26
|
## [v1.6.0] - 2022-07-26
|
||||||
|
|
||||||
**New**
|
**New**
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -11,7 +11,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.gcube.portlets.user</groupId>
|
<groupId>org.gcube.portlets.user</groupId>
|
||||||
<artifactId>uri-resolver-manager</artifactId>
|
<artifactId>uri-resolver-manager</artifactId>
|
||||||
<version>1.6.0</version>
|
<version>1.7.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>uri-resolver-manager</name>
|
<name>uri-resolver-manager</name>
|
||||||
<description>The URI Resolver Manager</description>
|
<description>The URI Resolver Manager</description>
|
||||||
|
|
|
@ -112,6 +112,14 @@ public class CatalogueResolverCallBuilder extends GenericResolver {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short link.
|
||||||
|
*
|
||||||
|
* @param theLink the the link
|
||||||
|
* @param parameters the parameters
|
||||||
|
* @return the string
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String shortLink(String theLink, Map<String, String> parameters) throws Exception {
|
public String shortLink(String theLink, Map<String, String> parameters) throws Exception {
|
||||||
LOG.info("specific shortLink called");
|
LOG.info("specific shortLink called");
|
||||||
|
@ -166,6 +174,12 @@ public class CatalogueResolverCallBuilder extends GenericResolver {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short the link.
|
||||||
|
*
|
||||||
|
* @param link the link
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
private String shortTheLink(String link) {
|
private String shortTheLink(String link) {
|
||||||
|
|
||||||
String toReturnLink = link;
|
String toReturnLink = link;
|
||||||
|
|
|
@ -0,0 +1,217 @@
|
||||||
|
package org.gcube.portlets.user.uriresolvermanager.resolvers;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.entity.GenericResolver;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.util.UrlEncoderUtil;
|
||||||
|
import org.gcube.portlets.user.urlshortener.UrlShortener;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class GeoportalResolverCallBuilder.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Mar 27, 2023
|
||||||
|
*/
|
||||||
|
public class GeoportalResolverCallBuilder extends GenericResolver {
|
||||||
|
|
||||||
|
private static final int _60SEC = 60000;
|
||||||
|
public static final Logger LOG = LoggerFactory.getLogger(GeoportalResolverCallBuilder.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new geoportal resolver call builder.
|
||||||
|
*
|
||||||
|
* @param resourceName the resource name
|
||||||
|
* @param entryName the entry name
|
||||||
|
*/
|
||||||
|
public GeoportalResolverCallBuilder(String resourceName, String entryName) {
|
||||||
|
super(resourceName, entryName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the link.
|
||||||
|
*
|
||||||
|
* @param baseURI the base URI
|
||||||
|
* @param parameters the parameters
|
||||||
|
* @return the link
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getLink(String baseURI, Map<String, String> parameters) throws Exception {
|
||||||
|
LOG.debug("called getLink: " + baseURI + " parameters: " + parameters);
|
||||||
|
|
||||||
|
HttpURLConnection con = null;
|
||||||
|
String theResponse = null;
|
||||||
|
try {
|
||||||
|
|
||||||
|
URL urlObj = new URL(baseURI);
|
||||||
|
con = (HttpURLConnection) urlObj.openConnection();
|
||||||
|
con.setRequestMethod("POST");
|
||||||
|
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
|
||||||
|
// con.setRequestProperty("Accept", "application/json");
|
||||||
|
|
||||||
|
con.setDoOutput(true);
|
||||||
|
con.setReadTimeout(_60SEC);
|
||||||
|
con.setConnectTimeout(_60SEC);
|
||||||
|
|
||||||
|
JSONObject jObj = new org.json.JSONObject();
|
||||||
|
for (String key : parameters.keySet()) {
|
||||||
|
jObj.put(key, parameters.get(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (queryStringParameters != null) {
|
||||||
|
// String queryString = UrlEncoderUtil.toQueryString(queryStringParameters);
|
||||||
|
// jObj.put(CatalogueResolverQueryStringBuilder.QUERY_STRING_PARAMETER, queryString);
|
||||||
|
// }
|
||||||
|
|
||||||
|
String toJSON = jObj.toString();
|
||||||
|
LOG.info("Submitting JSON: " + toJSON);
|
||||||
|
Integer code = null;
|
||||||
|
try {
|
||||||
|
|
||||||
|
OutputStream os = con.getOutputStream();
|
||||||
|
os.write(toJSON.getBytes("UTF-8"));
|
||||||
|
os.close();
|
||||||
|
|
||||||
|
code = con.getResponseCode();
|
||||||
|
theResponse = readResponse(con.getInputStream());
|
||||||
|
|
||||||
|
if (!((200 <= code) && (code <= 208))) {
|
||||||
|
throw new Exception("CatalogueResolver returned code: " + code + ". Response is: " + theResponse);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
theResponse = readResponse(con.getInputStream());
|
||||||
|
LOG.error("CatalogueResolver returned code: " + code + ". Response is: " + theResponse);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error(GeoportalResolverCallBuilder.class.getSimpleName() + " error: ", e);
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (con != null)
|
||||||
|
con.disconnect();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// silent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LOG.info("Got Link: " + theResponse);
|
||||||
|
return theResponse;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short link.
|
||||||
|
*
|
||||||
|
* @param theLink the the link
|
||||||
|
* @param parameters the parameters
|
||||||
|
* @return the string
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String shortLink(String theLink, Map<String, String> parameters) throws Exception {
|
||||||
|
LOG.info("specific shortLink called");
|
||||||
|
|
||||||
|
String linkDecoded = theLink;
|
||||||
|
|
||||||
|
String[] queryStringArray = theLink.split("\\?");
|
||||||
|
if (queryStringArray.length > 1) {
|
||||||
|
String queryString = queryStringArray[1];
|
||||||
|
String queryStringEncoded = UrlEncoderUtil.encodeQuery(queryString);
|
||||||
|
theLink = String.format("%s?%s", queryStringArray[0], queryStringEncoded);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (parameters != null) {
|
||||||
|
// LOG.debug("Trying to read the parameter: " + CatalogueResolverQueryStringBuilder.QUERY_STRING_PARAMETER);
|
||||||
|
// String queryStringParmeters = parameters.get(CatalogueResolverQueryStringBuilder.QUERY_STRING_PARAMETER);
|
||||||
|
// if (queryStringParmeters != null) {
|
||||||
|
// LOG.debug(CatalogueResolverQueryStringBuilder.QUERY_STRING_PARAMETER + " found");
|
||||||
|
// queryString = UrlEncoderUtil.encodeQuery(queryStringParmeters);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
try {
|
||||||
|
// LOG.debug(CatalogueResolverQueryStringBuilder.QUERY_STRING_PARAMETER + " encoded is: " + queryString);
|
||||||
|
// if (queryString != null) {
|
||||||
|
// String queryStringEncoded = UrlEncoderUtil.encodeString(queryString);
|
||||||
|
// theLink = String.format("%s?%s", theLink, queryStringEncoded);
|
||||||
|
// }
|
||||||
|
LOG.info("Encoded link is: " + theLink);
|
||||||
|
LOG.info("Shortner starts..");
|
||||||
|
String shortLink = shortTheLink(theLink);
|
||||||
|
LOG.info("Shorted link is: " + shortLink);
|
||||||
|
if (shortLink != null && shortLink.equals(theLink)) {
|
||||||
|
// here the short link and the input link are identical
|
||||||
|
// so the shortening did not work
|
||||||
|
// I'm returning the decoded link because it is directly consumable via browser
|
||||||
|
LOG.debug("Shorted link is equal to input link, returning decoded link: " + linkDecoded);
|
||||||
|
theLink = linkDecoded;
|
||||||
|
} else {
|
||||||
|
// here the link is really shorted
|
||||||
|
LOG.debug("The link is really short, returning it");
|
||||||
|
theLink = shortLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.warn("An error occurred during link shortening: ", e);
|
||||||
|
// here I'm returning the decoded link in case of error on shortening it
|
||||||
|
theLink = linkDecoded;
|
||||||
|
}
|
||||||
|
|
||||||
|
return theLink;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short the link.
|
||||||
|
*
|
||||||
|
* @param link the link
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
private String shortTheLink(String link) {
|
||||||
|
|
||||||
|
String toReturnLink = link;
|
||||||
|
try {
|
||||||
|
UrlShortener shortener = new UrlShortener();
|
||||||
|
String shortedLink = shortener.shorten(link);
|
||||||
|
LOG.info("Shorted link is: " + shortedLink);
|
||||||
|
toReturnLink = shortedLink;
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.warn("Returning source link, an error occurred during link shortening: ", e);
|
||||||
|
}
|
||||||
|
return toReturnLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read response.
|
||||||
|
*
|
||||||
|
* @param ris the ris
|
||||||
|
* @return the string
|
||||||
|
* @throws IOException Signals that an I/O exception has occurred.
|
||||||
|
*/
|
||||||
|
private String readResponse(InputStream ris) throws IOException {
|
||||||
|
// Receive the response from the server
|
||||||
|
InputStream in = new BufferedInputStream(ris);
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
result.append(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,81 @@
|
||||||
|
package org.gcube.portlets.user.uriresolvermanager.resolvers.query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class GeoportalResolverQueryString.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Mar 27, 2023
|
||||||
|
*/
|
||||||
|
public class GeoportalResolverQueryString {
|
||||||
|
|
||||||
|
private final String itemType;
|
||||||
|
private String itemId;
|
||||||
|
private String gcubeScope;
|
||||||
|
private String resolveAs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new geoportal resolver query string.
|
||||||
|
*
|
||||||
|
* @param builder the builder
|
||||||
|
*/
|
||||||
|
public GeoportalResolverQueryString(GeoportalResolverQueryStringBuilder builder) {
|
||||||
|
this.itemType = builder.getItemType();
|
||||||
|
this.itemId = builder.getItemId();
|
||||||
|
this.gcubeScope = builder.getGcubeScope();
|
||||||
|
this.resolveAs = builder.getResolveAs() != null ? builder.getResolveAs().getParamValue() : null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the item type.
|
||||||
|
*
|
||||||
|
* @return the item type
|
||||||
|
*/
|
||||||
|
public String getItemType() {
|
||||||
|
return itemType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the item id.
|
||||||
|
*
|
||||||
|
* @return the item id
|
||||||
|
*/
|
||||||
|
public String getItemId() {
|
||||||
|
return itemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the gcube scope.
|
||||||
|
*
|
||||||
|
* @return the gcube scope
|
||||||
|
*/
|
||||||
|
public String getGcubeScope() {
|
||||||
|
return gcubeScope;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the resolver as.
|
||||||
|
*
|
||||||
|
* @return the resolver as
|
||||||
|
*/
|
||||||
|
public String getResolveAs() {
|
||||||
|
return resolveAs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("GeoportalResolverQueryString [itemType=");
|
||||||
|
builder.append(itemType);
|
||||||
|
builder.append(", itemId=");
|
||||||
|
builder.append(itemId);
|
||||||
|
builder.append(", gcubeScope=");
|
||||||
|
builder.append(gcubeScope);
|
||||||
|
builder.append(", resolveAs=");
|
||||||
|
builder.append(resolveAs);
|
||||||
|
builder.append("]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,160 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.portlets.user.uriresolvermanager.resolvers.query;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class GeoportalResolverQueryStringBuilder.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Mar 27, 2023
|
||||||
|
*/
|
||||||
|
public final class GeoportalResolverQueryStringBuilder {
|
||||||
|
|
||||||
|
public static final Logger LOG = LoggerFactory.getLogger(GeoportalResolverQueryStringBuilder.class);
|
||||||
|
public static final String ITEM_TYPE_PARAMETER = "item_type";
|
||||||
|
public static final String ITEM_ID_PARAMETER = "item_id";
|
||||||
|
public static final String GCUBE_SCOPE_PARAMETER = "gcube_scope";
|
||||||
|
public static final String RESOLVE_AS_PARAMETER = "res";
|
||||||
|
|
||||||
|
private String itemType;
|
||||||
|
private String itemId;
|
||||||
|
private String gcubeScope;
|
||||||
|
private RESOLVE_AS resolveAs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Enum RESOLVE_AS_PARAMETER.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Mar 28, 2023
|
||||||
|
*/
|
||||||
|
public static enum RESOLVE_AS {
|
||||||
|
PUBLIC("public"), PRIVATE("private");
|
||||||
|
|
||||||
|
String paramValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new resolve as.
|
||||||
|
*
|
||||||
|
* @param paramValue the param value
|
||||||
|
*/
|
||||||
|
RESOLVE_AS(String paramValue) {
|
||||||
|
this.paramValue = paramValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the param value.
|
||||||
|
*
|
||||||
|
* @return the param value
|
||||||
|
*/
|
||||||
|
public String getParamValue() {
|
||||||
|
return paramValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new geoportal resolver query string builder.
|
||||||
|
*
|
||||||
|
* @param itemType the item type
|
||||||
|
* @param itemId the item id
|
||||||
|
*/
|
||||||
|
public GeoportalResolverQueryStringBuilder(String itemType, String itemId) {
|
||||||
|
this.itemType = itemType;
|
||||||
|
this.itemId = itemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scope.
|
||||||
|
*
|
||||||
|
* @param gcubeScope the gcube scope
|
||||||
|
* @return the geoportal resolver query string builder
|
||||||
|
*/
|
||||||
|
public GeoportalResolverQueryStringBuilder scope(String gcubeScope) {
|
||||||
|
this.gcubeScope = gcubeScope;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolver as.
|
||||||
|
*
|
||||||
|
* @param resolveAs the resolve as
|
||||||
|
* @return the geoportal resolver query string builder
|
||||||
|
*/
|
||||||
|
public GeoportalResolverQueryStringBuilder resolverAs(RESOLVE_AS resolveAs) {
|
||||||
|
this.resolveAs = resolveAs;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the item type.
|
||||||
|
*
|
||||||
|
* @return the item type
|
||||||
|
*/
|
||||||
|
public String getItemType() {
|
||||||
|
return itemType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the item id.
|
||||||
|
*
|
||||||
|
* @return the item id
|
||||||
|
*/
|
||||||
|
public String getItemId() {
|
||||||
|
return itemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the gcube scope.
|
||||||
|
*
|
||||||
|
* @return the gcube scope
|
||||||
|
*/
|
||||||
|
public String getGcubeScope() {
|
||||||
|
return gcubeScope;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RESOLVE_AS getResolveAs() {
|
||||||
|
return resolveAs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the query parameters.
|
||||||
|
*
|
||||||
|
* @return the map
|
||||||
|
*/
|
||||||
|
public Map<String, String> buildQueryParameters() {
|
||||||
|
|
||||||
|
GeoportalResolverQueryString crQS = new GeoportalResolverQueryString(this);
|
||||||
|
|
||||||
|
if (crQS.getItemType() == null || crQS.getItemType().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("The " + ITEM_TYPE_PARAMETER + " cannot be null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (crQS.getItemId() == null || crQS.getItemId().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("The " + ITEM_ID_PARAMETER + " cannot be null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (crQS.getGcubeScope() == null || crQS.getGcubeScope().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("The " + GCUBE_SCOPE_PARAMETER + " cannot be null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> query = new HashMap<String, String>();
|
||||||
|
query.put(ITEM_TYPE_PARAMETER, crQS.getItemType());
|
||||||
|
query.put(ITEM_ID_PARAMETER, crQS.getItemId());
|
||||||
|
query.put(GCUBE_SCOPE_PARAMETER, crQS.getGcubeScope());
|
||||||
|
if (crQS.getResolveAs() != null) {
|
||||||
|
query.put(RESOLVE_AS_PARAMETER, crQS.getResolveAs());
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,3 @@
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
import org.gcube.portlets.user.uriresolvermanager.UriResolverManager;
|
|
||||||
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
|
|
||||||
import org.gcube.portlets.user.uriresolvermanager.util.UrlEncoderUtil;
|
import org.gcube.portlets.user.uriresolvermanager.util.UrlEncoderUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -8,8 +8,9 @@ import org.gcube.portlets.user.uriresolvermanager.entity.Resolver;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.entity.ServiceParameter;
|
import org.gcube.portlets.user.uriresolvermanager.entity.ServiceParameter;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException;
|
import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
|
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.CatalogueResolverQueryString.MODERATION_OP;
|
|
||||||
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.CatalogueResolverQueryStringBuilder;
|
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.CatalogueResolverQueryStringBuilder;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.GeoportalResolverQueryStringBuilder;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.GeoportalResolverQueryStringBuilder.RESOLVE_AS;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,7 +20,7 @@ import org.junit.Test;
|
||||||
*/
|
*/
|
||||||
public class UriResolverManagerTest {
|
public class UriResolverManagerTest {
|
||||||
|
|
||||||
// @Test
|
//@Test
|
||||||
public void testUriResolverManger() {
|
public void testUriResolverManger() {
|
||||||
UriResolverManager manager;
|
UriResolverManager manager;
|
||||||
try {
|
try {
|
||||||
|
@ -45,7 +46,7 @@ public class UriResolverManagerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
// @Test
|
||||||
public void testCTLG() {
|
public void testCTLG() {
|
||||||
|
|
||||||
|
@ -68,7 +69,7 @@ public class UriResolverManagerTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
//@Test
|
||||||
public void testCTLGWithQueryString() {
|
public void testCTLGWithQueryString() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -125,6 +126,45 @@ public class UriResolverManagerTest {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//@Test
|
||||||
|
public void testGeoportalCreateLink() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
ScopeProvider.instance.set("/gcube");
|
||||||
|
UriResolverManager resolver;
|
||||||
|
|
||||||
|
String gcubeScope = "/gcube/devsec/devVRE";
|
||||||
|
String itemId = "63d011c4dcac4551b9a6b930";
|
||||||
|
String itemType = "profiledConcessioni";
|
||||||
|
|
||||||
|
resolver = new UriResolverManager("GEO");
|
||||||
|
|
||||||
|
//Method 1
|
||||||
|
// Map<String, String> params = new HashMap<String, String>();
|
||||||
|
// params.put(GeoportalResolverQueryStringBuilder.GCUBE_SCOPE_PARAMETER, gcubeScope);
|
||||||
|
// params.put(GeoportalResolverQueryStringBuilder.ITEM_ID_PARAMETER, itemId);
|
||||||
|
// params.put(GeoportalResolverQueryStringBuilder.ITEM_TYPE_PARAMETER, itemType);
|
||||||
|
// params.put(GeoportalResolverQueryStringBuilder.RESOLVE_AS_PARAMETER, GeoportalResolverQueryStringBuilder.RESOLVE_AS.PUBLIC.getParamValue());
|
||||||
|
|
||||||
|
//Method 2
|
||||||
|
GeoportalResolverQueryStringBuilder builder = new GeoportalResolverQueryStringBuilder(itemType,itemId);
|
||||||
|
builder.scope(gcubeScope);
|
||||||
|
builder.resolverAs(RESOLVE_AS.PUBLIC);
|
||||||
|
//builder.resolverAs(RESOLVE_AS.PRIVATE);
|
||||||
|
Map<String, String> params = builder.buildQueryParameters();
|
||||||
|
|
||||||
|
String shortLink = resolver.getLink(params, true);
|
||||||
|
System.out.println(shortLink);
|
||||||
|
} catch (UriResolverMapException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// @Test IS OK
|
// @Test IS OK
|
||||||
public void testSHUB() {
|
public void testSHUB() {
|
||||||
|
|
Loading…
Reference in New Issue