feature_23157 #2

Merged
francesco.mangiacrapa merged 5 commits from feature_23157 into master 2022-07-26 14:18:16 +02:00
12 changed files with 596 additions and 75 deletions

View File

@ -3,6 +3,12 @@
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).
## [v1.6.0-SNAPSHOT] - 2022-04-20
**New**
- [#23157] Enhanced to manage the CatalogueResolver with input query string
## [v1.5.0] - 2021-11-05
#### Enhancement

View File

@ -11,7 +11,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>uri-resolver-manager</artifactId>
<version>1.5.0</version>
<version>1.6.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>uri-resolver-manager</name>
<description>The URI Resolver Manager</description>

View File

@ -19,6 +19,7 @@ import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapExcept
import org.gcube.portlets.user.uriresolvermanager.readers.RuntimeResourceReader;
import org.gcube.portlets.user.uriresolvermanager.readers.UriResolverMapReader;
import org.gcube.portlets.user.uriresolvermanager.util.UrlEncoderUtil;
import org.gcube.portlets.user.uriresolvermanager.util.UrlEncoderUtil.URI_PART;
import org.gcube.portlets.user.urlshortener.UrlShortener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -151,8 +152,10 @@ public class UriResolverManager {
/**
* Gets the link.
*
* @param parameters the map of the parameters sent as HTTP query string
* @param shortLink if true the link is shorted otherwise none
* @param parameters the map of the parameters sent as HTTP query
* string
* @param queryStringParameters the query string parameters
* @param shortLink if true the link is shortened otherwise none
* @return the link
* @throws IllegalArgumentException the illegal argument exception
* @throws UriResolverMapException the uri resolver map exception
@ -204,62 +207,65 @@ public class UriResolverManager {
String baseURI = serviceAccessPoint.getServiceUrl();
// SPECIALIZED IMPLEMENTATION OF RESOLVER
try {
link = resolver.getLink(baseURI, parameters);
if (shortLink)
return shortTheLink(link);
LOG.debug("Read specialized getLink: " + link);
if (shortLink) {
link = resolver.shortLink(link, parameters);
}
return link;
} catch (NotImplementedException e) {
LOG.info("Specialized getLink not implemented, going to default implementation");
}
String linkDecoded = null;
String queryString = null;
if (!shortLink) {
// GENERIC IMPLEMENTATION OF RESOLVER. DEFAULT IMPLEMENTATION APPLYING...
if (link == null) {
// not shortening so returning the link with the query string with only the
// parameters encoded
LOG.info("getLink implemented via GET request and encoded query-string");
queryString = UrlEncoderUtil.encodeQuery(parameters);
String toReturn = String.format("%s?%s", baseURI, queryString);
LOG.info("returning link with encoded parameters in the query string: " + toReturn);
return toReturn;
LOG.info("Specialized getLink is null, applying DEFAULT implementation via GET request on base URI and encoded query-string");
String queryString = UrlEncoderUtil.encodeQuery(parameters);
link = String.format("%s?%s", baseURI, queryString);
// LOG.info("returning base URI with encoded parameters in the query string: " +
// linkEncoded);
// return toReturn;
} else {
LOG.info("Specialized getLink is not null");
}
// Not specialized getLink has been implemented
// Short link required
// Going to build the GET request with query string decoded
LOG.info("getLink implemented via GET request and (decoded) query-string");
queryString = UrlEncoderUtil.toQueryString(parameters);
linkDecoded = String.format("%s?%s", baseURI, queryString);
link = linkDecoded;
String linkNotShort = link;
LOG.info("Created HTTP link: " + link);
// Short link required
if (shortLink) {
try {
LOG.info("Short link requested, so encoding query string is required...");
String queryStringEncoded = UrlEncoderUtil.encodeString(queryString);
link = String.format("%s?%s", baseURI, queryStringEncoded);
URI_PART uriParts = UrlEncoderUtil.getURIParts(link);
if (uriParts.getQueryString() != null && !uriParts.getQueryString().isEmpty()) {
LOG.info("QueryString part " + uriParts.getQueryString() + " is not null, encoding it");
String queryStringEncoded = UrlEncoderUtil.encodeString(uriParts.getQueryString());
link = String.format("%s?%s", uriParts.getBaseURI(), queryStringEncoded);
}
LOG.info("Encoded link is: " + link);
LOG.info("Shortner starts..");
String shortedLink = shortTheLink(link);
LOG.info("Shorted link is: " + shortedLink);
if (shortedLink != null && shortedLink.equals(link)) {
String shortenedLink = shortTheLink(link);
if (shortenedLink != null && shortenedLink.equals(link)) {
// 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);
link = linkDecoded;
LOG.info("Short link is equal to long link, returning long link: " + linkNotShort);
link = linkNotShort;
} else {
// here the link is really shorted
LOG.debug("The link is really shorted, returning it");
link = shortedLink;
// here the link is really shortened
LOG.debug("The link is really short, returning it");
link = shortenedLink;
}
} 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
link = linkDecoded;
link = linkNotShort;
}
}
} catch (IllegalArgumentException e) {
@ -270,17 +276,18 @@ public class UriResolverManager {
throw new UriResolverMapException("Uri Resolver error: " + e.getMessage());
}
LOG.info("Returning HTTP(s) link: " + link);
return link;
}
private String shortTheLink(String link) {
private String shortTheLink(String sourceLink) {
String toReturnLink = link;
String toReturnLink = sourceLink;
try {
UrlShortener shortener = new UrlShortener();
String shortedLink = shortener.shorten(link);
LOG.info("Shorted link is: " + shortedLink);
toReturnLink = shortedLink;
String shortLink = shortener.shorten(sourceLink);
LOG.info("Short link is: " + shortLink);
toReturnLink = shortLink;
} catch (Exception e) {
LOG.warn("Returning source link, an error occurred during link shortening: ", e);
}
@ -309,7 +316,7 @@ public class UriResolverManager {
try {
String scope = ScopeProvider.instance.get();
LOG.info("SiscoveryServiceParameters is using scope: " + scope + ", read from ScopeProvider");
LOG.info("DiscoveryServiceParameters is using scope: " + scope + ", read from ScopeProvider");
if (scope == null)
throw new UriResolverMapException("Scope is null, set scope into ScopeProvider!");

View File

@ -64,18 +64,31 @@ public class GenericResolver implements Resolver {
public void setEntryName(String entryName) {
this.entryName = entryName;
}
/**
* Gets the link.
*
* @param baseURI the base URI
* @param baseURI the base URI
* @param parameters the parameters
* @return the link
* @throws Exception the exception
*/
public String getLink(String baseURI, Map<String, String> parameters) throws Exception{
throw new NotImplementedException("getLink Method not Implement");
@Override
public String getLink(String baseURI, Map<String, String> parameters) throws Exception {
throw new NotImplementedException("getLink method not implemented");
}
/**
* 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 {
throw new NotImplementedException("shortLink method not implemented");
}
/**
@ -98,4 +111,5 @@ public class GenericResolver implements Resolver {
builder.append("]");
return builder.toString();
}
}

View File

@ -28,11 +28,21 @@ public interface Resolver {
/**
* Gets the link.
*
* @param baseURI the base URI
* @param baseURI the base URI
* @param parameters the parameters
* @return the link
* @throws Exception the exception
*/
public String getLink(String baseURI, Map<String, String> parameters) throws Exception;
/**
* Short link.
*
* @param theLink the the link
* @param parameters the parameters
* @return the string
* @throws Exception the exception
*/
public String shortLink(String theLink, Map<String, String> parameters) throws Exception;
}

View File

@ -11,6 +11,8 @@ 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;
@ -47,8 +49,8 @@ public class CatalogueResolverCallBuilder extends GenericResolver {
*/
@Override
public String getLink(String baseURI, Map<String, String> parameters) throws Exception {
LOG.debug("called getLink: " + baseURI + " parameters: "+parameters);
LOG.debug("called getLink: " + baseURI + " parameters: " + parameters);
HttpURLConnection con = null;
String theResponse = null;
try {
@ -68,6 +70,11 @@ public class CatalogueResolverCallBuilder extends GenericResolver {
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;
@ -105,6 +112,74 @@ public class CatalogueResolverCallBuilder extends GenericResolver {
}
@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;
}
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.
*

View File

@ -0,0 +1,97 @@
package org.gcube.portlets.user.uriresolvermanager.resolvers.query;
/**
* The Class CatalogueResolverQueryString.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Apr 26, 2022
*/
public class CatalogueResolverQueryString {
/**
* The Enum MODERATION_OP.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Apr 26, 2022
*/
public static enum MODERATION_OP {
show
}
private final String itemName;
private String itemId;
private String itemStatus;
private MODERATION_OP moderation;
/**
* Instantiates a new catalogue resolver query string.
*
* @param builder the builder
*/
CatalogueResolverQueryString(CatalogueResolverQueryStringBuilder builder) {
this.itemName = builder.getItemName();
this.itemId = builder.getItemId();
this.itemStatus = builder.getItemStatus();
this.moderation = builder.getModeration();
}
/**
* Gets the item id.
*
* @return the item id
*/
public String getItemId() {
return itemId;
}
/**
* Gets the moderation.
*
* @return the moderation
*/
public MODERATION_OP getModeration() {
return moderation;
}
/**
* Gets the item name.
*
* @return the item name
*/
public String getItemName() {
return itemName;
}
/**
* Gets the item status.
*
* @return the item status
*/
public String getItemStatus() {
return itemStatus;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("CatalogueResolverQueryString [itemName=");
builder.append(itemName);
builder.append(", itemId=");
builder.append(itemId);
builder.append(", itemStatus=");
builder.append(itemStatus);
builder.append(", moderation=");
builder.append(moderation);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,176 @@
/*
*
*/
package org.gcube.portlets.user.uriresolvermanager.resolvers.query;
import java.util.HashMap;
import java.util.Map;
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.CatalogueResolverQueryString.MODERATION_OP;
import org.gcube.portlets.user.uriresolvermanager.util.UrlEncoderUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class CatalogueResolverQueryStringBuilder.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Apr 26, 2022
*/
public final class CatalogueResolverQueryStringBuilder {
// DEFAULT PARAMETERS
public static final String DEFAULT_STATUS = "pending";
public static final String DEFAULT_MODERATION_OP = MODERATION_OP.show.name();
public static final Logger LOG = LoggerFactory.getLogger(CatalogueResolverQueryStringBuilder.class);
public static final String MODERATION_PARAMETER = "moderation";
public static final String ITEM_NAME_PARAMETER = "item_name";
public static final String ITEM_ID_PARAMETER = "item_id";
public static final String STATUS_PARAMETER = "status";
public static final String QUERY_STRING_PARAMETER = "query_string";
private final String itemName;
private String itemId;
private String itemStatus;
private MODERATION_OP moderation;
/**
* Instantiates a new catalogue resolver query string builder.
*
* @param itemName the item name
*/
public CatalogueResolverQueryStringBuilder(String itemName) {
this.itemName = itemName;
}
/**
* Item id.
*
* @param itemId the item id
* @return the catalogue resolver query string builder
*/
public CatalogueResolverQueryStringBuilder itemId(String itemId) {
this.itemId = itemId;
return this;
}
/**
* Moderation.
*
* @param moderation the moderation
* @return the catalogue resolver query string builder
*/
public CatalogueResolverQueryStringBuilder moderation(MODERATION_OP moderation) {
this.moderation = moderation;
return this;
}
/**
* Item status.
*
* @param itemStatus the item status
* @return the catalogue resolver query string builder
*/
public CatalogueResolverQueryStringBuilder itemStatus(String itemStatus) {
this.itemStatus = itemStatus;
return this;
}
/**
* Gets the item name.
*
* @return the item name
*/
public String getItemName() {
return itemName;
}
/**
* Gets the item id.
*
* @return the item id
*/
public String getItemId() {
return itemId;
}
/**
* Gets the item status.
*
* @return the item status
*/
public String getItemStatus() {
return itemStatus;
}
/**
* Gets the moderation.
*
* @return the moderation
*/
public MODERATION_OP getModeration() {
return moderation;
}
/**
* Builds the query parameters.
*
* @return the map
*/
public Map<String, String> buildQueryParameters() {
CatalogueResolverQueryString crQS = new CatalogueResolverQueryString(this);
if (crQS.getItemName() == null || crQS.getItemName().isEmpty()) {
throw new IllegalArgumentException("The " + ITEM_NAME_PARAMETER + " cannot be null or empty");
}
Map<String, String> query = new HashMap<String, String>();
query.put(ITEM_NAME_PARAMETER, crQS.getItemName());
if (crQS.getItemId() != null) {
query.put(ITEM_ID_PARAMETER, crQS.getItemId());
}
if (crQS.getItemStatus() != null) {
query.put(STATUS_PARAMETER, crQS.getItemStatus());
} else {
query.put(STATUS_PARAMETER, DEFAULT_STATUS);
}
if (crQS.getModeration() != null) {
query.put(MODERATION_PARAMETER, crQS.getModeration().name());
} else {
query.put(MODERATION_PARAMETER, DEFAULT_MODERATION_OP);
}
return query;
}
/**
* Builds the query parameters to query string.
*
* @return the string
*/
public String buildQueryParametersToQueryString() {
Map<String, String> mapParameters = buildQueryParameters();
return UrlEncoderUtil.toQueryString(mapParameters);
}
/**
* Builds the query obj.
*
* @return the catalogue resolver query string
*/
public CatalogueResolverQueryString buildQueryObj() {
return new CatalogueResolverQueryString(this);
}
}

View File

@ -5,13 +5,11 @@ package org.gcube.portlets.user.uriresolvermanager.util;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// TODO: Auto-generated Javadoc
/**
* The Class UrlEncoderUtil.
*
@ -153,22 +151,52 @@ public class UrlEncoderUtil {
return string;
}
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
public static URI_PART getURIParts(String uri) {
// System.out.println(UrlEncoderUtil.encodeQuery("request=GetStyles", "layers=test Name", "service=WMS", "version=1.1.1"));
if (uri == null || uri.isEmpty())
return null;
HashMap<String, String> parameters = new HashMap<String, String>();
String[] uriSections = uri.split("\\?");
if (uriSections.length == 1) {
return new URI_PART(uriSections[0], null);
} else if (uriSections.length == 2) {
return new URI_PART(uriSections[0], uriSections[1]);
}
parameters.put("request", "GetStyles");
parameters.put("layers", "test Name");
parameters.put("version", "1.1.1");
return null;
System.out.println(UrlEncoderUtil.encodeQuery(parameters));
}
public static class URI_PART {
String baseURI;
String queryString;
public URI_PART() {
}
public URI_PART(String baseURI, String queryString) {
this.baseURI = baseURI;
this.queryString = queryString;
}
public String getBaseURI() {
return baseURI;
}
public String getQueryString() {
return queryString;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("URI_PART [baseURI=");
builder.append(baseURI);
builder.append(", queryString=");
builder.append(queryString);
builder.append("]");
return builder.toString();
}
}

1
src/test/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/resources/

View File

@ -1,6 +1,7 @@
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;
/**
*
@ -15,23 +16,54 @@ public class UriResolverManagerMain {
public static void main(String[] args) {
try {
ScopeProvider.instance.set("/gcube");
UriResolverManager resolver = new UriResolverManager("GIS");
System.out.println(resolver.getCapabilities());
System.out.println(resolver.getApplicationTypes());
String theLink = "https://data.dev.d4science.org/ctlg/devVRE/sarda-sarda";
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);
}
System.out.println(theLink);
// ScopeProvider.instance.set("/gcube");
// UriResolverManager resolver = new UriResolverManager("GIS");
// System.out.println(resolver.getCapabilities());
// System.out.println(resolver.getApplicationTypes());
// System.out.println(resolver.discoveryServiceParameters(resolver.getResolver("SMP-ID")));
// Map<String, String> params = new HashMap<String, String>();
// params.put("gis-UUID", "5ac49f44-999f-4efe-a32b-af71da2b39ac");
// params.put("scope", "/gcube/devsec/devVRE");
// String shortLink = resolver.getLink(params, true);
// System.out.println(shortLink); //true, link is shorted otherwise none
} catch (UriResolverMapException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
}catch (Exception e) {
//// System.out.println(shortLink); //true, link is shorted otherwise none
// } catch (UriResolverMapException e) {
// e.printStackTrace();
// } catch (IllegalArgumentException e) {
// e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* The main method.
*
* @param args the arguments
*/
// public static void main(String[] args) {
//
//// System.out.println(UrlEncoderUtil.encodeQuery("request=GetStyles", "layers=test Name", "service=WMS", "version=1.1.1"));
//
// HashMap<String, String> parameters = new HashMap<String, String>();
//
// parameters.put("request", "GetStyles");
// parameters.put("layers", "test Name");
// parameters.put("version", "1.1.1");
//
// System.out.println(UrlEncoderUtil.encodeQuery(parameters));
//
// }
}

View File

@ -1,10 +1,16 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.uriresolvermanager.UriResolverManager;
import org.gcube.portlets.user.uriresolvermanager.entity.Resolver;
import org.gcube.portlets.user.uriresolvermanager.entity.ServiceParameter;
import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException;
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.junit.Test;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
@ -19,14 +25,23 @@ public class UriResolverManagerTest {
try {
ScopeProvider.instance.set("/gcube/devsec/devVRE");
manager = new UriResolverManager();
System.out.println(manager.getCapabilities());
System.out.println(manager.getApplicationTypes());
System.out.println("Capabiities: " + manager.getCapabilities());
System.out.println("ApplicationTypes: " + manager.getApplicationTypes());
for (String applicationType : manager.getApplicationTypes()) {
Resolver resolver = manager.getResolver(applicationType);
System.out.println("ApplicationType: " + applicationType + " has: " + resolver);
List<ServiceParameter> serviceParameters = manager.discoveryServiceParameters(resolver);
System.out.println("Parameters: " + serviceParameters);
}
} catch (UriResolverMapException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@ -54,6 +69,64 @@ public class UriResolverManagerTest {
}
// @Test
public void testCTLGWithQueryString() {
try {
ScopeProvider.instance.set("/gcube/devsec/devVRE");
UriResolverManager resolver;
resolver = new UriResolverManager("CTLG");
Map<String, String> params = new HashMap<String, String>();
params.put("gcube_scope", "/gcube/devsec/devVRE");
params.put("entity_context", "dataset");
params.put("entity_name", "sarda-sarda");
params.put("query_string", "param1=value1&parm2=value2");
// METHOD 1 - Query String as parameter of the getLink method
String shortLink = resolver.getLink(params, true);
// METHOD 2 - Query String as parameter passed in the params
// String queryString = QueryStringUtil.toQueryString(queryStringParameters);
// params.put(CatalogueResolverQueryStringBuilder.QUERY_STRING_PARAMETER, queryString);
System.out.println(shortLink);
} catch (UriResolverMapException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
//@Test
public void testCTLGGenerateLinkForModeration() {
try {
ScopeProvider.instance.set("/gcube/devsec/devVRE");
UriResolverManager resolver;
resolver = new UriResolverManager("CTLG");
Map<String, String> params = new HashMap<String, String>();
params.put("gcube_scope", "/gcube/devsec/devVRE");
params.put("entity_context", "organization");
params.put("entity_name", "devvre");
CatalogueResolverQueryStringBuilder builder = new CatalogueResolverQueryStringBuilder(
"test-moderation-1649068829317");
//builder.itemStatus("approved").moderation(MODERATION_OP.show);
String queryString = builder.buildQueryParametersToQueryString();
params.put(CatalogueResolverQueryStringBuilder.QUERY_STRING_PARAMETER, queryString);
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
public void testSHUB() {
try {
@ -78,12 +151,14 @@ public class UriResolverManagerTest {
public void testGIS() {
try {
ScopeProvider.instance.set("/pred4s/preprod/preVRE");
String scope = "/pred4s/preprod/preVRE";
String UUID = "da165110-88fd-11da-a88f-000d939bc5d8";
ScopeProvider.instance.set(scope);
UriResolverManager resolver = new UriResolverManager("GIS");
Map<String, String> params = new HashMap<String, String>();
params.put("gis-UUID", "1a657005-29c6-4528-a115-69640c4c2900");
params.put("scope", "/pred4s/preprod/preVRE");
String shortLink = resolver.getLink(params, false);
params.put("gis-UUID", UUID);
params.put("scope", scope);
String shortLink = resolver.getLink(params, true);
System.out.println(shortLink);
} catch (UriResolverMapException e) {
e.printStackTrace();