From 3136586bd0e861b74eb46d548147e0a995724762 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 10 Apr 2024 10:54:45 +0200 Subject: [PATCH] Refactoring --- .../{Fishery.java => FisheryRecord.java} | 2 +- .../record/{Stock.java => StockRecord.java} | 2 +- ...yUnit.java => TraceabilityUnitRecord.java} | 2 +- .../{FisheryRESTAPIs.java => Fishery.java} | 10 +- .../org/gcube/grsf/publisher/rest/Stock.java | 267 ++++++++++++++++++ .../grsf/publisher/rest/StockRESTAPIs.java | 135 --------- ...nitRESTAPIs.java => TraceabilityUnit.java} | 10 +- 7 files changed, 280 insertions(+), 148 deletions(-) rename src/main/java/org/gcube/grsf/publisher/ckan/record/{Fishery.java => FisheryRecord.java} (78%) rename src/main/java/org/gcube/grsf/publisher/ckan/record/{Stock.java => StockRecord.java} (78%) rename src/main/java/org/gcube/grsf/publisher/ckan/record/{TraceabilityUnit.java => TraceabilityUnitRecord.java} (75%) rename src/main/java/org/gcube/grsf/publisher/rest/{FisheryRESTAPIs.java => Fishery.java} (97%) create mode 100644 src/main/java/org/gcube/grsf/publisher/rest/Stock.java delete mode 100644 src/main/java/org/gcube/grsf/publisher/rest/StockRESTAPIs.java rename src/main/java/org/gcube/grsf/publisher/rest/{TraceabilityUnitRESTAPIs.java => TraceabilityUnit.java} (97%) diff --git a/src/main/java/org/gcube/grsf/publisher/ckan/record/Fishery.java b/src/main/java/org/gcube/grsf/publisher/ckan/record/FisheryRecord.java similarity index 78% rename from src/main/java/org/gcube/grsf/publisher/ckan/record/Fishery.java rename to src/main/java/org/gcube/grsf/publisher/ckan/record/FisheryRecord.java index 15c819c..d301cb6 100644 --- a/src/main/java/org/gcube/grsf/publisher/ckan/record/Fishery.java +++ b/src/main/java/org/gcube/grsf/publisher/ckan/record/FisheryRecord.java @@ -3,7 +3,7 @@ package org.gcube.grsf.publisher.ckan.record; /** * @author Luca Frosini (ISTI - CNR) */ -public class Fishery extends Record { +public class FisheryRecord extends Record { @Override public String getType() { diff --git a/src/main/java/org/gcube/grsf/publisher/ckan/record/Stock.java b/src/main/java/org/gcube/grsf/publisher/ckan/record/StockRecord.java similarity index 78% rename from src/main/java/org/gcube/grsf/publisher/ckan/record/Stock.java rename to src/main/java/org/gcube/grsf/publisher/ckan/record/StockRecord.java index 7cbc5cf..018197e 100644 --- a/src/main/java/org/gcube/grsf/publisher/ckan/record/Stock.java +++ b/src/main/java/org/gcube/grsf/publisher/ckan/record/StockRecord.java @@ -3,7 +3,7 @@ package org.gcube.grsf.publisher.ckan.record; /** * @author Luca Frosini (ISTI - CNR) */ -public class Stock extends Record { +public class StockRecord extends Record { @Override public String getType() { diff --git a/src/main/java/org/gcube/grsf/publisher/ckan/record/TraceabilityUnit.java b/src/main/java/org/gcube/grsf/publisher/ckan/record/TraceabilityUnitRecord.java similarity index 75% rename from src/main/java/org/gcube/grsf/publisher/ckan/record/TraceabilityUnit.java rename to src/main/java/org/gcube/grsf/publisher/ckan/record/TraceabilityUnitRecord.java index ed0996c..10ece4b 100644 --- a/src/main/java/org/gcube/grsf/publisher/ckan/record/TraceabilityUnit.java +++ b/src/main/java/org/gcube/grsf/publisher/ckan/record/TraceabilityUnitRecord.java @@ -3,7 +3,7 @@ package org.gcube.grsf.publisher.ckan.record; /** * @author Luca Frosini (ISTI - CNR) */ -public class TraceabilityUnit extends Record { +public class TraceabilityUnitRecord extends Record { @Override public String getType() { diff --git a/src/main/java/org/gcube/grsf/publisher/rest/FisheryRESTAPIs.java b/src/main/java/org/gcube/grsf/publisher/rest/Fishery.java similarity index 97% rename from src/main/java/org/gcube/grsf/publisher/rest/FisheryRESTAPIs.java rename to src/main/java/org/gcube/grsf/publisher/rest/Fishery.java index eebaf64..6b8585b 100644 --- a/src/main/java/org/gcube/grsf/publisher/rest/FisheryRESTAPIs.java +++ b/src/main/java/org/gcube/grsf/publisher/rest/Fishery.java @@ -15,7 +15,7 @@ import javax.ws.rs.core.Response; import org.gcube.gcat.api.GCatConstants; import org.gcube.grsf.publisher.annotation.PATCH; import org.gcube.grsf.publisher.annotation.PURGE; -import org.gcube.grsf.publisher.ckan.record.Fishery; +import org.gcube.grsf.publisher.ckan.record.FisheryRecord; import com.webcohesion.enunciate.metadata.rs.ResponseCode; import com.webcohesion.enunciate.metadata.rs.StatusCodes; @@ -23,14 +23,14 @@ import com.webcohesion.enunciate.metadata.rs.StatusCodes; /** * @author Luca Frosini (ISTI - CNR) */ -@Path(FisheryRESTAPIs.COLLECTION_PATH) -public class FisheryRESTAPIs extends BaseRESTAPIs { +@Path(Fishery.COLLECTION_PATH) +public class Fishery extends BaseRESTAPIs { public static final String COLLECTION_PATH = "fishery"; public static final String GRSF_RECORD_UUID_PARAMETER = "fishery_record_id"; - public FisheryRESTAPIs() { - super(COLLECTION_PATH, GRSF_RECORD_UUID_PARAMETER, Fishery.class); + public Fishery() { + super(COLLECTION_PATH, GRSF_RECORD_UUID_PARAMETER, FisheryRecord.class); } /** diff --git a/src/main/java/org/gcube/grsf/publisher/rest/Stock.java b/src/main/java/org/gcube/grsf/publisher/rest/Stock.java new file mode 100644 index 0000000..a9ecafd --- /dev/null +++ b/src/main/java/org/gcube/grsf/publisher/rest/Stock.java @@ -0,0 +1,267 @@ +package org.gcube.grsf.publisher.rest; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +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.Response; + +import org.gcube.gcat.api.GCatConstants; +import org.gcube.grsf.publisher.annotation.PATCH; +import org.gcube.grsf.publisher.annotation.PURGE; +import org.gcube.grsf.publisher.ckan.record.StockRecord; + +import com.webcohesion.enunciate.metadata.rs.ResponseCode; +import com.webcohesion.enunciate.metadata.rs.StatusCodes; + +/** + * @author Luca Frosini (ISTI - CNR) + */ +@Path(Stock.COLLECTION_PATH) +public class Stock extends BaseRESTAPIs { + + public static final String COLLECTION_PATH = "stock"; + public static final String RECORD_ID_PARAMETER = "stock_record_id"; + + public Stock() { + super(COLLECTION_PATH, RECORD_ID_PARAMETER, StockRecord.class); + } + + /** + *

+ * The listing API provides paginated results by using the query parameters limit and offset.
+ * It returns an array list of string containing the GRSF UUIDs of the records.
+ * Each name can be used as {stock_record_id} path parameter to manage such a record. + *

+ * + *

Filtering options

+ *

+ * The listing method offers options to filter the results, thus enacting to search for records including spatial search (see ext_bbox below).
+ *

+ * + *

Basic Filtering options

+ *
+ *
include_private (bool)
+ *
+ * Optional.Default:false.
+ * If True, private records will be included in the results.
+ * For the sysadmins will be returned all private datasets.
+ * E.g. /stock?include_private=true + *
+ * + *
ext_bbox
+ *
+ * Optional.Default:null.
+ * The coordinates of the upper-right and bottom-left angle of a rectangular to query for. + * The form is Lat,Long,Lat,Long
+ * E.g. /stock?limit=10&offset=0&q=Gadus&ext_bbox=-7.535093,49.208494,3.890688,57.372349 + * returns the first 10 records with 'Gadus' having a spatial coverage in the specified bounding box. + *
+ * + *
+ * + *

Filtering options based on Solr query parameters

+ *

+ * It accepts the following query parameters (a subset of Solr search query parameters, see {@see Solr Query Syntax}): + *

+ *
+ *
q (string)
+ *
+ * Optional.Default:"*:*"
+ * The solr query.
+ * E.g. /stock?q=title:Gadus returns the stock records with word "Gadus" in the title.
+ * E.g. /stock?q=extras_systemtype:Marine Resource returns the GRSF Marine Resource records. + *
+ * + *
fq (string)
+ *
+ * Optional.Default:null.
+ * Filter query. A query string that limits the query results without influencing their scores.
+ * E.g. /stock?q=title:Gadus&fq=annotations:test returns with word "Gadus" in the 'title' and the word "test" in the 'Annotations'. + *
+ * + *
fq_list (list of strings)
+ *
+ * Optional.Default:null.
+ * Additional filter queries to apply.
+ * E.g. /stock?q=title:Gadus&fq_list=... returns the records with word "Gadus" in the 'title'. + *
+ * + *
sort (string)
+ *
+ * Optional.Default:"relevance asc, metadata_modified desc".
+ * Sorting of the search results.
+ * As per the solr documentation, this is a comma-separated string of field names and sort-orderings.
+ * E.g. /stock?q=title:Gadus&sort=name+asc returns the records with word "Gadus" in the 'title' + * sorting the results by name ascending. + *
+ *
+ * + *

Query results options

+ *

+ * The result is by default an array list of string containing the GRSF UUIDs of the records. + * Anyway, there are two options to get a different results. + *

+ *
+ *
count (bool)
+ *
+ * Optional.Default:false.
+ * If True, it indicates that the result must contains only the total number of records of the query.
+ * E.g. /stock?limit=10&offset=0&count=true + *
+ * + *
all_fields (bool)
+ *
+ * Optional.Default:false. + * If True, the returned array list contains the whole records representation and not only the GRSF UUIDs of the records.
+ * E.g. /stock?limit=10&offset=0&all_fields=true + *
+ *
+ *

+ * Please note that, count query parameter has priority over all_fields query parameter. + * In other words, all_fields query parameter is not considered is count query parameter is true. + *

+ * + * + * @param limit (Default:10) To get unlimited results the limit query parameters must be set to -1. + * If the results are too much the operation could fail. + * It is recommended to request no more than 1000 results. + * @param offset (Default:0) The offset parameter indicates the starting position of the result. + * @return It returns an array list of string containing the GRSF UUIDs of the records. + * E.g.
["GRSF_UUID_0","GRSF_UUID_1",...,"GRSF_UUID_10"]
+ * + * In the case the query parameter count=true it returns the total number of records of the query. + * E.g.
{"count":148}
+ * + * In the case the query parameter all_fields=true each element of the resulting array contains the record representation: + * E.g. + *
+	 *  [
+	 *  	{
+	 *  		"name"="GRSF_UUID_0",
+	 *  		...,
+	 *  		"private": false,
+	 *  		"license_id": "CC-BY-SA-4.0",
+	 *  	},
+	 *  	{
+	 *  		"name"="GRSF_UUID_1",
+	 *  		...,
+	 *  		"private": false,
+	 *  		"license_id": "CC-BY-SA-4.0",
+	 *  	},
+	 *  	...,
+	 *  	{
+	 *  		"name"="GRSF_UUID_N",
+	 *  		...,
+	 *  		"private": false,
+	 *  		"license_id": "CC-BY-SA-4.0",
+	 *  	}
+	 *  
+	 *  ]
+ * + * @pathExample /stock?limit=10&offset=0 + * @responseExample application/json;charset=UTF-8 ["GRSF_UUID_0","GRSF_UUID_1",...,"GRSF_UUID_N"] + */ + @GET + @Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) + @StatusCodes ({ + @ResponseCode ( code = 200, condition = "The request succeeded.") + }) + public String list(@QueryParam(GCatConstants.LIMIT_QUERY_PARAMETER) @DefaultValue("10") int limit, + @QueryParam(GCatConstants.OFFSET_QUERY_PARAMETER) @DefaultValue("0") int offset) { + return super.list(limit, offset); + } + + /** + * @pathExample /stock + */ + @POST + @Consumes(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) + @Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) + @StatusCodes ({ + @ResponseCode ( code = 201, condition = "The stock record has been created successfully.") + }) + public Response create(String json) { + return super.create(json); + } + + /** + * @pathExample /stock/866a479a-643a-4c21-bbcd-a3a73f28ea50 + */ + @GET + @Path("/{" + RECORD_ID_PARAMETER + "}") + @Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) + @StatusCodes ({ + @ResponseCode ( code = 200, condition = "The stock record exists.") + }) + @Override + public String read(@PathParam(RECORD_ID_PARAMETER) String id) { + return super.read(id); + } + + /** + * @pathExample /stock/866a479a-643a-4c21-bbcd-a3a73f28ea50 + */ + @PUT + @Path("/{" + RECORD_ID_PARAMETER + "}") + @Consumes(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) + @Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) + @StatusCodes ({ + @ResponseCode ( code = 200, condition = "The stock record has been updated successfully.") + }) + @Override + public String update(@PathParam(RECORD_ID_PARAMETER) String id, String json) { + return super.update(id, json); + } + + /** + * @pathExample /stock/866a479a-643a-4c21-bbcd-a3a73f28ea50 + */ + @PATCH + @Path("/{" + RECORD_ID_PARAMETER + "}") + @Consumes(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) + @Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) + @StatusCodes ({ + @ResponseCode ( code = 200, condition = "The stock record has been patched successfully.") + }) + @Override + public String patch(@PathParam(RECORD_ID_PARAMETER) String id, String json) { + return super.patch(id, json); + } + + /** + * @pathExample /stock/866a479a-643a-4c21-bbcd-a3a73f28ea50 + */ + @DELETE + @Path("/{" + RECORD_ID_PARAMETER + "}") + @StatusCodes ({ + @ResponseCode ( code = 204, condition = "The stock record has been deleted successfully."), + @ResponseCode ( code = 404, condition = "The stock record was not found.") + }) + @Override + public Response delete(@PathParam(RECORD_ID_PARAMETER) String id, + @QueryParam(GCatConstants.PURGE_QUERY_PARAMETER) @DefaultValue("false") Boolean purge) { + return super.delete(id, purge); + } + + /** + * @pathExample /stock/866a479a-643a-4c21-bbcd-a3a73f28ea50 + */ + @PURGE + @Path("/{" + RECORD_ID_PARAMETER + "}") + @StatusCodes ({ + @ResponseCode ( code = 204, condition = "The stock record has been purged successfully."), + @ResponseCode ( code = 404, condition = "The stock record was not found.") + }) + @Override + public Response purge(@PathParam(RECORD_ID_PARAMETER) String id) { + return super.purge(id); + } + +} diff --git a/src/main/java/org/gcube/grsf/publisher/rest/StockRESTAPIs.java b/src/main/java/org/gcube/grsf/publisher/rest/StockRESTAPIs.java deleted file mode 100644 index 86ea66a..0000000 --- a/src/main/java/org/gcube/grsf/publisher/rest/StockRESTAPIs.java +++ /dev/null @@ -1,135 +0,0 @@ -package org.gcube.grsf.publisher.rest; - -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -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.Response; - -import org.gcube.gcat.api.GCatConstants; -import org.gcube.grsf.publisher.annotation.PATCH; -import org.gcube.grsf.publisher.annotation.PURGE; -import org.gcube.grsf.publisher.ckan.record.Stock; - -import com.webcohesion.enunciate.metadata.rs.ResponseCode; -import com.webcohesion.enunciate.metadata.rs.StatusCodes; - -/** - * @author Luca Frosini (ISTI - CNR) - */ -@Path(StockRESTAPIs.COLLECTION_PATH) -public class StockRESTAPIs extends BaseRESTAPIs { - - public static final String COLLECTION_PATH = "stock"; - public static final String RECORD_ID_PARAMETER = "stock_record_id"; - - public StockRESTAPIs() { - super(COLLECTION_PATH, RECORD_ID_PARAMETER, Stock.class); - } - - /** - * @pathExample /stock - */ - @GET - @Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) - @StatusCodes ({ - @ResponseCode ( code = 200, condition = "The request succeeded.") - }) - public String list(@QueryParam(GCatConstants.LIMIT_QUERY_PARAMETER) @DefaultValue("10") int limit, - @QueryParam(GCatConstants.OFFSET_QUERY_PARAMETER) @DefaultValue("0") int offset) { - return super.list(limit, offset); - } - - /** - * @pathExample /stock - */ - @POST - @Consumes(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) - @Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) - @StatusCodes ({ - @ResponseCode ( code = 201, condition = "The stock record has been created successfully.") - }) - public Response create(String json) { - return super.create(json); - } - - /** - * @pathExample /stock/866a479a-643a-4c21-bbcd-a3a73f28ea50 - */ - @GET - @Path("/{" + RECORD_ID_PARAMETER + "}") - @Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) - @StatusCodes ({ - @ResponseCode ( code = 200, condition = "The stock record exists.") - }) - @Override - public String read(@PathParam(RECORD_ID_PARAMETER) String id) { - return super.read(id); - } - - /** - * @pathExample /stock/866a479a-643a-4c21-bbcd-a3a73f28ea50 - */ - @PUT - @Path("/{" + RECORD_ID_PARAMETER + "}") - @Consumes(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) - @Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) - @StatusCodes ({ - @ResponseCode ( code = 200, condition = "The stock record has been updated successfully.") - }) - @Override - public String update(@PathParam(RECORD_ID_PARAMETER) String id, String json) { - return super.update(id, json); - } - - /** - * @pathExample /stock/866a479a-643a-4c21-bbcd-a3a73f28ea50 - */ - @PATCH - @Path("/{" + RECORD_ID_PARAMETER + "}") - @Consumes(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) - @Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8) - @StatusCodes ({ - @ResponseCode ( code = 200, condition = "The stock record has been patched successfully.") - }) - @Override - public String patch(@PathParam(RECORD_ID_PARAMETER) String id, String json) { - return super.patch(id, json); - } - - /** - * @pathExample /stock/866a479a-643a-4c21-bbcd-a3a73f28ea50 - */ - @DELETE - @Path("/{" + RECORD_ID_PARAMETER + "}") - @StatusCodes ({ - @ResponseCode ( code = 204, condition = "The stock record has been deleted successfully."), - @ResponseCode ( code = 404, condition = "The stock record was not found.") - }) - @Override - public Response delete(@PathParam(RECORD_ID_PARAMETER) String id, - @QueryParam(GCatConstants.PURGE_QUERY_PARAMETER) @DefaultValue("false") Boolean purge) { - return super.delete(id, purge); - } - - /** - * @pathExample /stock/866a479a-643a-4c21-bbcd-a3a73f28ea50 - */ - @PURGE - @Path("/{" + RECORD_ID_PARAMETER + "}") - @StatusCodes ({ - @ResponseCode ( code = 204, condition = "The stock record has been purged successfully."), - @ResponseCode ( code = 404, condition = "The stock record was not found.") - }) - @Override - public Response purge(@PathParam(RECORD_ID_PARAMETER) String id) { - return super.purge(id); - } - -} diff --git a/src/main/java/org/gcube/grsf/publisher/rest/TraceabilityUnitRESTAPIs.java b/src/main/java/org/gcube/grsf/publisher/rest/TraceabilityUnit.java similarity index 97% rename from src/main/java/org/gcube/grsf/publisher/rest/TraceabilityUnitRESTAPIs.java rename to src/main/java/org/gcube/grsf/publisher/rest/TraceabilityUnit.java index 91f60af..11c72bf 100644 --- a/src/main/java/org/gcube/grsf/publisher/rest/TraceabilityUnitRESTAPIs.java +++ b/src/main/java/org/gcube/grsf/publisher/rest/TraceabilityUnit.java @@ -15,7 +15,7 @@ import javax.ws.rs.core.Response; import org.gcube.gcat.api.GCatConstants; import org.gcube.grsf.publisher.annotation.PATCH; import org.gcube.grsf.publisher.annotation.PURGE; -import org.gcube.grsf.publisher.ckan.record.TraceabilityUnit; +import org.gcube.grsf.publisher.ckan.record.TraceabilityUnitRecord; import com.webcohesion.enunciate.metadata.rs.ResponseCode; import com.webcohesion.enunciate.metadata.rs.StatusCodes; @@ -23,14 +23,14 @@ import com.webcohesion.enunciate.metadata.rs.StatusCodes; /** * @author Luca Frosini (ISTI - CNR) */ -@Path(TraceabilityUnitRESTAPIs.COLLECTION_PATH) -public class TraceabilityUnitRESTAPIs extends BaseRESTAPIs{ +@Path(TraceabilityUnit.COLLECTION_PATH) +public class TraceabilityUnit extends BaseRESTAPIs{ public static final String COLLECTION_PATH = "traceability-unit"; public static final String RECORD_ID_PARAMETER = "traceability_unit_record_id"; - public TraceabilityUnitRESTAPIs() { - super(COLLECTION_PATH, RECORD_ID_PARAMETER, TraceabilityUnit.class); + public TraceabilityUnit() { + super(COLLECTION_PATH, RECORD_ID_PARAMETER, TraceabilityUnitRecord.class); } /**