2018-03-21 11:57:56 +01:00
|
|
|
package eu.eudat.data.entities;
|
2017-09-14 12:37:36 +02:00
|
|
|
|
|
|
|
|
2018-10-02 16:33:58 +02:00
|
|
|
import eu.eudat.data.converters.DateToUTCConverter;
|
2019-05-21 17:17:41 +02:00
|
|
|
import eu.eudat.data.entities.helpers.EntityBinder;
|
2018-03-21 11:16:32 +01:00
|
|
|
import eu.eudat.queryable.queryableentity.DataEntity;
|
2017-09-14 12:37:36 +02:00
|
|
|
import org.hibernate.annotations.GenericGenerator;
|
|
|
|
import org.hibernate.annotations.Type;
|
|
|
|
|
2018-02-16 11:34:02 +01:00
|
|
|
import javax.persistence.*;
|
|
|
|
import java.util.*;
|
2018-05-28 11:50:42 +02:00
|
|
|
import java.util.stream.Collectors;
|
2017-09-14 12:37:36 +02:00
|
|
|
|
2017-11-02 15:25:05 +01:00
|
|
|
@Entity
|
2018-02-07 10:56:30 +01:00
|
|
|
@Table(name = "\"Dataset\"")
|
2018-01-02 09:36:40 +01:00
|
|
|
@NamedEntityGraphs({
|
2019-05-21 17:17:41 +02:00
|
|
|
@NamedEntityGraph(
|
|
|
|
name = "datasetListingModel",
|
|
|
|
attributeNodes = {@NamedAttributeNode("services"), @NamedAttributeNode(value = "datasetDataRepositories", subgraph = "datasetDataRepositories"),
|
|
|
|
@NamedAttributeNode(value = "datasetExternalDatasets", subgraph = "datasetExternalDatasets"), @NamedAttributeNode("registries"),
|
|
|
|
@NamedAttributeNode(value = "dmp", subgraph = "dmp"), @NamedAttributeNode("profile"), @NamedAttributeNode("creator")},
|
|
|
|
subgraphs = {
|
2019-07-31 16:57:34 +02:00
|
|
|
@NamedSubgraph(name = "dmp", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("users"), @NamedAttributeNode("grant"), @NamedAttributeNode("organisations")}),
|
2019-05-21 17:17:41 +02:00
|
|
|
@NamedSubgraph(name = "datasetDataRepositories", attributeNodes = {@NamedAttributeNode("dataRepository")}),
|
|
|
|
@NamedSubgraph(name = "datasetExternalDatasets", attributeNodes = {@NamedAttributeNode("externalDataset")})
|
|
|
|
}),
|
|
|
|
|
|
|
|
@NamedEntityGraph(
|
|
|
|
name = "datasetWizardModel",
|
|
|
|
attributeNodes = {@NamedAttributeNode("services"), @NamedAttributeNode("datasetDataRepositories"), @NamedAttributeNode("datasetExternalDatasets"), @NamedAttributeNode("registries"),
|
|
|
|
@NamedAttributeNode("dmp"), @NamedAttributeNode("profile"), @NamedAttributeNode("creator")}),
|
|
|
|
@NamedEntityGraph(
|
|
|
|
name = "datasetRecentActivity",
|
|
|
|
attributeNodes = {@NamedAttributeNode(value = "dmp", subgraph = "dmp")},
|
|
|
|
subgraphs = @NamedSubgraph(name = "dmp", attributeNodes = {@NamedAttributeNode("users")})),
|
|
|
|
@NamedEntityGraph(
|
|
|
|
name = "datasetDataRepositories",
|
|
|
|
attributeNodes = {@NamedAttributeNode(value = "dmp", subgraph = "dmp"), @NamedAttributeNode("creator")},
|
|
|
|
subgraphs = @NamedSubgraph(name = "dmp", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("users")}))
|
2018-01-17 13:03:51 +01:00
|
|
|
})
|
2018-03-19 13:40:04 +01:00
|
|
|
public class Dataset implements DataEntity<Dataset, UUID> {
|
2018-01-02 09:36:40 +01:00
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
public static Set<String> getHints() {
|
|
|
|
return hints;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Set<String> hints = new HashSet<>(Arrays.asList("datasetListingModel"));
|
|
|
|
|
|
|
|
public enum Status {
|
2019-06-19 16:16:05 +02:00
|
|
|
SAVED((short) 0), FINALISED((short) 1), CANCELED((short) 2), DELETED((short) 99),;
|
2019-05-21 17:17:41 +02:00
|
|
|
|
|
|
|
private short value;
|
|
|
|
|
|
|
|
private Status(short value) {
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public short getValue() {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Status fromInteger(int value) {
|
|
|
|
switch (value) {
|
|
|
|
case 0:
|
|
|
|
return SAVED;
|
|
|
|
case 1:
|
|
|
|
return FINALISED;
|
2019-06-19 16:16:05 +02:00
|
|
|
case 2:
|
|
|
|
return CANCELED;
|
2019-05-21 17:17:41 +02:00
|
|
|
case 99:
|
|
|
|
return DELETED;
|
|
|
|
default:
|
|
|
|
throw new RuntimeException("Unsupported Dataset Status");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Id
|
|
|
|
@GeneratedValue
|
|
|
|
@GenericGenerator(name = "uuid2", strategy = "uuid2")
|
|
|
|
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
|
|
|
private UUID id;
|
|
|
|
|
|
|
|
@Column(name = "\"Label\"")
|
|
|
|
private String label;
|
|
|
|
|
|
|
|
@ManyToOne(fetch = FetchType.LAZY)
|
2017-09-14 12:37:36 +02:00
|
|
|
// @Cascade(value=org.hibernate.annotations.CascadeType.ALL)
|
2019-05-21 17:17:41 +02:00
|
|
|
@JoinColumn(name = "\"DMP\"", nullable = false)
|
|
|
|
private DMP dmp;
|
2018-02-07 10:56:30 +01:00
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
@Column(name = "\"Uri\"")
|
|
|
|
private String uri;
|
2018-02-07 10:56:30 +01:00
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
@Type(type = "eu.eudat.configurations.typedefinition.XMLType")
|
|
|
|
@Column(name = "\"Properties\"", columnDefinition = "xml", nullable = true)
|
|
|
|
private String properties;
|
2018-02-07 10:56:30 +01:00
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
@ManyToOne(fetch = FetchType.LAZY)
|
|
|
|
//@Cascade(value=org.hibernate.annotations.CascadeType.ALL)
|
|
|
|
@JoinColumn(name = "\"Profile\"", nullable = true)
|
|
|
|
private DatasetProfile profile;
|
2018-02-07 10:56:30 +01:00
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
@Type(type = "eu.eudat.configurations.typedefinition.XMLType")
|
|
|
|
@Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true)
|
|
|
|
private String reference;
|
2018-02-07 10:56:30 +01:00
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
@OneToMany(fetch = FetchType.LAZY)
|
|
|
|
@JoinTable(name = "\"DatasetRegistry\"",
|
|
|
|
joinColumns = {@JoinColumn(name = "\"Dataset\"", referencedColumnName = "\"ID\"")},
|
|
|
|
inverseJoinColumns = {@JoinColumn(name = "\"Registry\"", referencedColumnName = "\"ID\"")}
|
|
|
|
)
|
|
|
|
private Set<Registry> registries;
|
2018-02-07 10:56:30 +01:00
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
@OneToMany(mappedBy = "dataset", cascade = CascadeType.ALL, orphanRemoval = true)
|
|
|
|
private Set<DatasetDataRepository> datasetDataRepositories;
|
2018-01-17 13:03:51 +01:00
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
@OneToMany(mappedBy = "dataset", cascade = CascadeType.ALL, orphanRemoval = true)
|
|
|
|
private Set<DatasetService> services;
|
2018-05-28 11:50:42 +02:00
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
@OneToMany(mappedBy = "dataset", cascade = CascadeType.ALL, orphanRemoval = true)
|
|
|
|
private Set<DatasetExternalDataset> datasetExternalDatasets;
|
2018-02-07 10:56:30 +01:00
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
@Column(name = "\"Status\"", nullable = false)
|
|
|
|
private Short status;
|
2018-02-07 10:56:30 +01:00
|
|
|
|
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
@Column(name = "\"Created\"")
|
|
|
|
@Convert(converter = DateToUTCConverter.class)
|
|
|
|
private Date created = null;
|
2018-02-07 10:56:30 +01:00
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
@Column(name = "\"Modified\"")
|
|
|
|
@Convert(converter = DateToUTCConverter.class)
|
|
|
|
private Date modified = new Date();
|
2018-02-07 10:56:30 +01:00
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
@ManyToOne(fetch = FetchType.LAZY)
|
|
|
|
@JoinColumn(name = "\"Creator\"", nullable = true)
|
|
|
|
private UserInfo creator;
|
2018-02-07 10:56:30 +01:00
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
@Column(name = "\"Description\"")
|
|
|
|
private String description;
|
2018-02-07 10:56:30 +01:00
|
|
|
|
2019-06-24 16:01:24 +02:00
|
|
|
@Column(name= "\"FinalizedAt\"")
|
2019-06-04 11:00:50 +02:00
|
|
|
@Convert(converter = DateToUTCConverter.class)
|
2019-06-24 16:01:24 +02:00
|
|
|
private Date finalizedAt;
|
2019-06-04 11:00:50 +02:00
|
|
|
|
2018-02-07 10:56:30 +01:00
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
public String getDescription() {
|
|
|
|
return description;
|
|
|
|
}
|
|
|
|
public void setDescription(String description) {
|
|
|
|
this.description = description;
|
|
|
|
}
|
2018-02-07 10:56:30 +01:00
|
|
|
|
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
public UserInfo getCreator() {
|
|
|
|
return creator;
|
|
|
|
}
|
|
|
|
public void setCreator(UserInfo creator) {
|
|
|
|
this.creator = creator;
|
|
|
|
}
|
2017-11-17 01:43:16 +01:00
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
public Short getStatus() {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
public void setStatus(Short status) {
|
|
|
|
this.status = status;
|
|
|
|
}
|
2017-11-02 17:17:56 +01:00
|
|
|
|
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
public Date getCreated() {
|
|
|
|
return created;
|
|
|
|
}
|
|
|
|
public void setCreated(Date created) {
|
|
|
|
this.created = created;
|
|
|
|
}
|
2017-11-02 17:17:56 +01:00
|
|
|
|
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
public Date getModified() {
|
|
|
|
return modified;
|
|
|
|
}
|
|
|
|
public void setModified(Date modified) {
|
|
|
|
this.modified = modified;
|
|
|
|
}
|
2017-11-02 17:17:56 +01:00
|
|
|
|
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
public Set<Registry> getRegistries() {
|
|
|
|
return registries;
|
|
|
|
}
|
|
|
|
public void setRegistries(Set<Registry> registries) {
|
|
|
|
this.registries = registries;
|
|
|
|
}
|
2017-09-14 12:37:36 +02:00
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
public Set<DatasetService> getServices() {
|
|
|
|
return services;
|
|
|
|
}
|
|
|
|
public void setServices(Set<DatasetService> services) {
|
|
|
|
this.services = services;
|
|
|
|
}
|
2017-09-14 12:37:36 +02:00
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
public UUID getId() {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
public void setId(UUID id) {
|
|
|
|
this.id = id;
|
|
|
|
}
|
2017-09-14 12:37:36 +02:00
|
|
|
|
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
public String getLabel() {
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
public void setLabel(String label) {
|
|
|
|
this.label = label;
|
|
|
|
}
|
2017-09-14 12:37:36 +02:00
|
|
|
|
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
public DMP getDmp() {
|
|
|
|
return dmp;
|
|
|
|
}
|
|
|
|
public void setDmp(DMP dmp) {
|
|
|
|
this.dmp = dmp;
|
|
|
|
}
|
2017-09-14 12:37:36 +02:00
|
|
|
|
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
public String getUri() {
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
public void setUri(String uri) {
|
|
|
|
this.uri = uri;
|
|
|
|
}
|
2017-09-14 12:37:36 +02:00
|
|
|
|
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
public String getProperties() {
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
public void setProperties(String properties) {
|
|
|
|
this.properties = properties;
|
|
|
|
}
|
2017-09-14 12:37:36 +02:00
|
|
|
|
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
public DatasetProfile getProfile() {
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
public void setProfile(DatasetProfile profile) {
|
|
|
|
this.profile = profile;
|
|
|
|
}
|
2017-09-14 12:37:36 +02:00
|
|
|
|
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
public Set<DatasetDataRepository> getDatasetDataRepositories() {
|
|
|
|
return datasetDataRepositories;
|
|
|
|
}
|
|
|
|
public void setDatasetDataRepositories(Set<DatasetDataRepository> datasetDataRepositories) {
|
|
|
|
this.datasetDataRepositories = datasetDataRepositories;
|
|
|
|
}
|
2017-11-02 15:25:05 +01:00
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
public String getReference() {
|
|
|
|
return reference;
|
|
|
|
}
|
|
|
|
public void setReference(String reference) {
|
|
|
|
this.reference = reference;
|
|
|
|
}
|
2017-12-17 22:34:24 +01:00
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
public Set<DatasetExternalDataset> getDatasetExternalDatasets() {
|
|
|
|
return datasetExternalDatasets;
|
|
|
|
}
|
|
|
|
public void setDatasetExternalDatasets(Set<DatasetExternalDataset> datasetExternalDatasets) {
|
|
|
|
this.datasetExternalDatasets = datasetExternalDatasets;
|
|
|
|
}
|
2017-12-17 22:34:24 +01:00
|
|
|
|
2019-06-24 16:01:24 +02:00
|
|
|
public Date getFinalizedAt() {
|
|
|
|
return finalizedAt;
|
2019-06-04 11:00:50 +02:00
|
|
|
}
|
2019-06-24 16:01:24 +02:00
|
|
|
public void setFinalizedAt(Date finalizedAt) {
|
|
|
|
this.finalizedAt = finalizedAt;
|
2019-06-04 11:00:50 +02:00
|
|
|
}
|
|
|
|
|
2019-05-21 17:17:41 +02:00
|
|
|
@Override
|
|
|
|
public void update(Dataset entity) {
|
|
|
|
this.setRegistries(entity.getRegistries());
|
|
|
|
if (this.getDatasetDataRepositories() == null) this.setDatasetDataRepositories(new HashSet<>());
|
|
|
|
if (!this.getDatasetDataRepositories().containsAll(entity.getDatasetDataRepositories())) {
|
|
|
|
this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories());
|
|
|
|
this.getDatasetDataRepositories().addAll(entity.getDatasetDataRepositories().stream().map(item -> {
|
|
|
|
item.setDataset(this);
|
|
|
|
return item;
|
|
|
|
}).collect(Collectors.toList()));
|
|
|
|
}
|
2019-09-06 11:15:05 +02:00
|
|
|
this.setUri(entity.getUri());
|
2019-05-21 17:17:41 +02:00
|
|
|
this.setDescription(entity.getDescription());
|
|
|
|
this.setLabel(entity.getLabel());
|
|
|
|
this.setProperties(entity.getProperties());
|
|
|
|
if (this.getDatasetExternalDatasets() == null) this.setDatasetExternalDatasets(new HashSet<>());
|
|
|
|
if (!this.getDatasetExternalDatasets().containsAll(entity.getDatasetExternalDatasets())) {
|
|
|
|
this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets());
|
|
|
|
this.getDatasetExternalDatasets().addAll(entity.getDatasetExternalDatasets().stream().map(item -> {
|
|
|
|
item.setDataset(this);
|
|
|
|
return item;
|
|
|
|
}).collect(Collectors.toList()));
|
|
|
|
}
|
2019-09-16 17:26:18 +02:00
|
|
|
if (this.getServices() == null) this.setServices(new HashSet<>());
|
|
|
|
if(!this.getServices().containsAll(entity.getServices())) {
|
|
|
|
this.getServices().removeAll(this.getServices());
|
|
|
|
this.getServices().addAll(entity.getServices());
|
|
|
|
}
|
2019-06-03 15:09:38 +02:00
|
|
|
this.setDmp(entity.getDmp());
|
2019-05-21 17:17:41 +02:00
|
|
|
this.setStatus(entity.getStatus());
|
|
|
|
this.setProfile(entity.getProfile());
|
|
|
|
this.setModified(new Date());
|
2019-06-24 16:01:24 +02:00
|
|
|
if (entity.getStatus().equals(Status.FINALISED.getValue())) this.setFinalizedAt(new Date());
|
2019-05-21 17:17:41 +02:00
|
|
|
if (entity.getCreator() != null) this.creator = entity.getCreator();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public UUID getKeys() {
|
|
|
|
return this.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Dataset buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
|
|
|
|
String currentBase = base.isEmpty() ? "" : base + ".";
|
|
|
|
if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
|
|
|
|
return this;
|
|
|
|
}
|
2017-09-14 12:37:36 +02:00
|
|
|
}
|