added method to generate the product url in clear (i.e., not encrypted)
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/ckan-util-library@141262 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
9a07dc0c59
commit
ef000671ee
|
@ -178,10 +178,20 @@ public interface DataCatalogue {
|
|||
/**
|
||||
* Given the id or the name of the dataset it returns its current url by contacting the uri resolver.
|
||||
* If no uri resolver is available, an url that is not guaranteed to be long term valid will be generated.
|
||||
* The information are encoded in the url.
|
||||
* @param datasetId
|
||||
* @return The url of the dataset on success, null otherwise
|
||||
*/
|
||||
String getUrlFromDatasetIdOrName(String datasetIdOrName);
|
||||
|
||||
/**
|
||||
* Given the id or the name of the dataset it returns its current url by contacting the uri resolver.
|
||||
* If no uri resolver is available, an url that is not guaranteed to be long term valid will be generated.
|
||||
* Information are not encrypted.
|
||||
* @param datasetId
|
||||
* @return The url of the dataset on success, null otherwise
|
||||
*/
|
||||
String getUnencryptedUrlFromDatasetIdOrName(String datasetIdOrName);
|
||||
|
||||
/**
|
||||
* Check if this user is a sysadmin. The api key is used to authorize this call.
|
||||
|
|
|
@ -909,7 +909,7 @@ public class DataCatalogueImpl implements DataCatalogue{
|
|||
@Override
|
||||
public String getUrlFromDatasetIdOrName(String datasetIdOrName) {
|
||||
|
||||
logger.debug("Request coming for getting dataset url of dataset with name/id " + datasetIdOrName);
|
||||
logger.debug("Request coming for getting dataset url (encrypted) of dataset with name/id " + datasetIdOrName);
|
||||
|
||||
// checks
|
||||
checkNotNull(datasetIdOrName);
|
||||
|
@ -925,7 +925,37 @@ public class DataCatalogueImpl implements DataCatalogue{
|
|||
if(dataset != null){
|
||||
|
||||
if(getUriResolverUrl() != null)
|
||||
url = getUrlForProduct(CONTEXT, EntityContext.DATASET, name);
|
||||
url = getUrlForProduct(CONTEXT, EntityContext.DATASET, name, true);
|
||||
|
||||
if(url == null || url.isEmpty())
|
||||
url = getPortletUrl() + "?" + URLEncoder.encode("path=/dataset/" + name, "UTF-8");
|
||||
|
||||
}
|
||||
}catch(Exception e){
|
||||
logger.error("Error while retrieving dataset with id/name=" + datasetIdOrName, e);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnencryptedUrlFromDatasetIdOrName(String datasetIdOrName) {
|
||||
logger.debug("Request coming for getting dataset url (not encrypted) of dataset with name/id " + datasetIdOrName);
|
||||
|
||||
// checks
|
||||
checkNotNull(datasetIdOrName);
|
||||
checkArgument(!datasetIdOrName.isEmpty());
|
||||
String url = null;
|
||||
try{
|
||||
|
||||
// get the dataset from name
|
||||
CheckedCkanClient client = new CheckedCkanClient(CKAN_CATALOGUE_URL, CKAN_TOKEN_SYS);
|
||||
CkanDataset dataset = client.getDataset(datasetIdOrName);
|
||||
String name = dataset.getName();
|
||||
|
||||
if(dataset != null){
|
||||
|
||||
if(getUriResolverUrl() != null)
|
||||
url = getUrlForProduct(CONTEXT, EntityContext.DATASET, name, false);
|
||||
|
||||
if(url == null || url.isEmpty())
|
||||
url = getPortletUrl() + "?" + URLEncoder.encode("path=/dataset/" + name, "UTF-8");
|
||||
|
@ -945,7 +975,7 @@ public class DataCatalogueImpl implements DataCatalogue{
|
|||
* @return the url for the product
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private String getUrlForProduct(String context, EntityContext entityContext, String entityName){
|
||||
private String getUrlForProduct(String context, EntityContext entityContext, String entityName, boolean encrypted){
|
||||
|
||||
String toReturn = null;
|
||||
|
||||
|
@ -957,6 +987,7 @@ public class DataCatalogueImpl implements DataCatalogue{
|
|||
requestEntity.put("gcube_scope", context);
|
||||
requestEntity.put("entity_context", entityContext.toString());
|
||||
requestEntity.put("entity_name", entityName);
|
||||
requestEntity.put("clear_url", encrypted);
|
||||
|
||||
StringEntity params = new StringEntity(requestEntity.toJSONString(), ContentType.APPLICATION_JSON);
|
||||
httpPostRequest.setEntity(params);
|
||||
|
|
Loading…
Reference in New Issue