You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
argos/dmp-backend/data/src/main/java/eu/eudat/data/entities/Dataset.java

332 lines
9.5 KiB
Java

package eu.eudat.data.entities;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import javax.persistence.*;
import java.util.*;
import java.util.stream.Collectors;
@Entity
@Table(name = "\"Dataset\"")
@NamedEntityGraphs({
@NamedEntityGraph(
name = "datasetListingModel",
attributeNodes = {@NamedAttributeNode("services"), @NamedAttributeNode(value = "datasetDataRepositories", subgraph = "datasetDataRepositories"), @NamedAttributeNode("datasetExternalDatasets"), @NamedAttributeNode("registries"),
@NamedAttributeNode(value = "dmp", subgraph = "dmp"), @NamedAttributeNode("profile"), @NamedAttributeNode("creator")},
subgraphs = {
@NamedSubgraph(name = "dmp", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("users")}),
@NamedSubgraph(name = "datasetDataRepositories", attributeNodes = {@NamedAttributeNode("dataRepository")})
}),
@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")}))
})
public class Dataset implements DataEntity<Dataset, UUID> {
public static Set<String> getHints() {
return hints;
}
private static final Set<String> hints = new HashSet<>(Arrays.asList("datasetListingModel"));
public enum Status {
SAVED((short) 0), FINALISED((short) 1), DELETED((short) 99);
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;
default:
throw new RuntimeException("Unsupported Project 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)
// @Cascade(value=org.hibernate.annotations.CascadeType.ALL)
@JoinColumn(name = "\"DMP\"", nullable = true)
private DMP dmp;
@Column(name = "\"Uri\"")
private String uri;
@Type(type = "eu.eudat.configurations.typedefinition.XMLType")
@Column(name = "\"Properties\"", columnDefinition = "xml", nullable = true)
private String properties;
@ManyToOne(fetch = FetchType.LAZY)
//@Cascade(value=org.hibernate.annotations.CascadeType.ALL)
@JoinColumn(name = "\"Profile\"", nullable = true)
private DatasetProfile profile;
@Type(type = "eu.eudat.configurations.typedefinition.XMLType")
@Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true)
private String reference;
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "\"DatasetRegistry\"",
joinColumns = {@JoinColumn(name = "\"Dataset\"", referencedColumnName = "\"ID\"")},
inverseJoinColumns = {@JoinColumn(name = "\"Registry\"", referencedColumnName = "\"ID\"")}
)
private Set<Registry> registries;
@OneToMany(mappedBy = "dataset", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<DatasetDataRepository> datasetDataRepositories;
@OneToMany(mappedBy = "dataset", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<DatasetService> services;
@OneToMany(mappedBy = "dataset", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<DatasetExternalDataset> datasetExternalDatasets;
@Column(name = "\"Status\"", nullable = false)
private Short status;
@Column(name = "\"IsPublic\"", nullable = false)
private boolean isPublic;
@Column(name = "\"Created\"")
private Date created = null;
@Column(name = "\"Modified\"")
private Date modified = new Date();
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"Creator\"", nullable = true)
private UserInfo creator;
@Column(name = "\"Description\"")
private String description;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public UserInfo getCreator() {
return creator;
}
public void setCreator(UserInfo creator) {
this.creator = creator;
}
public Short getStatus() {
return status;
}
public void setStatus(Short status) {
this.status = status;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getModified() {
return modified;
}
public void setModified(Date modified) {
this.modified = modified;
}
public Set<Registry> getRegistries() {
return registries;
}
public void setRegistries(Set<Registry> registries) {
this.registries = registries;
}
public Set<DatasetService> getServices() {
return services;
}
public void setServices(Set<DatasetService> services) {
this.services = services;
}
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 DMP getDmp() {
return dmp;
}
public void setDmp(DMP dmp) {
this.dmp = dmp;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public String getProperties() {
return properties;
}
public void setProperties(String properties) {
this.properties = properties;
}
public DatasetProfile getProfile() {
return profile;
}
public void setProfile(DatasetProfile profile) {
this.profile = profile;
}
public Set<DatasetDataRepository> getDatasetDataRepositories() {
return datasetDataRepositories;
}
public void setDatasetDataRepositories(Set<DatasetDataRepository> datasetDataRepositories) {
this.datasetDataRepositories = datasetDataRepositories;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public Set<DatasetExternalDataset> getDatasetExternalDatasets() {
return datasetExternalDatasets;
}
public void setDatasetExternalDatasets(Set<DatasetExternalDataset> datasetExternalDatasets) {
this.datasetExternalDatasets = datasetExternalDatasets;
}
public boolean isPublic() {
return isPublic;
}
public void setPublic(boolean aPublic) {
isPublic = aPublic;
}
@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()));
}
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()));
}
this.setStatus(entity.getStatus());
this.setProfile(entity.getProfile());
this.setModified(new Date());
if (entity.getCreator() != null) this.creator = entity.getCreator();
}
@Override
public UUID getKeys() {
return this.id;
}
}