From 5fe4be242c873937782ff5d6db3ba037806623fc Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Tue, 19 Nov 2024 15:34:43 +0100 Subject: [PATCH] propagation organizations --- .../community/SubCommunityApiController.java | 243 +++++++++++------- 1 file changed, 154 insertions(+), 89 deletions(-) diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/SubCommunityApiController.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/SubCommunityApiController.java index 774ebec4..42e287ef 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/SubCommunityApiController.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/SubCommunityApiController.java @@ -10,6 +10,7 @@ import static eu.dnetlib.openaire.common.ExporterConstants.W; import java.util.ArrayList; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; @@ -30,7 +31,6 @@ import eu.dnetlib.openaire.community.utils.CommunityMappingUtils; import eu.dnetlib.openaire.exporter.exceptions.CommunityException; import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException; import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider; -import eu.dnetlib.openaire.exporter.model.community.CommunityOrganization; import eu.dnetlib.openaire.exporter.model.community.CommunityProject; import eu.dnetlib.openaire.exporter.model.community.SubCommunity; import eu.dnetlib.openaire.exporter.model.community.SubCommunityWritableProperties; @@ -527,7 +527,7 @@ public class SubCommunityApiController extends AbstractExporterController { @GetMapping("/community/{id}/subcommunities/projects/{page}/{size}") @Operation(summary = "get community projects", description = "get community projects", tags = { - C_PJ, R + C_SUB, C_PJ, R }) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @@ -556,7 +556,7 @@ public class SubCommunityApiController extends AbstractExporterController { @PostMapping("/community/{id}/subcommunities/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 + C_SUB, C_PJ, W }) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @@ -581,7 +581,7 @@ public class SubCommunityApiController extends AbstractExporterController { @DeleteMapping("/community/{id}/subcommunities/projects") @Operation(summary = "remove a project from the community", description = "remove a project from the community", tags = { - C_PJ, W + C_SUB, C_PJ, W }) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @@ -606,7 +606,7 @@ public class SubCommunityApiController extends AbstractExporterController { @PostMapping("/community/{id}/subcommunities/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_SUB, C_PJ, W }) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @@ -632,7 +632,7 @@ public class SubCommunityApiController extends AbstractExporterController { @DeleteMapping("/community/{id}/subcommunities/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_SUB, C_PJ, W }) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @@ -657,7 +657,7 @@ public class SubCommunityApiController extends AbstractExporterController { @GetMapping("/community/{id}/subcommunities/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_SUB, C_PJ, R }) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @@ -682,7 +682,7 @@ public class SubCommunityApiController extends AbstractExporterController { @GetMapping("/community/{id}/subcommunities/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 + C_SUB, C_CP, R }) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @@ -708,7 +708,7 @@ public class SubCommunityApiController extends AbstractExporterController { @PostMapping("/community/{id}/subcommunities/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 + C_SUB, C_CP, W }) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @@ -734,7 +734,7 @@ public class SubCommunityApiController extends AbstractExporterController { @PostMapping("/community/{id}/subcommunities/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 + C_SUB, C_CP, W }) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @@ -760,7 +760,7 @@ public class SubCommunityApiController extends AbstractExporterController { @DeleteMapping("/community/{id}/subcommunities/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 + C_SUB, C_CP, W }) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @@ -785,7 +785,7 @@ public class SubCommunityApiController extends AbstractExporterController { @PostMapping("/community/{id}/subcommunities/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 + C_SUB, C_CP, W }) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @@ -811,7 +811,7 @@ public class SubCommunityApiController extends AbstractExporterController { @DeleteMapping("/community/{id}/subcommunities/datasourcesList") @Operation(summary = "remove a list of datasources from the community", description = "remove a list of datasources from the community", tags = { - C_CP, W + C_SUB, C_CP, W }) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @@ -835,22 +835,143 @@ public class SubCommunityApiController extends AbstractExporterController { } // ORGANIZATIONS + /* + * @GetMapping("/community/{id}/subcommunities/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 }) + * + * @ApiResponses(value = { + * + * @ApiResponse(responseCode = "200", description = "OK"), + * + * @ApiResponse(responseCode = "404", description = "not found"), + * + * @ApiResponse(responseCode = "500", description = "unexpected error") }) public List + * getCommunityOrganizations(@PathVariable final String id, @RequestParam final String subCommunityId) throws CommunityException { + * verifyIdParameters(id, subCommunityId); + * + * try { return communityService.getCommunityOrganizations(subCommunityId); } catch (final ResourceNotFoundException e) { throw e; } + * catch (final Throwable e) { throw new CommunityException(e); } } + * + * @PostMapping("/community/{id}/subcommunities/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") }) public CommunityOrganization addCommunityOrganization( + * + * @PathVariable final String id, + * + * @RequestParam final String subCommunityId, + * + * @RequestBody final CommunityOrganization organization) throws CommunityException { + * + * verifyIdParameters(id, subCommunityId); + * + * try { communityService.addCommunityOrganizations(subCommunityId, organization); return organization; } catch (final + * ResourceNotFoundException e) { throw e; } catch (final Throwable e) { throw new CommunityException(e); } } + * + * @PostMapping("/community/{id}/subcommunities/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") }) public CommunityOrganization[] addCommunityOrganizationList( + * + * @PathVariable final String id, + * + * @RequestParam final String subCommunityId, + * + * @RequestBody final CommunityOrganization[] orgs) throws CommunityException { + * + * verifyIdParameters(id, subCommunityId); + * + * try { communityService.addCommunityOrganizations(subCommunityId, orgs); return orgs; } catch (final ResourceNotFoundException e) { + * throw e; } catch (final Throwable e) { throw new CommunityException(e); } } + * + * @DeleteMapping("/community/{id}/subcommunities/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 }) + * + * @ApiResponses(value = { + * + * @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 subCommunityId, + * + * @RequestParam final String organizationName) throws CommunityException { + * + * verifyIdParameters(id, subCommunityId); + * + * try { communityService.removeCommunityOrganizations(subCommunityId, organizationName); } catch (final ResourceNotFoundException e) { + * throw e; } catch (final Throwable e) { throw new CommunityException(e); } } + * + * @DeleteMapping("/community/{id}/subcommunities/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 }) + * + * @ApiResponses(value = { + * + * @ApiResponse(responseCode = "200", description = "OK"), + * + * @ApiResponse(responseCode = "404", description = "not found"), + * + * @ApiResponse(responseCode = "500", description = "unexpected error") }) public void removeCommunityOrganizationList( + * + * @PathVariable final String id, + * + * @RequestParam final String subCommunityId, + * + * @RequestBody final String[] orgNames) throws CommunityException { + * + * verifyIdParameters(id, subCommunityId); + * + * try { communityService.removeCommunityOrganizations(subCommunityId, orgNames); } catch (final ResourceNotFoundException e) { throw e; + * } catch (final Throwable e) { throw new CommunityException(e); } } + */ - @GetMapping("/community/{id}/subcommunities/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 + // Propagation Organizations + + @GetMapping("/community/{id}/subcommunities/propagationOrganizations") + @Operation(summary = "return the propagation organizations of a sub-community", description = "try { return the propagation organizations of a community", tags = { + C_SUB, C_O, R }) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "not found"), @ApiResponse(responseCode = "500", description = "unexpected error") }) - public List getCommunityOrganizations(@PathVariable final String id, @RequestParam final String subCommunityId) + public Set getPropagationOrganizationsForCommunity(@PathVariable final String id, @RequestParam final String subCommunityId) throws CommunityException { - verifyIdParameters(id, subCommunityId); - try { - return communityService.getCommunityOrganizations(subCommunityId); + return communityService.getPropagationOrganizationsForCommunity(subCommunityId); } catch (final ResourceNotFoundException e) { throw e; } catch (final Throwable e) { @@ -858,25 +979,21 @@ public class SubCommunityApiController extends AbstractExporterController { } } - @PostMapping("/community/{id}/subcommunities/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 + @PostMapping("/community/{id}/subcommunities/propagationOrganizations") + @Operation(summary = "add an organization to the propagationOrganizationCommunityMap of a sub-community", description = "add an organization to the propagationOrganizationCommunityMap", tags = { + C_SUB, C_O, W }) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "not found"), @ApiResponse(responseCode = "500", description = "unexpected error") }) - public CommunityOrganization addCommunityOrganization( - @PathVariable final String id, + public Set addPropagationOrganizationForCommunity(@PathVariable final String id, @RequestParam final String subCommunityId, - @RequestBody final CommunityOrganization organization) throws CommunityException { - - verifyIdParameters(id, subCommunityId); + @RequestParam final String organizationId) throws CommunityException { try { - communityService.addCommunityOrganizations(subCommunityId, organization); - return organization; + return communityService.addPropagationOrganizationForCommunity(subCommunityId, organizationId.split(",")); } catch (final ResourceNotFoundException e) { throw e; } catch (final Throwable e) { @@ -884,25 +1001,21 @@ public class SubCommunityApiController extends AbstractExporterController { } } - @PostMapping("/community/{id}/subcommunities/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 + @DeleteMapping("/community/{id}/subcommunities/propagationOrganizations") + @Operation(summary = "delete an organization to the propagationOrganizationCommunityMap", description = "delete an organization from the propagationOrganizationCommunityMap of a sub-community", tags = { + C_SUB, C_O, W }) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "not found"), @ApiResponse(responseCode = "500", description = "unexpected error") }) - public CommunityOrganization[] addCommunityOrganizationList( - @PathVariable final String id, + public Set removePropagationOrganizationForCommunity(@PathVariable final String id, @RequestParam final String subCommunityId, - @RequestBody final CommunityOrganization[] orgs) throws CommunityException { - - verifyIdParameters(id, subCommunityId); + @RequestParam final String organizationId) throws CommunityException { try { - communityService.addCommunityOrganizations(subCommunityId, orgs); - return orgs; + return communityService.removePropagationOrganizationForCommunity(subCommunityId, organizationId.split(",")); } catch (final ResourceNotFoundException e) { throw e; } catch (final Throwable e) { @@ -910,55 +1023,7 @@ public class SubCommunityApiController extends AbstractExporterController { } } - @DeleteMapping("/community/{id}/subcommunities/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 - }) - @ApiResponses(value = { - @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 subCommunityId, - @RequestParam final String organizationName) throws CommunityException { - - verifyIdParameters(id, subCommunityId); - - try { - communityService.removeCommunityOrganizations(subCommunityId, organizationName); - } catch (final ResourceNotFoundException e) { - throw e; - } catch (final Throwable e) { - throw new CommunityException(e); - } - } - - @DeleteMapping("/community/{id}/subcommunities/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 - }) - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "OK"), - @ApiResponse(responseCode = "404", description = "not found"), - @ApiResponse(responseCode = "500", description = "unexpected error") - }) - public void removeCommunityOrganizationList( - @PathVariable final String id, - @RequestParam final String subCommunityId, - @RequestBody final String[] orgNames) throws CommunityException { - - verifyIdParameters(id, subCommunityId); - - try { - communityService.removeCommunityOrganizations(subCommunityId, orgNames); - } catch (final ResourceNotFoundException e) { - throw e; - } catch (final Throwable e) { - throw new CommunityException(e); - } - } + // Common methods private void verifyIdParameters(final String id, final String subCommunityId) throws CommunityException { if (!CommunityMappingUtils.isValidCommunityId(id)) { throw new CommunityException("Invalid community id: " + id); }