apis for propagationOrganizationCommunityMap

This commit is contained in:
Michele Artini 2023-06-28 12:29:59 +02:00
parent 835de9c1c6
commit 340a577430
3 changed files with 1347 additions and 1 deletions

View File

@ -9,6 +9,8 @@ import static eu.dnetlib.openaire.common.ExporterConstants.R;
import static eu.dnetlib.openaire.common.ExporterConstants.W;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@ -523,4 +525,68 @@ public class CommunityApiController {
res.setOpenAirecommunitylist(communityService.getOpenAIRECommunities(zenodoId));
return res;
}
// APIs to manage the propagationOrganizationCommunityMap
@RequestMapping(value = "/propagationOrganizationCommunityMap", produces = {
"application/json"
}, method = RequestMethod.GET)
@Operation(summary = "Get the propagationOrganizationCommunityMap", description = "propagationOrganizationCommunityMap", tags = {
C_O, 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>> getPropagationOrganizationCommunityMap() {
return communityService.getPropagationOrganizationCommunityMap();
}
@RequestMapping(value = "/community/{communityId}/propagationOrganizations", produces = {
"application/json"
}, method = RequestMethod.GET)
@Operation(summary = "return the propagation organizations of a community", description = "return the propagation organizations of a 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 Set<String> getPropagationOrganizationsForCommunity(@PathVariable final String communityId) {
return communityService.getPropagationOrganizationsForCommunity(communityId);
}
@RequestMapping(value = "/community/{communityId}/propagationOrganizations", produces = {
"application/json"
}, method = RequestMethod.POST)
@Operation(summary = "add an organization to the propagationOrganizationCommunityMap", description = "add an organization to the propagationOrganizationCommunityMap", tags = {
C_O, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public Set<String> addPropagationOrganizationForCommunity(@PathVariable final String communityId,
@RequestParam final String organizationId) {
return communityService.addPropagationOrganizationForCommunity(communityId, organizationId);
}
@RequestMapping(value = "/community/{communityId}/propagationOrganizations", produces = {
"application/json"
}, method = RequestMethod.DELETE)
@Operation(summary = "delete an organization to the propagationOrganizationCommunityMap", description = "delete an organization to the propagationOrganizationCommunityMap", tags = {
C_O, W
})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "not found"),
@ApiResponse(responseCode = "500", description = "unexpected error")
})
public Set<String> removePropagationOrganizationForCommunity(@PathVariable final String communityId,
@RequestParam final String organizationId) {
return communityService.removePropagationOrganizationForCommunity(communityId, organizationId);
}
}

View File

@ -3,6 +3,7 @@ package eu.dnetlib.openaire.community.db;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Function;
@ -19,6 +20,7 @@ import org.springframework.stereotype.Service;
import eu.dnetlib.openaire.community.db.model.DbCommunity;
import eu.dnetlib.openaire.community.db.model.DbDatasource;
import eu.dnetlib.openaire.community.db.model.DbDatasourcePK;
import eu.dnetlib.openaire.community.db.model.DbOrganization;
import eu.dnetlib.openaire.community.db.model.DbProject;
import eu.dnetlib.openaire.community.db.model.DbProjectPK;
import eu.dnetlib.openaire.community.db.model.DbSubCommunity;
@ -49,7 +51,7 @@ public class CommunityService {
// 1) Import tramite profili:
// 1.1) Completare CommunityImporterController
// 2) Subcommunities: visualizzazione tramite le context api
// 3) Come ritornare i campi delle community_orgs ? // Creare un metodo nuovo i valori devono arrivare dal wf di provision, esempio:
// 3) Importare le orgs dal wf di provision, ad esempio:
// https://services.openaire.eu/is/mvc/ui/isManager.do#/profile/4801c33c-66ca-4ab6-af64-aa812194ec61_V29ya2Zsb3dEU1Jlc291cmNlcy9Xb3JrZmxvd0RTUmVzb3VyY2VUeXBl
// 4) Verificare Tickets: #8835, #8854, #6483, #3259, #3494
@ -321,4 +323,31 @@ public class CommunityService {
return dbCommunityRepository.findByZenodoId(zenodoId);
}
public Map<String, Set<String>> getPropagationOrganizationCommunityMap() {
return dbOrganizationRepository.findAll()
.stream()
.collect(Collectors.groupingBy(DbOrganization::getOrgId, Collectors.mapping(DbOrganization::getCommunity, Collectors.toSet())));
}
public Set<String> getPropagationOrganizationsForCommunity(final String communityId) {
return dbOrganizationRepository.findByCommunity(communityId)
.stream()
.map(DbOrganization::getOrgId)
.collect(Collectors.toSet());
}
@Transactional
public Set<String> addPropagationOrganizationForCommunity(final String communityId, final String organizationId) {
final DbOrganization o = new DbOrganization(communityId, organizationId);
dbOrganizationRepository.save(o);
return getPropagationOrganizationsForCommunity(communityId);
}
@Transactional
public Set<String> removePropagationOrganizationForCommunity(final String communityId, final String organizationId) {
final DbOrganization o = new DbOrganization(communityId, organizationId);
dbOrganizationRepository.delete(o);
return getPropagationOrganizationsForCommunity(communityId);
}
}

File diff suppressed because one or more lines are too long