new_model_for_communities #15
|
@ -27,7 +27,7 @@ import eu.dnetlib.openaire.community.db.repository.DbDatasourceRepository;
|
||||||
import eu.dnetlib.openaire.community.db.repository.DbOrganizationRepository;
|
import eu.dnetlib.openaire.community.db.repository.DbOrganizationRepository;
|
||||||
import eu.dnetlib.openaire.community.db.repository.DbProjectRepository;
|
import eu.dnetlib.openaire.community.db.repository.DbProjectRepository;
|
||||||
import eu.dnetlib.openaire.community.db.repository.DbSupportOrgRepository;
|
import eu.dnetlib.openaire.community.db.repository.DbSupportOrgRepository;
|
||||||
import eu.dnetlib.openaire.community.db.utils.ConvertionUtils;
|
import eu.dnetlib.openaire.community.db.utils.CommunityMappingUtils;
|
||||||
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
|
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
|
||||||
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
|
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
|
||||||
import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider;
|
import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider;
|
||||||
|
@ -47,9 +47,8 @@ public class CommunityService {
|
||||||
// 1.1) Completare CommunityImporterController
|
// 1.1) Completare CommunityImporterController
|
||||||
// 1.2) Considerare anche le Subcommunities: importazione tramite profili
|
// 1.2) Considerare anche le Subcommunities: importazione tramite profili
|
||||||
// 2) Subcommunities: visualizzazione tramite le context api
|
// 2) Subcommunities: visualizzazione tramite le context api
|
||||||
// 3) Implemtare il metodo CommunityService.setCommunity
|
// 3) Come ritornare i campi delle community_orgs ?
|
||||||
// 4) ricontrollare se tutti i campi del database sono esposti dalle api (modello + mapping)
|
// 4) Verificare Tickets: #8835, #8854, #6483, #3259, #3494
|
||||||
// 5) Verificare Tickets: #8835, #8854, #6483, #3259, #3494
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DbCommunityRepository dbCommunityRepository;
|
private DbCommunityRepository dbCommunityRepository;
|
||||||
|
@ -65,30 +64,33 @@ public class CommunityService {
|
||||||
public List<CommunitySummary> listCommunities() throws CommunityException {
|
public List<CommunitySummary> listCommunities() throws CommunityException {
|
||||||
return dbCommunityRepository.findAll()
|
return dbCommunityRepository.findAll()
|
||||||
.stream()
|
.stream()
|
||||||
.map(ConvertionUtils::toCommunitySummary)
|
.map(CommunityMappingUtils::toCommunitySummary)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails saveCommunity(final CommunityDetails details) throws CommunityException {
|
public CommunityDetails saveCommunity(final CommunityDetails details) throws CommunityException {
|
||||||
dbCommunityRepository.save(ConvertionUtils.toCommunity(details));
|
dbCommunityRepository.save(CommunityMappingUtils.toCommunity(details));
|
||||||
return getCommunity(details.getId());
|
return getCommunity(details.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails getCommunity(final String id) throws CommunityException, ResourceNotFoundException {
|
public CommunityDetails getCommunity(final String id) throws CommunityException, ResourceNotFoundException {
|
||||||
final DbCommunity c = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
final DbCommunity c = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
||||||
return ConvertionUtils.CommunityDetails(c);
|
return CommunityMappingUtils.CommunityDetails(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public void setCommunity(final String id, final CommunityWritableProperties details) throws CommunityException, ResourceNotFoundException {
|
public void setCommunity(final String id, final CommunityWritableProperties details) throws CommunityException, ResourceNotFoundException {
|
||||||
// TODO Auto-generated method stub
|
final DbCommunity c = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
||||||
|
CommunityMappingUtils.populateCommunity(c, details);
|
||||||
|
dbCommunityRepository.save(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page<CommunityProject> getCommunityProjects(final String id, final int page, final int size) throws CommunityException, ResourceNotFoundException {
|
public Page<CommunityProject> getCommunityProjects(final String id, final int page, final int size) throws CommunityException, ResourceNotFoundException {
|
||||||
return dbProjectRepository.findByCommunity(id, PageRequest.of(page, size)).map(ConvertionUtils::toCommunityProject);
|
return dbProjectRepository.findByCommunity(id, PageRequest.of(page, size)).map(CommunityMappingUtils::toCommunityProject);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityProject addCommunityProject(final String id, final CommunityProject project) throws CommunityException, ResourceNotFoundException {
|
public CommunityProject addCommunityProject(final String id, final CommunityProject project) throws CommunityException, ResourceNotFoundException {
|
||||||
final DbProject p = ConvertionUtils.toDbProject(id, project);
|
final DbProject p = CommunityMappingUtils.toDbProject(id, project);
|
||||||
dbProjectRepository.save(p);
|
dbProjectRepository.save(p);
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
@ -97,7 +99,7 @@ public class CommunityService {
|
||||||
throws CommunityException, ResourceNotFoundException {
|
throws CommunityException, ResourceNotFoundException {
|
||||||
|
|
||||||
final List<DbProject> list = projectList.stream()
|
final List<DbProject> list = projectList.stream()
|
||||||
.map(p -> ConvertionUtils.toDbProject(id, p))
|
.map(p -> CommunityMappingUtils.toDbProject(id, p))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
dbProjectRepository.saveAll(list);
|
dbProjectRepository.saveAll(list);
|
||||||
|
@ -119,13 +121,13 @@ public class CommunityService {
|
||||||
public List<CommunityContentprovider> getCommunityContentproviders(final String id) throws CommunityException, ResourceNotFoundException {
|
public List<CommunityContentprovider> getCommunityContentproviders(final String id) throws CommunityException, ResourceNotFoundException {
|
||||||
return dbDatasourceRepository.findByCommunity(id)
|
return dbDatasourceRepository.findByCommunity(id)
|
||||||
.stream()
|
.stream()
|
||||||
.map(ConvertionUtils::toCommunityContentprovider)
|
.map(CommunityMappingUtils::toCommunityContentprovider)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityContentprovider addCommunityContentprovider(final String id, final CommunityContentprovider cp)
|
public CommunityContentprovider addCommunityContentprovider(final String id, final CommunityContentprovider cp)
|
||||||
throws CommunityException, ResourceNotFoundException {
|
throws CommunityException, ResourceNotFoundException {
|
||||||
final DbDatasource ds = ConvertionUtils.toDbDatasource(id, cp);
|
final DbDatasource ds = CommunityMappingUtils.toDbDatasource(id, cp);
|
||||||
dbDatasourceRepository.save(ds);
|
dbDatasourceRepository.save(ds);
|
||||||
return cp;
|
return cp;
|
||||||
}
|
}
|
||||||
|
@ -134,7 +136,7 @@ public class CommunityService {
|
||||||
throws CommunityException, ResourceNotFoundException {
|
throws CommunityException, ResourceNotFoundException {
|
||||||
|
|
||||||
final List<DbDatasource> list = contentprovidersList.stream()
|
final List<DbDatasource> list = contentprovidersList.stream()
|
||||||
.map(cp -> ConvertionUtils.toDbDatasource(id, cp))
|
.map(cp -> CommunityMappingUtils.toDbDatasource(id, cp))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
dbDatasourceRepository.saveAll(list);
|
dbDatasourceRepository.saveAll(list);
|
||||||
|
@ -161,13 +163,13 @@ public class CommunityService {
|
||||||
public List<CommunityOrganization> getCommunityOrganizations(final String id) throws CommunityException, ResourceNotFoundException {
|
public List<CommunityOrganization> getCommunityOrganizations(final String id) throws CommunityException, ResourceNotFoundException {
|
||||||
return dbSupportOrgRepository.findByCommunity(id)
|
return dbSupportOrgRepository.findByCommunity(id)
|
||||||
.stream()
|
.stream()
|
||||||
.map(ConvertionUtils::toCommunityOrganiztion)
|
.map(CommunityMappingUtils::toCommunityOrganiztion)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityOrganization addCommunityOrganization(final String id, final CommunityOrganization organization)
|
public CommunityOrganization addCommunityOrganization(final String id, final CommunityOrganization organization)
|
||||||
throws CommunityException, ResourceNotFoundException {
|
throws CommunityException, ResourceNotFoundException {
|
||||||
final DbSupportOrg o = ConvertionUtils.toDbSupportOrg(id, organization);
|
final DbSupportOrg o = CommunityMappingUtils.toDbSupportOrg(id, organization);
|
||||||
dbSupportOrgRepository.save(o);
|
dbSupportOrgRepository.save(o);
|
||||||
return organization;
|
return organization;
|
||||||
}
|
}
|
||||||
|
@ -176,7 +178,7 @@ public class CommunityService {
|
||||||
throws CommunityException, ResourceNotFoundException {
|
throws CommunityException, ResourceNotFoundException {
|
||||||
|
|
||||||
final List<DbSupportOrg> list = orgList.stream()
|
final List<DbSupportOrg> list = orgList.stream()
|
||||||
.map(o -> ConvertionUtils.toDbSupportOrg(id, o))
|
.map(o -> CommunityMappingUtils.toDbSupportOrg(id, o))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
dbSupportOrgRepository.saveAll(list);
|
dbSupportOrgRepository.saveAll(list);
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import eu.dnetlib.openaire.community.db.model.DbCommunity;
|
import eu.dnetlib.openaire.community.db.model.DbCommunity;
|
||||||
import eu.dnetlib.openaire.community.db.model.DbDatasource;
|
import eu.dnetlib.openaire.community.db.model.DbDatasource;
|
||||||
|
@ -15,8 +16,9 @@ import eu.dnetlib.openaire.exporter.model.community.CommunityDetails;
|
||||||
import eu.dnetlib.openaire.exporter.model.community.CommunityOrganization;
|
import eu.dnetlib.openaire.exporter.model.community.CommunityOrganization;
|
||||||
import eu.dnetlib.openaire.exporter.model.community.CommunityProject;
|
import eu.dnetlib.openaire.exporter.model.community.CommunityProject;
|
||||||
import eu.dnetlib.openaire.exporter.model.community.CommunitySummary;
|
import eu.dnetlib.openaire.exporter.model.community.CommunitySummary;
|
||||||
|
import eu.dnetlib.openaire.exporter.model.community.CommunityWritableProperties;
|
||||||
|
|
||||||
public class ConvertionUtils {
|
public class CommunityMappingUtils {
|
||||||
|
|
||||||
public final static String PIPE_SEPARATOR = "||";
|
public final static String PIPE_SEPARATOR = "||";
|
||||||
|
|
||||||
|
@ -33,6 +35,7 @@ public class ConvertionUtils {
|
||||||
c.setShortName(details.getShortName());
|
c.setShortName(details.getShortName());
|
||||||
c.setDescription(details.getDescription());
|
c.setDescription(details.getDescription());
|
||||||
c.setStatus(details.getStatus());
|
c.setStatus(details.getStatus());
|
||||||
|
c.setLogoUrl(details.getLogoUrl());
|
||||||
c.setMembership(details.getMembership());
|
c.setMembership(details.getMembership());
|
||||||
c.setType(details.getType());
|
c.setType(details.getType());
|
||||||
c.setClaim(details.getClaim());
|
c.setClaim(details.getClaim());
|
||||||
|
@ -45,12 +48,57 @@ public class ConvertionUtils {
|
||||||
c.setOtherZenodoCommunities(toStringArray(details.getOtherZenodoCommunities()));
|
c.setOtherZenodoCommunities(toStringArray(details.getOtherZenodoCommunities()));
|
||||||
c.setCreationDate(ObjectUtils.firstNonNull(details.getCreationDate(), LocalDateTime.now()));
|
c.setCreationDate(ObjectUtils.firstNonNull(details.getCreationDate(), LocalDateTime.now()));
|
||||||
c.setLastUpdateDate(LocalDateTime.now());
|
c.setLastUpdateDate(LocalDateTime.now());
|
||||||
c.setLogoUrl(details.getLogoUrl());
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String[] toStringArray(final List<String> list) {
|
public static void populateCommunity(final DbCommunity c, final CommunityWritableProperties details) {
|
||||||
return list.toArray(new String[list.size()]);
|
if (StringUtils.isNotBlank(details.getName())) {
|
||||||
|
c.setName(details.getName());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(details.getShortName())) {
|
||||||
|
c.setShortName(details.getShortName());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(details.getDescription())) {
|
||||||
|
c.setDescription(details.getDescription());
|
||||||
|
}
|
||||||
|
if (details.getStatus() != null) {
|
||||||
|
c.setStatus(details.getStatus());
|
||||||
|
}
|
||||||
|
if (details.getMembership() != null) {
|
||||||
|
c.setMembership(details.getMembership());
|
||||||
|
}
|
||||||
|
if (details.getType() != null) {
|
||||||
|
c.setType(details.getType());
|
||||||
|
}
|
||||||
|
if (details.getClaim() != null) {
|
||||||
|
c.setClaim(details.getClaim());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(details.getLogoUrl())) {
|
||||||
|
c.setLogoUrl(details.getLogoUrl());
|
||||||
|
}
|
||||||
|
if (details.getFos() != null) {
|
||||||
|
c.setFos(toStringArray(details.getFos()));
|
||||||
|
}
|
||||||
|
if (details.getSdg() != null) {
|
||||||
|
c.setSdg(toStringArray(details.getSdg()));
|
||||||
|
}
|
||||||
|
if (details.getSubjects() != null) {
|
||||||
|
c.setSubjects(toStringArray(details.getSubjects()));
|
||||||
|
}
|
||||||
|
if (details.getAdvancedConstraints() != null) {
|
||||||
|
c.setAdvancedConstraints(details.getAdvancedConstraints());
|
||||||
|
}
|
||||||
|
if (details.getRemoveConstraints() != null) {
|
||||||
|
c.setRemoveConstraints(details.getRemoveConstraints());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(details.getMainZenodoCommunity())) {
|
||||||
|
c.setMainZenodoCommunity(details.getMainZenodoCommunity());
|
||||||
|
}
|
||||||
|
if (details.getOtherZenodoCommunities() != null) {
|
||||||
|
c.setOtherZenodoCommunities(toStringArray(details.getOtherZenodoCommunities()));
|
||||||
|
}
|
||||||
|
|
||||||
|
c.setLastUpdateDate(LocalDateTime.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CommunityDetails CommunityDetails(final DbCommunity c) {
|
public static CommunityDetails CommunityDetails(final DbCommunity c) {
|
||||||
|
@ -141,4 +189,7 @@ public class ConvertionUtils {
|
||||||
return dbo;
|
return dbo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String[] toStringArray(final List<String> list) {
|
||||||
|
return list.toArray(new String[list.size()]);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -34,26 +34,26 @@ public class CommunityWritableProperties {
|
||||||
@Schema(description = "Advanced constraint for the association of results to the community")
|
@Schema(description = "Advanced constraint for the association of results to the community")
|
||||||
private SelectionCriteria advancedConstraints;
|
private SelectionCriteria advancedConstraints;
|
||||||
|
|
||||||
|
@Schema(description = "Constraint for removing")
|
||||||
|
private SelectionCriteria removeConstraints;
|
||||||
|
|
||||||
@Schema(description = "status of the community, drives its visibility")
|
@Schema(description = "status of the community, drives its visibility")
|
||||||
private CommunityStatus status;
|
private CommunityStatus status;
|
||||||
|
|
||||||
@Schema(description = "id of the main Zenodo community")
|
@Schema(description = "id of the main Zenodo community")
|
||||||
private String mainZenodoCommunity;
|
private String mainZenodoCommunity;
|
||||||
|
|
||||||
public static CommunityWritableProperties fromDetails(final CommunityDetails details) {
|
@Schema(description = "identifiers of the other Zenodo community")
|
||||||
final CommunityWritableProperties p = new CommunityWritableProperties();
|
private List<String> otherZenodoCommunities;
|
||||||
p.setName(details.getName());
|
|
||||||
p.setShortName(details.getShortName());
|
@Schema(description = "membership of the community")
|
||||||
p.setDescription(details.getDescription());
|
private CommunityMembershipType membership;
|
||||||
p.setLogoUrl(details.getLogoUrl());
|
|
||||||
p.setSubjects(details.getSubjects());
|
@Schema(description = "type of the community")
|
||||||
p.setStatus(details.getStatus());
|
private CommunityType type;
|
||||||
p.setMainZenodoCommunity(details.getZenodoCommunity());
|
|
||||||
p.setFos(details.getFos());
|
@Schema(description = "type of supported claim")
|
||||||
p.setSdg(details.getSdg());
|
private CommunityClaimType claim;
|
||||||
p.setAdvancedConstraints(details.getAdvancedConstraints());
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getFos() {
|
public List<String> getFos() {
|
||||||
return fos;
|
return fos;
|
||||||
|
@ -134,4 +134,44 @@ public class CommunityWritableProperties {
|
||||||
public void setMainZenodoCommunity(final String mainZenodoCommunity) {
|
public void setMainZenodoCommunity(final String mainZenodoCommunity) {
|
||||||
this.mainZenodoCommunity = mainZenodoCommunity;
|
this.mainZenodoCommunity = mainZenodoCommunity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CommunityMembershipType getMembership() {
|
||||||
|
return membership;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMembership(final CommunityMembershipType membership) {
|
||||||
|
this.membership = membership;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommunityType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(final CommunityType type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommunityClaimType getClaim() {
|
||||||
|
return claim;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClaim(final CommunityClaimType claim) {
|
||||||
|
this.claim = claim;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SelectionCriteria getRemoveConstraints() {
|
||||||
|
return removeConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemoveConstraints(final SelectionCriteria removeConstraints) {
|
||||||
|
this.removeConstraints = removeConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getOtherZenodoCommunities() {
|
||||||
|
return otherZenodoCommunities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOtherZenodoCommunities(final List<String> otherZenodoCommunities) {
|
||||||
|
this.otherZenodoCommunities = otherZenodoCommunities;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue