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.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 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 javax.validation.Valid; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @Api(tags = "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>** 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 **DataManagementPlanPublicListingModel**\n" + "4.1. id: string, id of dmp returned\n" + "4.2. label: string, label of dmp\n" + "4.3. grant: string, grant of dmp\n" + "4.4. createdAt: date, creation time of dmp\n" + "4.5. modifiedAt: date, modification time of dmp\n" + "4.6. version: integer, version of dmp\n" + "4.7. groupId: uuid, group id in which dmp belongs\n" + "4.8. users: list of UserInfoPublicModel, user who collaborated on the dmp\n" + "4.9. finalizedAt: date, finalization date\n" + "4.10. publishedAt: date, publication date\n"; private static final String getPagedResponseExample = "{\n" + " \"statusCode\": 0,\n" + " \"responseType\": 0,\n" + " \"message\": null,\n" + " \"payload\": {\n" + " \"totalCount\": 2,\n" + " \"data\": [\n" + " {\n" + " \"id\": \"912d87de-fce9-48e0-84a7-d5499d10682d\",\n" + " \"label\": \"Dmp For Project : 0/ANDRE\",\n" + " \"grant\": \"0/ANDRE\",\n" + " \"createdAt\": 1554128271000,\n" + " \"modifiedAt\": 1554128271000,\n" + " \"version\": 0,\n" + " \"groupId\": \"764ec97d-2475-4a75-843f-d620cffbdc3f\",\n" + " \"users\": [],\n" + " \"finalizedAt\": 1554128271000,\n" + " \"publishedAt\": 1554128271000,\n" + " \"hint\": \"dataManagementPlanListingModel\"\n" + " },\n" + " {\n" + " \"id\": \"43809706-0176-4d5c-b47c-c240ac5d874e\",\n" + " \"label\": \"Dmp new version clone\",\n" + " \"grant\": \"SMAD\",\n" + " \"createdAt\": 1539593145000,\n" + " \"modifiedAt\": 1539593145000,\n" + " \"version\": 2,\n" + " \"groupId\": \"536d9779-166e-4b55-ad3e-f93c06338598\",\n" + " \"users\": [],\n" + " \"finalizedAt\": 1539593145000,\n" + " \"publishedAt\": 1539593145000,\n" + " \"hint\": \"dataManagementPlanListingModel\"\n" + " }\n" + " ]\n" + " }\n" + "}"; private static final String getPagedRequestBodyDescription = "The dmpTableRequest is a DataManagementPlanPublicTableRequest object with the following fields:\n" + "• **length**: how many dmps should be fetched *(required)*\n" + "• **offset**: offset of the returned dmps, 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    Available strings are: 1) status, 2) label, 3) publishedAt, 4) created.\n" + "    **asc** equivalent to +label.\n    **desc** equivalent to -label.\n" + "**criteria**: this is DataManagementPlanPublicCriteria object which applies filters for the dmp returned. More specifically:\n" + " 1. periodStart: date, dmps created date greater than periodStart\n" + " 2. periodEnd: date, dmps created date less than periodEnd\n" + " 3. grants: list of uuids, dmps with the corresponding grants\n" + " 4. funders: list of uuids, dmps with the corresponding funders\n" + " 5. datasetTemplates: list of uuids, dataset templates which are described in the dmps\n" + " 6. dmpOrganisations: list of strings, dmps belonging to these organisations\n" + " 7. collaborators: list of uuids, user who collaborated on the creation/modification of dmps\n" + " 8. allVersions: boolean, if dmps should be fetched with all their versions\n" + " 9. groupIds: list of uuids, in which groups the dmps are\n" + "10. like: string, dmps fetched have this string matched in their label or description\n"; 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" + "**listing**: returns objects with all their properties completed\n" + "**autocomplete**: returns objects with only id, label, groupId and creationTime assigned"; private static final String getOverviewSinglePublicNotes = "The json response is of type **ResponseItem< DataManagementPlanPublicModel >** 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**: DataManagementPlanPublicModel, dmp returned\n" + "4.1. id: string, id of dmp returned\n" + "4.2. label: string, label of dmp\n" + "4.3. profile: string, profile of dmp\n" + "4.4. grant: GrantPublicOverviewModel, grant of dmp\n" + "4.5. createdAt: date, creation time of dmp\n" + "4.6. modifiedAt: date, modification time of dmp\n" + "4.7. finalizedAt: date, finalization date of dmp\n" + "4.8. organisations: list of OrganizationPublicModel, organizations in which dmp belongs\n" + "4.9. version: integer, version of dmp\n" + "4.10. groupId: uuid, group id in which dmp belongs\n" + "4.11. datasets: list of DatasetPublicModel, contained datasets\n" + "4.12. associatedProfiles: list of AssociatedProfilePublicModel, associated profiles of dmp\n" + "4.13. researchers: list of ResearcherPublicModel, researchers involved in dmp\n" + "4.14. users: list of UserInfoPublicModel, user who collaborated on the dmp\n" + "4.15. description: string, description of dmp\n" + "4.16. publishedAt: date, publication date\n" + "4.17. doi: string, if dmp has been published to zenodo so it has doi\n"; private static final String getOverviewSinglePublicResponseExample = "{\n" + " \"statusCode\": 0,\n" + " \"responseType\": 0,\n" + " \"message\": null,\n" + " \"payload\": {\n" + " \"id\": \"912d87de-fce9-48e0-84a7-d5499d10682d\",\n" + " \"label\": \"Dmp For Project : 0/ANDRE\",\n" + " \"profile\": null,\n" + " \"grant\": {\n" + " \"id\": \"79d35744-3bf4-4178-8bb0-bbc7110788d5\",\n" + " \"label\": \"0/ANDRE\",\n" + " \"abbreviation\": null,\n" + " \"description\": null,\n" + " \"startDate\": null,\n" + " \"endDate\": null,\n" + " \"uri\": null,\n" + " \"funder\": {\n" + " \"id\": \"baa92ce2-5ed8-4af0-8b9d-8eeabb8c3dbc\",\n" + " \"label\": \"0/ANDRE\",\n" + " \"hint\": null\n" + " },\n" + " \"hint\": null\n" + " },\n" + " \"createdAt\": 1554128271000,\n" + " \"modifiedAt\": 1554128271000,\n" + " \"finalizedAt\": 1554128271000,\n" + " \"organisations\": [],\n" + " \"version\": 0,\n" + " \"groupId\": \"764ec97d-2475-4a75-843f-d620cffbdc3f\",\n" + " \"datasets\": [\n" + " {\n" + " \"id\": \"ac0bf9b2-5804-456c-a5eb-6f797f888a28\",\n" + " \"label\": \"Dataset : Checks export order For Dmp : Dmp For Project : 0/ANDRE\",\n" + " \"reference\": null,\n" + " \"uri\": null,\n" + " \"description\": null,\n" + " \"status\": 1,\n" + " \"createdAt\": 1554127718000,\n" + " \"dmp\": {\n" + " \"id\": \"912d87de-fce9-48e0-84a7-d5499d10682d\",\n" + " \"label\": \"Dmp For Project : 0/ANDRE\",\n" + " \"grant\": \"0/ANDRE\",\n" + " \"createdAt\": 1554128271000,\n" + " \"modifiedAt\": 1554128271000,\n" + " \"version\": 0,\n" + " \"groupId\": \"764ec97d-2475-4a75-843f-d620cffbdc3f\",\n" + " \"users\": [\n" + " {\n" + " \"id\": \"e602dad2-2814-401b-b03f-ba05ba799bdc\",\n" + " \"name\": \"Georgios Kolokythas\",\n" + " \"role\": 0,\n" + " \"email\": \"iamgeorgioskolokythas@gmail.com\",\n" + " \"hint\": \"UserInfoListingModel\"\n" + " }\n" + " ],\n" + " \"finalizedAt\": 1554128271000,\n" + " \"publishedAt\": 1554128271000,\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\": \"01a85982-7cec-41c5-b1f1-74a646e0368b\",\n" + " \"label\": \"Checks export order\",\n" + " \"hint\": null\n" + " },\n" + " \"modifiedAt\": 1554128182000,\n" + " \"hint\": \"datasetOverviewModel\"\n" + " }\n" + " ],\n" + " \"associatedProfiles\": [\n" + " {\n" + " \"id\": \"01a85982-7cec-41c5-b1f1-74a646e0368b\",\n" + " \"label\": \"Checks export order\"\n" + " }\n" + " ],\n" + " \"researchers\": [],\n" + " \"users\": [\n" + " {\n" + " \"id\": \"e602dad2-2814-401b-b03f-ba05ba799bdc\",\n" + " \"name\": \"Georgios Kolokythas\",\n" + " \"role\": 0,\n" + " \"email\": \"iamgeorgioskolokythas@gmail.com\",\n" + " \"hint\": \"UserInfoListingModel\"\n" + " }\n" + " ],\n" + " \"description\": \"Hello\",\n" + " \"publishedAt\": 1554128271000,\n" + " \"doi\": null,\n" + " \"hint\": \"dataManagementPlanOverviewModel\"\n" + " }\n" + "}"; @Autowired public PublicDmpsDocumentation(ApiContext apiContext, DataManagementPlanPublicManager dataManagementPlanManager) { super(apiContext); this.dataManagementPlanManager = dataManagementPlanManager; } @ApiOperation(value = "This method is used to get a listing of public dmps.", notes = getPagedNotes) @ApiResponses(value = {@ApiResponse( code = 200, message = "The following example is generated using:\n" + "a) body: *{\"criteria\": {},\"length\": 2,\"offset\": 0,\"orderings\": {\"fields\": []} }*\n" + "b) fieldsGroup: listing", examples = @Example({@ExampleProperty( value = getPagedResponseExample, mediaType = APPLICATION_JSON_VALUE )}) )}) @RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>> getPaged(@Valid @RequestBody @ApiParam(value = getPagedRequestBodyDescription) DataManagmentPlanPublicTableRequest dmpTableRequest, @RequestParam @ApiParam(value = getPagedRequestParamDescription, example = "listing") String fieldsGroup) throws Exception { DataTableData dataTable = this.dataManagementPlanManager.getPublicPaged(dmpTableRequest, fieldsGroup); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable)); } @ApiOperation(value = "This method is used to get the overview of a public dmp.", notes = getOverviewSinglePublicNotes) @ApiResponses(value = {@ApiResponse( code = 200, message = "The following example is generated using id: *912d87de-fce9-48e0-84a7-d5499d10682d*", examples = @Example({@ExampleProperty( value = getOverviewSinglePublicResponseExample, mediaType = APPLICATION_JSON_VALUE )}) )}) @RequestMapping(method = RequestMethod.GET, value = {"/{id}"}, produces = "application/json") public @ResponseBody ResponseEntity> getOverviewSinglePublic(@PathVariable @ApiParam(value = "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().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan)); // } catch (Exception ex) { // return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).message(ex.getMessage())); // } } }