Refactors the way queries are generated

This commit is contained in:
ikalyvas 2019-05-21 18:17:41 +03:00
parent d15cbd6d9e
commit fd30cc9a94
38 changed files with 2863 additions and 2113 deletions

View File

@ -1,5 +1,6 @@
package eu.eudat.data.entities; package eu.eudat.data.entities;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
@ -14,140 +15,141 @@ import java.util.UUID;
@Table(name = "\"Content\"") @Table(name = "\"Content\"")
public class Content implements DataEntity<Content, UUID> { public class Content implements DataEntity<Content, UUID> {
public enum ParentType { public enum ParentType {
PROJECT(0); PROJECT(0);
private int value; private int value;
private ParentType(int value) { private ParentType(int value) {
this.value = value; this.value = value;
} }
public int getValue() { public int getValue() {
return value; return value;
} }
public static ParentType fromInteger(int value) { public static ParentType fromInteger(int value) {
switch (value) { switch (value) {
case 0: case 0:
return PROJECT; return PROJECT;
default: default:
throw new RuntimeException("Unsupported Content Parent Type Status"); throw new RuntimeException("Unsupported Content Parent Type Status");
} }
} }
} }
public enum LocationType { public enum LocationType {
EXTERNAL(0), INTERNAL(1); EXTERNAL(0), INTERNAL(1);
private Integer value; private Integer value;
private LocationType(Integer value) { private LocationType(Integer value) {
this.value = value; this.value = value;
} }
public Integer getValue() { public Integer getValue() {
return value; return value;
} }
public static LocationType fromInteger(int value) { public static LocationType fromInteger(int value) {
switch (value) { switch (value) {
case 0: case 0:
return EXTERNAL; return EXTERNAL;
case 1: case 1:
return INTERNAL; return INTERNAL;
default: default:
throw new RuntimeException("Unsupported Content Location Type"); throw new RuntimeException("Unsupported Content Location Type");
} }
} }
} }
@Id @Id
@GeneratedValue @GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2") @GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id; private UUID id;
@Column(name = "\"Filename\"", nullable = false) @Column(name = "\"Filename\"", nullable = false)
private String label; private String label;
@Column(name = "\"Extension\"", nullable = false) @Column(name = "\"Extension\"", nullable = false)
private String extension; private String extension;
@Column(name = "\"ParentType\"", nullable = false) @Column(name = "\"ParentType\"", nullable = false)
private Integer parentType; private Integer parentType;
@Column(name = "\"Uri\"", nullable = false) @Column(name = "\"Uri\"", nullable = false)
private String uri; private String uri;
@Column(name = "\"LocationType\"", nullable = false) @Column(name = "\"LocationType\"", nullable = false)
private Integer locationType; private Integer locationType;
public UUID getId() { public UUID getId() {
return id; return id;
} }
public void setId(UUID id) { public void setId(UUID id) {
this.id = id; this.id = id;
} }
public String getLabel() { public String getLabel() {
return label; return label;
} }
public void setLabel(String label) { public void setLabel(String label) {
this.label = label; this.label = label;
} }
public String getExtension() { public String getExtension() {
return extension; return extension;
} }
public void setExtension(String extension) { public void setExtension(String extension) {
this.extension = extension; this.extension = extension;
} }
public Integer getParentType() { public Integer getParentType() {
return parentType; return parentType;
} }
public void setParentType(Integer parentType) { public void setParentType(Integer parentType) {
this.parentType = parentType; this.parentType = parentType;
} }
public String getUri() { public String getUri() {
return uri; return uri;
} }
public void setUri(String uri) { public void setUri(String uri) {
this.uri = uri; this.uri = uri;
} }
public Integer getLocationType() { public Integer getLocationType() {
return locationType; return locationType;
} }
public void setLocationType(Integer locationType) { public void setLocationType(Integer locationType) {
this.locationType = locationType; this.locationType = locationType;
} }
@Override @Override
public void update(Content entity) { public void update(Content entity) {
this.extension = entity.getExtension(); this.extension = entity.getExtension();
this.label = entity.getLabel(); this.label = entity.getLabel();
this.locationType = entity.getLocationType(); this.locationType = entity.getLocationType();
this.parentType = entity.getParentType(); this.parentType = entity.getParentType();
this.uri = entity.getUri(); this.uri = entity.getUri();
} }
@Override @Override
public UUID getKeys() { public UUID getKeys() {
return this.id; return this.id;
} }
@Override @Override
public Content buildFromTuple(List<Tuple> tuple, String base) { public Content buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id")); String currentBase = base.isEmpty() ? "" : base + ".";
return this; if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
} return this;
}
} }

View File

@ -1,6 +1,7 @@
package eu.eudat.data.entities; package eu.eudat.data.entities;
import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import javax.persistence.*; import javax.persistence.*;
@ -12,144 +13,145 @@ import java.util.UUID;
@Entity @Entity
@Table(name = "\"Credential\"") @Table(name = "\"Credential\"")
@NamedEntityGraphs({ @NamedEntityGraphs({
@NamedEntityGraph( @NamedEntityGraph(
name = "credentialUserInfo", name = "credentialUserInfo",
attributeNodes = {@NamedAttributeNode("userInfo")}) attributeNodes = {@NamedAttributeNode("userInfo")})
}) })
public class Credential implements DataEntity<Credential,UUID> { public class Credential implements DataEntity<Credential, UUID> {
@Id @Id
@Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id; private UUID id;
@ManyToOne @ManyToOne
@JoinColumn(name = "\"UserId\"", nullable = false) @JoinColumn(name = "\"UserId\"", nullable = false)
private UserInfo userInfo; private UserInfo userInfo;
@Column(name = "\"Status\"", nullable = false) @Column(name = "\"Status\"", nullable = false)
private Integer status; private Integer status;
@Column(name = "\"Provider\"", nullable = false) @Column(name = "\"Provider\"", nullable = false)
private Integer provider; private Integer provider;
@Column(name = "\"Public\"", nullable = false) @Column(name = "\"Public\"", nullable = false)
private String publicValue; private String publicValue;
@Column(name = "\"Secret\"", nullable = false) @Column(name = "\"Secret\"", nullable = false)
private String secret; private String secret;
@Column(name = "\"CreationTime\"", nullable = false) @Column(name = "\"CreationTime\"", nullable = false)
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
private Date creationTime; private Date creationTime;
@Column(name = "\"LastUpdateTime\"", nullable = false) @Column(name = "\"LastUpdateTime\"", nullable = false)
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
private Date lastUpdateTime; private Date lastUpdateTime;
@Column(name = "\"ExternalId\"", nullable = false) @Column(name = "\"ExternalId\"", nullable = false)
private String externalId; private String externalId;
public UUID getId() { public UUID getId() {
return id; return id;
} }
public void setId(UUID id) { public void setId(UUID id) {
this.id = id; this.id = id;
} }
public UserInfo getUserInfo() { public UserInfo getUserInfo() {
return userInfo; return userInfo;
} }
public void setUserInfo(UserInfo userInfo) { public void setUserInfo(UserInfo userInfo) {
this.userInfo = userInfo; this.userInfo = userInfo;
} }
public Integer getStatus() { public Integer getStatus() {
return status; return status;
} }
public void setStatus(Integer status) { public void setStatus(Integer status) {
this.status = status; this.status = status;
} }
public Integer getProvider() { public Integer getProvider() {
return provider; return provider;
} }
public void setProvider(Integer provider) { public void setProvider(Integer provider) {
this.provider = provider; this.provider = provider;
} }
public String getPublicValue() { public String getPublicValue() {
return publicValue; return publicValue;
} }
public void setPublicValue(String publicValue) { public void setPublicValue(String publicValue) {
this.publicValue = publicValue; this.publicValue = publicValue;
} }
public String getSecret() { public String getSecret() {
return secret; return secret;
} }
public void setSecret(String secret) { public void setSecret(String secret) {
this.secret = secret; this.secret = secret;
} }
public Date getCreationTime() { public Date getCreationTime() {
return creationTime; return creationTime;
} }
public void setCreationTime(Date creationTime) { public void setCreationTime(Date creationTime) {
this.creationTime = creationTime; this.creationTime = creationTime;
} }
public Date getLastUpdateTime() { public Date getLastUpdateTime() {
return lastUpdateTime; return lastUpdateTime;
} }
public void setLastUpdateTime(Date lastUpdateTime) { public void setLastUpdateTime(Date lastUpdateTime) {
this.lastUpdateTime = lastUpdateTime; this.lastUpdateTime = lastUpdateTime;
} }
public String getExternalId() { public String getExternalId() {
return externalId; return externalId;
} }
public void setExternalId(String externalId) { public void setExternalId(String externalId) {
this.externalId = externalId; this.externalId = externalId;
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
Credential that = (Credential) o; Credential that = (Credential) o;
return provider.intValue() == that.provider.intValue(); return provider.intValue() == that.provider.intValue();
} }
@Override @Override
public int hashCode() { public int hashCode() {
return provider.intValue(); return provider.intValue();
} }
@Override @Override
public void update(Credential entity) { public void update(Credential entity) {
this.status = entity.status; this.status = entity.status;
this.publicValue = entity.getPublicValue(); this.publicValue = entity.getPublicValue();
this.secret = entity.getSecret(); this.secret = entity.getSecret();
this.lastUpdateTime = new Date(); this.lastUpdateTime = new Date();
} }
@Override @Override
public UUID getKeys() { public UUID getKeys() {
return this.id; return this.id;
} }
@Override @Override
public Credential buildFromTuple(List<Tuple> tuple, String base) { public Credential buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id")); String currentBase = base.isEmpty() ? "" : base + ".";
return this; if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
} return this;
}
} }

View File

@ -2,6 +2,7 @@ package eu.eudat.data.entities;
import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
@ -14,297 +15,317 @@ import java.util.stream.Collectors;
@Entity @Entity
@Table(name = "\"DMP\"") @Table(name = "\"DMP\"")
@NamedEntityGraphs({ @NamedEntityGraphs({
@NamedEntityGraph( @NamedEntityGraph(
name = "dataManagementPlanListingModel", name = "dataManagementPlanListingModel",
attributeNodes = {@NamedAttributeNode("organisations"), @NamedAttributeNode("researchers"), attributeNodes = {@NamedAttributeNode("organisations"), @NamedAttributeNode("researchers"),
@NamedAttributeNode("project"), @NamedAttributeNode(value = "users", subgraph = "users"), @NamedAttributeNode("creator"), @NamedAttributeNode("profile"), @NamedAttributeNode("dataset")}, @NamedAttributeNode("project"), @NamedAttributeNode(value = "users", subgraph = "users"), @NamedAttributeNode("creator"), @NamedAttributeNode("profile"), @NamedAttributeNode("dataset")},
subgraphs = { subgraphs = {
@NamedSubgraph(name = "users", attributeNodes = {@NamedAttributeNode("user")}), @NamedSubgraph(name = "users", attributeNodes = {@NamedAttributeNode("user")}),
} }
), ),
@NamedEntityGraph( @NamedEntityGraph(
name = "fullyDetailed", name = "fullyDetailed",
attributeNodes = { attributeNodes = {
@NamedAttributeNode("project"), @NamedAttributeNode("profile"), @NamedAttributeNode("project"), @NamedAttributeNode("profile"),
@NamedAttributeNode("users"), @NamedAttributeNode("organisations"), @NamedAttributeNode("researchers")}), @NamedAttributeNode("users"), @NamedAttributeNode("organisations"), @NamedAttributeNode("researchers")}),
@NamedEntityGraph( @NamedEntityGraph(
name = "dmpRecentActivity", name = "dmpRecentActivity",
attributeNodes = { attributeNodes = {
@NamedAttributeNode("users"), @NamedAttributeNode("creator")}) @NamedAttributeNode("users"), @NamedAttributeNode("creator")})
}) })
public class DMP implements DataEntity<DMP, UUID> { public class DMP implements DataEntity<DMP, UUID> {
public enum DMPStatus { public enum DMPStatus {
ACTIVE((short) 0), FINALISED((short) 1),DELETED((short) 99); ACTIVE((short) 0), FINALISED((short) 1), DELETED((short) 99);
private short value; private short value;
private DMPStatus(short value) { private DMPStatus(short value) {
this.value = value; this.value = value;
} }
public short getValue() { public short getValue() {
return value; return value;
} }
public static DMPStatus fromInteger(short value) { public static DMPStatus fromInteger(short value) {
switch (value) { switch (value) {
case 0: case 0:
return ACTIVE; return ACTIVE;
case 1: case 1:
return FINALISED; return FINALISED;
case 99: case 99:
return DELETED; return DELETED;
default: default:
throw new RuntimeException("Unsupported DMP Status"); throw new RuntimeException("Unsupported DMP Status");
} }
} }
} }
public static Set<String> getHints() { public static Set<String> getHints() {
return hints; return hints;
} }
private static final Set<String> hints = new HashSet<>(Arrays.asList("dataManagementPlanListingModel", "fullyDetailed")); private static final Set<String> hints = new HashSet<>(Arrays.asList("dataManagementPlanListingModel", "fullyDetailed"));
@Id @Id
@GeneratedValue @GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2") @GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id; private UUID id;
@Column(name = "\"GroupId\"", columnDefinition = "BINARY(16)") @Column(name = "\"GroupId\"", columnDefinition = "BINARY(16)")
private UUID groupId; private UUID groupId;
@Column(name = "\"Label\"") @Column(name = "\"Label\"")
private String label; private String label;
@Column(name = "\"Version\"") @Column(name = "\"Version\"")
private Integer version; private Integer version;
@OneToMany(mappedBy = "dmp", fetch = FetchType.LAZY) @OneToMany(mappedBy = "dmp", fetch = FetchType.LAZY)
private Set<Dataset> dataset; private Set<Dataset> dataset;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"Project\"") @JoinColumn(name = "\"Project\"")
private Project project; private Project project;
@Type(type = "eu.eudat.configurations.typedefinition.XMLType") @Type(type = "eu.eudat.configurations.typedefinition.XMLType")
@Column(name = "\"AssociatedDmps\"", columnDefinition = "xml", nullable = true) @Column(name = "\"AssociatedDmps\"", columnDefinition = "xml", nullable = true)
private String associatedDmps; private String associatedDmps;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"Profile\"") @JoinColumn(name = "\"Profile\"")
private DMPProfile profile; private DMPProfile profile;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"Creator\"") @JoinColumn(name = "\"Creator\"")
private UserInfo creator; private UserInfo creator;
@OneToMany(fetch = FetchType.LAZY) @OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "\"DMPOrganisation\"", @JoinTable(name = "\"DMPOrganisation\"",
joinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")}, joinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")},
inverseJoinColumns = {@JoinColumn(name = "\"Organisation\"", referencedColumnName = "\"ID\"")} inverseJoinColumns = {@JoinColumn(name = "\"Organisation\"", referencedColumnName = "\"ID\"")}
) )
private Set<Organisation> organisations; private Set<Organisation> organisations;
@OneToMany(fetch = FetchType.LAZY) @OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "\"DMPResearcher\"", @JoinTable(name = "\"DMPResearcher\"",
joinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")}, joinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")},
inverseJoinColumns = {@JoinColumn(name = "\"Researcher\"", referencedColumnName = "\"ID\"")} inverseJoinColumns = {@JoinColumn(name = "\"Researcher\"", referencedColumnName = "\"ID\"")}
) )
private Set<Researcher> researchers; private Set<Researcher> researchers;
@OneToMany(mappedBy = "dmp", fetch = FetchType.LAZY) @OneToMany(mappedBy = "dmp", fetch = FetchType.LAZY)
/*@OneToMany(fetch = FetchType.LAZY) /*@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "\"UserDMP\"", @JoinTable(name = "\"UserDMP\"",
joinColumns = {@JoinColumn(name = "dmp", referencedColumnName = "\"ID\"")}, joinColumns = {@JoinColumn(name = "dmp", referencedColumnName = "\"ID\"")},
inverseJoinColumns = {@JoinColumn(name = "usr", referencedColumnName = "id")} inverseJoinColumns = {@JoinColumn(name = "usr", referencedColumnName = "id")}
)*/ )*/
private Set<UserDMP> users; private Set<UserDMP> users;
@Column(name = "\"Status\"", nullable = false) @Column(name = "\"Status\"", nullable = false)
private Short status; private Short status;
@Column(name = "\"Properties\"") @Column(name = "\"Properties\"")
private String properties; private String properties;
@Column(name = "\"DmpProperties\"") @Column(name = "\"DmpProperties\"")
private String dmpProperties; private String dmpProperties;
@Column(name = "\"Created\"") @Column(name = "\"Created\"")
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
private Date created = null; private Date created = null;
@Column(name = "\"Modified\"") @Column(name = "\"Modified\"")
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
private Date modified = new Date(); private Date modified = new Date();
@Column(name = "\"Description\"") @Column(name = "\"Description\"")
private String description; private String description;
public String getDescription() { public String getDescription() {
return description; return description;
} }
public void setDescription(String description) {
this.description = description;
}
public UserInfo getCreator() { public void setDescription(String description) {
return creator; this.description = description;
} }
public void setCreator(UserInfo creator) {
this.creator = creator;
}
public Short getStatus() { public UserInfo getCreator() {
return status; return creator;
} }
public void setStatus(Short status) {
this.status = status;
}
public Date getCreated() { public void setCreator(UserInfo creator) {
return created; this.creator = creator;
} }
public void setCreated(Date created) {
this.created = created;
}
public Date getModified() { public Short getStatus() {
return modified; return status;
} }
public void setModified(Date modified) {
this.modified = modified;
}
public Set<UserDMP> getUsers() { public void setStatus(Short status) {
return users; this.status = status;
} }
public void setUsers(Set<UserDMP> users) {
this.users = users;
}
public UUID getId() { public Date getCreated() {
return id; return created;
} }
public void setId(UUID id) {
this.id = id;
}
public UUID getGroupId() { public void setCreated(Date created) {
return groupId; this.created = created;
} }
public void setGroupId(UUID groupId) {
this.groupId = groupId;
}
public String getLabel() { public Date getModified() {
return label; return modified;
} }
public void setLabel(String label) {
this.label = label;
}
public Integer getVersion() { public void setModified(Date modified) {
return version; this.modified = modified;
} }
public void setVersion(Integer version) {
this.version = version;
}
public Project getProject() { public Set<UserDMP> getUsers() {
return project; return users;
} }
public void setProject(Project project) {
this.project = project;
}
public String getAssociatedDmps() { public void setUsers(Set<UserDMP> users) {
return associatedDmps; this.users = users;
} }
public void setAssociatedDmps(String associatedDmps) {
this.associatedDmps = associatedDmps;
}
public DMPProfile getProfile() { public UUID getId() {
return profile; return id;
} }
public void setProfile(DMPProfile profile) {
this.profile = profile;
}
public Set<Dataset> getDataset() { public void setId(UUID id) {
return dataset; this.id = id;
} }
public void setDataset(Set<Dataset> dataset) {
this.dataset = dataset;
}
public Set<Organisation> getOrganisations() { public UUID getGroupId() {
return organisations; return groupId;
} }
public void setOrganisations(Set<Organisation> organisations) {
this.organisations = organisations;
}
public Set<Researcher> getResearchers() { public void setGroupId(UUID groupId) {
return researchers; this.groupId = groupId;
} }
public void setResearchers(Set<Researcher> researchers) {
this.researchers = researchers;
}
public String getProperties() { public String getLabel() {
return properties; return label;
} }
public void setProperties(String properties) {
this.properties = properties;
}
public String getDmpProperties() { public void setLabel(String label) {
return dmpProperties; this.label = label;
} }
public void setDmpProperties(String dmpProperties) {
this.dmpProperties = dmpProperties;
}
@Override public Integer getVersion() {
public void update(DMP entity) { return version;
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 void setVersion(Integer version) {
public UUID getKeys() { this.version = version;
return this.id; }
}
@Override public Project getProject() {
public DMP buildFromTuple(List<Tuple> tuple, String base) { return project;
this.id = tuple.get(0).get(base.isEmpty() ? "id" : base + "." + "id", UUID.class); }
this.dataset = tuple.stream().map(x -> new Dataset().buildFromTuple(tuple, base.isEmpty() ? "dataset" : base + "." + "dataset")).collect(Collectors.toSet());
this.creator = tuple.stream().map(x -> new UserInfo().buildFromTuple(tuple, base.isEmpty() ? "creator" : base + "." + "creator")).collect(Collectors.toList()).get(0); public void setProject(Project project) {
return this; 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;
}
@Override
public DMP 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");
this.dataset = tuple.stream().map(x -> new Dataset().buildFromTuple(tuple, fields, currentBase + "dataset")).collect(Collectors.toSet());
this.creator = tuple.stream().map(x -> new UserInfo().buildFromTuple(tuple, fields, currentBase + "creator")).collect(Collectors.toList()).get(0);
this.project = tuple.stream().map(x -> new Project().buildFromTuple(tuple, fields, currentBase + "project")).collect(Collectors.toList()).get(0);
return this;
}
} }

View File

@ -2,6 +2,7 @@ package eu.eudat.data.entities;
import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
@ -145,8 +146,9 @@ public class DMPProfile implements DataEntity<DMPProfile, UUID> {
} }
@Override @Override
public DMPProfile buildFromTuple(List<Tuple> tuple, String base) { public DMPProfile buildFromTuple(List<Tuple> tuple,List<String> fields, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id")); String currentBase = base.isEmpty() ? "" : base + ".";
if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
return this; return this;
} }
} }

View File

@ -1,6 +1,7 @@
package eu.eudat.data.entities; package eu.eudat.data.entities;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
@ -14,144 +15,145 @@ import java.util.UUID;
@Entity @Entity
@Table(name = "\"DataRepository\"") @Table(name = "\"DataRepository\"")
public class DataRepository implements Serializable, DataEntity<DataRepository,UUID> { public class DataRepository implements Serializable, DataEntity<DataRepository, UUID> {
@Id @Id
@GeneratedValue @GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2") @GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id; private UUID id;
@Column(name = "\"Label\"") @Column(name = "\"Label\"")
private String label; private String label;
@Column(name = "\"Abbreviation\"") @Column(name = "\"Abbreviation\"")
private String abbreviation; private String abbreviation;
@Column(name = "\"Reference\"", nullable = false) @Column(name = "\"Reference\"", nullable = false)
private String reference; private String reference;
@Column(name = "\"Uri\"") @Column(name = "\"Uri\"")
private String uri; private String uri;
@Type(type = "eu.eudat.configurations.typedefinition.XMLType") @Type(type = "eu.eudat.configurations.typedefinition.XMLType")
@Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true) @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true)
private String definition; private String definition;
@OneToMany(mappedBy = "dataRepository", cascade = CascadeType.ALL, orphanRemoval = true) @OneToMany(mappedBy = "dataRepository", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<DatasetDataRepository> datasetDataRepositories; private Set<DatasetDataRepository> datasetDataRepositories;
@Column(name = "\"Status\"", nullable = false) @Column(name = "\"Status\"", nullable = false)
private Short status; private Short status;
@Column(name = "\"Created\"") @Column(name = "\"Created\"")
private Date created = null; private Date created = null;
@Column(name = "\"Modified\"") @Column(name = "\"Modified\"")
private Date modified = new Date(); private Date modified = new Date();
public Short getStatus() { public Short getStatus() {
return status; return status;
} }
public void setStatus(Short status) { public void setStatus(Short status) {
this.status = status; this.status = status;
} }
public Date getCreated() { public Date getCreated() {
return created; return created;
} }
public void setCreated(Date created) { public void setCreated(Date created) {
this.created = created; this.created = created;
} }
public Date getModified() { public Date getModified() {
return modified; return modified;
} }
public void setModified(Date modified) { public void setModified(Date modified) {
this.modified = modified; this.modified = modified;
} }
public UUID getId() { public UUID getId() {
return id; return id;
} }
public void setId(UUID id) { public void setId(UUID id) {
this.id = id; this.id = id;
} }
public String getLabel() { public String getLabel() {
return label; return label;
} }
public void setLabel(String label) { public void setLabel(String label) {
this.label = label; this.label = label;
} }
public String getAbbreviation() { public String getAbbreviation() {
return abbreviation; return abbreviation;
} }
public void setAbbreviation(String abbreviation) { public void setAbbreviation(String abbreviation) {
this.abbreviation = abbreviation; this.abbreviation = abbreviation;
} }
public String getReference() { public String getReference() {
return reference; return reference;
} }
public void setReference(String reference) { public void setReference(String reference) {
this.reference = reference; this.reference = reference;
} }
public String getUri() { public String getUri() {
return uri; return uri;
} }
public void setUri(String uri) { public void setUri(String uri) {
this.uri = uri; this.uri = uri;
} }
public String getDefinition() { public String getDefinition() {
return definition; return definition;
} }
public void setDefinition(String definition) { public void setDefinition(String definition) {
this.definition = definition; this.definition = definition;
} }
public Set<DatasetDataRepository> getDatasetDataRepositories() { public Set<DatasetDataRepository> getDatasetDataRepositories() {
return datasetDataRepositories; return datasetDataRepositories;
} }
public void setDatasetDataRepositories(Set<DatasetDataRepository> datasetDataRepositories) { public void setDatasetDataRepositories(Set<DatasetDataRepository> datasetDataRepositories) {
this.datasetDataRepositories = datasetDataRepositories; this.datasetDataRepositories = datasetDataRepositories;
} }
@Override @Override
public void update(DataRepository entity) { public void update(DataRepository entity) {
} }
@Override @Override
public UUID getKeys() { public UUID getKeys() {
return this.id; return this.id;
} }
@Override @Override
public DataRepository buildFromTuple(List<Tuple> tuple, String base) { public DataRepository buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id")); String currentBase = base.isEmpty() ? "" : base + ".";
return this; if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
} return this;
}
} }

View File

@ -2,6 +2,7 @@ package eu.eudat.data.entities;
import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
@ -13,326 +14,327 @@ import java.util.stream.Collectors;
@Entity @Entity
@Table(name = "\"Dataset\"") @Table(name = "\"Dataset\"")
@NamedEntityGraphs({ @NamedEntityGraphs({
@NamedEntityGraph( @NamedEntityGraph(
name = "datasetListingModel", name = "datasetListingModel",
attributeNodes = {@NamedAttributeNode("services"), @NamedAttributeNode(value = "datasetDataRepositories", subgraph = "datasetDataRepositories"), attributeNodes = {@NamedAttributeNode("services"), @NamedAttributeNode(value = "datasetDataRepositories", subgraph = "datasetDataRepositories"),
@NamedAttributeNode(value = "datasetExternalDatasets", subgraph = "datasetExternalDatasets"), @NamedAttributeNode("registries"), @NamedAttributeNode(value = "datasetExternalDatasets", subgraph = "datasetExternalDatasets"), @NamedAttributeNode("registries"),
@NamedAttributeNode(value = "dmp", subgraph = "dmp"), @NamedAttributeNode("profile"), @NamedAttributeNode("creator")}, @NamedAttributeNode(value = "dmp", subgraph = "dmp"), @NamedAttributeNode("profile"), @NamedAttributeNode("creator")},
subgraphs = { subgraphs = {
@NamedSubgraph(name = "dmp", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("users"), @NamedAttributeNode("project"), @NamedAttributeNode("organisations")}), @NamedSubgraph(name = "dmp", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("users"), @NamedAttributeNode("project"), @NamedAttributeNode("organisations")}),
@NamedSubgraph(name = "datasetDataRepositories", attributeNodes = {@NamedAttributeNode("dataRepository")}), @NamedSubgraph(name = "datasetDataRepositories", attributeNodes = {@NamedAttributeNode("dataRepository")}),
@NamedSubgraph(name = "datasetExternalDatasets", attributeNodes = {@NamedAttributeNode("externalDataset")}) @NamedSubgraph(name = "datasetExternalDatasets", attributeNodes = {@NamedAttributeNode("externalDataset")})
}), }),
@NamedEntityGraph( @NamedEntityGraph(
name = "datasetWizardModel", name = "datasetWizardModel",
attributeNodes = {@NamedAttributeNode("services"), @NamedAttributeNode("datasetDataRepositories"), @NamedAttributeNode("datasetExternalDatasets"), @NamedAttributeNode("registries"), attributeNodes = {@NamedAttributeNode("services"), @NamedAttributeNode("datasetDataRepositories"), @NamedAttributeNode("datasetExternalDatasets"), @NamedAttributeNode("registries"),
@NamedAttributeNode("dmp"), @NamedAttributeNode("profile"), @NamedAttributeNode("creator")}), @NamedAttributeNode("dmp"), @NamedAttributeNode("profile"), @NamedAttributeNode("creator")}),
@NamedEntityGraph( @NamedEntityGraph(
name = "datasetRecentActivity", name = "datasetRecentActivity",
attributeNodes = {@NamedAttributeNode(value = "dmp", subgraph = "dmp")}, attributeNodes = {@NamedAttributeNode(value = "dmp", subgraph = "dmp")},
subgraphs = @NamedSubgraph(name = "dmp", attributeNodes = {@NamedAttributeNode("users")})), subgraphs = @NamedSubgraph(name = "dmp", attributeNodes = {@NamedAttributeNode("users")})),
@NamedEntityGraph( @NamedEntityGraph(
name = "datasetDataRepositories", name = "datasetDataRepositories",
attributeNodes = {@NamedAttributeNode(value = "dmp", subgraph = "dmp"), @NamedAttributeNode("creator")}, attributeNodes = {@NamedAttributeNode(value = "dmp", subgraph = "dmp"), @NamedAttributeNode("creator")},
subgraphs = @NamedSubgraph(name = "dmp", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("users")})) subgraphs = @NamedSubgraph(name = "dmp", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("users")}))
}) })
public class Dataset implements DataEntity<Dataset, UUID> { public class Dataset implements DataEntity<Dataset, UUID> {
public static Set<String> getHints() { public static Set<String> getHints() {
return hints; return hints;
} }
private static final Set<String> hints = new HashSet<>(Arrays.asList("datasetListingModel")); private static final Set<String> hints = new HashSet<>(Arrays.asList("datasetListingModel"));
public enum Status { public enum Status {
SAVED((short) 0), FINALISED((short) 1), DELETED((short) 99); SAVED((short) 0), FINALISED((short) 1), DELETED((short) 99);
private short value; private short value;
private Status(short value) { private Status(short value) {
this.value = value; this.value = value;
} }
public short getValue() { public short getValue() {
return value; return value;
} }
public static Status fromInteger(int value) { public static Status fromInteger(int value) {
switch (value) { switch (value) {
case 0: case 0:
return SAVED; return SAVED;
case 1: case 1:
return FINALISED; return FINALISED;
case 99: case 99:
return DELETED; return DELETED;
default: default:
throw new RuntimeException("Unsupported Dataset Status"); throw new RuntimeException("Unsupported Dataset Status");
} }
} }
} }
@Id @Id
@GeneratedValue @GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2") @GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id; private UUID id;
@Column(name = "\"Label\"") @Column(name = "\"Label\"")
private String label; private String label;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
// @Cascade(value=org.hibernate.annotations.CascadeType.ALL) // @Cascade(value=org.hibernate.annotations.CascadeType.ALL)
@JoinColumn(name = "\"DMP\"", nullable = false) @JoinColumn(name = "\"DMP\"", nullable = false)
private DMP dmp; private DMP dmp;
@Column(name = "\"Uri\"") @Column(name = "\"Uri\"")
private String uri; private String uri;
@Type(type = "eu.eudat.configurations.typedefinition.XMLType") @Type(type = "eu.eudat.configurations.typedefinition.XMLType")
@Column(name = "\"Properties\"", columnDefinition = "xml", nullable = true) @Column(name = "\"Properties\"", columnDefinition = "xml", nullable = true)
private String properties; private String properties;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
//@Cascade(value=org.hibernate.annotations.CascadeType.ALL) //@Cascade(value=org.hibernate.annotations.CascadeType.ALL)
@JoinColumn(name = "\"Profile\"", nullable = true) @JoinColumn(name = "\"Profile\"", nullable = true)
private DatasetProfile profile; private DatasetProfile profile;
@Type(type = "eu.eudat.configurations.typedefinition.XMLType") @Type(type = "eu.eudat.configurations.typedefinition.XMLType")
@Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true) @Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true)
private String reference; private String reference;
@OneToMany(fetch = FetchType.LAZY) @OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "\"DatasetRegistry\"", @JoinTable(name = "\"DatasetRegistry\"",
joinColumns = {@JoinColumn(name = "\"Dataset\"", referencedColumnName = "\"ID\"")}, joinColumns = {@JoinColumn(name = "\"Dataset\"", referencedColumnName = "\"ID\"")},
inverseJoinColumns = {@JoinColumn(name = "\"Registry\"", referencedColumnName = "\"ID\"")} inverseJoinColumns = {@JoinColumn(name = "\"Registry\"", referencedColumnName = "\"ID\"")}
) )
private Set<Registry> registries; private Set<Registry> registries;
@OneToMany(mappedBy = "dataset", cascade = CascadeType.ALL, orphanRemoval = true) @OneToMany(mappedBy = "dataset", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<DatasetDataRepository> datasetDataRepositories; private Set<DatasetDataRepository> datasetDataRepositories;
@OneToMany(mappedBy = "dataset", cascade = CascadeType.ALL, orphanRemoval = true) @OneToMany(mappedBy = "dataset", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<DatasetService> services; private Set<DatasetService> services;
@OneToMany(mappedBy = "dataset", cascade = CascadeType.ALL, orphanRemoval = true) @OneToMany(mappedBy = "dataset", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<DatasetExternalDataset> datasetExternalDatasets; private Set<DatasetExternalDataset> datasetExternalDatasets;
@Column(name = "\"Status\"", nullable = false) @Column(name = "\"Status\"", nullable = false)
private Short status; private Short status;
@Column(name = "\"IsPublic\"", nullable = false) @Column(name = "\"IsPublic\"", nullable = false)
private boolean isPublic; private boolean isPublic;
@Column(name = "\"Created\"") @Column(name = "\"Created\"")
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
private Date created = null; private Date created = null;
@Column(name = "\"Modified\"") @Column(name = "\"Modified\"")
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
private Date modified = new Date(); private Date modified = new Date();
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"Creator\"", nullable = true) @JoinColumn(name = "\"Creator\"", nullable = true)
private UserInfo creator; private UserInfo creator;
@Column(name = "\"Description\"") @Column(name = "\"Description\"")
private String description; private String description;
public String getDescription() { public String getDescription() {
return description; return description;
} }
public void setDescription(String description) { public void setDescription(String description) {
this.description = description; this.description = description;
} }
public UserInfo getCreator() { public UserInfo getCreator() {
return creator; return creator;
} }
public void setCreator(UserInfo creator) { public void setCreator(UserInfo creator) {
this.creator = creator; this.creator = creator;
} }
public Short getStatus() { public Short getStatus() {
return status; return status;
} }
public void setStatus(Short status) { public void setStatus(Short status) {
this.status = status; this.status = status;
} }
public Date getCreated() { public Date getCreated() {
return created; return created;
} }
public void setCreated(Date created) { public void setCreated(Date created) {
this.created = created; this.created = created;
} }
public Date getModified() { public Date getModified() {
return modified; return modified;
} }
public void setModified(Date modified) { public void setModified(Date modified) {
this.modified = modified; this.modified = modified;
} }
public Set<Registry> getRegistries() { public Set<Registry> getRegistries() {
return registries; return registries;
} }
public void setRegistries(Set<Registry> registries) { public void setRegistries(Set<Registry> registries) {
this.registries = registries; this.registries = registries;
} }
public Set<DatasetService> getServices() { public Set<DatasetService> getServices() {
return services; return services;
} }
public void setServices(Set<DatasetService> services) { public void setServices(Set<DatasetService> services) {
this.services = services; this.services = services;
} }
public UUID getId() { public UUID getId() {
return id; return id;
} }
public void setId(UUID id) { public void setId(UUID id) {
this.id = id; this.id = id;
} }
public String getLabel() { public String getLabel() {
return label; return label;
} }
public void setLabel(String label) { public void setLabel(String label) {
this.label = label; this.label = label;
} }
public DMP getDmp() { public DMP getDmp() {
return dmp; return dmp;
} }
public void setDmp(DMP dmp) { public void setDmp(DMP dmp) {
this.dmp = dmp; this.dmp = dmp;
} }
public String getUri() { public String getUri() {
return uri; return uri;
} }
public void setUri(String uri) { public void setUri(String uri) {
this.uri = uri; this.uri = uri;
} }
public String getProperties() { public String getProperties() {
return properties; return properties;
} }
public void setProperties(String properties) { public void setProperties(String properties) {
this.properties = properties; this.properties = properties;
} }
public DatasetProfile getProfile() { public DatasetProfile getProfile() {
return profile; return profile;
} }
public void setProfile(DatasetProfile profile) { public void setProfile(DatasetProfile profile) {
this.profile = profile; this.profile = profile;
} }
public Set<DatasetDataRepository> getDatasetDataRepositories() { public Set<DatasetDataRepository> getDatasetDataRepositories() {
return datasetDataRepositories; return datasetDataRepositories;
} }
public void setDatasetDataRepositories(Set<DatasetDataRepository> datasetDataRepositories) { public void setDatasetDataRepositories(Set<DatasetDataRepository> datasetDataRepositories) {
this.datasetDataRepositories = datasetDataRepositories; this.datasetDataRepositories = datasetDataRepositories;
} }
public String getReference() { public String getReference() {
return reference; return reference;
} }
public void setReference(String reference) { public void setReference(String reference) {
this.reference = reference; this.reference = reference;
} }
public Set<DatasetExternalDataset> getDatasetExternalDatasets() { public Set<DatasetExternalDataset> getDatasetExternalDatasets() {
return datasetExternalDatasets; return datasetExternalDatasets;
} }
public void setDatasetExternalDatasets(Set<DatasetExternalDataset> datasetExternalDatasets) { public void setDatasetExternalDatasets(Set<DatasetExternalDataset> datasetExternalDatasets) {
this.datasetExternalDatasets = datasetExternalDatasets; this.datasetExternalDatasets = datasetExternalDatasets;
} }
public boolean isPublic() { public boolean isPublic() {
return isPublic; return isPublic;
} }
public void setPublic(boolean aPublic) { public void setPublic(boolean aPublic) {
isPublic = aPublic; isPublic = aPublic;
} }
@Override @Override
public void update(Dataset entity) { public void update(Dataset entity) {
this.setRegistries(entity.getRegistries()); this.setRegistries(entity.getRegistries());
if (this.getDatasetDataRepositories() == null) this.setDatasetDataRepositories(new HashSet<>()); if (this.getDatasetDataRepositories() == null) this.setDatasetDataRepositories(new HashSet<>());
if (!this.getDatasetDataRepositories().containsAll(entity.getDatasetDataRepositories())) { if (!this.getDatasetDataRepositories().containsAll(entity.getDatasetDataRepositories())) {
this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories()); this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories());
this.getDatasetDataRepositories().addAll(entity.getDatasetDataRepositories().stream().map(item -> { this.getDatasetDataRepositories().addAll(entity.getDatasetDataRepositories().stream().map(item -> {
item.setDataset(this); item.setDataset(this);
return item; return item;
}).collect(Collectors.toList())); }).collect(Collectors.toList()));
} }
this.setDescription(entity.getDescription()); this.setDescription(entity.getDescription());
this.setLabel(entity.getLabel()); this.setLabel(entity.getLabel());
this.setProperties(entity.getProperties()); this.setProperties(entity.getProperties());
if (this.getDatasetExternalDatasets() == null) this.setDatasetExternalDatasets(new HashSet<>()); if (this.getDatasetExternalDatasets() == null) this.setDatasetExternalDatasets(new HashSet<>());
if (!this.getDatasetExternalDatasets().containsAll(entity.getDatasetExternalDatasets())) { if (!this.getDatasetExternalDatasets().containsAll(entity.getDatasetExternalDatasets())) {
this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets()); this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets());
this.getDatasetExternalDatasets().addAll(entity.getDatasetExternalDatasets().stream().map(item -> { this.getDatasetExternalDatasets().addAll(entity.getDatasetExternalDatasets().stream().map(item -> {
item.setDataset(this); item.setDataset(this);
return item; return item;
}).collect(Collectors.toList())); }).collect(Collectors.toList()));
} }
this.setStatus(entity.getStatus()); this.setStatus(entity.getStatus());
this.setProfile(entity.getProfile()); this.setProfile(entity.getProfile());
this.setModified(new Date()); this.setModified(new Date());
if (entity.getCreator() != null) this.creator = entity.getCreator(); if (entity.getCreator() != null) this.creator = entity.getCreator();
} }
@Override @Override
public UUID getKeys() { public UUID getKeys() {
return this.id; return this.id;
} }
@Override @Override
public Dataset buildFromTuple(List<Tuple> tuple, String base) { public Dataset buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.id = (UUID) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id"); String currentBase = base.isEmpty() ? "" : base + ".";
return this; if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
} return this;
}
} }

View File

@ -1,8 +1,8 @@
package eu.eudat.data.entities; package eu.eudat.data.entities;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import javax.persistence.*; import javax.persistence.*;
import java.util.List; import java.util.List;
@ -14,83 +14,84 @@ import java.util.UUID;
@Entity @Entity
@Table(name = "\"DatasetDataRepository\"") @Table(name = "\"DatasetDataRepository\"")
public class DatasetDataRepository implements DataEntity<DatasetDataRepository,UUID> { public class DatasetDataRepository implements DataEntity<DatasetDataRepository, UUID> {
@Id @Id
@GeneratedValue @GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2") @GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id; private UUID id;
@ManyToOne @ManyToOne
@JoinColumn(name = "\"Dataset\"", nullable = false) @JoinColumn(name = "\"Dataset\"", nullable = false)
private Dataset dataset; private Dataset dataset;
@ManyToOne @ManyToOne
@JoinColumn(name = "\"DataRepository\"", nullable = false) @JoinColumn(name = "\"DataRepository\"", nullable = false)
private DataRepository dataRepository; private DataRepository dataRepository;
@Column(name = "\"Role\"") @Column(name = "\"Role\"")
private Integer role; private Integer role;
@Column(name = "\"Data\"") @Column(name = "\"Data\"")
private String data; private String data;
public UUID getId() { public UUID getId() {
return id; return id;
} }
public void setId(UUID id) { public void setId(UUID id) {
this.id = id; this.id = id;
} }
public Dataset getDataset() { public Dataset getDataset() {
return dataset; return dataset;
} }
public void setDataset(Dataset dataset) { public void setDataset(Dataset dataset) {
this.dataset = dataset; this.dataset = dataset;
} }
public DataRepository getDataRepository() { public DataRepository getDataRepository() {
return dataRepository; return dataRepository;
} }
public void setDataRepository(DataRepository dataRepository) { public void setDataRepository(DataRepository dataRepository) {
this.dataRepository = dataRepository; this.dataRepository = dataRepository;
} }
public Integer getRole() { public Integer getRole() {
return role; return role;
} }
public void setRole(Integer role) { public void setRole(Integer role) {
this.role = role; this.role = role;
} }
public String getData() { public String getData() {
return data; return data;
} }
public void setData(String data) { public void setData(String data) {
this.data = data; this.data = data;
} }
@Override @Override
public void update(DatasetDataRepository entity) { public void update(DatasetDataRepository entity) {
this.dataset = entity.getDataset(); this.dataset = entity.getDataset();
this.dataRepository = entity.getDataRepository(); this.dataRepository = entity.getDataRepository();
this.role = entity.getRole(); this.role = entity.getRole();
} }
@Override @Override
public UUID getKeys() { public UUID getKeys() {
return this.id; return this.id;
} }
@Override @Override
public DatasetDataRepository buildFromTuple(List<Tuple> tuple, String base) { public DatasetDataRepository buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id")); String currentBase = base.isEmpty() ? "" : base + ".";
return this; if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
} return this;
}
} }

View File

@ -1,8 +1,8 @@
package eu.eudat.data.entities; package eu.eudat.data.entities;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import javax.persistence.*; import javax.persistence.*;
import java.util.List; import java.util.List;
@ -11,84 +11,85 @@ import java.util.UUID;
@Entity @Entity
@Table(name = "\"DatasetExternalDataset\"") @Table(name = "\"DatasetExternalDataset\"")
public class DatasetExternalDataset implements DataEntity<DatasetExternalDataset,UUID> { public class DatasetExternalDataset implements DataEntity<DatasetExternalDataset, UUID> {
@Id @Id
@GeneratedValue @GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2") @GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id; private UUID id;
@ManyToOne @ManyToOne
@JoinColumn(name = "\"Dataset\"", nullable = false) @JoinColumn(name = "\"Dataset\"", nullable = false)
private Dataset dataset; private Dataset dataset;
@ManyToOne @ManyToOne
@JoinColumn(name = "\"ExternalDataset\"", nullable = false) @JoinColumn(name = "\"ExternalDataset\"", nullable = false)
private ExternalDataset externalDataset; private ExternalDataset externalDataset;
@Column(name = "\"Role\"") @Column(name = "\"Role\"")
private Integer role; private Integer role;
@Column(name = "\"Data\"") @Column(name = "\"Data\"")
private String data; private String data;
public UUID getId() { public UUID getId() {
return id; return id;
} }
public void setId(UUID id) { public void setId(UUID id) {
this.id = id; this.id = id;
} }
public Dataset getDataset() { public Dataset getDataset() {
return dataset; return dataset;
} }
public void setDataset(Dataset dataset) { public void setDataset(Dataset dataset) {
this.dataset = dataset; this.dataset = dataset;
} }
public ExternalDataset getExternalDataset() { public ExternalDataset getExternalDataset() {
return externalDataset; return externalDataset;
} }
public void setExternalDataset(ExternalDataset externalDataset) { public void setExternalDataset(ExternalDataset externalDataset) {
this.externalDataset = externalDataset; this.externalDataset = externalDataset;
} }
public Integer getRole() { public Integer getRole() {
return role; return role;
} }
public void setRole(Integer role) { public void setRole(Integer role) {
this.role = role; this.role = role;
} }
public String getData() { public String getData() {
return data; return data;
} }
public void setData(String data) { public void setData(String data) {
this.data = data; this.data = data;
} }
@Override @Override
public void update(DatasetExternalDataset entity) { public void update(DatasetExternalDataset entity) {
this.dataset = entity.getDataset(); this.dataset = entity.getDataset();
this.externalDataset = entity.getExternalDataset(); this.externalDataset = entity.getExternalDataset();
this.role = entity.getRole(); this.role = entity.getRole();
} }
@Override @Override
public UUID getKeys() { public UUID getKeys() {
return this.id; return this.id;
} }
@Override @Override
public DatasetExternalDataset buildFromTuple(List<Tuple> tuple, String base) { public DatasetExternalDataset buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id")); String currentBase = base.isEmpty() ? "" : base + ".";
return this; if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
} return this;
}
} }

View File

@ -2,6 +2,7 @@ package eu.eudat.data.entities;
import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
@ -15,148 +16,170 @@ import java.util.UUID;
@Entity @Entity
@Table(name = "\"DatasetProfile\"") @Table(name = "\"DatasetProfile\"")
public class DatasetProfile implements DataEntity<DatasetProfile,UUID>{ public class DatasetProfile implements DataEntity<DatasetProfile, UUID> {
public enum Status { public enum Status {
SAVED((short) 0), FINALIZED((short) 1), DELETED((short) 99); SAVED((short) 0), FINALIZED((short) 1), DELETED((short) 99);
private short value; private short value;
private Status(short value) { private Status(short value) {
this.value = value; this.value = value;
} }
public short getValue() {
return value;
}
public static Status fromInteger(int value) { public short getValue() {
switch (value) { return value;
case 0: }
return SAVED;
case 1:
return FINALIZED;
case 99:
return DELETED;
default:
throw new RuntimeException("Unsupported Dataset Profile Status");
}
}
}
@Id public static Status fromInteger(int value) {
@GeneratedValue switch (value) {
@GenericGenerator(name = "uuid2", strategy = "uuid2") case 0:
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") return SAVED;
private UUID id; case 1:
return FINALIZED;
case 99:
return DELETED;
default:
throw new RuntimeException("Unsupported Dataset Profile Status");
}
}
}
@Column(name = "\"Label\"") @Id
private String label; @GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "profile") @Column(name = "\"Label\"")
private Set<Dataset> dataset; private String label;
@Type(type = "eu.eudat.configurations.typedefinition.XMLType") @OneToMany(fetch = FetchType.LAZY, mappedBy = "profile")
@Column(name = "\"Definition\"", columnDefinition = "xml", nullable = false) private Set<Dataset> dataset;
private String definition;
@Column(name = "\"Status\"", nullable = false) @Type(type = "eu.eudat.configurations.typedefinition.XMLType")
private Short status; @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = false)
private String definition;
@Column(name = "\"Created\"") @Column(name = "\"Status\"", nullable = false)
@Convert(converter = DateToUTCConverter.class) private Short status;
private Date created;
@Column(name = "\"Modified\"") @Column(name = "\"Created\"")
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
private Date modified = new Date(); private Date created;
@Column(name = "\"Description\"") @Column(name = "\"Modified\"")
private String description; @Convert(converter = DateToUTCConverter.class)
private Date modified = new Date();
@Column(name = "\"GroupId\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "\"Description\"")
private UUID groupId; private String description;
@Column(name = "\"Version\"", nullable = false) @Column(name = "\"GroupId\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private Short version; private UUID groupId;
@Column(name = "\"Version\"", nullable = false)
private Short version;
public String getDescription() { public String getDescription() {
return description; return description;
} }
public void setDescription(String description) {
this.description = description;
}
public Short getStatus() { public void setDescription(String description) {
return status; this.description = description;
} }
public void setStatus(Short status) {
this.status = status;
}
public Date getCreated() { public Short getStatus() {
return created; return status;
} }
public void setCreated(Date created) {
this.created = created;
}
public Date getModified() { public void setStatus(Short status) {
return modified; this.status = status;
} }
public void setModified(Date modified) {
this.modified = modified;
}
public UUID getId() { public Date getCreated() {
return id; return created;
} }
public void setId(UUID id) { this.id = id;}
public String getLabel() { public void setCreated(Date created) {
return label; this.created = created;
} }
public void setLabel(String label) {
this.label = label;
}
public String getDefinition() { public Date getModified() {
return definition; return modified;
} }
public void setDefinition(String definition) {
this.definition = definition;
}
public Set<Dataset> getDataset() { public void setModified(Date modified) {
return dataset; this.modified = modified;
} }
public void setDataset(Set<Dataset> dataset) {
this.dataset = dataset;
}
public UUID getGroupId() { return groupId; } public UUID getId() {
public void setGroupId(UUID groupId) { this.groupId = groupId;} return id;
}
public Short getVersion() { return version; } public void setId(UUID id) {
public void setVersion(Short version) { this.version = version; } this.id = id;
}
@Override public String getLabel() {
public String toString() { return label;
return "DatasetProfileListingModel [id=" + id + ", label=" + label + ", dataset=" + dataset + ", definition=" + definition + ", version=" + version + "]"; }
}
@Override public void setLabel(String label) {
public void update(DatasetProfile entity) { this.label = label;
} }
@Override public String getDefinition() {
public UUID getKeys() { return definition;
return this.id; }
}
@Override public void setDefinition(String definition) {
public DatasetProfile buildFromTuple(List<Tuple> tuple, String base) { this.definition = definition;
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id")); }
return this;
} public Set<Dataset> getDataset() {
return dataset;
}
public void setDataset(Set<Dataset> dataset) {
this.dataset = dataset;
}
public UUID getGroupId() {
return groupId;
}
public void setGroupId(UUID groupId) {
this.groupId = groupId;
}
public Short getVersion() {
return version;
}
public void setVersion(Short version) {
this.version = version;
}
@Override
public String toString() {
return "DatasetProfileListingModel [id=" + id + ", label=" + label + ", dataset=" + dataset + ", definition=" + definition + ", version=" + version + "]";
}
@Override
public void update(DatasetProfile entity) {
}
@Override
public UUID getKeys() {
return this.id;
}
@Override
public DatasetProfile 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;
}
} }

View File

@ -3,10 +3,8 @@ package eu.eudat.data.entities;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import javax.persistence.*; import javax.persistence.*;
import java.io.Serializable;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -15,83 +13,84 @@ import java.util.UUID;
@Table(name = "\"DatasetService\"") @Table(name = "\"DatasetService\"")
public class DatasetService implements DataEntity<DatasetService, UUID> { public class DatasetService implements DataEntity<DatasetService, UUID> {
@Id @Id
@GeneratedValue @GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2") @GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id; private UUID id;
@ManyToOne @ManyToOne
@JoinColumn(name = "\"Dataset\"", nullable = false) @JoinColumn(name = "\"Dataset\"", nullable = false)
private Dataset dataset; private Dataset dataset;
@ManyToOne @ManyToOne
@JoinColumn(name = "\"Service\"", nullable = false) @JoinColumn(name = "\"Service\"", nullable = false)
private Service service; private Service service;
@Column(name = "\"Role\"") @Column(name = "\"Role\"")
private Integer role; private Integer role;
@Column(name = "\"Data\"") @Column(name = "\"Data\"")
private String data; private String data;
public UUID getId() { public UUID getId() {
return id; return id;
} }
public void setId(UUID id) { public void setId(UUID id) {
this.id = id; this.id = id;
} }
public Dataset getDataset() { public Dataset getDataset() {
return dataset; return dataset;
} }
public void setDataset(Dataset dataset) { public void setDataset(Dataset dataset) {
this.dataset = dataset; this.dataset = dataset;
} }
public Service getService() { public Service getService() {
return service; return service;
} }
public void setService(Service service) { public void setService(Service service) {
this.service = service; this.service = service;
} }
public Integer getRole() { public Integer getRole() {
return role; return role;
} }
public void setRole(Integer role) { public void setRole(Integer role) {
this.role = role; this.role = role;
} }
public String getData() { public String getData() {
return data; return data;
} }
public void setData(String data) { public void setData(String data) {
this.data = data; this.data = data;
} }
@Override @Override
public void update(DatasetService entity) { public void update(DatasetService entity) {
this.dataset = entity.getDataset(); this.dataset = entity.getDataset();
this.service = entity.getService(); this.service = entity.getService();
this.role = entity.getRole(); this.role = entity.getRole();
} }
@Override @Override
public UUID getKeys() { public UUID getKeys() {
return this.id; return this.id;
} }
@Override @Override
public DatasetService buildFromTuple(List<Tuple> tuple, String base) { public DatasetService buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id")); String currentBase = base.isEmpty() ? "" : base + ".";
return this; if(fields.contains(currentBase + "id")) this.id = UUID.fromString((String) tuple.get(0).get(currentBase + "id"));
} return this;
}
} }

View File

@ -1,6 +1,7 @@
package eu.eudat.data.entities; package eu.eudat.data.entities;
import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
@ -108,8 +109,9 @@ public class ExternalDataset implements DataEntity<ExternalDataset,UUID> {
} }
@Override @Override
public ExternalDataset buildFromTuple(List<Tuple> tuple, String base) { public ExternalDataset buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id")); String currentBase = base.isEmpty() ? "" : base + ".";
if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
return this; return this;
} }
} }

View File

@ -1,5 +1,6 @@
package eu.eudat.data.entities; package eu.eudat.data.entities;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
@ -11,104 +12,105 @@ import java.util.UUID;
@Entity @Entity
@Table(name = "\"Invitation\"") @Table(name = "\"Invitation\"")
public class Invitation implements DataEntity<Invitation,UUID> { public class Invitation implements DataEntity<Invitation, UUID> {
@Id @Id
@GeneratedValue @GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2") @GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "\"Id\"", updatable = false, nullable = false) @Column(name = "\"Id\"", updatable = false, nullable = false)
private UUID id; private UUID id;
@Column(name = "\"InvitationEmail\"", nullable = false) @Column(name = "\"InvitationEmail\"", nullable = false)
private String invitationEmail; private String invitationEmail;
@OneToOne(fetch = FetchType.EAGER) @OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "\"CreationUser\"", nullable = false) @JoinColumn(name = "\"CreationUser\"", nullable = false)
private UserInfo user; private UserInfo user;
@OneToOne(fetch = FetchType.EAGER) @OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "\"Dmp\"", nullable = false) @JoinColumn(name = "\"Dmp\"", nullable = false)
private DMP dmp; private DMP dmp;
@Column(name = "\"Token\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "\"Token\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID token; private UUID token;
@Column(name = "\"AcceptedInvitation\"", nullable = false) @Column(name = "\"AcceptedInvitation\"", nullable = false)
private boolean acceptedInvitation; private boolean acceptedInvitation;
@Type(type = "eu.eudat.configurations.typedefinition.XMLType") @Type(type = "eu.eudat.configurations.typedefinition.XMLType")
@Column(name = "\"Properties\"", columnDefinition = "xml", nullable = true) @Column(name = "\"Properties\"", columnDefinition = "xml", nullable = true)
private String properties; private String properties;
public UUID getId() { public UUID getId() {
return id; return id;
} }
public void setId(UUID id) { public void setId(UUID id) {
this.id = id; this.id = id;
} }
public String getInvitationEmail() { public String getInvitationEmail() {
return invitationEmail; return invitationEmail;
} }
public void setInvitationEmail(String invitationEmail) { public void setInvitationEmail(String invitationEmail) {
this.invitationEmail = invitationEmail; this.invitationEmail = invitationEmail;
} }
public UserInfo getUser() { public UserInfo getUser() {
return user; return user;
} }
public void setUser(UserInfo user) { public void setUser(UserInfo user) {
this.user = user; this.user = user;
} }
public DMP getDmp() { public DMP getDmp() {
return dmp; return dmp;
} }
public void setDmp(DMP dmp) { public void setDmp(DMP dmp) {
this.dmp = dmp; this.dmp = dmp;
} }
public UUID getToken() { public UUID getToken() {
return token; return token;
} }
public void setToken(UUID token) { public void setToken(UUID token) {
this.token = token; this.token = token;
} }
public String getProperties() { public String getProperties() {
return properties; return properties;
} }
public void setProperties(String properties) { public void setProperties(String properties) {
this.properties = properties; this.properties = properties;
} }
public boolean getAcceptedInvitation() { public boolean getAcceptedInvitation() {
return acceptedInvitation; return acceptedInvitation;
} }
public void setAcceptedInvitation(boolean acceptedInvitation) { public void setAcceptedInvitation(boolean acceptedInvitation) {
this.acceptedInvitation = acceptedInvitation; this.acceptedInvitation = acceptedInvitation;
} }
@Override @Override
public void update(Invitation entity) { public void update(Invitation entity) {
} }
@Override @Override
public UUID getKeys() { public UUID getKeys() {
return this.id; return this.id;
} }
@Override @Override
public Invitation buildFromTuple(List<Tuple> tuple, String base) { public Invitation buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id")); String currentBase = base.isEmpty() ? "" : base + ".";
return this; if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
} return this;
}
} }

View File

@ -1,6 +1,7 @@
package eu.eudat.data.entities; package eu.eudat.data.entities;
import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
@ -145,8 +146,9 @@ public class Organisation implements Serializable, DataEntity<Organisation,UUID>
} }
@Override @Override
public Organisation buildFromTuple(List<Tuple> tuple, String base) { public Organisation buildFromTuple(List<Tuple> tuple,List<String> fields, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id")); String currentBase = base.isEmpty() ? "" : base + ".";
if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
return this; return this;
} }
} }

View File

@ -2,6 +2,7 @@ package eu.eudat.data.entities;
import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
@ -17,297 +18,301 @@ import java.util.stream.Collectors;
@Entity @Entity
@Table(name = "\"Project\"") @Table(name = "\"Project\"")
@NamedEntityGraphs({ @NamedEntityGraphs({
@NamedEntityGraph( @NamedEntityGraph(
name = "projectRecentActivity", name = "projectRecentActivity",
attributeNodes = {@NamedAttributeNode(value = "dmps", subgraph = "dmps")}, attributeNodes = {@NamedAttributeNode(value = "dmps", subgraph = "dmps")},
subgraphs = @NamedSubgraph(name = "dmps", attributeNodes = {@NamedAttributeNode("users")}) subgraphs = @NamedSubgraph(name = "dmps", attributeNodes = {@NamedAttributeNode("users")})
), ),
@NamedEntityGraph( @NamedEntityGraph(
name = "projectListingItem", name = "projectListingItem",
attributeNodes = {@NamedAttributeNode(value = "dmps", subgraph = "dmps"), @NamedAttributeNode(value = "content")}, attributeNodes = {@NamedAttributeNode(value = "dmps", subgraph = "dmps"), @NamedAttributeNode(value = "content")},
subgraphs = @NamedSubgraph(name = "dmps", attributeNodes = {@NamedAttributeNode("creator"),@NamedAttributeNode("project"), @NamedAttributeNode("users")}) subgraphs = @NamedSubgraph(name = "dmps", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("project"), @NamedAttributeNode("users")})
) )
}) })
public class Project implements DataEntity<Project, UUID> { public class Project implements DataEntity<Project, UUID> {
public enum Status { public enum Status {
ACTIVE((short) 1), INACTIVE((short) 0), DELETED((short) 99); ACTIVE((short) 1), INACTIVE((short) 0), DELETED((short) 99);
private short value; private short value;
private Status(short value) { private Status(short value) {
this.value = value; this.value = value;
} }
public short getValue() { public short getValue() {
return value; return value;
} }
public static Status fromInteger(int value) { public static Status fromInteger(int value) {
switch (value) { switch (value) {
case 0: case 0:
return INACTIVE; return INACTIVE;
case 1: case 1:
return ACTIVE; return ACTIVE;
case 99: case 99:
return DELETED; return DELETED;
default: default:
throw new RuntimeException("Unsupported Project Status"); throw new RuntimeException("Unsupported Project Status");
} }
} }
} }
public enum ProjectType { public enum ProjectType {
EXTERNAL(0), INTERNAL(1); EXTERNAL(0), INTERNAL(1);
private Integer value; private Integer value;
private ProjectType(Integer value) { private ProjectType(Integer value) {
this.value = value; this.value = value;
} }
public Integer getValue() { public Integer getValue() {
return value; return value;
} }
public static ProjectType fromInteger(int value) { public static ProjectType fromInteger(int value) {
switch (value) { switch (value) {
case 0: case 0:
return EXTERNAL; return EXTERNAL;
case 1: case 1:
return INTERNAL; return INTERNAL;
default: default:
throw new RuntimeException("Unsupported Project Type"); throw new RuntimeException("Unsupported Project Type");
} }
} }
} }
@Id @Id
@GeneratedValue @GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2") @GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id; private UUID id;
@OneToMany(mappedBy = "project") @OneToMany(mappedBy = "project")
private Set<DMP> dmps; private Set<DMP> dmps;
@Column(name = "\"Label\"") @Column(name = "\"Label\"")
private String label; private String label;
@Column(name = "\"Abbreviation\"") @Column(name = "\"Abbreviation\"")
private String abbreviation; private String abbreviation;
@Type(type = "eu.eudat.configurations.typedefinition.XMLType") @Type(type = "eu.eudat.configurations.typedefinition.XMLType")
@Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true) @Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true)
private String reference; private String reference;
@Column(name = "\"Uri\"") @Column(name = "\"Uri\"")
private String uri; private String uri;
@Type(type = "eu.eudat.configurations.typedefinition.XMLType") @Type(type = "eu.eudat.configurations.typedefinition.XMLType")
@Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true) @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true)
private String definition; private String definition;
@Column(name = "\"StartDate\"", nullable = false) @Column(name = "\"StartDate\"", nullable = false)
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
private Date startdate = null; private Date startdate = null;
@Column(name = "\"EndDate\"", nullable = false) @Column(name = "\"EndDate\"", nullable = false)
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
private Date enddate = null; private Date enddate = null;
@Column(name = "\"Status\"", nullable = false) @Column(name = "\"Status\"", nullable = false)
private Short status; private Short status;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"CreationUser\"", nullable = true) @JoinColumn(name = "\"CreationUser\"", nullable = true)
private UserInfo creationUser; private UserInfo creationUser;
@Column(name = "\"Created\"") @Column(name = "\"Created\"")
private Date created = null; private Date created = null;
@Column(name = "\"Modified\"") @Column(name = "\"Modified\"")
private Date modified = new Date(); private Date modified = new Date();
@Column(name = "\"Description\"") @Column(name = "\"Description\"")
private String description; private String description;
@Column(name = "\"Type\"") @Column(name = "\"Type\"")
private Integer type; private Integer type;
@OneToOne(fetch = FetchType.LAZY) @OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"Content\"") @JoinColumn(name = "\"Content\"")
private Content content; private Content content;
public Project() { public Project() {
} }
public Project(Project project) { public Project(Project project) {
this.id = project.getId(); this.id = project.getId();
} }
public String getDescription() { public String getDescription() {
return description; return description;
} }
public void setDescription(String description) { public void setDescription(String description) {
this.description = description; this.description = description;
} }
public Short getStatus() { public Short getStatus() {
return status; return status;
} }
public void setStatus(Short status) { public void setStatus(Short status) {
this.status = status; this.status = status;
} }
public Date getCreated() { public Date getCreated() {
return created; return created;
} }
public void setCreated(Date created) { public void setCreated(Date created) {
this.created = created; this.created = created;
} }
public Date getModified() { public Date getModified() {
return modified; return modified;
} }
public void setModified(Date modified) { public void setModified(Date modified) {
this.modified = modified; this.modified = modified;
} }
public Date getStartdate() { public Date getStartdate() {
return startdate; return startdate;
} }
public void setStartdate(Date startdate) { public void setStartdate(Date startdate) {
this.startdate = startdate; this.startdate = startdate;
} }
public Date getEnddate() { public Date getEnddate() {
return enddate; return enddate;
} }
public void setEnddate(Date enddate) { public void setEnddate(Date enddate) {
this.enddate = enddate; this.enddate = enddate;
} }
public UUID getId() { public UUID getId() {
return id; return id;
} }
public void setId(UUID id) { public void setId(UUID id) {
this.id = id; this.id = id;
} }
public String getLabel() { public String getLabel() {
return label; return label;
} }
public void setLabel(String label) { public void setLabel(String label) {
this.label = label; this.label = label;
} }
public String getAbbreviation() { public String getAbbreviation() {
return abbreviation; return abbreviation;
} }
public void setAbbreviation(String abbreviation) { public void setAbbreviation(String abbreviation) {
this.abbreviation = abbreviation; this.abbreviation = abbreviation;
} }
public String getReference() { public String getReference() {
return reference; return reference;
} }
public void setReference(String reference) { public void setReference(String reference) {
this.reference = reference; this.reference = reference;
} }
public String getUri() { public String getUri() {
return uri; return uri;
} }
public void setUri(String uri) { public void setUri(String uri) {
this.uri = uri; this.uri = uri;
} }
public String getDefinition() { public String getDefinition() {
return definition; return definition;
} }
public void setDefinition(String definition) { public void setDefinition(String definition) {
this.definition = definition; this.definition = definition;
} }
public Set<DMP> getDmps() { public Set<DMP> getDmps() {
return dmps; return dmps;
} }
public void setDmps(Set<DMP> dmps) { public void setDmps(Set<DMP> dmps) {
this.dmps = dmps; this.dmps = dmps;
} }
public UserInfo getCreationUser() { public UserInfo getCreationUser() {
return creationUser; return creationUser;
} }
public void setCreationUser(UserInfo creationUser) { public void setCreationUser(UserInfo creationUser) {
this.creationUser = creationUser; this.creationUser = creationUser;
} }
public Integer getType() { public Integer getType() {
return type; return type;
} }
public void setType(Integer type) { public void setType(Integer type) {
this.type = type; this.type = type;
} }
public Content getContent() { public Content getContent() {
return content; return content;
} }
public void setContent(Content content) { public void setContent(Content content) {
this.content = content; this.content = content;
} }
@Override @Override
public void update(Project entity) { public void update(Project entity) {
this.description = entity.getDescription(); this.description = entity.getDescription();
this.label = entity.getLabel(); this.label = entity.getLabel();
this.abbreviation = entity.getAbbreviation(); this.abbreviation = entity.getAbbreviation();
this.created = entity.getCreated(); this.created = entity.getCreated();
this.definition = entity.getDefinition(); this.definition = entity.getDefinition();
this.dmps = entity.getDmps(); this.dmps = entity.getDmps();
this.enddate = entity.getEnddate(); this.enddate = entity.getEnddate();
this.modified = new Date(); this.modified = new Date();
if (entity.getContent() != null) this.content = entity.getContent(); if (entity.getContent() != null) this.content = entity.getContent();
} }
@Override @Override
public UUID getKeys() { public UUID getKeys() {
return this.id; return this.id;
} }
@Override @Override
public Project buildFromTuple(List<Tuple> tuple, String base) { public Project buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.id = (UUID) tuple.get(0).get(base.isEmpty() ? "id" : base + "." + "id" ); String currentBase = base.isEmpty() ? "" : base + ".";
this.dmps = tuple.stream().map(x-> new DMP().buildFromTuple(tuple,"dmps")).collect(Collectors.toSet()); if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
return this; if (fields.contains(currentBase + "dmps"))
} this.dmps = tuple.stream().map(x -> new DMP().buildFromTuple(tuple, fields, currentBase + "dmps")).collect(Collectors.toSet());
if (fields.contains(currentBase + "creationUser"))
this.creationUser = tuple.stream().map(x -> new UserInfo().buildFromTuple(tuple, fields, currentBase + "creationUser")).collect(Collectors.toList()).get(0);
return this;
}
} }

View File

@ -2,8 +2,8 @@ package eu.eudat.data.entities;
import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
import javax.persistence.*; import javax.persistence.*;
@ -15,150 +15,151 @@ import java.util.UUID;
@Entity @Entity
@Table(name = "\"Registry\"") @Table(name = "\"Registry\"")
public class Registry implements DataEntity<Registry,UUID> { public class Registry implements DataEntity<Registry, UUID> {
@Id @Id
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id; private UUID id;
@Column(name = "\"Label\"") @Column(name = "\"Label\"")
private String label; private String label;
@Column(name = "\"Abbreviation\"") @Column(name = "\"Abbreviation\"")
private String abbreviation; private String abbreviation;
@Column(name = "\"Reference\"", nullable = true) @Column(name = "\"Reference\"", nullable = true)
private String reference; private String reference;
@Column(name = "\"Uri\"") @Column(name = "\"Uri\"")
private String uri; private String uri;
@Type(type = "eu.eudat.configurations.typedefinition.XMLType") @Type(type = "eu.eudat.configurations.typedefinition.XMLType")
@Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true) @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true)
private String definition; private String definition;
@OneToMany(fetch = FetchType.LAZY) @OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "\"DatasetRegistry\"", @JoinTable(name = "\"DatasetRegistry\"",
joinColumns = {@JoinColumn(name = "\"Registry\"", referencedColumnName = "\"ID\"")}, joinColumns = {@JoinColumn(name = "\"Registry\"", referencedColumnName = "\"ID\"")},
inverseJoinColumns = {@JoinColumn(name = "\"Dataset\"", referencedColumnName = "\"ID\"")} inverseJoinColumns = {@JoinColumn(name = "\"Dataset\"", referencedColumnName = "\"ID\"")}
) )
private Set<Dataset> datasets; private Set<Dataset> datasets;
@Column(name = "\"Status\"", nullable = false) @Column(name = "\"Status\"", nullable = false)
private Short status; private Short status;
@Column(name = "\"Created\"") @Column(name = "\"Created\"")
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
private Date created = null; private Date created = null;
@Column(name = "\"Modified\"") @Column(name = "\"Modified\"")
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
private Date modified = new Date(); private Date modified = new Date();
public Short getStatus() { public Short getStatus() {
return status; return status;
} }
public void setStatus(Short status) { public void setStatus(Short status) {
this.status = status; this.status = status;
} }
public Date getCreated() { public Date getCreated() {
return created; return created;
} }
public void setCreated(Date created) { public void setCreated(Date created) {
this.created = created; this.created = created;
} }
public Date getModified() { public Date getModified() {
return modified; return modified;
} }
public void setModified(Date modified) { public void setModified(Date modified) {
this.modified = modified; this.modified = modified;
} }
public UUID getId() { public UUID getId() {
return id; return id;
} }
public void setId(UUID id) { public void setId(UUID id) {
this.id = id; this.id = id;
} }
public String getLabel() { public String getLabel() {
return label; return label;
} }
public void setLabel(String label) { public void setLabel(String label) {
this.label = label; this.label = label;
} }
public String getAbbreviation() { public String getAbbreviation() {
return abbreviation; return abbreviation;
} }
public void setAbbreviation(String abbreviation) { public void setAbbreviation(String abbreviation) {
this.abbreviation = abbreviation; this.abbreviation = abbreviation;
} }
public String getReference() { public String getReference() {
return reference; return reference;
} }
public void setReference(String reference) { public void setReference(String reference) {
this.reference = reference; this.reference = reference;
} }
public String getUri() { public String getUri() {
return uri; return uri;
} }
public void setUri(String uri) { public void setUri(String uri) {
this.uri = uri; this.uri = uri;
} }
public String getDefinition() { public String getDefinition() {
return definition; return definition;
} }
public void setDefinition(String definition) { public void setDefinition(String definition) {
this.definition = definition; this.definition = definition;
} }
public Set<Dataset> getDatasets() { public Set<Dataset> getDatasets() {
return datasets; return datasets;
} }
public void setDatasets(Set<Dataset> datasets) { public void setDatasets(Set<Dataset> datasets) {
this.datasets = datasets; this.datasets = datasets;
} }
@Override @Override
public void update(Registry entity) { public void update(Registry entity) {
} }
@Override @Override
public UUID getKeys() { public UUID getKeys() {
return this.id; return this.id;
} }
@Override @Override
public Registry buildFromTuple(List<Tuple> tuple, String base) { public Registry buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id")); String currentBase = base.isEmpty() ? "" : base + ".";
return this; if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
} return this;
}
} }

View File

@ -2,6 +2,7 @@ package eu.eudat.data.entities;
import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
@ -15,153 +16,154 @@ import java.util.UUID;
@Entity @Entity
@Table(name = "\"Researcher\"") @Table(name = "\"Researcher\"")
public class Researcher implements DataEntity<Researcher,UUID> { public class Researcher implements DataEntity<Researcher, UUID> {
@Id @Id
@GeneratedValue @GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2") @GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id; private UUID id;
@Column(name = "\"Label\"") @Column(name = "\"Label\"")
private String label; private String label;
@Column(name = "\"Uri\"") @Column(name = "\"Uri\"")
private String uri; private String uri;
@Column(name = "\"PrimaryEmail\"") @Column(name = "\"PrimaryEmail\"")
private String primaryEmail; private String primaryEmail;
@Type(type = "eu.eudat.configurations.typedefinition.XMLType") @Type(type = "eu.eudat.configurations.typedefinition.XMLType")
@Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true) @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true)
private String definition; private String definition;
@Type(type = "eu.eudat.configurations.typedefinition.XMLType") @Type(type = "eu.eudat.configurations.typedefinition.XMLType")
@Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true) @Column(name = "\"Reference\"", columnDefinition = "xml", nullable = true)
private String reference; private String reference;
@OneToMany(fetch = FetchType.LAZY) @OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "\"DMPResearcher\"", @JoinTable(name = "\"DMPResearcher\"",
joinColumns = {@JoinColumn(name = "\"Researcher\"", referencedColumnName = "\"ID\"")}, joinColumns = {@JoinColumn(name = "\"Researcher\"", referencedColumnName = "\"ID\"")},
inverseJoinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")} inverseJoinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")}
) )
private Set<DMP> dMPs; private Set<DMP> dMPs;
@Column(name = "\"Status\"", nullable = false) @Column(name = "\"Status\"", nullable = false)
private Short status; private Short status;
@Column(name = "\"Created\"") @Column(name = "\"Created\"")
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
private Date created = null; private Date created = null;
@Column(name = "\"Modified\"") @Column(name = "\"Modified\"")
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
private Date modified = new Date(); private Date modified = new Date();
public Short getStatus() { public Short getStatus() {
return status; return status;
} }
public void setStatus(Short status) { public void setStatus(Short status) {
this.status = status; this.status = status;
} }
public Date getCreated() { public Date getCreated() {
return created; return created;
} }
public void setCreated(Date created) { public void setCreated(Date created) {
this.created = created; this.created = created;
} }
public Date getModified() { public Date getModified() {
return modified; return modified;
} }
public void setModified(Date modified) { public void setModified(Date modified) {
this.modified = modified; this.modified = modified;
} }
public UUID getId() { public UUID getId() {
return id; return id;
} }
public void setId(UUID id) { public void setId(UUID id) {
this.id = id; this.id = id;
} }
public String getLabel() { public String getLabel() {
return label; return label;
} }
public void setLabel(String label) { public void setLabel(String label) {
this.label = label; this.label = label;
} }
public String getPrimaryEmail() { public String getPrimaryEmail() {
return primaryEmail; return primaryEmail;
} }
public void setPrimaryEmail(String primaryEmail) { public void setPrimaryEmail(String primaryEmail) {
this.primaryEmail = primaryEmail; this.primaryEmail = primaryEmail;
} }
public String getReference() { public String getReference() {
return reference; return reference;
} }
public void setReference(String reference) { public void setReference(String reference) {
this.reference = reference; this.reference = reference;
} }
public String getUri() { public String getUri() {
return uri; return uri;
} }
public void setUri(String uri) { public void setUri(String uri) {
this.uri = uri; this.uri = uri;
} }
public String getDefinition() { public String getDefinition() {
return definition; return definition;
} }
public void setDefinition(String definition) { public void setDefinition(String definition) {
this.definition = definition; this.definition = definition;
} }
public Set<DMP> getdMPs() { public Set<DMP> getdMPs() {
return dMPs; return dMPs;
} }
public void setdMPs(Set<DMP> dMPs) { public void setdMPs(Set<DMP> dMPs) {
this.dMPs = dMPs; this.dMPs = dMPs;
} }
@Override @Override
public void update(Researcher entity) { public void update(Researcher entity) {
} }
@Override @Override
public UUID getKeys() { public UUID getKeys() {
return this.id; return this.id;
} }
@Override @Override
public Researcher buildFromTuple(List<Tuple> tuple, String base) { public Researcher buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id")); String currentBase = base.isEmpty() ? "" : base + ".";
return this; if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
} return this;
}
} }

View File

@ -16,144 +16,145 @@ import java.util.UUID;
@Table(name = "\"Service\"") @Table(name = "\"Service\"")
public class Service implements DataEntity<Service, UUID> { public class Service implements DataEntity<Service, UUID> {
@Id @Id
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id; private UUID id;
@Column(name = "\"Label\"") @Column(name = "\"Label\"")
private String label; private String label;
@Column(name = "\"Abbreviation\"") @Column(name = "\"Abbreviation\"")
private String abbreviation; private String abbreviation;
@Column(name = "\"Reference\"", nullable = true) @Column(name = "\"Reference\"", nullable = true)
private String reference; private String reference;
@Column(name = "\"Uri\"") @Column(name = "\"Uri\"")
private String uri; private String uri;
@Type(type = "eu.eudat.configurations.typedefinition.XMLType") @Type(type = "eu.eudat.configurations.typedefinition.XMLType")
@Column(name = "\"Definition\"", columnDefinition = "xml", nullable = false) @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = false)
private String definition; private String definition;
@OneToMany(mappedBy = "service", cascade = CascadeType.ALL, orphanRemoval = true) @OneToMany(mappedBy = "service", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<DatasetService> services; private Set<DatasetService> services;
@Column(name = "\"Status\"", nullable = false) @Column(name = "\"Status\"", nullable = false)
private Short status; private Short status;
@Column(name = "\"Created\"") @Column(name = "\"Created\"")
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
private Date created = null; private Date created = null;
@Column(name = "\"Modified\"") @Column(name = "\"Modified\"")
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
private Date modified = new Date(); private Date modified = new Date();
public Short getStatus() { public Short getStatus() {
return status; return status;
} }
public void setStatus(Short status) { public void setStatus(Short status) {
this.status = status; this.status = status;
} }
public Date getCreated() { public Date getCreated() {
return created; return created;
} }
public void setCreated(Date created) { public void setCreated(Date created) {
this.created = created; this.created = created;
} }
public Date getModified() { public Date getModified() {
return modified; return modified;
} }
public void setModified(Date modified) { public void setModified(Date modified) {
this.modified = modified; this.modified = modified;
} }
public UUID getId() { public UUID getId() {
return id; return id;
} }
public void setId(UUID id) { public void setId(UUID id) {
this.id = id; this.id = id;
} }
public String getLabel() { public String getLabel() {
return label; return label;
} }
public void setLabel(String label) { public void setLabel(String label) {
this.label = label; this.label = label;
} }
public String getAbbreviation() { public String getAbbreviation() {
return abbreviation; return abbreviation;
} }
public void setAbbreviation(String abbreviation) { public void setAbbreviation(String abbreviation) {
this.abbreviation = abbreviation; this.abbreviation = abbreviation;
} }
public String getReference() { public String getReference() {
return reference; return reference;
} }
public void setReference(String reference) { public void setReference(String reference) {
this.reference = reference; this.reference = reference;
} }
public String getUri() { public String getUri() {
return uri; return uri;
} }
public void setUri(String uri) { public void setUri(String uri) {
this.uri = uri; this.uri = uri;
} }
public String getDefinition() { public String getDefinition() {
return definition; return definition;
} }
public void setDefinition(String definition) { public void setDefinition(String definition) {
this.definition = definition; this.definition = definition;
} }
public Set<DatasetService> getServices() { public Set<DatasetService> getServices() {
return services; return services;
} }
public void setServices(Set<DatasetService> services) { public void setServices(Set<DatasetService> services) {
this.services = services; this.services = services;
} }
@Override @Override
public void update(Service entity) { public void update(Service entity) {
} }
@Override @Override
public UUID getKeys() { public UUID getKeys() {
return this.id; return this.id;
} }
@Override @Override
public Service buildFromTuple(List<Tuple> tuple, String base) { public Service buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id")); String currentBase = base.isEmpty() ? "" : base + ".";
return this; if (fields.contains(currentBase + "id")) this.id = UUID.fromString((String) tuple.get(0).get(currentBase + "id"));
} return this;
}
} }

View File

@ -1,5 +1,6 @@
package eu.eudat.data.entities; package eu.eudat.data.entities;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
@ -11,94 +12,95 @@ import java.util.UUID;
@Table(name = "\"UserDMP\"") @Table(name = "\"UserDMP\"")
public class UserDMP implements DataEntity<UserDMP, UUID> { public class UserDMP implements DataEntity<UserDMP, UUID> {
public enum UserDMPRoles { public enum UserDMPRoles {
OWNER(0), USER(1); OWNER(0), USER(1);
private Integer value; private Integer value;
private UserDMPRoles(Integer value) { private UserDMPRoles(Integer value) {
this.value = value; this.value = value;
} }
public Integer getValue() { public Integer getValue() {
return value; return value;
} }
public static UserDMPRoles fromInteger(Integer value) { public static UserDMPRoles fromInteger(Integer value) {
switch (value) { switch (value) {
case 0: case 0:
return OWNER; return OWNER;
case 1: case 1:
return USER; return USER;
default: default:
throw new RuntimeException("Unsupported User Dmp Role Message Code"); throw new RuntimeException("Unsupported User Dmp Role Message Code");
} }
} }
} }
@Id @Id
@GeneratedValue @GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2") @GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id; private UUID id;
@OneToOne(fetch = FetchType.LAZY) @OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "usr") @JoinColumn(name = "usr")
private UserInfo user; private UserInfo user;
@OneToOne(fetch = FetchType.LAZY) @OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "dmp") @JoinColumn(name = "dmp")
private DMP dmp; private DMP dmp;
@Column(name = "role") @Column(name = "role")
private Integer role; private Integer role;
public UUID getId() { public UUID getId() {
return id; return id;
} }
public void setId(UUID id) { public void setId(UUID id) {
this.id = id; this.id = id;
} }
public UserInfo getUser() { public UserInfo getUser() {
return user; return user;
} }
public void setUser(UserInfo user) { public void setUser(UserInfo user) {
this.user = user; this.user = user;
} }
public DMP getDmp() { public DMP getDmp() {
return dmp; return dmp;
} }
public void setDmp(DMP dmp) { public void setDmp(DMP dmp) {
this.dmp = dmp; this.dmp = dmp;
} }
public Integer getRole() { public Integer getRole() {
return role; return role;
} }
public void setRole(Integer role) { public void setRole(Integer role) {
this.role = role; this.role = role;
} }
@Override @Override
public void update(UserDMP entity) { public void update(UserDMP entity) {
this.role = entity.getRole(); this.role = entity.getRole();
} }
@Override @Override
public UUID getKeys() { public UUID getKeys() {
return this.id; return this.id;
} }
@Override @Override
public UserDMP buildFromTuple(List<Tuple> tuple, String base) { public UserDMP buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id")); String currentBase = base.isEmpty() ? "" : base + ".";
return this; if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
} return this;
}
} }

View File

@ -1,6 +1,7 @@
package eu.eudat.data.entities; package eu.eudat.data.entities;
import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
@ -12,175 +13,176 @@ import java.util.*;
@Entity @Entity
@Table(name = "\"UserInfo\"") @Table(name = "\"UserInfo\"")
@NamedEntityGraphs({ @NamedEntityGraphs({
@NamedEntityGraph( @NamedEntityGraph(
name = "userInfo", name = "userInfo",
attributeNodes = {@NamedAttributeNode("userRoles"), @NamedAttributeNode("credentials")}), attributeNodes = {@NamedAttributeNode("userRoles"), @NamedAttributeNode("credentials")}),
}) })
public class UserInfo implements DataEntity<UserInfo, UUID> { public class UserInfo implements DataEntity<UserInfo, UUID> {
@Id @Id
@GeneratedValue @GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2") @GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id; private UUID id;
@Column(name = "email", nullable = false) @Column(name = "email", nullable = false)
private String email = null; private String email = null;
@Column(name = "authorization_level", nullable = false) @Column(name = "authorization_level", nullable = false)
private Short authorization_level; //0 admin, 1 user private Short authorization_level; //0 admin, 1 user
@Column(name = "usertype", nullable = false) @Column(name = "usertype", nullable = false)
private Short usertype; // 0 internal, 1 external private Short usertype; // 0 internal, 1 external
@Column(name = "verified_email", nullable = true) @Column(name = "verified_email", nullable = true)
private Boolean verified_email = null; private Boolean verified_email = null;
@Column(name = "name", nullable = true) @Column(name = "name", nullable = true)
private String name = null; private String name = null;
@Column(name = "created", nullable = false) @Column(name = "created", nullable = false)
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
private Date created = null; private Date created = null;
@Column(name = "lastloggedin", nullable = true) @Column(name = "lastloggedin", nullable = true)
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
private Date lastloggedin = null; private Date lastloggedin = null;
@Type(type = "eu.eudat.configurations.typedefinition.XMLType") @Type(type = "eu.eudat.configurations.typedefinition.XMLType")
@Column(name = "additionalinfo", nullable = true) @Column(name = "additionalinfo", nullable = true)
private String additionalinfo; private String additionalinfo;
@OneToMany(fetch = FetchType.LAZY) @OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "\"UserDMP\"", @JoinTable(name = "\"UserDMP\"",
joinColumns = {@JoinColumn(name = "usr", referencedColumnName = "id")}, joinColumns = {@JoinColumn(name = "usr", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "dmp", referencedColumnName = "\"ID\"")} inverseJoinColumns = {@JoinColumn(name = "dmp", referencedColumnName = "\"ID\"")}
) )
private Set<DMP> dmps; private Set<DMP> dmps;
@OneToMany(mappedBy = "userInfo", fetch = FetchType.LAZY) @OneToMany(mappedBy = "userInfo", fetch = FetchType.LAZY)
private Set<Credential> credentials = new HashSet<>(); private Set<Credential> credentials = new HashSet<>();
@OneToMany(mappedBy = "userInfo", fetch = FetchType.LAZY) @OneToMany(mappedBy = "userInfo", fetch = FetchType.LAZY)
private Set<UserRole> userRoles = new HashSet<>(); private Set<UserRole> userRoles = new HashSet<>();
public Set<DMP> getDmps() { public Set<DMP> getDmps() {
return dmps; return dmps;
} }
public void setDmps(Set<DMP> dmps) { public void setDmps(Set<DMP> dmps) {
this.dmps = dmps; this.dmps = dmps;
} }
public UUID getId() { public UUID getId() {
return id; return id;
} }
public void setId(UUID id) { public void setId(UUID id) {
this.id = id; this.id = id;
} }
public Date getCreated() { public Date getCreated() {
return created; return created;
} }
public void setCreated(Date created) { public void setCreated(Date created) {
this.created = created; this.created = created;
} }
public Date getLastloggedin() { public Date getLastloggedin() {
return lastloggedin; return lastloggedin;
} }
public void setLastloggedin(Date lastloggedin) { public void setLastloggedin(Date lastloggedin) {
this.lastloggedin = lastloggedin; this.lastloggedin = lastloggedin;
} }
public String getEmail() { public String getEmail() {
return email; return email;
} }
public void setEmail(String email) { public void setEmail(String email) {
this.email = email; this.email = email;
} }
public Short getAuthorization_level() { public Short getAuthorization_level() {
return authorization_level; return authorization_level;
} }
public void setAuthorization_level(Short authorization_level) { public void setAuthorization_level(Short authorization_level) {
this.authorization_level = authorization_level; this.authorization_level = authorization_level;
} }
public Short getUsertype() { public Short getUsertype() {
return usertype; return usertype;
} }
public void setUsertype(Short usertype) { public void setUsertype(Short usertype) {
this.usertype = usertype; this.usertype = usertype;
} }
public Boolean getVerified_email() { public Boolean getVerified_email() {
return verified_email; return verified_email;
} }
public void setVerified_email(Boolean verified_email) { public void setVerified_email(Boolean verified_email) {
this.verified_email = verified_email; this.verified_email = verified_email;
} }
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public String getAdditionalinfo() { public String getAdditionalinfo() {
return additionalinfo; return additionalinfo;
} }
public void setAdditionalinfo(String additionalinfo) { public void setAdditionalinfo(String additionalinfo) {
this.additionalinfo = additionalinfo; this.additionalinfo = additionalinfo;
} }
public Set<Credential> getCredentials() { public Set<Credential> getCredentials() {
return credentials; return credentials;
} }
public void setCredentials(Set<Credential> credentials) { public void setCredentials(Set<Credential> credentials) {
this.credentials = credentials; this.credentials = credentials;
} }
public Set<UserRole> getUserRoles() { public Set<UserRole> getUserRoles() {
return userRoles; return userRoles;
} }
public void setUserRoles(Set<UserRole> userRoles) { public void setUserRoles(Set<UserRole> userRoles) {
this.userRoles = userRoles; this.userRoles = userRoles;
} }
@Override @Override
public void update(UserInfo entity) { public void update(UserInfo entity) {
this.name = entity.getName(); this.name = entity.getName();
this.email = entity.getEmail(); this.email = entity.getEmail();
this.additionalinfo = entity.getAdditionalinfo(); this.additionalinfo = entity.getAdditionalinfo();
this.lastloggedin = entity.getLastloggedin(); this.lastloggedin = entity.getLastloggedin();
this.userRoles = entity.getUserRoles(); this.userRoles = entity.getUserRoles();
} }
@Override @Override
public UUID getKeys() { public UUID getKeys() {
return this.id; return this.id;
} }
@Override @Override
public UserInfo buildFromTuple(List<Tuple> tuple, String base) { public UserInfo buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.id = (UUID) tuple.get(0).get(base.isEmpty() ? "id" : base + "." + "id" ); String currentBase = base.isEmpty() ? "" : base + ".";
return this; if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
} return this;
}
} }

View File

@ -1,5 +1,6 @@
package eu.eudat.data.entities; package eu.eudat.data.entities;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
@ -12,56 +13,57 @@ import java.util.UUID;
@Table(name = "\"UserRole\"") @Table(name = "\"UserRole\"")
public class UserRole implements DataEntity<UserRole, UUID> { public class UserRole implements DataEntity<UserRole, UUID> {
@Id @Id
@GeneratedValue @GeneratedValue
@GenericGenerator(name = "uuid2", strategy = "uuid2") @GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id; private UUID id;
@Column(name = "\"Role\"", nullable = false) @Column(name = "\"Role\"", nullable = false)
private int role; private int role;
@ManyToOne(fetch = FetchType.EAGER) @ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "\"UserId\"", nullable = false) @JoinColumn(name = "\"UserId\"", nullable = false)
private UserInfo userInfo; private UserInfo userInfo;
public UUID getId() { public UUID getId() {
return id; return id;
} }
public void setId(UUID id) { public void setId(UUID id) {
this.id = id; this.id = id;
} }
public int getRole() { public int getRole() {
return role; return role;
} }
public void setRole(int role) { public void setRole(int role) {
this.role = role; this.role = role;
} }
public UserInfo getUserInfo() { public UserInfo getUserInfo() {
return userInfo; return userInfo;
} }
public void setUserInfo(UserInfo userInfo) { public void setUserInfo(UserInfo userInfo) {
this.userInfo = userInfo; this.userInfo = userInfo;
} }
@Override @Override
public void update(UserRole entity) { public void update(UserRole entity) {
} }
@Override @Override
public UUID getKeys() { public UUID getKeys() {
return this.id; return this.id;
} }
@Override @Override
public UserRole buildFromTuple(List<Tuple> tuple, String base) { public UserRole buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id")); String currentBase = base.isEmpty() ? "" : base + ".";
return this; if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id");
} return this;
}
} }

View File

@ -1,6 +1,7 @@
package eu.eudat.data.entities; package eu.eudat.data.entities;
import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import javax.persistence.*; import javax.persistence.*;
@ -13,68 +14,69 @@ import java.util.UUID;
@Table(name = "\"UserToken\"") @Table(name = "\"UserToken\"")
public class UserToken implements DataEntity<UserToken, UUID> { public class UserToken implements DataEntity<UserToken, UUID> {
@Id @Id
@Column(name = "\"Token\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @Column(name = "\"Token\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID token; private UUID token;
@OneToOne(fetch = FetchType.EAGER) @OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "\"UserId\"", nullable = false) @JoinColumn(name = "\"UserId\"", nullable = false)
private UserInfo user; private UserInfo user;
@Column(name = "\"IssuedAt\"", nullable = false) @Column(name = "\"IssuedAt\"", nullable = false)
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
private Date issuedAt = null; private Date issuedAt = null;
@Column(name = "\"ExpiresAt\"", nullable = false) @Column(name = "\"ExpiresAt\"", nullable = false)
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
private Date expiresAt = null; private Date expiresAt = null;
public UUID getToken() { public UUID getToken() {
return token; return token;
} }
public void setToken(UUID token) { public void setToken(UUID token) {
this.token = token; this.token = token;
} }
public UserInfo getUser() { public UserInfo getUser() {
return user; return user;
} }
public void setUser(UserInfo user) { public void setUser(UserInfo user) {
this.user = user; this.user = user;
} }
public Date getIssuedAt() { public Date getIssuedAt() {
return issuedAt; return issuedAt;
} }
public void setIssuedAt(Date issuedAt) { public void setIssuedAt(Date issuedAt) {
this.issuedAt = issuedAt; this.issuedAt = issuedAt;
} }
public Date getExpiresAt() { public Date getExpiresAt() {
return expiresAt; return expiresAt;
} }
public void setExpiresAt(Date expiresAt) { public void setExpiresAt(Date expiresAt) {
this.expiresAt = expiresAt; this.expiresAt = expiresAt;
} }
@Override @Override
public void update(UserToken entity) { public void update(UserToken entity) {
} }
@Override @Override
public UUID getKeys() { public UUID getKeys() {
return this.token; return this.token;
} }
@Override @Override
public UserToken buildFromTuple(List<Tuple> tuple, String base) { public UserToken buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.token = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "token" : "token")); String currentBase = base.isEmpty() ? "" : base + ".";
return this; if (fields.contains(currentBase + "token")) this.token = EntityBinder.fromTuple(tuple, currentBase + "token");
} return this;
}
} }

View File

@ -0,0 +1,14 @@
package eu.eudat.data.entities.helpers;
import javax.persistence.Tuple;
import java.util.List;
public class EntityBinder {
public static <T> T fromTuple(List<Tuple> tuple, String path) {
try {
return (T) tuple.get(0).get(path);
}catch (IllegalArgumentException illegalArgument){
return null;
}
}
}

View File

@ -0,0 +1,109 @@
package eu.eudat.query;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.Project;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.types.FieldSelectionType;
import eu.eudat.queryable.types.SelectionField;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.Subquery;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.UUID;
public class DMPQuery extends Query<DMP, UUID> {
private UUID id;
private UUID groupId;
private String label;
private int version;
private ProjectQuery projectQuery;
private List<Integer> statuses;
private Date created;
private Date modified;
public DMPQuery(DatabaseAccessLayer<DMP, UUID> databaseAccessLayer) {
super(databaseAccessLayer);
}
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 int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public ProjectQuery getProjectQuery() {
return projectQuery;
}
public void setProjectQuery(ProjectQuery projectQuery) {
this.projectQuery = projectQuery;
}
public List<Integer> getStatuses() {
return statuses;
}
public void setStatuses(List<Integer> statuses) {
statuses = statuses;
}
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 QueryableList<DMP> getQuery() {
QueryableList<DMP> query = this.databaseAccessLayer.asQueryable();
if (this.id != null) {
query.where((builder, root) -> builder.equal(root.get("id"), this.id));
}
if(this.projectQuery != null){
Subquery<Project> projectQuery = this.projectQuery.getQuery().query(Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "id")));
query.where((builder, root) -> root.get("project").get("id").in(projectQuery));
}
if(this.getStatuses() != null && !this.getStatuses().isEmpty()){
query.where((builder, root) -> root.get("status").in(this.getStatuses()));
}
return query;
}
}

View File

@ -0,0 +1,7 @@
package eu.eudat.query;
import java.util.UUID;
public class DatasetProfileQuery {
}

View File

@ -0,0 +1,20 @@
package eu.eudat.query;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.entities.Dataset;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
public class DatasetQuery extends Query<Dataset, UUID> {
public DatasetQuery(DatabaseAccessLayer<Dataset, UUID> databaseAccessLayer) {
super(databaseAccessLayer);
}
@Override
public QueryableList<Dataset> getQuery() {
return null;
}
}

View File

@ -0,0 +1,101 @@
package eu.eudat.query;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.entities.Project;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.types.FieldSelectionType;
import eu.eudat.queryable.types.SelectionField;
import javax.persistence.criteria.Subquery;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.UUID;
public class ProjectQuery extends Query<Project, UUID> {
private UUID id;
private List<UUID> ids;
private String label;
private List<Integer> statuses;
private Date created;
private Date modified;
private UserQuery userQuery;
public ProjectQuery(DatabaseAccessLayer<Project, UUID> databaseAccessLayer) {
super(databaseAccessLayer);
}
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public List<UUID> getIds() {
return ids;
}
public void setIds(List<UUID> ids) {
this.ids = ids;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public List<Integer> getStatuses() {
return statuses;
}
public void setStatuses(List<Integer> statuses) {
statuses = statuses;
}
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 UserQuery getUserQuery() {
return userQuery;
}
public void setUserQuery(UserQuery userQuery) {
this.userQuery = userQuery;
}
@Override
public QueryableList<Project> getQuery() {
QueryableList<Project> query = this.databaseAccessLayer.asQueryable();
if (this.id != null)
query.where((builder, root) -> builder.equal(root.get("id"), this.id));
if (this.ids != null && !this.ids.isEmpty())
query.where((builder, root) -> root.get("id").in(this.ids));
if (this.getStatuses() != null && !this.getStatuses().isEmpty())
query.where((builder, root) -> root.get("status").in(this.getStatuses()));
if (this.userQuery != null) {
Subquery<UserInfo> userInfoSubquery = this.userQuery.getQuery().query(Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "id")));
query.where((builder, root) -> root.get("creationUser").get("id").in(userInfoSubquery));
}
return query;
}
}

View File

@ -0,0 +1,15 @@
package eu.eudat.query;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.queryableentity.DataEntity;
public abstract class Query<T extends DataEntity, K> {
protected DatabaseAccessLayer<T,K> databaseAccessLayer;
public Query(DatabaseAccessLayer<T, K> databaseAccessLayer) {
this.databaseAccessLayer = databaseAccessLayer;
}
public abstract QueryableList<T> getQuery();
}

View File

@ -0,0 +1,32 @@
package eu.eudat.query;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.queryable.QueryableList;
import java.util.UUID;
public class UserQuery extends Query<UserInfo, UUID> {
private UUID id;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public UserQuery(DatabaseAccessLayer<UserInfo, UUID> databaseAccessLayer) {
super(databaseAccessLayer);
}
@Override
public QueryableList<UserInfo> getQuery() {
QueryableList<UserInfo> query = this.databaseAccessLayer.asQueryable();
if (this.id != null)
query.where((builder, root) -> builder.equal(root.get("id"), this.id));
return query;
}
}

View File

@ -4,6 +4,8 @@ import eu.eudat.queryable.jpa.predicates.*;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import eu.eudat.queryable.types.SelectionField; import eu.eudat.queryable.types.SelectionField;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Subquery; import javax.persistence.criteria.Subquery;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -47,6 +49,8 @@ public interface QueryableList<T extends DataEntity> {
CompletableFuture<Long> countAsync(); CompletableFuture<Long> countAsync();
Subquery<T> query(List<SelectionField> fields);
Subquery<T> subQuery(SinglePredicate<T> predicate, List<SelectionField> fields); Subquery<T> subQuery(SinglePredicate<T> predicate, List<SelectionField> fields);
Subquery<T> subQuery(NestedQuerySinglePredicate<T> predicate, List<SelectionField> fields); Subquery<T> subQuery(NestedQuerySinglePredicate<T> predicate, List<SelectionField> fields);

View File

@ -204,7 +204,7 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
.collect(Collectors.groupingBy(x -> x.get("id"))); .collect(Collectors.groupingBy(x -> x.get("id")));
return results.stream().map(x -> { return results.stream().map(x -> {
try { try {
return (T) this.tClass.newInstance().buildFromTuple(groupedResults.get(x.get("id")), ""); return (T) this.tClass.newInstance().buildFromTuple(groupedResults.get(x.get("id")), this.fields, "");
} catch (InstantiationException | IllegalAccessException e) { } catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -243,7 +243,7 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
.collect(Collectors.groupingBy(x -> x.get("id"))); .collect(Collectors.groupingBy(x -> x.get("id")));
return CompletableFuture.supplyAsync(() -> results.stream().map(x -> { return CompletableFuture.supplyAsync(() -> results.stream().map(x -> {
try { try {
return (T) this.tClass.newInstance().buildFromTuple(groupedResults.get(x.get("id")), ""); return (T) this.tClass.newInstance().buildFromTuple(groupedResults.get(x.get("id")), this.fields, "");
} catch (InstantiationException | IllegalAccessException e) { } catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -383,8 +383,7 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
} }
@Override @Override
public <U extends public <U extends Comparable> Subquery<U> subQueryMax(SinglePredicate<T> predicate, List<SelectionField> fields, Class<U> uClass) {
Comparable> Subquery<U> subQueryMax(SinglePredicate<T> predicate, List<SelectionField> fields, Class<U> uClass) {
Subquery<U> subquery = this.manager.getCriteriaBuilder().createQuery().subquery(uClass); Subquery<U> subquery = this.manager.getCriteriaBuilder().createQuery().subquery(uClass);
this.nestedQueryRoot = subquery.from(this.tClass); this.nestedQueryRoot = subquery.from(this.tClass);
subquery.where(predicate.applyPredicate(this.manager.getCriteriaBuilder(), this.nestedQueryRoot)); subquery.where(predicate.applyPredicate(this.manager.getCriteriaBuilder(), this.nestedQueryRoot));
@ -416,6 +415,21 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
return this; return this;
} }
@Override
public Subquery<T> query(List<SelectionField> fields) {
CriteriaBuilder builder = this.manager.getCriteriaBuilder();
Subquery<T> query = builder.createQuery().subquery(this.tClass);
this.root = query.from(this.tClass);
query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
if (fields.get(0).getType() == FieldSelectionType.FIELD)
query.select(this.root.get(fields.get(0).getField()));
else if (fields.get(0).getType() == FieldSelectionType.COMPOSITE_FIELD) {
query.select(this.root.get(fields.get(0).getField().split(":")[0]).get(fields.get(0).getField().split(":")[1]));
}
if (distinct) query.distinct(true);
return query;
}
@Override @Override
public <V> void update(EntitySelectPredicate<T> selectPredicate, V value) { public <V> void update(EntitySelectPredicate<T> selectPredicate, V value) {
CriteriaBuilder builder = this.manager CriteriaBuilder builder = this.manager

View File

@ -3,8 +3,10 @@ package eu.eudat.queryable.queryableentity;
import javax.persistence.Tuple; import javax.persistence.Tuple;
import java.util.List; import java.util.List;
public interface DataEntity<T,K> { public interface DataEntity<T, K> {
void update(T entity); void update(T entity);
K getKeys();
T buildFromTuple(List<Tuple> tuple, String base); K getKeys();
T buildFromTuple(List<Tuple> tuple, List<String> fields, String base);
} }

View File

@ -2,33 +2,33 @@ package eu.eudat.controllers;
import eu.eudat.configurations.dynamicproject.DynamicProjectConfiguration; import eu.eudat.configurations.dynamicproject.DynamicProjectConfiguration;
import eu.eudat.criteria.DMPCriteria;
import eu.eudat.data.dao.criteria.DynamicFieldsCriteria; import eu.eudat.data.dao.criteria.DynamicFieldsCriteria;
import eu.eudat.data.dao.criteria.RequestItem; import eu.eudat.data.dao.criteria.RequestItem;
import eu.eudat.data.dao.entities.DMPDao; import eu.eudat.data.dao.entities.DMPDao;
import eu.eudat.data.entities.DMP; import eu.eudat.data.entities.DMP;
import eu.eudat.data.query.items.item.dmp.DataManagementPlanCriteriaRequest;
import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest; import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest;
import eu.eudat.data.query.items.table.dmp.DataManagmentPlanPublicTableRequest; import eu.eudat.data.query.items.table.dmp.DataManagmentPlanPublicTableRequest;
import eu.eudat.exceptions.datamanagementplan.DMPNewVersionException; import eu.eudat.exceptions.datamanagementplan.DMPNewVersionException;
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException; import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
import eu.eudat.logic.managers.DataManagementPlanManager; import eu.eudat.logic.managers.DataManagementPlanManager;
import eu.eudat.logic.managers.DatasetManager; import eu.eudat.logic.managers.DatasetManager;
import eu.eudat.logic.managers.FileManager;
import eu.eudat.logic.security.claims.ClaimedAuthorities; import eu.eudat.logic.security.claims.ClaimedAuthorities;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.services.forms.VisibilityRuleService; import eu.eudat.logic.services.forms.VisibilityRuleService;
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope; import eu.eudat.logic.services.operations.DatabaseRepository;
import eu.eudat.models.data.dmp.DataManagementPlan; import eu.eudat.models.data.dmp.DataManagementPlan;
import eu.eudat.models.data.files.ContentFile;
import eu.eudat.models.data.helpermodels.Tuple; import eu.eudat.models.data.helpermodels.Tuple;
import eu.eudat.models.data.helpers.common.DataTableData; import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.listingmodels.DataManagementPlanListingModel; import eu.eudat.models.data.listingmodels.DataManagementPlanListingModel;
import eu.eudat.models.data.listingmodels.DataManagementPlanOverviewModel; import eu.eudat.models.data.listingmodels.DataManagementPlanOverviewModel;
import eu.eudat.models.data.security.Principal; import eu.eudat.models.data.security.Principal;
import eu.eudat.query.DMPQuery;
import eu.eudat.query.ProjectQuery;
import eu.eudat.query.UserQuery;
import eu.eudat.types.ApiMessageCode; import eu.eudat.types.ApiMessageCode;
import eu.eudat.types.Authorities; import eu.eudat.types.Authorities;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -46,6 +46,7 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -55,148 +56,163 @@ import java.util.UUID;
@RequestMapping(value = {"/api/dmps/"}) @RequestMapping(value = {"/api/dmps/"})
public class DMPs extends BaseController { public class DMPs extends BaseController {
private DynamicProjectConfiguration dynamicProjectConfiguration; private DynamicProjectConfiguration dynamicProjectConfiguration;
private Environment environment; private Environment environment;
private DataManagementPlanManager dataManagementPlanManager; private DataManagementPlanManager dataManagementPlanManager;
private DatasetManager datasetManager; private DatasetManager datasetManager;
@Autowired
public DMPs(ApiContext apiContext, DynamicProjectConfiguration dynamicProjectConfiguration, Environment environment,
DataManagementPlanManager dataManagementPlanManager, DatasetManager datasetManager) {
super(apiContext);
this.dynamicProjectConfiguration = dynamicProjectConfiguration;
this.environment = environment;
this.dataManagementPlanManager = dataManagementPlanManager;
this.datasetManager = datasetManager;
}
@Transactional @Autowired
@RequestMapping(method = RequestMethod.GET, value = {"{id}/unlock"}, produces = "application/json") public DMPs(ApiContext apiContext, DynamicProjectConfiguration dynamicProjectConfiguration, Environment environment,
public @ResponseBody DataManagementPlanManager dataManagementPlanManager, DatasetManager datasetManager) {
ResponseEntity<ResponseItem<DMP>> unlock(@PathVariable(value = "id") UUID id, Principal principal) throws Exception { super(apiContext);
this.dataManagementPlanManager.unlock(id); this.dynamicProjectConfiguration = dynamicProjectConfiguration;
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Unlocked")); this.environment = environment;
} this.dataManagementPlanManager = dataManagementPlanManager;
this.datasetManager = datasetManager;
}
@RequestMapping(method = RequestMethod.POST, value = {"/paged"}, consumes = "application/json", produces = "application/json") @Transactional
public @ResponseBody @RequestMapping(method = RequestMethod.GET, value = {"{id}/unlock"}, produces = "application/json")
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanListingModel>>> getPaged(@Valid @RequestBody DataManagementPlanTableRequest dataManagementPlanTableRequest,@RequestParam String fieldsGroup, Principal principal) throws Exception { public @ResponseBody
DataTableData<DataManagementPlanListingModel> dataTable = this.dataManagementPlanManager.getPaged(dataManagementPlanTableRequest, principal, fieldsGroup); ResponseEntity<ResponseItem<DMP>> unlock(@PathVariable(value = "id") UUID id, Principal principal) throws Exception {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable)); this.dataManagementPlanManager.unlock(id);
} return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Unlocked"));
}
@RequestMapping(method = RequestMethod.GET, value = {"{id}"}) @RequestMapping(method = RequestMethod.POST, value = {"/paged"}, consumes = "application/json", produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity getSingle(@PathVariable String id,@RequestHeader("Content-Type") String contentType, Principal principal) throws IllegalAccessException,InterruptedException, InstantiationException, IOException { ResponseEntity<ResponseItem<DataTableData<DataManagementPlanListingModel>>> getPaged(@Valid @RequestBody DataManagementPlanTableRequest dataManagementPlanTableRequest, @RequestParam String fieldsGroup, Principal principal) throws Exception {
if(contentType.equals("application/xml") || contentType.equals("application/msword")){ //|| contentType.equals("application/pdf") DataTableData<DataManagementPlanListingModel> dataTable = this.dataManagementPlanManager.getPaged(dataManagementPlanTableRequest, principal, fieldsGroup);
DMPDao dmpDao = this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
VisibilityRuleService visibilityRuleService = this.getApiContext().getUtilitiesService().getVisibilityRuleService(); }
ResponseEntity<byte[]> document = this.dataManagementPlanManager.getDocument(id, contentType);
return document;
}
else{
eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSingle(id, principal, this.dynamicProjectConfiguration);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
}
}
@RequestMapping(method = RequestMethod.GET, value = {"/overview/{id}"}) @RequestMapping(method = RequestMethod.GET, value = {"{id}"})
public @ResponseBody public @ResponseBody
ResponseEntity getOverviewSingle(@PathVariable String id, Principal principal) throws IllegalAccessException,InterruptedException, InstantiationException, IOException { ResponseEntity getSingle(@PathVariable String id, @RequestHeader("Content-Type") String contentType, Principal principal) throws IllegalAccessException, InterruptedException, InstantiationException, IOException {
DataManagementPlanOverviewModel dataManagementPlan = this.dataManagementPlanManager.getOverviewSingle(id, principal); if (contentType.equals("application/xml") || contentType.equals("application/msword")) { //|| contentType.equals("application/pdf")
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanOverviewModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan)); DMPDao dmpDao = this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao();
} VisibilityRuleService visibilityRuleService = this.getApiContext().getUtilitiesService().getVisibilityRuleService();
ResponseEntity<byte[]> document = this.dataManagementPlanManager.getDocument(id, contentType);
return document;
} else {
eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSingle(id, principal, this.dynamicProjectConfiguration);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
}
}
@RequestMapping(method = RequestMethod.GET, value = {"/public/{id}"}) @RequestMapping(method = RequestMethod.GET, value = {"/overview/{id}"})
public @ResponseBody public @ResponseBody
ResponseEntity getSinglePublic(@PathVariable String id) throws IllegalAccessException,InterruptedException, InstantiationException, IOException { ResponseEntity getOverviewSingle(@PathVariable String id, Principal principal) throws IllegalAccessException, InterruptedException, InstantiationException, IOException {
try { DataManagementPlanOverviewModel dataManagementPlan = this.dataManagementPlanManager.getOverviewSingle(id, principal);
eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSinglePublic(id, this.dynamicProjectConfiguration); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanOverviewModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan)); }
}
catch (Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).message(ex.getMessage()));
}
}
@Transactional @RequestMapping(method = RequestMethod.GET, value = {"/public/{id}"})
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json") public @ResponseBody
public @ResponseBody ResponseEntity getSinglePublic(@PathVariable String id) throws IllegalAccessException, InterruptedException, InstantiationException, IOException {
ResponseEntity<ResponseItem<DMP>> createOrUpdate(@RequestBody eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan, Principal principal) throws Exception { try {
this.dataManagementPlanManager.createOrUpdate(this.getApiContext(), dataManagementPlan, principal); eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSinglePublic(id, this.dynamicProjectConfiguration);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created")); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
} } catch (Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).message(ex.getMessage()));
}
}
@RequestMapping(method = RequestMethod.POST, value = {"/new/{id}"}, consumes = "application/json", produces = "application/json") @Transactional
public @ResponseBody @RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
ResponseEntity<ResponseItem<DMP>> newVersion(@PathVariable UUID id, @Valid @RequestBody eu.eudat.models.data.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception { public @ResponseBody
try { ResponseEntity<ResponseItem<DMP>> createOrUpdate(@RequestBody eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan, Principal principal) throws Exception {
this.dataManagementPlanManager.newVersion(id, dataManagementPlan, principal); this.dataManagementPlanManager.createOrUpdate(this.getApiContext(), dataManagementPlan, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.NO_MESSAGE)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
} catch (DMPNewVersionException exception) { }
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage()));
}
}
@RequestMapping(method = RequestMethod.POST, value = {"/clone/{id}"}, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/new/{id}"}, consumes = "application/json", produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<DMP>> clone(@PathVariable UUID id, @RequestBody eu.eudat.models.data.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception { ResponseEntity<ResponseItem<DMP>> newVersion(@PathVariable UUID id, @Valid @RequestBody eu.eudat.models.data.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
this.dataManagementPlanManager.clone(id, dataManagementPlan, principal); try {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.NO_MESSAGE)); this.dataManagementPlanManager.newVersion(id, dataManagementPlan, principal);
} return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.NO_MESSAGE));
} catch (DMPNewVersionException exception) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage()));
}
}
@Transactional @RequestMapping(method = RequestMethod.POST, value = {"/clone/{id}"}, consumes = "application/json", produces = "application/json")
@RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json") public @ResponseBody
public @ResponseBody ResponseEntity<ResponseItem<DMP>> clone(@PathVariable UUID id, @RequestBody eu.eudat.models.data.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
ResponseEntity<ResponseItem<DMP>> delete(@PathVariable UUID id, Principal principal) { this.dataManagementPlanManager.clone(id, dataManagementPlan, principal);
try{ return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.NO_MESSAGE));
this.dataManagementPlanManager.delete(id); }
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Deleted Datamanagement Plan"));
}catch (DMPWithDatasetsDeleteException exception){
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage()));
}
}
@RequestMapping(method = RequestMethod.POST, value = {"/dynamic"}, consumes = "application/json", produces = "application/json") @Transactional
public @ResponseBody @RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json")
ResponseEntity<ResponseItem<List<Tuple<String, String>>>> getWithCriteria(@RequestBody RequestItem<DynamicFieldsCriteria> criteriaRequestItem, Principal principal) throws InstantiationException, IllegalAccessException { public @ResponseBody
List<Tuple<String, String>> dataTable = this.dataManagementPlanManager.getDynamicFields(criteriaRequestItem.getCriteria().getId(), this.dynamicProjectConfiguration, criteriaRequestItem.getCriteria()); ResponseEntity<ResponseItem<DMP>> delete(@PathVariable UUID id, Principal principal) {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Tuple<String, String>>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable)); try {
} this.dataManagementPlanManager.delete(id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Deleted Datamanagement Plan"));
} catch (DMPWithDatasetsDeleteException exception) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage()));
}
}
@RequestMapping(method = RequestMethod.GET, value = {"/getPDF/{id}"}) @RequestMapping(method = RequestMethod.POST, value = {"/dynamic"}, consumes = "application/json", produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<byte[]> getPDFDocument(@PathVariable String id, @RequestHeader("Content-Type") String contentType) throws IllegalAccessException, IOException, InstantiationException, InterruptedException { ResponseEntity<ResponseItem<List<Tuple<String, String>>>> getWithCriteria(@RequestBody RequestItem<DynamicFieldsCriteria> criteriaRequestItem, Principal principal) throws InstantiationException, IllegalAccessException {
System.out.println(contentType); List<Tuple<String, String>> dataTable = this.dataManagementPlanManager.getDynamicFields(criteriaRequestItem.getCriteria().getId(), this.dynamicProjectConfiguration, criteriaRequestItem.getCriteria());
File file = this.dataManagementPlanManager.getWordDocument(id); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Tuple<String, String>>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
File pdffile = datasetManager.convertToPDF(file, environment, file.getName()); }
InputStream resource = new FileInputStream(pdffile);
System.out.println("Mime Type of " + file.getName() + " is " +
new MimetypesFileTypeMap().getContentType(file));
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(pdffile.length());
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
responseHeaders.set("Content-Disposition", "attachment;filename=" + pdffile.getName());
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
byte[] content = org.apache.poi.util.IOUtils.toByteArray(resource); @RequestMapping(method = RequestMethod.GET, value = {"/getPDF/{id}"})
return new ResponseEntity<>(content, public @ResponseBody
responseHeaders, ResponseEntity<byte[]> getPDFDocument(@PathVariable String id, @RequestHeader("Content-Type") String contentType) throws IllegalAccessException, IOException, InstantiationException, InterruptedException {
HttpStatus.OK); System.out.println(contentType);
} File file = this.dataManagementPlanManager.getWordDocument(id);
File pdffile = datasetManager.convertToPDF(file, environment, file.getName());
InputStream resource = new FileInputStream(pdffile);
System.out.println("Mime Type of " + file.getName() + " is " +
new MimetypesFileTypeMap().getContentType(file));
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(pdffile.length());
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
responseHeaders.set("Content-Disposition", "attachment;filename=" + pdffile.getName());
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
@RequestMapping(method = RequestMethod.POST, value = {"/upload"}) byte[] content = org.apache.poi.util.IOUtils.toByteArray(resource);
public ResponseEntity<ResponseItem> dmpXmlUpload(@RequestParam("file") MultipartFile[] files, Principal principal) throws IOException, JAXBException, Exception { return new ResponseEntity<>(content,
this.dataManagementPlanManager.createDmpFromXml(this.getApiContext(), files, principal); responseHeaders,
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List>() HttpStatus.OK);
.status(ApiMessageCode.SUCCESS_MESSAGE)); }
}
@RequestMapping(method = RequestMethod.POST, value = {"/public/paged"}, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/upload"})
public @ResponseBody public ResponseEntity<ResponseItem> dmpXmlUpload(@RequestParam("file") MultipartFile[] files, Principal principal) throws IOException, JAXBException, Exception {
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanListingModel>>> getPublicPaged(@RequestBody DataManagmentPlanPublicTableRequest dmpTableRequest, @ClaimedAuthorities(claims = {Authorities.ANONYMOUS}) Principal principal) throws Exception { this.dataManagementPlanManager.createDmpFromXml(this.getApiContext(), files, principal);
DataTableData<DataManagementPlanListingModel> dmp = this.dataManagementPlanManager.getPaged(dmpTableRequest, "listing") ; return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List>()
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dmp)); .status(ApiMessageCode.SUCCESS_MESSAGE));
} }
@RequestMapping(method = RequestMethod.POST, value = {"/public/paged"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanListingModel>>> getPublicPaged(@RequestBody DataManagmentPlanPublicTableRequest dmpTableRequest, @ClaimedAuthorities(claims = {Authorities.ANONYMOUS}) Principal principal) throws Exception {
DataTableData<DataManagementPlanListingModel> dmp = this.dataManagementPlanManager.getPaged(dmpTableRequest, "listing");
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dmp));
}
@RequestMapping(method = RequestMethod.POST, value = {"/test"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanListingModel>>> test(@RequestBody DMPCriteria criteria, @ClaimedAuthorities(claims = {Authorities.ANONYMOUS}) Principal principal) throws Exception {
DatabaseRepository dbRepo = this.getApiContext().getOperationsContext().getDatabaseRepository();
DMPQuery query = criteria.getQuery(dbRepo.getDmpDao());
ProjectQuery projectQuery = criteria.getProject().getQuery(dbRepo.getProjectDao());
UserQuery userQuery = criteria.getProject().getCreator().getQuery(dbRepo.getUserInfoDao());
projectQuery.setUserQuery(userQuery);
query.setProjectQuery(projectQuery);
List<DataManagementPlanListingModel> models = query.getQuery().withFields(Arrays.asList("id", "project.id", "dataset.id", "project.creationUser.id")).select(x -> new DataManagementPlanListingModel().fromDataModel(x));
DataTableData<DataManagementPlanListingModel> dmp = new DataTableData<>();
dmp.setData(models);
dmp.setTotalCount(query.getQuery().count());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dmp));
}
} }

View File

@ -0,0 +1,116 @@
package eu.eudat.criteria;
import eu.eudat.criteria.entities.Criteria;
import eu.eudat.criteria.entities.DateCriteria;
import eu.eudat.data.dao.entities.DMPDao;
import eu.eudat.query.DMPQuery;
import java.util.UUID;
public class DMPCriteria {
private Criteria<UUID> id;
private Criteria<UUID> groupId;
private Criteria<String> label;
private Criteria<Integer> version;
private ProjectCriteria project;
private DateCriteria created;
private DateCriteria modified;
public Criteria<UUID> getId() {
return id;
}
public void setId(Criteria<UUID> id) {
this.id = id;
}
public void setId(String id) {
Criteria<UUID> criteria = new Criteria<>();
criteria.setAs(id);
this.id = criteria;
}
public Criteria<UUID> getGroupId() {
return groupId;
}
public void setGroupId(Criteria<UUID> groupId) {
this.groupId = groupId;
}
public void setGroupId(String groupId) {
Criteria<UUID> criteria = new Criteria<>();
criteria.setAs(groupId);
this.groupId = criteria;
}
public Criteria<String> getLabel() {
return label;
}
public void setLabel(Criteria<String> label) {
this.label = label;
}
public void setLabel(String label) {
Criteria<String> criteria = new Criteria<>();
criteria.setAs(label);
this.label = criteria;
}
public Criteria<Integer> getVersion() {
return version;
}
public void setVersion(Criteria<Integer> version) {
this.version = version;
}
public void setVersion(String version) {
Criteria<Integer> criteria = new Criteria<>();
criteria.setAs(version);
this.version = criteria;
}
public ProjectCriteria getProject() {
return project;
}
public void setProject(ProjectCriteria project) {
this.project = project;
}
public DateCriteria getCreated() {
return created;
}
public void setCreated(DateCriteria created) {
this.created = created;
}
public void setCreated(String created) {
DateCriteria criteria = new DateCriteria();
criteria.setAs(created);
this.created = criteria;
}
public DateCriteria getModified() {
return modified;
}
public void setModified(DateCriteria modified) {
this.modified = modified;
}
public void setModified(String modified) {
DateCriteria criteria = new DateCriteria();
criteria.setAs(modified);
this.modified = criteria;
}
public DMPQuery getQuery(DMPDao dao) {
DMPQuery dmpQuery = new DMPQuery(dao);
dmpQuery.setId(this.id.getValue());
return dmpQuery;
}
}

View File

@ -0,0 +1,112 @@
package eu.eudat.criteria;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.node.JsonNodeType;
import eu.eudat.criteria.entities.Criteria;
import eu.eudat.criteria.entities.DateCriteria;
import eu.eudat.data.dao.entities.ProjectDao;
import eu.eudat.query.ProjectQuery;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
public class ProjectCriteria {
private Criteria<UUID> id;
private List<UUID> ids;
private Criteria<String> label;
private List<Integer> statuses;
private DateCriteria created;
private DateCriteria modified;
private UserCriteria creator;
public Criteria<UUID> getId() {
return id;
}
public void setId(JsonNode jsonNode) throws IOException {
if (jsonNode.getNodeType().equals(JsonNodeType.STRING)) {
Criteria<UUID> criteria = new Criteria<>();
criteria.setAs(jsonNode.asText());
this.id = criteria;
} else if (jsonNode.getNodeType().equals(JsonNodeType.OBJECT)) {
ObjectReader reader = new ObjectMapper().readerFor(new TypeReference<Criteria<UUID>>() {});
this.id = reader.readValue(jsonNode);
}
}
public List<UUID> getIds() {
return ids;
}
public void setIds(List<UUID> ids) {
this.ids = ids;
}
public Criteria<String> getLabel() {
return label;
}
public void setLabel(Criteria<String> label) {
this.label = label;
}
public void setLabel(String label) {
Criteria<String> criteria = new Criteria<>();
criteria.setAs(label);
this.label = criteria;
}
public List<Integer> getStatuses() {
return statuses;
}
public void setStatuses(List<Integer> statuses) {
this.statuses = statuses;
}
public DateCriteria getCreated() {
return created;
}
public void setCreated(DateCriteria created) {
this.created = created;
}
public void setCreated(String created) {
DateCriteria criteria = new DateCriteria();
criteria.setAs(created);
this.created = criteria;
}
public DateCriteria getModified() {
return modified;
}
public void setModified(DateCriteria modified) {
this.modified = modified;
}
public void setModified(String modified) {
DateCriteria criteria = new DateCriteria();
criteria.setAs(modified);
this.modified = criteria;
}
public UserCriteria getCreator() {
return creator;
}
public void setCreator(UserCriteria creator) {
this.creator = creator;
}
public ProjectQuery getQuery(ProjectDao dao) {
ProjectQuery query = new ProjectQuery(dao);
query.setId(this.id.getValue());
return query;
}
}

View File

@ -0,0 +1,38 @@
package eu.eudat.criteria;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.node.JsonNodeType;
import eu.eudat.criteria.entities.Criteria;
import eu.eudat.data.dao.entities.UserInfoDao;
import eu.eudat.query.UserQuery;
import java.io.IOException;
import java.util.UUID;
public class UserCriteria {
private Criteria<UUID> id;
public Criteria<UUID> getId() {
return id;
}
public void setId(JsonNode jsonNode) throws IOException {
if (jsonNode.getNodeType().equals(JsonNodeType.STRING)) {
Criteria<UUID> criteria = new Criteria<>();
criteria.setAs(jsonNode.asText());
this.id = criteria;
} else if (jsonNode.getNodeType().equals(JsonNodeType.OBJECT)) {
ObjectReader reader = new ObjectMapper().readerFor(new TypeReference<Criteria<UUID>>() {});
this.id = reader.readValue(jsonNode);
}
}
public UserQuery getQuery(UserInfoDao dao) {
UserQuery query = new UserQuery(dao);
query.setId(this.id.getValue());
return query;
}
}

View File

@ -0,0 +1,36 @@
package eu.eudat.criteria.entities;
enum BaseCriteriaType implements CriteriaType {
EQUALS,
NOT_EQUALS
}
public class Criteria<T> {
private String as;
private BaseCriteriaType type;
private T value;
public String getAs() {
return as;
}
public void setAs(String as) {
this.as = as;
}
public CriteriaType getType() {
return type;
}
public void setType(BaseCriteriaType type) {
this.type = type;
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
}

View File

@ -0,0 +1,4 @@
package eu.eudat.criteria.entities;
public interface CriteriaType {
}

View File

@ -0,0 +1,32 @@
package eu.eudat.criteria.entities;
import java.util.Date;
enum DateCriteriaType implements CriteriaType {
EQUALS,
NOT_EQUALS,
BEFORE,
BETWEEN,
AFTER
}
public class DateCriteria extends Criteria<Date> {
private Date values;
private CriteriaType type;
public Date getValues() {
return values;
}
public void setValues(Date values) {
this.values = values;
}
public CriteriaType getType() {
return type;
}
public void setType(DateCriteriaType type) {
this.type = type;
}
}