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

253 lines
15 KiB
Java

package eu.eudat.publicapi.controllers;
import eu.eudat.controllers.BaseController;
import eu.eudat.logic.security.claims.ClaimedAuthorities;
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.models.data.security.Principal;
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 eu.eudat.types.Authorities;
import io.swagger.annotations.*;
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;
@Api(tags = "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" +
" 1. **message**: string, message indicating error, null if everything went well\n" +
" 2. **statusCode**: integer, status code indicating if something unexpected happened, otherwise 0\n" +
" 3. **responseType**: integer, 0 for json, 1 for file\n" +
" 4. **payload**: DataTableData, containing the number of values of actual data returned and the data of type **DatasetPublicListingModel**\n" +
"4.1. id: string, id of dataset returned\n" +
"4.2. label: string, label of dataset\n" +
"4.3. grant: string, grant of dataset\n" +
"4.4. dmp: string, dmp description\n" +
"4.5. dmpId: string, dmp's id\n" +
"4.6. profile: DatasetProfilePublicModel, dataset's profile\n" +
"4.8. createdAt: date, creation date\n" +
"4.9. modifiedAt: date, modification date\n" +
"4.10. description: string, dataset's description\n" +
"4.11. finalizedAt: date, finalization date\n" +
"4.12. dmpPublishedAt: date, dmp's publication date\n" +
"4.13. version: integer, dataset's version\n" +
"4.14. users: list of UserInfoPublicModel, user who collaborated on the dataset\n";
public static final String getPagedResponseExample = "{\n" +
" \"statusCode\": 0,\n" +
" \"responseType\": 0,\n" +
" \"message\": null,\n" +
" \"payload\": {\n" +
" \"totalCount\": 2,\n" +
" \"data\": [\n" +
" {\n" +
" \"id\": \"aefc0f61-f2a7-410d-80c6-d3737afc0cd4\",\n" +
" \"label\": \"Copied 27: Agrion forcipula .\",\n" +
" \"grant\": \"Advanced Nitrogen Recovery from Sludge and other Organic Waste Materials (NITRO)\",\n" +
" \"dmp\": \"DMP_Advanced_Nitrogen_Recovery_from_Sludge_and_other_Organic_Waste_Materials_(NITRO)_0.xml\",\n" +
" \"dmpId\": \"8a8368a5-59e9-4d53-aaab-723da2df2d3b\",\n" +
" \"profile\": {\n" +
" \"id\": \"0b5b52f3-266a-45cf-8066-d1e5a70d65e1\",\n" +
" \"label\": \"Horizon 2020 (Devel Clone)\",\n" +
" \"hint\": null\n" +
" },\n" +
" \"createdAt\": 1652274681000,\n" +
" \"modifiedAt\": 1652275258000,\n" +
" \"description\": null,\n" +
" \"finalizedAt\": 1652275257000,\n" +
" \"dmpPublishedAt\": 1652276406000,\n" +
" \"version\": 0,\n" +
" \"users\": [\n" +
" {\n" +
" \"id\": \"4cb5671a-0575-4a50-878a-d1bdf59648a0\",\n" +
" \"name\": \"George Kalampokis\",\n" +
" \"role\": 0,\n" +
" \"email\": \"gkfortests@gmail.com\",\n" +
" \"hint\": \"UserInfoListingModel\"\n" +
" }\n" +
" ],\n" +
" \"hint\": \"datasetListingModel\"\n" +
" },\n" +
" {\n" +
" \"id\": \"f3b241fc-c692-4bb6-b10e-b2a4e2829f9e\",\n" +
" \"label\": \"manually 23\",\n" +
" \"grant\": \"Advanced Nitrogen Recovery from Sludge and other Organic Waste Materials (NITRO)\",\n" +
" \"dmp\": \"DMP_Advanced_Nitrogen_Recovery_from_Sludge_and_other_Organic_Waste_Materials_(NITRO)_0.xml\",\n" +
" \"dmpId\": \"8a8368a5-59e9-4d53-aaab-723da2df2d3b\",\n" +
" \"profile\": {\n" +
" \"id\": \"0b5b52f3-266a-45cf-8066-d1e5a70d65e1\",\n" +
" \"label\": \"Horizon 2020 (Devel Clone)\",\n" +
" \"hint\": null\n" +
" },\n" +
" \"createdAt\": 1652274735000,\n" +
" \"modifiedAt\": 1652275259000,\n" +
" \"description\": null,\n" +
" \"finalizedAt\": 1652275258000,\n" +
" \"dmpPublishedAt\": 1652276406000,\n" +
" \"version\": 0,\n" +
" \"users\": [\n" +
" {\n" +
" \"id\": \"4cb5671a-0575-4a50-878a-d1bdf59648a0\",\n" +
" \"name\": \"George Kalampokis\",\n" +
" \"role\": 0,\n" +
" \"email\": \"gkfortests@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" +
"• **length**: how many datasets should be fetched *(required)*\n" + "• **offset**: offset of the returned datasets, first time should be 0, then offset += length\n" +
"• **orderings**: array of strings specifying the order, format:= +string or -string or asc or desc. " +
"**+** means ascending order. **-** means descending order.\n&nbsp;&nbsp;&nbsp;&nbsp;Available strings are: 1) status, 2) label, 3) created.\n" +
"&nbsp;&nbsp;&nbsp;&nbsp;**asc** equivalent to +label.\n&nbsp;&nbsp;&nbsp;&nbsp;**desc** equivalent to -label.\n" +
"**criteria**: this is DatasetPublicCriteria object which applies filters for the datasets returned. More specifically:\n" +
" 1. periodStart: date, datasets created date greater than periodStart\n" +
" 2. periodEnd: date, datasets created date less than periodEnd\n" +
" 3. grants: list of uuids, dmps(datasets) with the corresponding grants\n" +
" 4. collaborators: list of uuids, user who collaborated on the creation/modification of datasets\n" +
" 5. datasetTemplates: list of uuids, dataset templates uuids to be included\n" +
" 6. dmpOrganisations: list of strings, datasets involved in dmps which belong to these organisations\n" +
" 7. tags: list of Tag objects, tags involved in datasets\n" +
" 8. dmpIds: list of uuids, dmps with the specific ids\n" +
" 9. groupIds: list of uuids, in which groups the datasets are\n" +
"10. allVersions: boolean, if datasets should be fetched with all their versions\n" +
"11. like: string, datasets fetched have this string matched in their label or description\n";
public static final String getOverviewSinglePublicNotes = "The json response is of type **ResponseItem< DatasetPublicModel >** containing the following properties:\n" +
" 1. **message**: string, message indicating error, null if everything went well\n" +
" 2. **statusCode**: integer, status code indicating if something unexpected happened, otherwise 0\n" +
" 3. **responseType**: integer, 0 for json, 1 for file\n" +
" 4. **payload**: DatasetPublicModel, dmp returned\n" +
"4.1. id: uuid, id of dataset returned\n" +
"4.2. label: string, label of dataset\n" +
"4.3. reference: string, reference of dataset\n" +
"4.4. uri: string, uri of dataset\n" +
"4.5. description: string, dataset's description\n" +
"4.6. status: string, dataset's status\n" +
"4.7. createdAt: date, creation time of dataset\n" +
"4.8. dmp: DataManagementPlanPublicListingModel, dmp to which dataset belongs\n" +
"4.9. datasetProfileDefinition: PagedDatasetProfile, dataset's paged description\n" +
"4.10. registries: list of RegistryPublicModel, dataset's registries\n" +
"4.11. services: list of ServicePublicModel, dataset's services\n" +
"4.12. dataRepositories: list of DataRepositoryPublicModel, dataset's data repositories\n" +
"4.13. tags: list of Tag, dataset's tags\n" +
"4.14. externalDatasets: list of ExternalDatasetPublicListingModel, dataset's external datasets\n" +
"4.15. profile: DatasetProfilePublicModel, dataset's profile\n" +
"4.16. modifiedAt: date, modification time of dataset\n";
public static final String getOverviewSinglePublicResponseExample = "{\n" +
" \"statusCode\": 0,\n" +
" \"responseType\": 0,\n" +
" \"message\": null,\n" +
" \"payload\": {\n" +
" \"id\": \"aefc0f61-f2a7-410d-80c6-d3737afc0cd4\",\n" +
" \"label\": \"Copied 27: Agrion forcipula .\",\n" +
" \"reference\": null,\n" +
" \"uri\": null,\n" +
" \"description\": null,\n" +
" \"status\": 1,\n" +
" \"createdAt\": 1652274681000,\n" +
" \"dmp\": {\n" +
" \"id\": \"8a8368a5-59e9-4d53-aaab-723da2df2d3b\",\n" +
" \"label\": \"DMP_Advanced_Nitrogen_Recovery_from_Sludge_and_other_Organic_Waste_Materials_(NITRO)_0.xml\",\n" +
" \"grant\": \"Advanced Nitrogen Recovery from Sludge and other Organic Waste Materials (NITRO)\",\n" +
" \"createdAt\": 1652274679000,\n" +
" \"modifiedAt\": 1652276406000,\n" +
" \"version\": 0,\n" +
" \"groupId\": \"5c3f8569-e3f2-4701-a5f0-8d8b2c07cc49\",\n" +
" \"users\": [\n" +
" {\n" +
" \"id\": \"4cb5671a-0575-4a50-878a-d1bdf59648a0\",\n" +
" \"name\": \"George Kalampokis\",\n" +
" \"role\": 0,\n" +
" \"email\": \"gkfortests@gmail.com\",\n" +
" \"hint\": \"UserInfoListingModel\"\n" +
" }\n" +
" ],\n" +
" \"finalizedAt\": 1652276406000,\n" +
" \"publishedAt\": 1652276406000,\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\": \"0b5b52f3-266a-45cf-8066-d1e5a70d65e1\",\n" +
" \"label\": \"Horizon 2020 (Devel Clone)\",\n" +
" \"hint\": null\n" +
" },\n" +
" \"modifiedAt\": 1652275258000,\n" +
" \"hint\": \"datasetOverviewModel\"\n" +
" }\n" +
"}";
@Autowired
public PublicDatasetsDescriptionDocumentation(ApiContext apiContext, DatasetPublicManager datasetManager) {
super(apiContext);
this.datasetManager = datasetManager;
}
@ApiOperation(value = "This method is used to get a listing of public datasets.", notes = getPagedNotes)
@ApiResponses(value = {@ApiResponse(
code = 200,
message = "The following example is generated using body: *{\"criteria\": {},\"length\": 2,\"offset\": 0,\"orderings\": {\"fields\": []} }*",
examples = @Example({@ExampleProperty(
value = getPagedResponseExample,
mediaType = APPLICATION_JSON_VALUE
)})
)})
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<DatasetPublicListingModel>>> getPaged(@RequestBody @ApiParam(value = 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));
}
@ApiOperation(value = "This method is used to get the overview of a public dataset.", notes = getOverviewSinglePublicNotes)
@ApiResponses(value = {@ApiResponse(
code = 200,
message = "The following example is generated using id: *aefc0f61-f2a7-410d-80c6-d3737afc0cd4*",
examples = @Example({@ExampleProperty(
value = getOverviewSinglePublicResponseExample,
mediaType = APPLICATION_JSON_VALUE
)})
)})
@RequestMapping(method = RequestMethod.GET, value = {"/{id}"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DatasetPublicModel>> getOverviewSinglePublic(@PathVariable @ApiParam(value = "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()));
// }
}
}