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 ae228039..6c04fc68 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 @@ -18,14 +18,16 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.data.domain.Page; import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import eu.dnetlib.openaire.common.AbstractExporterController; +import eu.dnetlib.openaire.community.model.DepositionInfo; import eu.dnetlib.openaire.exporter.exceptions.CommunityException; import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException; import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider; @@ -44,7 +46,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; @RestController @CrossOrigin(origins = { - "*" + "*" }) @ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true") @Tag(name = "OpenAIRE Communities API", description = "the OpenAIRE Community API") @@ -53,15 +55,13 @@ public class CommunityApiController extends AbstractExporterController { @Autowired private CommunityService communityService; - @RequestMapping(value = "/community/communities", produces = { - "application/json" - }, method = RequestMethod.GET) + @GetMapping("/community/communities") @Operation(summary = "get all community profiles", description = "get all community profiles", tags = { - C, R + C, R }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public List listCommunities() throws CommunityException { try { @@ -73,16 +73,14 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/", produces = { - "application/json" - }, method = RequestMethod.POST) + @PostMapping("/community/") @Operation(summary = "add a new community profile", description = "add a new community profile", tags = { - C, W + C, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public CommunityDetails getCommunity(@RequestBody final CommunityDetails details) throws CommunityException { try { @@ -94,16 +92,14 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}", produces = { - "application/json" - }, method = RequestMethod.GET) + @GetMapping("/community/{id}") @Operation(summary = "get community profile", description = "get community profile", tags = { - C, R + C, R }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public CommunityDetails getCommunity(@PathVariable final String id) throws CommunityException { try { @@ -115,20 +111,18 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}", produces = { - "application/json" - }, method = RequestMethod.POST) + @PostMapping("/community/{id}") @Operation(summary = "update community details", description = "update community details", tags = { - C, W + C, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public void setCommunity( - @PathVariable final String id, - @RequestBody final CommunityWritableProperties properties) throws CommunityException { + @PathVariable final String id, + @RequestBody final CommunityWritableProperties properties) throws CommunityException { try { communityService.setCommunity(id, properties); } catch (final ResourceNotFoundException e) { @@ -138,19 +132,17 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}", produces = { - "application/json" - }, method = RequestMethod.DELETE) + @DeleteMapping("/community/{id}") @Operation(summary = "delete a community", description = "delete a community", tags = { - C, W + C, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public void deleteCommunity(@PathVariable final String id, @RequestParam(required = false, defaultValue = "false") final boolean recursive) - throws CommunityException { + throws CommunityException { try { communityService.deleteCommunity(id, recursive); } catch (final ResourceNotFoundException e) { @@ -160,24 +152,22 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/projects/{page}/{size}", produces = { - "application/json" - }, method = RequestMethod.GET) + @GetMapping("/community/{id}/projects/{page}/{size}") @Operation(summary = "get community projects", description = "get community projects", tags = { - C_PJ, R + C_PJ, R }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public Page getCommunityProjects(@PathVariable final String id, - @PathVariable final Integer page, - @PathVariable final Integer size, - @RequestParam(required = false) final String funder, - @RequestParam(required = false) final String searchFilter, - @RequestParam(required = false) final String orderBy) - throws CommunityException { + @PathVariable final Integer page, + @PathVariable final Integer size, + @RequestParam(required = false) final String funder, + @RequestParam(required = false) final String searchFilter, + @RequestParam(required = false) final String orderBy) + throws CommunityException { try { return communityService.getCommunityProjects(id, funder, searchFilter, page, size, orderBy); } catch (final ResourceNotFoundException e) { @@ -187,20 +177,18 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/projects", produces = { - "application/json" - }, method = RequestMethod.POST) - @Operation(summary = "associate a project to the community", description = "associate a project to the community", tags = { - C_PJ, W + @PostMapping("/community/{id}/projects") + @Operation(summary = "associate a project to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", description = "associate a project to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", tags = { + C_PJ, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public CommunityProject addCommunityProject( - @PathVariable final String id, - @RequestBody final CommunityProject project) throws CommunityException { + @PathVariable final String id, + @RequestBody final CommunityProject project) throws CommunityException { try { return communityService.addCommunityProject(id, project); @@ -211,20 +199,18 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/projects", produces = { - "application/json" - }, method = RequestMethod.DELETE) + @DeleteMapping("/community/{id}/projects") @Operation(summary = "remove a project from the community", description = "remove a project from the community", tags = { - C_PJ, W + C_PJ, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public void deleteCommunityProject( - @PathVariable final String id, - @RequestParam final String projectId) throws CommunityException { + @PathVariable final String id, + @RequestParam final String projectId) throws CommunityException { try { communityService.removeCommunityProjects(id, projectId); } catch (final ResourceNotFoundException e) { @@ -234,20 +220,18 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/projectList", produces = { - "application/json" - }, method = RequestMethod.POST) + @PostMapping("/community/{id}/projectList") @Operation(summary = "associate a list of project to the community", description = "associate a list of project to the community", tags = { - C_PJ, W + C_PJ, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public CommunityProject[] addCommunityProjectList( - @PathVariable final String id, - @RequestBody final CommunityProject[] projects) throws CommunityException { + @PathVariable final String id, + @RequestBody final CommunityProject[] projects) throws CommunityException { try { communityService.addCommunityProjects(id, projects); return projects; @@ -258,20 +242,18 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/projectList", produces = { - "application/json" - }, method = RequestMethod.DELETE) + @DeleteMapping("/community/{id}/projectList") @Operation(summary = "remove a list of projects from the community", description = "remove a list of projects from the community", tags = { - C_PJ, W + C_PJ, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public void deleteCommunityProjectList( - @PathVariable final String id, - @RequestBody final String[] projectIdList) throws CommunityException { + @PathVariable final String id, + @RequestBody final String[] projectIdList) throws CommunityException { try { communityService.removeCommunityProjects(id, projectIdList); } catch (final ResourceNotFoundException e) { @@ -281,19 +263,17 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/funders", produces = { - "application/json" - }, method = RequestMethod.GET) + @GetMapping("/community/{id}/funders") @Operation(summary = "get the funders of the projects of a community", description = "get the funders of the projects of a community", tags = { - C_PJ, R + C_PJ, R }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public List getCommunityFunders(@PathVariable final String id) - throws CommunityException { + throws CommunityException { try { return communityService.getCommunityFunders(id); } catch (final ResourceNotFoundException e) { @@ -303,20 +283,21 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/contentproviders", produces = { - "application/json" - }, method = RequestMethod.GET) - @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 = { - C_CP, R + // 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") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) - public List getCommunityContentproviders(@PathVariable final String id) throws CommunityException { + public List getCommunityDatasources(@PathVariable final String id, @RequestParam(required = false) final Boolean deposit) + throws CommunityException { try { - return communityService.getCommunityContentproviders(id); + return deposit == null ? communityService.getCommunityDatasources(id) : communityService.getCommunityDatasourcesWithDeposit(id, deposit); } catch (final ResourceNotFoundException e) { throw e; } catch (final Throwable e) { @@ -324,114 +305,205 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/contentproviders", produces = { - "application/json" - }, method = RequestMethod.POST) - @Operation(summary = "associate a content provider to the community", description = "associate a content provider to the community", tags = { - C_CP, W + @PostMapping("/community/{id}/datasources") + @Operation(summary = "associate a datasource to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", description = "associate a datasource to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", tags = { + C_CP, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @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 = "update the deposit and message filelds of a datasource associated to the community", description = "update the deposit and message filelds of a datasource associated 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, provide all the fields or the method will overwrite with nulls the fields that are missing", description = "associate a list of datasources to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", 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 = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") + }) + public List getCommunityContentproviders(@PathVariable final String id, @RequestParam(required = false) final Boolean deposit) + throws CommunityException { + return getCommunityDatasources(id, deposit); + } + + @Deprecated + @PostMapping("/community/{id}/contentproviders") + @Operation(summary = "associate a datasource to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", description = "associate a datasource to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", 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 CommunityContentprovider contentprovider) throws CommunityException { + @PathVariable final String id, + @RequestBody final CommunityContentprovider contentprovider) throws CommunityException { - try { - communityService.addCommunityContentProviders(id, contentprovider); - return contentprovider; - } catch (final ResourceNotFoundException e) { - throw e; - } catch (final Throwable e) { - throw new CommunityException(e); - } + return addCommunityDatasource(id, contentprovider); } - @RequestMapping(value = "/community/{id}/contentproviders", produces = { - "application/json" - }, method = RequestMethod.DELETE) - @Operation(summary = "remove the association between a content provider and the community", description = "remove the association between a content provider and the community", tags = { - C_CP, W + @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 = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) - public void removeCommunityContentprovider( - @PathVariable final String id, - @RequestParam final String contentproviderId) throws CommunityException { - try { - communityService.removeCommunityContentProviders(id, contentproviderId); - } catch (final ResourceNotFoundException e) { - throw e; - } catch (final Throwable e) { - throw new CommunityException(e); - } + public void removeCommunityContentprovider(@PathVariable final String id, @RequestParam final String contentproviderId) throws CommunityException { + removeCommunityDatasource(id, contentproviderId); } - @RequestMapping(value = "/community/{id}/contentprovidersList", produces = { - "application/json" - }, method = RequestMethod.POST) - @Operation(summary = "associate a list of content providers to the community", description = "associate a list of content providers to the community", tags = { - C_CP, W + @Deprecated + @PostMapping("/community/{id}/contentprovidersList") + @Operation(summary = "associate a list of datasources to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", description = "associate a list of datasources to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", tags = { + C_CP, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public CommunityContentprovider[] addCommunityContentProvidersList( - @PathVariable final String id, - @RequestBody final CommunityContentprovider[] contentprovidersList) throws CommunityException { - - try { - communityService.addCommunityContentProviders(id, contentprovidersList); - return contentprovidersList; - } catch (final ResourceNotFoundException e) { - throw e; - } catch (final Throwable e) { - throw new CommunityException(e); - } + @PathVariable final String id, + @RequestBody final CommunityContentprovider[] contentprovidersList) throws CommunityException { + return addCommunityDatasourcesList(id, contentprovidersList); } - @RequestMapping(value = "/community/{id}/contentprovidersList", produces = { - "application/json" - }, method = RequestMethod.DELETE) - @Operation(summary = "remove a list of content providers from the community", description = "remove a list of content providers from the community", tags = { - C_CP, W + @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 = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public void deleteCommunityContentProvidersList( - @PathVariable final String id, - @RequestBody final String[] contentProviderIdList) throws CommunityException { - try { - communityService.removeCommunityContentProviders(id, contentProviderIdList); - } catch (final ResourceNotFoundException e) { - throw e; - } catch (final Throwable e) { - throw new CommunityException(e); - } + @PathVariable final String id, + @RequestBody final String[] contentProviderIdList) throws CommunityException { + deleteCommunityDatasourcesList(id, contentProviderIdList); } - // ADDING CODE FOR COMMUNITY ORGANIZATIONS + // ORGANIZATIONS - @RequestMapping(value = "/community/{id}/organizations", produces = { - "application/json" - }, method = RequestMethod.GET) + @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 = { - C_O, R + C_O, R }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public List getCommunityOrganizations(@PathVariable final String id) throws CommunityException { try { @@ -443,20 +515,18 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/organizations", produces = { - "application/json" - }, method = RequestMethod.POST) - @Operation(summary = "associate an organization to the community", description = "associate an organization to the community", tags = { - C_O, W + @PostMapping("/community/{id}/organizations") + @Operation(summary = "associate an organization to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", description = "associate an organization to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", tags = { + C_O, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public CommunityOrganization addCommunityOrganization( - @PathVariable final String id, - @RequestBody final CommunityOrganization organization) throws CommunityException { + @PathVariable final String id, + @RequestBody final CommunityOrganization organization) throws CommunityException { try { communityService.addCommunityOrganizations(id, organization); return organization; @@ -467,20 +537,18 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/organizationList", produces = { - "application/json" - }, method = RequestMethod.POST) - @Operation(summary = "associate a list of organizations to the community", description = "associate a list of organizations to the community", tags = { - C_O, W + @PostMapping("/community/{id}/organizationList") + @Operation(summary = "associate a list of organizations to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", description = "associate a list of organizations to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", tags = { + C_O, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public CommunityOrganization[] addCommunityOrganizationList( - @PathVariable final String id, - @RequestBody final CommunityOrganization[] orgs) throws CommunityException { + @PathVariable final String id, + @RequestBody final CommunityOrganization[] orgs) throws CommunityException { try { communityService.addCommunityOrganizations(id, orgs); @@ -492,20 +560,18 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/organizations", produces = { - "application/json" - }, method = RequestMethod.DELETE) + @DeleteMapping("/community/{id}/organizations") @Operation(summary = "remove the association between an organization and the community", description = "remove the association between an organization and the community", tags = { - C_O, W + C_O, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public void removeCommunityOrganization( - @PathVariable final String id, - @RequestParam final String organizationName) throws CommunityException { + @PathVariable final String id, + @RequestParam final String organizationName) throws CommunityException { try { communityService.removeCommunityOrganizations(id, organizationName); } catch (final ResourceNotFoundException e) { @@ -515,20 +581,18 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/organizationList", produces = { - "application/json" - }, method = RequestMethod.DELETE) + @DeleteMapping("/community/{id}/organizationList") @Operation(summary = "remove a list of associations between some organizations and the community", description = "remove a list of associations between some organizations and the community", tags = { - C_O, W + C_O, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public void removeCommunityOrganizationList( - @PathVariable final String id, - @RequestBody final String[] orgNames) throws CommunityException { + @PathVariable final String id, + @RequestBody final String[] orgNames) throws CommunityException { try { communityService.removeCommunityOrganizations(id, orgNames); } catch (final ResourceNotFoundException e) { @@ -540,20 +604,18 @@ public class CommunityApiController extends AbstractExporterController { // ********************** - @RequestMapping(value = "/community/{id}/subjects", produces = { - "application/json" - }, method = RequestMethod.POST) + @PostMapping("/community/{id}/subjects") @Operation(summary = "associate a subject to the community", description = "associate a subject to the community", tags = { - C, W + C, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public CommunityDetails addCommunitySubjects( - @PathVariable final String id, - @RequestBody final String[] subjects) throws CommunityException { + @PathVariable final String id, + @RequestBody final String[] subjects) throws CommunityException { try { return communityService.addCommunitySubjects(id, subjects); @@ -564,20 +626,18 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/subjects", produces = { - "application/json" - }, method = RequestMethod.DELETE) + @DeleteMapping("/community/{id}/subjects") @Operation(summary = "remove subjects from a community", description = "remove subjects from a community", tags = { - C, W + C, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public CommunityDetails removeCommunitySubjects( - @PathVariable final String id, - @RequestBody final String[] subjects) throws CommunityException { + @PathVariable final String id, + @RequestBody final String[] subjects) throws CommunityException { try { return communityService.removeCommunitySubjects(id, subjects); @@ -588,20 +648,18 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/fos", produces = { - "application/json" - }, method = RequestMethod.POST) + @PostMapping("/community/{id}/fos") @Operation(summary = "associate a fos to the community", description = "associate a fos to the community", tags = { - C, W + C, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public CommunityDetails addCommunityFOS( - @PathVariable final String id, - @RequestBody final String[] subjects) throws CommunityException { + @PathVariable final String id, + @RequestBody final String[] subjects) throws CommunityException { try { return communityService.addCommunityFOS(id, subjects); @@ -612,20 +670,18 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/fos", produces = { - "application/json" - }, method = RequestMethod.DELETE) + @DeleteMapping("/community/{id}/fos") @Operation(summary = "remove fos from a community", description = "remove fos from a community", tags = { - C, W + C, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public CommunityDetails removeCommunityFOS( - @PathVariable final String id, - @RequestBody final String[] subjects) throws CommunityException { + @PathVariable final String id, + @RequestBody final String[] subjects) throws CommunityException { try { return communityService.removeCommunityFOS(id, subjects); @@ -636,20 +692,18 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/sdg", produces = { - "application/json" - }, method = RequestMethod.POST) + @PostMapping("/community/{id}/sdg") @Operation(summary = "associate a sdg to the community", description = "associate a sdg to the community", tags = { - C, W + C, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public CommunityDetails addCommunitySDG( - @PathVariable final String id, - @RequestBody final String[] subjects) throws CommunityException { + @PathVariable final String id, + @RequestBody final String[] subjects) throws CommunityException { try { return communityService.addCommunitySDG(id, subjects); @@ -660,20 +714,18 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/sdg", produces = { - "application/json" - }, method = RequestMethod.DELETE) + @DeleteMapping("/community/{id}/sdg") @Operation(summary = "remove sdg from a community", description = "remove sdg from a community", tags = { - C, W + C, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public CommunityDetails removeCommunitySDG( - @PathVariable final String id, - @RequestBody final String[] subjects) throws CommunityException { + @PathVariable final String id, + @RequestBody final String[] subjects) throws CommunityException { try { return communityService.removeCommunitySDG(id, subjects); @@ -684,20 +736,18 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/advancedConstraint", produces = { - "application/json" - }, method = RequestMethod.POST) + @PostMapping("/community/{id}/advancedConstraint") @Operation(summary = "the set of constraints to be used to extend the association between result and community", description = "the set of constraints to be used to extend the association between result and community", tags = { - C, W + C, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public CommunityDetails addAdvancedConstraint( - @PathVariable final String id, - @RequestBody final SelectionCriteria advancedConstraint) throws CommunityException { + @PathVariable final String id, + @RequestBody final SelectionCriteria advancedConstraint) throws CommunityException { try { return communityService.addCommunityAdvancedConstraint(id, advancedConstraint); @@ -708,19 +758,17 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/advancedConstraint", produces = { - "application/json" - }, method = RequestMethod.DELETE) + @DeleteMapping("/community/{id}/advancedConstraint") @Operation(summary = "remove the constraints to extend the association result community from a community", description = "remove the constraints to extend the association result community from a community", tags = { - C, W + C, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public CommunityDetails removeAdvancedConstraint( - @PathVariable final String id) throws CommunityException { + @PathVariable final String id) throws CommunityException { try { return communityService.removeCommunityAdvancedConstraint(id); @@ -731,20 +779,18 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/removeConstraint", produces = { - "application/json" - }, method = RequestMethod.POST) + @PostMapping("/community/{id}/removeConstraint") @Operation(summary = "the set of constraints to be used to remove the association between result and community", description = "the set of constraints to be used to remove the association between result and community", tags = { - C, W + C, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public CommunityDetails addRemoveConstraint( - @PathVariable final String id, - @RequestBody final SelectionCriteria removeConstraint) throws CommunityException { + @PathVariable final String id, + @RequestBody final SelectionCriteria removeConstraint) throws CommunityException { try { return communityService.addCommunityRemoveConstraint(id, removeConstraint); @@ -755,16 +801,14 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/removeConstraint", produces = { - "application/json" - }, method = RequestMethod.DELETE) + @DeleteMapping("/community/{id}/removeConstraint") @Operation(summary = "remove the constraints to remove the association beetween result and community", description = "remove the constraints to remove the association beetween result and community", tags = { - C, W + C, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public CommunityDetails removeRemoveConstraint(@PathVariable final String id) throws CommunityException { @@ -777,21 +821,19 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/zenodocommunities", produces = { - "application/json" - }, method = RequestMethod.POST) + @PostMapping("/community/{id}/zenodocommunities") @Operation(summary = "associate a Zenodo community to the community", description = "associate a Zenodo community to the community", tags = { - C_ZC, W + C_ZC, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public CommunityDetails addCommunityZenodoCommunity( - @PathVariable final String id, - @RequestParam(required = false, defaultValue = "false") final boolean main, - @RequestParam final String zenodocommunity) throws CommunityException { + @PathVariable final String id, + @RequestParam(required = false, defaultValue = "false") final boolean main, + @RequestParam final String zenodocommunity) throws CommunityException { try { return communityService.addCommunityZenodoCommunity(id, zenodocommunity, main); @@ -803,21 +845,19 @@ public class CommunityApiController extends AbstractExporterController { } - @RequestMapping(value = "/community/{id}/zenodocommunities", produces = { - "application/json" - }, method = RequestMethod.DELETE) + @DeleteMapping("/community/{id}/zenodocommunities") @Operation(summary = "remove a Zenodo community from a community", description = "remove a Zenodo community from a community", tags = { - C_ZC, W + C_ZC, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public void removeCommunityZenodoCommunity( - @PathVariable final String id, - @RequestParam(required = false, defaultValue = "false") final boolean main, - @RequestParam final String zenodocommunity) throws CommunityException { + @PathVariable final String id, + @RequestParam(required = false, defaultValue = "false") final boolean main, + @RequestParam final String zenodocommunity) throws CommunityException { try { communityService.removeCommunityZenodoCommunity(id, zenodocommunity, main); } catch (final ResourceNotFoundException e) { @@ -827,16 +867,14 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{zenodoId}/openairecommunities", produces = { - "application/json" - }, method = RequestMethod.GET) + @GetMapping("/community/{zenodoId}/openairecommunities") @Operation(summary = "get the list of OpenAIRE communities associated to a given Zenodo community", description = "get the list of OpenAIRE communities associated to a given Zenodo community", tags = { - C_ZC, R + C_ZC, R }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public CommunityOpenAIRECommunities getOpenAireCommunities(@PathVariable final String zenodoId) throws CommunityException { try { @@ -852,16 +890,14 @@ public class CommunityApiController extends AbstractExporterController { } // APIs to manage the propagationOrganizationCommunityMap - @RequestMapping(value = "/propagationOrganizationCommunityMap", produces = { - "application/json" - }, method = RequestMethod.GET) + @GetMapping("/propagationOrganizationCommunityMap") @Operation(summary = "Get the propagationOrganizationCommunityMap", description = "propagationOrganizationCommunityMap", tags = { - C_O, R + C_O, R }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public Map> getPropagationOrganizationCommunityMap() throws CommunityException { try { @@ -873,16 +909,14 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/propagationOrganizations", produces = { - "application/json" - }, method = RequestMethod.GET) + @GetMapping("/community/{id}/propagationOrganizations") @Operation(summary = "try { return the propagation organizations of a community", description = "try { return the propagation organizations of a community", tags = { - C_O, R + C_O, R }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public Set getPropagationOrganizationsForCommunity(@PathVariable final String id) throws CommunityException { try { @@ -894,19 +928,17 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/propagationOrganizations", produces = { - "application/json" - }, method = RequestMethod.POST) + @PostMapping("/community/{id}/propagationOrganizations") @Operation(summary = "add an organization to the propagationOrganizationCommunityMap", description = "add an organization to the propagationOrganizationCommunityMap", tags = { - C_O, W + C_O, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public Set addPropagationOrganizationForCommunity(@PathVariable final String id, - @RequestParam final String organizationId) throws CommunityException { + @RequestParam final String organizationId) throws CommunityException { try { return communityService.addPropagationOrganizationForCommunity(id, organizationId.split(",")); @@ -917,19 +949,17 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/propagationOrganizations", produces = { - "application/json" - }, method = RequestMethod.DELETE) + @DeleteMapping("/community/{id}/propagationOrganizations") @Operation(summary = "delete an organization to the propagationOrganizationCommunityMap", description = "delete an organization to the propagationOrganizationCommunityMap", tags = { - C_O, W + C_O, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public Set removePropagationOrganizationForCommunity(@PathVariable final String id, - @RequestParam final String organizationId) throws CommunityException { + @RequestParam final String organizationId) throws CommunityException { try { return communityService.removePropagationOrganizationForCommunity(id, organizationId.split(",")); @@ -942,24 +972,22 @@ public class CommunityApiController extends AbstractExporterController { // APIs to manage the sub communities - @RequestMapping(value = "/community/{id}/subcommunities", produces = { - "application/json" - }, method = RequestMethod.GET) + @GetMapping("/community/{id}/subcommunities") @Operation(summary = "get the list of subcommunities for a given community", description = "get the list of subcommunities for a given community", tags = { - C_SUB, R + C_SUB, R }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public List getSubCommunities(@PathVariable final String id, @RequestParam(required = false, defaultValue = "false") final boolean all) - throws CommunityException { + throws CommunityException { try { return communityService.getSubCommunities(id) - .stream() - .filter(sc -> all || sc.isBrowsable()) - .collect(Collectors.toList()); + .stream() + .filter(sc -> all || sc.isBrowsable()) + .collect(Collectors.toList()); } catch (final ResourceNotFoundException e) { throw e; } catch (final Throwable e) { @@ -967,20 +995,18 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/subcommunities", produces = { - "application/json" - }, method = RequestMethod.POST) - @Operation(summary = "associate a subcommunity to the community", description = "associate a subcommunity to the community", tags = { - C_SUB, W + @PostMapping("/community/{id}/subcommunities") + @Operation(summary = "associate a subcommunity to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", description = "associate a subcommunity to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", tags = { + C_SUB, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public SubCommunity addSubCommunity( - @PathVariable final String id, - @RequestBody final SubCommunity subcommunity) throws CommunityException { + @PathVariable final String id, + @RequestBody final SubCommunity subcommunity) throws CommunityException { try { communityService.addSubCommunities(id, subcommunity); return subcommunity; @@ -991,20 +1017,18 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/subcommunitiesList", produces = { - "application/json" - }, method = RequestMethod.POST) - @Operation(summary = "associate a list of subcommunities to the community", description = "associate a list of subcommunities to the community", tags = { - C_SUB, W + @PostMapping("/community/{id}/subcommunitiesList") + @Operation(summary = "associate a list of subcommunities to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", description = "associate a list of subcommunities to the community, provide all the fields or the method will overwrite with nulls the fields that are missing", tags = { + C_SUB, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public SubCommunity[] addSubCommunityList( - @PathVariable final String id, - @RequestBody final SubCommunity[] subcommunities) throws CommunityException { + @PathVariable final String id, + @RequestBody final SubCommunity[] subcommunities) throws CommunityException { try { communityService.addSubCommunities(id, subcommunities); @@ -1016,20 +1040,18 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/subcommunities", produces = { - "application/json" - }, method = RequestMethod.DELETE) + @DeleteMapping("/community/{id}/subcommunities") @Operation(summary = "remove the association between a subcommunity and the community", description = "remove the association between a subcommunity and the community", tags = { - C_SUB, W + C_SUB, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public void removeSubCommunity( - @PathVariable final String id, - @RequestParam final String subCommunityId) throws CommunityException { + @PathVariable final String id, + @RequestParam final String subCommunityId) throws CommunityException { try { communityService.removeSubCommunities(id, subCommunityId); } catch (final ResourceNotFoundException e) { @@ -1039,20 +1061,18 @@ public class CommunityApiController extends AbstractExporterController { } } - @RequestMapping(value = "/community/{id}/subcommunitiesList", produces = { - "application/json" - }, method = RequestMethod.DELETE) + @DeleteMapping("/community/{id}/subcommunitiesList") @Operation(summary = "remove a list of associations between some subcommunities and the community", description = "remove a list of associations between some subcommunities and the community", tags = { - C_SUB, W + C_SUB, W }) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") }) public void removeSubcommunities( - @PathVariable final String id, - @RequestBody final String[] subCommunityIdList) throws CommunityException { + @PathVariable final String id, + @RequestBody final String[] subCommunityIdList) throws CommunityException { try { communityService.removeSubCommunities(id, subCommunityIdList); } catch (final ResourceNotFoundException e) { diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityService.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityService.java index defe39d1..6bb64753 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityService.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/CommunityService.java @@ -3,6 +3,7 @@ package eu.dnetlib.openaire.community; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -74,21 +75,17 @@ public class CommunityService { public List listCommunities() { return dbCommunityRepository.findAll() - .stream() - .map(CommunityMappingUtils::toCommunitySummary) - .collect(Collectors.toList()); + .stream() + .map(CommunityMappingUtils::toCommunitySummary) + .collect(Collectors.toList()); } @Transactional public CommunityDetails newCommunity(final CommunityDetails details) throws CommunityException { - if (StringUtils.isBlank(details.getId())) { - throw new CommunityException("Empty Id"); - } else if (dbCommunityRepository.existsById(details.getId())) { - throw new CommunityException("Community already exists: " + details.getId()); - } else { - details.setCreationDate(LocalDateTime.now()); - return saveCommunity(details); - } + if (StringUtils.isBlank(details.getId())) { throw new CommunityException("Empty Id"); } + if (dbCommunityRepository.existsById(details.getId())) { throw new CommunityException("Community already exists: " + details.getId()); } + details.setCreationDate(LocalDateTime.now()); + return saveCommunity(details); } @@ -115,23 +112,23 @@ public class CommunityService { @Transactional public Page getCommunityProjects(final String id, - final String funder, - final String filter, - final int page, - final int size, - final String orderBy) throws CommunityException { + final String funder, + final String filter, + final int page, + final int size, + final String orderBy) throws CommunityException { if (StringUtils.isBlank(id)) { throw new CommunityException("Empty ID"); } try { final Sort sort; if (StringUtils.isBlank(orderBy)) { sort = Sort.by("projectName"); - } else if (orderBy.equalsIgnoreCase("funder")) { + } else if ("funder".equalsIgnoreCase(orderBy)) { sort = Sort.by("projectFunder").and(Sort.by("projectName")); - } else if (orderBy.equalsIgnoreCase("grantId")) { + } else if ("grantId".equalsIgnoreCase(orderBy)) { sort = Sort.by("projectCode"); - } else if (orderBy.equalsIgnoreCase("acronym")) { + } else if ("acronym".equalsIgnoreCase(orderBy)) { sort = Sort.by("projectAcronym"); - } else if (orderBy.equalsIgnoreCase("openaireId")) { + } else if ("openaireId".equalsIgnoreCase(orderBy)) { sort = Sort.by("projectId"); } else { sort = Sort.by("projectName"); @@ -140,10 +137,9 @@ public class CommunityService { final PageRequest pageable = PageRequest.of(page, size, sort); if (StringUtils.isAllBlank(filter, funder)) { return dbProjectRepository.findByCommunity(id, pageable).map(CommunityMappingUtils::toCommunityProject); - } else { - final Specification projSpec = prepareProjectSpec(id, funder, filter); - return dbProjectRepository.findAll(projSpec, pageable).map(CommunityMappingUtils::toCommunityProject); } + final Specification projSpec = prepareProjectSpec(id, funder, filter); + return dbProjectRepository.findAll(projSpec, pageable).map(CommunityMappingUtils::toCommunityProject); } catch (final Throwable e) { log.error(e); throw new CommunityException(e); @@ -191,8 +187,8 @@ public class CommunityService { public void addCommunityProjects(final String id, final CommunityProject... projects) throws CommunityException { try { final List list = Arrays.stream(projects) - .map(p -> CommunityMappingUtils.toDbProject(id, p)) - .collect(Collectors.toList()); + .map(p -> CommunityMappingUtils.toDbProject(id, p)) + .collect(Collectors.toList()); dbProjectRepository.saveAll(list); } catch (final Throwable e) { @@ -204,56 +200,75 @@ public class CommunityService { @Transactional public void removeCommunityProjects(final String id, final String... ids) { final List list = Arrays.stream(ids) - .map(projectId -> new DbProjectPK(id, projectId)) - .collect(Collectors.toList()); + .map(projectId -> new DbProjectPK(id, projectId)) + .collect(Collectors.toList()); dbProjectRepository.deleteAllById(list); } - public List getCommunityContentproviders(final String id) { + public List getCommunityDatasources(final String id) { return dbDatasourceRepository.findByCommunity(id) - .stream() - .map(CommunityMappingUtils::toCommunityContentprovider) - .collect(Collectors.toList()); + .stream() + .map(CommunityMappingUtils::toCommunityContentprovider) + .collect(Collectors.toList()); + } + + public List getCommunityDatasourcesWithDeposit(final String id, final boolean deposit) { + return dbDatasourceRepository.findByCommunityAndDeposit(id, deposit) + .stream() + .map(CommunityMappingUtils::toCommunityContentprovider) + .collect(Collectors.toList()); } @Transactional - public void addCommunityContentProviders(final String id, final CommunityContentprovider... contentproviders) { + public CommunityContentprovider updateCommunityDatasourcesDeposit(final String id, final String dsId, final Boolean deposit, final String message) { + return dbDatasourceRepository.findById(new DbDatasourcePK(id, dsId)) + .map(ds -> { + ds.setDeposit(deposit != null ? deposit : false); + ds.setMessage(message); + return ds; + }) + .map(CommunityMappingUtils::toCommunityContentprovider) + .orElseThrow(() -> new ResourceNotFoundException("Community and/or Datasource not found")); + } + + @Transactional + public void addCommunityDatasources(final String id, final CommunityContentprovider... contentproviders) { final List list = Arrays.stream(contentproviders) - .map(cp -> CommunityMappingUtils.toDbDatasource(id, cp)) - .collect(Collectors.toList()); + .map(cp -> CommunityMappingUtils.toDbDatasource(id, cp)) + .collect(Collectors.toList()); dbDatasourceRepository.saveAll(list); } @Transactional - public void removeCommunityContentProviders(final String id, final String... ids) { + public void removeCommunityDatasources(final String id, final String... ids) { final List list = Arrays.stream(ids) - .map(dsId -> new DbDatasourcePK(id, dsId)) - .collect(Collectors.toList()); + .map(dsId -> new DbDatasourcePK(id, dsId)) + .collect(Collectors.toList()); dbDatasourceRepository.deleteAllById(list); } @Transactional public void removeCommunityOrganizations(final String id, final String... orgNames) { final List list = Arrays.stream(orgNames) - .map(name -> new DbSupportOrgPK(id, name)) - .collect(Collectors.toList()); + .map(name -> new DbSupportOrgPK(id, name)) + .collect(Collectors.toList()); dbSupportOrgRepository.deleteAllById(list); } @Transactional public List getCommunityOrganizations(final String id) { return dbSupportOrgRepository.findByCommunity(id) - .stream() - .map(CommunityMappingUtils::toCommunityOrganization) - .collect(Collectors.toList()); + .stream() + .map(CommunityMappingUtils::toCommunityOrganization) + .collect(Collectors.toList()); } @Transactional public void addCommunityOrganizations(final String id, final CommunityOrganization... orgs) { final List list = Arrays.stream(orgs) - .map(o -> CommunityMappingUtils.toDbSupportOrg(id, o)) - .collect(Collectors.toList()); + .map(o -> CommunityMappingUtils.toDbSupportOrg(id, o)) + .collect(Collectors.toList()); dbSupportOrgRepository.saveAll(list); } @@ -266,43 +281,43 @@ public class CommunityService { @Transactional public List getSubCommunities(final String id) { return dbSubCommunityRepository.findByCommunity(id) - .stream() - .map(CommunityMappingUtils::toSubCommunity) - .collect(Collectors.toList()); + .stream() + .map(CommunityMappingUtils::toSubCommunity) + .collect(Collectors.toList()); } @Transactional public void addSubCommunities(final String id, final SubCommunity... subs) { final List list = Arrays.stream(subs) - .map(s -> CommunityMappingUtils.toDbSubCommunity(id, s)) - .collect(Collectors.toList()); + .map(s -> CommunityMappingUtils.toDbSubCommunity(id, s)) + .collect(Collectors.toList()); dbSubCommunityRepository.saveAll(list); } @Transactional public CommunityDetails addCommunitySubjects(final String id, final String... subjects) { - return modifyElementToArrayField(id, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), false, subjects); + return modifyElementToArrayField(id, DbCommunity::getSubjects, DbCommunity::setSubjects, false, subjects); } public CommunityDetails removeCommunitySubjects(final String id, final String... subjects) { - return modifyElementToArrayField(id, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), true, subjects); + return modifyElementToArrayField(id, DbCommunity::getSubjects, DbCommunity::setSubjects, true, subjects); } public CommunityDetails addCommunityFOS(final String id, final String... foss) { - return modifyElementToArrayField(id, c -> c.getFos(), (c, fos) -> c.setFos(fos), false, foss); + return modifyElementToArrayField(id, DbCommunity::getFos, DbCommunity::setFos, false, foss); } public CommunityDetails removeCommunityFOS(final String id, final String... foss) { - return modifyElementToArrayField(id, c -> c.getFos(), (c, fos) -> c.setFos(fos), true, foss); + return modifyElementToArrayField(id, DbCommunity::getFos, DbCommunity::setFos, true, foss); } public CommunityDetails addCommunitySDG(final String id, final String... sdgs) { - return modifyElementToArrayField(id, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), false, sdgs); + return modifyElementToArrayField(id, DbCommunity::getSdg, DbCommunity::setSdg, false, sdgs); } public CommunityDetails removeCommunitySDG(final String id, final String... sdgs) { - return modifyElementToArrayField(id, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), true, sdgs); + return modifyElementToArrayField(id, DbCommunity::getSdg, DbCommunity::setSdg, true, sdgs); } @Transactional @@ -342,25 +357,19 @@ public class CommunityService { } public CommunityDetails removeCommunityZenodoCommunity(final String id, final String zenodoCommunity, final boolean isMain) { - if (isMain) { - return updateElementToSimpleField(id, (c, val) -> c.setMainZenodoCommunity(val), null); - } else { - return modifyElementToArrayField(id, c -> c.getOtherZenodoCommunities(), (c, arr) -> c.setOtherZenodoCommunities(arr), true, zenodoCommunity); - } + if (isMain) { return updateElementToSimpleField(id, DbCommunity::setMainZenodoCommunity, null); } + return modifyElementToArrayField(id, DbCommunity::getOtherZenodoCommunities, DbCommunity::setOtherZenodoCommunities, true, zenodoCommunity); } public CommunityDetails addCommunityZenodoCommunity(final String id, final String zenodoCommunity, final boolean isMain) { - if (isMain) { - return updateElementToSimpleField(id, (c, val) -> c.setMainZenodoCommunity(val), zenodoCommunity); - } else { - return modifyElementToArrayField(id, c -> c.getOtherZenodoCommunities(), (c, arr) -> c.setOtherZenodoCommunities(arr), false, zenodoCommunity); - } + if (isMain) { return updateElementToSimpleField(id, DbCommunity::setMainZenodoCommunity, zenodoCommunity); } + return modifyElementToArrayField(id, DbCommunity::getOtherZenodoCommunities, DbCommunity::setOtherZenodoCommunities, false, zenodoCommunity); } @Transactional private CommunityDetails updateElementToSimpleField(final String id, - final BiConsumer setter, - final String value) { + final BiConsumer setter, + final String value) { final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id)); setter.accept(dbEntry, value); dbEntry.setLastUpdateDate(LocalDateTime.now()); @@ -370,19 +379,17 @@ public class CommunityService { @Transactional private CommunityDetails modifyElementToArrayField(final String id, - final Function getter, - final BiConsumer setter, - final boolean remove, - final String... values) { + final Function getter, + final BiConsumer setter, + final boolean remove, + final String... values) { final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id)); final Set tmpList = new LinkedHashSet<>(); final String[] oldValues = getter.apply(dbEntry); if (oldValues != null) { - for (final String s : oldValues) { - tmpList.add(s); - } + Collections.addAll(tmpList, oldValues); } if (remove) { tmpList.removeAll(Arrays.asList(values)); @@ -407,16 +414,16 @@ public class CommunityService { @Transactional public Map> getPropagationOrganizationCommunityMap() { return dbOrganizationRepository.findAll() - .stream() - .collect(Collectors.groupingBy(DbOrganization::getOrgId, Collectors.mapping(DbOrganization::getCommunity, Collectors.toSet()))); + .stream() + .collect(Collectors.groupingBy(DbOrganization::getOrgId, Collectors.mapping(DbOrganization::getCommunity, Collectors.toSet()))); } @Transactional public Set getPropagationOrganizationsForCommunity(final String communityId) { return dbOrganizationRepository.findByCommunity(communityId) - .stream() - .map(DbOrganization::getOrgId) - .collect(Collectors.toSet()); + .stream() + .map(DbOrganization::getOrgId) + .collect(Collectors.toSet()); } @Transactional @@ -454,8 +461,8 @@ public class CommunityService { final List res = new ArrayList<>(); res.add(dbCommunityRepository.findById(id) - .map(CommunityMappingUtils::asIISConfigurationEntry) - .orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id))); + .map(CommunityMappingUtils::asIISConfigurationEntry) + .orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id))); for (final DbSubCommunity subc : dbSubCommunityRepository.findByCommunity(id)) { res.add(CommunityMappingUtils.asIISConfigurationEntry(subc)); diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/importer/CommunityImporterService.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/importer/CommunityImporterService.java index 224beee9..ec39e22d 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/importer/CommunityImporterService.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/importer/CommunityImporterService.java @@ -6,6 +6,7 @@ import java.util.Arrays; import java.util.Base64; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -115,23 +116,20 @@ public class CommunityImporterService { public List importPropagationOrganizationsFromProfile(final String xml, final boolean simulation) throws Exception { final String json = DocumentHelper.parseText(xml) - .selectSingleNode("//NODE[@name='setPropagationOrganizationCommunityMap']//PARAM[@name='parameterValue']") - .getText(); + .selectSingleNode("//NODE[@name='setPropagationOrganizationCommunityMap']//PARAM[@name='parameterValue']") + .getText(); final List list = new ObjectMapper() - .readValue(json, new TypeReference>>() {}) - .entrySet() - .stream() - .flatMap(e -> e.getValue() + .readValue(json, new TypeReference>>() {}) + .entrySet() .stream() - .map(community -> { - if (e.getKey().contains("|")) { - return new DbOrganization(community, StringUtils.substringAfter(e.getKey(), "|")); - } else { - return new DbOrganization(community, e.getKey()); - } - })) - .collect(Collectors.toList()); + .flatMap(e -> e.getValue() + .stream() + .map(community -> { + if (e.getKey().contains("|")) { return new DbOrganization(community, StringUtils.substringAfter(e.getKey(), "|")); } + return new DbOrganization(community, e.getKey()); + })) + .collect(Collectors.toList()); if (!simulation) { list.forEach(o -> { @@ -153,69 +151,69 @@ public class CommunityImporterService { final CommunityDetails community = asCommunityDetails(context); final List datasources = - getCommunityInfo(context, CONTENTPROVIDERS_ID_SUFFIX, c -> asCommunityDataprovider(context.getId(), c)) - .stream() - .map(o -> { - if (o.getOpenaireId() == null) { - log.warn("Openaire ID is missing, organization: " + o.getOfficialname()); - } else if (o.getOpenaireId().contains("|")) { - o.setOpenaireId(StringUtils.substringAfter(o.getOpenaireId(), "|")); - } - return o; - }) - .filter(o -> o.getOpenaireId() != null) - .collect(Collectors.toList()); + getCommunityInfo(context, CONTENTPROVIDERS_ID_SUFFIX, c -> asCommunityDataprovider(context.getId(), c)) + .stream() + .map(o -> { + if (o.getOpenaireId() == null) { + log.warn("Openaire ID is missing, organization: " + o.getOfficialname()); + } else if (o.getOpenaireId().contains("|")) { + o.setOpenaireId(StringUtils.substringAfter(o.getOpenaireId(), "|")); + } + return o; + }) + .filter(o -> o.getOpenaireId() != null) + .collect(Collectors.toList()); final List projects = - getCommunityInfo(context, PROJECTS_ID_SUFFIX, c -> asCommunityProject(context.getId(), c)) - .stream() - .map(p -> { - if (p.getOpenaireId() == null) { - if (p.getFunder().equalsIgnoreCase("EC")) { - final String ns = findNamespaceForECProject(p.getGrantId()); - if (ns != null) { - p.setOpenaireId(ns + "::" + Hashing.md5(p.getGrantId())); - } else { - log.warn("EC project not in the db: " + p.getGrantId()); + getCommunityInfo(context, PROJECTS_ID_SUFFIX, c -> asCommunityProject(context.getId(), c)) + .stream() + .map(p -> { + if (p.getOpenaireId() == null) { + if ("EC".equalsIgnoreCase(p.getFunder())) { + final String ns = findNamespaceForECProject(p.getGrantId()); + if (ns != null) { + p.setOpenaireId(ns + "::" + Hashing.md5(p.getGrantId())); + } else { + log.warn("EC project not in the db: " + p.getGrantId()); + } + } else if ("NSF".equalsIgnoreCase(p.getFunder())) { + p.setOpenaireId("nsf_________::" + Hashing.md5(p.getGrantId())); + } else if ("NIH".equalsIgnoreCase(p.getFunder())) { + p.setOpenaireId("nih_________::" + Hashing.md5(p.getGrantId())); + } else { + log.warn("Openaire ID is missing, funder: " + p.getFunder()); + } + } else if (p.getOpenaireId().contains("|")) { + p.setOpenaireId(StringUtils.substringAfter(p.getOpenaireId(), "|")); } - } else if (p.getFunder().equalsIgnoreCase("NSF")) { - p.setOpenaireId("nsf_________::" + Hashing.md5(p.getGrantId())); - } else if (p.getFunder().equalsIgnoreCase("NIH")) { - p.setOpenaireId("nih_________::" + Hashing.md5(p.getGrantId())); - } else { - log.warn("Openaire ID is missing, funder: " + p.getFunder()); - } - } else if (p.getOpenaireId().contains("|")) { - p.setOpenaireId(StringUtils.substringAfter(p.getOpenaireId(), "|")); - } - return p; - }) - .filter(p -> p.getOpenaireId() != null) - .collect(Collectors.toList()); + return p; + }) + .filter(p -> p.getOpenaireId() != null) + .collect(Collectors.toList()); final List orgs = - getCommunityInfo(context, ORGANIZATION_ID_SUFFIX, c -> asCommunityOrganization(context.getId(), c)); + getCommunityInfo(context, ORGANIZATION_ID_SUFFIX, c -> asCommunityOrganization(context.getId(), c)); final List otherZenodoCommunities = - getCommunityInfo(context, ZENODOCOMMUNITY_ID_SUFFIX, c -> asZenodoCommunity(c)); + getCommunityInfo(context, ZENODOCOMMUNITY_ID_SUFFIX, CommunityImporterService::asZenodoCommunity); community.setOtherZenodoCommunities(otherZenodoCommunities); final List subs = context.getCategories() - .entrySet() - .stream() - .filter(e -> !e.getKey().equals(context.getId() + CONTENTPROVIDERS_ID_SUFFIX)) - .filter(e -> !e.getKey().equals(context.getId() + PROJECTS_ID_SUFFIX)) - .filter(e -> !e.getKey().equals(context.getId() + ORGANIZATION_ID_SUFFIX)) - .filter(e -> !e.getKey().equals(context.getId() + ZENODOCOMMUNITY_ID_SUFFIX)) - .map(e -> e.getValue()) - .map(cat -> asSubCommunities(context.getId(), null, cat.getLabel(), cat.getConcepts())) - .flatMap(List::stream) - .collect(Collectors.toList()); + .entrySet() + .stream() + .filter(e -> !(context.getId() + CONTENTPROVIDERS_ID_SUFFIX).equals(e.getKey())) + .filter(e -> !(context.getId() + PROJECTS_ID_SUFFIX).equals(e.getKey())) + .filter(e -> !(context.getId() + ORGANIZATION_ID_SUFFIX).equals(e.getKey())) + .filter(e -> !(context.getId() + ZENODOCOMMUNITY_ID_SUFFIX).equals(e.getKey())) + .map(Entry::getValue) + .map(cat -> asSubCommunities(context.getId(), null, cat.getLabel(), cat.getConcepts())) + .flatMap(List::stream) + .collect(Collectors.toList()); service.saveCommunity(community); service.addCommunityProjects(context.getId(), projects.toArray(new CommunityProject[projects.size()])); - service.addCommunityContentProviders(context.getId(), datasources.toArray(new CommunityContentprovider[datasources.size()])); + service.addCommunityDatasources(context.getId(), datasources.toArray(new CommunityContentprovider[datasources.size()])); service.addCommunityOrganizations(context.getId(), orgs.toArray(new CommunityOrganization[orgs.size()])); service.addSubCommunities(context.getId(), subs.toArray(new SubCommunity[subs.size()])); } catch ( @@ -226,14 +224,14 @@ public class CommunityImporterService { } private List getCommunityInfo(final Context context, final String idSuffix, final Function mapping) - throws CommunityException { + throws CommunityException { if (context != null) { final Map categories = context.getCategories(); final Category category = categories.get(context.getId() + idSuffix); if (category != null) { return category.getConcepts() - .stream() - .map(mapping) - .collect(Collectors.toList()); } + .stream() + .map(mapping) + .collect(Collectors.toList()); } } return Lists.newArrayList(); } @@ -302,6 +300,8 @@ public class CommunityImporterService { d.setOfficialname(firstValue(CCONTENTPROVIDER_OFFICIALNAME, p)); d.setEnabled(BooleanUtils.toBoolean(firstValue(CCONTENTPROVIDER_ENABLED, p))); d.setSelectioncriteria(SelectionCriteria.fromJson(firstValue(CCONTENTPROVIDER_SELCRITERIA, p))); + d.setDeposit(false); + d.setMessage(null); return d; } @@ -339,7 +339,7 @@ public class CommunityImporterService { private String findNamespaceForECProject(final String code) { final List list = - jdbcTemplate.queryForList("SELECT substr(id, 1, 12) from projects where code = ? and id like 'corda%'", String.class, code); + jdbcTemplate.queryForList("SELECT substr(id, 1, 12) from projects where code = ? and id like 'corda%'", String.class, code); return list.isEmpty() ? null : list.get(0); } @@ -355,11 +355,11 @@ public class CommunityImporterService { private static List splitValues(final Stream stream, final String separator) { return stream.map(s -> s.split(separator)) - .map(Arrays::asList) - .flatMap(List::stream) - .filter(StringUtils::isNotBlank) - .map(StringUtils::trim) - .collect(Collectors.toList()); + .map(Arrays::asList) + .flatMap(List::stream) + .filter(StringUtils::isNotBlank) + .map(StringUtils::trim) + .collect(Collectors.toList()); } private static String firstValue(final String name, final List params) { @@ -372,13 +372,13 @@ public class CommunityImporterService { private static Stream asValues(final String name, final List params) { return params == null ? Stream.empty() - : params.stream() - .filter(p -> p != null) - .filter(p -> StringUtils.isNotBlank(p.getName())) - .filter(p -> p.getName().trim().equals(name.trim())) - .map(Param::getValue) - .map(StringUtils::trim) - .distinct(); + : params.stream() + .filter(p -> p != null) + .filter(p -> StringUtils.isNotBlank(p.getName())) + .filter(p -> p.getName().trim().equals(name.trim())) + .map(Param::getValue) + .map(StringUtils::trim) + .distinct(); } protected DbOrganizationRepository getDbOrganizationRepository() { diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/model/DbDatasource.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/model/DbDatasource.java index 685b141c..0ef70fa2 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/model/DbDatasource.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/model/DbDatasource.java @@ -40,6 +40,12 @@ public class DbDatasource implements Serializable { @Column(name = "constraints") private SelectionCriteria constraints; + @Column(name = "deposit") + private Boolean deposit; + + @Column(name = "message") + private String message; + public DbDatasource() {} public DbDatasource(final String community, final String dsId, final String dsName, final String dsOfficialName, final SelectionCriteria constraints) { @@ -98,4 +104,20 @@ public class DbDatasource implements Serializable { this.constraints = constraints; } + public Boolean getDeposit() { + return deposit; + } + + public void setDeposit(final Boolean deposit) { + this.deposit = deposit; + } + + public String getMessage() { + return message; + } + + public void setMessage(final String message) { + this.message = message; + } + } diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/model/DepositionInfo.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/model/DepositionInfo.java new file mode 100644 index 00000000..476ab549 --- /dev/null +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/model/DepositionInfo.java @@ -0,0 +1,39 @@ +package eu.dnetlib.openaire.community.model; + +import java.io.Serializable; + +public class DepositionInfo implements Serializable { + + private static final long serialVersionUID = 7538663287451167904L; + + private String openaireId; + + private Boolean deposit; + + private String message; + + public String getOpenaireId() { + return openaireId; + } + + public void setOpenaireId(final String openaireId) { + this.openaireId = openaireId; + } + + public Boolean getDeposit() { + return deposit; + } + + public void setDeposit(final Boolean deposit) { + this.deposit = deposit; + } + + public String getMessage() { + return message; + } + + public void setMessage(final String message) { + this.message = message; + } + +} diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/repository/DbDatasourceRepository.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/repository/DbDatasourceRepository.java index 6afbd38b..7dbea398 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/repository/DbDatasourceRepository.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/repository/DbDatasourceRepository.java @@ -13,5 +13,8 @@ public interface DbDatasourceRepository extends JpaRepository findByCommunity(String community); + List findByCommunityAndDeposit(String community, boolean deposit); + void deleteByCommunity(String id); + } diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/utils/CommunityMappingUtils.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/utils/CommunityMappingUtils.java index ed2de6a4..a72ac787 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/utils/CommunityMappingUtils.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/utils/CommunityMappingUtils.java @@ -189,6 +189,8 @@ public class CommunityMappingUtils { ccp.setOfficialname(dbEntry.getDsOfficialName()); ccp.setSelectioncriteria(dbEntry.getConstraints()); ccp.setEnabled(dbEntry.getEnabled() != null ? dbEntry.getEnabled() : true); + ccp.setDeposit(dbEntry.getDeposit() != null ? dbEntry.getDeposit() : false); + ccp.setMessage(dbEntry.getMessage()); return ccp; } @@ -200,6 +202,8 @@ public class CommunityMappingUtils { ds.setDsOfficialName(provider.getOfficialname()); ds.setConstraints(provider.getSelectioncriteria()); ds.setEnabled(provider.isEnabled()); + ds.setDeposit(provider.getDeposit() != null ? provider.getDeposit() : false); + ds.setMessage(provider.getMessage()); return ds; } @@ -262,8 +266,8 @@ public class CommunityMappingUtils { public static LocalDateTime asLocalDateTime(final Date date) { return date.toInstant() - .atZone(ZoneId.systemDefault()) - .toLocalDateTime(); + .atZone(ZoneId.systemDefault()) + .toLocalDateTime(); } private static String[] toStringArray(final List list) { diff --git a/apps/dnet-exporter-api/src/main/resources/sql/community-schema.sql b/apps/dnet-exporter-api/src/main/resources/sql/community-schema.sql index d90a256c..299dcf9b 100644 --- a/apps/dnet-exporter-api/src/main/resources/sql/community-schema.sql +++ b/apps/dnet-exporter-api/src/main/resources/sql/community-schema.sql @@ -44,8 +44,10 @@ CREATE TABLE community_datasources ( ds_id text NOT NULL, ds_name text NOT NULL, ds_officialname text NOT NULL, - enabled boolean NOT NULL DEFAULT true; + enabled boolean NOT NULL DEFAULT true constraints jsonb, + deposit boolean NOT NULL DEFAULT false, + message text, PRIMARY KEY (community, ds_id) ); diff --git a/apps/dnet-exporter-api/src/test/java/eu/dnetlib/openaire/community/importer/CommunityImporterServiceTest.java b/apps/dnet-exporter-api/src/test/java/eu/dnetlib/openaire/community/importer/CommunityImporterServiceTest.java index 5141b89e..6a8410fb 100644 --- a/apps/dnet-exporter-api/src/test/java/eu/dnetlib/openaire/community/importer/CommunityImporterServiceTest.java +++ b/apps/dnet-exporter-api/src/test/java/eu/dnetlib/openaire/community/importer/CommunityImporterServiceTest.java @@ -60,9 +60,9 @@ class CommunityImporterServiceTest { // list.forEach(System.out::println); assertEquals(245, list.size()); - assertEquals(1, list.stream().filter(o -> o.getOrgId().equals("openorgs____::9dd5545aacd3d8019e00c3f837269746")).count()); - assertEquals(2, list.stream().filter(o -> o.getOrgId().equals("openorgs____::d11f981828c485cd23d93f7f24f24db1")).count()); - assertEquals(14, list.stream().filter(o -> o.getCommunity().equals("beopen")).count()); + assertEquals(1, list.stream().filter(o -> "openorgs____::9dd5545aacd3d8019e00c3f837269746".equals(o.getOrgId())).count()); + assertEquals(2, list.stream().filter(o -> "openorgs____::d11f981828c485cd23d93f7f24f24db1".equals(o.getOrgId())).count()); + assertEquals(14, list.stream().filter(o -> "beopen".equals(o.getCommunity())).count()); } @SuppressWarnings("unchecked") @@ -85,7 +85,7 @@ class CommunityImporterServiceTest { Mockito.verify(service, Mockito.times(1)).saveCommunity(detailsCapture.capture()); Mockito.verify(service, Mockito.times(1)).addCommunityProjects(Mockito.anyString(), projectsCapture.capture()); - Mockito.verify(service, Mockito.times(1)).addCommunityContentProviders(Mockito.anyString(), datasourcesCapture.capture()); + Mockito.verify(service, Mockito.times(1)).addCommunityDatasources(Mockito.anyString(), datasourcesCapture.capture()); Mockito.verify(service, Mockito.times(1)).addCommunityOrganizations(Mockito.anyString(), orgsCapture.capture()); Mockito.verify(service, Mockito.times(1)).addSubCommunities(Mockito.anyString(), subCommunitiesCapture.capture()); @@ -132,7 +132,7 @@ class CommunityImporterServiceTest { Mockito.verify(service, Mockito.times(1)).saveCommunity(detailsCapture.capture()); Mockito.verify(service, Mockito.times(1)).addCommunityProjects(Mockito.anyString(), projectsCapture.capture()); - Mockito.verify(service, Mockito.times(1)).addCommunityContentProviders(Mockito.anyString(), datasourcesCapture.capture()); + Mockito.verify(service, Mockito.times(1)).addCommunityDatasources(Mockito.anyString(), datasourcesCapture.capture()); Mockito.verify(service, Mockito.times(1)).addCommunityOrganizations(Mockito.anyString(), orgsCapture.capture()); Mockito.verify(service, Mockito.times(1)).addSubCommunities(Mockito.anyString(), subCommunitiesCapture.capture()); diff --git a/libs/dnet-exporter-model/src/main/java/eu/dnetlib/openaire/exporter/model/community/CommunityContentprovider.java b/libs/dnet-exporter-model/src/main/java/eu/dnetlib/openaire/exporter/model/community/CommunityContentprovider.java index c8cba59c..c74fd0d0 100644 --- a/libs/dnet-exporter-model/src/main/java/eu/dnetlib/openaire/exporter/model/community/CommunityContentprovider.java +++ b/libs/dnet-exporter-model/src/main/java/eu/dnetlib/openaire/exporter/model/community/CommunityContentprovider.java @@ -34,6 +34,12 @@ public class CommunityContentprovider { @Schema(description = "content provider selection criteria", required = false) private SelectionCriteria selectioncriteria; + @Schema(description = "suggested for deposition", required = false) + private Boolean deposit; + + @Schema(description = "message for the deposition page", required = false) + private String message; + public String getOpenaireId() { return openaireId; } @@ -75,7 +81,7 @@ public class CommunityContentprovider { } public SelectionCriteria getSelectioncriteria() { - return this.selectioncriteria; + return selectioncriteria; } public void setSelectioncriteria(final SelectionCriteria selectioncriteria) { @@ -101,17 +107,33 @@ public class CommunityContentprovider { public String toString() { final StringBuilder builder = new StringBuilder(); builder.append("CommunityContentprovider [\n\topenaireId = ") - .append(openaireId) - .append(",\n\tcommunityId = ") - .append(communityId) - .append(",\n\tname = ") - .append(name) - .append(",\n\tofficialname = ") - .append(officialname) - .append(",\n\tselectioncriteria = ") - .append(selectioncriteria) - .append("\n]"); + .append(openaireId) + .append(",\n\tcommunityId = ") + .append(communityId) + .append(",\n\tname = ") + .append(name) + .append(",\n\tofficialname = ") + .append(officialname) + .append(",\n\tselectioncriteria = ") + .append(selectioncriteria) + .append("\n]"); return builder.toString(); } + public Boolean getDeposit() { + return deposit; + } + + public void setDeposit(final Boolean deposit) { + this.deposit = deposit; + } + + public String getMessage() { + return message; + } + + public void setMessage(final String message) { + this.message = message; + } + }