argos/dmp-backend/web/src/main/java/eu/eudat/publicapi/controllers/PublicDmpsDocumentation.java

301 lines
18 KiB
Java

package eu.eudat.publicapi.controllers;
import eu.eudat.controllers.BaseController;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.publicapi.managers.DataManagementPlanPublicManager;
import eu.eudat.publicapi.models.listingmodels.DataManagementPlanPublicListingModel;
import eu.eudat.publicapi.models.overviewmodels.DataManagementPlanPublicModel;
import eu.eudat.publicapi.request.dmp.DataManagmentPlanPublicTableRequest;
import eu.eudat.types.ApiMessageCode;
import io.swagger.annotations.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@Tag(name = "DMPs", description = "Provides DMP public API's.")
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/public/dmps"})
public class PublicDmpsDocumentation extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(PublicDmpsDocumentation.class);
private DataManagementPlanPublicManager dataManagementPlanManager;
private static final String getPagedNotes = "The json response is of type **ResponseItem<DataTableData< DataManagementPlanPublicListingModel >>** containing the following properties:\n" +
"<ol>" +
" <li><b>message</b>: string, message indicating error, null if everything went well</li>" +
" <li><b>statusCode</b>: integer, status code indicating if something unexpected happened, otherwise 0</li>" +
" <li><b>responseType</b>: integer, 0 for json, 1 for file</li>" +
" <li><b>payload</b>: DataTableData, containing the number of values of actual data returned and the data of type <b>DataManagementPlanPublicListingModel</b></li>" +
" <ol>" +
" <li>id: string, id of dmp returned</li>" +
" <li>label: string, label of dmp</li>" +
" <li>grant: string, grant of dmp</li>" +
" <li>createdAt: date, creation time of dmp</li>" +
" <li>modifiedAt: date, modification time of dmp</li>" +
" <li>version: integer, version of dmp</li>" +
" <li>groupId: uuid, group id in which dmp belongs</li>" +
" <li>users: list of UserInfoPublicModel, user who collaborated on the dmp</li>" +
" <li>researchers: list of ResearcherPublicModel, researchers involved in the dmp</li>" +
" <li>finalizedAt: date, finalization date</li>" +
" <li>publishedAt: date, publication date</li>" +
" </ol>" +
"</ol>";
private static final String getPagedResponseExample = "{\n" +
" \"statusCode\": 0,\n" +
" \"responseType\": 0,\n" +
" \"message\": null,\n" +
" \"payload\": {\n" +
" \"totalCount\": 2,\n" +
" \"data\": [\n" +
" {\n" +
" \"id\": \"e9a73d77-adfa-4546-974f-4a4a623b53a8\",\n" +
" \"label\": \"Giorgos's DMP\",\n" +
" \"grant\": \"Novel EOSC services for Emerging Atmosphere, Underwater and Space Challenges\",\n" +
" \"createdAt\": 1579077317000,\n" +
" \"modifiedAt\": 1586444334000,\n" +
" \"version\": 0,\n" +
" \"groupId\": \"d949592d-f862-4b31-a43a-f5f70596df5e\",\n" +
" \"users\": [],\n" +
" \"finalizedAt\": 1586444334000,\n" +
" \"publishedAt\": 1586444334000,\n" +
" \"hint\": \"dataManagementPlanListingModel\"\n" +
" },\n" +
" {\n" +
" \"id\": \"e27789f1-de35-4b4a-9587-a46d131c366e\",\n" +
" \"label\": \"TestH2020Clone3\",\n" +
" \"grant\": \"Evaluation of the Benefits of innovative Concepts of laminar nacelle and HTP installed on a business jet configuration\",\n" +
" \"createdAt\": 1600774437000,\n" +
" \"modifiedAt\": 1600879107000,\n" +
" \"version\": 0,\n" +
" \"groupId\": \"7b793c17-cb69-41d2-a97d-e8d1b03ddbed\",\n" +
" \"users\": [],\n" +
" \"finalizedAt\": 1600879107000,\n" +
" \"publishedAt\": 1600879107000,\n" +
" \"hint\": \"dataManagementPlanListingModel\"\n" +
" }\n" +
" ]\n" +
" }\n" +
"}";
private static final String getPagedRequestBodyDescription = "The dmpTableRequest is a DataManagementPlanPublicTableRequest object with the following fields:\n" +
"<ul>" +
" <li><b>length</b>: how many dmps should be fetched <i>(required)</i></li>" +
" <li><b>offset</b>: offset of the returned dmps, first time should be 0, then offset += length</li>" +
" <li><b>orderings</b>: array of strings specifying the order, format:= +string or -string or asc or desc.</li>" +
"<b>+</b> means ascending order. <b>-</b> means descending order.<br>&nbsp;&nbsp;&nbsp;&nbsp;Available strings are: 1) status, 2) label, 3) publishedAt, 4) created.<br>" +
"&nbsp;&nbsp;&nbsp;&nbsp;<b>asc</b> equivalent to +label.<br>&nbsp;&nbsp;&nbsp;&nbsp;<b>desc</b> equivalent to -label.<br>" +
"<li><b>criteria</b>: this is DataManagementPlanPublicCriteria object which applies filters for the dmp returned. More specifically:</li>" +
" <ol>" +
" <li>periodStart: date, dmps created date greater than periodStart</li>" +
" <li>periodEnd: date, dmps created date less than periodEnd</li>" +
" <li>grants: list of uuids, dmps with the corresponding grants</li>" +
" <li>grantsLike: list of strings, dmps fetched having their grant matching any of the strings provided</li>" +
" <li>funders: list of uuids, dmps with the corresponding funders</li>" +
" <li>fundersLike: list of strings, dmps fetched having their funders matching any of the strings provided</li>" +
" <li>datasetTemplates: list of uuids, dataset templates which are described in the dmps</li>" +
" <li>dmpOrganisations: list of strings, dmps belonging to these organisations</li>" +
" <li>collaborators: list of uuids, user who collaborated on the creation/modification of dmps</li>" +
" <li>collaboratorsLike: list of strings, dmps fetched having their collaborators matching any of the strings provided</li>" +
" <li>allVersions: boolean, if dmps should be fetched with all their versions</li>" +
" <li>groupIds: list of uuids, in which groups the dmps are</li>" +
" <li>like: string, dmps fetched have this string matched in their label or description</li>" +
" </ol>" +
"<ul>";
private static final String getPagedRequestParamDescription = "The fieldsGroup is a string which indicates if the returned objects would have all their properties\n" +
"There are two available values: 1) listing and 2) autocomplete\n" +
"<ul>" +
" <li><b>listing</b>: returns objects with all their properties completed</li>" +
" <li><b>autocomplete</b>: returns objects with only id, label, groupId and creationTime assigned</li>" +
"<ul>";
private static final String getOverviewSinglePublicNotes = "The json response is of type **ResponseItem< DataManagementPlanPublicModel >** containing the following properties:\n" +
"<ol>" +
" <li><b>message</b>: string, message indicating error, null if everything went well</li>" +
" <li><b>statusCode</b>: integer, status code indicating if something unexpected happened, otherwise 0</li>" +
" <li><b>responseType</b>: integer, 0 for json, 1 for file</li>" +
" <li><b>payload</b>: DataManagementPlanPublicModel, dmp returned</li>" +
" <ol>" +
" <li>id: string, id of dmp returned</li>" +
" <li>label: string, label of dmp</li>" +
" <li>profile: string, profile of dmp</li>" +
" <li>grant: GrantPublicOverviewModel, grant of dmp</li>" +
" <li>createdAt: date, creation time of dmp</li>" +
" <li>modifiedAt: date, modification time of dmp</li>" +
" <li>finalizedAt: date, finalization date of dmp</li>" +
" <li>organisations: list of OrganizationPublicModel, organizations in which dmp belongs</li>" +
" <li>version: integer, version of dmp</li>" +
" <li>groupId: uuid, group id in which dmp belongs</li>" +
" <li>datasets: list of DatasetPublicModel, contained datasets</li>" +
" <li>associatedProfiles: list of AssociatedProfilePublicModel, associated profiles of dmp</li>" +
" <li>researchers: list of ResearcherPublicModel, researchers involved in dmp</li>" +
" <li>users: list of UserInfoPublicModel, user who collaborated on the dmp</li>" +
" <li>description: string, description of dmp</li>" +
" <li>publishedAt: date, publication date</li>" +
" <li>doi: string, if dmp has been published to zenodo so it has doi</li>" +
" </ol>" +
"</ol>";
private static final String getOverviewSinglePublicResponseExample = "{\n" +
" \"statusCode\": 0,\n" +
" \"responseType\": 0,\n" +
" \"message\": null,\n" +
" \"payload\": {\n" +
" \"id\": \"e9a73d77-adfa-4546-974f-4a4a623b53a8\",\n" +
" \"label\": \"Giorgos's DMP\",\n" +
" \"profile\": null,\n" +
" \"grant\": {\n" +
" \"id\": \"c8309ae5-4e56-43eb-aa5a-9950c24051fe\",\n" +
" \"label\": \"Novel EOSC services for Emerging Atmosphere, Underwater and Space Challenges\",\n" +
" \"abbreviation\": null,\n" +
" \"description\": null,\n" +
" \"startDate\": null,\n" +
" \"endDate\": null,\n" +
" \"uri\": null,\n" +
" \"funder\": {\n" +
" \"id\": \"25e76828-3539-4c66-9870-0ecea7a4d16e\",\n" +
" \"label\": \"European Commission||EC\",\n" +
" \"hint\": null\n" +
" },\n" +
" \"hint\": null\n" +
" },\n" +
" \"createdAt\": 1579077317000,\n" +
" \"modifiedAt\": 1586444334000,\n" +
" \"finalizedAt\": 1586444334000,\n" +
" \"organisations\": [],\n" +
" \"version\": 0,\n" +
" \"groupId\": \"d949592d-f862-4b31-a43a-f5f70596df5e\",\n" +
" \"datasets\": [\n" +
" {\n" +
" \"id\": \"853a24c3-def4-4978-985f-92e7fa57ef22\",\n" +
" \"label\": \"Giorgos's Dataset Desc\",\n" +
" \"reference\": null,\n" +
" \"uri\": null,\n" +
" \"description\": null,\n" +
" \"status\": 1,\n" +
" \"createdAt\": 1579077532000,\n" +
" \"dmp\": {\n" +
" \"id\": \"e9a73d77-adfa-4546-974f-4a4a623b53a8\",\n" +
" \"label\": \"Giorgos's DMP\",\n" +
" \"grant\": \"Novel EOSC services for Emerging Atmosphere, Underwater and Space Challenges\",\n" +
" \"createdAt\": 1579077317000,\n" +
" \"modifiedAt\": 1586444334000,\n" +
" \"version\": 0,\n" +
" \"groupId\": \"d949592d-f862-4b31-a43a-f5f70596df5e\",\n" +
" \"users\": [\n" +
" {\n" +
" \"id\": \"00476b4d-0491-44ca-b2fd-92e695062a48\",\n" +
" \"name\": \"OpenDMP OpenDMP\",\n" +
" \"role\": 0,\n" +
" \"email\": \"opendmpeu@gmail.com\",\n" +
" \"hint\": \"UserInfoListingModel\"\n" +
" }\n" +
" ],\n" +
" \"finalizedAt\": 1586444334000,\n" +
" \"publishedAt\": 1586444334000,\n" +
" \"hint\": \"dataManagementPlanListingModel\"\n" +
" },\n" +
" \"datasetProfileDefinition\": {\n" +
" \"pages\": [...],\n" +
" \"rules\": [...],\n" +
" \"status\": 0\n" +
" },\n" +
" \"registries\": [],\n" +
" \"services\": [],\n" +
" \"dataRepositories\": [],\n" +
" \"tags\": null,\n" +
" \"externalDatasets\": [],\n" +
" \"profile\": {\n" +
" \"id\": \"2a6e0835-349e-412c-9fcc-8e1298ce8a5a\",\n" +
" \"label\": \"Horizon 2020\",\n" +
" \"hint\": null\n" +
" },\n" +
" \"modifiedAt\": 1579077898000,\n" +
" \"hint\": \"datasetOverviewModel\"\n" +
" }\n" +
" ],\n" +
" \"associatedProfiles\": [\n" +
" {\n" +
" \"id\": \"f41bd794-761d-4fe8-ab67-3a989d982c53\",\n" +
" \"label\": \"Swedish Research Council\"\n" +
" },\n" +
" {\n" +
" \"id\": \"2a6e0835-349e-412c-9fcc-8e1298ce8a5a\",\n" +
" \"label\": \"Horizon 2020\"\n" +
" }\n" +
" ],\n" +
" \"researchers\": [],\n" +
" \"users\": [\n" +
" {\n" +
" \"id\": \"00476b4d-0491-44ca-b2fd-92e695062a48\",\n" +
" \"name\": \"OpenDMP OpenDMP\",\n" +
" \"role\": 0,\n" +
" \"email\": \"opendmpeu@gmail.com\",\n" +
" \"hint\": \"UserInfoListingModel\"\n" +
" }\n" +
" ],\n" +
" \"description\": null,\n" +
" \"publishedAt\": 1586444334000,\n" +
" \"doi\": \"10.5072/zenodo.522151\",\n" +
" \"hint\": \"dataManagementPlanOverviewModel\"\n" +
" }\n" +
"}";
@Autowired
public PublicDmpsDocumentation(ApiContext apiContext, DataManagementPlanPublicManager dataManagementPlanManager) {
super(apiContext);
this.dataManagementPlanManager = dataManagementPlanManager;
}
@Operation(summary = "This method is used to get a listing of public dmps.", description = getPagedNotes)
@io.swagger.v3.oas.annotations.responses.ApiResponses(value = {@ApiResponse(
responseCode = "200",
description = "The following example is generated using:\n" +
"a) body: *{\"criteria\": {},\"length\": 2,\"offset\": 0,\"orderings\": {\"fields\": []} }*\n" +
"b) fieldsGroup: listing",
content = @Content(mediaType = APPLICATION_JSON_VALUE, examples = {@ExampleObject(
value = getPagedResponseExample
)})
)})
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanPublicListingModel>>> getPaged(@Valid @RequestBody @io.swagger.v3.oas.annotations.parameters.RequestBody(description = getPagedRequestBodyDescription) DataManagmentPlanPublicTableRequest dmpTableRequest,
@RequestParam @Parameter(description = getPagedRequestParamDescription, example = "listing") String fieldsGroup) throws Exception {
DataTableData<DataManagementPlanPublicListingModel> dataTable = this.dataManagementPlanManager.getPublicPaged(dmpTableRequest, fieldsGroup);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanPublicListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
}
@Operation(summary = "This method is used to get the overview of a public dmp.", description = getOverviewSinglePublicNotes)
@io.swagger.v3.oas.annotations.responses.ApiResponses(value = {@ApiResponse(
responseCode = "200",
description = "The following example is generated using id: *e9a73d77-adfa-4546-974f-4a4a623b53a8*",
content = @Content(mediaType = APPLICATION_JSON_VALUE, examples = {@ExampleObject(
value = getOverviewSinglePublicResponseExample
)})
)})
@RequestMapping(method = RequestMethod.GET, value = {"/{id}"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DataManagementPlanPublicModel>> getOverviewSinglePublic(@PathVariable @Parameter(description = "fetch the dmp with the given id", example = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") String id) throws Exception {
// try {
DataManagementPlanPublicModel dataManagementPlan = this.dataManagementPlanManager.getOverviewSinglePublic(id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanPublicModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
// } catch (Exception ex) {
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataManagementPlanOverviewModel>().status(ApiMessageCode.NO_MESSAGE).message(ex.getMessage()));
// }
}
}