Adding documentation

This commit is contained in:
Luca Frosini 2024-04-09 18:19:39 +02:00
parent a7c6c346ba
commit c344742c70
3 changed files with 159 additions and 27 deletions

View File

@ -185,7 +185,7 @@ public class FisheryRESTAPIs extends BaseRESTAPIs<Fishery> {
@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.")
@ResponseCode ( code = 201, condition = "The fishery record has been created successfully.")
})
public Response create(String json) {
return super.create(json);
@ -198,7 +198,7 @@ public class FisheryRESTAPIs extends BaseRESTAPIs<Fishery> {
@Path("/{" + GRSF_RECORD_UUID_PARAMETER + "}")
@Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8)
@StatusCodes ({
@ResponseCode ( code = 200, condition = "The stock record exists.")
@ResponseCode ( code = 200, condition = "The fishery record exists.")
})
@Override
public String read(@PathParam(GRSF_RECORD_UUID_PARAMETER) String id) {
@ -213,7 +213,7 @@ public class FisheryRESTAPIs extends BaseRESTAPIs<Fishery> {
@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.")
@ResponseCode ( code = 200, condition = "The fishery record has been updated successfully.")
})
@Override
public String update(@PathParam(GRSF_RECORD_UUID_PARAMETER) String id, String json) {
@ -228,7 +228,7 @@ public class FisheryRESTAPIs extends BaseRESTAPIs<Fishery> {
@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.")
@ResponseCode ( code = 200, condition = "The fishery record has been patched successfully.")
})
@Override
public String patch(@PathParam(GRSF_RECORD_UUID_PARAMETER) String id, String json) {
@ -241,8 +241,8 @@ public class FisheryRESTAPIs extends BaseRESTAPIs<Fishery> {
@DELETE
@Path("/{" + GRSF_RECORD_UUID_PARAMETER + "}")
@StatusCodes ({
@ResponseCode ( code = 204, condition = "The stock record has been deleted successfully."),
@ResponseCode ( code = 404, condition = "The stock record was not found.")
@ResponseCode ( code = 204, condition = "The fishery record has been deleted successfully."),
@ResponseCode ( code = 404, condition = "The fishery record was not found.")
})
@Override
public Response delete(@PathParam(GRSF_RECORD_UUID_PARAMETER) String id,
@ -256,8 +256,8 @@ public class FisheryRESTAPIs extends BaseRESTAPIs<Fishery> {
@PURGE
@Path("/{" + GRSF_RECORD_UUID_PARAMETER + "}")
@StatusCodes ({
@ResponseCode ( code = 204, condition = "The stock record has been purged successfully."),
@ResponseCode ( code = 404, condition = "The stock record was not found.")
@ResponseCode ( code = 204, condition = "The fishery record has been purged successfully."),
@ResponseCode ( code = 404, condition = "The fishery record was not found.")
})
@Override
public Response purge(@PathParam(GRSF_RECORD_UUID_PARAMETER) String id) {

View File

@ -34,7 +34,139 @@ public class TraceabilityUnitRESTAPIs extends BaseRESTAPIs<TraceabilityUnit>{
}
/**
* @pathExample /traceability-unit
* <p>
* The listing API provides paginated results by using the query parameters limit and offset.<br/>
* It returns an array list of string containing the GRSF UUIDs of the records.<br/>
* Each name can be used as <code>{traceability_unit_record_id}</code> path parameter to manage such a record.
* </p>
*
* <h3>Filtering options</h3>
* <p>
* The listing method offers options to filter the results, thus enacting to search for records including spatial search (see ext_bbox below).<br/>
* </p>
*
* <h4>Basic Filtering options</h4>
* <dl>
* <dt>include_private (bool)</dt>
* <dd>
* <em>Optional</em>.<em>Default:false</em>.<br/>
* If True, private records will be included in the results.<br/>
* For the sysadmins will be returned all private datasets.<br/>
* E.g. <code>/traceability-unit?include_private=true</code>
* </dd>
*
* <dt style="margin-top: 5px;">ext_bbox</dt>
* <dd>
* <em>Optional</em>.<em>Default:null</em>.<br/>
* The coordinates of the upper-right and bottom-left angle of a rectangular to query for.
* The form is <code>Lat,Long,Lat,Long</code><br/>
* E.g. <code>/traceability-unit?limit=10&offset=0&q=Gadus&ext_bbox=-7.535093,49.208494,3.890688,57.372349</code>
* returns the first 10 records with 'Gadus' having a spatial coverage in the specified bounding box.
* </dd>
*
* </dl>
*
* <h4>Filtering options based on Solr query parameters</h4>
* <p>
* It accepts the following query parameters (a subset of Solr search query parameters, see {@see <a href="https://solrtutorial.com/solr-query-syntax.html">Solr Query Syntax</a>}):
* </p>
* <dl>
* <dt>q (string)</dt>
* <dd>
* <em>Optional</em>.<em>Default:"*:*"</em><br/>
* The solr query.<br/>
* E.g. <code>/traceability-unit?q=title:Gadus</code> returns the traceability unit records with word "Gadus" in the title.<br/>
* E.g. <code>/traceability-unit?q=extras_systemtype:Traceability Unit</code> returns the GRSF <em>Traceability Unit</em> records.
* </dd>
*
* <dt style="margin-top: 5px;">fq (string)</dt>
* <dd>
* <em>Optional</em>.<em>Default:null</em>.<br/>
* Filter query. A query string that limits the query results without influencing their scores.<br/>
* E.g. <code>/traceability-unit?q=title:Gadus&fq=annotations:test</code> returns with word "Gadus" in the 'title' and the word "test" in the 'Annotations'.
* </dd>
*
* <dt style="margin-top: 5px;">fq_list (list of strings)</dt>
* <dd>
* <em>Optional</em>.<em>Default:null</em>.<br/>
* Additional filter queries to apply.<br/>
* E.g. <code>/traceability-unit?q=title:Gadus&fq_list=...</code> returns the records with word "Gadus" in the 'title'.
* </dd>
*
* <dt style="margin-top: 5px;">sort (string)</dt>
* <dd>
* <em>Optional</em>.<em>Default:"relevance asc, metadata_modified desc"</em>.<br/>
* Sorting of the search results.<br/>
* As per the solr documentation, this is a comma-separated string of field names and sort-orderings.<br/>
* E.g. <code>/traceability-unit?q=title:Gadus&sort=name+asc</code> returns the records with word "Gadus" in the 'title'
* sorting the results by name ascending.
* </dd>
* <dl>
*
* <h3>Query results options</h3>
* <p>
* 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.
* </p>
* <dl>
* <dt>count (bool)</dt>
* <dd>
* <em>Optional</em>.<em>Default:false</em>.<br/>
* If True, it indicates that the result must contains only the total number of records of the query.<br/>
* E.g. <code>/traceability-unit?limit=10&offset=0&count=true</code>
* </dd>
*
* <dt style="margin-top: 5px;">all_fields (bool)</dt>
* <dd>
* <em>Optional</em>.<em>Default:false</em>.
* If True, the returned array list contains the whole records representation and not only the GRSF UUIDs of the records.</br/>
* E.g. <code>/traceability-unit?limit=10&offset=0&all_fields=true</code>
* </dd>
* </dl>
* <p>
* Please note that, <code>count</code> query parameter has priority over <code>all_fields</code> query parameter.
* In other words, <code>all_fields</code> query parameter is not considered is <code>count</code> query parameter is true.
* </p>
*
*
* @param limit (<em>Default:10</em>) 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 (<em>Default:0</em>) 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.<pre>["GRSF_UUID_0","GRSF_UUID_1",...,"GRSF_UUID_10"]</pre>
*
* In the case the query parameter <code>count=true</code> it returns the total number of records of the query.
* E.g. <pre>{"count":148}</pre>
*
* In the case the query parameter <code>all_fields=true</code> each element of the resulting array contains the record representation:
* E.g.
* <pre>
* [
* {
* "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",
* }
*
* ]</pre>
*
* @pathExample /traceability-unit?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)
@ -53,7 +185,7 @@ public class TraceabilityUnitRESTAPIs extends BaseRESTAPIs<TraceabilityUnit>{
@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.")
@ResponseCode ( code = 201, condition = "The traceability unit record has been created successfully.")
})
public Response create(String json) {
return super.create(json);
@ -66,7 +198,7 @@ public class TraceabilityUnitRESTAPIs extends BaseRESTAPIs<TraceabilityUnit>{
@Path("/{" + RECORD_ID_PARAMETER + "}")
@Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8)
@StatusCodes ({
@ResponseCode ( code = 200, condition = "The stock record exists.")
@ResponseCode ( code = 200, condition = "The traceability unit record exists.")
})
@Override
public String read(@PathParam(RECORD_ID_PARAMETER) String id) {
@ -81,7 +213,7 @@ public class TraceabilityUnitRESTAPIs extends BaseRESTAPIs<TraceabilityUnit>{
@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.")
@ResponseCode ( code = 200, condition = "The traceability unit record has been updated successfully.")
})
@Override
public String update(@PathParam(RECORD_ID_PARAMETER) String id, String json) {
@ -96,7 +228,7 @@ public class TraceabilityUnitRESTAPIs extends BaseRESTAPIs<TraceabilityUnit>{
@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.")
@ResponseCode ( code = 200, condition = "The traceability unit record has been patched successfully.")
})
@Override
public String patch(@PathParam(RECORD_ID_PARAMETER) String id, String json) {
@ -109,8 +241,8 @@ public class TraceabilityUnitRESTAPIs extends BaseRESTAPIs<TraceabilityUnit>{
@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.")
@ResponseCode ( code = 204, condition = "The traceability unit record has been deleted successfully."),
@ResponseCode ( code = 404, condition = "The traceability unit record was not found.")
})
@Override
public Response delete(@PathParam(RECORD_ID_PARAMETER) String id,
@ -124,8 +256,8 @@ public class TraceabilityUnitRESTAPIs extends BaseRESTAPIs<TraceabilityUnit>{
@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.")
@ResponseCode ( code = 204, condition = "The traceability unit record has been purged successfully."),
@ResponseCode ( code = 404, condition = "The traceability unit record was not found.")
})
@Override
public Response purge(@PathParam(RECORD_ID_PARAMETER) String id) {

View File

@ -177,7 +177,7 @@ public class RecordTest extends ContextTest {
return record;
}
@Ignore
// @Ignore
@Test
public void testFisheryRecords() throws Exception {
List<String> types = new ArrayList<>();
@ -185,7 +185,7 @@ public class RecordTest extends ContextTest {
int maxTestRecords = Integer.MAX_VALUE;
// maxTestRecords = 1;
int maxTestRecordsPerSource = Integer.MAX_VALUE;
maxTestRecordsPerSource = 1;
maxTestRecordsPerSource = 3;
boolean restart = false;
String restartFromSource = null;
// String restartFromSource = "firms";
@ -217,7 +217,7 @@ public class RecordTest extends ContextTest {
testRecords(types, restart, restartFromSource, restartFromFile, maxTestRecords, maxTestRecordsPerSource);
}
@Ignore
// @Ignore
@Test
public void testTraceabilityUnitRecords() throws Exception {
List<String> types = new ArrayList<>();
@ -234,7 +234,7 @@ public class RecordTest extends ContextTest {
testRecords(types, restart, restartFromSource, restartFromFile, maxTestRecords, maxTestRecordsPerSource);
}
@Ignore
// @Ignore
@Test
public void testAll() throws Exception {
ContextTest.setContextByName(VRE_GRSF_PRE);
@ -243,9 +243,9 @@ public class RecordTest extends ContextTest {
types.add(STOCK);
types.add(TRACEABILITY_UNIT);
int maxTestRecords = Integer.MAX_VALUE;
maxTestRecords = 1;
// maxTestRecords = 1;
int maxTestRecordsPerSource = Integer.MAX_VALUE;
maxTestRecordsPerSource = 1;
maxTestRecordsPerSource = 25;
boolean restart = false;
String restartFromSource = null;
String restartFromFile = null;
@ -457,7 +457,7 @@ public class RecordTest extends ContextTest {
testedRecords, diff, TimeUnit.MILLISECONDS.toSeconds(diff));
}
// @Ignore
@Ignore
@Test
public void testList() {
MultivaluedMap<String, String> mvm = new MultivaluedHashMap<String,String>();
@ -473,10 +473,10 @@ public class RecordTest extends ContextTest {
}
}
@Ignore
// @Ignore
@Test
public void testDeleteAll() throws Exception {
ContextTest.setContextByName(DEVVRE);
// ContextTest.setContextByName(DEVVRE);
MultivaluedMap<String, String> mvm = new MultivaluedHashMap<String,String>();
UriInfo uriInfo = getUriInfo(mvm);
@ -510,7 +510,7 @@ public class RecordTest extends ContextTest {
record.setName(name);
logger.info("Going to delete {} with GRSF UUID {}", record.getType(), name);
// record.purge();
record.purge();
logger.trace("Going to sleep for {} millis", sleepTime);
Thread.sleep(sleepTime);