added url of the product to the result set of the methods get-catalogue-id-and-url-from-name (previously known as get-catalogue-id-from-name)
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@140043 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
a2fc076aa4
commit
cd4a2ebe8f
|
@ -63,6 +63,8 @@ public class GrsfPublisherFisheryService {
|
|||
// Logger
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(GrsfPublisherFisheryService.class);
|
||||
|
||||
private static final String PRODUCT_URL_FIELD_KEY = "Product URL";
|
||||
|
||||
@GET
|
||||
@Path("hello")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
|
@ -241,7 +243,7 @@ public class GrsfPublisherFisheryService {
|
|||
|
||||
// add the "Product URL" to the field
|
||||
Map<String, List<String>> addField = new HashMap<String, List<String>>();
|
||||
addField.put("Product URL", Arrays.asList(productUrl));
|
||||
addField.put(PRODUCT_URL_FIELD_KEY, Arrays.asList(productUrl));
|
||||
catalogue.patchProductCustomFields(id, apiKey, addField);
|
||||
|
||||
if(!groups.isEmpty()){
|
||||
|
@ -412,9 +414,9 @@ public class GrsfPublisherFisheryService {
|
|||
}
|
||||
|
||||
@GET
|
||||
@Path("get-catalogue-id-from-name")
|
||||
@Path("get-catalogue-id-and-url-from-name")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getCatalogueIdFromKBID(
|
||||
public Response getCatalogueIdAndUrlFromKBID(
|
||||
@QueryParam("name") String name){
|
||||
|
||||
// retrieve context and username
|
||||
|
@ -436,7 +438,18 @@ public class GrsfPublisherFisheryService {
|
|||
|
||||
CkanDataset dataset = catalogue.getDataset(name, catalogue.getApiKeyFromUsername(username));
|
||||
if(dataset != null){
|
||||
responseBean.setResult(dataset.getId());
|
||||
|
||||
Map<String, String> result = new HashMap<String, String>();
|
||||
result.put("id", dataset.getId());
|
||||
|
||||
// retrieve the product url
|
||||
Map<String, String> customFields = dataset.getExtrasAsHashMap();
|
||||
if(customFields.containsKey(PRODUCT_URL_FIELD_KEY))
|
||||
result.put("url", customFields.get(PRODUCT_URL_FIELD_KEY));
|
||||
else
|
||||
result.put("url", catalogue.getUrlFromDatasetIdOrName(dataset.getId()));
|
||||
|
||||
responseBean.setResult(result);
|
||||
responseBean.setSuccess(true);
|
||||
}else{
|
||||
responseBean.setMessage("Unable to retrieve a catalogue product with name " + name);
|
||||
|
|
|
@ -63,6 +63,8 @@ public class GrsfPublisherStockService {
|
|||
// Logger
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(GrsfPublisherStockService.class);
|
||||
|
||||
private static final String PRODUCT_URL_FIELD_KEY = "Product URL";
|
||||
|
||||
@GET
|
||||
@Path("hello")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
|
@ -231,7 +233,7 @@ public class GrsfPublisherStockService {
|
|||
|
||||
// add the "Product URL" to the field
|
||||
Map<String, List<String>> addField = new HashMap<String, List<String>>();
|
||||
addField.put("Product URL", Arrays.asList(productUrl));
|
||||
addField.put(PRODUCT_URL_FIELD_KEY, Arrays.asList(productUrl));
|
||||
catalogue.patchProductCustomFields(id, apiKey, addField);
|
||||
|
||||
if(!groups.isEmpty()){
|
||||
|
@ -400,9 +402,9 @@ public class GrsfPublisherStockService {
|
|||
}
|
||||
|
||||
@GET
|
||||
@Path("get-catalogue-id-from-name")
|
||||
@Path("get-catalogue-id-and-url-from-name")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getCatalogueIdFromKBID(
|
||||
public Response getCatalogueIdAndUrlFromKBID(
|
||||
@QueryParam("name") String name){
|
||||
|
||||
// retrieve context and username
|
||||
|
@ -425,10 +427,20 @@ public class GrsfPublisherStockService {
|
|||
|
||||
CkanDataset dataset = catalogue.getDataset(name, catalogue.getApiKeyFromUsername(username));
|
||||
if(dataset != null){
|
||||
responseBean.setResult(dataset.getId());
|
||||
|
||||
Map<String, String> result = new HashMap<String, String>();
|
||||
result.put("id", dataset.getId());
|
||||
|
||||
// retrieve the product url
|
||||
Map<String, String> customFields = dataset.getExtrasAsHashMap();
|
||||
if(customFields.containsKey(PRODUCT_URL_FIELD_KEY))
|
||||
result.put("url", customFields.get(PRODUCT_URL_FIELD_KEY));
|
||||
else
|
||||
result.put("url", catalogue.getUrlFromDatasetIdOrName(dataset.getId()));
|
||||
|
||||
responseBean.setResult(result);
|
||||
responseBean.setSuccess(true);
|
||||
}else{
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
responseBean.setMessage("Unable to retrieve a catalogue product with name " + name);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue