improved comments
This commit is contained in:
parent
e2da9ddb2f
commit
ac7873cd30
|
@ -220,14 +220,15 @@ public class UriResolverManager {
|
|||
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) {
|
||||
// not shortening so returning the link with the query string with only the
|
||||
// parameters encoded
|
||||
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);
|
||||
// LOG.info("returning base URI with encoded parameters in the query string: " +
|
||||
// linkEncoded);
|
||||
// return toReturn;
|
||||
} else {
|
||||
LOG.info("Specialized getLink is not null");
|
||||
|
@ -241,17 +242,19 @@ public class UriResolverManager {
|
|||
LOG.info("Short link requested, so encoding query string is required...");
|
||||
|
||||
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 shortenedLink = shortTheLink(link);
|
||||
LOG.info("Short link is: " + shortenedLink);
|
||||
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 long link, returning long link: " + linkNotShort);
|
||||
LOG.info("Short link is equal to long link, returning long link: " + linkNotShort);
|
||||
link = linkNotShort;
|
||||
} else {
|
||||
// here the link is really shortened
|
||||
|
@ -277,14 +280,14 @@ public class UriResolverManager {
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -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.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;
|
||||
|
||||
/**
|
||||
|
@ -80,8 +79,36 @@ public class UriResolverManagerTest {
|
|||
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);
|
||||
|
||||
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);
|
||||
String queryString = builder.buildQueryParametersToQueryString();
|
||||
params.put(CatalogueResolverQueryStringBuilder.QUERY_STRING_PARAMETER, queryString);
|
||||
|
@ -122,7 +149,7 @@ public class UriResolverManagerTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
//@Test
|
||||
public void testGIS() {
|
||||
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue