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

267 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.DatasetPublicManager;
import eu.eudat.publicapi.models.listingmodels.DatasetPublicListingModel;
import eu.eudat.publicapi.models.overviewmodels.DatasetPublicModel;
import eu.eudat.publicapi.request.dataset.DatasetPublicTableRequest;
import eu.eudat.types.ApiMessageCode;
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 = "Datasets Description", description = "Provides Dataset description public API's.")
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/public/datasets/"})
public class PublicDatasetsDescriptionDocumentation extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(PublicDatasetsDescriptionDocumentation.class);
private DatasetPublicManager datasetManager;
public static final String getPagedNotes = "The json response is of type **ResponseItem<DataTableData< DatasetPublicListingModel >>** 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>DatasetPublicListingModel</b></li>" +
" <ol>" +
" <li>id: string, id of dataset returned</li>" +
" <li>label: string, label of dataset</li>" +
" <li>grant: string, grant of dataset</li>" +
" <li>dmp: string, dmp description</li>" +
" <li>dmpId: string, dmp's id</li>" +
" <li>profile: DatasetProfilePublicModel, dataset's profile</li>" +
" <li>createdAt: date, creation date</li>" +
" <li>modifiedAt: date, modification date</li>" +
" <li>description: string, dataset's description</li>" +
" <li>finalizedAt: date, finalization date</li>" +
" <li>dmpPublishedAt: date, dmp's publication date</li>" +
" <li>version: integer, dataset's version</li>" +
" <li>users: list of UserInfoPublicModel, user who collaborated on the dataset</li>" +
" </ol>" +
"</ol>";
public static final String getPagedResponseExample = "{\n" +
" \"statusCode\": 0,\n" +
" \"responseType\": 0,\n" +
" \"message\": null,\n" +
" \"payload\": {\n" +
" \"totalCount\": 2,\n" +
" \"data\": [\n" +
" {\n" +
" \"id\": \"ef7dfbdc-c5c1-46a7-a37b-c8d8692f1c0e\",\n" +
" \"label\": \"BARKAMOL RIVOJLANGAN SHAXSNI TARBIYALASHDA HARAKATLI O`YINLARNING O`RNI\",\n" +
" \"grant\": \"A next generation nano media tailored to capture and recycle hazardous micropollutants in contaminated industrial wastewater.\",\n" +
" \"dmp\": \"test for demo\",\n" +
" \"dmpId\": \"9dee6e72-7a4c-4fbd-b8a4-1f8cda38eb5e\",\n" +
" \"profile\": {\n" +
" \"id\": \"771283d7-a5be-4a93-bd3c-8b1883fe837c\",\n" +
" \"label\": \"Horizon Europe\",\n" +
" \"hint\": null\n" +
" },\n" +
" \"createdAt\": 1662711279000,\n" +
" \"modifiedAt\": 1662712928000,\n" +
" \"description\": \"<p>&nbsp; &nbsp; &nbsp;Annotatsiya &nbsp;Maqolada &nbsp;bolalarni &nbsp;o`yin &nbsp;mavjud &nbsp;bo`lgan &nbsp;shakllarda &nbsp;mavjud&nbsp;<br>\\nhayot &nbsp;bilan &nbsp;kengroq &nbsp;tanishtirishga &nbsp;imkon &nbsp;beradi. &nbsp;O`yin &nbsp;bolalarning &nbsp;turli &nbsp;xil&nbsp;<br>\\nfaoliyati,o`yin &nbsp;ko`nikmalarini &nbsp;shakllantirishga &nbsp;yordam &nbsp;beradi.Ularni &nbsp;fikrlash, &nbsp;his-<br>\\ntuyg`ular, tajribalar, o`yin muammosini hal qilishning faol usullarini izlash, ularning&nbsp;<br>\\no`yin sharoitlari va sharoitlariga bo`ysunishi, o`yindagi bolalarning munosabatlari,&nbsp;<br>\\no`yin orqali bola organik rivojlanadi, &nbsp;inson madaniyatining muhim qatlami kattalar&nbsp;<br>\\no`rtasidagi &nbsp;munosabatlar &nbsp;- &nbsp;oilada, &nbsp;ularning &nbsp;kasbiy &nbsp;faoliyati &nbsp;va &nbsp;boshqalar. &nbsp;O`yin&nbsp;<br>\\no`qituvchilar barcha ta&rsquo;lim vazifalarini, shu jumladan o`rganishni hal qiladigan eng&nbsp;<br>\\nmuhim faoliyat sifatida foydalaniladi.&nbsp;</p>\",\n" +
" \"finalizedAt\": 1662712928000,\n" +
" \"dmpPublishedAt\": 1662713226000,\n" +
" \"version\": 0,\n" +
" \"users\": [\n" +
" {\n" +
" \"id\": \"33024e48-d528-45a5-8035-ea48641bd2f2\",\n" +
" \"name\": \"DMP author\",\n" +
" \"role\": 0,\n" +
" \"email\": \"kanavou.p@gmail.com\",\n" +
" \"hint\": \"UserInfoListingModel\"\n" +
" }\n" +
" ],\n" +
" \"hint\": \"datasetListingModel\"\n" +
" },\n" +
" {\n" +
" \"id\": \"0f253ab2-18cb-4798-adc1-135b81cfad0c\",\n" +
" \"label\": \"A \\\"zoom-elit\\\" és a kamionosok küzdelme, avagy a meritokrácia és a populizmus összecsapása\",\n" +
" \"grant\": \"Discovery Projects - Grant ID: DP140100157\",\n" +
" \"dmp\": \"TEST UPDATE 2.8.2022\",\n" +
" \"dmpId\": \"1f4daa8f-4e2f-4dc9-a60b-f6b75d313400\",\n" +
" \"profile\": {\n" +
" \"id\": \"3d43ba45-25fa-4815-81b4-9bf22ecd8316\",\n" +
" \"label\": \"HE_Final\",\n" +
" \"hint\": null\n" +
" },\n" +
" \"createdAt\": 1659392761000,\n" +
" \"modifiedAt\": 1659393655000,\n" +
" \"description\": \"<p>A kanadai kamionosok &bdquo;szabads&aacute;gmenete&rdquo; kapcs&aacute;n a&nbsp;New York Times&nbsp;has&aacute;bjain Ross Donthat publicista egy r&eacute;gi k&ouml;nyvre h&iacute;vja fel a figyelmet, amely sok &eacute;vtizeddel ezelőtt megj&oacute;solta az elit elleni hasonl&oacute; l&aacute;zad&aacute;sokat.</p>\",\n" +
" \"finalizedAt\": 1659393654000,\n" +
" \"dmpPublishedAt\": 1659393698000,\n" +
" \"version\": 0,\n" +
" \"users\": [\n" +
" {\n" +
" \"id\": \"33024e48-d528-45a5-8035-ea48641bd2f2\",\n" +
" \"name\": \"DMP author\",\n" +
" \"role\": 0,\n" +
" \"email\": \"kanavou.p@gmail.com\",\n" +
" \"hint\": \"UserInfoListingModel\"\n" +
" }\n" +
" ],\n" +
" \"hint\": \"datasetListingModel\"\n" +
" }\n" +
" ]\n" +
" }\n" +
"}";
public static final String getPagedRequestBodyDescription = "The datasetTableRequest is a DatasetPublicTableRequest object with the following fields:\n" +
"<ul>" +
"<li><b>length</b>: how many datasets should be fetched <i>(required)</i></li>" +
"<li><b>offset</b>: offset of the returned datasets, 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) 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 DatasetPublicCriteria object which applies filters for the datasets returned. More specifically:</li>" +
" <ol>" +
" <li>periodStart: date, datasets created date greater than periodStart</li>" +
" <li>periodEnd: date, datasets created date less than periodEnd</li>" +
" <li>grants: list of uuids, dmps(datasets) with the corresponding grants</li>" +
" <li>collaborators: list of uuids, user who collaborated on the creation/modification of datasets</li>" +
" <li>datasetTemplates: list of uuids, dataset templates uuids to be included</li>" +
" <li>dmpOrganisations: list of strings, datasets involved in dmps which belong to these organisations</li>" +
" <li>tags: list of Tag objects, tags involved in datasets</li>" +
" <li>dmpIds: list of uuids, dmps with the specific ids</li>" +
" <li>groupIds: list of uuids, in which groups the datasets are</li>" +
" <li>allVersions: boolean, if datasets should be fetched with all their versions</li>" +
" <li>like: string, datasets fetched have this string matched in their label or description</li>" +
" </ol>" +
"</ul>";
public static final String getOverviewSinglePublicNotes = "The json response is of type **ResponseItem< DatasetPublicModel >** 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>: DatasetPublicModel, dmp returned</li>" +
" <ol>" +
" <li>id: uuid, id of dataset returned</li>" +
" <li>label: string, label of dataset</li>" +
" <li>reference: string, reference of dataset</li>" +
" <li>uri: string, uri of dataset</li>" +
" <li>description: string, dataset's description</li>" +
" <li>status: string, dataset's status</li>" +
" <li>createdAt: date, creation time of dataset</li>" +
" <li>dmp: DataManagementPlanPublicListingModel, dmp to which dataset belongs</li>" +
" <li>datasetProfileDefinition: PagedDatasetProfile, dataset's paged description</li>" +
" <li>registries: list of RegistryPublicModel, dataset's registries</li>" +
" <li>services: list of ServicePublicModel, dataset's services</li>" +
" <li>dataRepositories: list of DataRepositoryPublicModel, dataset's data repositories</li>" +
" <li>tags: list of Tag, dataset's tags</li>" +
" <li>externalDatasets: list of ExternalDatasetPublicListingModel, dataset's external datasets</li>" +
" <li>profile: DatasetProfilePublicModel, dataset's profile</li>" +
" <li>modifiedAt: date, modification time of dataset</li>" +
" </ol>" +
"</ol>";
public static final String getOverviewSinglePublicResponseExample = "{\n" +
" \"statusCode\": 0,\n" +
" \"responseType\": 0,\n" +
" \"message\": null,\n" +
" \"payload\": {\n" +
" \"id\": \"ef7dfbdc-c5c1-46a7-a37b-c8d8692f1c0e\",\n" +
" \"label\": \"BARKAMOL RIVOJLANGAN SHAXSNI TARBIYALASHDA HARAKATLI O`YINLARNING O`RNI\",\n" +
" \"reference\": null,\n" +
" \"uri\": null,\n" +
" \"description\": \"<p>&nbsp; &nbsp; &nbsp;Annotatsiya &nbsp;Maqolada &nbsp;bolalarni &nbsp;o`yin &nbsp;mavjud &nbsp;bo`lgan &nbsp;shakllarda &nbsp;mavjud&nbsp;<br>\\nhayot &nbsp;bilan &nbsp;kengroq &nbsp;tanishtirishga &nbsp;imkon &nbsp;beradi. &nbsp;O`yin &nbsp;bolalarning &nbsp;turli &nbsp;xil&nbsp;<br>\\nfaoliyati,o`yin &nbsp;ko`nikmalarini &nbsp;shakllantirishga &nbsp;yordam &nbsp;beradi.Ularni &nbsp;fikrlash, &nbsp;his-<br>\\ntuyg`ular, tajribalar, o`yin muammosini hal qilishning faol usullarini izlash, ularning&nbsp;<br>\\no`yin sharoitlari va sharoitlariga bo`ysunishi, o`yindagi bolalarning munosabatlari,&nbsp;<br>\\no`yin orqali bola organik rivojlanadi, &nbsp;inson madaniyatining muhim qatlami kattalar&nbsp;<br>\\no`rtasidagi &nbsp;munosabatlar &nbsp;- &nbsp;oilada, &nbsp;ularning &nbsp;kasbiy &nbsp;faoliyati &nbsp;va &nbsp;boshqalar. &nbsp;O`yin&nbsp;<br>\\no`qituvchilar barcha ta&rsquo;lim vazifalarini, shu jumladan o`rganishni hal qiladigan eng&nbsp;<br>\\nmuhim faoliyat sifatida foydalaniladi.&nbsp;</p>\",\n" +
" \"status\": 1,\n" +
" \"createdAt\": 1662711279000,\n" +
" \"dmp\": {\n" +
" \"id\": \"9dee6e72-7a4c-4fbd-b8a4-1f8cda38eb5e\",\n" +
" \"label\": \"test for demo\",\n" +
" \"grant\": \"A next generation nano media tailored to capture and recycle hazardous micropollutants in contaminated industrial wastewater.\",\n" +
" \"createdAt\": 1662710691000,\n" +
" \"modifiedAt\": 1662713226000,\n" +
" \"version\": 0,\n" +
" \"groupId\": \"adaa4e17-7375-45b8-b052-09edaeb6da86\",\n" +
" \"users\": [\n" +
" {\n" +
" \"id\": \"33024e48-d528-45a5-8035-ea48641bd2f2\",\n" +
" \"name\": \"DMP author\",\n" +
" \"role\": 0,\n" +
" \"email\": \"kanavou.p@gmail.com\",\n" +
" \"hint\": \"UserInfoListingModel\"\n" +
" }\n" +
" ],\n" +
" \"finalizedAt\": 1662713226000,\n" +
" \"publishedAt\": 1662713226000,\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\": \"771283d7-a5be-4a93-bd3c-8b1883fe837c\",\n" +
" \"label\": \"Horizon Europe\",\n" +
" \"hint\": null\n" +
" },\n" +
" \"modifiedAt\": 1662712928000,\n" +
" \"hint\": \"datasetOverviewModel\"\n" +
" }\n" +
"}";
@Autowired
public PublicDatasetsDescriptionDocumentation(ApiContext apiContext, DatasetPublicManager datasetManager) {
super(apiContext);
this.datasetManager = datasetManager;
}
@Operation(summary = "This method is used to get a listing of public datasets.", description = getPagedNotes)
@io.swagger.v3.oas.annotations.responses.ApiResponses(value = {@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "200",
description = "The following example is generated using body: *{\"criteria\": {},\"length\": 2,\"offset\": 0,\"orderings\": {\"fields\": []} }*",
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<DatasetPublicListingModel>>> getPaged(@Valid @RequestBody @io.swagger.v3.oas.annotations.parameters.RequestBody(description = getPagedRequestBodyDescription) DatasetPublicTableRequest datasetTableRequest) throws Exception {
DataTableData<DatasetPublicListingModel> dataTable = this.datasetManager.getPublicPaged(datasetTableRequest);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DatasetPublicListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
}
@Operation(summary = "This method is used to get the overview of a public dataset.", description = getOverviewSinglePublicNotes)
@io.swagger.v3.oas.annotations.responses.ApiResponses(value = {@ApiResponse(
responseCode = "200",
description = "The following example is generated using id: *ef7dfbdc-c5c1-46a7-a37b-c8d8692f1c0e*",
content = @Content(mediaType = APPLICATION_JSON_VALUE, examples = {@ExampleObject(
value = getOverviewSinglePublicResponseExample
)})
)})
@RequestMapping(method = RequestMethod.GET, value = {"/{id}"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DatasetPublicModel>> getOverviewSinglePublic(@PathVariable @Parameter(description = "fetch the dataset with the given id", example = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") String id) throws Exception {
// try {
DatasetPublicModel dataset = this.datasetManager.getOverviewSinglePublic(id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetPublicModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataset));
// } catch (Exception ex) {
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataManagementPlanOverviewModel>().status(ApiMessageCode.NO_MESSAGE).message(ex.getMessage()));
// }
}
}