added methods to retrieve products of type stock/fishery for the different sources. At most 1000 datasets'ids are returned

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@139725 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-12-06 16:06:51 +00:00
parent d3f3eeddd9
commit d409a4dd10
2 changed files with 119 additions and 14 deletions

View File

@ -27,10 +27,10 @@ import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.library.utils.Caller;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.Common;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.DeleteProductBean;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.FisheryRecord;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.RefersToBean;
import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseBean;
import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseCreationBean;
import org.gcube.data_catalogue.grsf_publish_ws.utils.HelperMethods;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Product_Type;
@ -164,7 +164,7 @@ public class GrsfPublisherFisheryService {
+ " The current Manage context is " + (String)contextServlet.getInitParameter(HelperMethods.MANAGE_CONTEX_KEY)
+ " The current Public context is " + (String)contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY)
);
if(contextFromStatus.equals(HelperMethods.MANAGE_CONTEX_KEY)){
if(sourceInPath.equals(Sources.GRSF)){
record.setRecordType(Record_Type.AGGREGATED);
@ -307,7 +307,7 @@ public class GrsfPublisherFisheryService {
Sources sourceInPath = Sources.onDeserialize(source);
if(sourceInPath == null)
throw new Exception("The specified source in the path is unrecognized. Values accepted are [rams, firms, fishsource, grsf]");
throw new Exception("The specified source in the path is unrecognized. Values accepted are [ram, firms, fishsource, grsf]");
logger.info("The request is to create a stock object of source " + sourceInPath);
@ -322,7 +322,7 @@ public class GrsfPublisherFisheryService {
}
// get extras and check there is the product type
if(fisheryInCkan.getExtrasAsHashMap().get(Common.PRODUCT_TYPE_KEY).equals(Product_Type.FISHERY.getOrigName())){
if(catalogue.isDatasetInGroup(source + "-" + "fishery", recordToDelete.getId())){
logger.warn("Ok, this is a fishery, removing it");
boolean deleted = catalogue.deleteProduct(fisheryInCkan.getId(), catalogue.getApiKeyFromUsername(username), true);
if(deleted){
@ -337,7 +337,7 @@ public class GrsfPublisherFisheryService {
}else{
status = Status.BAD_REQUEST;
throw new Exception("The id you are using doesn't belong to a Fishery product!");
throw new Exception("The id you are using doesn't belong to a Fishery product having source " + source + "!");
}
}catch(Exception e){
logger.error("Failed to delete this ");
@ -348,4 +348,56 @@ public class GrsfPublisherFisheryService {
return Response.status(status).entity(responseBean).build();
}
@GET
@Path("get-fisheries-ids")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getFisheriesIds(
@PathParam("source") String source){
// retrieve context and username
String context = ScopeProvider.instance.get();
ResponseBean responseBean = new ResponseBean();
Status status = Status.INTERNAL_SERVER_ERROR;
logger.info("Received call to get fisheries with source " + source);
List<String> datasetsIds = new ArrayList<String>();
try{
// Cast the source to the accepted ones
Sources sourceInPath = Sources.onDeserialize(source);
if(sourceInPath == null)
throw new Exception("The specified source in the path is unrecognized. Values accepted are [ram, firms, fishsource, grsf]");
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
if(catalogue == null){
status = Status.INTERNAL_SERVER_ERROR;
throw new Exception("There was a problem while serving your request");
}
List<CkanDataset> datasets = catalogue.getProductsInGroup(source + "-" + "fishery");
for (CkanDataset ckanDataset : datasets) {
datasetsIds.add(ckanDataset.getId());
}
responseBean.setResult(datasetsIds);
responseBean.setSuccess(true);
}catch(Exception e){
logger.error("Failed to delete this ", e);
status = Status.INTERNAL_SERVER_ERROR;
responseBean.setSuccess(false);
responseBean.setMessage(e.getMessage());
}
return Response.status(status).entity(responseBean).build();
}
}

View File

@ -27,10 +27,10 @@ import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.library.utils.Caller;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.Common;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.DeleteProductBean;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.RefersToBean;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.StockRecord;
import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseBean;
import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseCreationBean;
import org.gcube.data_catalogue.grsf_publish_ws.utils.HelperMethods;
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Product_Type;
@ -106,7 +106,7 @@ public class GrsfPublisherStockService {
Sources sourceInPath = Sources.onDeserialize(source);
if(sourceInPath == null)
throw new Exception("The specified source in the path is unrecogized. Values accepted are [rams, firms, fishsource, grsf]");
throw new Exception("The specified source in the path is unrecogized. Values accepted are [ram, firms, fishsource, grsf]");
logger.info("The request is to create a stock object of source " + sourceInPath);
@ -300,9 +300,9 @@ public class GrsfPublisherStockService {
Sources sourceInPath = Sources.onDeserialize(source);
if(sourceInPath == null)
throw new Exception("The specified source in the path is unrecognized. Values accepted are [rams, firms, fishsource, grsf]");
throw new Exception("The specified source in the path is unrecognized. Values accepted are [ram, firms, fishsource, grsf]");
logger.info("The request is to create a stock object of source " + sourceInPath);
logger.info("The request is to delete a stock object of source " + sourceInPath);
// retrieve the catalogue instance
CkanDataset stockInCkan = catalogue.getDataset(recordToDelete.getId(), catalogue.getApiKeyFromUsername(username));
@ -313,11 +313,11 @@ public class GrsfPublisherStockService {
throw new Exception("There was a problem while serving your request. This product was not found");
}
// get extras and check there is the product type
if(stockInCkan.getExtrasAsHashMap().get(Common.PRODUCT_TYPE_KEY).equals(Product_Type.STOCK.getOrigName())){
logger.warn("Ok, this is a stock, removing it");
if(catalogue.isDatasetInGroup(source + "-" + "stock", recordToDelete.getId())){
logger.warn("Ok, this is a stock of the right type, removing it");
boolean deleted = catalogue.deleteProduct(stockInCkan.getId(), catalogue.getApiKeyFromUsername(username), true);
if(deleted){
logger.info("Stock DELETED AND PURGED!");
@ -331,7 +331,7 @@ public class GrsfPublisherStockService {
}else{
status = Status.BAD_REQUEST;
throw new Exception("The id you are using doesn't belong to a Stock product!");
throw new Exception("The id you are using doesn't belong to a Stock product having source " + source + "!");
}
}catch(Exception e){
@ -342,5 +342,58 @@ public class GrsfPublisherStockService {
return Response.status(status).entity(responseBean).build();
}
@GET
@Path("get-stocks-ids")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getStocksIds(
@PathParam("source") String source){
// retrieve context and username
String context = ScopeProvider.instance.get();
ResponseBean responseBean = new ResponseBean();
Status status = Status.INTERNAL_SERVER_ERROR;
// check it is a stock ...
logger.info("Received call to get stocks with source " + source);
List<String> datasetsIds = new ArrayList<String>();
try{
// Cast the source to the accepted ones
Sources sourceInPath = Sources.onDeserialize(source);
if(sourceInPath == null)
throw new Exception("The specified source in the path is unrecognized. Values accepted are [ram, firms, fishsource, grsf]");
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
if(catalogue == null){
status = Status.INTERNAL_SERVER_ERROR;
throw new Exception("There was a problem while serving your request");
}
List<CkanDataset> datasets = catalogue.getProductsInGroup(source + "-" + "stock");
for (CkanDataset ckanDataset : datasets) {
datasetsIds.add(ckanDataset.getId());
}
responseBean.setResult(datasetsIds);
responseBean.setSuccess(true);
}catch(Exception e){
logger.error("Failed to delete this ", e);
status = Status.INTERNAL_SERVER_ERROR;
responseBean.setSuccess(false);
responseBean.setMessage(e.getMessage());
}
return Response.status(status).entity(responseBean).build();
}
}