persist referential integrity
This commit is contained in:
parent
f483b30895
commit
84fd2a5704
|
@ -6,11 +6,14 @@ import java.util.UUID;
|
|||
import dao.Dao;
|
||||
import entities.DataRepository;
|
||||
import entities.responses.IDLabelPair;
|
||||
import models.dataset.criteria.Criteria;
|
||||
|
||||
public interface DataRepositoryDao extends Dao<DataRepository, UUID> {
|
||||
|
||||
List<UUID> listAllIDs();
|
||||
|
||||
List<IDLabelPair> listAllIDsLabels();
|
||||
|
||||
List<DataRepository> listBy(Criteria<DataRepository> criteria);
|
||||
|
||||
}
|
|
@ -5,12 +5,17 @@ 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 org.hibernate.query.Query;
|
||||
|
||||
import dao.JpaDao;
|
||||
import entities.DataRepository;
|
||||
import entities.Registry;
|
||||
import entities.responses.IDLabelPair;
|
||||
import models.dataset.criteria.Criteria;
|
||||
|
||||
public class DataRepositoryDaoImpl extends JpaDao<DataRepository, UUID> implements DataRepositoryDao {
|
||||
|
||||
|
@ -37,6 +42,17 @@ public class DataRepositoryDaoImpl extends JpaDao<DataRepository, UUID> implemen
|
|||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<DataRepository> listBy(Criteria<DataRepository> criteria) {
|
||||
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<DataRepository> criteriaQuery = criteriaBuilder .createQuery(DataRepository.class);
|
||||
Root<DataRepository> root = criteriaQuery.from(DataRepository.class);
|
||||
criteriaQuery.where(criteriaBuilder.equal(root.get("reference"), criteria.getLike()));
|
||||
TypedQuery<DataRepository> typedQuery = entityManager.createQuery(criteriaQuery);
|
||||
return typedQuery.getResultList();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,11 @@ 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;
|
||||
|
||||
public interface RegistryDao extends Dao<Registry, UUID> {
|
||||
|
||||
|
@ -14,5 +16,6 @@ public interface RegistryDao extends Dao<Registry, UUID> {
|
|||
|
||||
List<IDLabelPair> listAllIDsLabels();
|
||||
|
||||
List<Registry> listBy(Criteria<Registry> criteria);
|
||||
|
||||
}
|
|
@ -5,13 +5,18 @@ 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 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;
|
||||
|
||||
public class RegistryDaoImpl extends JpaDao<Registry, UUID> implements RegistryDao {
|
||||
|
||||
|
@ -39,5 +44,16 @@ public class RegistryDaoImpl extends JpaDao<Registry, UUID> implements RegistryD
|
|||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Registry> listBy(Criteria<Registry> criteria) {
|
||||
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<Registry> criteriaQuery = criteriaBuilder .createQuery(Registry.class);
|
||||
Root<Registry> root = criteriaQuery.from(Registry.class);
|
||||
criteriaQuery.where(criteriaBuilder.equal(root.get("reference"), criteria.getLike()));
|
||||
TypedQuery<Registry> typedQuery = entityManager.createQuery(criteriaQuery);
|
||||
return typedQuery.getResultList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -4,8 +4,10 @@ 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;
|
||||
|
||||
public interface ServiceDao extends Dao<Service, UUID> {
|
||||
|
||||
|
@ -13,4 +15,6 @@ public interface ServiceDao extends Dao<Service, UUID> {
|
|||
|
||||
List<IDLabelPair> listAllIDsLabels();
|
||||
|
||||
List<Service> listBy(Criteria<Service> criteria);
|
||||
|
||||
}
|
|
@ -5,12 +5,18 @@ 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 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;
|
||||
|
||||
public class ServiceDaoImpl extends JpaDao<Service, UUID> implements ServiceDao {
|
||||
|
||||
|
@ -37,6 +43,16 @@ public class ServiceDaoImpl extends JpaDao<Service, UUID> implements ServiceDao
|
|||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Service> listBy(Criteria<Service> criteria) {
|
||||
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<Service> criteriaQuery = criteriaBuilder .createQuery(Service.class);
|
||||
Root<Service> root = criteriaQuery.from(Service.class);
|
||||
criteriaQuery.where(criteriaBuilder.equal(root.get("reference"), criteria.getLike()));
|
||||
TypedQuery<Service> typedQuery = entityManager.createQuery(criteriaQuery);
|
||||
return typedQuery.getResultList();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -48,8 +48,7 @@ public class DataRepository implements Serializable {
|
|||
@Column(name = "\"Abbreviation\"")
|
||||
private String abbreviation;
|
||||
|
||||
@Type(type="typedefinition.XMLType")
|
||||
@Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true)
|
||||
@Column(name = "\"Reference\"", nullable = false)
|
||||
private String reference;
|
||||
|
||||
@Column(name = "\"Uri\"")
|
||||
|
|
|
@ -49,8 +49,7 @@ public class Registry implements Serializable {
|
|||
@Column(name = "\"Abbreviation\"")
|
||||
private String abbreviation;
|
||||
|
||||
@Type(type="typedefinition.XMLType")
|
||||
@Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true)
|
||||
@Column(name = "\"Reference\"", nullable = true)
|
||||
private String reference;
|
||||
|
||||
@Column(name = "\"Uri\"")
|
||||
|
|
|
@ -50,15 +50,14 @@ public class Service implements Serializable {
|
|||
@Column(name = "\"Abbreviation\"")
|
||||
private String abbreviation;
|
||||
|
||||
@Type(type="typedefinition.XMLType")
|
||||
@Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true)
|
||||
@Column(name = "\"Reference\"", nullable = true)
|
||||
private String reference;
|
||||
|
||||
@Column(name = "\"Uri\"")
|
||||
private String uri;
|
||||
|
||||
@Type(type="typedefinition.XMLType")
|
||||
@Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true)
|
||||
@Column(name = "\"Definition\"", columnDefinition = "xml", nullable = false)
|
||||
private String definition;
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package models.dataset;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class DataRepository {
|
||||
private String pid;
|
||||
private String name;
|
||||
private String uri;
|
||||
|
||||
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 void fromDataModel(entities.DataRepository entity){
|
||||
this.pid = entity.getReference();
|
||||
this.name = entity.getLabel();
|
||||
this.uri = entity.getUri();
|
||||
}
|
||||
|
||||
public entities.DataRepository toDataModel(){
|
||||
entities.DataRepository entity = new entities.DataRepository();
|
||||
entity.setReference(this.pid);
|
||||
entity.setLabel(this.name);
|
||||
entity.setUri(this.uri);
|
||||
entity.setCreated(new Date());
|
||||
entity.setModified(new Date());
|
||||
entity.setStatus((short)0);
|
||||
return entity;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
package models.dataset;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Dataset {
|
||||
private UUID id;
|
||||
private String label;
|
||||
private String reference;
|
||||
private String uri;
|
||||
private short status;
|
||||
private String properties;
|
||||
private List<Registry> registries;
|
||||
private List<Service> services;
|
||||
private List<DataRepository> dataRepositories;
|
||||
|
||||
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 String getReference() {
|
||||
return reference;
|
||||
}
|
||||
|
||||
public void setReference(String reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
public String getUri() {
|
||||
return uri;
|
||||
}
|
||||
public void setUri(String uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
public short getStatus() {
|
||||
return status;
|
||||
}
|
||||
public void setStatus(short status) {
|
||||
this.status = status;
|
||||
}
|
||||
public String getProperties() {
|
||||
return properties;
|
||||
}
|
||||
public void setProperties(String properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
public List<Registry> getRegistries() {
|
||||
return registries;
|
||||
}
|
||||
public void setRegistries(List<Registry> registries) {
|
||||
this.registries = registries;
|
||||
}
|
||||
public List<Service> getServices() {
|
||||
return services;
|
||||
}
|
||||
public void setServices(List<Service> services) {
|
||||
this.services = services;
|
||||
}
|
||||
public List<DataRepository> getDataRepositories() {
|
||||
return dataRepositories;
|
||||
}
|
||||
public void setDataRepositories(List<DataRepository> dataRepositories) {
|
||||
this.dataRepositories = dataRepositories;
|
||||
}
|
||||
|
||||
public void fromDataModel(entities.DataRepository entity){
|
||||
|
||||
}
|
||||
|
||||
public entities.Dataset toDataModel(){
|
||||
entities.Dataset entity = new entities.Dataset();
|
||||
entity.setId(this.id);
|
||||
entity.setLabel(this.label);
|
||||
entity.setReference(this.reference);
|
||||
entity.setUri(this.uri);
|
||||
entity.setProperties(this.properties);
|
||||
entity.setStatus(this.status);
|
||||
|
||||
if(!this.registries.isEmpty()){
|
||||
entity.setRegistries(new HashSet<entities.Registry>());
|
||||
for(Registry registry:this.registries){
|
||||
entity.getRegistries().add(registry.toDataModel());
|
||||
}
|
||||
}
|
||||
|
||||
if(!this.dataRepositories.isEmpty()){
|
||||
entity.setDataRepositories(new HashSet<entities.DataRepository>());
|
||||
for(DataRepository dataRepository:this.dataRepositories){
|
||||
entity.getDataRepositories().add(dataRepository.toDataModel());
|
||||
}
|
||||
}
|
||||
|
||||
if(!this.services.isEmpty()){
|
||||
entity.setServices(new HashSet<entities.Service>());
|
||||
for(Service service:this.services){
|
||||
entity.getServices().add(service.toDataModel());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package models.dataset;
|
||||
|
||||
public class Registry {
|
||||
|
||||
public void fromDataModel(entities.Registry entity){
|
||||
|
||||
}
|
||||
|
||||
public entities.Registry toDataModel(){
|
||||
entities.Registry entity = new entities.Registry();
|
||||
return entity;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package models.dataset;
|
||||
|
||||
public class Service {
|
||||
public void fromDataModel(entities.Service entity){
|
||||
|
||||
}
|
||||
|
||||
public entities.Service toDataModel(){
|
||||
entities.Service entity = new entities.Service();
|
||||
return entity;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package models.dataset.criteria;
|
||||
|
||||
public abstract class Criteria<T> {
|
||||
private String like;
|
||||
|
||||
public String getLike() {
|
||||
return like;
|
||||
}
|
||||
|
||||
public void setLike(String like) {
|
||||
this.like = like;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package models.dataset.criteria;
|
||||
|
||||
import entities.DataRepository;
|
||||
|
||||
public class DataRepositoryCriteria extends Criteria<DataRepository>{
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package models.dataset.criteria;
|
||||
|
||||
import entities.Registry;
|
||||
|
||||
public class RegistryCriteria extends Criteria<Registry>{
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package models.dataset.criteria;
|
||||
|
||||
import entities.Service;
|
||||
|
||||
public class ServiceCriteria extends Criteria<Service>{
|
||||
|
||||
}
|
|
@ -57,6 +57,9 @@ 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 responses.RestResponse;
|
||||
|
||||
|
||||
|
@ -126,10 +129,8 @@ public class Datasets {
|
|||
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/create" }, consumes = "application/json", produces="application/json")
|
||||
public @ResponseBody ResponseEntity<Object> createDataset(@RequestBody Dataset dataset) {
|
||||
|
||||
|
||||
|
||||
public @ResponseBody ResponseEntity<Object> createDataset(@RequestBody models.dataset.Dataset modeldataset) {
|
||||
|
||||
String userID = null;
|
||||
try {
|
||||
userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
|
||||
|
@ -143,6 +144,36 @@ public class Datasets {
|
|||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here");
|
||||
|
||||
|
||||
Dataset dataset = modeldataset.toDataModel();
|
||||
if(dataset.getDataRepositories()!=null&&!dataset.getDataRepositories().isEmpty()){
|
||||
for(entities.DataRepository dataRepo : dataset.getDataRepositories()){
|
||||
DataRepositoryCriteria criteria = new DataRepositoryCriteria();
|
||||
criteria.setLike(dataRepo.getReference());
|
||||
List<entities.DataRepository> entries = this.dataRepositoryDao.listBy(criteria);
|
||||
if(entries!=null&&!entries.isEmpty())dataRepo.setId(entries.get(0).getId());
|
||||
else dataRepo = this.dataRepositoryDao.create(dataRepo);
|
||||
}
|
||||
}
|
||||
|
||||
if(dataset.getServices()!=null&&!dataset.getServices().isEmpty()){
|
||||
for(entities.Service service : dataset.getServices()){
|
||||
ServiceCriteria criteria = new ServiceCriteria();
|
||||
criteria.setLike(service.getReference());
|
||||
List<entities.Service> entries = this.serviceDao.listBy(criteria);
|
||||
if(entries!=null&&!entries.isEmpty())service.setId(entries.get(0).getId());
|
||||
else service = this.serviceDao.create(service);
|
||||
}
|
||||
}
|
||||
|
||||
if(dataset.getRegistries()!=null&&!dataset.getRegistries().isEmpty()){
|
||||
for(entities.Registry registry : dataset.getRegistries()){
|
||||
RegistryCriteria criteria = new RegistryCriteria();
|
||||
criteria.setLike(registry.getReference());
|
||||
List<entities.Registry> entries = this.registryDao.listBy(criteria);
|
||||
if(entries!=null&&!entries.isEmpty())registry.setId( entries.get(0).getId());
|
||||
else registry = this.registryDao.create(registry);
|
||||
}
|
||||
}
|
||||
|
||||
dataset.setId(null);
|
||||
dataset.setCreated(new Date());
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -136,7 +136,7 @@ export class DatasetsComponent implements OnInit {
|
|||
dmp: { "id": '' },
|
||||
services:[],
|
||||
registries:[],
|
||||
repositories:[]
|
||||
dataRepositories:[]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -147,7 +147,7 @@
|
|||
</div>
|
||||
<div class="form-group">
|
||||
<label for="repositories-dropdown" class="form-control-label">Repositories:</label>
|
||||
<p-autoComplete id="repositories-dropdown" [(ngModel)]="dataset.repositories" [suggestions]="filteredRepositories" (completeMethod)="searchRepositories($event)"
|
||||
<p-autoComplete id="repositories-dropdown" [(ngModel)]="dataset.dataRepositories" [suggestions]="filteredRepositories" (completeMethod)="searchRepositories($event)"
|
||||
[minLength]="1" name="repositories" [multiple]="true" emptyMessage="No results found!" field="name">
|
||||
</p-autoComplete>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue