implementation of some internal methods
This commit is contained in:
parent
71d3ed7cee
commit
c622c4cd53
|
@ -140,7 +140,7 @@ public class CommunityApiController {
|
||||||
})
|
})
|
||||||
public void deleteCommunityProject(
|
public void deleteCommunityProject(
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final Integer projectId) throws CommunityException, ResourceNotFoundException {
|
@RequestBody final String projectId) throws CommunityException, ResourceNotFoundException {
|
||||||
|
|
||||||
communityService.removeCommunityProject(id, projectId);
|
communityService.removeCommunityProject(id, projectId);
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ public class CommunityApiController {
|
||||||
})
|
})
|
||||||
public void deleteCommunityProjectList(
|
public void deleteCommunityProjectList(
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final List<Integer> projectIdList) throws CommunityException, ResourceNotFoundException {
|
@RequestBody final List<String> projectIdList) throws CommunityException, ResourceNotFoundException {
|
||||||
|
|
||||||
communityService.removeCommunityProjectList(id, projectIdList);
|
communityService.removeCommunityProjectList(id, projectIdList);
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,7 @@ public class CommunityApiController {
|
||||||
})
|
})
|
||||||
public void removeCommunityContentprovider(
|
public void removeCommunityContentprovider(
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final Integer contentproviderId) throws CommunityException, ResourceNotFoundException {
|
@RequestBody final String contentproviderId) throws CommunityException, ResourceNotFoundException {
|
||||||
|
|
||||||
communityService.removeCommunityContentProvider(id, contentproviderId);
|
communityService.removeCommunityContentProvider(id, contentproviderId);
|
||||||
}
|
}
|
||||||
|
@ -263,7 +263,7 @@ public class CommunityApiController {
|
||||||
})
|
})
|
||||||
public void deleteCommunityContentProvidersList(
|
public void deleteCommunityContentProvidersList(
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final List<Integer> contentProviderIdList) throws CommunityException, ResourceNotFoundException {
|
@RequestBody final List<String> contentProviderIdList) throws CommunityException, ResourceNotFoundException {
|
||||||
|
|
||||||
communityService.removeCommunityContentProviderList(id, contentProviderIdList);
|
communityService.removeCommunityContentProviderList(id, contentProviderIdList);
|
||||||
}
|
}
|
||||||
|
@ -316,7 +316,7 @@ public class CommunityApiController {
|
||||||
})
|
})
|
||||||
public void removeCommunityOrganization(
|
public void removeCommunityOrganization(
|
||||||
@PathVariable final String id,
|
@PathVariable final String id,
|
||||||
@RequestBody final Integer organizationId) throws CommunityException, ResourceNotFoundException {
|
@RequestBody final String organizationId) throws CommunityException, ResourceNotFoundException {
|
||||||
|
|
||||||
communityService.removeCommunityOrganization(id, organizationId);
|
communityService.removeCommunityOrganization(id, organizationId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,26 @@
|
||||||
package eu.dnetlib.openaire.community.db;
|
package eu.dnetlib.openaire.community.db;
|
||||||
|
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
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.DbProject;
|
import eu.dnetlib.openaire.community.db.model.DbProject;
|
||||||
|
import eu.dnetlib.openaire.community.db.model.DbProjectPK;
|
||||||
import eu.dnetlib.openaire.community.db.repository.DbCommunityRepository;
|
import eu.dnetlib.openaire.community.db.repository.DbCommunityRepository;
|
||||||
import eu.dnetlib.openaire.community.db.repository.DbDatasourceRepository;
|
import eu.dnetlib.openaire.community.db.repository.DbDatasourceRepository;
|
||||||
import eu.dnetlib.openaire.community.db.repository.DbOrganizationRepository;
|
import eu.dnetlib.openaire.community.db.repository.DbOrganizationRepository;
|
||||||
|
@ -29,6 +42,14 @@ import eu.dnetlib.openaire.exporter.model.community.selectioncriteria.SelectionC
|
||||||
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
|
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
|
||||||
public class CommunityService {
|
public class CommunityService {
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// 1) Aggiungere i campi membership e claim al modello delle api
|
||||||
|
// 2) Capire come gestire il campo Id (Integer) di CommunityProject
|
||||||
|
// 3) Gestire paginazione dei progetti
|
||||||
|
// 4) CommunityContentprovider sono le datasources?
|
||||||
|
// 5) Capire come gestire il campo Id (Integer) di CommunityContentprovider
|
||||||
|
// 5) Capire come gestire il campo Id (Integer) di CommunityOrganization
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DbCommunityRepository dbCommunityRepository;
|
private DbCommunityRepository dbCommunityRepository;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -81,91 +102,118 @@ public class CommunityService {
|
||||||
return projectList;
|
return projectList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeCommunityProject(final String id, final Integer projectId) throws CommunityException, ResourceNotFoundException {
|
public void removeCommunityProject(final String id, final String projectId) throws CommunityException, ResourceNotFoundException {
|
||||||
// dbProjectRepository.deleteById(new DbProjectPK(id, projectId));
|
dbProjectRepository.deleteById(new DbProjectPK(id, projectId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeCommunityProjectList(final String id, final List<Integer> projectIdList) throws CommunityException, ResourceNotFoundException {
|
public void removeCommunityProjectList(final String id, final List<String> projectIdList) throws CommunityException, ResourceNotFoundException {
|
||||||
// TODO Auto-generated method stub
|
final List<DbProjectPK> list = projectIdList.stream()
|
||||||
|
.map(projectId -> new DbProjectPK(id, projectId))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
dbProjectRepository.deleteAllById(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CommunityContentprovider> getCommunityContentproviders(final String id) throws CommunityException, ResourceNotFoundException {
|
public List<CommunityContentprovider> getCommunityContentproviders(final String id) throws CommunityException, ResourceNotFoundException {
|
||||||
// TODO Auto-generated method stub
|
return dbDatasourceRepository.findByCommunity(id)
|
||||||
return null;
|
.stream()
|
||||||
|
.map(ConvertionUtils::toCommunityContentprovider)
|
||||||
|
.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 {
|
||||||
// TODO Auto-generated method stub
|
final DbDatasource ds = ConvertionUtils.toDbDatasource(id, cp);
|
||||||
return null;
|
dbDatasourceRepository.save(ds);
|
||||||
}
|
return cp;
|
||||||
|
|
||||||
public void removeCommunityContentProvider(final String id, final Integer contentproviderId) throws CommunityException, ResourceNotFoundException {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CommunityContentprovider> addCommunityContentProvidersList(final String id, final List<CommunityContentprovider> contentprovidersList)
|
public List<CommunityContentprovider> addCommunityContentProvidersList(final String id, final List<CommunityContentprovider> contentprovidersList)
|
||||||
throws CommunityException, ResourceNotFoundException {
|
throws CommunityException, ResourceNotFoundException {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
final List<DbDatasource> list = contentprovidersList.stream()
|
||||||
|
.map(cp -> ConvertionUtils.toDbDatasource(id, cp))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
dbDatasourceRepository.saveAll(list);
|
||||||
|
|
||||||
|
return contentprovidersList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeCommunityContentProviderList(final String id, final List<Integer> contentProviderIdList)
|
public void removeCommunityContentProvider(final String id, final String contentproviderId) throws CommunityException, ResourceNotFoundException {
|
||||||
|
dbDatasourceRepository.deleteById(new DbDatasourcePK(id, contentproviderId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeCommunityContentProviderList(final String id, final List<String> contentProviderIdList)
|
||||||
throws CommunityException, ResourceNotFoundException {
|
throws CommunityException, ResourceNotFoundException {
|
||||||
// TODO Auto-generated method stub
|
final List<DbDatasourcePK> list = contentProviderIdList.stream()
|
||||||
|
.map(dsId -> new DbDatasourcePK(id, dsId))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
dbDatasourceRepository.deleteAllById(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeCommunityOrganization(final String id, final Integer organizationId) throws CommunityException, ResourceNotFoundException {
|
public void removeCommunityOrganization(final String id, final String organizationId) throws CommunityException, ResourceNotFoundException {
|
||||||
// TODO Auto-generated method stub
|
dbDatasourceRepository.deleteById(new DbDatasourcePK(id, organizationId));
|
||||||
}
|
|
||||||
|
|
||||||
public List<CommunityZenodoCommunity> getCommunityZenodoCommunities(final String id) throws CommunityException, ResourceNotFoundException {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CommunityOrganization> getCommunityOrganizations(final String id) throws CommunityException, ResourceNotFoundException {
|
public List<CommunityOrganization> getCommunityOrganizations(final String id) throws CommunityException, ResourceNotFoundException {
|
||||||
// TODO Auto-generated method stub
|
return dbOrganizationRepository.findByCommunity(id)
|
||||||
return null;
|
.stream()
|
||||||
|
.map(ConvertionUtils::toCommunityOrganiztion)
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public CommunityDetails addCommunitySubjects(final String id, final List<String> subjects) throws CommunityException, ResourceNotFoundException {
|
public CommunityDetails addCommunitySubjects(final String id, final List<String> subjects) throws CommunityException, ResourceNotFoundException {
|
||||||
// TODO Auto-generated method stub
|
return modifyElementToArrayField(id, subjects, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), false);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public CommunityDetails removeCommunitySubjects(final String id, final List<String> subjects) throws CommunityException, ResourceNotFoundException {
|
public CommunityDetails removeCommunitySubjects(final String id, final List<String> subjects) throws CommunityException, ResourceNotFoundException {
|
||||||
// TODO Auto-generated method stub
|
return modifyElementToArrayField(id, subjects, c -> c.getSubjects(), (c, subs) -> c.setSubjects(subs), true);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public CommunityDetails addCommunityFOS(final String id, final List<String> foss) throws CommunityException, ResourceNotFoundException {
|
public CommunityDetails addCommunityFOS(final String id, final List<String> foss) throws CommunityException, ResourceNotFoundException {
|
||||||
// TODO Auto-generated method stub
|
return modifyElementToArrayField(id, foss, c -> c.getFos(), (c, fos) -> c.setFos(fos), false);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public CommunityDetails removeCommunityFOS(final String id, final List<String> foss) throws CommunityException, ResourceNotFoundException {
|
public CommunityDetails removeCommunityFOS(final String id, final List<String> foss) throws CommunityException, ResourceNotFoundException {
|
||||||
// TODO Auto-generated method stub
|
return modifyElementToArrayField(id, foss, c -> c.getFos(), (c, fos) -> c.setFos(fos), true);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public CommunityDetails addCommunitySDG(final String id, final List<String> sdgs) throws CommunityException, ResourceNotFoundException {
|
public CommunityDetails addCommunitySDG(final String id, final List<String> sdgs) throws CommunityException, ResourceNotFoundException {
|
||||||
// TODO Auto-generated method stub
|
return modifyElementToArrayField(id, sdgs, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), false);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public CommunityDetails removeCommunitySDG(final String id, final List<String> sdgs) throws CommunityException, ResourceNotFoundException {
|
public CommunityDetails removeCommunitySDG(final String id, final List<String> sdgs) throws CommunityException, ResourceNotFoundException {
|
||||||
// TODO Auto-generated method stub
|
return modifyElementToArrayField(id, sdgs, c -> c.getSdg(), (c, sdg) -> c.setSdg(sdg), true);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails addCommunityAdvancedConstraint(final String id, final SelectionCriteria advancedCosntraint)
|
public CommunityDetails addCommunityAdvancedConstraint(final String id, final SelectionCriteria advancedCosntraint)
|
||||||
throws CommunityException, ResourceNotFoundException {
|
throws CommunityException, ResourceNotFoundException {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
try {
|
||||||
|
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
||||||
|
dbEntry.setAdvancedConstraints(new ObjectMapper().writeValueAsString(advancedCosntraint));
|
||||||
|
dbCommunityRepository.save(dbEntry);
|
||||||
|
return getCommunity(id);
|
||||||
|
} catch (final JsonProcessingException e) {
|
||||||
|
throw new CommunityException("Error converting json");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommunityDetails removeCommunityAdvancedConstraint(final String id) throws ResourceNotFoundException, CommunityException {
|
public CommunityDetails removeCommunityAdvancedConstraint(final String id) throws ResourceNotFoundException, CommunityException {
|
||||||
|
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
||||||
|
dbEntry.setAdvancedConstraints(null);
|
||||||
|
dbCommunityRepository.save(dbEntry);
|
||||||
|
return getCommunity(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CommunityZenodoCommunity> getCommunityZenodoCommunities(final String id) throws CommunityException, ResourceNotFoundException {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -190,4 +238,33 @@ public class CommunityService {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CommunityDetails modifyElementToArrayField(final String id,
|
||||||
|
final List<String> values,
|
||||||
|
final Function<DbCommunity, String[]> getter,
|
||||||
|
final BiConsumer<DbCommunity, String[]> setter,
|
||||||
|
final boolean remove) throws ResourceNotFoundException, CommunityException {
|
||||||
|
|
||||||
|
final DbCommunity dbEntry = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
||||||
|
|
||||||
|
final Set<String> tmpList = new LinkedHashSet<>();
|
||||||
|
final String[] oldValues = getter.apply(dbEntry);
|
||||||
|
if (oldValues != null) {
|
||||||
|
for (final String s : oldValues) {
|
||||||
|
tmpList.add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (remove) {
|
||||||
|
tmpList.removeAll(values);
|
||||||
|
} else {
|
||||||
|
tmpList.addAll(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
setter.accept(dbEntry, tmpList.toArray(new String[tmpList.size()]));
|
||||||
|
|
||||||
|
dbCommunityRepository.save(dbEntry);
|
||||||
|
|
||||||
|
return getCommunity(id);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
package eu.dnetlib.openaire.community.db;
|
package eu.dnetlib.openaire.community.db;
|
||||||
|
|
||||||
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.DbOrganization;
|
||||||
import eu.dnetlib.openaire.community.db.model.DbProject;
|
import eu.dnetlib.openaire.community.db.model.DbProject;
|
||||||
|
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.CommunityProject;
|
||||||
import eu.dnetlib.openaire.exporter.model.community.CommunitySummary;
|
import eu.dnetlib.openaire.exporter.model.community.CommunitySummary;
|
||||||
|
|
||||||
|
@ -22,4 +26,24 @@ public class ConvertionUtils {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static CommunityContentprovider toCommunityContentprovider(final DbDatasource dbEntry) {
|
||||||
|
// TODO
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DbDatasource toDbDatasource(final String id, final CommunityContentprovider provider) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommunityOrganization toCommunityOrganiztion(final DbOrganization dbEntry) {
|
||||||
|
// TODO
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DbOrganization toDbOrganization(final String id, final CommunityOrganization org) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,13 @@ public class DbDatasourcePK implements Serializable {
|
||||||
|
|
||||||
private String dsId;
|
private String dsId;
|
||||||
|
|
||||||
|
public DbDatasourcePK() {}
|
||||||
|
|
||||||
|
public DbDatasourcePK(final String community, final String dsId) {
|
||||||
|
this.community = community;
|
||||||
|
this.dsId = dsId;
|
||||||
|
}
|
||||||
|
|
||||||
public String getCommunity() {
|
public String getCommunity() {
|
||||||
return community;
|
return community;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue