From 7b4bea071038791298669849584717b86c9741da Mon Sep 17 00:00:00 2001 From: ikalyvas Date: Sun, 10 Dec 2017 00:31:07 +0200 Subject: [PATCH] referential integrity for researchers and organizations --- .../java/dao/entities/DataRepositoryDao.java | 2 +- .../dao/entities/DataRepositoryDaoImpl.java | 3 +- .../java/dao/entities/OrganisationDao.java | 7 +- .../dao/entities/OrganisationDaoImpl.java | 17 ++- .../main/java/dao/entities/RegistryDao.java | 4 +- .../java/dao/entities/RegistryDaoImpl.java | 4 +- .../main/java/dao/entities/ResearcherDao.java | 5 + .../java/dao/entities/ResearcherDaoImpl.java | 15 +++ .../main/java/dao/entities/ServiceDao.java | 3 +- .../java/dao/entities/ServiceDaoImpl.java | 4 +- dmp-backend/src/main/java/entities/DMP.java | 2 +- .../src/main/java/entities/DataEntity.java | 4 + .../main/java/entities/DataRepository.java | 2 +- .../src/main/java/entities/Dataset.java | 2 +- .../src/main/java/entities/Organisation.java | 2 +- .../src/main/java/entities/Project.java | 2 +- .../src/main/java/entities/Registry.java | 2 +- .../src/main/java/entities/Researcher.java | 2 +- .../src/main/java/entities/Service.java | 2 +- .../src/main/java/models/DataModel.java | 8 ++ .../{dataset => }/criteria/Criteria.java | 6 +- .../criteria/DataRepositoryCriteria.java | 2 +- .../models/criteria/OrganisationCriteria.java | 6 + .../criteria/RegistryCriteria.java | 2 +- .../models/criteria/ResearcherCriteria.java | 6 + .../criteria/ServiceCriteria.java | 2 +- .../java/models/dataset/DataRepository.java | 4 +- .../src/main/java/models/dataset/Dataset.java | 6 +- .../main/java/models/dataset/Registry.java | 4 +- .../src/main/java/models/dataset/Service.java | 4 +- .../java/models/dmp/DataManagementPlan.java | 110 ++++++++++++++++++ .../main/java/models/dmp/Organisation.java | 54 +++++++++ .../src/main/java/models/dmp/Project.java | 29 +++++ .../src/main/java/models/dmp/Researcher.java | 62 ++++++++++ .../src/main/java/rest/entities/DMPs.java | 56 +++++---- .../entities/DatasetProfileController.java | 1 - .../src/main/java/rest/entities/Datasets.java | 27 +---- .../src/main/java/rest/entities/Projects.java | 14 +-- .../builders/DomainModelConverter.java | 28 +++++ dmp-frontend/src/app/dmps/dmp.component.ts | 9 +- dmp-frontend/src/app/services/rest-base.ts | 2 +- 41 files changed, 433 insertions(+), 93 deletions(-) create mode 100644 dmp-backend/src/main/java/entities/DataEntity.java create mode 100644 dmp-backend/src/main/java/models/DataModel.java rename dmp-backend/src/main/java/models/{dataset => }/criteria/Criteria.java (55%) rename dmp-backend/src/main/java/models/{dataset => }/criteria/DataRepositoryCriteria.java (76%) create mode 100644 dmp-backend/src/main/java/models/criteria/OrganisationCriteria.java rename dmp-backend/src/main/java/models/{dataset => }/criteria/RegistryCriteria.java (72%) create mode 100644 dmp-backend/src/main/java/models/criteria/ResearcherCriteria.java rename dmp-backend/src/main/java/models/{dataset => }/criteria/ServiceCriteria.java (72%) create mode 100644 dmp-backend/src/main/java/models/dmp/DataManagementPlan.java create mode 100644 dmp-backend/src/main/java/models/dmp/Organisation.java create mode 100644 dmp-backend/src/main/java/models/dmp/Project.java create mode 100644 dmp-backend/src/main/java/models/dmp/Researcher.java create mode 100644 dmp-backend/src/main/java/utilities/builders/DomainModelConverter.java diff --git a/dmp-backend/src/main/java/dao/entities/DataRepositoryDao.java b/dmp-backend/src/main/java/dao/entities/DataRepositoryDao.java index 239178068..39be39779 100644 --- a/dmp-backend/src/main/java/dao/entities/DataRepositoryDao.java +++ b/dmp-backend/src/main/java/dao/entities/DataRepositoryDao.java @@ -6,7 +6,7 @@ import java.util.UUID; import dao.Dao; import entities.DataRepository; import entities.responses.IDLabelPair; -import models.dataset.criteria.Criteria; +import models.criteria.Criteria; public interface DataRepositoryDao extends Dao { diff --git a/dmp-backend/src/main/java/dao/entities/DataRepositoryDaoImpl.java b/dmp-backend/src/main/java/dao/entities/DataRepositoryDaoImpl.java index bc3fc176a..d79997436 100644 --- a/dmp-backend/src/main/java/dao/entities/DataRepositoryDaoImpl.java +++ b/dmp-backend/src/main/java/dao/entities/DataRepositoryDaoImpl.java @@ -13,9 +13,8 @@ import org.hibernate.query.Query; import dao.JpaDao; import entities.DataRepository; -import entities.Registry; import entities.responses.IDLabelPair; -import models.dataset.criteria.Criteria; +import models.criteria.Criteria; public class DataRepositoryDaoImpl extends JpaDao implements DataRepositoryDao { diff --git a/dmp-backend/src/main/java/dao/entities/OrganisationDao.java b/dmp-backend/src/main/java/dao/entities/OrganisationDao.java index 7fa04dbf9..4092bdd51 100644 --- a/dmp-backend/src/main/java/dao/entities/OrganisationDao.java +++ b/dmp-backend/src/main/java/dao/entities/OrganisationDao.java @@ -5,12 +5,17 @@ import java.util.UUID; import dao.Dao; import entities.Organisation; +import entities.Registry; import entities.responses.IDLabelPair; +import models.criteria.Criteria; public interface OrganisationDao extends Dao { public List listAllIDs(); List listAllIDsLabels(); - + + List listBy(Criteria criteria); + + } \ No newline at end of file diff --git a/dmp-backend/src/main/java/dao/entities/OrganisationDaoImpl.java b/dmp-backend/src/main/java/dao/entities/OrganisationDaoImpl.java index d520361fa..2b2e8438b 100644 --- a/dmp-backend/src/main/java/dao/entities/OrganisationDaoImpl.java +++ b/dmp-backend/src/main/java/dao/entities/OrganisationDaoImpl.java @@ -5,7 +5,12 @@ import java.util.UUID; import java.util.stream.Collectors; import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import entities.Registry; +import models.criteria.Criteria; import org.hibernate.query.Query; import dao.JpaDao; @@ -36,7 +41,17 @@ public class OrganisationDaoImpl extends JpaDao implements O }) .collect(Collectors.toList()); } - + + + @Override + public List listBy(Criteria criteria) { + CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); + CriteriaQuery criteriaQuery = criteriaBuilder .createQuery(Organisation.class); + Root root = criteriaQuery.from(Organisation.class); + criteriaQuery.where(criteriaBuilder.equal(root.get("reference"), criteria.getLike())); + TypedQuery typedQuery = entityManager.createQuery(criteriaQuery); + return typedQuery.getResultList(); + } } diff --git a/dmp-backend/src/main/java/dao/entities/RegistryDao.java b/dmp-backend/src/main/java/dao/entities/RegistryDao.java index 08291fae4..a62862544 100644 --- a/dmp-backend/src/main/java/dao/entities/RegistryDao.java +++ b/dmp-backend/src/main/java/dao/entities/RegistryDao.java @@ -4,11 +4,9 @@ import java.util.List; import java.util.UUID; import dao.Dao; -import entities.DataRepository; import entities.Registry; -import entities.Researcher; import entities.responses.IDLabelPair; -import models.dataset.criteria.Criteria; +import models.criteria.Criteria; public interface RegistryDao extends Dao { diff --git a/dmp-backend/src/main/java/dao/entities/RegistryDaoImpl.java b/dmp-backend/src/main/java/dao/entities/RegistryDaoImpl.java index 5a52b8e95..c97f82cc9 100644 --- a/dmp-backend/src/main/java/dao/entities/RegistryDaoImpl.java +++ b/dmp-backend/src/main/java/dao/entities/RegistryDaoImpl.java @@ -12,11 +12,9 @@ import javax.persistence.criteria.Root; import org.hibernate.query.Query; import dao.JpaDao; -import entities.DataRepository; import entities.Registry; -import entities.Researcher; import entities.responses.IDLabelPair; -import models.dataset.criteria.Criteria; +import models.criteria.Criteria; public class RegistryDaoImpl extends JpaDao implements RegistryDao { diff --git a/dmp-backend/src/main/java/dao/entities/ResearcherDao.java b/dmp-backend/src/main/java/dao/entities/ResearcherDao.java index 1cf3913ed..78617c79d 100644 --- a/dmp-backend/src/main/java/dao/entities/ResearcherDao.java +++ b/dmp-backend/src/main/java/dao/entities/ResearcherDao.java @@ -4,8 +4,10 @@ import java.util.List; import java.util.UUID; import dao.Dao; +import entities.Registry; import entities.Researcher; import entities.responses.IDLabelPair; +import models.criteria.Criteria; public interface ResearcherDao extends Dao { @@ -15,4 +17,7 @@ public interface ResearcherDao extends Dao { Researcher getResearcherByEmail(String email); + List listBy(Criteria criteria); + + } \ No newline at end of file diff --git a/dmp-backend/src/main/java/dao/entities/ResearcherDaoImpl.java b/dmp-backend/src/main/java/dao/entities/ResearcherDaoImpl.java index 6a9d78691..0c33c9867 100644 --- a/dmp-backend/src/main/java/dao/entities/ResearcherDaoImpl.java +++ b/dmp-backend/src/main/java/dao/entities/ResearcherDaoImpl.java @@ -5,7 +5,12 @@ import java.util.UUID; import java.util.stream.Collectors; import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import entities.Registry; +import models.criteria.Criteria; import org.hibernate.query.Query; import dao.JpaDao; @@ -48,6 +53,16 @@ public class ResearcherDaoImpl extends JpaDao implements Resea return null; } + + @Override + public List listBy(Criteria criteria) { + CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); + CriteriaQuery criteriaQuery = criteriaBuilder .createQuery(Researcher.class); + Root root = criteriaQuery.from(Researcher.class); + criteriaQuery.where(criteriaBuilder.equal(root.get("reference"), criteria.getLike())); + TypedQuery typedQuery = entityManager.createQuery(criteriaQuery); + return typedQuery.getResultList(); + } } diff --git a/dmp-backend/src/main/java/dao/entities/ServiceDao.java b/dmp-backend/src/main/java/dao/entities/ServiceDao.java index de0fcfaf5..2001a949b 100644 --- a/dmp-backend/src/main/java/dao/entities/ServiceDao.java +++ b/dmp-backend/src/main/java/dao/entities/ServiceDao.java @@ -4,10 +4,9 @@ import java.util.List; import java.util.UUID; import dao.Dao; -import entities.DataRepository; import entities.Service; import entities.responses.IDLabelPair; -import models.dataset.criteria.Criteria; +import models.criteria.Criteria; public interface ServiceDao extends Dao { diff --git a/dmp-backend/src/main/java/dao/entities/ServiceDaoImpl.java b/dmp-backend/src/main/java/dao/entities/ServiceDaoImpl.java index 4dd8aac96..d0460b77b 100644 --- a/dmp-backend/src/main/java/dao/entities/ServiceDaoImpl.java +++ b/dmp-backend/src/main/java/dao/entities/ServiceDaoImpl.java @@ -12,11 +12,9 @@ import javax.persistence.criteria.Root; import org.hibernate.query.Query; import dao.JpaDao; -import entities.DataRepository; -import entities.Registry; import entities.Service; import entities.responses.IDLabelPair; -import models.dataset.criteria.Criteria; +import models.criteria.Criteria; public class ServiceDaoImpl extends JpaDao implements ServiceDao { diff --git a/dmp-backend/src/main/java/entities/DMP.java b/dmp-backend/src/main/java/entities/DMP.java index 2193361e1..6dbebdcfb 100644 --- a/dmp-backend/src/main/java/entities/DMP.java +++ b/dmp-backend/src/main/java/entities/DMP.java @@ -37,7 +37,7 @@ import com.fasterxml.jackson.databind.SerializationFeature; @Entity @Table(name="\"DMP\"") @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id", scope = DMP.class) -public class DMP implements Serializable { +public class DMP implements Serializable,DataEntity { private static final long serialVersionUID = -8263056535208547615L; diff --git a/dmp-backend/src/main/java/entities/DataEntity.java b/dmp-backend/src/main/java/entities/DataEntity.java new file mode 100644 index 000000000..e5f4b0295 --- /dev/null +++ b/dmp-backend/src/main/java/entities/DataEntity.java @@ -0,0 +1,4 @@ +package entities; + +public interface DataEntity { +} diff --git a/dmp-backend/src/main/java/entities/DataRepository.java b/dmp-backend/src/main/java/entities/DataRepository.java index 6ae5b9224..fa804f07e 100644 --- a/dmp-backend/src/main/java/entities/DataRepository.java +++ b/dmp-backend/src/main/java/entities/DataRepository.java @@ -28,7 +28,7 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; @Entity @Table(name="\"DataRepository\"") @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id") -public class DataRepository implements Serializable { +public class DataRepository implements Serializable,DataEntity { private static final long serialVersionUID = 4162323701450468639L; diff --git a/dmp-backend/src/main/java/entities/Dataset.java b/dmp-backend/src/main/java/entities/Dataset.java index b20c4f7c6..876e8385a 100644 --- a/dmp-backend/src/main/java/entities/Dataset.java +++ b/dmp-backend/src/main/java/entities/Dataset.java @@ -32,7 +32,7 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; @Entity @Table(name="\"Dataset\"") @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id") -public class Dataset implements Serializable { +public class Dataset implements Serializable,DataEntity { private static final long serialVersionUID = 3575723814399553259L; diff --git a/dmp-backend/src/main/java/entities/Organisation.java b/dmp-backend/src/main/java/entities/Organisation.java index d764286d7..c0582f178 100644 --- a/dmp-backend/src/main/java/entities/Organisation.java +++ b/dmp-backend/src/main/java/entities/Organisation.java @@ -30,7 +30,7 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; @Entity @Table(name="\"Organisation\"") @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id") -public class Organisation implements Serializable { +public class Organisation implements Serializable,DataEntity { private static final long serialVersionUID = 3614146195740867782L; diff --git a/dmp-backend/src/main/java/entities/Project.java b/dmp-backend/src/main/java/entities/Project.java index c1092ce10..a1b9c3f4a 100644 --- a/dmp-backend/src/main/java/entities/Project.java +++ b/dmp-backend/src/main/java/entities/Project.java @@ -35,7 +35,7 @@ import com.fasterxml.jackson.databind.SerializationFeature; @Entity @Table(name="\"Project\"") @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id") -public class Project implements Serializable { +public class Project implements Serializable,DataEntity { private static final long serialVersionUID = -767048645098311154L; diff --git a/dmp-backend/src/main/java/entities/Registry.java b/dmp-backend/src/main/java/entities/Registry.java index e1d59a955..d68922d4c 100644 --- a/dmp-backend/src/main/java/entities/Registry.java +++ b/dmp-backend/src/main/java/entities/Registry.java @@ -30,7 +30,7 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; @Entity @Table(name="\"Registry\"") @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id") -public class Registry implements Serializable { +public class Registry implements Serializable,DataEntity { private static final long serialVersionUID = -277572262583178090L; diff --git a/dmp-backend/src/main/java/entities/Researcher.java b/dmp-backend/src/main/java/entities/Researcher.java index 6f73094a0..d4a5287ff 100644 --- a/dmp-backend/src/main/java/entities/Researcher.java +++ b/dmp-backend/src/main/java/entities/Researcher.java @@ -30,7 +30,7 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; @Entity @Table(name="\"Researcher\"") @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id") -public class Researcher implements Serializable { +public class Researcher implements Serializable,DataEntity { private static final long serialVersionUID = -2513186824704729896L; diff --git a/dmp-backend/src/main/java/entities/Service.java b/dmp-backend/src/main/java/entities/Service.java index 4f79e7035..ad0907ba9 100644 --- a/dmp-backend/src/main/java/entities/Service.java +++ b/dmp-backend/src/main/java/entities/Service.java @@ -32,7 +32,7 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; @Entity @Table(name="\"Service\"") @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id") -public class Service implements Serializable { +public class Service implements Serializable,DataEntity { private static final long serialVersionUID = 163279108676904730L; diff --git a/dmp-backend/src/main/java/models/DataModel.java b/dmp-backend/src/main/java/models/DataModel.java new file mode 100644 index 000000000..12a0925cd --- /dev/null +++ b/dmp-backend/src/main/java/models/DataModel.java @@ -0,0 +1,8 @@ +package models; + +import entities.DataEntity; + +public interface DataModel { + void fromDataModel(T entity) throws InstantiationException, IllegalAccessException; + T toDataModel(); +} diff --git a/dmp-backend/src/main/java/models/dataset/criteria/Criteria.java b/dmp-backend/src/main/java/models/criteria/Criteria.java similarity index 55% rename from dmp-backend/src/main/java/models/dataset/criteria/Criteria.java rename to dmp-backend/src/main/java/models/criteria/Criteria.java index 9f1387045..9510e5ac8 100644 --- a/dmp-backend/src/main/java/models/dataset/criteria/Criteria.java +++ b/dmp-backend/src/main/java/models/criteria/Criteria.java @@ -1,6 +1,8 @@ -package models.dataset.criteria; +package models.criteria; -public abstract class Criteria { +import entities.DataEntity; + +public abstract class Criteria { private String like; public String getLike() { diff --git a/dmp-backend/src/main/java/models/dataset/criteria/DataRepositoryCriteria.java b/dmp-backend/src/main/java/models/criteria/DataRepositoryCriteria.java similarity index 76% rename from dmp-backend/src/main/java/models/dataset/criteria/DataRepositoryCriteria.java rename to dmp-backend/src/main/java/models/criteria/DataRepositoryCriteria.java index 0b5c0f0a5..77788c063 100644 --- a/dmp-backend/src/main/java/models/dataset/criteria/DataRepositoryCriteria.java +++ b/dmp-backend/src/main/java/models/criteria/DataRepositoryCriteria.java @@ -1,4 +1,4 @@ -package models.dataset.criteria; +package models.criteria; import entities.DataRepository; diff --git a/dmp-backend/src/main/java/models/criteria/OrganisationCriteria.java b/dmp-backend/src/main/java/models/criteria/OrganisationCriteria.java new file mode 100644 index 000000000..60af4982e --- /dev/null +++ b/dmp-backend/src/main/java/models/criteria/OrganisationCriteria.java @@ -0,0 +1,6 @@ +package models.criteria; + +import entities.Organisation; + +public class OrganisationCriteria extends Criteria { +} diff --git a/dmp-backend/src/main/java/models/dataset/criteria/RegistryCriteria.java b/dmp-backend/src/main/java/models/criteria/RegistryCriteria.java similarity index 72% rename from dmp-backend/src/main/java/models/dataset/criteria/RegistryCriteria.java rename to dmp-backend/src/main/java/models/criteria/RegistryCriteria.java index aa387ea9b..e913b84a2 100644 --- a/dmp-backend/src/main/java/models/dataset/criteria/RegistryCriteria.java +++ b/dmp-backend/src/main/java/models/criteria/RegistryCriteria.java @@ -1,4 +1,4 @@ -package models.dataset.criteria; +package models.criteria; import entities.Registry; diff --git a/dmp-backend/src/main/java/models/criteria/ResearcherCriteria.java b/dmp-backend/src/main/java/models/criteria/ResearcherCriteria.java new file mode 100644 index 000000000..1918d647c --- /dev/null +++ b/dmp-backend/src/main/java/models/criteria/ResearcherCriteria.java @@ -0,0 +1,6 @@ +package models.criteria; + +import entities.Researcher; + +public class ResearcherCriteria extends Criteria { +} diff --git a/dmp-backend/src/main/java/models/dataset/criteria/ServiceCriteria.java b/dmp-backend/src/main/java/models/criteria/ServiceCriteria.java similarity index 72% rename from dmp-backend/src/main/java/models/dataset/criteria/ServiceCriteria.java rename to dmp-backend/src/main/java/models/criteria/ServiceCriteria.java index 0da5acf95..c821181a2 100644 --- a/dmp-backend/src/main/java/models/dataset/criteria/ServiceCriteria.java +++ b/dmp-backend/src/main/java/models/criteria/ServiceCriteria.java @@ -1,4 +1,4 @@ -package models.dataset.criteria; +package models.criteria; import entities.Service; diff --git a/dmp-backend/src/main/java/models/dataset/DataRepository.java b/dmp-backend/src/main/java/models/dataset/DataRepository.java index c99c8104c..f4cb6895b 100644 --- a/dmp-backend/src/main/java/models/dataset/DataRepository.java +++ b/dmp-backend/src/main/java/models/dataset/DataRepository.java @@ -1,8 +1,10 @@ package models.dataset; +import models.DataModel; + import java.util.Date; -public class DataRepository { +public class DataRepository implements DataModel{ private String pid; private String name; private String uri; diff --git a/dmp-backend/src/main/java/models/dataset/Dataset.java b/dmp-backend/src/main/java/models/dataset/Dataset.java index 8d0a7da99..6d433f962 100644 --- a/dmp-backend/src/main/java/models/dataset/Dataset.java +++ b/dmp-backend/src/main/java/models/dataset/Dataset.java @@ -1,11 +1,13 @@ package models.dataset; +import models.DataModel; + import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.UUID; -public class Dataset { +public class Dataset implements DataModel{ private UUID id; private String label; private String reference; @@ -72,7 +74,7 @@ public class Dataset { this.dataRepositories = dataRepositories; } - public void fromDataModel(entities.DataRepository entity){ + public void fromDataModel(entities.Dataset entity){ } diff --git a/dmp-backend/src/main/java/models/dataset/Registry.java b/dmp-backend/src/main/java/models/dataset/Registry.java index e1c99dbea..d610e1a37 100644 --- a/dmp-backend/src/main/java/models/dataset/Registry.java +++ b/dmp-backend/src/main/java/models/dataset/Registry.java @@ -1,6 +1,8 @@ package models.dataset; -public class Registry { +import models.DataModel; + +public class Registry implements DataModel{ public void fromDataModel(entities.Registry entity){ diff --git a/dmp-backend/src/main/java/models/dataset/Service.java b/dmp-backend/src/main/java/models/dataset/Service.java index 972f666da..d5942b902 100644 --- a/dmp-backend/src/main/java/models/dataset/Service.java +++ b/dmp-backend/src/main/java/models/dataset/Service.java @@ -1,6 +1,8 @@ package models.dataset; -public class Service { +import models.DataModel; + +public class Service implements DataModel{ public void fromDataModel(entities.Service entity){ } diff --git a/dmp-backend/src/main/java/models/dmp/DataManagementPlan.java b/dmp-backend/src/main/java/models/dmp/DataManagementPlan.java new file mode 100644 index 000000000..34bed1f56 --- /dev/null +++ b/dmp-backend/src/main/java/models/dmp/DataManagementPlan.java @@ -0,0 +1,110 @@ +package models.dmp; + +import com.sun.org.apache.regexp.internal.RE; +import entities.*; +import entities.Project; +import models.DataModel; +import utilities.builders.DomainModelConverter; + +import java.util.*; +import java.util.stream.Collector; +import java.util.stream.Collectors; + +public class DataManagementPlan implements DataModel{ + private UUID id; + private String label; + private UUID previous; + private int version; + private int status; + private models.dmp.Project project; + private List organizations; + private List researchers; + + public UUID getId() { + return id; + } + + public void setId(UUID id) { + this.id = id; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public UUID getPrevious() { + return previous; + } + + public void setPrevious(UUID previous) { + this.previous = previous; + } + + public int getVersion() { + return version; + } + + public void setVersion(int version) { + this.version = version; + } + + public List getOrganizations() { + return organizations; + } + + public void setOrganizations(List organizations) { + this.organizations = organizations; + } + + public List getResearchers() { + return researchers; + } + + public void setResearchers(List researchers) { + this.researchers = researchers; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public models.dmp.Project getProject() { + return project; + } + + public void setProject(models.dmp.Project project) { + this.project = project; + } + + @Override + public void fromDataModel(DMP entity) throws InstantiationException, IllegalAccessException { + this.id = entity.getId(); + this.organizations =new DomainModelConverter().fromDataModel(entity.getOrganisations().stream().collect(Collectors.toList()),Organisation.class); + this.researchers =new DomainModelConverter().fromDataModel(entity.getResearchers().stream().collect(Collectors.toList()),Researcher.class); + this.version = entity.getVersion(); + this.previous = entity.getPrevious(); + this.label = entity.getLabel(); + this.project = new models.dmp.Project(); + this.project.fromDataModel(entity.getProject()); + } + + @Override + public DMP toDataModel() { + DMP dataManagementPlanEntity = new DMP(); + dataManagementPlanEntity.setId(this.id); + dataManagementPlanEntity.setOrganisations(new HashSet(new DomainModelConverter().toDataModel(this.organizations))); + dataManagementPlanEntity.setResearchers(new HashSet(new DomainModelConverter().toDataModel(this.researchers))); + dataManagementPlanEntity.setVersion(this.version); + dataManagementPlanEntity.setPrevious(this.previous); + dataManagementPlanEntity.setLabel(this.label); + return dataManagementPlanEntity; + } +} diff --git a/dmp-backend/src/main/java/models/dmp/Organisation.java b/dmp-backend/src/main/java/models/dmp/Organisation.java new file mode 100644 index 000000000..6bd10d8c6 --- /dev/null +++ b/dmp-backend/src/main/java/models/dmp/Organisation.java @@ -0,0 +1,54 @@ +package models.dmp; + +import models.DataModel; + +import java.util.Date; + +public class Organisation implements DataModel { + private String pid; + private String name; + private String uri; + private int status; + + public String getPid() { + return pid; + } + + public void setPid(String pid) { + this.pid = pid; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUri() { + return uri; + } + + public void setUri(String uri) { + this.uri = uri; + } + + @Override + public void fromDataModel(entities.Organisation entity) { + this.pid = entity.getReference(); + this.name = entity.getLabel(); + this.uri = entity.getUri(); + } + + @Override + public entities.Organisation toDataModel() { + entities.Organisation organisationEntity = new entities.Organisation(); + organisationEntity.setReference(this.pid); + organisationEntity.setLabel(this.name); + organisationEntity.setUri(this.uri); + organisationEntity.setCreated(new Date()); + organisationEntity.setStatus((short)this.status); + return organisationEntity; + } +} diff --git a/dmp-backend/src/main/java/models/dmp/Project.java b/dmp-backend/src/main/java/models/dmp/Project.java new file mode 100644 index 000000000..cc4fa0289 --- /dev/null +++ b/dmp-backend/src/main/java/models/dmp/Project.java @@ -0,0 +1,29 @@ +package models.dmp; + +import models.DataModel; + +import java.util.UUID; + +public class Project implements DataModel{ + private UUID id; + + public UUID getId() { + return id; + } + + public void setId(UUID id) { + this.id = id; + } + + @Override + public void fromDataModel(entities.Project entity) { + this.id = entity.getId(); + } + + @Override + public entities.Project toDataModel() { + entities.Project project = new entities.Project(); + project.setId(this.id); + return project; + } +} diff --git a/dmp-backend/src/main/java/models/dmp/Researcher.java b/dmp-backend/src/main/java/models/dmp/Researcher.java new file mode 100644 index 000000000..94cfb7901 --- /dev/null +++ b/dmp-backend/src/main/java/models/dmp/Researcher.java @@ -0,0 +1,62 @@ +package models.dmp; + +import models.DataModel; + +import java.util.Date; + +public class Researcher implements DataModel { + private String pid; + private String name; + private String uri; + private int status; + + public String getPid() { + return pid; + } + + public void setPid(String pid) { + this.pid = pid; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUri() { + return uri; + } + + public void setUri(String uri) { + this.uri = uri; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + @Override + public void fromDataModel(entities.Researcher entity) { + this.pid = entity.getReference(); + this.name = entity.getLabel(); + this.status = entity.getStatus(); + this.uri = entity.getUri(); + } + + @Override + public entities.Researcher toDataModel() { + entities.Researcher researcher = new entities.Researcher(); + researcher.setReference(this.pid); + researcher.setLabel(this.name); + researcher.setCreated(new Date()); + researcher.setStatus((short)this.status); + return researcher; + } +} diff --git a/dmp-backend/src/main/java/rest/entities/DMPs.java b/dmp-backend/src/main/java/rest/entities/DMPs.java index 254dbf304..bdc85de20 100644 --- a/dmp-backend/src/main/java/rest/entities/DMPs.java +++ b/dmp-backend/src/main/java/rest/entities/DMPs.java @@ -1,16 +1,16 @@ package rest.entities; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; import javax.transaction.Transactional; +import models.criteria.DataRepositoryCriteria; +import models.criteria.OrganisationCriteria; +import models.criteria.ResearcherCriteria; +import models.criteria.ServiceCriteria; +import models.dmp.DataManagementPlan; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -20,16 +20,9 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.mchange.v2.sql.filter.SynchronizedFilterDataSource; - import dao.entities.DMPDao; import dao.entities.DMPProfileDao; import dao.entities.DataRepositoryDao; @@ -44,16 +37,11 @@ import dao.entities.ResearcherDao; import dao.entities.ServiceDao; import dao.entities.UserInfoDao; import entities.DMP; -import entities.DMPProfile; import entities.Dataset; -import entities.DatasetProfile; -import entities.DatasetProfileRuleset; -import entities.Project; import entities.UserInfo; import entities.responses.IDLabelPair; import helpers.SerializerProvider; -import helpers.Transformers; -import responses.RestResponse; +import utilities.builders.DomainModelConverter; @RestController @@ -94,7 +82,9 @@ public class DMPs { public @ResponseBody ResponseEntity getDMP(@PathVariable("id") String id){ try { DMP dmp = dMPDao.read(UUID.fromString(id)); - return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(dmp)); + DataManagementPlan dataManagementPlan = new DataManagementPlan(); + dataManagementPlan.fromDataModel(dmp); + return ResponseEntity.status(HttpStatus.OK).body(dataManagementPlan); } catch(Exception ex) { ex.printStackTrace(); @@ -243,7 +233,7 @@ public class DMPs { } @RequestMapping(method = RequestMethod.POST, value = { "/dmp/createofuser" }, produces="text/plain", consumes = "application/json") - public @ResponseBody ResponseEntity createDmpOfUser(@RequestBody DMP dmp){ + public @ResponseBody ResponseEntity createDmpOfUser(@RequestBody DataManagementPlan dataManagementPlan){ String userID = null; @@ -259,11 +249,31 @@ public class DMPs { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here"); try { - + DMP dmp = dataManagementPlan.toDataModel(); + + if(dmp.getOrganisations()!=null&&!dmp.getOrganisations().isEmpty()){ + for(entities.Organisation organisation: dmp.getOrganisations()){ + OrganisationCriteria criteria = new OrganisationCriteria(); + criteria.setLike(organisation.getReference()); + List entries = this.organisationDao.listBy(criteria); + if(entries!=null&&!entries.isEmpty())organisation.setId(entries.get(0).getId()); + else organisation = this.organisationDao.create(organisation); + } + } + + if(dmp.getResearchers()!=null&&!dmp.getResearchers().isEmpty()){ + for(entities.Researcher researcher : dmp.getResearchers()){ + ResearcherCriteria criteria = new ResearcherCriteria(); + criteria.setLike(researcher.getReference()); + List entries = this.researcherDao.listBy(criteria); + if(entries!=null&&!entries.isEmpty())researcher.setId(entries.get(0).getId()); + else researcher = this.researcherDao.create(researcher); + } + } dmp.setId(null); dmp.setCreator(userInfo); - + dmp.setProject(this.projectDao.read(dataManagementPlan.getProject().getId())); Set users = new HashSet(); users.add(userInfo); dmp.setUsers(users); diff --git a/dmp-backend/src/main/java/rest/entities/DatasetProfileController.java b/dmp-backend/src/main/java/rest/entities/DatasetProfileController.java index a54e07ceb..cdae0581d 100644 --- a/dmp-backend/src/main/java/rest/entities/DatasetProfileController.java +++ b/dmp-backend/src/main/java/rest/entities/DatasetProfileController.java @@ -16,7 +16,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; -import com.google.gson.JsonObject; import dao.entities.DatasetDao; import dao.entities.DatasetProfileDao; diff --git a/dmp-backend/src/main/java/rest/entities/Datasets.java b/dmp-backend/src/main/java/rest/entities/Datasets.java index 93f7bd106..bf3ca874c 100644 --- a/dmp-backend/src/main/java/rest/entities/Datasets.java +++ b/dmp-backend/src/main/java/rest/entities/Datasets.java @@ -1,23 +1,13 @@ package rest.entities; -import java.io.IOException; -import java.io.PrintStream; import java.util.Date; -import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.UUID; -import java.util.stream.Collectors; -import javax.transaction.Transactional; - -import org.apache.commons.lang3.SerializationUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -27,11 +17,6 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; - import dao.entities.DMPDao; import dao.entities.DMPProfileDao; import dao.entities.DataRepositoryDao; @@ -46,20 +31,14 @@ import dao.entities.ResearcherDao; import dao.entities.ServiceDao; import dao.entities.UserInfoDao; import entities.DMP; -import entities.DMPProfile; import entities.Dataset; import entities.DatasetProfile; -import entities.DatasetProfileRuleset; -import entities.DatasetProfileViewstyle; -import entities.Organisation; -import entities.Project; import entities.UserInfo; import helpers.SafeCleanAttribs; import helpers.SerializerProvider; -import helpers.Transformers; -import models.dataset.criteria.DataRepositoryCriteria; -import models.dataset.criteria.RegistryCriteria; -import models.dataset.criteria.ServiceCriteria; +import models.criteria.DataRepositoryCriteria; +import models.criteria.RegistryCriteria; +import models.criteria.ServiceCriteria; import responses.RestResponse; diff --git a/dmp-backend/src/main/java/rest/entities/Projects.java b/dmp-backend/src/main/java/rest/entities/Projects.java index 88101c696..4ef5066b1 100644 --- a/dmp-backend/src/main/java/rest/entities/Projects.java +++ b/dmp-backend/src/main/java/rest/entities/Projects.java @@ -179,10 +179,10 @@ public class Projects { p.setId(project.getId()); try { projectDao.delete(p); - return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted Project entity!\"}"); + return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted Researcher entity!\"}"); } catch (Exception e) { e.printStackTrace(); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete Project!\"}"); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete Researcher!\"}"); } } @@ -199,7 +199,7 @@ public class Projects { return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted project!\"}"); } catch (Exception e) { e.printStackTrace(); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not delete Project!\"}"); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not delete Researcher!\"}"); } } @@ -212,7 +212,7 @@ public class Projects { Set dmps = projectDao.read(project.getId()).getDmps(); return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(dmps)); } catch (Exception e) { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create Project!\"}"); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create Researcher!\"}"); } } @@ -250,10 +250,10 @@ public class Projects { /* * OLD ONE - Map userProjects = new HashMap(); + Map userProjects = new HashMap(); userInfo.getDmps().forEach( dmp -> { - Project proj = dmp.getProject(); + Researcher proj = dmp.getProject(); userProjects.put(proj.getId(), proj); }); @@ -320,7 +320,7 @@ public class Projects { // @Transactional // @RequestMapping(method = RequestMethod.POST, value = { "/project/updateofuser" }, produces="text/plain") -// public @ResponseBody ResponseEntity updateProjectOfUser(@RequestBody Project project){ +// public @ResponseBody ResponseEntity updateProjectOfUser(@RequestBody Researcher project){ // // if(project.getId()==null) // return ResponseEntity.status(HttpStatus.NOT_MODIFIED).body("Cannot update, id was null"); diff --git a/dmp-backend/src/main/java/utilities/builders/DomainModelConverter.java b/dmp-backend/src/main/java/utilities/builders/DomainModelConverter.java new file mode 100644 index 000000000..5e82242db --- /dev/null +++ b/dmp-backend/src/main/java/utilities/builders/DomainModelConverter.java @@ -0,0 +1,28 @@ +package utilities.builders; + +import entities.DataEntity; +import models.DataModel; + +import java.util.LinkedList; +import java.util.List; + +public class DomainModelConverter> { + + public List toDataModel(List models){ + List entities = new LinkedList<>(); + for(U model : models){ + entities.add(model.toDataModel()); + } + return entities; + } + + public List fromDataModel(List entities,Class clazz) throws IllegalAccessException, InstantiationException { + List models = new LinkedList<>(); + for(T entity:entities){ + U model = clazz.newInstance(); + model.fromDataModel(entity); + models.add(model); + } + return models; + } +} diff --git a/dmp-frontend/src/app/dmps/dmp.component.ts b/dmp-frontend/src/app/dmps/dmp.component.ts index ecc8bd5ba..5f0fe7e0d 100644 --- a/dmp-frontend/src/app/dmps/dmp.component.ts +++ b/dmp-frontend/src/app/dmps/dmp.component.ts @@ -190,9 +190,12 @@ export class DmpComponent implements OnInit { editDmp(item) { - this.dmp = Object.assign({}, item); - this.dmp.project = item.project.id; - $("#newDmpModal").modal("show"); + this.serverService.getDmp(item.id).subscribe(result=>{ + this.dmp = result; + this.dmp.project = result.project.id + $("#newDmpModal").modal("show"); + }) + } cloneDmp(item) { diff --git a/dmp-frontend/src/app/services/rest-base.ts b/dmp-frontend/src/app/services/rest-base.ts index 868eeab67..b0210c108 100644 --- a/dmp-frontend/src/app/services/rest-base.ts +++ b/dmp-frontend/src/app/services/rest-base.ts @@ -18,7 +18,7 @@ export class RestBase { protocol: string = "http"; - hostname: string ="192.168.32.103" + hostname: string ="localhost" port: number = 8080; webappname: string = "dmp-backend";