From a463896e715274f7301f4a64c5f2b488dd63b93d Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Thu, 21 Nov 2024 09:47:04 +0100 Subject: [PATCH] new api form datasourceCommunity Map --- .../openaire/community/CommunityService.java | 24 ++++++++++++++++++ .../OtherCommunityApiController.java | 25 +++++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) 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 68efc1a9..218679d5 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 @@ -46,6 +46,7 @@ import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider; import eu.dnetlib.openaire.exporter.model.community.CommunityDetails; import eu.dnetlib.openaire.exporter.model.community.CommunityOrganization; import eu.dnetlib.openaire.exporter.model.community.CommunityProject; +import eu.dnetlib.openaire.exporter.model.community.CommunityStatus; import eu.dnetlib.openaire.exporter.model.community.CommunitySummary; import eu.dnetlib.openaire.exporter.model.community.CommunityType; import eu.dnetlib.openaire.exporter.model.community.CommunityWritableProperties; @@ -405,11 +406,34 @@ public class CommunityService { @Transactional public Map> getPropagationOrganizationCommunityMap() { + + final Set valids = dbCommunityRepository.findAll() + .stream() + .filter(c -> c.getStatus() != CommunityStatus.hidden) + .map(DbCommunity::getId) + .collect(Collectors.toSet()); + return dbOrganizationRepository.findAll() .stream() + .filter(o -> valids.contains(o.getCommunity())) .collect(Collectors.groupingBy(DbOrganization::getOrgId, Collectors.mapping(DbOrganization::getCommunity, Collectors.toSet()))); } + @Transactional + public Map> getDatasourceCommunityMap() { + + final Set valids = dbCommunityRepository.findAll() + .stream() + .filter(c -> c.getStatus() != CommunityStatus.hidden) + .map(DbCommunity::getId) + .collect(Collectors.toSet()); + + return dbDatasourceRepository.findAll() + .stream() + .filter(o -> valids.contains(o.getCommunity())) + .collect(Collectors.groupingBy(DbDatasource::getDsId, Collectors.mapping(DbDatasource::getCommunity, Collectors.toSet()))); + } + @Transactional public Set getPropagationOrganizationsForCommunity(final String communityId) { return dbOrganizationRepository.findByCommunity(communityId) diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/OtherCommunityApiController.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/OtherCommunityApiController.java index 0c6094df..083420c9 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/OtherCommunityApiController.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/community/OtherCommunityApiController.java @@ -1,5 +1,6 @@ package eu.dnetlib.openaire.community; +import static eu.dnetlib.openaire.common.ExporterConstants.C_CP; import static eu.dnetlib.openaire.common.ExporterConstants.C_O; import static eu.dnetlib.openaire.common.ExporterConstants.C_ZC; import static eu.dnetlib.openaire.common.ExporterConstants.R; @@ -37,7 +38,7 @@ public class OtherCommunityApiController extends AbstractExporterController { // APIs to manage the propagationOrganizationCommunityMap @GetMapping("/propagationOrganizationCommunityMap") - @Operation(summary = "Get the propagationOrganizationCommunityMap", description = "propagationOrganizationCommunityMap", tags = { + @Operation(summary = "Get the propagationOrganizationCommunityMap", description = "Get the propagationOrganizationCommunityMap", tags = { C_O, R }) @ApiResponses(value = { @@ -55,8 +56,28 @@ public class OtherCommunityApiController extends AbstractExporterController { } } - // Specific API for ZENODO communities + // APIs to manage the datasourceCommunityMap + @GetMapping("/datasourceCommunityMap") + @Operation(summary = "Get the datasourceCommunityMap", description = "Get the datasourceCommunityMap", tags = { + C_CP, R + }) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "404", description = "not found"), + @ApiResponse(responseCode = "500", description = "unexpected error") + }) + public Map> getDatasourceCommunityMap() throws CommunityException { + try { + return communityService.getPropagationOrganizationCommunityMap(); + } catch (final ResourceNotFoundException e) { + throw e; + } catch (final Throwable e) { + throw new CommunityException(e); + } + } + + // Specific API for ZENODO communities @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