added methods to retrieve a catalogue identifier, given the product name (i.e., the knowledge base identifier)
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@139858 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
928b6dbabc
commit
01b08a10ba
|
@ -19,6 +19,7 @@ import javax.ws.rs.POST;
|
|||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
@ -171,7 +172,7 @@ public class GrsfPublisherFisheryService {
|
|||
|
||||
// set the type
|
||||
record.setProductType(Product_Type.FISHERY.getOrigName());
|
||||
|
||||
|
||||
// product system type is a list of values for sources records, so remove it (so that no group is generated)
|
||||
if(!sourceInPath.equals(Sources.GRSF))
|
||||
record.setProductionSystemType(null);
|
||||
|
@ -368,7 +369,6 @@ public class GrsfPublisherFisheryService {
|
|||
|
||||
@GET
|
||||
@Path("get-fisheries-ids")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getFisheriesIds(
|
||||
@PathParam("source") String source){
|
||||
|
@ -418,4 +418,51 @@ public class GrsfPublisherFisheryService {
|
|||
return Response.status(status).entity(responseBean).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("get-catalogue-id-from-name")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getCatalogueIdFromKBID(
|
||||
@QueryParam("name") String name){
|
||||
|
||||
// retrieve context and username
|
||||
String context = ScopeProvider.instance.get();
|
||||
Caller caller = AuthorizationProvider.instance.get();
|
||||
String username = caller.getClient().getId();
|
||||
|
||||
ResponseBean responseBean = new ResponseBean();
|
||||
Status status = Status.INTERNAL_SERVER_ERROR;
|
||||
|
||||
logger.info("Received call to get the catalogue identifier for the product with name " + name);
|
||||
|
||||
try{
|
||||
|
||||
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
||||
if(catalogue == null){
|
||||
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
throw new Exception("There was a problem while serving your request");
|
||||
|
||||
}
|
||||
|
||||
CkanDataset dataset = catalogue.getDataset(name, catalogue.getApiKeyFromUsername(username));
|
||||
if(dataset != null){
|
||||
responseBean.setResult(dataset.getId());
|
||||
responseBean.setSuccess(true);
|
||||
}else{
|
||||
responseBean.setResult(null);
|
||||
responseBean.setSuccess(false);
|
||||
responseBean.setMessage("Unable to retrieve a catalogue product with name " + name);
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Failed to retrieve this product", e);
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
responseBean.setSuccess(false);
|
||||
responseBean.setMessage(e.getMessage());
|
||||
}
|
||||
|
||||
return Response.status(status).entity(responseBean).build();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import javax.ws.rs.POST;
|
|||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
@ -361,7 +362,6 @@ public class GrsfPublisherStockService {
|
|||
|
||||
@GET
|
||||
@Path("get-stocks-ids")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getStocksIds(
|
||||
@PathParam("source") String source){
|
||||
|
@ -411,5 +411,51 @@ public class GrsfPublisherStockService {
|
|||
|
||||
return Response.status(status).entity(responseBean).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("get-catalogue-id-from-name")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getCatalogueIdFromKBID(
|
||||
@QueryParam("name") String name){
|
||||
|
||||
// retrieve context and username
|
||||
String context = ScopeProvider.instance.get();
|
||||
Caller caller = AuthorizationProvider.instance.get();
|
||||
String username = caller.getClient().getId();
|
||||
|
||||
ResponseBean responseBean = new ResponseBean();
|
||||
Status status = Status.INTERNAL_SERVER_ERROR;
|
||||
|
||||
logger.info("Received call to get the catalogue identifier for the product with name " + name);
|
||||
|
||||
try{
|
||||
|
||||
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
||||
if(catalogue == null){
|
||||
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
throw new Exception("There was a problem while serving your request");
|
||||
|
||||
}
|
||||
|
||||
CkanDataset dataset = catalogue.getDataset(name, catalogue.getApiKeyFromUsername(username));
|
||||
if(dataset != null){
|
||||
responseBean.setResult(dataset.getId());
|
||||
responseBean.setSuccess(true);
|
||||
}else{
|
||||
responseBean.setResult(null);
|
||||
responseBean.setSuccess(false);
|
||||
responseBean.setMessage("Unable to retrieve a catalogue product with name " + name);
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Failed to retrieve this product", e);
|
||||
status = Status.INTERNAL_SERVER_ERROR;
|
||||
responseBean.setSuccess(false);
|
||||
responseBean.setMessage(e.getMessage());
|
||||
}
|
||||
|
||||
return Response.status(status).entity(responseBean).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue