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/DMP.java

323 lines
7.9 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.*;
@Entity
@Table(name = "\"DMP\"")
@NamedEntityGraphs({
@NamedEntityGraph(
name = "dataManagementPlanListingModel",
attributeNodes = {@NamedAttributeNode("organisations"), @NamedAttributeNode("researchers"),
@NamedAttributeNode("project"), @NamedAttributeNode("creator"), @NamedAttributeNode("profile"), @NamedAttributeNode("dataset")}
),
@NamedEntityGraph(
name = "fullyDetailed",
attributeNodes = {
@NamedAttributeNode("project"), @NamedAttributeNode("profile"),
@NamedAttributeNode("users"), @NamedAttributeNode("organisations"), @NamedAttributeNode("researchers")}),
@NamedEntityGraph(
name = "dmpRecentActivity",
attributeNodes = {
@NamedAttributeNode("users"), @NamedAttributeNode("creator")})
})
public class DMP implements DataEntity<DMP, UUID> {
public enum DMPStatus {
ACTIVE((short) 0), DELETED((short) 1);
private short value;
private DMPStatus(short value) {
this.value = value;
}
public short getValue() {
return value;
}
public static DMPStatus fromInteger(short value) {
switch (value) {
case 0:
return ACTIVE;
case 1:
return DELETED;
default:
throw new RuntimeException("Unsupported DMP Status");
}
}
}
public static Set<String> getHints() {
return hints;
}
private static final Set<String> hints = new HashSet<>(Arrays.asList("dataManagementPlanListingModel", "fullyDetailed"));
@Id
@GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
@Column(name = "\"GroupId\"", columnDefinition = "BINARY(16)")
private UUID groupId;
@Column(name = "\"Label\"")
private String label;
@Column(name = "\"Version\"")
private Integer version;
@OneToMany(mappedBy = "dmp", fetch = FetchType.LAZY)
private Set<Dataset> dataset;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"Project\"")
private Project project;
@Type(type = "eu.eudat.configurations.typedefinition.XMLType")
@Column(name = "\"AssociatedDmps\"", columnDefinition = "xml", nullable = true)
private String associatedDmps;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"Profile\"")
private DMPProfile profile;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"Creator\"")
private UserInfo creator;
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "\"DMPOrganisation\"",
joinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")},
inverseJoinColumns = {@JoinColumn(name = "\"Organisation\"", referencedColumnName = "\"ID\"")}
)
private Set<Organisation> organisations;
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "\"DMPResearcher\"",
joinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")},
inverseJoinColumns = {@JoinColumn(name = "\"Researcher\"", referencedColumnName = "\"ID\"")}
)
private Set<Researcher> researchers;
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "\"UserDMP\"",
joinColumns = {@JoinColumn(name = "dmp", referencedColumnName = "\"ID\"")},
inverseJoinColumns = {@JoinColumn(name = "usr", referencedColumnName = "id")}
)
private Set<UserInfo> users;
@Column(name = "\"Status\"", nullable = false)
private Short status;
@Column(name = "\"Properties\"")
private String properties;
@Column(name = "\"DmpProperties\"")
private String dmpProperties;
@Column(name = "\"Created\"")
private Date created = null;
@Column(name = "\"Modified\"")
private Date modified = new Date();
@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<UserInfo> getUsers() {
return users;
}
public void setUsers(Set<UserInfo> users) {
this.users = users;
}
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public UUID getGroupId() {
return groupId;
}
public void setGroupId(UUID groupId) {
this.groupId = groupId;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
public Project getProject() {
return project;
}
public void setProject(Project project) {
this.project = project;
}
public String getAssociatedDmps() {
return associatedDmps;
}
public void setAssociatedDmps(String associatedDmps) {
this.associatedDmps = associatedDmps;
}
public DMPProfile getProfile() {
return profile;
}
public void setProfile(DMPProfile profile) {
this.profile = profile;
}
public Set<Dataset> getDataset() {
return dataset;
}
public void setDataset(Set<Dataset> dataset) {
this.dataset = dataset;
}
public Set<Organisation> getOrganisations() {
return organisations;
}
public void setOrganisations(Set<Organisation> organisations) {
this.organisations = organisations;
}
public Set<Researcher> getResearchers() {
return researchers;
}
public void setResearchers(Set<Researcher> researchers) {
this.researchers = researchers;
}
public String getProperties() {
return properties;
}
public void setProperties(String properties) {
this.properties = properties;
}
public String getDmpProperties() {
return dmpProperties;
}
public void setDmpProperties(String dmpProperties) {
this.dmpProperties = dmpProperties;
}
@Override
public void update(DMP entity) {
this.associatedDmps = entity.associatedDmps;
this.label = entity.getLabel();
this.profile = entity.getProfile();
this.status = entity.getStatus();
this.created = entity.created;
this.properties = entity.getProperties();
this.project = entity.getProject();
this.description = entity.getDescription();
this.researchers = entity.getResearchers();
this.organisations = entity.getOrganisations();
this.dmpProperties = entity.getDmpProperties();
this.setModified(new Date());
if (entity.getUsers() != null) this.users = entity.getUsers();
}
@Override
public UUID getKeys() {
return this.id;
}
}