referential integrity for researchers and organizations
This commit is contained in:
parent
2f86c38e21
commit
7b4bea0710
|
@ -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<DataRepository, UUID> {
|
||||
|
||||
|
|
|
@ -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<DataRepository, UUID> implements DataRepositoryDao {
|
||||
|
||||
|
|
|
@ -5,7 +5,9 @@ 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<Organisation, UUID> {
|
||||
|
||||
|
@ -13,4 +15,7 @@ public interface OrganisationDao extends Dao<Organisation, UUID> {
|
|||
|
||||
List<IDLabelPair> listAllIDsLabels();
|
||||
|
||||
List<Organisation> listBy(Criteria<Organisation> criteria);
|
||||
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
@ -38,5 +43,15 @@ public class OrganisationDaoImpl extends JpaDao<Organisation, UUID> implements O
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Organisation> listBy(Criteria<Organisation> criteria) {
|
||||
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<Organisation> criteriaQuery = criteriaBuilder .createQuery(Organisation.class);
|
||||
Root<Organisation> root = criteriaQuery.from(Organisation.class);
|
||||
criteriaQuery.where(criteriaBuilder.equal(root.get("reference"), criteria.getLike()));
|
||||
TypedQuery<Organisation> typedQuery = entityManager.createQuery(criteriaQuery);
|
||||
return typedQuery.getResultList();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Registry, UUID> {
|
||||
|
||||
|
|
|
@ -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<Registry, UUID> implements RegistryDao {
|
||||
|
||||
|
|
|
@ -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<Researcher, UUID> {
|
||||
|
||||
|
@ -15,4 +17,7 @@ public interface ResearcherDao extends Dao<Researcher, UUID> {
|
|||
|
||||
Researcher getResearcherByEmail(String email);
|
||||
|
||||
List<Researcher> listBy(Criteria<Researcher> criteria);
|
||||
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
@ -49,5 +54,15 @@ public class ResearcherDaoImpl extends JpaDao<Researcher, UUID> implements Resea
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Researcher> listBy(Criteria<Researcher> criteria) {
|
||||
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<Researcher> criteriaQuery = criteriaBuilder .createQuery(Researcher.class);
|
||||
Root<Researcher> root = criteriaQuery.from(Researcher.class);
|
||||
criteriaQuery.where(criteriaBuilder.equal(root.get("reference"), criteria.getLike()));
|
||||
TypedQuery<Researcher> typedQuery = entityManager.createQuery(criteriaQuery);
|
||||
return typedQuery.getResultList();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Service, UUID> {
|
||||
|
||||
|
|
|
@ -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<Service, UUID> implements ServiceDao {
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
package entities;
|
||||
|
||||
public interface DataEntity {
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package models;
|
||||
|
||||
import entities.DataEntity;
|
||||
|
||||
public interface DataModel<T extends DataEntity> {
|
||||
void fromDataModel(T entity) throws InstantiationException, IllegalAccessException;
|
||||
T toDataModel();
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package models.dataset.criteria;
|
||||
package models.criteria;
|
||||
|
||||
public abstract class Criteria<T> {
|
||||
import entities.DataEntity;
|
||||
|
||||
public abstract class Criteria<T extends DataEntity> {
|
||||
private String like;
|
||||
|
||||
public String getLike() {
|
|
@ -1,4 +1,4 @@
|
|||
package models.dataset.criteria;
|
||||
package models.criteria;
|
||||
|
||||
import entities.DataRepository;
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package models.criteria;
|
||||
|
||||
import entities.Organisation;
|
||||
|
||||
public class OrganisationCriteria extends Criteria<Organisation> {
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package models.dataset.criteria;
|
||||
package models.criteria;
|
||||
|
||||
import entities.Registry;
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package models.criteria;
|
||||
|
||||
import entities.Researcher;
|
||||
|
||||
public class ResearcherCriteria extends Criteria<Researcher> {
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package models.dataset.criteria;
|
||||
package models.criteria;
|
||||
|
||||
import entities.Service;
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
package models.dataset;
|
||||
|
||||
import models.DataModel;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class DataRepository {
|
||||
public class DataRepository implements DataModel<entities.DataRepository>{
|
||||
private String pid;
|
||||
private String name;
|
||||
private String uri;
|
||||
|
|
|
@ -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<entities.Dataset>{
|
||||
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){
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package models.dataset;
|
||||
|
||||
public class Registry {
|
||||
import models.DataModel;
|
||||
|
||||
public class Registry implements DataModel<entities.Registry>{
|
||||
|
||||
public void fromDataModel(entities.Registry entity){
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package models.dataset;
|
||||
|
||||
public class Service {
|
||||
import models.DataModel;
|
||||
|
||||
public class Service implements DataModel<entities.Service>{
|
||||
public void fromDataModel(entities.Service entity){
|
||||
|
||||
}
|
||||
|
|
|
@ -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<DMP>{
|
||||
private UUID id;
|
||||
private String label;
|
||||
private UUID previous;
|
||||
private int version;
|
||||
private int status;
|
||||
private models.dmp.Project project;
|
||||
private List<Organisation> organizations;
|
||||
private List<Researcher> 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<Organisation> getOrganizations() {
|
||||
return organizations;
|
||||
}
|
||||
|
||||
public void setOrganizations(List<Organisation> organizations) {
|
||||
this.organizations = organizations;
|
||||
}
|
||||
|
||||
public List<Researcher> getResearchers() {
|
||||
return researchers;
|
||||
}
|
||||
|
||||
public void setResearchers(List<Researcher> 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<entities.Organisation,Organisation>().fromDataModel(entity.getOrganisations().stream().collect(Collectors.toList()),Organisation.class);
|
||||
this.researchers =new DomainModelConverter<entities.Researcher,Researcher>().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<entities.Organisation>(new DomainModelConverter<entities.Organisation,Organisation>().toDataModel(this.organizations)));
|
||||
dataManagementPlanEntity.setResearchers(new HashSet<entities.Researcher>(new DomainModelConverter<entities.Researcher,Researcher>().toDataModel(this.researchers)));
|
||||
dataManagementPlanEntity.setVersion(this.version);
|
||||
dataManagementPlanEntity.setPrevious(this.previous);
|
||||
dataManagementPlanEntity.setLabel(this.label);
|
||||
return dataManagementPlanEntity;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package models.dmp;
|
||||
|
||||
import models.DataModel;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Organisation implements DataModel<entities.Organisation> {
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package models.dmp;
|
||||
|
||||
import models.DataModel;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Project implements DataModel<entities.Project>{
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package models.dmp;
|
||||
|
||||
import models.DataModel;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Researcher implements DataModel<entities.Researcher> {
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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<Object> 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<Object> createDmpOfUser(@RequestBody DMP dmp){
|
||||
public @ResponseBody ResponseEntity<Object> 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<entities.Organisation> 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<entities.Researcher> 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<UserInfo> users = new HashSet<UserInfo>();
|
||||
users.add(userInfo);
|
||||
dmp.setUsers(users);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
||||
|
|
|
@ -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<DMP> 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<UUID, Project> userProjects = new HashMap<UUID, Project>();
|
||||
Map<UUID, Researcher> userProjects = new HashMap<UUID, Researcher>();
|
||||
|
||||
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<Object> updateProjectOfUser(@RequestBody Project project){
|
||||
// public @ResponseBody ResponseEntity<Object> updateProjectOfUser(@RequestBody Researcher project){
|
||||
//
|
||||
// if(project.getId()==null)
|
||||
// return ResponseEntity.status(HttpStatus.NOT_MODIFIED).body("Cannot update, id was null");
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package utilities.builders;
|
||||
|
||||
import entities.DataEntity;
|
||||
import models.DataModel;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class DomainModelConverter<T extends DataEntity,U extends DataModel<T>> {
|
||||
|
||||
public List<T> toDataModel(List<U> models){
|
||||
List<T> entities = new LinkedList<>();
|
||||
for(U model : models){
|
||||
entities.add(model.toDataModel());
|
||||
}
|
||||
return entities;
|
||||
}
|
||||
|
||||
public List<U> fromDataModel(List<T> entities,Class<U> clazz) throws IllegalAccessException, InstantiationException {
|
||||
List<U> models = new LinkedList<>();
|
||||
for(T entity:entities){
|
||||
U model = clazz.newInstance();
|
||||
model.fromDataModel(entity);
|
||||
models.add(model);
|
||||
}
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -190,9 +190,12 @@ export class DmpComponent implements OnInit {
|
|||
|
||||
|
||||
editDmp(item) {
|
||||
this.dmp = Object.assign({}, item);
|
||||
this.dmp.project = item.project.id;
|
||||
this.serverService.getDmp(item.id).subscribe(result=>{
|
||||
this.dmp = result;
|
||||
this.dmp.project = result.project.id
|
||||
$("#newDmpModal").modal("show");
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
cloneDmp(item) {
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
Loading…
Reference in New Issue