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;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
@ -146,8 +147,9 @@ public class Content implements DataEntity<Content, UUID> {
}
@Override
public Content buildFromTuple(List<Tuple> tuple, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id"));
public Content 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

@ -1,6 +1,7 @@
package eu.eudat.data.entities;
import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity;
import javax.persistence.*;
@ -16,7 +17,7 @@ import java.util.UUID;
name = "credentialUserInfo",
attributeNodes = {@NamedAttributeNode("userInfo")})
})
public class Credential implements DataEntity<Credential,UUID> {
public class Credential implements DataEntity<Credential, UUID> {
@Id
@Column(name = "\"Id\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
@ -148,8 +149,9 @@ public class Credential implements DataEntity<Credential,UUID> {
}
@Override
public Credential buildFromTuple(List<Tuple> tuple, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id"));
public Credential 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

@ -2,6 +2,7 @@ package eu.eudat.data.entities;
import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
@ -35,7 +36,7 @@ import java.util.stream.Collectors;
public class DMP implements DataEntity<DMP, UUID> {
public enum DMPStatus {
ACTIVE((short) 0), FINALISED((short) 1),DELETED((short) 99);
ACTIVE((short) 0), FINALISED((short) 1), DELETED((short) 99);
private short value;
@ -155,6 +156,7 @@ public class DMP implements DataEntity<DMP, UUID> {
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@ -162,6 +164,7 @@ public class DMP implements DataEntity<DMP, UUID> {
public UserInfo getCreator() {
return creator;
}
public void setCreator(UserInfo creator) {
this.creator = creator;
}
@ -169,6 +172,7 @@ public class DMP implements DataEntity<DMP, UUID> {
public Short getStatus() {
return status;
}
public void setStatus(Short status) {
this.status = status;
}
@ -176,6 +180,7 @@ public class DMP implements DataEntity<DMP, UUID> {
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
@ -183,6 +188,7 @@ public class DMP implements DataEntity<DMP, UUID> {
public Date getModified() {
return modified;
}
public void setModified(Date modified) {
this.modified = modified;
}
@ -190,6 +196,7 @@ public class DMP implements DataEntity<DMP, UUID> {
public Set<UserDMP> getUsers() {
return users;
}
public void setUsers(Set<UserDMP> users) {
this.users = users;
}
@ -197,6 +204,7 @@ public class DMP implements DataEntity<DMP, UUID> {
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
@ -204,6 +212,7 @@ public class DMP implements DataEntity<DMP, UUID> {
public UUID getGroupId() {
return groupId;
}
public void setGroupId(UUID groupId) {
this.groupId = groupId;
}
@ -211,6 +220,7 @@ public class DMP implements DataEntity<DMP, UUID> {
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
@ -218,6 +228,7 @@ public class DMP implements DataEntity<DMP, UUID> {
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
@ -225,6 +236,7 @@ public class DMP implements DataEntity<DMP, UUID> {
public Project getProject() {
return project;
}
public void setProject(Project project) {
this.project = project;
}
@ -232,6 +244,7 @@ public class DMP implements DataEntity<DMP, UUID> {
public String getAssociatedDmps() {
return associatedDmps;
}
public void setAssociatedDmps(String associatedDmps) {
this.associatedDmps = associatedDmps;
}
@ -239,6 +252,7 @@ public class DMP implements DataEntity<DMP, UUID> {
public DMPProfile getProfile() {
return profile;
}
public void setProfile(DMPProfile profile) {
this.profile = profile;
}
@ -246,6 +260,7 @@ public class DMP implements DataEntity<DMP, UUID> {
public Set<Dataset> getDataset() {
return dataset;
}
public void setDataset(Set<Dataset> dataset) {
this.dataset = dataset;
}
@ -253,6 +268,7 @@ public class DMP implements DataEntity<DMP, UUID> {
public Set<Organisation> getOrganisations() {
return organisations;
}
public void setOrganisations(Set<Organisation> organisations) {
this.organisations = organisations;
}
@ -260,6 +276,7 @@ public class DMP implements DataEntity<DMP, UUID> {
public Set<Researcher> getResearchers() {
return researchers;
}
public void setResearchers(Set<Researcher> researchers) {
this.researchers = researchers;
}
@ -267,6 +284,7 @@ public class DMP implements DataEntity<DMP, UUID> {
public String getProperties() {
return properties;
}
public void setProperties(String properties) {
this.properties = properties;
}
@ -274,6 +292,7 @@ public class DMP implements DataEntity<DMP, UUID> {
public String getDmpProperties() {
return dmpProperties;
}
public void setDmpProperties(String dmpProperties) {
this.dmpProperties = dmpProperties;
}
@ -301,10 +320,12 @@ public class DMP implements DataEntity<DMP, UUID> {
}
@Override
public DMP buildFromTuple(List<Tuple> tuple, String base) {
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 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.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
@ -145,8 +146,9 @@ public class DMPProfile implements DataEntity<DMPProfile, UUID> {
}
@Override
public DMPProfile buildFromTuple(List<Tuple> tuple, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id"));
public DMPProfile 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

@ -1,6 +1,7 @@
package eu.eudat.data.entities;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
@ -14,7 +15,7 @@ import java.util.UUID;
@Entity
@Table(name = "\"DataRepository\"")
public class DataRepository implements Serializable, DataEntity<DataRepository,UUID> {
public class DataRepository implements Serializable, DataEntity<DataRepository, UUID> {
@Id
@GeneratedValue
@ -150,8 +151,9 @@ public class DataRepository implements Serializable, DataEntity<DataRepository,U
}
@Override
public DataRepository buildFromTuple(List<Tuple> tuple, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id"));
public DataRepository 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

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

View File

@ -1,8 +1,8 @@
package eu.eudat.data.entities;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import javax.persistence.*;
import java.util.List;
@ -14,7 +14,7 @@ import java.util.UUID;
@Entity
@Table(name = "\"DatasetDataRepository\"")
public class DatasetDataRepository implements DataEntity<DatasetDataRepository,UUID> {
public class DatasetDataRepository implements DataEntity<DatasetDataRepository, UUID> {
@Id
@GeneratedValue
@ -89,8 +89,9 @@ public class DatasetDataRepository implements DataEntity<DatasetDataRepository,U
}
@Override
public DatasetDataRepository buildFromTuple(List<Tuple> tuple, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id"));
public DatasetDataRepository 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

@ -1,8 +1,8 @@
package eu.eudat.data.entities;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import javax.persistence.*;
import java.util.List;
@ -11,7 +11,7 @@ import java.util.UUID;
@Entity
@Table(name = "\"DatasetExternalDataset\"")
public class DatasetExternalDataset implements DataEntity<DatasetExternalDataset,UUID> {
public class DatasetExternalDataset implements DataEntity<DatasetExternalDataset, UUID> {
@Id
@GeneratedValue
@ -87,8 +87,9 @@ public class DatasetExternalDataset implements DataEntity<DatasetExternalDataset
}
@Override
public DatasetExternalDataset buildFromTuple(List<Tuple> tuple, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id"));
public DatasetExternalDataset 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

@ -2,6 +2,7 @@ package eu.eudat.data.entities;
import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
@ -15,7 +16,7 @@ import java.util.UUID;
@Entity
@Table(name = "\"DatasetProfile\"")
public class DatasetProfile implements DataEntity<DatasetProfile,UUID>{
public class DatasetProfile implements DataEntity<DatasetProfile, UUID> {
public enum Status {
SAVED((short) 0), FINALIZED((short) 1), DELETED((short) 99);
@ -25,6 +26,7 @@ public class DatasetProfile implements DataEntity<DatasetProfile,UUID>{
private Status(short value) {
this.value = value;
}
public short getValue() {
return value;
}
@ -83,6 +85,7 @@ public class DatasetProfile implements DataEntity<DatasetProfile,UUID>{
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@ -90,6 +93,7 @@ public class DatasetProfile implements DataEntity<DatasetProfile,UUID>{
public Short getStatus() {
return status;
}
public void setStatus(Short status) {
this.status = status;
}
@ -97,6 +101,7 @@ public class DatasetProfile implements DataEntity<DatasetProfile,UUID>{
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
@ -104,6 +109,7 @@ public class DatasetProfile implements DataEntity<DatasetProfile,UUID>{
public Date getModified() {
return modified;
}
public void setModified(Date modified) {
this.modified = modified;
}
@ -111,11 +117,15 @@ public class DatasetProfile implements DataEntity<DatasetProfile,UUID>{
public UUID getId() {
return id;
}
public void setId(UUID id) { this.id = id;}
public void setId(UUID id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
@ -123,6 +133,7 @@ public class DatasetProfile implements DataEntity<DatasetProfile,UUID>{
public String getDefinition() {
return definition;
}
public void setDefinition(String definition) {
this.definition = definition;
}
@ -130,15 +141,26 @@ public class DatasetProfile implements DataEntity<DatasetProfile,UUID>{
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 UUID getGroupId() {
return groupId;
}
public Short getVersion() { return version; }
public void setVersion(Short version) { this.version = version; }
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() {
@ -155,8 +177,9 @@ public class DatasetProfile implements DataEntity<DatasetProfile,UUID>{
}
@Override
public DatasetProfile buildFromTuple(List<Tuple> tuple, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id"));
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 org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import javax.persistence.*;
import java.io.Serializable;
import java.util.List;
import java.util.UUID;
@ -90,8 +88,9 @@ public class DatasetService implements DataEntity<DatasetService, UUID> {
}
@Override
public DatasetService buildFromTuple(List<Tuple> tuple, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id"));
public DatasetService buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
String currentBase = base.isEmpty() ? "" : base + ".";
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;
import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
@ -108,8 +109,9 @@ public class ExternalDataset implements DataEntity<ExternalDataset,UUID> {
}
@Override
public ExternalDataset buildFromTuple(List<Tuple> tuple, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id"));
public ExternalDataset 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

@ -1,5 +1,6 @@
package eu.eudat.data.entities;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
@ -11,7 +12,7 @@ import java.util.UUID;
@Entity
@Table(name = "\"Invitation\"")
public class Invitation implements DataEntity<Invitation,UUID> {
public class Invitation implements DataEntity<Invitation, UUID> {
@Id
@GeneratedValue
@ -107,8 +108,9 @@ public class Invitation implements DataEntity<Invitation,UUID> {
}
@Override
public Invitation buildFromTuple(List<Tuple> tuple, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id"));
public Invitation 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

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

@ -2,6 +2,7 @@ package eu.eudat.data.entities;
import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
@ -25,7 +26,7 @@ import java.util.stream.Collectors;
@NamedEntityGraph(
name = "projectListingItem",
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> {
@ -305,9 +306,13 @@ public class Project implements DataEntity<Project, UUID> {
}
@Override
public Project buildFromTuple(List<Tuple> tuple, String base) {
this.id = (UUID) tuple.get(0).get(base.isEmpty() ? "id" : base + "." + "id" );
this.dmps = tuple.stream().map(x-> new DMP().buildFromTuple(tuple,"dmps")).collect(Collectors.toSet());
public Project 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");
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.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import javax.persistence.*;
@ -15,7 +15,7 @@ import java.util.UUID;
@Entity
@Table(name = "\"Registry\"")
public class Registry implements DataEntity<Registry,UUID> {
public class Registry implements DataEntity<Registry, UUID> {
@Id
@ -157,8 +157,9 @@ public class Registry implements DataEntity<Registry,UUID> {
}
@Override
public Registry buildFromTuple(List<Tuple> tuple, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id"));
public Registry 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

@ -2,6 +2,7 @@ package eu.eudat.data.entities;
import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
@ -15,7 +16,7 @@ import java.util.UUID;
@Entity
@Table(name = "\"Researcher\"")
public class Researcher implements DataEntity<Researcher,UUID> {
public class Researcher implements DataEntity<Researcher, UUID> {
@Id
@GeneratedValue
@ -160,8 +161,9 @@ public class Researcher implements DataEntity<Researcher,UUID> {
}
@Override
public Researcher buildFromTuple(List<Tuple> tuple, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id"));
public Researcher 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

@ -152,8 +152,9 @@ public class Service implements DataEntity<Service, UUID> {
}
@Override
public Service buildFromTuple(List<Tuple> tuple, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id"));
public Service buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
String currentBase = base.isEmpty() ? "" : base + ".";
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;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
@ -97,8 +98,9 @@ public class UserDMP implements DataEntity<UserDMP, UUID> {
}
@Override
public UserDMP buildFromTuple(List<Tuple> tuple, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id"));
public UserDMP 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

@ -1,6 +1,7 @@
package eu.eudat.data.entities;
import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
@ -179,8 +180,9 @@ public class UserInfo implements DataEntity<UserInfo, UUID> {
}
@Override
public UserInfo buildFromTuple(List<Tuple> tuple, String base) {
this.id = (UUID) tuple.get(0).get(base.isEmpty() ? "id" : base + "." + "id" );
public UserInfo 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

@ -1,5 +1,6 @@
package eu.eudat.data.entities;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
@ -60,8 +61,9 @@ public class UserRole implements DataEntity<UserRole, UUID> {
}
@Override
public UserRole buildFromTuple(List<Tuple> tuple, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id"));
public UserRole 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

@ -1,6 +1,7 @@
package eu.eudat.data.entities;
import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.entities.helpers.EntityBinder;
import eu.eudat.queryable.queryableentity.DataEntity;
import javax.persistence.*;
@ -73,8 +74,9 @@ public class UserToken implements DataEntity<UserToken, UUID> {
}
@Override
public UserToken buildFromTuple(List<Tuple> tuple, String base) {
this.token = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "token" : "token"));
public UserToken buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
String currentBase = base.isEmpty() ? "" : base + ".";
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.types.SelectionField;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Subquery;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@ -47,6 +49,8 @@ public interface QueryableList<T extends DataEntity> {
CompletableFuture<Long> countAsync();
Subquery<T> query(List<SelectionField> fields);
Subquery<T> subQuery(SinglePredicate<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")));
return results.stream().map(x -> {
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) {
e.printStackTrace();
}
@ -243,7 +243,7 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
.collect(Collectors.groupingBy(x -> x.get("id")));
return CompletableFuture.supplyAsync(() -> results.stream().map(x -> {
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) {
e.printStackTrace();
}
@ -383,8 +383,7 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
}
@Override
public <U extends
Comparable> Subquery<U> subQueryMax(SinglePredicate<T> predicate, List<SelectionField> fields, Class<U> uClass) {
public <U extends Comparable> Subquery<U> subQueryMax(SinglePredicate<T> predicate, List<SelectionField> fields, Class<U> uClass) {
Subquery<U> subquery = this.manager.getCriteriaBuilder().createQuery().subquery(uClass);
this.nestedQueryRoot = subquery.from(this.tClass);
subquery.where(predicate.applyPredicate(this.manager.getCriteriaBuilder(), this.nestedQueryRoot));
@ -416,6 +415,21 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
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
public <V> void update(EntitySelectPredicate<T> selectPredicate, V value) {
CriteriaBuilder builder = this.manager

View File

@ -3,8 +3,10 @@ package eu.eudat.queryable.queryableentity;
import javax.persistence.Tuple;
import java.util.List;
public interface DataEntity<T,K> {
public interface DataEntity<T, K> {
void update(T entity);
K getKeys();
T buildFromTuple(List<Tuple> tuple, String base);
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.criteria.DMPCriteria;
import eu.eudat.data.dao.criteria.DynamicFieldsCriteria;
import eu.eudat.data.dao.criteria.RequestItem;
import eu.eudat.data.dao.entities.DMPDao;
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.DataManagmentPlanPublicTableRequest;
import eu.eudat.exceptions.datamanagementplan.DMPNewVersionException;
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
import eu.eudat.logic.managers.DataManagementPlanManager;
import eu.eudat.logic.managers.DatasetManager;
import eu.eudat.logic.managers.FileManager;
import eu.eudat.logic.security.claims.ClaimedAuthorities;
import eu.eudat.logic.services.ApiContext;
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.files.ContentFile;
import eu.eudat.models.data.helpermodels.Tuple;
import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.listingmodels.DataManagementPlanListingModel;
import eu.eudat.models.data.listingmodels.DataManagementPlanOverviewModel;
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.Authorities;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpHeaders;
@ -46,6 +46,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
@ -59,6 +60,7 @@ public class DMPs extends BaseController {
private Environment environment;
private DataManagementPlanManager dataManagementPlanManager;
private DatasetManager datasetManager;
@Autowired
public DMPs(ApiContext apiContext, DynamicProjectConfiguration dynamicProjectConfiguration, Environment environment,
DataManagementPlanManager dataManagementPlanManager, DatasetManager datasetManager) {
@ -79,21 +81,20 @@ public class DMPs extends BaseController {
@RequestMapping(method = RequestMethod.POST, value = {"/paged"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanListingModel>>> getPaged(@Valid @RequestBody DataManagementPlanTableRequest dataManagementPlanTableRequest,@RequestParam String fieldsGroup, Principal principal) throws Exception {
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanListingModel>>> getPaged(@Valid @RequestBody DataManagementPlanTableRequest dataManagementPlanTableRequest, @RequestParam String fieldsGroup, Principal principal) throws Exception {
DataTableData<DataManagementPlanListingModel> dataTable = this.dataManagementPlanManager.getPaged(dataManagementPlanTableRequest, principal, fieldsGroup);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
}
@RequestMapping(method = RequestMethod.GET, value = {"{id}"})
public @ResponseBody
ResponseEntity getSingle(@PathVariable String id,@RequestHeader("Content-Type") String contentType, Principal principal) throws IllegalAccessException,InterruptedException, InstantiationException, IOException {
if(contentType.equals("application/xml") || contentType.equals("application/msword")){ //|| contentType.equals("application/pdf")
ResponseEntity getSingle(@PathVariable String id, @RequestHeader("Content-Type") String contentType, Principal principal) throws IllegalAccessException, InterruptedException, InstantiationException, IOException {
if (contentType.equals("application/xml") || contentType.equals("application/msword")) { //|| contentType.equals("application/pdf")
DMPDao dmpDao = this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao();
VisibilityRuleService visibilityRuleService = this.getApiContext().getUtilitiesService().getVisibilityRuleService();
ResponseEntity<byte[]> document = this.dataManagementPlanManager.getDocument(id, contentType);
return document;
}
else{
} 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));
}
@ -101,19 +102,18 @@ public class DMPs extends BaseController {
@RequestMapping(method = RequestMethod.GET, value = {"/overview/{id}"})
public @ResponseBody
ResponseEntity getOverviewSingle(@PathVariable String id, Principal principal) throws IllegalAccessException,InterruptedException, InstantiationException, IOException {
ResponseEntity getOverviewSingle(@PathVariable String id, Principal principal) throws IllegalAccessException, InterruptedException, InstantiationException, IOException {
DataManagementPlanOverviewModel dataManagementPlan = this.dataManagementPlanManager.getOverviewSingle(id, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlanOverviewModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
}
@RequestMapping(method = RequestMethod.GET, value = {"/public/{id}"})
public @ResponseBody
ResponseEntity getSinglePublic(@PathVariable String id) throws IllegalAccessException,InterruptedException, InstantiationException, IOException {
ResponseEntity getSinglePublic(@PathVariable String id) throws IllegalAccessException, InterruptedException, InstantiationException, IOException {
try {
eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSinglePublic(id, this.dynamicProjectConfiguration);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
}
catch (Exception ex) {
} catch (Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).message(ex.getMessage()));
}
}
@ -148,10 +148,10 @@ public class DMPs extends BaseController {
@RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DMP>> delete(@PathVariable UUID id, Principal principal) {
try{
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){
} catch (DMPWithDatasetsDeleteException exception) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage()));
}
}
@ -195,7 +195,23 @@ public class DMPs extends BaseController {
@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") ;
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;
}
}