new api form datasourceCommunity Map

This commit is contained in:
Michele Artini 2024-11-21 09:47:04 +01:00
parent 981d5c7844
commit a463896e71
2 changed files with 47 additions and 2 deletions

View File

@ -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<String, Set<String>> getPropagationOrganizationCommunityMap() {
final Set<String> 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<String, Set<String>> getDatasourceCommunityMap() {
final Set<String> 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<String> getPropagationOrganizationsForCommunity(final String communityId) {
return dbOrganizationRepository.findByCommunity(communityId)

View File

@ -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<String, Set<String>> 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