new_model_for_communities #15

Merged
michele.artini merged 81 commits from new_model_for_communities into master 2023-10-24 08:12:26 +02:00
19 changed files with 147 additions and 86 deletions
Showing only changes of commit 71d3ed7cee - Show all commits

View File

@ -1,16 +1,18 @@
package eu.dnetlib.openaire.community.db;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import eu.dnetlib.openaire.community.db.repository.CommunityDatasourceRepository;
import eu.dnetlib.openaire.community.db.repository.CommunityOrgRepository;
import eu.dnetlib.openaire.community.db.repository.CommunityProjectRepository;
import eu.dnetlib.openaire.community.db.repository.CommunityRepository;
import eu.dnetlib.openaire.community.db.repository.CommunitySupportOrgRepository;
import eu.dnetlib.openaire.community.db.model.DbProject;
import eu.dnetlib.openaire.community.db.repository.DbCommunityRepository;
import eu.dnetlib.openaire.community.db.repository.DbDatasourceRepository;
import eu.dnetlib.openaire.community.db.repository.DbOrganizationRepository;
import eu.dnetlib.openaire.community.db.repository.DbProjectRepository;
import eu.dnetlib.openaire.community.db.repository.DbSupportOrgRepository;
import eu.dnetlib.openaire.exporter.exceptions.CommunityException;
import eu.dnetlib.openaire.exporter.exceptions.ResourceNotFoundException;
import eu.dnetlib.openaire.exporter.model.community.CommunityContentprovider;
@ -28,19 +30,21 @@ import eu.dnetlib.openaire.exporter.model.community.selectioncriteria.SelectionC
public class CommunityService {
@Autowired
private CommunityRepository communityRepository;
private DbCommunityRepository dbCommunityRepository;
@Autowired
private CommunityProjectRepository communityProjectRepository;
private DbProjectRepository dbProjectRepository;
@Autowired
private CommunityDatasourceRepository communityDatasourceRepository;
private DbDatasourceRepository dbDatasourceRepository;
@Autowired
private CommunityOrgRepository communityOrgRepository;
private DbOrganizationRepository dbOrganizationRepository;
@Autowired
private CommunitySupportOrgRepository communitySupportOrgRepository;
private DbSupportOrgRepository dbSupportOrgRepository;
public List<CommunitySummary> listCommunities() throws CommunityException {
// TODO Auto-generated method stub
return null;
return dbCommunityRepository.findAll()
.stream()
.map(ConvertionUtils::toSummary)
.collect(Collectors.toList());
}
public CommunityDetails getCommunity(final String id) throws CommunityException, ResourceNotFoundException {
@ -53,23 +57,32 @@ public class CommunityService {
}
public List<CommunityProject> getCommunityProjects(final String id) throws CommunityException, ResourceNotFoundException {
// TODO Auto-generated method stub
return null;
return dbProjectRepository.findByCommunity(id)
.stream()
.map(ConvertionUtils::toCommunityProject)
.collect(Collectors.toList());
}
public CommunityProject addCommunityProject(final String id, final CommunityProject project) throws CommunityException, ResourceNotFoundException {
// TODO Auto-generated method stub
return null;
final DbProject p = ConvertionUtils.toDbProject(id, project);
dbProjectRepository.save(p);
return project;
}
public List<CommunityProject> addCommunityProjectList(final String id, final List<CommunityProject> projectList)
throws CommunityException, ResourceNotFoundException {
// TODO Auto-generated method stub
return null;
final List<DbProject> list = projectList.stream()
.map(p -> ConvertionUtils.toDbProject(id, p))
.collect(Collectors.toList());
dbProjectRepository.saveAll(list);
return projectList;
}
public void removeCommunityProject(final String id, final Integer projectId) throws CommunityException, ResourceNotFoundException {
// TODO Auto-generated method stub
// dbProjectRepository.deleteById(new DbProjectPK(id, projectId));
}
public void removeCommunityProjectList(final String id, final List<Integer> projectIdList) throws CommunityException, ResourceNotFoundException {

View File

@ -0,0 +1,25 @@
package eu.dnetlib.openaire.community.db;
import eu.dnetlib.openaire.community.db.model.DbCommunity;
import eu.dnetlib.openaire.community.db.model.DbProject;
import eu.dnetlib.openaire.exporter.model.community.CommunityProject;
import eu.dnetlib.openaire.exporter.model.community.CommunitySummary;
public class ConvertionUtils {
public static CommunitySummary toSummary(final DbCommunity dbEntry) {
// TODO
return null;
}
public static CommunityProject toCommunityProject(final DbProject dbEntry) {
// TODO
return null;
}
public static DbProject toDbProject(final String id, final CommunityProject project) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -35,7 +35,7 @@ import eu.dnetlib.openaire.community.db.enums.CommunityType;
@TypeDef(name = "json", typeClass = JsonStringType.class),
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
})
public class Community implements Serializable {
public class DbCommunity implements Serializable {
private static final long serialVersionUID = 1L;

View File

@ -10,8 +10,8 @@ import javax.persistence.Table;
@Entity
@Table(name = "community_datasources")
@IdClass(CommunityDatasourcePK.class)
public class CommunityDatasource implements Serializable {
@IdClass(DbDatasourcePK.class)
public class DbDatasource implements Serializable {
private static final long serialVersionUID = 1L;
@ -26,9 +26,9 @@ public class CommunityDatasource implements Serializable {
@Column(name = "ds_name")
private String dsName;
public CommunityDatasource() {}
public DbDatasource() {}
public CommunityDatasource(final String community, final String dsId, final String dsName) {
public DbDatasource(final String community, final String dsId, final String dsName) {
this.community = community;
this.dsId = dsId;
this.dsName = dsName;

View File

@ -3,7 +3,7 @@ package eu.dnetlib.openaire.community.db.model;
import java.io.Serializable;
import java.util.Objects;
public class CommunityDatasourcePK implements Serializable {
public class DbDatasourcePK implements Serializable {
private static final long serialVersionUID = 1L;
@ -35,8 +35,8 @@ public class CommunityDatasourcePK implements Serializable {
@Override
public boolean equals(final Object obj) {
if (this == obj) { return true; }
if (!(obj instanceof CommunityDatasourcePK)) { return false; }
final CommunityDatasourcePK other = (CommunityDatasourcePK) obj;
if (!(obj instanceof DbDatasourcePK)) { return false; }
final DbDatasourcePK other = (DbDatasourcePK) obj;
return Objects.equals(community, other.community) && Objects.equals(dsId, other.dsId);
}

View File

@ -10,8 +10,8 @@ import javax.persistence.Table;
@Entity
@Table(name = "community_orgs")
@IdClass(CommunityOrgPK.class)
public class CommunityOrg implements Serializable {
@IdClass(DbOrganizationPK.class)
public class DbOrganization implements Serializable {
private static final long serialVersionUID = 1L;
@ -23,9 +23,9 @@ public class CommunityOrg implements Serializable {
@Column(name = "org_id")
private String orgId;
public CommunityOrg() {}
public DbOrganization() {}
public CommunityOrg(final String community, final String orgId) {
public DbOrganization(final String community, final String orgId) {
this.community = community;
this.orgId = orgId;
}

View File

@ -3,7 +3,7 @@ package eu.dnetlib.openaire.community.db.model;
import java.io.Serializable;
import java.util.Objects;
public class CommunityOrgPK implements Serializable {
public class DbOrganizationPK implements Serializable {
private static final long serialVersionUID = 1L;
@ -35,8 +35,8 @@ public class CommunityOrgPK implements Serializable {
@Override
public boolean equals(final Object obj) {
if (this == obj) { return true; }
if (!(obj instanceof CommunityDatasourcePK)) { return false; }
final CommunityOrgPK other = (CommunityOrgPK) obj;
if (!(obj instanceof DbDatasourcePK)) { return false; }
final DbOrganizationPK other = (DbOrganizationPK) obj;
return Objects.equals(community, other.community) && Objects.equals(orgId, other.orgId);
}

View File

@ -10,8 +10,8 @@ import javax.persistence.Table;
@Entity
@Table(name = "community_projects")
@IdClass(CommunityProjectPK.class)
public class CommunityProject implements Serializable {
@IdClass(DbProjectPK.class)
public class DbProject implements Serializable {
private static final long serialVersionUID = 1L;
@ -35,9 +35,9 @@ public class CommunityProject implements Serializable {
@Column(name = "project_funder")
private String projectFunder;
public CommunityProject() {}
public DbProject() {}
public CommunityProject(final String community, final String projectId, final String projectCode, final String projectName, final String projectAcronym,
public DbProject(final String community, final String projectId, final String projectCode, final String projectName, final String projectAcronym,
final String projectFunder) {
this.community = community;
this.projectId = projectId;

View File

@ -3,7 +3,7 @@ package eu.dnetlib.openaire.community.db.model;
import java.io.Serializable;
import java.util.Objects;
public class CommunityProjectPK implements Serializable {
public class DbProjectPK implements Serializable {
private static final long serialVersionUID = 1L;
@ -11,6 +11,13 @@ public class CommunityProjectPK implements Serializable {
private String projectId;
public DbProjectPK() {}
public DbProjectPK(final String community, final String projectId) {
this.community = community;
this.projectId = projectId;
}
public String getCommunity() {
return community;
}
@ -35,8 +42,8 @@ public class CommunityProjectPK implements Serializable {
@Override
public boolean equals(final Object obj) {
if (this == obj) { return true; }
if (!(obj instanceof CommunityProjectPK)) { return false; }
final CommunityProjectPK other = (CommunityProjectPK) obj;
if (!(obj instanceof DbProjectPK)) { return false; }
final DbProjectPK other = (DbProjectPK) obj;
return Objects.equals(community, other.community) && Objects.equals(projectId, other.projectId);
}

View File

@ -10,8 +10,8 @@ import javax.persistence.Table;
@Entity
@Table(name = "community_support_orgs")
@IdClass(CommunitySupportOrgPK.class)
public class CommunitySupportOrg implements Serializable {
@IdClass(DbSupportOrgPK.class)
public class DbSupportOrg implements Serializable {
private static final long serialVersionUID = 1L;

View File

@ -3,7 +3,7 @@ package eu.dnetlib.openaire.community.db.model;
import java.io.Serializable;
import java.util.Objects;
public class CommunitySupportOrgPK implements Serializable {
public class DbSupportOrgPK implements Serializable {
private static final long serialVersionUID = 1L;
@ -35,8 +35,8 @@ public class CommunitySupportOrgPK implements Serializable {
@Override
public boolean equals(final Object obj) {
if (this == obj) { return true; }
if (!(obj instanceof CommunitySupportOrgPK)) { return false; }
final CommunitySupportOrgPK other = (CommunitySupportOrgPK) obj;
if (!(obj instanceof DbSupportOrgPK)) { return false; }
final DbSupportOrgPK other = (DbSupportOrgPK) obj;
return Objects.equals(community, other.community) && Objects.equals(orgName, other.orgName);
}

View File

@ -1,11 +0,0 @@
package eu.dnetlib.openaire.community.db.repository;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.jpa.repository.JpaRepository;
import eu.dnetlib.openaire.community.db.model.Community;
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
public interface CommunityDatasourceRepository extends JpaRepository<Community, String> {
}

View File

@ -1,12 +0,0 @@
package eu.dnetlib.openaire.community.db.repository;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.jpa.repository.JpaRepository;
import eu.dnetlib.openaire.community.db.model.CommunityOrg;
import eu.dnetlib.openaire.community.db.model.CommunityOrgPK;
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
public interface CommunityOrgRepository extends JpaRepository<CommunityOrg, CommunityOrgPK> {
}

View File

@ -1,12 +0,0 @@
package eu.dnetlib.openaire.community.db.repository;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.jpa.repository.JpaRepository;
import eu.dnetlib.openaire.community.db.model.CommunitySupportOrg;
import eu.dnetlib.openaire.community.db.model.CommunitySupportOrgPK;
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
public interface CommunitySupportOrgRepository extends JpaRepository<CommunitySupportOrg, CommunitySupportOrgPK> {
}

View File

@ -3,9 +3,9 @@ package eu.dnetlib.openaire.community.db.repository;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.jpa.repository.JpaRepository;
import eu.dnetlib.openaire.community.db.model.Community;
import eu.dnetlib.openaire.community.db.model.DbCommunity;
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
public interface CommunityRepository extends JpaRepository<Community, String> {
public interface DbCommunityRepository extends JpaRepository<DbCommunity, String> {
}

View File

@ -0,0 +1,15 @@
package eu.dnetlib.openaire.community.db.repository;
import java.util.List;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.jpa.repository.JpaRepository;
import eu.dnetlib.openaire.community.db.model.DbDatasource;
import eu.dnetlib.openaire.community.db.model.DbDatasourcePK;
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
public interface DbDatasourceRepository extends JpaRepository<DbDatasource, DbDatasourcePK> {
List<DbDatasource> findByCommunity(String community);
}

View File

@ -0,0 +1,16 @@
package eu.dnetlib.openaire.community.db.repository;
import java.util.List;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.jpa.repository.JpaRepository;
import eu.dnetlib.openaire.community.db.model.DbOrganization;
import eu.dnetlib.openaire.community.db.model.DbOrganizationPK;
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
public interface DbOrganizationRepository extends JpaRepository<DbOrganization, DbOrganizationPK> {
List<DbOrganization> findByCommunity(String community);
}

View File

@ -1,12 +1,16 @@
package eu.dnetlib.openaire.community.db.repository;
import java.util.List;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.jpa.repository.JpaRepository;
import eu.dnetlib.openaire.community.db.model.CommunityProject;
import eu.dnetlib.openaire.community.db.model.CommunityProjectPK;
import eu.dnetlib.openaire.community.db.model.DbProject;
import eu.dnetlib.openaire.community.db.model.DbProjectPK;
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
public interface CommunityProjectRepository extends JpaRepository<CommunityProject, CommunityProjectPK> {
public interface DbProjectRepository extends JpaRepository<DbProject, DbProjectPK> {
List<DbProject> findByCommunity(String community);
}

View File

@ -0,0 +1,16 @@
package eu.dnetlib.openaire.community.db.repository;
import java.util.List;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.jpa.repository.JpaRepository;
import eu.dnetlib.openaire.community.db.model.DbSupportOrg;
import eu.dnetlib.openaire.community.db.model.DbSupportOrgPK;
@ConditionalOnProperty(value = "openaire.exporter.enable.community", havingValue = "true")
public interface DbSupportOrgRepository extends JpaRepository<DbSupportOrg, DbSupportOrgPK> {
List<DbSupportOrg> findByCommunity(String community);
}