minor fix for getProductUrl method

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/ckan-util-library@139751 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-12-07 10:22:48 +00:00
parent 0ccf090e14
commit 5d8ec1875a
2 changed files with 14 additions and 11 deletions

View File

@ -913,7 +913,7 @@ public class DataCatalogueImpl implements DataCatalogue{
// checks
checkNotNull(datasetIdOrName);
checkArgument(!datasetIdOrName.isEmpty());
String url = null;
try{
// get the dataset from name
@ -922,20 +922,18 @@ public class DataCatalogueImpl implements DataCatalogue{
String name = dataset.getName();
if(dataset != null){
String url = null;
if(getUriResolverUrl() != null)
url = getUrlForProduct(validForContext, EntityContext.DATASET, name);
if(url == null)
return getPortletUrl() + "?" + URLEncoder.encode("path=/dataset/" + name, "UTF-8");
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 null;
return url;
}
/**
@ -966,8 +964,8 @@ public class DataCatalogueImpl implements DataCatalogue{
if(response.getStatusLine().getStatusCode() != 200)
throw new Exception("There was an error while creating an url " + response.getStatusLine());
String result = EntityUtils.toString(response.getEntity());
logger.debug("Result is " + result);
toReturn = EntityUtils.toString(response.getEntity());
logger.debug("Result is " + toReturn);
}catch(Exception e){
logger.error("Failed to get an url for this product", e);

View File

@ -15,6 +15,8 @@ import org.gcube.datacatalogue.ckanutillibrary.models.CkanDatasetRelationship;
import org.gcube.datacatalogue.ckanutillibrary.models.DatasetRelationships;
import org.gcube.datacatalogue.ckanutillibrary.models.RolesCkanGroupOrOrg;
import org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.LoggerFactory;
import eu.trentorise.opendata.jackan.CheckedCkanClient;
@ -37,16 +39,19 @@ public class TestDataCatalogueLib {
String subjectId = "aa_father4";
String objectId = "bb_son4";
// @Before
public void before(){
@Before
public void before() throws Exception{
factory = DataCatalogueFactory.getFactory();
}
//@Test
@Test
public void testManageProduct() throws Exception{
DataCatalogueImpl catalogue = factory.getUtilsPerScope(scope);
logger.debug("Manage product is " + catalogue.isManageProductEnabled());
String url = catalogue.getUrlFromDatasetIdOrName("test_with_duplicated_keys");
logger.debug("Url is " + url);
}