You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gcat/src/main/java/org/gcube/gcat/utils/URIResolver.java

50 lines
1.6 KiB
Java

package org.gcube.gcat.utils;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
import org.gcube.datacatalogue.ckanutillibrary.server.utils.url.EntityContext;
import org.gcube.gcat.persistence.ckan.CKAN;
import org.gcube.gcat.utils.HTTPCall.HTTPMETHOD;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
public class URIResolver {
private static final String CATALOGUE_CONTEXT = "gcube_scope";
private static final String ENTITY_TYPE = "entity_context";
private static final String ENTITY_NAME = "entity_name";
private static final String CATALOGUE_PLAIN_URL = "clear_url";
protected ObjectMapper objectMapper;
public URIResolver() {
this.objectMapper = new ObjectMapper();
}
public String getCatalogueItemURL(String name) {
try {
DataCatalogue dataCatalogue = CKAN.getCatalogue();
String uriResolverURL = dataCatalogue.getUriResolverUrl();
HTTPCall httpCall = new HTTPCall(uriResolverURL);
ObjectNode requestContent = objectMapper.createObjectNode();
requestContent.put(CATALOGUE_CONTEXT, ContextUtility.getCurrentContext());
requestContent.put(ENTITY_TYPE, EntityContext.PRODUCT.toString());
requestContent.put(ENTITY_NAME, name);
requestContent.put(CATALOGUE_PLAIN_URL, true);
String url = httpCall.call("", HTTPMETHOD.POST, objectMapper.writeValueAsString(requestContent),
MediaType.APPLICATION_JSON);
return url;
} catch(Exception e) {
throw new WebApplicationException(e);
}
}
}