This commit is contained in:
Michele Artini 2023-06-15 14:37:15 +02:00
parent 01cea6fe12
commit ce55185bcf
2 changed files with 44 additions and 12 deletions

View File

@ -71,13 +71,13 @@ 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::toSummary) .map(ConvertionUtils::toCommunitySummary)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public CommunityDetails getCommunity(final String id) throws CommunityException, ResourceNotFoundException { public CommunityDetails getCommunity(final String id) throws CommunityException, ResourceNotFoundException {
// TODO Auto-generated method stub final DbCommunity c = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
return null; return ConvertionUtils.CommunityDetails(c);
} }
public void setCommunity(final String id, final CommunityWritableProperties details) throws CommunityException, ResourceNotFoundException { public void setCommunity(final String id, final CommunityWritableProperties details) throws CommunityException, ResourceNotFoundException {

View File

@ -2,20 +2,41 @@ package eu.dnetlib.openaire.community.db.utils;
import static eu.dnetlib.openaire.community.CommunityConstants.PIPE_SEPARATOR; import static eu.dnetlib.openaire.community.CommunityConstants.PIPE_SEPARATOR;
import java.util.Arrays;
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;
import eu.dnetlib.openaire.community.db.model.DbOrganization; 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.CommunityContentprovider;
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.selectioncriteria.SelectionCriteria;
public class ConvertionUtils { public class ConvertionUtils {
public static CommunitySummary toSummary(final DbCommunity c) { public static CommunitySummary toCommunitySummary(final DbCommunity c) {
final CommunitySummary summary = new CommunitySummary(); final CommunitySummary summary = new CommunitySummary();
populateSummary(summary, c);
return summary;
}
public static CommunityDetails CommunityDetails(final DbCommunity c) {
final CommunityDetails details = new CommunityDetails();
populateSummary(details, c);
details.setAdvancedConstraints(SelectionCriteria.fromJson(c.getAdvancedConstraints()));
details.setFos(Arrays.asList(c.getFos()));
details.setSdg(Arrays.asList(c.getSdg()));
details.setSubjects(Arrays.asList(c.getSubjects()));
// TODO: add the new fields
return null;
}
private static void populateSummary(final CommunitySummary summary, final DbCommunity c) {
summary.setId(c.getId()); summary.setId(c.getId());
summary.setShortName(c.getLabel()); summary.setShortName(c.getLabel());
summary.setName(null); // TODO: the field is missing in the db model summary.setName(null); // TODO: the field is missing in the db model
@ -27,8 +48,6 @@ public class ConvertionUtils {
summary.setLogoUrl(c.getLogoUrl()); summary.setLogoUrl(c.getLogoUrl());
summary.setStatus(c.getStatus()); summary.setStatus(c.getStatus());
summary.setZenodoCommunity(c.getMainZenodoCommunity()); summary.setZenodoCommunity(c.getMainZenodoCommunity());
return summary;
} }
public static CommunityProject toCommunityProject(final DbProject dbEntry) { public static CommunityProject toCommunityProject(final DbProject dbEntry) {
@ -50,8 +69,14 @@ public class ConvertionUtils {
} }
public static DbProject toDbProject(final String id, final CommunityProject project) { public static DbProject toDbProject(final String id, final CommunityProject project) {
// TODO Auto-generated method stub final DbProject p = new DbProject();
return null; p.setCommunity(id);
p.setProjectId(project.getOpenaireId());
p.setProjectName(project.getName());
p.setProjectAcronym(project.getAcronym());
p.setProjectCode(project.getGrantId());
p.setProjectFunder(project.getFunder());
return p;
} }
public static CommunityContentprovider toCommunityContentprovider(final DbDatasource dbEntry) { public static CommunityContentprovider toCommunityContentprovider(final DbDatasource dbEntry) {
@ -74,8 +99,11 @@ public class ConvertionUtils {
} }
public static DbDatasource toDbDatasource(final String id, final CommunityContentprovider provider) { public static DbDatasource toDbDatasource(final String id, final CommunityContentprovider provider) {
// TODO Auto-generated method stub final DbDatasource ds = new DbDatasource();
return null; ds.setCommunity(id);
ds.setDsId(provider.getOpenaireId());
ds.setDsName(provider.getName());
return ds;
} }
public static CommunityOrganization toCommunityOrganiztion(final DbOrganization dbEntry) { public static CommunityOrganization toCommunityOrganiztion(final DbOrganization dbEntry) {
@ -94,8 +122,12 @@ public class ConvertionUtils {
} }
public static DbOrganization toDbOrganization(final String id, final CommunityOrganization org) { public static DbOrganization toDbOrganization(final String id, final CommunityOrganization org) {
// TODO Auto-generated method stub final DbOrganization dbo = new DbOrganization();
return null; dbo.setCommunity(id);
dbo.setOrgId(org.getId());
// TODO le Support Orgs non sono ancora gestite
return dbo;
} }
} }