mapping
This commit is contained in:
parent
01cea6fe12
commit
ce55185bcf
|
@ -71,13 +71,13 @@ public class CommunityService {
|
|||
public List<CommunitySummary> listCommunities() throws CommunityException {
|
||||
return dbCommunityRepository.findAll()
|
||||
.stream()
|
||||
.map(ConvertionUtils::toSummary)
|
||||
.map(ConvertionUtils::toCommunitySummary)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public CommunityDetails getCommunity(final String id) throws CommunityException, ResourceNotFoundException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
final DbCommunity c = dbCommunityRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Community not found: " + id));
|
||||
return ConvertionUtils.CommunityDetails(c);
|
||||
}
|
||||
|
||||
public void setCommunity(final String id, final CommunityWritableProperties details) throws CommunityException, ResourceNotFoundException {
|
||||
|
|
|
@ -2,20 +2,41 @@ package eu.dnetlib.openaire.community.db.utils;
|
|||
|
||||
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.DbDatasource;
|
||||
import eu.dnetlib.openaire.community.db.model.DbOrganization;
|
||||
import eu.dnetlib.openaire.community.db.model.DbProject;
|
||||
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.CommunitySummary;
|
||||
import eu.dnetlib.openaire.exporter.model.community.selectioncriteria.SelectionCriteria;
|
||||
|
||||
public class ConvertionUtils {
|
||||
|
||||
public static CommunitySummary toSummary(final DbCommunity c) {
|
||||
public static CommunitySummary toCommunitySummary(final DbCommunity c) {
|
||||
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.setShortName(c.getLabel());
|
||||
summary.setName(null); // TODO: the field is missing in the db model
|
||||
|
@ -27,8 +48,6 @@ public class ConvertionUtils {
|
|||
summary.setLogoUrl(c.getLogoUrl());
|
||||
summary.setStatus(c.getStatus());
|
||||
summary.setZenodoCommunity(c.getMainZenodoCommunity());
|
||||
|
||||
return summary;
|
||||
}
|
||||
|
||||
public static CommunityProject toCommunityProject(final DbProject dbEntry) {
|
||||
|
@ -50,8 +69,14 @@ public class ConvertionUtils {
|
|||
}
|
||||
|
||||
public static DbProject toDbProject(final String id, final CommunityProject project) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
final DbProject p = new DbProject();
|
||||
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) {
|
||||
|
@ -74,8 +99,11 @@ public class ConvertionUtils {
|
|||
}
|
||||
|
||||
public static DbDatasource toDbDatasource(final String id, final CommunityContentprovider provider) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
final DbDatasource ds = new DbDatasource();
|
||||
ds.setCommunity(id);
|
||||
ds.setDsId(provider.getOpenaireId());
|
||||
ds.setDsName(provider.getName());
|
||||
return ds;
|
||||
}
|
||||
|
||||
public static CommunityOrganization toCommunityOrganiztion(final DbOrganization dbEntry) {
|
||||
|
@ -94,8 +122,12 @@ public class ConvertionUtils {
|
|||
}
|
||||
|
||||
public static DbOrganization toDbOrganization(final String id, final CommunityOrganization org) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
final DbOrganization dbo = new DbOrganization();
|
||||
dbo.setCommunity(id);
|
||||
dbo.setOrgId(org.getId());
|
||||
|
||||
// TODO le Support Orgs non sono ancora gestite
|
||||
return dbo;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue