#23157 CatalogueResolver enhancement
This commit is contained in:
parent
f124c6ea36
commit
350d97dd75
|
@ -3,6 +3,12 @@
|
||||||
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.6.0-SNAPSHOT] - 2022-04-20
|
||||||
|
|
||||||
|
**New**
|
||||||
|
|
||||||
|
- [#23157] Enhanced to manage the CatalogueResolver with input query string
|
||||||
|
|
||||||
## [v1.5.0] - 2021-11-05
|
## [v1.5.0] - 2021-11-05
|
||||||
|
|
||||||
#### Enhancement
|
#### Enhancement
|
||||||
|
|
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.5.0</version>
|
<version>1.6.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>
|
||||||
|
|
|
@ -151,8 +151,10 @@ public class UriResolverManager {
|
||||||
/**
|
/**
|
||||||
* Gets the link.
|
* Gets the link.
|
||||||
*
|
*
|
||||||
* @param parameters the map of the parameters sent as HTTP query string
|
* @param parameters the map of the parameters sent as HTTP query
|
||||||
* @param shortLink if true the link is shorted otherwise none
|
* string
|
||||||
|
* @param queryStringParameters the query string parameters
|
||||||
|
* @param shortLink if true the link is shortened otherwise none
|
||||||
* @return the link
|
* @return the link
|
||||||
* @throws IllegalArgumentException the illegal argument exception
|
* @throws IllegalArgumentException the illegal argument exception
|
||||||
* @throws UriResolverMapException the uri resolver map exception
|
* @throws UriResolverMapException the uri resolver map exception
|
||||||
|
@ -204,16 +206,20 @@ public class UriResolverManager {
|
||||||
|
|
||||||
String baseURI = serviceAccessPoint.getServiceUrl();
|
String baseURI = serviceAccessPoint.getServiceUrl();
|
||||||
|
|
||||||
|
//SPECIALIZED IMPLEMENTATION OF RESOLVER
|
||||||
try {
|
try {
|
||||||
link = resolver.getLink(baseURI, parameters);
|
link = resolver.getLink(baseURI, parameters);
|
||||||
if (shortLink)
|
LOG.debug("Read specialized getLink: "+link);
|
||||||
return shortTheLink(link);
|
if (shortLink) {
|
||||||
|
link = resolver.shortLink(link, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
return link;
|
return link;
|
||||||
} catch (NotImplementedException e) {
|
} catch (NotImplementedException e) {
|
||||||
LOG.info("Specialized getLink not implemented, going to default implementation");
|
LOG.info("Specialized getLink not implemented, going to default implementation");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//GENERIC IMPLEMENTATION OF RESOLVER
|
||||||
String linkDecoded = null;
|
String linkDecoded = null;
|
||||||
String queryString = null;
|
String queryString = null;
|
||||||
|
|
||||||
|
@ -242,9 +248,9 @@ public class UriResolverManager {
|
||||||
link = String.format("%s?%s", baseURI, queryStringEncoded);
|
link = String.format("%s?%s", baseURI, queryStringEncoded);
|
||||||
LOG.info("Encoded link is: " + link);
|
LOG.info("Encoded link is: " + link);
|
||||||
LOG.info("Shortner starts..");
|
LOG.info("Shortner starts..");
|
||||||
String shortedLink = shortTheLink(link);
|
String shortenedLink = shortTheLink(link);
|
||||||
LOG.info("Shorted link is: " + shortedLink);
|
LOG.info("Short link is: " + shortenedLink);
|
||||||
if (shortedLink != null && shortedLink.equals(link)) {
|
if (shortenedLink != null && shortenedLink.equals(link)) {
|
||||||
// here the short link and the input link are identical
|
// here the short link and the input link are identical
|
||||||
// so the shortening did not work
|
// so the shortening did not work
|
||||||
// I'm returning the decoded link because it is directly consumable via browser
|
// I'm returning the decoded link because it is directly consumable via browser
|
||||||
|
@ -253,7 +259,7 @@ public class UriResolverManager {
|
||||||
} else {
|
} else {
|
||||||
// here the link is really shorted
|
// here the link is really shorted
|
||||||
LOG.debug("The link is really shorted, returning it");
|
LOG.debug("The link is really shorted, returning it");
|
||||||
link = shortedLink;
|
link = shortenedLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -309,7 +315,7 @@ public class UriResolverManager {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String scope = ScopeProvider.instance.get();
|
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)
|
if (scope == null)
|
||||||
throw new UriResolverMapException("Scope is null, set scope into ScopeProvider!");
|
throw new UriResolverMapException("Scope is null, set scope into ScopeProvider!");
|
||||||
|
|
|
@ -64,18 +64,31 @@ public class GenericResolver implements Resolver {
|
||||||
public void setEntryName(String entryName) {
|
public void setEntryName(String entryName) {
|
||||||
this.entryName = entryName;
|
this.entryName = entryName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the link.
|
* Gets the link.
|
||||||
*
|
*
|
||||||
* @param baseURI the base URI
|
* @param baseURI the base URI
|
||||||
* @param parameters the parameters
|
* @param parameters the parameters
|
||||||
* @return the link
|
* @return the link
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public String getLink(String baseURI, Map<String, String> parameters) throws Exception{
|
@Override
|
||||||
throw new NotImplementedException("getLink Method not Implement");
|
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("]");
|
builder.append("]");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,11 +28,21 @@ public interface Resolver {
|
||||||
/**
|
/**
|
||||||
* Gets the link.
|
* Gets the link.
|
||||||
*
|
*
|
||||||
* @param baseURI the base URI
|
* @param baseURI the base URI
|
||||||
* @param parameters the parameters
|
* @param parameters the parameters
|
||||||
* @return the link
|
* @return the link
|
||||||
* @throws Exception the exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public String getLink(String baseURI, Map<String, String> parameters) throws 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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,9 @@ import java.net.URL;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.portlets.user.uriresolvermanager.entity.GenericResolver;
|
import org.gcube.portlets.user.uriresolvermanager.entity.GenericResolver;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.CatalogueResolverQueryStringBuilder;
|
||||||
|
import org.gcube.portlets.user.uriresolvermanager.util.UrlEncoderUtil;
|
||||||
|
import org.gcube.portlets.user.urlshortener.UrlShortener;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -47,8 +50,8 @@ public class CatalogueResolverCallBuilder extends GenericResolver {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getLink(String baseURI, Map<String, String> parameters) throws Exception {
|
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;
|
HttpURLConnection con = null;
|
||||||
String theResponse = null;
|
String theResponse = null;
|
||||||
try {
|
try {
|
||||||
|
@ -68,6 +71,11 @@ public class CatalogueResolverCallBuilder extends GenericResolver {
|
||||||
jObj.put(key, parameters.get(key));
|
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();
|
String toJSON = jObj.toString();
|
||||||
LOG.info("Submitting JSON: " + toJSON);
|
LOG.info("Submitting JSON: " + toJSON);
|
||||||
Integer code = null;
|
Integer code = null;
|
||||||
|
@ -105,6 +113,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.
|
* Read response.
|
||||||
*
|
*
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,167 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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 {
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
Map<String, String> query = new HashMap<String, String>();
|
||||||
|
|
||||||
|
if (crQS.getItemId() != null) {
|
||||||
|
query.put(ITEM_ID_PARAMETER, crQS.getItemId());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (crQS.getItemName() != null) {
|
||||||
|
query.put(ITEM_NAME_PARAMETER, crQS.getItemName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (crQS.getItemStatus() != null) {
|
||||||
|
query.put(STATUS_PARAMETER, crQS.getItemStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (crQS.getModeration() != null) {
|
||||||
|
query.put(MODERATION_PARAMETER, crQS.getModeration().name());
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -5,13 +5,12 @@ package org.gcube.portlets.user.uriresolvermanager.util;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
// TODO: Auto-generated Javadoc
|
|
||||||
/**
|
/**
|
||||||
* The Class UrlEncoderUtil.
|
* The Class UrlEncoderUtil.
|
||||||
*
|
*
|
||||||
|
@ -153,23 +152,5 @@ public class UrlEncoderUtil {
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
/resources/
|
|
@ -1,6 +1,7 @@
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.UriResolverManager;
|
import org.gcube.portlets.user.uriresolvermanager.UriResolverManager;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
|
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) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
ScopeProvider.instance.set("/gcube");
|
|
||||||
UriResolverManager resolver = new UriResolverManager("GIS");
|
String theLink = "https://data.dev.d4science.org/ctlg/devVRE/sarda-sarda";
|
||||||
System.out.println(resolver.getCapabilities());
|
String[] queryStringArray = theLink.split("\\?");
|
||||||
System.out.println(resolver.getApplicationTypes());
|
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")));
|
// System.out.println(resolver.discoveryServiceParameters(resolver.getResolver("SMP-ID")));
|
||||||
|
|
||||||
// Map<String, String> params = new HashMap<String, String>();
|
// Map<String, String> params = new HashMap<String, String>();
|
||||||
// params.put("gis-UUID", "5ac49f44-999f-4efe-a32b-af71da2b39ac");
|
// params.put("gis-UUID", "5ac49f44-999f-4efe-a32b-af71da2b39ac");
|
||||||
// params.put("scope", "/gcube/devsec/devVRE");
|
// params.put("scope", "/gcube/devsec/devVRE");
|
||||||
// String shortLink = resolver.getLink(params, true);
|
// String shortLink = resolver.getLink(params, true);
|
||||||
// System.out.println(shortLink); //true, link is shorted otherwise none
|
//// System.out.println(shortLink); //true, link is shorted otherwise none
|
||||||
} catch (UriResolverMapException e) {
|
// } catch (UriResolverMapException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
} catch (IllegalArgumentException e) {
|
// } catch (IllegalArgumentException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
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));
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.portlets.user.uriresolvermanager.UriResolverManager;
|
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.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.util.UrlEncoderUtil;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
@ -19,19 +26,28 @@ public class UriResolverManagerTest {
|
||||||
try {
|
try {
|
||||||
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
||||||
manager = new UriResolverManager();
|
manager = new UriResolverManager();
|
||||||
System.out.println(manager.getCapabilities());
|
System.out.println("Capabiities: " + manager.getCapabilities());
|
||||||
System.out.println(manager.getApplicationTypes());
|
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) {
|
} catch (UriResolverMapException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
//@Test
|
||||||
public void testCTLG() {
|
public void testCTLG() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -53,7 +69,39 @@ public class UriResolverManagerTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
//@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");
|
||||||
|
|
||||||
|
CatalogueResolverQueryStringBuilder builder = new CatalogueResolverQueryStringBuilder("sarda-sarda");
|
||||||
|
builder.itemStatus("pending").moderation(MODERATION_OP.show);
|
||||||
|
String queryString = builder.buildQueryParametersToQueryString();
|
||||||
|
params.put(CatalogueResolverQueryStringBuilder.QUERY_STRING_PARAMETER, queryString);
|
||||||
|
// 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 testSHUB() {
|
public void testSHUB() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -74,16 +122,16 @@ public class UriResolverManagerTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
//@Test
|
||||||
public void testGIS() {
|
public void testGIS() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ScopeProvider.instance.set("/pred4s/preprod/preVRE");
|
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
||||||
UriResolverManager resolver = new UriResolverManager("GIS");
|
UriResolverManager resolver = new UriResolverManager("GIS");
|
||||||
Map<String, String> params = new HashMap<String, String>();
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
params.put("gis-UUID", "1a657005-29c6-4528-a115-69640c4c2900");
|
params.put("gis-UUID", "1a657005-29c6-4528-a115-69640c4c2900");
|
||||||
params.put("scope", "/pred4s/preprod/preVRE");
|
params.put("scope", "/gcube/devsec/devVRE");
|
||||||
String shortLink = resolver.getLink(params, false);
|
String shortLink = resolver.getLink(params, true);
|
||||||
System.out.println(shortLink);
|
System.out.println(shortLink);
|
||||||
} catch (UriResolverMapException e) {
|
} catch (UriResolverMapException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
Loading…
Reference in New Issue