diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java index a2ab25f0..8801e8b9 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityApiController.java @@ -286,8 +286,142 @@ public class CommunityApiController extends AbstractExporterController { } } - @GetMapping({ "/community/{id}/contentproviders", "/community/{id}/datasources" }) - @Operation(summary = "get the list of content providers associated to a given community", description = "get the list of content providers associated to a given community", tags = { + // Datasources + + @GetMapping("/community/{id}/datasources") + @Operation(summary = "get the list of datasources associated to a given community", description = "get the list of content providers associated to a given community", tags = { + C_CP, R + }) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") + }) + public List getCommunityDatasources(@PathVariable final String id, @RequestParam(required = false) final Boolean deposit) + throws CommunityException { + try { + return deposit == null ? communityService.getCommunityDatasources(id) : communityService.getCommunityDatasourcesWithDeposit(id, deposit); + } catch (final ResourceNotFoundException e) { + throw e; + } catch (final Throwable e) { + throw new CommunityException(e); + } + } + + @PostMapping("/community/{id}/datasources") + @Operation(summary = "associate a datasource to the community", description = "associate a datasource to the community", tags = { + C_CP, W + }) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") + }) + public CommunityContentprovider addCommunityDatasource( + @PathVariable final String id, + @RequestBody final CommunityContentprovider datasource) throws CommunityException { + + try { + communityService.addCommunityDatasources(id, datasource); + return datasource; + } catch (final ResourceNotFoundException e) { + throw e; + } catch (final Throwable e) { + throw new CommunityException(e); + } + } + + @PostMapping("/community/{id}/datasources/deposit") + @Operation(summary = "associate a datasource to the community", description = "associate a datasource to the community", tags = { + C_CP, W + }) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") + }) + public CommunityContentprovider addCommunityDatasourceDeposit( + @PathVariable final String id, + @RequestBody final DepositionInfo info) throws CommunityException { + try { + return communityService.updateCommunityDatasourcesDeposit(id, info.getOpenaireId(), info.getDeposit(), info.getMessage()); + } catch (final ResourceNotFoundException e) { + throw e; + } catch (final Throwable e) { + throw new CommunityException(e); + } + } + + @DeleteMapping("/community/{id}/datasources") + @Operation(summary = "remove the association between a datasource and the community", description = "remove the association between a datasource and the community", tags = { + C_CP, W + }) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") + }) + public void removeCommunityDatasource( + @PathVariable final String id, + @RequestParam final String dsId) throws CommunityException { + try { + communityService.removeCommunityDatasources(id, dsId); + } catch (final ResourceNotFoundException e) { + throw e; + } catch (final Throwable e) { + throw new CommunityException(e); + } + } + + @PostMapping("/community/{id}/datasourcesList") + @Operation(summary = "associate a list of datasources to the community", description = "associate a list of datasources to the community", tags = { + C_CP, W + }) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") + }) + public CommunityContentprovider[] addCommunityDatasourcesList( + @PathVariable final String id, + @RequestBody final CommunityContentprovider[] dsList) throws CommunityException { + + try { + communityService.addCommunityDatasources(id, dsList); + return dsList; + } catch (final ResourceNotFoundException e) { + throw e; + } catch (final Throwable e) { + throw new CommunityException(e); + } + } + + @DeleteMapping("/community/{id}/datasourcesList") + @Operation(summary = "remove a list of datasources from the community", description = "remove a list of datasources from the community", tags = { + C_CP, W + }) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") + }) + public void deleteCommunityDatasourcesList( + @PathVariable final String id, + @RequestBody final String[] dsIdList) throws CommunityException { + try { + communityService.removeCommunityDatasources(id, dsIdList); + } catch (final ResourceNotFoundException e) { + throw e; + } catch (final Throwable e) { + throw new CommunityException(e); + } + } + + // Content Providers (DEPRECATED) + + @Deprecated + @GetMapping("/community/{id}/contentproviders") + @Operation(summary = "get the list of datasources associated to a given community", description = "get the list of content providers associated to a given community", tags = { C_CP, R }) @ApiResponses(value = { @@ -306,8 +440,9 @@ public class CommunityApiController extends AbstractExporterController { } } - @PostMapping({ "/community/{id}/contentproviders", "/community/{id}/datasources" }) - @Operation(summary = "associate a content provider to the community", description = "associate a content provider to the community", tags = { + @Deprecated + @PostMapping("/community/{id}/contentproviders") + @Operation(summary = "associate a datasource to the community", description = "associate a datasource to the community", tags = { C_CP, W }) @ApiResponses(value = { @@ -329,29 +464,9 @@ public class CommunityApiController extends AbstractExporterController { } } - @PostMapping("/community/{id}/datasources/deposit") - @Operation(summary = "associate a content provider to the community", description = "associate a content provider to the community", tags = { - C_CP, W - }) - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") - }) - public CommunityContentprovider addCommunityContentprovider( - @PathVariable final String id, - @RequestBody final DepositionInfo info) throws CommunityException { - try { - return communityService.updateCommunityDatasourcesDeposit(id, info.getOpenaireId(), info.getDeposit(), info.getMessage()); - } catch (final ResourceNotFoundException e) { - throw e; - } catch (final Throwable e) { - throw new CommunityException(e); - } - } - - @DeleteMapping({ "/community/{id}/contentproviders", "/community/{id}/datasources" }) - @Operation(summary = "remove the association between a content provider and the community", description = "remove the association between a content provider and the community", tags = { + @Deprecated + @DeleteMapping("/community/{id}/contentproviders") + @Operation(summary = "remove the association between a datasource and the community", description = "remove the association between a datasource and the community", tags = { C_CP, W }) @ApiResponses(value = { @@ -371,8 +486,9 @@ public class CommunityApiController extends AbstractExporterController { } } - @PostMapping({ "/community/{id}/contentprovidersList", "/community/{id}/datasourcesList" }) - @Operation(summary = "associate a list of content providers to the community", description = "associate a list of content providers to the community", tags = { + @Deprecated + @PostMapping("/community/{id}/contentprovidersList") + @Operation(summary = "associate a list of datasources to the community", description = "associate a list of datasources to the community", tags = { C_CP, W }) @ApiResponses(value = { @@ -394,8 +510,9 @@ public class CommunityApiController extends AbstractExporterController { } } - @DeleteMapping({ "/community/{id}/contentprovidersList", "/community/{id}/datasourcesList" }) - @Operation(summary = "remove a list of content providers from the community", description = "remove a list of content providers from the community", tags = { + @Deprecated + @DeleteMapping("/community/{id}/contentprovidersList") + @Operation(summary = "remove a list of datasources from the community", description = "remove a list of datasources from the community", tags = { C_CP, W }) @ApiResponses(value = { @@ -415,7 +532,7 @@ public class CommunityApiController extends AbstractExporterController { } } - // ADDING CODE FOR COMMUNITY ORGANIZATIONS + // ORGANIZATIONS @GetMapping("/community/{id}/organizations") @Operation(summary = "get the list of organizations for a given community", description = "get the list of organizations for a given community", tags = {