improved comments
This commit is contained in:
parent
e2da9ddb2f
commit
ac7873cd30
|
@ -220,38 +220,41 @@ public class UriResolverManager {
|
||||||
LOG.info("Specialized getLink not implemented, going to default implementation");
|
LOG.info("Specialized getLink not implemented, going to default implementation");
|
||||||
}
|
}
|
||||||
|
|
||||||
//GENERIC IMPLEMENTATION OF RESOLVER. DEFAULT IMPLEMENTATION APPLYING
|
// GENERIC IMPLEMENTATION OF RESOLVER. DEFAULT IMPLEMENTATION APPLYING...
|
||||||
if (link == null) {
|
if (link == null) {
|
||||||
// not shortening so returning the link with the query string with only the
|
// not shortening so returning the link with the query string with only the
|
||||||
// parameters encoded
|
// parameters encoded
|
||||||
LOG.info("Specialized getLink is null, applying DEFAULT implementation via GET request on base URI and encoded query-string");
|
LOG.info("Specialized getLink is null, applying DEFAULT implementation via GET request on base URI and encoded query-string");
|
||||||
String queryString = UrlEncoderUtil.encodeQuery(parameters);
|
String queryString = UrlEncoderUtil.encodeQuery(parameters);
|
||||||
link = String.format("%s?%s", baseURI, queryString);
|
link = String.format("%s?%s", baseURI, queryString);
|
||||||
//LOG.info("returning base URI with encoded parameters in the query string: " + linkEncoded);
|
// LOG.info("returning base URI with encoded parameters in the query string: " +
|
||||||
//return toReturn;
|
// linkEncoded);
|
||||||
}else {
|
// return toReturn;
|
||||||
|
} else {
|
||||||
LOG.info("Specialized getLink is not null");
|
LOG.info("Specialized getLink is not null");
|
||||||
}
|
}
|
||||||
|
|
||||||
String linkNotShort = link;
|
String linkNotShort = link;
|
||||||
LOG.info("Created HTTP link: " + link);
|
LOG.info("Created HTTP link: " + link);
|
||||||
// Short link required
|
// Short link required
|
||||||
if (shortLink) {
|
if (shortLink) {
|
||||||
try {
|
try {
|
||||||
LOG.info("Short link requested, so encoding query string is required...");
|
LOG.info("Short link requested, so encoding query string is required...");
|
||||||
|
|
||||||
URI_PART uriParts = UrlEncoderUtil.getURIParts(link);
|
URI_PART uriParts = UrlEncoderUtil.getURIParts(link);
|
||||||
String queryStringEncoded = UrlEncoderUtil.encodeString(uriParts.getQueryString());
|
if (uriParts.getQueryString() != null && !uriParts.getQueryString().isEmpty()) {
|
||||||
link = String.format("%s?%s", uriParts.getBaseURI(), queryStringEncoded);
|
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("Encoded link is: " + link);
|
||||||
LOG.info("Shortner starts..");
|
LOG.info("Shortner starts..");
|
||||||
String shortenedLink = shortTheLink(link);
|
String shortenedLink = shortTheLink(link);
|
||||||
LOG.info("Short link is: " + shortenedLink);
|
|
||||||
if (shortenedLink != null && shortenedLink.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
|
||||||
LOG.debug("Shorted link is equal to long link, returning long link: " + linkNotShort);
|
LOG.info("Short link is equal to long link, returning long link: " + linkNotShort);
|
||||||
link = linkNotShort;
|
link = linkNotShort;
|
||||||
} else {
|
} else {
|
||||||
// here the link is really shortened
|
// here the link is really shortened
|
||||||
|
@ -272,19 +275,19 @@ public class UriResolverManager {
|
||||||
LOG.error("Uri Resolver Exception: ", e);
|
LOG.error("Uri Resolver Exception: ", e);
|
||||||
throw new UriResolverMapException("Uri Resolver error: " + e.getMessage());
|
throw new UriResolverMapException("Uri Resolver error: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.info("Returning HTTP(s) link: " + link);
|
LOG.info("Returning HTTP(s) link: " + link);
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String shortTheLink(String link) {
|
private String shortTheLink(String sourceLink) {
|
||||||
|
|
||||||
String toReturnLink = link;
|
String toReturnLink = sourceLink;
|
||||||
try {
|
try {
|
||||||
UrlShortener shortener = new UrlShortener();
|
UrlShortener shortener = new UrlShortener();
|
||||||
String shortedLink = shortener.shorten(link);
|
String shortLink = shortener.shorten(sourceLink);
|
||||||
LOG.info("Shorted link is: " + shortedLink);
|
LOG.info("Short link is: " + shortLink);
|
||||||
toReturnLink = shortedLink;
|
toReturnLink = shortLink;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.warn("Returning source link, an error occurred during link shortening: ", e);
|
LOG.warn("Returning source link, an error occurred during link shortening: ", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentExcep
|
||||||
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.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.util.UrlEncoderUtil;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,7 +68,7 @@ public class UriResolverManagerTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
//@Test
|
||||||
public void testCTLGWithQueryString() {
|
public void testCTLGWithQueryString() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -80,8 +79,36 @@ public class UriResolverManagerTest {
|
||||||
params.put("gcube_scope", "/gcube/devsec/devVRE");
|
params.put("gcube_scope", "/gcube/devsec/devVRE");
|
||||||
params.put("entity_context", "dataset");
|
params.put("entity_context", "dataset");
|
||||||
params.put("entity_name", "sarda-sarda");
|
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);
|
||||||
|
|
||||||
CatalogueResolverQueryStringBuilder builder = new CatalogueResolverQueryStringBuilder("sarda-sarda");
|
// 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 testCTLGGeneratLinkForModeration() {
|
||||||
|
|
||||||
|
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("devVRE");
|
||||||
builder.itemStatus("pending").moderation(MODERATION_OP.show);
|
builder.itemStatus("pending").moderation(MODERATION_OP.show);
|
||||||
String queryString = builder.buildQueryParametersToQueryString();
|
String queryString = builder.buildQueryParametersToQueryString();
|
||||||
params.put(CatalogueResolverQueryStringBuilder.QUERY_STRING_PARAMETER, queryString);
|
params.put(CatalogueResolverQueryStringBuilder.QUERY_STRING_PARAMETER, queryString);
|
||||||
|
@ -122,7 +149,7 @@ public class UriResolverManagerTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
//@Test
|
||||||
public void testGIS() {
|
public void testGIS() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue