remove old data entities

This commit is contained in:
Efstratios Giannopoulos 2023-11-16 14:01:39 +02:00
parent 7c8b385146
commit dec8f6354c
77 changed files with 2240 additions and 2781 deletions

View File

@ -2,14 +2,16 @@ package eu.eudat.data;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.converters.enums.IsActiveConverter;
import eu.eudat.data.old.queryableentity.DataEntity;
import jakarta.persistence.*;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
@Entity
@Table(name = "\"DmpDescriptionTemplate\"")
public class DmpDescriptionTemplateEntity {
public class DmpDescriptionTemplateEntity implements DataEntity<DmpDescriptionTemplateEntity, UUID> {
@Id
@Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
@ -104,4 +106,18 @@ public class DmpDescriptionTemplateEntity {
this.isActive = isActive;
}
@Override
public void update(DmpDescriptionTemplateEntity entity) {
}
@Override
public UUID getKeys() {
return null;
}
@Override
public DmpDescriptionTemplateEntity buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
return null;
}
}

View File

@ -8,14 +8,16 @@ import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.converters.enums.DmpAccessTypeConverter;
import eu.eudat.data.converters.enums.DmpStatusConverter;
import eu.eudat.data.converters.enums.IsActiveConverter;
import eu.eudat.data.old.queryableentity.DataEntity;
import jakarta.persistence.*;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
@Entity
@Table(name = "\"Dmp\"")
public class DmpEntity {
public class DmpEntity implements DataEntity<DmpEntity, UUID> {
@Id
@Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
@ -244,4 +246,20 @@ public class DmpEntity {
public void setVersionStatus(DmpVersionStatus versionStatus) {
this.versionStatus = versionStatus;
}
@Override
public void update(DmpEntity entity) {
}
@Override
public UUID getKeys() {
return null;
}
@Override
public DmpEntity buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
return null;
}
}

View File

@ -4,14 +4,16 @@ import eu.eudat.commons.enums.DmpUserRole;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.converters.enums.DmpUserRoleConverter;
import eu.eudat.data.converters.enums.IsActiveConverter;
import eu.eudat.data.old.queryableentity.DataEntity;
import jakarta.persistence.*;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
@Entity
@Table(name = "\"DmpUser\"")
public class DmpUserEntity {
public class DmpUserEntity implements DataEntity {
@Id
@Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
@ -107,4 +109,18 @@ public class DmpUserEntity {
this.isActive = isActive;
}
@Override
public void update(Object entity) {
}
@Override
public Object getKeys() {
return null;
}
@Override
public Object buildFromTuple(List tuple, List fields, String base) {
return null;
}
}

View File

@ -2,14 +2,11 @@ package eu.eudat.data;
import eu.eudat.commons.enums.EntityType;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.converters.enums.EntityTypeConverter;
import eu.eudat.data.converters.enums.IsActiveConverter;
import eu.eudat.data.old.DMP;
import jakarta.persistence.*;
import java.time.Instant;
import java.util.Date;
import java.util.UUID;
@Entity

View File

@ -1,401 +0,0 @@
package eu.eudat.data.old;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DmpBlueprintEntity;
import eu.eudat.data.EntityDoiEntity;
import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.old.queryableentity.DataEntity;
import jakarta.persistence.*;
import java.util.*;
import java.util.stream.Collectors;
@Entity
@Table(name = "\"DMP\"")
@NamedEntityGraphs({
@NamedEntityGraph(
name = "dataManagementPlanListingModel",
attributeNodes = {
@NamedAttributeNode("grant"), @NamedAttributeNode("creator"), @NamedAttributeNode("profile")}/*,*/
/*subgraphs = {
@NamedSubgraph(name = "users", attributeNodes = {@NamedAttributeNode("user")}),
}*/
),
@NamedEntityGraph(
name = "fullyDetailed",
attributeNodes = {
@NamedAttributeNode("grant"), @NamedAttributeNode("profile"),
@NamedAttributeNode(value = "users", subgraph = "users"), @NamedAttributeNode("organisations"), @NamedAttributeNode("researchers")
},
subgraphs = {
@NamedSubgraph(name = "users", attributeNodes = {@NamedAttributeNode("user")})
}
),
@NamedEntityGraph(
name = "dmpRecentActivity",
attributeNodes = {
@NamedAttributeNode("users"), @NamedAttributeNode("creator")}),
// @NamedEntityGraph(
// name = "recentDmpModel",
// attributeNodes = {@NamedAttributeNode("organisations"), @NamedAttributeNode("researchers"), @NamedAttributeNode("associatedDmps"),
// @NamedAttributeNode("grant"), @NamedAttributeNode(value = "users", subgraph = "users"), @NamedAttributeNode("creator"), @NamedAttributeNode("profile"), @NamedAttributeNode(value = "dataset", subgraph = "dataset")},
// subgraphs = {
// @NamedSubgraph(name = "users", attributeNodes = {@NamedAttributeNode("user")}),
// @NamedSubgraph(name = "dataset", attributeNodes = {@NamedAttributeNode("id"), @NamedAttributeNode("label")})
// }
// ),
@NamedEntityGraph(
name = "versionListingModel",
attributeNodes = {@NamedAttributeNode("id"), @NamedAttributeNode("groupId"), @NamedAttributeNode("version")}
)
})
public class DMP implements DataEntity<DMP, UUID> {
public enum DMPStatus {
ACTIVE((short) 0), FINALISED((short) 1),DELETED((short) 99);
private short value;
private DMPStatus(short value) {
this.value = value;
}
public short getValue() {
return value;
}
public static DMPStatus fromInteger(short value) {
switch (value) {
case 0:
return ACTIVE;
case 1:
return FINALISED;
case 99:
return DELETED;
default:
throw new RuntimeException("Unsupported DMP Status");
}
}
}
public static Set<String> getHints() {
return hints;
}
private static final Set<String> hints = new HashSet<>(Arrays.asList("dataManagementPlanListingModel", "fullyDetailed"));
@Id
@GeneratedValue
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
@Column(name = "\"GroupId\"", columnDefinition = "BINARY(16)")
private UUID groupId;
@Column(name = "\"Label\"")
private String label;
@Column(name = "\"Version\"")
private Integer version;
@Transient
private Set<DescriptionEntity> descriptionEntity;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"Grant\"")
private Grant grant;
/*@Type(type = "eu.eudat.configurations.typedefinition.XMLType")
@Column(name = "\"AssociatedDmps\"", columnDefinition = "xml", nullable = true)
private String associatedDmps;*/
@OneToMany(fetch = FetchType.LAZY, mappedBy = "dmp")
private Set<DMPDatasetProfile> associatedDmps;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"Profile\"")
private DmpBlueprintEntity profile;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"Creator\"")
private UserInfo creator;
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "\"DMPOrganisation\"",
joinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")},
inverseJoinColumns = {@JoinColumn(name = "\"Organisation\"", referencedColumnName = "\"ID\"")}
)
private Set<Organisation> organisations;
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "\"DMPResearcher\"",
joinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")},
inverseJoinColumns = {@JoinColumn(name = "\"Researcher\"", referencedColumnName = "\"ID\"")}
)
private Set<Researcher> researchers;
@OneToMany(mappedBy = "dmp", fetch = FetchType.LAZY)
/*@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "\"UserDMP\"",
joinColumns = {@JoinColumn(name = "dmp", referencedColumnName = "\"ID\"")},
inverseJoinColumns = {@JoinColumn(name = "usr", referencedColumnName = "id")}
)*/
private Set<UserDMP> users;
@Column(name = "\"Status\"", nullable = false)
private Short status;
@Column(name = "\"Properties\"")
private String properties;
@Column(name = "\"DmpProperties\"")
private String dmpProperties;
@Column(name = "\"Created\"")
@Convert(converter = DateToUTCConverter.class)
private Date created = null;
@Column(name = "\"Modified\"")
@Convert(converter = DateToUTCConverter.class)
private Date modified = new Date();
@Column(name = "\"Description\"")
private String description;
@Column(name= "\"FinalizedAt\"")
@Convert(converter = DateToUTCConverter.class)
private Date finalizedAt;
@Column(name = "\"isPublic\"", nullable = false)
private boolean isPublic;
@Column(name= "\"PublishedAt\"")
@Convert(converter = DateToUTCConverter.class)
private Date publishedAt;
@Transient
private Set<EntityDoiEntity> dois;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"Project\"")
private Project project;
@Column(name = "\"extraProperties\"")
private String extraProperties;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public UserInfo getCreator() {
return creator;
}
public void setCreator(UserInfo creator) {
this.creator = creator;
}
public Short getStatus() {
return status;
}
public void setStatus(Short status) {
this.status = status;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getModified() {
return modified;
}
public void setModified(Date modified) {
this.modified = modified;
}
public Set<UserDMP> getUsers() {
return users;
}
public void setUsers(Set<UserDMP> users) {
this.users = users;
}
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public UUID getGroupId() {
return groupId;
}
public void setGroupId(UUID groupId) {
this.groupId = groupId;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
public Grant getGrant() {
return grant;
}
public void setGrant(Grant grant) {
this.grant = grant;
}
public Set<DMPDatasetProfile> getAssociatedDmps() {
return associatedDmps;
}
public void setAssociatedDmps(Set<DMPDatasetProfile> associatedDmps) {
this.associatedDmps = associatedDmps;
}
public DmpBlueprintEntity getProfile() {
return profile;
}
public void setProfile(DmpBlueprintEntity profile) {
this.profile = profile;
}
public Set<DescriptionEntity> getDataset() {
return descriptionEntity;
}
public void setDataset(Set<DescriptionEntity> descriptionEntity) {
this.descriptionEntity = descriptionEntity;
}
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;
}
public Date getFinalizedAt() {
return finalizedAt;
}
public void setFinalizedAt(Date finalizedAt) {
this.finalizedAt = finalizedAt;
}
public boolean isPublic() {
return isPublic;
}
public void setPublic(boolean aPublic) {
isPublic = aPublic;
}
public Date getPublishedAt() {
return publishedAt;
}
public void setPublishedAt(Date publishedAt) {
this.publishedAt = publishedAt;
}
public Set<EntityDoiEntity> getDois() {
return dois;
}
public void setDois(Set<EntityDoiEntity> dois) {
this.dois = dois;
}
public Project getProject() {
return project;
}
public void setProject(Project project) {
this.project = project;
}
public String getExtraProperties() {
return extraProperties;
}
public void setExtraProperties(String extraProperties) {
this.extraProperties = extraProperties;
}
@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.grant = entity.getGrant();
this.description = entity.getDescription();
this.researchers = entity.getResearchers();
this.organisations = entity.getOrganisations();
this.dmpProperties = entity.getDmpProperties();
this.isPublic = entity.isPublic;
this.project = entity.getProject();
this.setModified(new Date());
if (entity.getStatus().equals(DMPStatus.FINALISED.getValue())) this.setFinalizedAt(new Date());
if (entity.isPublic) this.setPublishedAt(new Date());
if (entity.getUsers() != null) this.users = entity.getUsers();
this.dois = entity.getDois();
this.extraProperties = entity.getExtraProperties();
}
@Override
public UUID getKeys() {
return this.id;
}
@Override
public DMP buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.id = tuple.get(0).get(base.isEmpty() ? "id" : base + "." + "id", UUID.class);
this.descriptionEntity = tuple.stream().map(x -> new DescriptionEntity().buildFromTuple(tuple, fields ,base.isEmpty() ? "dataset" : base + "." + "dataset")).collect(Collectors.toSet());
this.creator = tuple.stream().map(x -> new UserInfo().buildFromTuple(tuple, fields , base.isEmpty() ? "creator" : base + "." + "creator")).collect(Collectors.toList()).get(0);
return this;
}
}

View File

@ -1,75 +0,0 @@
package eu.eudat.data.old;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.data.old.queryableentity.DataEntity;
import jakarta.persistence.*;
import java.util.List;
import java.util.UUID;
@Entity
@Table(name = "\"DMPDatasetProfile\"")
public class DMPDatasetProfile implements DataEntity<DMPDatasetProfile, UUID> {
@Id
@GeneratedValue
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
@ManyToOne
@JoinColumn(name = "\"dmp\"")
private DMP dmp;
@ManyToOne
@JoinColumn(name = "\"datasetprofile\"")
private DescriptionTemplateEntity datasetprofile;
@Column(name = "\"data\"")
private String data;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public DMP getDmp() {
return dmp;
}
public void setDmp(DMP dmp) {
this.dmp = dmp;
}
public DescriptionTemplateEntity getDatasetprofile() {
return datasetprofile;
}
public void setDatasetprofile(DescriptionTemplateEntity datasetprofile) {
this.datasetprofile = datasetprofile;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
@Override
public void update(DMPDatasetProfile entity) {
this.dmp = entity.getDmp();
this.datasetprofile = entity.getDatasetprofile();
this.data = entity.getData();
}
@Override
public UUID getKeys() {
return this.id;
}
@Override
public DMPDatasetProfile buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id"));
return this;
}
}

View File

@ -1,60 +0,0 @@
package eu.eudat.data.old;
import jakarta.persistence.*;
import java.io.Serializable;
import java.util.UUID;
@Entity
@Table(name = "\"DMPOrganisation\"")
public class DMPOrganisation {
@Id
@GeneratedValue
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
@Column(name = "\"DMP\"")
private UUID dmp;
@Column(name = "\"Organisation\"")
private UUID organisation;
@Column(name = "\"Role\"")
private Integer role;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public UUID getDmp() {
return dmp;
}
public void setDmp(UUID dmp) {
this.dmp = dmp;
}
public UUID getOrganisation() {
return organisation;
}
public void setOrganisation(UUID organisation) {
this.organisation = organisation;
}
public Integer getRole() {
return role;
}
public void setRole(Integer role) {
this.role = role;
}
}

View File

@ -1,60 +0,0 @@
package eu.eudat.data.old;
import jakarta.persistence.*;
import java.util.UUID;
@Entity
@Table(name = "\"DMPResearcher\"")
public class DMPResearcher {
@Id
@GeneratedValue
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
@Column(name = "\"DMP\"")
private UUID dmp;
@Column(name = "\"Researcher\"")
private UUID researcher;
@Column(name = "\"Role\"")
private Integer role;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public UUID getDmp() {
return dmp;
}
public void setDmp(UUID dmp) {
this.dmp = dmp;
}
public UUID getResearcher() {
return researcher;
}
public void setResearcher(UUID researcher) {
this.researcher = researcher;
}
public Integer getRole() {
return role;
}
public void setRole(Integer role) {
this.role = role;
}
}

View File

@ -12,18 +12,18 @@ import java.util.stream.Collectors;
@Entity
@Table(name = "\"Grant\"")
@NamedEntityGraphs({
@NamedEntityGraph(
name = "grantRecentActivity",
attributeNodes = {@NamedAttributeNode(value = "dmps", subgraph = "dmps")},
subgraphs = @NamedSubgraph(name = "dmps", attributeNodes = {@NamedAttributeNode("users")})
),
@NamedEntityGraph(
name = "grantListingItem",
attributeNodes = {@NamedAttributeNode(value = "dmps", subgraph = "dmps"), @NamedAttributeNode(value = "content")},
subgraphs = @NamedSubgraph(name = "dmps", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("grant"), @NamedAttributeNode("users")})
)
})
//@NamedEntityGraphs({
// @NamedEntityGraph(
// name = "grantRecentActivity",
// attributeNodes = {@NamedAttributeNode(value = "dmps", subgraph = "dmps")},
// subgraphs = @NamedSubgraph(name = "dmps", attributeNodes = {@NamedAttributeNode("users")})
// ),
// @NamedEntityGraph(
// name = "grantListingItem",
// attributeNodes = {@NamedAttributeNode(value = "dmps", subgraph = "dmps"), @NamedAttributeNode(value = "content")},
// subgraphs = @NamedSubgraph(name = "dmps", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("grant"), @NamedAttributeNode("users")})
// )
//})
public class Grant implements DataEntity<Grant, UUID> {
public enum Status {
@ -85,8 +85,8 @@ public class Grant implements DataEntity<Grant, UUID> {
private UUID id;
@OneToMany(mappedBy = "grant")
private Set<DMP> dmps;
// @OneToMany(mappedBy = "grant")
// private Set<DMP> dmps;
@Column(name = "\"Label\"")
private String label;
@ -229,12 +229,12 @@ public class Grant implements DataEntity<Grant, UUID> {
this.definition = definition;
}
public Set<DMP> getDmps() {
return dmps;
}
public void setDmps(Set<DMP> dmps) {
this.dmps = dmps;
}
// public Set<DMP> getDmps() {
// return dmps;
// }
// public void setDmps(Set<DMP> dmps) {
// this.dmps = dmps;
// }
public UserInfo getCreationUser() {
return creationUser;
@ -271,7 +271,7 @@ public class Grant implements DataEntity<Grant, UUID> {
this.abbreviation = entity.getAbbreviation();
this.created = entity.getCreated();
this.definition = entity.getDefinition();
this.dmps = entity.getDmps();
// this.dmps = entity.getDmps();
this.startdate = entity.getStartdate();
this.enddate = entity.getEnddate();
this.modified = new Date();
@ -289,8 +289,8 @@ public class Grant implements DataEntity<Grant, UUID> {
public Grant 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(Arrays.asList(x), fields, currentBase + "dmps")).collect(Collectors.toSet());
// if (fields.contains(currentBase + "dmps"))
// this.dmps = tuple.stream().map(x -> new DMP().buildFromTuple(Arrays.asList(x), fields, currentBase + "dmps")).collect(Collectors.toSet());
if (fields.contains(currentBase + "creationUser"))
this.creationUser = tuple.stream().map(x -> new UserInfo().buildFromTuple(Arrays.asList(x), fields, currentBase + "creationUser")).collect(Collectors.toList()).get(0);
return this;

View File

@ -24,9 +24,9 @@ public class Invitation implements DataEntity<Invitation, UUID> {
@JoinColumn(name = "\"CreationUser\"", nullable = false)
private UserInfo user;
@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "\"Dmp\"", nullable = false)
private DMP dmp;
// @OneToOne(fetch = FetchType.EAGER)
// @JoinColumn(name = "\"Dmp\"", nullable = false)
// private DMP dmp;
@Column(name = "\"Token\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID token;
@ -61,13 +61,13 @@ public class Invitation implements DataEntity<Invitation, UUID> {
this.user = user;
}
public DMP getDmp() {
return dmp;
}
public void setDmp(DMP dmp) {
this.dmp = dmp;
}
// public DMP getDmp() {
// return dmp;
// }
//
// public void setDmp(DMP dmp) {
// this.dmp = dmp;
// }
public UUID getToken() {
return token;

View File

@ -12,13 +12,13 @@ import java.util.Set;
import java.util.UUID;
@Entity
@Table(name = "\"Organisation\"")
@NamedEntityGraphs({
@NamedEntityGraph(
name = "organisationRecentActivity",
attributeNodes = {@NamedAttributeNode(value = "dmps")}
)
})
//@Table(name = "\"Organisation\"")
//@NamedEntityGraphs({
// @NamedEntityGraph(
// name = "organisationRecentActivity",
// attributeNodes = {@NamedAttributeNode(value = "dmps")}
// )
//})
public class Organisation implements Serializable, DataEntity<Organisation,UUID> {
@Id
@ -41,12 +41,12 @@ public class Organisation implements Serializable, DataEntity<Organisation,UUID>
@Column(name = "\"Definition\"", nullable = true)
private String definition;
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "\"DMPOrganisation\"",
joinColumns = {@JoinColumn(name = "\"Organisation\"", referencedColumnName = "\"ID\"")},
inverseJoinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")}
)
private Set<DMP> dmps;
// @OneToMany(fetch = FetchType.LAZY)
// @JoinTable(name = "\"DMPOrganisation\"",
// joinColumns = {@JoinColumn(name = "\"Organisation\"", referencedColumnName = "\"ID\"")},
// inverseJoinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")}
// )
// private Set<DMP> dmps;
@Column(name = "\"Status\"", nullable = false)
private Short status;
@ -123,12 +123,12 @@ public class Organisation implements Serializable, DataEntity<Organisation,UUID>
this.definition = definition;
}
public Set<DMP> getDmps() {
return dmps;
}
public void setDmps(Set<DMP> dmps) {
this.dmps = dmps;
}
// public Set<DMP> getDmps() {
// return dmps;
// }
// public void setDmps(Set<DMP> dmps) {
// this.dmps = dmps;
// }
@Override
public void update(Organisation entity) {

View File

@ -70,8 +70,8 @@ public class Project implements DataEntity<Project, UUID> {
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
@OneToMany(mappedBy = "project")
private Set<DMP> dmps;
// @OneToMany(mappedBy = "project")
// private Set<DMP> dmps;
@Column(name = "\"Label\"")
private String label;
@ -131,12 +131,12 @@ public class Project implements DataEntity<Project, UUID> {
this.id = id;
}
public Set<DMP> getDmps() {
return dmps;
}
public void setDmps(Set<DMP> dmps) {
this.dmps = dmps;
}
// public Set<DMP> getDmps() {
// return dmps;
// }
// public void setDmps(Set<DMP> dmps) {
// this.dmps = dmps;
// }
public String getLabel() {
return label;
@ -243,7 +243,7 @@ public class Project implements DataEntity<Project, UUID> {
this.abbreviation = entity.getAbbreviation();
this.created = entity.getCreated();
this.definition = entity.getDefinition();
this.dmps = entity.getDmps();
// this.dmps = entity.getDmps();
this.startdate = entity.getStartdate();
this.enddate = entity.getEnddate();
this.modified = new Date();
@ -258,7 +258,7 @@ public class Project implements DataEntity<Project, UUID> {
project.setAbbreviation(grant.getAbbreviation());
project.setCreated(new Date());
project.setDefinition(grant.getDefinition());
project.setDmps(grant.getDmps());
// project.setDmps(grant.getDmps());
project.setStartdate(grant.getStartdate());
project.setEnddate(grant.getEnddate());
project.setModified(new Date());
@ -279,8 +279,8 @@ public class Project implements DataEntity<Project, UUID> {
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(Arrays.asList(x), fields, currentBase + "dmps")).collect(Collectors.toSet());
// if (fields.contains(currentBase + "dmps"))
// this.dmps = tuple.stream().map(x -> new DMP().buildFromTuple(Arrays.asList(x), fields, currentBase + "dmps")).collect(Collectors.toSet());
if (fields.contains(currentBase + "creationUser"))
this.creationUser = tuple.stream().map(x -> new UserInfo().buildFromTuple(Arrays.asList(x), fields, currentBase + "creationUser")).collect(Collectors.toList()).get(0);
return this;

View File

@ -36,12 +36,12 @@ public class Researcher implements DataEntity<Researcher, UUID> {
private String reference;
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "\"DMPResearcher\"",
joinColumns = {@JoinColumn(name = "\"Researcher\"", referencedColumnName = "\"ID\"")},
inverseJoinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")}
)
private Set<DMP> dMPs;
// @OneToMany(fetch = FetchType.LAZY)
// @JoinTable(name = "\"DMPResearcher\"",
// joinColumns = {@JoinColumn(name = "\"Researcher\"", referencedColumnName = "\"ID\"")},
// inverseJoinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")}
// )
// private Set<DMP> dMPs;
@Column(name = "\"Status\"", nullable = false)
@ -123,12 +123,12 @@ public class Researcher implements DataEntity<Researcher, UUID> {
this.definition = definition;
}
public Set<DMP> getdMPs() {
return dMPs;
}
public void setdMPs(Set<DMP> dMPs) {
this.dMPs = dMPs;
}
// public Set<DMP> getdMPs() {
// return dMPs;
// }
// public void setdMPs(Set<DMP> dMPs) {
// this.dMPs = dMPs;
// }
public UserInfo getCreationUser() {
return creationUser;

View File

@ -1,113 +0,0 @@
package eu.eudat.data.old;
import eu.eudat.data.old.helpers.EntityBinder;
import eu.eudat.data.old.queryableentity.DataEntity;
import jakarta.persistence.*;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
@Entity
@Table(name = "\"UserDMP\"")
public class UserDMP implements DataEntity<UserDMP, UUID> {
public enum UserDMPRoles {
OWNER(0), USER(1);
private Integer value;
private UserDMPRoles(Integer value) {
this.value = value;
}
public Integer getValue() {
return value;
}
public static List<Integer> getAllValues() {
List<Integer> list = new LinkedList<>();
for (Enum en : UserDMP.UserDMPRoles.values()) {
list.add(((UserDMPRoles) en).value);
}
return list;
}
public static UserDMPRoles fromInteger(Integer value) {
switch (value) {
case 0:
return OWNER;
case 1:
return USER;
default:
throw new RuntimeException("Unsupported User Dmp Role Message Code");
}
}
}
@Id
@GeneratedValue
@Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "usr")
private UserInfo user;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "dmp")
private DMP dmp;
@Column(name = "role")
private Integer role;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public UserInfo getUser() {
return user;
}
public void setUser(UserInfo user) {
this.user = user;
}
public DMP getDmp() {
return dmp;
}
public void setDmp(DMP dmp) {
this.dmp = dmp;
}
public Integer getRole() {
return role;
}
public void setRole(Integer role) {
this.role = role;
}
@Override
public void update(UserDMP entity) {
this.role = entity.getRole();
}
@Override
public UUID getKeys() {
return this.id;
}
@Override
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

@ -66,12 +66,12 @@ public class UserInfo implements DataEntity<UserInfo, UUID> {
private String additionalinfo;
public final static String _additionalinfo = "additionalinfo";
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "\"UserDMP\"",
joinColumns = {@JoinColumn(name = "usr", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "dmp", referencedColumnName = "\"ID\"")}
)
private Set<DMP> dmps;
// @OneToMany(fetch = FetchType.LAZY)
// @JoinTable(name = "\"UserDMP\"",
// joinColumns = {@JoinColumn(name = "usr", referencedColumnName = "id")},
// inverseJoinColumns = {@JoinColumn(name = "dmp", referencedColumnName = "\"ID\"")}
// )
// private Set<DMP> dmps;
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "Id")
@ -86,13 +86,13 @@ public class UserInfo implements DataEntity<UserInfo, UUID> {
@OneToMany(mappedBy = "userId", fetch = FetchType.LAZY)
private Set<Notification> notifications = new HashSet<>();
public Set<DMP> getDmps() {
return dmps;
}
public void setDmps(Set<DMP> dmps) {
this.dmps = dmps;
}
// public Set<DMP> getDmps() {
// return dmps;
// }
//
// public void setDmps(Set<DMP> dmps) {
// this.dmps = dmps;
// }
public UUID getId() {
return id;

View File

@ -1,8 +1,10 @@
package eu.eudat.model;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.old.queryableentity.DataEntity;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
public class DmpDescriptionTemplate{
@ -90,5 +92,4 @@ public class DmpDescriptionTemplate {
public void setIsActive(IsActive isActive) {
this.isActive = isActive;
}
}

View File

@ -3,6 +3,8 @@ package eu.eudat.model.mapper.deposit;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.DmpUserEntity;
import eu.eudat.data.old.*;
import eu.eudat.depositinterface.models.*;
import eu.eudat.commons.types.xml.XmlBuilder;
@ -28,27 +30,27 @@ public class DMPToDepositMapper {
private static final ObjectMapper mapper = new ObjectMapper();
@Transactional
public static DMPDepositModel fromDMP(DMP entity, FileEnvelope pdfFile, FileEnvelope jsonFile, File supportingFilesZip, String previousDOI) {
public static DMPDepositModel fromDMP(DmpEntity entity, FileEnvelope pdfFile, FileEnvelope jsonFile, File supportingFilesZip, String previousDOI) {
DMPDepositModel deposit = new DMPDepositModel();
deposit.setId(entity.getId());
deposit.setVersion(entity.getVersion());
deposit.setLabel(entity.getLabel());
deposit.setDescription(entity.getDescription());
deposit.setPublic(entity.isPublic());
deposit.setDatasets(entity.getDataset().stream().map(DMPToDepositMapper::fromDataset).collect(Collectors.toList()));
deposit.setUsers(entity.getUsers().stream().map(DMPToDepositMapper::fromUserDMP).collect(Collectors.toSet()));
deposit.setOrganisations(entity.getOrganisations().stream().map(DMPToDepositMapper::fromOrganisation).collect(Collectors.toSet()));
deposit.setResearchers(entity.getResearchers().stream().map(DMPToDepositMapper::fromResearcher).collect(Collectors.toSet()));
if (entity.getGrant() != null) {
deposit.setGrant(fromGrant(entity.getGrant()));
}
deposit.setPdfFile(pdfFile);
deposit.setRdaJsonFile(jsonFile);
deposit.setSupportingFilesZip(supportingFilesZip);
deposit.setPreviousDOI(previousDOI);
deposit.setExtraProperties(entity.getExtraProperties());
// deposit.setId(entity.getId());
// deposit.setVersion(entity.getVersion());
// deposit.setLabel(entity.getLabel());
// deposit.setDescription(entity.getDescription());
// deposit.setPublic(entity.isPublic());
// deposit.setDatasets(entity.getDataset().stream().map(DMPToDepositMapper::fromDataset).collect(Collectors.toList()));
// deposit.setUsers(entity.getUsers().stream().map(DMPToDepositMapper::fromUserDMP).collect(Collectors.toSet()));
// deposit.setOrganisations(entity.getOrganisations().stream().map(DMPToDepositMapper::fromOrganisation).collect(Collectors.toSet()));
// deposit.setResearchers(entity.getResearchers().stream().map(DMPToDepositMapper::fromResearcher).collect(Collectors.toSet()));
// if (entity.getGrant() != null) {
// deposit.setGrant(fromGrant(entity.getGrant()));
// }
//
// deposit.setPdfFile(pdfFile);
// deposit.setRdaJsonFile(jsonFile);
// deposit.setSupportingFilesZip(supportingFilesZip);
// deposit.setPreviousDOI(previousDOI);
//
// deposit.setExtraProperties(entity.getExtraProperties());
return deposit;
}
@ -118,12 +120,12 @@ public class DMPToDepositMapper {
return deposit;
}
private static UserDMPDepositModel fromUserDMP(UserDMP entity){
UserDMPDepositModel deposit = new UserDMPDepositModel();
deposit.setUser(fromUserInfo(entity.getUser()));
deposit.setRole(entity.getRole());
return deposit;
}
// private static UserDMPDepositModel fromUserDMP(DmpUserEntity entity){
// UserDMPDepositModel deposit = new UserDMPDepositModel();
// deposit.setUser(fromUserInfo(entity.getUser()));
// deposit.setRole(entity.getRole().getValue().intValue());
// return deposit;
// }
private static UserInfoDepositModel fromUserInfo(UserInfo entity){
UserInfoDepositModel deposit = new UserInfoDepositModel();

View File

@ -5,12 +5,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.types.xml.XmlBuilder;
import eu.eudat.data.*;
import eu.eudat.data.old.UserDMP;
import eu.eudat.data.old.UserInfo;
import eu.eudat.depositinterface.models.*;
import eu.eudat.query.DescriptionQuery;
import eu.eudat.query.DescriptionTemplateQuery;
import eu.eudat.query.DmpDescriptionTemplateQuery;
import eu.eudat.query.DmpUserQuery;
import gr.cite.tools.data.query.QueryFactory;
import jakarta.persistence.EntityManager;
import jakarta.persistence.criteria.*;
@ -49,7 +49,7 @@ public class DmpEntityDepositMapper {
public DMPDepositModel toDeposit(DmpEntity dmpEntity, File zip, FileEnvelope pdf, FileEnvelope json, String previousDOI) {
DMPDepositModel model = new DMPDepositModel();
List<DescriptionEntity> desciptions = this.getDescriptions(dmpEntity.getId());
List<UserDMP> users = getUsers(dmpEntity.getId());
List<DmpUserEntity> users = getUsers(dmpEntity.getId());
model.setId(dmpEntity.getId());
model.setLabel(dmpEntity.getLabel());
model.setDescription(dmpEntity.getDescription());
@ -142,21 +142,17 @@ public class DmpEntityDepositMapper {
return deposit;
}
private List<UserDMP> getUsers(UUID dmpId) {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<UserDMP> query = builder.createQuery(UserDMP.class);
Root<UserDMP> root = query.from(UserDMP.class);
Join<UserInfo, UserDMP> join = root.join("user").join("id");
query = query.multiselect(root.get("user"), root.get("role"));
return entityManager.createQuery(query).getResultList();
private List<DmpUserEntity> getUsers(UUID dmpId) {
return this.queryFactory.query(DmpUserQuery.class).userIds(dmpId).collect();
}
private UserDMPDepositModel toUserDeposit(UserDMP user) {
private UserDMPDepositModel toUserDeposit(DmpUserEntity user) {
UserDMPDepositModel userDMPDepositModel = new UserDMPDepositModel();
userDMPDepositModel.setUser(new UserInfoDepositModel());
userDMPDepositModel.getUser().setName(user.getUser().getName());
userDMPDepositModel.getUser().setEmail(user.getUser().getEmail());
userDMPDepositModel.setRole(user.getRole());
UserInfo userInfo = this.entityManager.find(UserInfo.class, user.getUser());
userDMPDepositModel.getUser().setName(userInfo.getName());
userDMPDepositModel.getUser().setEmail(userInfo.getEmail());
userDMPDepositModel.setRole(user.getRole().getValue().intValue());
return userDMPDepositModel;
}

View File

@ -5,7 +5,6 @@ import eu.eudat.commons.enums.EntityType;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.EntityDoiEntity;
import eu.eudat.data.old.DMP;
import eu.eudat.model.EntityDoi;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.query.FieldResolver;

View File

@ -1,14 +1,14 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DmpBlueprintEntity;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.old.Grant;
import java.util.Date;
import java.util.List;
import java.util.UUID;
public class DataManagementPlanCriteria extends Criteria<DMP> {
public class DataManagementPlanCriteria extends Criteria<DmpEntity> {
private Date periodStart;
private Date periodEnd;
private DmpBlueprintEntity profile;

View File

@ -1,12 +1,12 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DmpEntity;
import eu.eudat.types.grant.GrantStateType;
import java.util.List;
import java.util.UUID;
public class DataManagementPlanPublicCriteria extends Criteria<DMP> {
public class DataManagementPlanPublicCriteria extends Criteria<DmpEntity> {
private GrantStateType grantStatus;
private List<UUID> grants;
public List<UUID> datasetProfile;

View File

@ -1,10 +1,10 @@
package eu.eudat.data.dao.criteria;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.old.UserInfo;
public class DatasetWizardUserDmpCriteria extends Criteria<DMP> {
public class DatasetWizardUserDmpCriteria extends Criteria<DmpEntity> {
private UserInfo userInfo;
public UserInfo getUserInfo() {

View File

@ -1,21 +1,21 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
import eu.eudat.data.dao.criteria.DatasetWizardUserDmpCriteria;
import eu.eudat.data.old.DMP;
import eu.eudat.data.old.UserInfo;
import eu.eudat.queryable.QueryableList;
import java.util.List;
import java.util.UUID;
public interface DMPDao extends DatabaseAccessLayer<DMP, UUID> {
public interface DMPDao extends DatabaseAccessLayer<DmpEntity, UUID> {
QueryableList<DMP> getWithCriteria(DataManagementPlanCriteria criteria);
QueryableList<DmpEntity> getWithCriteria(DataManagementPlanCriteria criteria);
QueryableList<DMP> getUserDmps(DatasetWizardUserDmpCriteria datasetWizardAutocompleteRequest, UserInfo userInfo);
QueryableList<DmpEntity> getUserDmps(DatasetWizardUserDmpCriteria datasetWizardAutocompleteRequest, UserInfo userInfo);
QueryableList<DMP> getAuthenticated(QueryableList<DMP> query, UUID principalId, List<Integer> roles);
QueryableList<DmpEntity> getAuthenticated(QueryableList<DmpEntity> query, UUID principalId, List<Integer> roles);
}

View File

@ -1,10 +1,12 @@
package eu.eudat.data.dao.entities;
import eu.eudat.commons.enums.DmpStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
import eu.eudat.data.dao.criteria.DatasetWizardUserDmpCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.old.DMP;
import eu.eudat.data.old.UserInfo;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.types.FieldSelectionType;
@ -25,16 +27,16 @@ import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("dMPDao")
public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
public class DMPDaoImpl extends DatabaseAccess<DmpEntity> implements DMPDao {
@Autowired
public DMPDaoImpl(DatabaseService<DMP> databaseService) {
public DMPDaoImpl(DatabaseService<DmpEntity> databaseService) {
super(databaseService);
}
@Override
public QueryableList<DMP> getWithCriteria(DataManagementPlanCriteria criteria) {
QueryableList<DMP> query = getDatabaseService().getQueryable(DMP.getHints(), DMP.class);
public QueryableList<DmpEntity> getWithCriteria(DataManagementPlanCriteria criteria) {
QueryableList<DmpEntity> query = getDatabaseService().getQueryable(DmpEntity.class);
if (criteria.getLike() != null && !criteria.getLike().isEmpty())
query.where((builder, root) -> builder.or(
builder.like(builder.upper(root.get("label")), "%" + criteria.getLike().toUpperCase() + "%"),
@ -51,14 +53,14 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("version"),
query.subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.and(
builder1.equal(externalRoot.get("groupId"), nestedRoot.get("groupId")),
builder1.notEqual(nestedRoot.get("status"), DMP.DMPStatus.DELETED.getValue())), Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "version")), Integer.class)));
builder1.notEqual(nestedRoot.get("isActive"), IsActive.Inactive.getValue())), Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "version")), Integer.class)));
if (criteria.getGroupIds() != null && !criteria.getGroupIds().isEmpty())
query.where((builder, root) -> root.get("groupId").in(criteria.getGroupIds()));
if (criteria.getStatus() != null) {
if (criteria.getStatus() == DMP.DMPStatus.FINALISED.getValue()) {
query.where((builder, root) -> builder.equal(root.get("status"), DMP.DMPStatus.FINALISED.getValue()));
} else if (criteria.getStatus() == DMP.DMPStatus.ACTIVE.getValue()) {
query.where((builder, root) -> builder.equal(root.get("status"), DMP.DMPStatus.ACTIVE.getValue()));
if (criteria.getStatus() == DmpStatus.Finalized.getValue().intValue()) {
query.where((builder, root) -> builder.equal(root.get("status"), DmpStatus.Finalized.getValue()));
} else if (criteria.getStatus() == DmpStatus.Draft.getValue().intValue()) {
query.where((builder, root) -> builder.equal(root.get("status"), DmpStatus.Draft.getValue()));
}
}
if (criteria.getIsPublic()) {
@ -92,11 +94,11 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
if (criteria.hasDoi()) {
query.where((builder, root) -> builder.not(builder.isNull(root.join("dois").get("id"))));
}
query.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()));
query.where((builder, root) -> builder.notEqual(root.get("isActive"), IsActive.Inactive));
return query;
}
public QueryableList<DMP> getAuthenticated(QueryableList<DMP> query, UUID principal, List<Integer> roles) {
public QueryableList<DmpEntity> getAuthenticated(QueryableList<DmpEntity> query, UUID principal, List<Integer> roles) {
if (roles != null && !roles.isEmpty()) {
query.where((builder, root) -> {
Join userJoin = root.join("users", JoinType.LEFT);
@ -111,18 +113,18 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
@Override
@Transactional
public DMP createOrUpdate(DMP item) {
return this.getDatabaseService().createOrUpdate(item, DMP.class);
public DmpEntity createOrUpdate(DmpEntity item) {
return this.getDatabaseService().createOrUpdate(item, DmpEntity.class);
}
@Override
public DMP find(UUID id) throws InvalidApplicationException {
return getDatabaseService().getQueryable(DMP.class).where((builder, root) -> builder.equal((root.get("id")), id)).getSingle();
public DmpEntity find(UUID id) throws InvalidApplicationException {
return getDatabaseService().getQueryable(DmpEntity.class).where((builder, root) -> builder.equal((root.get("id")), id)).getSingle();
}
@Override
public QueryableList<DMP> getUserDmps(DatasetWizardUserDmpCriteria datasetWizardUserDmpCriteria, UserInfo userInfo) {
QueryableList<DMP> query = getDatabaseService().getQueryable(DMP.class).where((builder, root) -> builder.or(builder.equal(root.get("creator"), userInfo), builder.isMember(userInfo, root.get("users"))));
public QueryableList<DmpEntity> getUserDmps(DatasetWizardUserDmpCriteria datasetWizardUserDmpCriteria, UserInfo userInfo) {
QueryableList<DmpEntity> query = getDatabaseService().getQueryable(DmpEntity.class).where((builder, root) -> builder.or(builder.equal(root.get("creator"), userInfo), builder.isMember(userInfo, root.get("users"))));
if (datasetWizardUserDmpCriteria.getLike() != null && !datasetWizardUserDmpCriteria.getLike().isEmpty()) {
query.where((builder, root) -> builder.like(root.get("label"), "%" + datasetWizardUserDmpCriteria.getLike() + "%"));
}
@ -130,23 +132,23 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
}
@Override
public void delete(DMP item) {
public void delete(DmpEntity item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<DMP> asQueryable() {
return this.getDatabaseService().getQueryable(DMP.class);
public QueryableList<DmpEntity> asQueryable() {
return this.getDatabaseService().getQueryable(DmpEntity.class);
}
@Async
@Override
public CompletableFuture<DMP> createOrUpdateAsync(DMP item) {
public CompletableFuture<DmpEntity> createOrUpdateAsync(DmpEntity item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public DMP find(UUID id, String hint) {
public DmpEntity find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -2,10 +2,10 @@ package eu.eudat.data.dao.entities;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.DatasetCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.old.UserInfo;
import eu.eudat.queryable.QueryableList;
@ -52,7 +52,7 @@ public class DatasetDaoImpl extends DatabaseAccess<DescriptionEntity> implements
if (criteria.getPeriodStart() != null)
query.where((builder, root) -> builder.greaterThan(root.get("created"), criteria.getPeriodStart()));
if (!criteria.getAllVersions())
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"), query.subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.and(builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), builder1.notEqual(nestedRoot.get("dmp").get("status"), DMP.DMPStatus.DELETED.getValue())), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), Integer.class)));
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"), query.subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.and(builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), builder1.notEqual(nestedRoot.get("dmp").get("isActive"), IsActive.Inactive.getValue())), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), Integer.class)));
if (criteria.getGroupIds() != null && !criteria.getGroupIds().isEmpty())
query.where((builder, root) -> root.get("dmp").get("groupId").in(criteria.getGroupIds()));
if (criteria.getDmpIds() != null && !criteria.getDmpIds().isEmpty())
@ -92,7 +92,7 @@ public class DatasetDaoImpl extends DatabaseAccess<DescriptionEntity> implements
query.where(((builder, root) -> root.get("id").in(ids)));
if (!criteria.getAllVersions())
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"), query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.and(builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), builder1.notEqual(nestedRoot.get("dmp").get("status"), DMP.DMPStatus.DELETED.getValue())), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class)));
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"), query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.and(builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), builder1.notEqual(nestedRoot.get("dmp").get("isActive"), IsActive.Inactive.getValue())), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class)));
return query;
}

View File

@ -1,9 +1,10 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.DmpDescriptionTemplateEntity;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.old.DMPDatasetProfile;
import eu.eudat.model.DmpDescriptionTemplate;
import java.util.UUID;
public interface DmpDatasetProfileDao extends DatabaseAccessLayer<DMPDatasetProfile, UUID> {
public interface DmpDatasetProfileDao extends DatabaseAccessLayer<DmpDescriptionTemplateEntity, UUID> {
}

View File

@ -1,8 +1,9 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.DmpDescriptionTemplateEntity;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.old.DMPDatasetProfile;
import eu.eudat.model.DmpDescriptionTemplate;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
@ -13,40 +14,40 @@ import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Service("dmpDatasetProfileDao")
public class DmpDatasetProfileDaoImpl extends DatabaseAccess<DMPDatasetProfile> implements DmpDatasetProfileDao {
public class DmpDatasetProfileDaoImpl extends DatabaseAccess<DmpDescriptionTemplateEntity> implements DmpDatasetProfileDao {
@Autowired
public DmpDatasetProfileDaoImpl(DatabaseService<DMPDatasetProfile> databaseService) {
public DmpDatasetProfileDaoImpl(DatabaseService<DmpDescriptionTemplateEntity> databaseService) {
super(databaseService);
}
@Override
public DMPDatasetProfile createOrUpdate(DMPDatasetProfile item) {
return this.getDatabaseService().createOrUpdate(item, DMPDatasetProfile.class);
public DmpDescriptionTemplateEntity createOrUpdate(DmpDescriptionTemplateEntity item) {
return this.getDatabaseService().createOrUpdate(item, DmpDescriptionTemplateEntity.class);
}
@Override
@Async
public CompletableFuture<DMPDatasetProfile> createOrUpdateAsync(DMPDatasetProfile item) {
public CompletableFuture<DmpDescriptionTemplateEntity> createOrUpdateAsync(DmpDescriptionTemplateEntity item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public DMPDatasetProfile find(UUID id) throws InvalidApplicationException {
return this.getDatabaseService().getQueryable(DMPDatasetProfile.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
public DmpDescriptionTemplateEntity find(UUID id) throws InvalidApplicationException {
return this.getDatabaseService().getQueryable(DmpDescriptionTemplateEntity.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public DMPDatasetProfile find(UUID id, String hint) {
public DmpDescriptionTemplateEntity find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public void delete(DMPDatasetProfile item) {
public void delete(DmpDescriptionTemplateEntity item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<DMPDatasetProfile> asQueryable() {
return this.getDatabaseService().getQueryable(DMPDatasetProfile.class);
public QueryableList<DmpDescriptionTemplateEntity> asQueryable() {
return this.getDatabaseService().getQueryable(DmpDescriptionTemplateEntity.class);
}
}

View File

@ -1,9 +1,10 @@
package eu.eudat.data.dao.entities;
import eu.eudat.commons.enums.DmpStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.GrantCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.old.DMP;
import eu.eudat.data.old.Grant;
import eu.eudat.data.old.UserInfo;
import eu.eudat.queryable.QueryableList;
@ -51,11 +52,11 @@ public class GrantDaoImpl extends DatabaseAccess<Grant> implements GrantDao {
, builder.isNull(root.get("enddate"))));
}
if (criteria.isPublic()) {
query.where((builder, root) -> builder.equal(root.join("dmps").get("status"), DMP.DMPStatus.FINALISED.getValue())).distinct();
query.where((builder, root) -> builder.equal(root.join("dmps").get("status"), DmpStatus.Finalized.getValue())).distinct();
}
if (criteria.isActive()) {
query.where((builder, root) -> builder.notEqual(root.join("dmps").get("status"), DMP.DMPStatus.DELETED.getValue())).distinct();
query.where((builder, root) -> builder.notEqual(root.join("dmps").get("isActive"), IsActive.Inactive.getValue())).distinct();
}
if (criteria.getFunderId() != null && !criteria.getFunderId().trim().isEmpty())
query.where((builder, root) -> builder.equal(root.get("funder").get("id"), UUID.fromString(criteria.getFunderId())));

View File

@ -1,9 +1,10 @@
package eu.eudat.data.dao.entities;
import eu.eudat.commons.enums.DmpStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.criteria.OrganisationCriteria;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.old.DMP;
import eu.eudat.data.old.Organisation;
import eu.eudat.data.old.UserInfo;
import eu.eudat.queryable.QueryableList;
@ -37,12 +38,12 @@ public class OrganisationDaoImpl extends DatabaseAccess<Organisation> implements
query.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + criteria.getLabelLike().toUpperCase() + "%"));
}
if (criteria.getPublic() != null && criteria.getPublic()) {
query.where((builder, root) -> builder.equal(root.join("dmps", JoinType.LEFT).get("status"), DMP.DMPStatus.FINALISED.getValue()));
query.where((builder, root) -> builder.equal(root.join("dmps", JoinType.LEFT).get("status"), DmpStatus.Finalized.getValue()));
}
}
if (criteria.isActive()) {
query.where((builder, root) -> builder.notEqual(root.join("dmps").get("status"), DMP.DMPStatus.DELETED.getValue())).distinct();
query.where((builder, root) -> builder.notEqual(root.join("dmps").get("isActive"), IsActive.Inactive.getValue())).distinct();
}
return query;

View File

@ -1,12 +1,12 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.DmpUserEntity;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.old.UserDMP;
import java.util.UUID;
/**
* Created by ikalyvas on 2/8/2018.
*/
public interface UserDmpDao extends DatabaseAccessLayer<UserDMP, UUID> {
public interface UserDmpDao extends DatabaseAccessLayer<DmpUserEntity, UUID> {
}

View File

@ -1,8 +1,8 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.DmpUserEntity;
import eu.eudat.data.dao.DatabaseAccess;
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.eudat.data.old.UserDMP;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
@ -16,41 +16,41 @@ import java.util.concurrent.CompletableFuture;
* Created by ikalyvas on 2/8/2018.
*/
@Component("userDmpDao")
public class UserDmpDaoImpl extends DatabaseAccess<UserDMP> implements UserDmpDao {
public class UserDmpDaoImpl extends DatabaseAccess<DmpUserEntity> implements UserDmpDao {
@Autowired
public UserDmpDaoImpl(DatabaseService<UserDMP> databaseService) {
public UserDmpDaoImpl(DatabaseService<DmpUserEntity> databaseService) {
super(databaseService);
}
@Override
public UserDMP createOrUpdate(UserDMP item) {
return this.getDatabaseService().createOrUpdate(item, UserDMP.class);
public DmpUserEntity createOrUpdate(DmpUserEntity item) {
return this.getDatabaseService().createOrUpdate(item, DmpUserEntity.class);
}
@Override
public UserDMP find(UUID id) throws InvalidApplicationException {
return this.getDatabaseService().getQueryable(UserDMP.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingleOrDefault();
public DmpUserEntity find(UUID id) throws InvalidApplicationException {
return this.getDatabaseService().getQueryable(DmpUserEntity.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingleOrDefault();
}
@Override
public void delete(UserDMP item) {
public void delete(DmpUserEntity item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<UserDMP> asQueryable() {
return this.getDatabaseService().getQueryable(UserDMP.class);
public QueryableList<DmpUserEntity> asQueryable() {
return this.getDatabaseService().getQueryable(DmpUserEntity.class);
}
@Async
@Override
public CompletableFuture<UserDMP> createOrUpdateAsync(UserDMP item) {
public CompletableFuture<DmpUserEntity> createOrUpdateAsync(DmpUserEntity item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public UserDMP find(UUID id, String hint) {
public DmpUserEntity find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -1,14 +1,14 @@
package eu.eudat.data.query.items.item.dataset;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.dao.criteria.DatasetWizardUserDmpCriteria;
import eu.eudat.data.old.DMP;
import eu.eudat.data.query.definition.Query;
import eu.eudat.queryable.QueryableList;
public class DatasetWizardAutocompleteRequest extends Query<DatasetWizardUserDmpCriteria, DMP> {
public class DatasetWizardAutocompleteRequest extends Query<DatasetWizardUserDmpCriteria, DmpEntity> {
@Override
public QueryableList<DMP> applyCriteria() {
QueryableList<DMP> query = this.getQuery().where((builder, root) -> builder.or(builder.equal(root.get("creator"), this.getCriteria().getUserInfo()), builder.isMember(this.getCriteria().getUserInfo(), root.get("users"))));
public QueryableList<DmpEntity> applyCriteria() {
QueryableList<DmpEntity> query = this.getQuery().where((builder, root) -> builder.or(builder.equal(root.get("creator"), this.getCriteria().getUserInfo()), builder.isMember(this.getCriteria().getUserInfo(), root.get("users"))));
if (this.getCriteria().getLike() != null && !this.getCriteria().getLike().isEmpty()) {
query.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + this.getCriteria().getLike().toUpperCase() + "%"));
}

View File

@ -1,7 +1,8 @@
package eu.eudat.data.query.items.item.dmp;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
import eu.eudat.data.old.DMP;
import eu.eudat.data.query.definition.Query;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.types.FieldSelectionType;
@ -9,10 +10,10 @@ import eu.eudat.queryable.types.SelectionField;
import java.util.Arrays;
public class DataManagementPlanCriteriaRequest extends Query<DataManagementPlanCriteria, DMP> {
public class DataManagementPlanCriteriaRequest extends Query<DataManagementPlanCriteria, DmpEntity> {
@Override
public QueryableList<DMP> applyCriteria() {
QueryableList<DMP> query = this.getQuery();
public QueryableList<DmpEntity> applyCriteria() {
QueryableList<DmpEntity> query = this.getQuery();
if (this.getCriteria().getLike() != null && !this.getCriteria().getLike().isEmpty())
query.where((builder, root) -> builder.or(
builder.like(builder.upper(root.get("label")), "%" + this.getCriteria().getLike().toUpperCase() + "%"),
@ -27,7 +28,7 @@ public class DataManagementPlanCriteriaRequest extends Query<DataManagementPlanC
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("version"), query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("groupId"), nestedRoot.get("groupId")), Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "version")), String.class)));
if (this.getCriteria().getGroupIds() != null && !this.getCriteria().getGroupIds().isEmpty())
query.where((builder, root) -> root.get("groupId").in(this.getCriteria().getGroupIds()));
query.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()));
query.where((builder, root) -> builder.notEqual(root.get("isActive"), IsActive.Inactive.getValue()));
return query;
}
}

View File

@ -1,7 +1,8 @@
package eu.eudat.data.query.items.table.dmp;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
import eu.eudat.data.old.DMP;
import eu.eudat.data.query.PaginationService;
import eu.eudat.data.query.definition.TableQuery;
import eu.eudat.queryable.QueryableList;
@ -11,10 +12,10 @@ import eu.eudat.queryable.types.SelectionField;
import java.util.Arrays;
import java.util.UUID;
public class DataManagementPlanTableRequest extends TableQuery<DataManagementPlanCriteria, DMP, UUID> {
public class DataManagementPlanTableRequest extends TableQuery<DataManagementPlanCriteria, DmpEntity, UUID> {
@Override
public QueryableList<DMP> applyCriteria() {
QueryableList<DMP> query = this.getQuery();
public QueryableList<DmpEntity> applyCriteria() {
QueryableList<DmpEntity> query = this.getQuery();
if (this.getCriteria().getLike() != null && !this.getCriteria().getLike().isEmpty())
query.where((builder, root) -> builder.or(
builder.like(builder.upper(root.get("label")), "%" + this.getCriteria().getLike().toUpperCase() + "%"),
@ -29,12 +30,12 @@ public class DataManagementPlanTableRequest extends TableQuery<DataManagementPla
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("version"), query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("groupId"), nestedRoot.get("groupId")), Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "version")), String.class)));
if (this.getCriteria().getGroupIds() != null && !this.getCriteria().getGroupIds().isEmpty())
query.where((builder, root) -> root.get("groupId").in(this.getCriteria().getGroupIds()));
query.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()));
query.where((builder, root) -> builder.notEqual(root.get("isActive"), IsActive.Inactive.getValue()));
return query;
}
@Override
public QueryableList<DMP> applyPaging(QueryableList<DMP> items) {
public QueryableList<DmpEntity> applyPaging(QueryableList<DmpEntity> items) {
return PaginationService.applyPaging(items, this);
}
}

View File

@ -1,7 +1,7 @@
package eu.eudat.data.query.items.table.dmp;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.dao.criteria.DataManagementPlanPublicCriteria;
import eu.eudat.data.old.DMP;
import eu.eudat.data.query.PaginationService;
import eu.eudat.data.query.definition.TableQuery;
import eu.eudat.queryable.QueryableList;
@ -13,10 +13,10 @@ import java.util.Arrays;
import java.util.Date;
import java.util.UUID;
public class DataManagmentPlanPublicTableRequest extends TableQuery<DataManagementPlanPublicCriteria, DMP, UUID> {
public class DataManagmentPlanPublicTableRequest extends TableQuery<DataManagementPlanPublicCriteria, DmpEntity, UUID> {
public QueryableList<DMP> applyCriteria() {
QueryableList<DMP> query = this.getQuery();
public QueryableList<DmpEntity> applyCriteria() {
QueryableList<DmpEntity> query = this.getQuery();
query.where((builder, root) -> builder.equal(root.get("isPublic"), true));
if (this.getCriteria().getLike() != null && !this.getCriteria().getLike().isEmpty())
query.where((builder, root) -> builder.or(
@ -48,7 +48,7 @@ public class DataManagmentPlanPublicTableRequest extends TableQuery<DataManageme
}
@Override
public QueryableList<DMP> applyPaging(QueryableList<DMP> items) {
public QueryableList<DmpEntity> applyPaging(QueryableList<DmpEntity> items) {
return PaginationService.applyPaging(items, this);
}
}

View File

@ -1,7 +1,7 @@
package eu.eudat.query;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.old.Grant;
import eu.eudat.data.old.UserInfo;
@ -17,7 +17,7 @@ import java.util.Date;
import java.util.List;
import java.util.UUID;
public class DMPQuery extends Query<DMP, UUID> {
public class DMPQuery extends Query<DmpEntity, UUID> {
private UUID id;
private UUID groupId;
private String label;
@ -29,11 +29,11 @@ public class DMPQuery extends Query<DMP, UUID> {
private Date created;
private Date modified;
public DMPQuery(DatabaseAccessLayer<DMP, UUID> databaseAccessLayer) {
public DMPQuery(DatabaseAccessLayer<DmpEntity, UUID> databaseAccessLayer) {
super(databaseAccessLayer);
}
public DMPQuery(DatabaseAccessLayer<DMP, UUID> databaseAccessLayer, List<String> selectionFields) {
public DMPQuery(DatabaseAccessLayer<DmpEntity, UUID> databaseAccessLayer, List<String> selectionFields) {
super(databaseAccessLayer, selectionFields);
}
@ -117,8 +117,8 @@ public class DMPQuery extends Query<DMP, UUID> {
this.datasetQuery = datasetQuery;
}
public QueryableList<DMP> getQuery() throws InvalidApplicationException {
QueryableList<DMP> query = this.databaseAccessLayer.asQueryable();
public QueryableList<DmpEntity> getQuery() throws InvalidApplicationException {
QueryableList<DmpEntity> query = this.databaseAccessLayer.asQueryable();
if (this.id != null) {
query.where((builder, root) -> builder.equal(root.get("id"), this.id));
}

View File

@ -1,7 +1,7 @@
package eu.eudat.query;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.types.FieldSelectionType;
@ -59,7 +59,7 @@ public class DatasetQuery extends Query<DescriptionEntity, UUID> {
query.where((builder, root) -> builder.equal(root.get("id"), this.id));
}
if (this.dmpQuery != null) {
Subquery<DMP> dmpSubQuery = this.dmpQuery.getQuery().query(Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "id")));
Subquery<DmpEntity> dmpSubQuery = this.dmpQuery.getQuery().query(Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "id")));
query.where((builder, root) -> root.get("dmp").get("id").in(dmpSubQuery));
}
return query;

View File

@ -4,9 +4,9 @@ package eu.eudat.controllers;
import eu.eudat.authorization.Permission;
import eu.eudat.configurations.dynamicgrant.DynamicGrantConfiguration;
import eu.eudat.criteria.DMPCriteria;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.dao.criteria.DynamicFieldsCriteria;
import eu.eudat.data.dao.criteria.RequestItem;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem;
import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest;
@ -249,7 +249,7 @@ public class DMPs extends BaseController {
ResponseEntity<ResponseItem<eu.eudat.models.data.dmp.DataManagementPlan>> createOrUpdate(@RequestBody eu.eudat.models.data.dmp.DataManagementPlanEditorModel dataManagementPlanEditorModel) throws Exception {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
DMP dmp = this.dataManagementPlanManager.createOrUpdate(dataManagementPlanEditorModel);
DmpEntity dmp = this.dataManagementPlanManager.createOrUpdate(dataManagementPlanEditorModel);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.data.dmp.DataManagementPlan>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created").payload(new eu.eudat.models.data.dmp.DataManagementPlan().fromDataModel(dmp)));
}
@ -259,7 +259,7 @@ public class DMPs extends BaseController {
ResponseEntity<ResponseItem<UUID>> createOrUpdateWithDatasets(@RequestBody eu.eudat.models.data.dmp.DataManagementPlanEditorModel dataManagementPlanEditorModel) throws Exception {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
DMP dmp = this.dataManagementPlanManager.createOrUpdateWithDatasets(dataManagementPlanEditorModel);
DmpEntity dmp = this.dataManagementPlanManager.createOrUpdateWithDatasets(dataManagementPlanEditorModel);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UUID>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created").payload(dmp.getId()));
}
@ -286,14 +286,14 @@ 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) {
ResponseEntity<ResponseItem<DmpEntity>> delete(@PathVariable UUID id) {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
try {
this.dataManagementPlanManager.delete(id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Deleted Datamanagement Plan"));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DmpEntity>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Deleted Datamanagement Plan"));
} catch (DMPWithDatasetsDeleteException | IOException | InvalidApplicationException exception) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DmpEntity>().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage()));
}
}
@ -313,55 +313,55 @@ public class DMPs extends BaseController {
}
@RequestMapping(method = RequestMethod.GET, value = {"/makepublic/{id}"})
public ResponseEntity<ResponseItem<DMP>> makePublic(@PathVariable String id) {
public ResponseEntity<ResponseItem<DmpEntity>> makePublic(@PathVariable String id) {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
try {
this.dataManagementPlanManager.makePublic(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Data Datamanagement Plan made public."));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DmpEntity>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Data Datamanagement Plan made public."));
} catch (Exception e) {
logger.error(e.getMessage(), e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to make Data Management Plan public."));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DmpEntity>().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to make Data Management Plan public."));
}
}
@RequestMapping(method = RequestMethod.POST, value = {"/finalize/{id}"})
public ResponseEntity<ResponseItem<DMP>> makeFinalize(@PathVariable String id, @RequestBody DatasetsToBeFinalized datasetsToBeFinalized) {
public ResponseEntity<ResponseItem<DmpEntity>> makeFinalize(@PathVariable String id, @RequestBody DatasetsToBeFinalized datasetsToBeFinalized) {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
try {
this.dataManagementPlanManager.makeFinalize(UUID.fromString(id), datasetsToBeFinalized);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Data Datamanagement Plan made finalized."));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DmpEntity>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Data Datamanagement Plan made finalized."));
} catch (Exception e) {
logger.error(e.getMessage(), e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to finalize Data Management Plan."));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DmpEntity>().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to finalize Data Management Plan."));
}
}
@RequestMapping(method = RequestMethod.POST, value = {"/unfinalize/{id}"})
public ResponseEntity<ResponseItem<DMP>> undoFinalize(@PathVariable String id) {
public ResponseEntity<ResponseItem<DmpEntity>> undoFinalize(@PathVariable String id) {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
try {
this.dataManagementPlanManager.undoFinalize(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Data Datamanagement Plan made active."));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DmpEntity>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Data Datamanagement Plan made active."));
} catch (Exception e) {
logger.error(e.getMessage(), e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to unfinalize the Data Management Plan."));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DmpEntity>().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to unfinalize the Data Management Plan."));
}
}
@RequestMapping(method = RequestMethod.POST, value = {"/updateusers/{id}"})
public ResponseEntity<ResponseItem<DMP>> updateUsers(@PathVariable String id, @RequestBody List<UserInfoListingModel> users) {
public ResponseEntity<ResponseItem<DmpEntity>> updateUsers(@PathVariable String id, @RequestBody List<UserInfoListingModel> users) {
this.authorizationService.authorizeForce(Permission.AuthenticatedRole);
try {
this.dataManagementPlanManager.updateUsers(UUID.fromString(id), users);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Updated Colaborators for Data Datamanagement Plan."));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DmpEntity>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Updated Colaborators for Data Datamanagement Plan."));
} catch (Exception e) {
logger.error(e.getMessage(), e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to update the users of Data Management Plan."));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DmpEntity>().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to update the users of Data Management Plan."));
}
}

View File

@ -3,6 +3,7 @@ package eu.eudat.controllers;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission;
import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.enums.DmpAccessType;
import eu.eudat.commons.enums.FieldType;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.scope.user.UserScope;
@ -11,7 +12,7 @@ import eu.eudat.commons.types.descriptiontemplate.FieldEntity;
import eu.eudat.commons.types.descriptiontemplate.fielddata.UploadDataEntity;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.old.FileUpload;
import eu.eudat.exceptions.security.UnauthorisedException;
import eu.eudat.logic.managers.DatasetProfileManager;
@ -145,11 +146,14 @@ public class FileController {
throw new NoSuchElementException("No dataset with id " + fileUpload.getEntityId() + " found. This dataset was related to the file with id " + id);
}
DMP dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId());
DmpEntity dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId());
if (!dmp.isPublic() && dmp.getUsers()
.stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId()))
.collect(Collectors.toList()).size() == 0)
if (!dmp.getAccessType().equals(DmpAccessType.Public)
//TODO
// && dmp.getUsers()
// .stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId()))
// .collect(Collectors.toList()).size() == 0
)
throw new UnauthorisedException();
}

View File

@ -4,7 +4,7 @@ package eu.eudat.controllers;
import eu.eudat.authorization.Permission;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.old.Funder;
import eu.eudat.data.old.Project;
import eu.eudat.data.old.Grant;
@ -90,7 +90,7 @@ public class QuickWizardController extends BaseController {
//Create Dmp
DataManagementPlan dataManagementPlan = quickWizard.getDmp().toDataDmp(grantEntity, projectEntity, userScope);
DMP dmpEntity = this.quickWizardManager.createOrUpdate(dataManagementPlan, funderEntity);
DmpEntity dmpEntity = this.quickWizardManager.createOrUpdate(dataManagementPlan, funderEntity);
//Create Datasets
quickWizard.getDmp().setId(dmpEntity.getId());

View File

@ -1,8 +1,8 @@
package eu.eudat.logic.builders.entity;
import eu.eudat.data.CredentialEntity;
import eu.eudat.data.DmpEntity;
import eu.eudat.logic.builders.Builder;
import eu.eudat.data.old.DMP;
import eu.eudat.data.old.UserInfo;
import eu.eudat.data.old.UserRole;
@ -34,7 +34,7 @@ public class UserInfoBuilder extends Builder<UserInfo> {
private String additionalinfo;
private Set<DMP> dmps;
private Set<DmpEntity> dmps;
private Set<CredentialEntity> credentials = new HashSet<>();
@ -87,7 +87,7 @@ public class UserInfoBuilder extends Builder<UserInfo> {
return this;
}
public UserInfoBuilder dmps(Set<DMP> dmps) {
public UserInfoBuilder dmps(Set<DmpEntity> dmps) {
this.dmps = dmps;
return this;
}
@ -120,7 +120,7 @@ public class UserInfoBuilder extends Builder<UserInfo> {
userInfo.setAdditionalinfo(additionalinfo);
userInfo.setUserRoles(userRoles);
userInfo.setCredentials(credentials);
userInfo.setDmps(dmps);
// userInfo.setDmps(dmps); //TODO
userInfo.setVerified_email(verified_email);
userInfo.setUserStatus(userStatus);
return userInfo;

View File

@ -3,6 +3,7 @@ package eu.eudat.logic.managers;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
import eu.eudat.data.dao.criteria.DatasetCriteria;
import eu.eudat.data.dao.criteria.GrantCriteria;
@ -11,7 +12,6 @@ import eu.eudat.data.dao.entities.DMPDao;
import eu.eudat.data.dao.entities.DatasetDao;
import eu.eudat.data.dao.entities.GrantDao;
import eu.eudat.data.dao.entities.OrganisationDao;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.old.Grant;
import eu.eudat.data.old.UserInfo;
@ -86,7 +86,7 @@ public class DashBoardManager {
publicCriteria.setOnlyPublic(true);
publicCriteria.setAllVersions(false);
List<DMP> dmps = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(publicCriteria).toList();
List<DmpEntity> dmps = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(publicCriteria).toList();
// DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
OrganisationCriteria organisationCriteria = new OrganisationCriteria();
@ -97,12 +97,12 @@ public class DashBoardManager {
// List<DMP> dmps = databaseRepository.getDmpDao().getWithCriteria(dataManagementPlanCriteria).toList();
long numberOfDatasets = 0;
LinkedList<Grant> grants = new LinkedList<>();
for (DMP dmp : dmps) {
numberOfDatasets = numberOfDatasets + dmp.getDataset().stream()
.filter(item -> item.getStatus() == DescriptionStatus.Finalized).count();
if (dmp.getGrant() != null) {
grants.add(dmp.getGrant());
}
for (DmpEntity dmp : dmps) {
// numberOfDatasets = numberOfDatasets + dmp.getDataset().stream() //TODO
// .filter(item -> item.getStatus() == DescriptionStatus.Finalized).count();
// if (dmp.getGrant() != null) {
// grants.add(dmp.getGrant());
// }
}
statistics.setTotalDataManagementPlanCount((long) dmps.size());
@ -201,7 +201,7 @@ public class DashBoardManager {
.withHint("dmpRecentActivity")
.orderBy((builder, root) -> builder.desc(root.get("modified")))
.take(numberofactivities)
.selectAsync(item -> recentActivityDataBuilder.label(item.getLabel()).timestamp(item.getModified()).id(item.getId().toString()).build())
.selectAsync(item -> recentActivityDataBuilder.label(item.getLabel()).timestamp(Date.from(item.getUpdatedAt())).id(item.getId().toString()).build())
.whenComplete((dmpActivities, throwable) -> activity.setRecentDmpActivities(dmpActivities));
CompletableFuture<List<RecentActivityData>> datasets = datasetRepository.getAuthenticated(datasetRepository.getWithCriteria(datasetCriteria), user, roles).distinct()
@ -311,7 +311,7 @@ public class DashBoardManager {
CompletableFuture<List<SearchBarItem>> publicDmps = dataManagementPlanRepository.asQueryable()
.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%"))
.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()))
.where((builder, root) -> builder.notEqual(root.get("isActive"), IsActive.Inactive))
.where((builder, root) -> builder.equal(root.get("isPublic"), true))
.orderBy((builder, root) -> builder.desc(root.get("modified")))
.selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.DMP.getValue(), true))
@ -329,7 +329,7 @@ public class DashBoardManager {
CompletableFuture<List<SearchBarItem>> dmps = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.asQueryable(), this.userScope.getUserId(), roles)
.withHint("dmpRecentActivity")
.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%"))
.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()))
.where((builder, root) -> builder.notEqual(root.get("isActive"), IsActive.Inactive))
.orderBy((builder, root) -> builder.desc(root.get("modified")))
.selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.DMP.getValue(), false))
.whenComplete((dmpItems, throwable) -> searchBarItems.addAll(dmpItems));

View File

@ -6,11 +6,11 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.authorization.Permission;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.enums.DmpAccessType;
import eu.eudat.commons.enums.DmpStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.data.TagEntity;
import eu.eudat.data.*;
import eu.eudat.data.dao.criteria.*;
import eu.eudat.data.dao.entities.DataRepositoryDao;
import eu.eudat.data.dao.entities.DatasetDao;
@ -300,10 +300,13 @@ public class DatasetManager {
DatasetWizardModel dataset = new DatasetWizardModel();
DescriptionEntity descriptionEntityEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
;
DMP dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId());
if (dmp.getUsers()
.stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId()))
.collect(Collectors.toList()).size() == 0 && !dmp.isPublic())
DmpEntity dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId());
if (
//TODO
// dmp.getUsers()
// .stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId()))
// .collect(Collectors.toList()).size() == 0 &&
!dmp.getAccessType().equals(DmpAccessType.Public))
throw new UnauthorisedException();
dataset.setDatasetProfileDefinition(getPagedProfile(dataset, descriptionEntityEntity));
dataset.fromDataModel(descriptionEntityEntity);
@ -365,8 +368,8 @@ public class DatasetManager {
public DatasetWizardModel getSinglePublic(String id) throws Exception {
DatasetWizardModel dataset = new DatasetWizardModel();
DescriptionEntity descriptionEntityEntity = databaseRepository.getDatasetDao().isPublicDataset(UUID.fromString(id));
DMP dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getId()).isActive(IsActive.Active).first().getDmpId());
if (descriptionEntityEntity != null && descriptionEntityEntity.getStatus() == DescriptionStatus.Finalized && dmp.getStatus() == 1) {
DmpEntity dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getId()).isActive(IsActive.Active).first().getDmpId());
if (descriptionEntityEntity != null && descriptionEntityEntity.getStatus() == DescriptionStatus.Finalized && dmp.getStatus().getValue() == 1) {
dataset.setDatasetProfileDefinition(getPagedProfile(dataset, descriptionEntityEntity));
dataset.fromDataModel(descriptionEntityEntity);
return dataset;
@ -380,14 +383,17 @@ public class DatasetManager {
if (descriptionEntityEntity.getIsActive() == IsActive.Inactive) {
throw new Exception("Dataset is deleted.");
}
DMP dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId());
DmpEntity dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId());
if (!isPublic && !this.userScope.isSet()) {
throw new UnauthorisedException();
} else
if (!isPublic && dmp.getUsers()
.stream().noneMatch(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId()))) {
if (!isPublic
//TODO
// && dmp.getUsers()
// .stream().noneMatch(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId()))
) {
throw new UnauthorisedException();
} else if (isPublic && !dmp.isPublic()) {
} else if (isPublic && !dmp.getAccessType().equals(DmpAccessType.Public)) {
throw new ForbiddenException("Selected Dataset is not public");
}
DatasetOverviewModel dataset = new DatasetOverviewModel();
@ -418,8 +424,11 @@ public class DatasetManager {
DatasetWizardModel dataset = new DatasetWizardModel();
XWPFDocument document = configLoader.getDatasetDocument();
DMP dmpEntity = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId());
if (!dmpEntity.isPublic() && dmpEntity.getUsers().stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())).collect(Collectors.toList()).size() == 0)
DmpEntity dmpEntity = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId());
if (!dmpEntity.getAccessType().equals(DmpAccessType.Public)
//TODO
// && dmpEntity.getUsers().stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())).collect(Collectors.toList()).size() == 0
)
throw new UnauthorisedException();
wordBuilder.fillFirstPage(dmpEntity, descriptionEntityEntity, document, true);
@ -556,10 +565,13 @@ public class DatasetManager {
public FileEnvelope getWordDocumentFile(ConfigLoader configLoader, String id, VisibilityRuleService visibilityRuleService) throws IOException, InvalidApplicationException {
DescriptionEntity descriptionEntityEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
DMP dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId());
if (!dmp.isPublic() && dmp.getUsers()
.stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId()))
.collect(Collectors.toList()).size() == 0)
DmpEntity dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId());
if (!dmp.getAccessType().equals(DmpAccessType.Public)
//TODO
// && dmp.getUsers()
// .stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId()))
// .collect(Collectors.toList()).size() == 0
)
throw new UnauthorisedException();
String label = descriptionEntityEntity.getLabel().replaceAll("[^a-zA-Z0-9+ ]", "");
FileEnvelope exportEnvelope = new FileEnvelope();
@ -586,10 +598,13 @@ public class DatasetManager {
ExportXmlBuilder xmlBuilder = new ExportXmlBuilder();
DatasetWizardModel dataset = new DatasetWizardModel();
DescriptionEntity descriptionEntityEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
DMP dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId());
if (!dmp.isPublic() && dmp.getUsers()
.stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId()))
.collect(Collectors.toList()).size() == 0)
DmpEntity dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId());
if (!dmp.getAccessType().equals(DmpAccessType.Public)
//TODO
// && dmp.getUsers()
// .stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId()))
// .collect(Collectors.toList()).size() == 0
)
throw new UnauthorisedException();
Map<String, Object> properties = new HashMap<>();
if (descriptionEntityEntity.getProperties() != null) {
@ -610,7 +625,7 @@ public class DatasetManager {
public DescriptionEntity createOrUpdate(DatasetWizardModel datasetWizardModel) throws Exception {
Boolean sendNotification = false;
DescriptionEntity tempDescriptionEntity = null;
DMP dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(datasetWizardModel.getDmp().getId());
DmpEntity dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(datasetWizardModel.getDmp().getId());
if (datasetWizardModel.getId() != null) {
tempDescriptionEntity = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(datasetWizardModel.getId());
if (tempDescriptionEntity != null) {
@ -625,7 +640,7 @@ public class DatasetManager {
} else {
metricsManager.increaseValue(MetricNames.DATASET, 1, MetricNames.DRAFT);
}
if (dmp.getStatus().equals(DMP.DMPStatus.FINALISED.getValue()) && datasetWizardModel.getId() != null)
if (dmp.getStatus().equals(DmpStatus.Finalized) && datasetWizardModel.getId() != null)
throw new Exception("DMP is finalized, therefore Dataset cannot be edited.");
DescriptionEntity descriptionEntity = datasetWizardModel.toDataModel();
// descriptionEntity.setDmpId(dmp.getId()); //TODO
@ -649,15 +664,15 @@ public class DatasetManager {
DescriptionEntity descriptionEntity1 = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(descriptionEntity);
datasetWizardModel.setId(descriptionEntity1.getId());
if (datasetWizardModel.getDmp().getGrant() == null) {
DMP dmp1 = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity1.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId());
DmpEntity dmp1 = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity1.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId());
datasetWizardModel.setDmp(new DataManagementPlan().fromDataModelNoDatasets(dmp1));
}
// descriptionEntity1.setDescriptionTemplateId(datasetWizardModel.getProfile().getId()); //TODO
// datasetWizardModel.setDatasetProfileDefinition(getPagedProfile(datasetWizardModel, dataset1));
UUID dmpId = this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity1.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId();
DMP dmp1 = databaseRepository.getDmpDao().find(dmpId);
dmp1.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
DmpEntity dmp1 = databaseRepository.getDmpDao().find(dmpId);
// dmp1.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));//TODO
//updateTags(descriptionEntity1, datasetWizardModel.getTags()); //TODO
if (sendNotification) {
if (descriptionEntity1.getStatus() != DescriptionStatus.Finalized) {
@ -711,17 +726,17 @@ public class DatasetManager {
});
}
private void sendNotification(DescriptionEntity descriptionEntity, DMP dmp, UserInfo user, NotificationType notificationType) throws InvalidApplicationException {
List<UserDMP> userDMPS = databaseRepository.getUserDmpDao().asQueryable().where(((builder, root) -> builder.equal(root.get("dmp").get("id"), dmp.getId()))).toList();
for (UserDMP userDMP : userDMPS) {
if (!userDMP.getUser().getId().equals(user.getId())) {
private void sendNotification(DescriptionEntity descriptionEntity, DmpEntity dmp, UserInfo user, NotificationType notificationType) throws InvalidApplicationException {
List<DmpUserEntity> userDMPS = databaseRepository.getUserDmpDao().asQueryable().where(((builder, root) -> builder.equal(root.get("dmp").get("id"), dmp.getId()))).toList();
for (DmpUserEntity userDMP : userDMPS) {
if (!userDMP.getUser().equals(user.getId())) {
Notification notification = new Notification();
notification.setUserId(user);
notification.setType(notificationType);
notification.setNotifyState(NotifyState.PENDING);
notification.setIsActive(ActiveStatus.ACTIVE);
notification.setData("{" +
"\"userId\": \"" + userDMP.getUser().getId() + "\"" +
"\"userId\": \"" + userDMP.getUser() + "\"" +
", \"id\": \"" + descriptionEntity.getId() + "\"" +
", \"name\": \"" + descriptionEntity.getLabel() + "\"" +
", \"path\": \"" + notificationPaths.get(notificationType) + "\"" +
@ -729,7 +744,7 @@ public class DatasetManager {
notification.setCreatedAt(new Date());
notification.setUpdatedAt(notification.getCreatedAt());
notification.setContactTypeHint(ContactType.EMAIL);
notification.setContactHint(userDMP.getUser().getEmail());
notification.setContactHint(databaseRepository.getUserInfoDao().find(userDMP.getUser()).getEmail());
databaseRepository.getNotificationDao().createOrUpdate(notification);
}
}
@ -1029,7 +1044,7 @@ public class DatasetManager {
DescriptionEntity entity = new DescriptionEntity();
entity.setProperties(jsonDatasetProperties.toString());
entity.setLabel(importFile.getOriginalFilename());
DMP dmp = new DMP();
DmpEntity dmp = new DmpEntity();
dmp.setId(UUID.fromString(dmpId));
// entity.setDmpId(dmp.getId()); //TODO
entity.setStatus(DescriptionStatus.Draft);
@ -1091,8 +1106,8 @@ public class DatasetManager {
descriptionEntityEntities.forEach(datasetEntity -> {
try {
UUID dmpId = this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(datasetEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId();
DMP dmp = databaseRepository.getDmpDao().find(dmpId);
dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));
DmpEntity dmp = databaseRepository.getDmpDao().find(dmpId);
//dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); //TODO
// eu.eudat.elastic.entities.Dataset dataset = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(datasetEntity.getId().toString()); //TODO
// updateTags(datasetEntity, dataset != null ? dataset.getTags() : null);
} catch (Exception e) {

View File

@ -1,12 +1,13 @@
package eu.eudat.logic.managers;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.enums.DmpStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.dao.criteria.DatasetProfileCriteria;
import eu.eudat.data.dao.entities.DMPDao;
import eu.eudat.data.dao.entities.DatasetProfileDao;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.data.old.UserInfo;
@ -34,7 +35,7 @@ public class DatasetWizardManager {
public static List<DataManagentPlanListingModel> getUserDmps(DMPDao dmpRepository, DatasetWizardAutocompleteRequest datasetWizardAutocompleteRequest, UserScope userScope) throws InstantiationException, IllegalAccessException, InvalidApplicationException {
UserInfo userInfo = new UserInfo();
userInfo.setId(userScope.getUserId());
QueryableList<DMP> items = dmpRepository.getUserDmps(datasetWizardAutocompleteRequest.getCriteria(), userInfo);
QueryableList<DmpEntity> items = dmpRepository.getUserDmps(datasetWizardAutocompleteRequest.getCriteria(), userInfo);
List<DataManagentPlanListingModel> dataManagementPlans = items.select(item -> new DataManagentPlanListingModel().fromDataModel(item));
return dataManagementPlans;
}
@ -56,8 +57,8 @@ public class DatasetWizardManager {
public void unlock(ApiContext apiContext, QueryFactory queryFactory, UUID uuid) throws DatasetWizardCannotUnlockException, InvalidApplicationException {
DescriptionEntity descriptionEntity = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(uuid);
DMP dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId());
if(dmp.getStatus() == DMP.DMPStatus.FINALISED.getValue()) throw new DatasetWizardCannotUnlockException("To perform this action you will need to revert DMP's finalisation");
DmpEntity dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId());
if(dmp.getStatus().equals(DmpStatus.Finalized)) throw new DatasetWizardCannotUnlockException("To perform this action you will need to revert DMP's finalisation");
descriptionEntity.setStatus(DescriptionStatus.Draft);
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(descriptionEntity);
return;

View File

@ -6,7 +6,6 @@ import eu.eudat.data.query.items.table.grant.GrantTableRequest;
import eu.eudat.exceptions.grant.GrantWithDMPsDeleteException;
import eu.eudat.logic.builders.model.models.GrantBuilder;
import eu.eudat.data.dao.entities.GrantDao;
import eu.eudat.data.old.DMP;
import eu.eudat.logic.proxy.config.ExternalUrlCriteria;
import eu.eudat.logic.services.operations.DatabaseRepository;
import eu.eudat.logic.utilities.helpers.ListHelper;
@ -180,9 +179,10 @@ public class GrantManager {
public void delete(UUID uuid) throws InvalidApplicationException {
eu.eudat.data.old.Grant oldGrant = apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().find(uuid);
if (oldGrant.getDmps().size() > 0)
throw new GrantWithDMPsDeleteException("You cannot Remove Grants with DMPs");
oldGrant.setStatus(DMP.DMPStatus.DELETED.getValue());
//TODO
// if (oldGrant.getDmps().size() > 0)
// throw new GrantWithDMPsDeleteException("You cannot Remove Grants with DMPs");
// oldGrant.setStatus(DMP.DMPStatus.DELETED.getValue());
apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(oldGrant);
}
}

View File

@ -1,13 +1,16 @@
package eu.eudat.logic.managers;
import eu.eudat.commons.enums.DmpUserRole;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.old.DMP;
import eu.eudat.data.old.UserDMP;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.DmpUserEntity;
import eu.eudat.data.old.UserInfo;
import eu.eudat.data.query.items.item.userinfo.UserInfoRequestItem;
import eu.eudat.exceptions.security.UnauthorisedException;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.logic.utilities.helpers.StreamDistinctBy;
import eu.eudat.model.DmpUser;
import eu.eudat.models.data.invitation.Invitation;
import eu.eudat.models.data.invitation.Properties;
import eu.eudat.models.data.userinfo.UserInfoInvitationModel;
@ -56,11 +59,11 @@ public class InvitationsManager {
});
List<UserInfoInvitationModel> alreadySignedInUsers = invitation.getUsers().stream().filter(item -> item.getId() != null).collect(Collectors.toList());
List<UserInfo> alreadySignedInUsersEntities = alreadySignedInUsers.stream().map(UserInfoInvitationModel::toDataModel).collect(Collectors.toList());
List<UserDMP> userInfoToUserDmp = new LinkedList<>();
List<DmpUserEntity> userInfoToUserDmp = new LinkedList<>();
for (UserInfo userInfo : alreadySignedInUsersEntities) {
UserDMP userDMP = new UserDMP();
userDMP.setUser(userInfo);
userDMP.setRole(invitation.getRole());
DmpUserEntity userDMP = new DmpUserEntity();
userDMP.setUser(userInfo.getId());
userDMP.setRole(DmpUserRole.of(invitation.getRole().shortValue()));
userInfoToUserDmp.add(userDMP);
/*if (!apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().areAssociated(principalUser, userInfo)) {
UserAssociation userAssociation = new UserAssociation();
@ -69,7 +72,7 @@ public class InvitationsManager {
apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().createOrUpdate(userAssociation);
}*/
}
DMP dataManagementPlan = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(invitation.getDataManagementPlan());
DmpEntity dataManagementPlan = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(invitation.getDataManagementPlan());
apiContext.getUtilitiesService().getInvitationService().createInvitations(apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao(), apiContext.getUtilitiesService().getMailService(), invitation.getUsers().stream().map(UserInfoInvitationModel::toDataModel).collect(Collectors.toList()), dataManagementPlan, invitation.getRole(), principalUser);
apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), userInfoToUserDmp, dataManagementPlan);
}
@ -83,80 +86,86 @@ public class InvitationsManager {
return userAssociation.getFirstUser();
}
}).collect(Collectors.toList());*/
List<UserInfo> users = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao()
.getAuthenticated(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().asQueryable()
.where(((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()))), this.userScope.getUserId(), Stream.of(0, 1).collect(Collectors.toList()))
.toList().stream().map(DMP::getUsers).flatMap(Collection::stream).map(UserDMP::getUser)
.filter(userInfo -> !userInfo.getId().equals(this.userScope.getUserIdSafe())).filter(StreamDistinctBy.distinctByKey(UserInfo::getId)).collect(Collectors.toList());
List<UserInfo> users = new ArrayList<>();
//TODO
// apiContext.getOperationsContext().getDatabaseRepository().getDmpDao()
// .getAuthenticated(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().asQueryable()
// .where(((builder, root) -> builder.notEqual(root.get("isActive"), IsActive.Inactive))), this.userScope.getUserId(), Stream.of(0, 1).collect(Collectors.toList()))
// .toList().stream().map(DmpEntity::getUsers).flatMap(Collection::stream).map(DmpUser::getUser)
// .filter(userInfo -> !userInfo.getId().equals(this.userScope.getUserIdSafe())).filter(StreamDistinctBy.distinctByKey(UserInfo::getId)).collect(Collectors.toList());
List<UserInfoInvitationModel> userModels = users.stream().map(userInfo -> new UserInfoInvitationModel().fromDataModel(userInfo)).collect(Collectors.toList());
return userModels;
}
public List<UserInfoInvitationModel> getUsersWithCriteria(UserInfoRequestItem userInfoRequestItem) throws IllegalAccessException, InstantiationException, InvalidApplicationException {
List<UserInfo> users = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao()
.getAuthenticated(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().asQueryable()
.where(((builder, root) ->
builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()))), this.userScope.getUserId(), Stream.of(0, 1).collect(Collectors.toList()))
.toList().stream().map(DMP::getUsers).flatMap(Collection::stream).map(UserDMP::getUser)
.filter(userInfo -> !userInfo.getId().equals(this.userScope.getUserIdSafe())).filter(StreamDistinctBy.distinctByKey(UserInfo::getId))
.filter(userInfo -> (userInfoRequestItem == null || userInfoRequestItem.getCriteria() == null || userInfoRequestItem.getCriteria().getLike() == null
|| userInfo.getName().toLowerCase().contains(userInfoRequestItem.getCriteria().getLike().toLowerCase())
|| (userInfo.getEmail().toLowerCase().contains(userInfoRequestItem.getCriteria().getLike().toLowerCase()))))
.collect(Collectors.toList());
// .where((builder, root) -> builder.like(builder.upper(root.get("name")), "%" + userInfoRequestItem.getCriteria().getLike().toUpperCase() + "%"))
List<UserInfoInvitationModel> userModels = users.stream().map(userInfo -> new UserInfoInvitationModel().fromDataModel(userInfo)).collect(Collectors.toList());
return userModels;
//TODO
// List<UserInfo> users = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao()
// .getAuthenticated(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().asQueryable()
// .where(((builder, root) ->
// builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()))), this.userScope.getUserId(), Stream.of(0, 1).collect(Collectors.toList()))
// .toList().stream().map(DMP::getUsers).flatMap(Collection::stream).map(UserDMP::getUser)
// .filter(userInfo -> !userInfo.getId().equals(this.userScope.getUserIdSafe())).filter(StreamDistinctBy.distinctByKey(UserInfo::getId))
// .filter(userInfo -> (userInfoRequestItem == null || userInfoRequestItem.getCriteria() == null || userInfoRequestItem.getCriteria().getLike() == null
// || userInfo.getName().toLowerCase().contains(userInfoRequestItem.getCriteria().getLike().toLowerCase())
// || (userInfo.getEmail().toLowerCase().contains(userInfoRequestItem.getCriteria().getLike().toLowerCase()))))
// .collect(Collectors.toList());
//// .where((builder, root) -> builder.like(builder.upper(root.get("name")), "%" + userInfoRequestItem.getCriteria().getLike().toUpperCase() + "%"))
//
// List<UserInfoInvitationModel> userModels = users.stream().map(userInfo -> new UserInfoInvitationModel().fromDataModel(userInfo)).collect(Collectors.toList());
// return userModels;
return new ArrayList<>();
}
public UUID assignUserAcceptedInvitation(UUID invitationID) throws UnauthorisedException, JAXBException, IOException, InvalidApplicationException {
eu.eudat.data.old.Invitation invitation = apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().find(invitationID);
if (invitation == null)
throw new UnauthorisedException("There is no Data Management Plan assigned to this Link");
if (invitation.getAcceptedInvitation()) return invitation.getDmp().getId(); //throw new UnauthorisedException("This Url Has Expired");
JAXBContext context = JAXBContext.newInstance(Properties.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
Properties properties = (Properties) unmarshaller.unmarshal(new StringReader(invitation.getProperties()));
UserInfo invitedUser = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId());
QueryableList<UserDMP> userDMPQueryableList = apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where(((builder, root) -> builder.and(builder.equal(root.get("dmp").get("id"), invitation.getDmp().getId()), builder.equal(root.get("user").get("id"), invitedUser.getId()))));
UserDMP existingUserDMP = userDMPQueryableList.getSingleOrDefault();
if (existingUserDMP != null) {
if (properties.getRole() != null && existingUserDMP.getRole() > properties.getRole()) {
existingUserDMP.setRole(properties.getRole());
DMP datamanagementPlan = invitation.getDmp();
apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(existingUserDMP);
apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), existingUserDMP, datamanagementPlan);
invitation.setAcceptedInvitation(true);
apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().createOrUpdate(invitation);
datamanagementPlan.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), datamanagementPlan.getId())).toList()));
//dataManagementPlanManager.updateIndex(datamanagementPlan); //TODO
return datamanagementPlan.getId();
}
} else {
UserDMP userDMP = new UserDMP();
userDMP.setUser(invitedUser);
userDMP.setDmp(invitation.getDmp());
if (properties.getRole() != null) {
userDMP.setRole(properties.getRole());
} else {
userDMP.setRole(UserDMP.UserDMPRoles.USER.getValue());
}
/*if (!apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().areAssociated(invitedUser, invitation.getUser())) {
UserAssociation userAssociation = new UserAssociation();
userAssociation.setFirstUser(invitedUser);
userAssociation.setSecondUser(invitation.getUser());
apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().createOrUpdate(userAssociation);
}*/
DMP datamanagementPlan = invitation.getDmp();
apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP);
apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), userDMP, datamanagementPlan);
invitation.setAcceptedInvitation(true);
apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().createOrUpdate(invitation);
datamanagementPlan.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), datamanagementPlan.getId())).toList()));
// dataManagementPlanManager.updateIndex(datamanagementPlan); //TODo
return datamanagementPlan.getId();
}
return invitation.getDmp().getId();
//TODO
// eu.eudat.data.old.Invitation invitation = apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().find(invitationID);
// if (invitation == null)
// throw new UnauthorisedException("There is no Data Management Plan assigned to this Link");
// if (invitation.getAcceptedInvitation()) return invitation.getDmp().getId(); //throw new UnauthorisedException("This Url Has Expired");
// JAXBContext context = JAXBContext.newInstance(Properties.class);
// Unmarshaller unmarshaller = context.createUnmarshaller();
// Properties properties = (Properties) unmarshaller.unmarshal(new StringReader(invitation.getProperties()));
// UserInfo invitedUser = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId());
// QueryableList<UserDMP> userDMPQueryableList = apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where(((builder, root) -> builder.and(builder.equal(root.get("dmp").get("id"), invitation.getDmp().getId()), builder.equal(root.get("user").get("id"), invitedUser.getId()))));
// UserDMP existingUserDMP = userDMPQueryableList.getSingleOrDefault();
// if (existingUserDMP != null) {
// if (properties.getRole() != null && existingUserDMP.getRole() > properties.getRole()) {
// existingUserDMP.setRole(properties.getRole());
// DMP datamanagementPlan = invitation.getDmp();
// apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(existingUserDMP);
// apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), existingUserDMP, datamanagementPlan);
// invitation.setAcceptedInvitation(true);
// apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().createOrUpdate(invitation);
// datamanagementPlan.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), datamanagementPlan.getId())).toList()));
// //dataManagementPlanManager.updateIndex(datamanagementPlan); //TODO
// return datamanagementPlan.getId();
// }
// } else {
// UserDMP userDMP = new UserDMP();
// userDMP.setUser(invitedUser);
// userDMP.setDmp(invitation.getDmp());
//
// if (properties.getRole() != null) {
// userDMP.setRole(properties.getRole());
// } else {
// userDMP.setRole(UserDMP.UserDMPRoles.USER.getValue());
// }
// /*if (!apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().areAssociated(invitedUser, invitation.getUser())) {
// UserAssociation userAssociation = new UserAssociation();
// userAssociation.setFirstUser(invitedUser);
// userAssociation.setSecondUser(invitation.getUser());
// apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().createOrUpdate(userAssociation);
// }*/
// DmpEntity datamanagementPlan = invitation.getDmp();
// apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP);
// apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), userDMP, datamanagementPlan);
// invitation.setAcceptedInvitation(true);
// apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().createOrUpdate(invitation);
// datamanagementPlan.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), datamanagementPlan.getId())).toList()));
//// dataManagementPlanManager.updateIndex(datamanagementPlan); //TODo
// return datamanagementPlan.getId();
// }
// return invitation.getDmp().getId();
return null;
}
}

View File

@ -2,8 +2,8 @@ package eu.eudat.logic.managers;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.CredentialEntity;
import eu.eudat.data.DmpUserEntity;
import eu.eudat.data.old.EmailConfirmation;
import eu.eudat.data.old.UserDMP;
import eu.eudat.data.old.UserInfo;
import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException;
import eu.eudat.exceptions.emailconfirmation.TokenExpiredException;
@ -20,7 +20,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.transaction.Transactional;
import javax.management.InvalidApplicationException;
import java.io.IOException;
import java.util.*;
@Component
@ -88,9 +87,9 @@ public class MergeEmailConfirmationManager {
CredentialEntity credential = databaseRepository.getCredentialDao().asQueryable().where((builder, root) -> builder.and(builder.equal(root.get("userId"), oldUser.getId()), builder.equal(root.get("provider"), provider))).getSingle();
credential.setUserId(newUser.getId());
databaseRepository.getCredentialDao().createOrUpdate(credential);
List<UserDMP> userDmps = databaseRepository.getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("user"), oldUser)).toList();
List<DmpUserEntity> userDmps = databaseRepository.getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("user"), oldUser)).toList();
userDmps.forEach(userDmp -> {
userDmp.setUser(newUser);
userDmp.setUser(newUser.getId());
databaseRepository.getUserDmpDao().createOrUpdate(userDmp);
});
//TODO

View File

@ -1,6 +1,9 @@
package eu.eudat.logic.managers;
import eu.eudat.commons.enums.DmpUserRole;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.DmpUserEntity;
import eu.eudat.data.dao.criteria.FunderCriteria;
import eu.eudat.data.dao.criteria.GrantCriteria;
import eu.eudat.data.dao.criteria.ProjectCriteria;
@ -50,22 +53,25 @@ public class QuickWizardManager {
return databaseRepository.getProjectDao().createOrUpdate(projectEntity);
}
public DMP createOrUpdate(DataManagementPlan dataManagementPlan, Funder funderEntity) throws Exception {
DMP newDmp = dataManagementPlan.toDataModel();
public DmpEntity createOrUpdate(DataManagementPlan dataManagementPlan, Funder funderEntity) throws Exception {
DmpEntity newDmp = dataManagementPlan.toDataModel();
if (funderEntity != null) {
newDmp.getGrant().setFunder(funderEntity);
//TODO
//newDmp.getGrant().setFunder(funderEntity);
}
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId());
createFunderIfItDoesntExist(newDmp, user);
createGrantIfItDoesntExist(newDmp, user);
if (newDmp.getProject() == null) {
newDmp.setProject(new Project());
newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant()));
}
//TODO
// if (newDmp.getProject() == null) {
// newDmp.setProject(new Project());
// newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant()));
// }
createProjectIfItDoesntExist(newDmp, user);
apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant());
DMP dmpret = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
//TODO
//apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant());
DmpEntity dmpret = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
if (dataManagementPlan.getAssociatedUsers().size() == 0)
assignUser(newDmp, user, apiContext);
@ -80,54 +86,54 @@ public class QuickWizardManager {
// apiContext.getOperationsContext().getElasticRepository().getDmpRepository().createOrUpdate(elastic);
// }
private void assignUser(DMP dmp, UserInfo userInfo, ApiContext apiContext) {
UserDMP userDMP = new UserDMP();
userDMP.setDmp(dmp);
userDMP.setUser(userInfo);
userDMP.setRole(UserDMP.UserDMPRoles.OWNER.getValue());
private void assignUser(DmpEntity dmp, UserInfo userInfo, ApiContext apiContext) {
DmpUserEntity userDMP = new DmpUserEntity();
userDMP.setDmp(dmp.getId());
userDMP.setUser(userInfo.getId());
userDMP.setRole(DmpUserRole.User);
apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP);
}
private void createGrantIfItDoesntExist(DMP newDmp, UserInfo userInfo) throws InvalidApplicationException {
if (newDmp.getGrant() != null) {
Grant grant = newDmp.getGrant();
GrantCriteria criteria = new GrantCriteria();
criteria.setReference(grant.getReference());
Grant grantEntity = databaseRepository.getGrantDao().getWithCriteria(criteria).getSingleOrDefault();
if (grantEntity != null) grant.setId(grantEntity.getId());
else {
grant.setType(Grant.GrantType.EXTERNAL.getValue());
databaseRepository.getGrantDao().createOrUpdate(grant);
}
}
private void createGrantIfItDoesntExist(DmpEntity newDmp, UserInfo userInfo) throws InvalidApplicationException {
// if (newDmp.getGrant() != null) {
// Grant grant = newDmp.getGrant();
// GrantCriteria criteria = new GrantCriteria();
// criteria.setReference(grant.getReference());
// Grant grantEntity = databaseRepository.getGrantDao().getWithCriteria(criteria).getSingleOrDefault();
// if (grantEntity != null) grant.setId(grantEntity.getId());
// else {
// grant.setType(Grant.GrantType.EXTERNAL.getValue());
// databaseRepository.getGrantDao().createOrUpdate(grant);
// }
// }
}
private void createFunderIfItDoesntExist(DMP newDmp, UserInfo userInfo) throws InvalidApplicationException {
if (newDmp.getGrant().getFunder() != null) {
Funder funder = newDmp.getGrant().getFunder();
FunderCriteria criteria = new FunderCriteria();
criteria.setReference(funder.getReference());
Funder funderEntity = databaseRepository.getFunderDao().getWithCritetia(criteria).getSingleOrDefault();
if (funderEntity != null) funder.setId(funderEntity.getId());
else {
funder.setType(Funder.FunderType.EXTERNAL.getValue());
databaseRepository.getFunderDao().createOrUpdate(funder);
}
}
private void createFunderIfItDoesntExist(DmpEntity newDmp, UserInfo userInfo) throws InvalidApplicationException {
// if (newDmp.getGrant().getFunder() != null) { //TODO
// Funder funder = newDmp.getGrant().getFunder();
// FunderCriteria criteria = new FunderCriteria();
// criteria.setReference(funder.getReference());
// Funder funderEntity = databaseRepository.getFunderDao().getWithCritetia(criteria).getSingleOrDefault();
// if (funderEntity != null) funder.setId(funderEntity.getId());
// else {
// funder.setType(Funder.FunderType.EXTERNAL.getValue());
// databaseRepository.getFunderDao().createOrUpdate(funder);
// }
// }
}
private void createProjectIfItDoesntExist(DMP newDmp, UserInfo userInfo) throws InvalidApplicationException {
if (newDmp.getProject() != null) {
Project project = newDmp.getProject();
ProjectCriteria criteria = new ProjectCriteria();
criteria.setReference(project.getReference());
Project projectEntity = databaseRepository.getProjectDao().getWithCritetia(criteria).getSingleOrDefault();
if (projectEntity != null) project.setId(projectEntity.getId());
else {
if (project.getId() == null) project.setId(UUID.randomUUID());
project.setType(Project.ProjectType.EXTERNAL.getValue());
databaseRepository.getProjectDao().createOrUpdate(project);
}
}
private void createProjectIfItDoesntExist(DmpEntity newDmp, UserInfo userInfo) throws InvalidApplicationException {
// if (newDmp.getProject() != null) { //TODO
// Project project = newDmp.getProject();
// ProjectCriteria criteria = new ProjectCriteria();
// criteria.setReference(project.getReference());
// Project projectEntity = databaseRepository.getProjectDao().getWithCritetia(criteria).getSingleOrDefault();
// if (projectEntity != null) project.setId(projectEntity.getId());
// else {
// if (project.getId() == null) project.setId(UUID.randomUUID());
// project.setType(Project.ProjectType.EXTERNAL.getValue());
// databaseRepository.getProjectDao().createOrUpdate(project);
// }
// }
}
}

View File

@ -2,7 +2,7 @@ package eu.eudat.logic.managers;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DmpEntity;
import eu.eudat.models.rda.Dmp;
import eu.eudat.models.rda.RDAModel;
import eu.eudat.models.rda.mapper.DmpRDAMapper;
@ -26,7 +26,7 @@ public class RDAManager {
}
@Transactional
public String convertToRDA(DMP dmp) throws JsonProcessingException, InvalidApplicationException {
public String convertToRDA(DmpEntity dmp) throws JsonProcessingException, InvalidApplicationException {
String result = "";
Dmp rdaDmp = dmpRDAMapper.toRDA(dmp);
@ -41,7 +41,7 @@ public class RDAManager {
return result;
}
public DMP convertToEntity(String json, String[] profiles) throws IOException, InvalidApplicationException {
public DmpEntity convertToEntity(String json, String[] profiles) throws IOException, InvalidApplicationException {
ObjectMapper mapper = new ObjectMapper();
Dmp rda = mapper.readValue(json, RDAModel.class).getDmp();

View File

@ -5,9 +5,9 @@ import eu.eudat.authorization.Permission;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity;
import eu.eudat.data.CredentialEntity;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
import eu.eudat.data.dao.entities.UserInfoDao;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.data.old.UserInfo;
import eu.eudat.data.old.UserRole;
@ -98,8 +98,8 @@ public class UserManager {
List<Integer> roles = new LinkedList<>();
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria();
criteria.setAllVersions(false);
QueryableList<DMP> items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(criteria);
List<DMP> dmps = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getAuthenticated(items, userId, roles).take(5).toList();
QueryableList<DmpEntity> items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(criteria);
List<DmpEntity> dmps = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getAuthenticated(items, userId, roles).take(5).toList();
profile.setAssociatedDmps(dmps.stream().map(x -> new DataManagementPlan().fromDataModel(x)).collect(Collectors.toList()));
return profile;
}

View File

@ -1,13 +1,14 @@
package eu.eudat.logic.services.utilities;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.DmpUserEntity;
import eu.eudat.data.dao.entities.DMPDao;
import eu.eudat.data.dao.entities.InvitationDao;
import eu.eudat.data.old.DMP;
import eu.eudat.data.old.Invitation;
import eu.eudat.data.old.UserDMP;
import eu.eudat.data.old.UserInfo;
import eu.eudat.models.rda.Dmp;
import eu.eudat.service.mail.MailService;
import jakarta.mail.MessagingException;
import java.util.List;
@ -15,11 +16,11 @@ import java.util.concurrent.CompletableFuture;
public interface InvitationService {
void assignToDmp(DMPDao dmpDao, List<UserDMP> users, DMP dmp);
void assignToDmp(DMPDao dmpDao, List<DmpUserEntity> users, DmpEntity dmp);
void assignToDmp(DMPDao dmpDao, UserDMP user, DMP dmp);
void assignToDmp(DMPDao dmpDao, DmpUserEntity user, DmpEntity dmp);
void createInvitations(InvitationDao invitationDao, MailService mailService, List<UserInfo> users, DMP dmp, Integer role, UserInfo creator) throws MessagingException;
void createInvitations(InvitationDao invitationDao, MailService mailService, List<UserInfo> users, DmpEntity dmp, Integer role, UserInfo creator) throws MessagingException;
CompletableFuture sendInvitationAsync(DMP dmp, Invitation invitation, String recipient, MailService mailService, Integer role) throws MessagingException;
CompletableFuture sendInvitationAsync(DmpEntity dmp, Invitation invitation, String recipient, MailService mailService, Integer role) throws MessagingException;
}

View File

@ -1,11 +1,11 @@
package eu.eudat.logic.services.utilities;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.DmpUserEntity;
import eu.eudat.data.dao.entities.DMPDao;
import eu.eudat.data.dao.entities.InvitationDao;
import eu.eudat.data.old.DMP;
import eu.eudat.data.old.Invitation;
import eu.eudat.data.old.UserDMP;
import eu.eudat.data.old.UserInfo;
import eu.eudat.models.data.invitation.Properties;
import eu.eudat.service.mail.MailService;
@ -37,26 +37,26 @@ public class InvitationServiceImpl implements InvitationService {
}
@Override
public void assignToDmp(DMPDao dmpDao, List<UserDMP> users, DMP dmp) {
for (UserDMP user : users) {
dmp.getUsers().add(user);
}
public void assignToDmp(DMPDao dmpDao, List<DmpUserEntity> users, DmpEntity dmp) {
// for (DmpUserEntity user : users) {
// dmp.getUsers().add(user);
// } //TODO
dmpDao.createOrUpdate(dmp);
}
@Override
public void assignToDmp(DMPDao dmpDao, UserDMP user, DMP dmp) {
if (!dmp.getUsers().stream().map(x -> x.getUser().getId()).collect(Collectors.toList()).contains(user.getId())) {
dmp.getUsers().add(user);
dmpDao.createOrUpdate(dmp);
}
public void assignToDmp(DMPDao dmpDao, DmpUserEntity user, DmpEntity dmp) {
// if (!dmp.getUsers().stream().map(x -> x.getUser().getId()).collect(Collectors.toList()).contains(user.getId())) {
// dmp.getUsers().add(user);
// dmpDao.createOrUpdate(dmp);
// } //TODO
}
@Override
public void createInvitations(InvitationDao invitationDao, MailService mailService, List<UserInfo> users, DMP dmp, Integer role, UserInfo creator) throws MessagingException {
public void createInvitations(InvitationDao invitationDao, MailService mailService, List<UserInfo> users, DmpEntity dmp, Integer role, UserInfo creator) throws MessagingException {
for (UserInfo userInfo : users) {
Invitation invitation = new Invitation();
invitation.setDmp(dmp);
// invitation.setDmp(dmp); //TODO
invitation.setInvitationEmail(userInfo.getEmail());
invitation.setUser(creator);
invitation.setToken(UUID.randomUUID());
@ -78,7 +78,7 @@ public class InvitationServiceImpl implements InvitationService {
}
@Override
public CompletableFuture sendInvitationAsync(DMP dmp, Invitation invitation, String recipient, MailService mailService, Integer role) {
public CompletableFuture sendInvitationAsync(DmpEntity dmp, Invitation invitation, String recipient, MailService mailService, Integer role) {
return CompletableFuture.runAsync(() -> {
SimpleMail mail = new SimpleMail();
mail.setSubject(createSubject(dmp, mailService.getMailTemplateSubject()));
@ -92,17 +92,17 @@ public class InvitationServiceImpl implements InvitationService {
});
}
private String createSubject(DMP dmp, String templateSubject) {
private String createSubject(DmpEntity dmp, String templateSubject) {
String subject = templateSubject.replace("{dmpname}", dmp.getLabel());
return subject;
}
private String createContent(UUID invitationID, DMP dmp, String recipient, String templateContent, Integer role) {
private String createContent(UUID invitationID, DmpEntity dmp, String recipient, String templateContent, Integer role) {
String content = templateContent.replace("{dmpname}", dmp.getLabel());
content = content.replace("{invitationID}", invitationID.toString());
content = content.replace("{recipient}", recipient);
content = content.replace("{host}", this.environment.getProperty("dmp.domain"));
content = content.replace("{dmprole}", UserDMP.UserDMPRoles.fromInteger(role).name());
// content = content.replace("{dmprole}", UserDMP.UserDMPRoles.fromInteger(role).name()); //TODO
return content;
}

View File

@ -5,8 +5,8 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.commons.enums.FieldDataComboBoxType;
import eu.eudat.commons.types.descriptiontemplate.fielddata.*;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.old.Organisation;
import eu.eudat.data.old.Researcher;
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
@ -1014,7 +1014,7 @@ public class WordBuilder {
return -1;
}
public void fillFirstPage(DMP dmpEntity, DescriptionEntity descriptionEntityEntity, XWPFDocument document, boolean isDataset) {
public void fillFirstPage(DmpEntity dmpEntity, DescriptionEntity descriptionEntityEntity, XWPFDocument document, boolean isDataset) {
int parPos = 0;
int descrParPos = -1;
XWPFParagraph descrPar = null;
@ -1046,23 +1046,25 @@ public class WordBuilder {
r.setText(text, 0);
} else if(text.equals("{ARGOS.DMP.RESEARCHERS}")) {
String researchersNames = "";
Set<Researcher> researchers = dmpEntity.getResearchers();
int i = 0;
for(Researcher researcher : researchers){
i++;
researchersNames += researcher.getLabel() + (i < researchers.size() ? ", " : "");
}
//TODO
// Set<Researcher> researchers = dmpEntity.getResearchers();
// int i = 0;
// for(Researcher researcher : researchers){
// i++;
// researchersNames += researcher.getLabel() + (i < researchers.size() ? ", " : "");
// }
text = text.replace("{ARGOS.DMP.RESEARCHERS}", researchersNames);
r.setText(text, 0);
r.setFontSize(17);
} else if(text.equals("{ARGOS.DMP.ORGANIZATIONS}")) {
String organisationsNames = "";
Set<Organisation> organisations = dmpEntity.getOrganisations();
int i = 0;
for(Organisation organisation : organisations){
i++;
organisationsNames += organisation.getLabel() + (i < organisations.size() ? ", " : "");
}
//TODO
// Set<Organisation> organisations = dmpEntity.getOrganisations();
// int i = 0;
// for(Organisation organisation : organisations){
// i++;
// organisationsNames += organisation.getLabel() + (i < organisations.size() ? ", " : "");
// }
text = text.replace("{ARGOS.DMP.ORGANIZATIONS}", organisationsNames);
r.setText(text, 0);
r.setFontSize(17);
@ -1092,31 +1094,32 @@ public class WordBuilder {
XWPFTable tbl = document.getTables().get(0);
Iterator<XWPFTableRow> it = tbl.getRows().iterator();
it.next(); // skip first row
if(it.hasNext() && dmpEntity.getGrant() != null){
XWPFParagraph p = it.next().getCell(0).getParagraphs().get(0);
XWPFRun run = p.createRun();
run.setText(dmpEntity.getGrant().getFunder().getLabel());
run.setFontSize(17);
p.setAlignment(ParagraphAlignment.CENTER);
}
it = tbl.getRows().iterator();
it.next();
if(it.hasNext() && dmpEntity.getGrant() != null){
XWPFParagraph p = it.next().getCell(1).getParagraphs().get(0);
XWPFRun run = p.createRun();
String text = dmpEntity.getGrant().getLabel();
String reference = dmpEntity.getGrant().getReference();
if(reference != null) {
String[] parts = reference.split("::");
text += parts.length > 1 ? "/ No "+parts[parts.length - 1] : "";
}
run.setText(text);
run.setFontSize(17);
p.setAlignment(ParagraphAlignment.CENTER);
}
//TODO
// if(it.hasNext() && dmpEntity.getGrant() != null){
// XWPFParagraph p = it.next().getCell(0).getParagraphs().get(0);
// XWPFRun run = p.createRun();
// run.setText(dmpEntity.getGrant().getFunder().getLabel());
// run.setFontSize(17);
// p.setAlignment(ParagraphAlignment.CENTER);
// }
// it = tbl.getRows().iterator();
// it.next();
// if(it.hasNext() && dmpEntity.getGrant() != null){
// XWPFParagraph p = it.next().getCell(1).getParagraphs().get(0);
// XWPFRun run = p.createRun();
// String text = dmpEntity.getGrant().getLabel();
// String reference = dmpEntity.getGrant().getReference();
// if(reference != null) {
// String[] parts = reference.split("::");
// text += parts.length > 1 ? "/ No "+parts[parts.length - 1] : "";
// }
// run.setText(text);
// run.setFontSize(17);
// p.setAlignment(ParagraphAlignment.CENTER);
// }
}
public void fillFooter(DMP dmpEntity, DescriptionEntity descriptionEntityEntity, XWPFDocument document, boolean isDataset) {
public void fillFooter(DmpEntity dmpEntity, DescriptionEntity descriptionEntityEntity, XWPFDocument document, boolean isDataset) {
document.getFooterList().forEach(xwpfFooter -> {
List<XWPFRun> runs = xwpfFooter.getParagraphs().get(0).getRuns();
if(runs != null){
@ -1131,26 +1134,27 @@ public class WordBuilder {
text = text.replace("{ARGOS.DATASET.TITLE}", descriptionEntityEntity.getLabel());
r.setText(text, 0);
}
if(text.contains("{ARGOS.DMP.LICENSE}")){
try{
Map<String, String> license = ((Map<String, String>) mapper.readValue(dmpEntity.getExtraProperties(), Map.class).get("license"));
text = text.replace("{ARGOS.DMP.LICENSE}", license.get("pid"));
}
catch (JsonProcessingException | NullPointerException e){
text = text.replace("{ARGOS.DMP.LICENSE}", "License: -");
}
r.setText(text, 0);
}
if(text.contains("{ARGOS.DMP.DOI}")){
if(dmpEntity.getDois() != null && !dmpEntity.getDois().isEmpty())
text = text.replace("{ARGOS.DMP.DOI}", dmpEntity.getDois().iterator().next().getDoi());
else
text = text.replace("{ARGOS.DMP.DOI}", "-");
r.setText(text, 0);
}
//TODO
// if(text.contains("{ARGOS.DMP.LICENSE}")){
// try{
// Map<String, String> license = ((Map<String, String>) mapper.readValue(dmpEntity.getExtraProperties(), Map.class).get("license"));
// text = text.replace("{ARGOS.DMP.LICENSE}", license.get("pid"));
// }
// catch (JsonProcessingException | NullPointerException e){
// text = text.replace("{ARGOS.DMP.LICENSE}", "License: -");
// }
// r.setText(text, 0);
// }
// if(text.contains("{ARGOS.DMP.DOI}")){
// if(dmpEntity.getDois() != null && !dmpEntity.getDois().isEmpty())
// text = text.replace("{ARGOS.DMP.DOI}", dmpEntity.getDois().iterator().next().getDoi());
// else
// text = text.replace("{ARGOS.DMP.DOI}", "-");
// r.setText(text, 0);
// }
if(text.contains("{ARGOS.DMP.LAST_MODIFIED}")){
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
text = text.replace("{ARGOS.DMP.LAST_MODIFIED}", formatter.format(dmpEntity.getModified()));
text = text.replace("{ARGOS.DMP.LAST_MODIFIED}", formatter.format(dmpEntity.getUpdatedAt()));
r.setText(text, 0);
}
}

View File

@ -1,6 +1,6 @@
package eu.eudat.models.data.dashboard.recent.model;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DmpEntity;
import eu.eudat.models.data.listingmodels.UserInfoListingModel;
import eu.eudat.models.data.urls.DatasetUrlListing;
@ -10,7 +10,7 @@ import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
public class RecentDmpModel extends RecentActivityModel<DMP, RecentDmpModel> {
public class RecentDmpModel extends RecentActivityModel<DmpEntity, RecentDmpModel> {
private Map<String, Object> extraProperties;
private List<DatasetUrlListing> datasets;
private UUID groupId;
@ -41,33 +41,33 @@ public class RecentDmpModel extends RecentActivityModel<DMP, RecentDmpModel> {
@Override
@Transactional
public RecentActivityModel fromEntity(DMP entity) {
public RecentActivityModel fromEntity(DmpEntity entity) {
this.setType(RecentActivityType.DMP.getIndex());
this.setId(entity.getId().toString());
this.setTitle(entity.getLabel());
this.setCreated(entity.getCreated());
this.setModified(entity.getModified());
this.setStatus(entity.getStatus());
this.setVersion(entity.getVersion());
this.datasets = entity.getDataset().stream().map(dataset -> new DatasetUrlListing().fromDataModel(dataset)).collect(Collectors.toList());
this.setFinalizedAt(entity.getFinalizedAt());
if (entity.getGrant() != null) {
this.setGrant(entity.getGrant().getLabel());
}
this.groupId = entity.getGroupId();
this.setPublic(entity.isPublic());
this.setPublishedAt(entity.getPublishedAt());
this.setUsers(entity.getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList()));
this.setTitle(entity.getLabel()); //TODO
// this.setCreated(entity.getCreated());
// this.setModified(entity.getModified());
// this.setStatus(entity.getStatus());
// this.setVersion(entity.getVersion());
// this.datasets = entity.getDataset().stream().map(dataset -> new DatasetUrlListing().fromDataModel(dataset)).collect(Collectors.toList());
// this.setFinalizedAt(entity.getFinalizedAt());
// if (entity.getGrant() != null) {
// this.setGrant(entity.getGrant().getLabel());
// }
// this.groupId = entity.getGroupId();
// this.setPublic(entity.isPublic());
// this.setPublishedAt(entity.getPublishedAt());
// this.setUsers(entity.getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList()));
return this;
}
@Override
public RecentDmpModel fromDataModel(DMP entity) {
public RecentDmpModel fromDataModel(DmpEntity entity) {
return (RecentDmpModel) this.fromEntity(entity);
}
@Override
public DMP toDataModel() throws Exception {
public DmpEntity toDataModel() throws Exception {
return null;
}

View File

@ -1,10 +1,10 @@
package eu.eudat.models.data.datasetwizard;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DmpEntity;
import eu.eudat.models.DataModel;
public class DataManagentPlanListingModel implements DataModel<DMP, DataManagentPlanListingModel> {
public class DataManagentPlanListingModel implements DataModel<DmpEntity, DataManagentPlanListingModel> {
private String id;
private String label;
@ -26,14 +26,14 @@ public class DataManagentPlanListingModel implements DataModel<DMP, DataManagent
}
@Override
public DataManagentPlanListingModel fromDataModel(DMP entity) {
public DataManagentPlanListingModel fromDataModel(DmpEntity entity) {
this.id = entity.getId().toString();
this.label = entity.getLabel();
return this;
}
@Override
public DMP toDataModel() {
public DmpEntity toDataModel() {
return null;
}

View File

@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.DmpBlueprintEntity;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.old.*;
import eu.eudat.model.doi.Doi;
import eu.eudat.models.DataModel;
@ -21,7 +22,7 @@ import net.minidev.json.JSONObject;
import java.util.*;
import java.util.stream.Collectors;
public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
public class DataManagementPlan implements DataModel<DmpEntity, DataManagementPlan> {
private UUID id;
private String label;
private UUID groupId;
@ -235,204 +236,205 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
}
@Override
public DataManagementPlan fromDataModel(DMP entity) {
public DataManagementPlan fromDataModel(DmpEntity entity) {
this.id = entity.getId();
this.profile = entity.getProfile() != null ? new Tuple<UUID, String>(entity.getProfile().getId(), entity.getProfile().getLabel()) : null;
this.organisations = entity.getOrganisations() != null ? entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
this.researchers = entity.getResearchers() != null ? entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>();
this.version = entity.getVersion();
this.groupId = this.groupId == null ? null : entity.getGroupId();
this.label = entity.getLabel();
this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null;
if(entity.getGrant() != null) {
this.grant = new Grant();
this.grant.fromDataModel(entity.getGrant());
}
else {
this.grant = null;
}
this.creator = new eu.eudat.models.data.userinfo.UserInfo();
this.groupId = entity.getGroupId();
this.lockable = entity.getDataset() != null && entity.getDataset().stream().findAny().isPresent();
if (this.properties != null) {
this.extraFields = new ArrayList<>();
this.properties.forEach((id, value) -> {
if (value != null) {
ExtraFieldModel extraField = new ExtraFieldModel();
extraField.setId(id);
extraField.setValue(value.toString());
this.extraFields.add(extraField);
}
});
}
if (entity.getUsers() != null && entity.getUsers().stream().anyMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())))
this.creator.fromDataModel(entity.getUsers().stream().filter(user -> user.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser());
if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) {
this.profiles = new LinkedList<>();
for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) {
AssociatedProfile associatedProfile = new AssociatedProfile().fromData(dmpDescriptionProfile.getDatasetprofile());
associatedProfile.setId(dmpDescriptionProfile.getId());
try {
associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference<Map<String, Object>>() {}));
}
catch (Exception e) {
associatedProfile.setData(null);
}
this.profiles.add(associatedProfile);
}
}
if (entity.getDataset() != null) {
if (entity.isPublic()) {
this.datasets = entity.getDataset().stream()
.filter(dataset -> !dataset.getIsActive().equals(IsActive.Inactive) && !dataset.getStatus().equals(DescriptionStatus.Canceled) && !dataset.getStatus().equals(DescriptionStatus.Draft))
.map(x -> new DatasetWizardModel().fromDataModelNoDmp(x)).collect(Collectors.toList());
} else {
this.datasets = entity.getDataset().stream()
.filter(dataset -> !dataset.getIsActive().equals(IsActive.Inactive) && !dataset.getStatus().equals(DescriptionStatus.Draft))
.map(x -> new DatasetWizardModel().fromDataModelNoDmp(x)).collect(Collectors.toList());
}
}
this.modified = entity.getModified();
this.created = entity.getCreated();
this.description = entity.getDescription();
this.status = entity.getStatus();
this.associatedUsers = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()) : new ArrayList<>();
this.users = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
this.dois = entity.getDois() != null ? entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>();
if (entity.getProject() != null) {
this.project = new Project();
this.project = new Project().fromDataModel(entity.getProject());
}
if (entity.getGrant() != null && entity.getGrant().getFunder() != null) {
this.funder = new Funder();
this.funder.fromDataModel(entity.getGrant().getFunder());
}
this.isPublic = entity.isPublic();
this.extraProperties = entity.getExtraProperties() != null ? new org.json.JSONObject(entity.getExtraProperties()).toMap() : null;
//TODO
// this.profile = entity.getProfile() != null ? new Tuple<UUID, String>(entity.getProfile().getId(), entity.getProfile().getLabel()) : null;
// this.organisations = entity.getOrganisations() != null ? entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
// this.researchers = entity.getResearchers() != null ? entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>();
// this.version = entity.getVersion();
// this.groupId = this.groupId == null ? null : entity.getGroupId();
// this.label = entity.getLabel();
// this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null;
// if(entity.getGrant() != null) {
// this.grant = new Grant();
// this.grant.fromDataModel(entity.getGrant());
// }
// else {
// this.grant = null;
// }
// this.creator = new eu.eudat.models.data.userinfo.UserInfo();
// this.groupId = entity.getGroupId();
// this.lockable = entity.getDataset() != null && entity.getDataset().stream().findAny().isPresent();
// if (this.properties != null) {
// this.extraFields = new ArrayList<>();
// this.properties.forEach((id, value) -> {
// if (value != null) {
// ExtraFieldModel extraField = new ExtraFieldModel();
// extraField.setId(id);
// extraField.setValue(value.toString());
// this.extraFields.add(extraField);
// }
// });
// }
// if (entity.getUsers() != null && entity.getUsers().stream().anyMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())))
// this.creator.fromDataModel(entity.getUsers().stream().filter(user -> user.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser());
//
// if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) {
// this.profiles = new LinkedList<>();
// for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) {
// AssociatedProfile associatedProfile = new AssociatedProfile().fromData(dmpDescriptionProfile.getDatasetprofile());
// associatedProfile.setId(dmpDescriptionProfile.getId());
// try {
// associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference<Map<String, Object>>() {}));
// }
// catch (Exception e) {
// associatedProfile.setData(null);
// }
// this.profiles.add(associatedProfile);
// }
// }
// if (entity.getDataset() != null) {
// if (entity.isPublic()) {
// this.datasets = entity.getDataset().stream()
// .filter(dataset -> !dataset.getIsActive().equals(IsActive.Inactive) && !dataset.getStatus().equals(DescriptionStatus.Canceled) && !dataset.getStatus().equals(DescriptionStatus.Draft))
// .map(x -> new DatasetWizardModel().fromDataModelNoDmp(x)).collect(Collectors.toList());
// } else {
// this.datasets = entity.getDataset().stream()
// .filter(dataset -> !dataset.getIsActive().equals(IsActive.Inactive) && !dataset.getStatus().equals(DescriptionStatus.Draft))
// .map(x -> new DatasetWizardModel().fromDataModelNoDmp(x)).collect(Collectors.toList());
// }
// }
// this.modified = entity.getModified();
// this.created = entity.getCreated();
// this.description = entity.getDescription();
// this.status = entity.getStatus();
// this.associatedUsers = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()) : new ArrayList<>();
// this.users = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
// this.dois = entity.getDois() != null ? entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>();
//
// if (entity.getProject() != null) {
// this.project = new Project();
// this.project = new Project().fromDataModel(entity.getProject());
// }
//
// if (entity.getGrant() != null && entity.getGrant().getFunder() != null) {
// this.funder = new Funder();
// this.funder.fromDataModel(entity.getGrant().getFunder());
// }
// this.isPublic = entity.isPublic();
//
// this.extraProperties = entity.getExtraProperties() != null ? new org.json.JSONObject(entity.getExtraProperties()).toMap() : null;
return this;
}
@Override
public DMP toDataModel() throws Exception {
DMP dataManagementPlanEntity = new DMP();
if (this.profile != null) {
DmpBlueprintEntity dmpBlueprint = new DmpBlueprintEntity();
dmpBlueprint.setId(this.profile.getId());
dataManagementPlanEntity.setProfile(dmpBlueprint);
}
dataManagementPlanEntity.setId(this.id);
if (this.organisations != null && !this.organisations.isEmpty())
dataManagementPlanEntity.setOrganisations(new HashSet<>(this.organisations.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
if (this.researchers != null && !this.researchers.isEmpty())
dataManagementPlanEntity.setResearchers(new HashSet<>(this.researchers.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
dataManagementPlanEntity.setVersion(this.version);
dataManagementPlanEntity.setLabel(this.label);
if (this.grant != null) dataManagementPlanEntity.setGrant(this.grant.toDataModel());
dataManagementPlanEntity.setStatus((short) this.status);
dataManagementPlanEntity.setDescription(this.description);
if (this.project != null) {
dataManagementPlanEntity.setProject(this.project.toDataModel());
}
if (this.profiles != null) {
Set<DMPDatasetProfile> dmpDatasetProfiles = new HashSet<>();
for (AssociatedProfile profile : this.profiles) {
DMPDatasetProfile dmpDatasetProfile = new DMPDatasetProfile();
dmpDatasetProfile.setId(profile.getId());
dmpDatasetProfile.setDmp(dataManagementPlanEntity);
dmpDatasetProfile.setDatasetprofile(profile.toData());
dmpDatasetProfile.setData(new ObjectMapper().writeValueAsString(profile.getData()));
dmpDatasetProfiles.add(dmpDatasetProfile);
}
dataManagementPlanEntity.setAssociatedDmps(dmpDatasetProfiles);
}
if(this.extraFields != null) {
this.properties = this.extraFields.stream().collect(Collectors.toMap(ExtraFieldModel::getId, ExtraFieldModel::getValue));
}
dataManagementPlanEntity.setProperties(this.properties != null ? JSONObject.toJSONString(this.properties) : null);
dataManagementPlanEntity.setGroupId(this.groupId != null ? this.groupId : UUID.randomUUID());
dataManagementPlanEntity.setModified(this.modified != null ? this.modified : new Date());
dataManagementPlanEntity.setCreated(this.created != null ? this.created : new Date());
if (this.dynamicFields != null)
dataManagementPlanEntity.setDmpProperties(JSONObject.toJSONString(this.dynamicFields.stream().filter(item -> item.getValue() != null).collect(Collectors.toMap(DynamicFieldWithValue::getId, DynamicFieldWithValue::getValue))));
if (this.isPublic != null) {
dataManagementPlanEntity.setPublic(this.isPublic);
}
dataManagementPlanEntity.setExtraProperties(this.extraProperties != null ? JSONObject.toJSONString(this.extraProperties) : null);
public DmpEntity toDataModel() throws Exception {
DmpEntity dataManagementPlanEntity = new DmpEntity(); //TODO
// if (this.profile != null) {
// DmpBlueprintEntity dmpBlueprint = new DmpBlueprintEntity();
// dmpBlueprint.setId(this.profile.getId());
// dataManagementPlanEntity.setProfile(dmpBlueprint);
// }
// dataManagementPlanEntity.setId(this.id);
// if (this.organisations != null && !this.organisations.isEmpty())
// dataManagementPlanEntity.setOrganisations(new HashSet<>(this.organisations.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
// if (this.researchers != null && !this.researchers.isEmpty())
// dataManagementPlanEntity.setResearchers(new HashSet<>(this.researchers.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
// dataManagementPlanEntity.setVersion(this.version);
// dataManagementPlanEntity.setLabel(this.label);
// if (this.grant != null) dataManagementPlanEntity.setGrant(this.grant.toDataModel());
// dataManagementPlanEntity.setStatus((short) this.status);
// dataManagementPlanEntity.setDescription(this.description);
// if (this.project != null) {
// dataManagementPlanEntity.setProject(this.project.toDataModel());
// }
// if (this.profiles != null) {
// Set<DMPDatasetProfile> dmpDatasetProfiles = new HashSet<>();
// for (AssociatedProfile profile : this.profiles) {
// DMPDatasetProfile dmpDatasetProfile = new DMPDatasetProfile();
// dmpDatasetProfile.setId(profile.getId());
// dmpDatasetProfile.setDmp(dataManagementPlanEntity);
// dmpDatasetProfile.setDatasetprofile(profile.toData());
// dmpDatasetProfile.setData(new ObjectMapper().writeValueAsString(profile.getData()));
// dmpDatasetProfiles.add(dmpDatasetProfile);
// }
// dataManagementPlanEntity.setAssociatedDmps(dmpDatasetProfiles);
// }
// if(this.extraFields != null) {
// this.properties = this.extraFields.stream().collect(Collectors.toMap(ExtraFieldModel::getId, ExtraFieldModel::getValue));
// }
// dataManagementPlanEntity.setProperties(this.properties != null ? JSONObject.toJSONString(this.properties) : null);
// dataManagementPlanEntity.setGroupId(this.groupId != null ? this.groupId : UUID.randomUUID());
// dataManagementPlanEntity.setModified(this.modified != null ? this.modified : new Date());
// dataManagementPlanEntity.setCreated(this.created != null ? this.created : new Date());
// if (this.dynamicFields != null)
// dataManagementPlanEntity.setDmpProperties(JSONObject.toJSONString(this.dynamicFields.stream().filter(item -> item.getValue() != null).collect(Collectors.toMap(DynamicFieldWithValue::getId, DynamicFieldWithValue::getValue))));
//
// if (this.isPublic != null) {
// dataManagementPlanEntity.setPublic(this.isPublic);
// }
//
// dataManagementPlanEntity.setExtraProperties(this.extraProperties != null ? JSONObject.toJSONString(this.extraProperties) : null);
return dataManagementPlanEntity;
}
public DataManagementPlan fromDataModelNoDatasets(DMP entity) {
this.id = entity.getId();
this.profile = entity.getProfile() != null ? new Tuple<UUID, String>(entity.getProfile().getId(), entity.getProfile().getLabel()) : null;
this.organisations = entity.getOrganisations() != null ? entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
this.researchers = entity.getResearchers() != null ? entity.getResearchers().stream().filter(Objects::nonNull).map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
this.version = entity.getVersion();
this.label = entity.getLabel();
this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null;
this.creator = new eu.eudat.models.data.userinfo.UserInfo();
this.groupId = entity.getGroupId();
this.lockable = entity.getDataset() != null && entity.getDataset().stream().findAny().isPresent();
if (this.properties != null) {
this.extraFields = new ArrayList<>();
this.properties.forEach((id, value) -> {
if (value != null) {
ExtraFieldModel extraField = new ExtraFieldModel();
extraField.setId(id);
extraField.setValue(value.toString());
this.extraFields.add(extraField);
}
});
}
if (entity.getUsers() != null && entity.getUsers().stream().anyMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())))
this.creator.fromDataModel(entity.getUsers().stream().filter(user -> user.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser());
if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) {
this.profiles = new LinkedList<>();
for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) {
AssociatedProfile associatedProfile = new AssociatedProfile().fromData(dmpDescriptionProfile.getDatasetprofile());
associatedProfile.setId(dmpDescriptionProfile.getId());
try {
associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference<Map<String, Object>>() {}));
}
catch (Exception e) {
associatedProfile.setData(null);
}
this.profiles.add(associatedProfile);
}
}
this.modified = entity.getModified();
this.created = entity.getCreated();
this.description = entity.getDescription();
this.status = entity.getStatus();
this.associatedUsers = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()) : new ArrayList<>();
this.users = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
this.dois = entity.getDois() != null ? entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>();
if(entity.getGrant() != null) {
this.grant = new Grant();
this.grant.fromDataModel(entity.getGrant());
}
else {
this.grant = null;
}
if (entity.getProject() != null) {
this.project = new Project();
this.project = new Project().fromDataModel(entity.getProject());
}
if (entity.getGrant() != null && entity.getGrant().getFunder() != null) {
this.funder = new Funder();
this.funder.fromDataModel(entity.getGrant().getFunder());
}
this.isPublic = entity.isPublic();
this.extraProperties = entity.getExtraProperties() != null ? new org.json.JSONObject(entity.getExtraProperties()).toMap() : null;
public DataManagementPlan fromDataModelNoDatasets(DmpEntity entity) {
this.id = entity.getId(); //TODO
// this.profile = entity.getProfile() != null ? new Tuple<UUID, String>(entity.getProfile().getId(), entity.getProfile().getLabel()) : null;
// this.organisations = entity.getOrganisations() != null ? entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
// this.researchers = entity.getResearchers() != null ? entity.getResearchers().stream().filter(Objects::nonNull).map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
// this.version = entity.getVersion();
// this.label = entity.getLabel();
// this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null;
// this.creator = new eu.eudat.models.data.userinfo.UserInfo();
// this.groupId = entity.getGroupId();
// this.lockable = entity.getDataset() != null && entity.getDataset().stream().findAny().isPresent();
// if (this.properties != null) {
// this.extraFields = new ArrayList<>();
// this.properties.forEach((id, value) -> {
// if (value != null) {
// ExtraFieldModel extraField = new ExtraFieldModel();
// extraField.setId(id);
// extraField.setValue(value.toString());
// this.extraFields.add(extraField);
// }
// });
// }
// if (entity.getUsers() != null && entity.getUsers().stream().anyMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())))
// this.creator.fromDataModel(entity.getUsers().stream().filter(user -> user.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser());
//
// if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) {
// this.profiles = new LinkedList<>();
// for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) {
// AssociatedProfile associatedProfile = new AssociatedProfile().fromData(dmpDescriptionProfile.getDatasetprofile());
// associatedProfile.setId(dmpDescriptionProfile.getId());
// try {
// associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference<Map<String, Object>>() {}));
// }
// catch (Exception e) {
// associatedProfile.setData(null);
// }
// this.profiles.add(associatedProfile);
// }
// }
// this.modified = entity.getModified();
// this.created = entity.getCreated();
// this.description = entity.getDescription();
// this.status = entity.getStatus();
// this.associatedUsers = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()) : new ArrayList<>();
// this.users = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
// this.dois = entity.getDois() != null ? entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>();
// if(entity.getGrant() != null) {
// this.grant = new Grant();
// this.grant.fromDataModel(entity.getGrant());
// }
// else {
// this.grant = null;
// }
//
// if (entity.getProject() != null) {
// this.project = new Project();
// this.project = new Project().fromDataModel(entity.getProject());
// }
// if (entity.getGrant() != null && entity.getGrant().getFunder() != null) {
// this.funder = new Funder();
// this.funder.fromDataModel(entity.getGrant().getFunder());
// }
// this.isPublic = entity.isPublic();
//
// this.extraProperties = entity.getExtraProperties() != null ? new org.json.JSONObject(entity.getExtraProperties()).toMap() : null;
return this;
}

View File

@ -3,6 +3,7 @@ package eu.eudat.models.data.dmp;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.data.DmpBlueprintEntity;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.old.*;
import eu.eudat.models.DataModel;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
@ -18,7 +19,7 @@ import net.minidev.json.JSONObject;
import java.util.*;
import java.util.stream.Collectors;
public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagementPlanEditorModel> {
public class DataManagementPlanEditorModel implements DataModel<DmpEntity, DataManagementPlanEditorModel> {
private UUID id;
private String label;
private UUID groupId;
@ -223,171 +224,171 @@ public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagem
}
@Override
public DataManagementPlanEditorModel fromDataModel(DMP entity) {
public DataManagementPlanEditorModel fromDataModel(DmpEntity entity) {
this.id = entity.getId();
this.profile = entity.getProfile() != null ? new Tuple<UUID, String>(entity.getProfile().getId(), entity.getProfile().getLabel()) : null;
this.organisations = entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList());
this.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList());
this.version = entity.getVersion();
this.groupId = this.groupId == null ? null : entity.getGroupId();
this.label = entity.getLabel();
this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null;
if (entity.getGrant() != null) {
this.grant = new GrantDMPEditorModel();
this.grant.getExistGrant().fromDataModel(entity.getGrant());
this.grant.getExistGrant().setSource("");
}
this.creator = new eu.eudat.models.data.userinfo.UserInfo();
this.groupId = entity.getGroupId();
this.lockable = entity.getDataset().stream().findAny().isPresent();
if (this.properties != null) {
this.extraFields = new ArrayList<>();
this.properties.forEach((id, value) -> {
ExtraFieldModel extraField = new ExtraFieldModel();
extraField.setId(id);
extraField.setValue(value.toString());
this.extraFields.add(extraField);
});
}
if (entity.getUsers().stream().anyMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())))
this.creator.fromDataModel(entity.getUsers().stream().filter(user -> user.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser());
if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) {
this.profiles = new LinkedList<>();
for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) {
AssociatedProfile associatedProfile = new AssociatedProfile().fromData(dmpDescriptionProfile.getDatasetprofile());
try {
associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference<Map<String, Object>>() {}));
}
catch (Exception e) {
associatedProfile.setData(null);
}
this.profiles.add(associatedProfile);
}
}
this.datasets = entity.getDataset().stream().map(item -> new DatasetWizardModel().fromDataModelNoDmp(item)).collect(Collectors.toList());
this.modified = entity.getModified();
this.created = entity.getCreated();
this.description = entity.getDescription();
this.status = entity.getStatus();
this.project = new ProjectDMPEditorModel();
this.project.getExistProject().fromDataModel(entity.getProject());
this.associatedUsers = entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList());
this.users = entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList());
if (entity.getGrant() != null) {
this.funder = new FunderDMPEditorModel();
this.funder.getExistFunder().fromDataModel(entity.getGrant().getFunder());
}
this.extraProperties = entity.getExtraProperties() != null ? new org.json.JSONObject(entity.getExtraProperties()).toMap() : null;
// this.profile = entity.getProfile() != null ? new Tuple<UUID, String>(entity.getProfile().getId(), entity.getProfile().getLabel()) : null; //TODO
// this.organisations = entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList());
// this.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList());
// this.version = entity.getVersion();
// this.groupId = this.groupId == null ? null : entity.getGroupId();
// this.label = entity.getLabel();
// this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null;
// if (entity.getGrant() != null) {
// this.grant = new GrantDMPEditorModel();
// this.grant.getExistGrant().fromDataModel(entity.getGrant());
// this.grant.getExistGrant().setSource("");
// }
// this.creator = new eu.eudat.models.data.userinfo.UserInfo();
// this.groupId = entity.getGroupId();
// this.lockable = entity.getDataset().stream().findAny().isPresent();
// if (this.properties != null) {
// this.extraFields = new ArrayList<>();
// this.properties.forEach((id, value) -> {
// ExtraFieldModel extraField = new ExtraFieldModel();
// extraField.setId(id);
// extraField.setValue(value.toString());
// this.extraFields.add(extraField);
// });
// }
// if (entity.getUsers().stream().anyMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())))
// this.creator.fromDataModel(entity.getUsers().stream().filter(user -> user.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser());
//
// if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) {
// this.profiles = new LinkedList<>();
// for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) {
// AssociatedProfile associatedProfile = new AssociatedProfile().fromData(dmpDescriptionProfile.getDatasetprofile());
// try {
// associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference<Map<String, Object>>() {}));
// }
// catch (Exception e) {
// associatedProfile.setData(null);
// }
// this.profiles.add(associatedProfile);
// }
// }
// this.datasets = entity.getDataset().stream().map(item -> new DatasetWizardModel().fromDataModelNoDmp(item)).collect(Collectors.toList());
// this.modified = entity.getModified();
// this.created = entity.getCreated();
// this.description = entity.getDescription();
// this.status = entity.getStatus();
// this.project = new ProjectDMPEditorModel();
// this.project.getExistProject().fromDataModel(entity.getProject());
// this.associatedUsers = entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList());
// this.users = entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList());
// if (entity.getGrant() != null) {
// this.funder = new FunderDMPEditorModel();
// this.funder.getExistFunder().fromDataModel(entity.getGrant().getFunder());
// }
// this.extraProperties = entity.getExtraProperties() != null ? new org.json.JSONObject(entity.getExtraProperties()).toMap() : null;
return this;
}
@Override
public DMP toDataModel() throws Exception {
DMP dataManagementPlanEntity = new DMP();
if (this.profile != null) {
DmpBlueprintEntity dmpBlueprint = new DmpBlueprintEntity();
dmpBlueprint.setId(this.profile.getId());
dataManagementPlanEntity.setProfile(dmpBlueprint);
}
dataManagementPlanEntity.setId(this.id);
if (this.organisations != null && !this.organisations.isEmpty())
dataManagementPlanEntity.setOrganisations(new HashSet<>(this.organisations.stream().map(Organisation::toDataModel).collect(Collectors.toList())));
if (this.researchers != null && !this.researchers.isEmpty())
dataManagementPlanEntity.setResearchers(new HashSet<>(this.researchers.stream().map(Researcher::toDataModel).collect(Collectors.toList())));
dataManagementPlanEntity.setVersion(this.version);
dataManagementPlanEntity.setLabel(this.label);
if (this.grant != null) {
if (this.grant.getExistGrant() != null && this.grant.getLabel() == null && this.grant.getDescription() == null)
dataManagementPlanEntity.setGrant(this.grant.getExistGrant().toDataModel());
else if (this.grant.getLabel() != null) {
Grant grant = new Grant();
grant.setId(UUID.randomUUID());
grant.setAbbreviation("");
grant.setLabel(this.grant.getLabel());
grant.setType(Grant.GrantType.INTERNAL.getValue());
grant.setReference("dmp:" + (this.grant.getReference() != null ? this.grant.getReference() : grant.getId()));
grant.setUri("");
grant.setDefinition("");
grant.setCreated(new Date());
grant.setStatus(Grant.Status.ACTIVE.getValue());
grant.setModified(new Date());
grant.setDescription(this.grant.getDescription());
dataManagementPlanEntity.setGrant(grant);
}
}
if (this.funder != null) {
if (this.funder.getLabel() != null) {
Funder funder = new Funder();
funder.setId(UUID.randomUUID());
funder.setLabel(this.funder.getLabel());
funder.setType(Funder.FunderType.INTERNAL.getValue());
funder.setReference("dmp:" + (this.funder.getReference() != null ? this.funder.getReference() : funder.getId()));
funder.setDefinition("");
funder.setCreated(new Date());
funder.setStatus(Funder.Status.ACTIVE.getValue());
funder.setModified(new Date());
dataManagementPlanEntity.getGrant().setFunder(funder);
} else if (this.funder.getExistFunder() != null && this.funder.getLabel() == null){
dataManagementPlanEntity.getGrant().setFunder(this.funder.getExistFunder().toDataModel());
dataManagementPlanEntity.getGrant().getFunder().setType(Funder.FunderType.EXTERNAL.getValue());
}
}
if (this.project != null) {
if (this.project.getExistProject() != null && this.project.getLabel() == null && this.project.getDescription() == null)
dataManagementPlanEntity.setProject(this.project.getExistProject().toDataModel());
else if (this.project.getLabel() != null) {
Project project = new Project();
project.setId(UUID.randomUUID());
project.setAbbreviation("");
project.setLabel(this.project.getLabel());
project.setType(Project.ProjectType.INTERNAL.getValue());
project.setReference("dmp:" + (this.project.getReference() != null ? this.project.getReference() : project.getId()));
project.setUri("");
project.setDefinition("");
project.setCreated(new Date());
project.setStatus(Project.Status.ACTIVE.getValue());
project.setModified(new Date());
project.setDescription(this.project.getDescription());
dataManagementPlanEntity.setProject(project);
}
}
dataManagementPlanEntity.setStatus((short) this.status);
if (this.status == (int) DMP.DMPStatus.FINALISED.getValue()) {
dataManagementPlanEntity.setFinalizedAt(new Date());
}
dataManagementPlanEntity.setDescription(this.description);
if (this.profiles != null) {
Set<DMPDatasetProfile> dmpDatasetProfiles = new HashSet<>();
for (AssociatedProfile profile : this.profiles) {
DMPDatasetProfile dmpDatasetProfile = new DMPDatasetProfile();
dmpDatasetProfile.setId(profile.getId());
dmpDatasetProfile.setDmp(dataManagementPlanEntity);
dmpDatasetProfile.setDatasetprofile(profile.toData());
dmpDatasetProfile.setData(new ObjectMapper().writeValueAsString(profile.getData()));
dmpDatasetProfiles.add(dmpDatasetProfile);
}
dataManagementPlanEntity.setAssociatedDmps(dmpDatasetProfiles);
}
if(this.extraFields != null) {
this.properties = new HashMap<>();
this.extraFields.forEach((extraField) -> this.properties.put(extraField.getId(), extraField.getValue()));
}
dataManagementPlanEntity.setProperties(this.properties != null ? JSONObject.toJSONString(this.properties) : null);
dataManagementPlanEntity.setGroupId(this.groupId != null ? this.groupId : UUID.randomUUID());
dataManagementPlanEntity.setModified(this.modified != null ? this.modified : new Date());
dataManagementPlanEntity.setCreated(this.created != null ? this.created : new Date());
if (this.dynamicFields != null)
dataManagementPlanEntity.setDmpProperties(JSONObject.toJSONString(this.dynamicFields.stream().filter(item -> item.getValue() != null).collect(Collectors.toMap(DynamicFieldWithValue::getId, DynamicFieldWithValue::getValue))));
dataManagementPlanEntity.setExtraProperties(this.extraProperties != null ? JSONObject.toJSONString(this.extraProperties) : null);
public DmpEntity toDataModel() throws Exception {
DmpEntity dataManagementPlanEntity = new DmpEntity();//TODO
// if (this.profile != null) {
// DmpBlueprintEntity dmpBlueprint = new DmpBlueprintEntity();
// dmpBlueprint.setId(this.profile.getId());
// dataManagementPlanEntity.setProfile(dmpBlueprint);
// }
// dataManagementPlanEntity.setId(this.id);
// if (this.organisations != null && !this.organisations.isEmpty())
// dataManagementPlanEntity.setOrganisations(new HashSet<>(this.organisations.stream().map(Organisation::toDataModel).collect(Collectors.toList())));
// if (this.researchers != null && !this.researchers.isEmpty())
// dataManagementPlanEntity.setResearchers(new HashSet<>(this.researchers.stream().map(Researcher::toDataModel).collect(Collectors.toList())));
// dataManagementPlanEntity.setVersion(this.version);
// dataManagementPlanEntity.setLabel(this.label);
// if (this.grant != null) {
// if (this.grant.getExistGrant() != null && this.grant.getLabel() == null && this.grant.getDescription() == null)
// dataManagementPlanEntity.setGrant(this.grant.getExistGrant().toDataModel());
// else if (this.grant.getLabel() != null) {
// Grant grant = new Grant();
// grant.setId(UUID.randomUUID());
// grant.setAbbreviation("");
// grant.setLabel(this.grant.getLabel());
// grant.setType(Grant.GrantType.INTERNAL.getValue());
// grant.setReference("dmp:" + (this.grant.getReference() != null ? this.grant.getReference() : grant.getId()));
// grant.setUri("");
// grant.setDefinition("");
// grant.setCreated(new Date());
// grant.setStatus(Grant.Status.ACTIVE.getValue());
// grant.setModified(new Date());
// grant.setDescription(this.grant.getDescription());
//
// dataManagementPlanEntity.setGrant(grant);
// }
// }
//
// if (this.funder != null) {
// if (this.funder.getLabel() != null) {
// Funder funder = new Funder();
// funder.setId(UUID.randomUUID());
// funder.setLabel(this.funder.getLabel());
// funder.setType(Funder.FunderType.INTERNAL.getValue());
// funder.setReference("dmp:" + (this.funder.getReference() != null ? this.funder.getReference() : funder.getId()));
// funder.setDefinition("");
// funder.setCreated(new Date());
// funder.setStatus(Funder.Status.ACTIVE.getValue());
// funder.setModified(new Date());
//
// dataManagementPlanEntity.getGrant().setFunder(funder);
// } else if (this.funder.getExistFunder() != null && this.funder.getLabel() == null){
// dataManagementPlanEntity.getGrant().setFunder(this.funder.getExistFunder().toDataModel());
// dataManagementPlanEntity.getGrant().getFunder().setType(Funder.FunderType.EXTERNAL.getValue());
// }
// }
//
// if (this.project != null) {
// if (this.project.getExistProject() != null && this.project.getLabel() == null && this.project.getDescription() == null)
// dataManagementPlanEntity.setProject(this.project.getExistProject().toDataModel());
// else if (this.project.getLabel() != null) {
// Project project = new Project();
// project.setId(UUID.randomUUID());
// project.setAbbreviation("");
// project.setLabel(this.project.getLabel());
// project.setType(Project.ProjectType.INTERNAL.getValue());
// project.setReference("dmp:" + (this.project.getReference() != null ? this.project.getReference() : project.getId()));
// project.setUri("");
// project.setDefinition("");
// project.setCreated(new Date());
// project.setStatus(Project.Status.ACTIVE.getValue());
// project.setModified(new Date());
// project.setDescription(this.project.getDescription());
//
// dataManagementPlanEntity.setProject(project);
// }
// }
//
// dataManagementPlanEntity.setStatus((short) this.status);
// if (this.status == (int) DMP.DMPStatus.FINALISED.getValue()) {
// dataManagementPlanEntity.setFinalizedAt(new Date());
// }
// dataManagementPlanEntity.setDescription(this.description);
// if (this.profiles != null) {
// Set<DMPDatasetProfile> dmpDatasetProfiles = new HashSet<>();
// for (AssociatedProfile profile : this.profiles) {
// DMPDatasetProfile dmpDatasetProfile = new DMPDatasetProfile();
// dmpDatasetProfile.setId(profile.getId());
// dmpDatasetProfile.setDmp(dataManagementPlanEntity);
// dmpDatasetProfile.setDatasetprofile(profile.toData());
// dmpDatasetProfile.setData(new ObjectMapper().writeValueAsString(profile.getData()));
// dmpDatasetProfiles.add(dmpDatasetProfile);
// }
// dataManagementPlanEntity.setAssociatedDmps(dmpDatasetProfiles);
// }
// if(this.extraFields != null) {
// this.properties = new HashMap<>();
// this.extraFields.forEach((extraField) -> this.properties.put(extraField.getId(), extraField.getValue()));
// }
// dataManagementPlanEntity.setProperties(this.properties != null ? JSONObject.toJSONString(this.properties) : null);
// dataManagementPlanEntity.setGroupId(this.groupId != null ? this.groupId : UUID.randomUUID());
// dataManagementPlanEntity.setModified(this.modified != null ? this.modified : new Date());
// dataManagementPlanEntity.setCreated(this.created != null ? this.created : new Date());
// if (this.dynamicFields != null)
// dataManagementPlanEntity.setDmpProperties(JSONObject.toJSONString(this.dynamicFields.stream().filter(item -> item.getValue() != null).collect(Collectors.toMap(DynamicFieldWithValue::getId, DynamicFieldWithValue::getValue))));
//
// dataManagementPlanEntity.setExtraProperties(this.extraProperties != null ? JSONObject.toJSONString(this.extraProperties) : null);
return dataManagementPlanEntity;
}

View File

@ -1,7 +1,10 @@
package eu.eudat.models.data.dmp;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.commons.enums.DmpStatus;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.DmpUserEntity;
import eu.eudat.data.old.*;
import eu.eudat.models.DataModel;
import eu.eudat.models.data.dataset.Dataset;
@ -14,13 +17,14 @@ import net.minidev.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.Instant;
import java.util.*;
import java.util.stream.Collectors;
/**
* Created by ikalyvas on 2/5/2018.
*/
public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataManagementPlanNewVersionModel> {
public class DataManagementPlanNewVersionModel implements DataModel<DmpEntity, DataManagementPlanNewVersionModel> {
private static final Logger logger = LoggerFactory.getLogger(DataManagementPlanNewVersionModel.class);
private UUID id;
@ -162,112 +166,112 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
}
@Override
public DataManagementPlanNewVersionModel fromDataModel(DMP entity) {
public DataManagementPlanNewVersionModel fromDataModel(DmpEntity entity) {
return null;
}
@Override
public DMP toDataModel() throws Exception {
DMP entity = new DMP();
public DmpEntity toDataModel() throws Exception {
DmpEntity entity = new DmpEntity();
entity.setId(this.id);
// entity.setUsers(new HashSet<>(new ArrayList<>(this.associatedUsers)));
entity.setDescription(this.description);
entity.setStatus((short) this.status);
entity.setStatus(DmpStatus.of((short)this.status));
entity.setGroupId(this.groupId == null ? UUID.randomUUID() : this.groupId);
entity.setCreated(new Date());
entity.setCreatedAt(Instant.now());
entity.setUpdatedAt(Instant.now());
entity.setLabel(this.label);
entity.setModified(new Date());
List<DescriptionEntity> descriptionEntities = new LinkedList<>();
if (this.datasets != null) {
for (Dataset dataset : this.datasets) {
DescriptionEntity entityDescriptionEntity = new DescriptionEntity();
entityDescriptionEntity.setId(dataset.getId());
descriptionEntities.add(entityDescriptionEntity);
}
entity.setDataset(new HashSet<>(descriptionEntities));
}
if (this.organisations != null && !this.organisations.isEmpty())
entity.setOrganisations(new HashSet<>(this.organisations.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
if (this.researchers != null && !this.researchers.isEmpty())
entity.setResearchers(new HashSet<>(this.researchers.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
/*if (this.grant != null) {
entity.setGrant(this.grant.toDataModel());
}*/
List<DescriptionEntity> descriptionEntities = new LinkedList<>();//TODO
// if (this.datasets != null) {
// for (Dataset dataset : this.datasets) {
// DescriptionEntity entityDescriptionEntity = new DescriptionEntity();
// entityDescriptionEntity.setId(dataset.getId());
// descriptionEntities.add(entityDescriptionEntity);
// }
// entity.setDataset(new HashSet<>(descriptionEntities));
// }
// if (this.organisations != null && !this.organisations.isEmpty())
// entity.setOrganisations(new HashSet<>(this.organisations.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
// if (this.researchers != null && !this.researchers.isEmpty())
// entity.setResearchers(new HashSet<>(this.researchers.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
// /*if (this.grant != null) {
// entity.setGrant(this.grant.toDataModel());
// }*/
//
// if (this.grant != null) {
// if (this.grant.getExistGrant() != null && this.grant.getLabel() == null && this.grant.getDescription() == null)
// entity.setGrant(this.grant.getExistGrant().toDataModel());
// else if (this.grant.getLabel() != null) {
// Grant grant = new Grant();
// grant.setId(UUID.randomUUID());
// grant.setAbbreviation("");
// grant.setLabel(this.grant.getLabel());
// grant.setType(Grant.GrantType.INTERNAL.getValue());
// grant.setReference("dmp:" + (this.grant.getReference() != null ? this.grant.getReference() : grant.getId()));
// grant.setUri("");
// grant.setDefinition("");
// grant.setCreated(new Date());
// grant.setStatus(Grant.Status.ACTIVE.getValue());
// grant.setModified(new Date());
// grant.setDescription(this.grant.getDescription());
//
// entity.setGrant(grant);
// }
// }
//
// if (this.funder != null) {
// if (this.funder.getLabel() != null) {
// Funder funder = new Funder();
// funder.setId(UUID.randomUUID());
// funder.setLabel(this.funder.getLabel());
// funder.setType(Funder.FunderType.INTERNAL.getValue());
// funder.setReference("dmp:" + (this.funder.getReference() != null ? this.funder.getReference() : funder.getId()));
// funder.setDefinition("");
// funder.setCreated(new Date());
// funder.setStatus(Funder.Status.ACTIVE.getValue());
// funder.setModified(new Date());
//
// entity.getGrant().setFunder(funder);
// } else if (this.funder.getExistFunder() != null && this.funder.getLabel() == null) {
// entity.getGrant().setFunder(this.funder.getExistFunder().toDataModel());
// entity.getGrant().getFunder().setType(Funder.FunderType.EXTERNAL.getValue());
// }
// }
if (this.grant != null) {
if (this.grant.getExistGrant() != null && this.grant.getLabel() == null && this.grant.getDescription() == null)
entity.setGrant(this.grant.getExistGrant().toDataModel());
else if (this.grant.getLabel() != null) {
Grant grant = new Grant();
grant.setId(UUID.randomUUID());
grant.setAbbreviation("");
grant.setLabel(this.grant.getLabel());
grant.setType(Grant.GrantType.INTERNAL.getValue());
grant.setReference("dmp:" + (this.grant.getReference() != null ? this.grant.getReference() : grant.getId()));
grant.setUri("");
grant.setDefinition("");
grant.setCreated(new Date());
grant.setStatus(Grant.Status.ACTIVE.getValue());
grant.setModified(new Date());
grant.setDescription(this.grant.getDescription());
entity.setGrant(grant);
}
}
if (this.funder != null) {
if (this.funder.getLabel() != null) {
Funder funder = new Funder();
funder.setId(UUID.randomUUID());
funder.setLabel(this.funder.getLabel());
funder.setType(Funder.FunderType.INTERNAL.getValue());
funder.setReference("dmp:" + (this.funder.getReference() != null ? this.funder.getReference() : funder.getId()));
funder.setDefinition("");
funder.setCreated(new Date());
funder.setStatus(Funder.Status.ACTIVE.getValue());
funder.setModified(new Date());
entity.getGrant().setFunder(funder);
} else if (this.funder.getExistFunder() != null && this.funder.getLabel() == null) {
entity.getGrant().setFunder(this.funder.getExistFunder().toDataModel());
entity.getGrant().getFunder().setType(Funder.FunderType.EXTERNAL.getValue());
}
}
if (this.project != null) {
if (this.project.getExistProject() != null && this.project.getLabel() == null && this.project.getDescription() == null)
entity.setProject(this.project.getExistProject().toDataModel());
else if (this.project.getLabel() != null) {
Project project = new Project();
project.setId(UUID.randomUUID());
project.setAbbreviation("");
project.setLabel(this.project.getLabel());
project.setType(Project.ProjectType.INTERNAL.getValue());
project.setReference("dmp:" + (this.project.getReference() != null ? this.project.getReference() : project.getId()));
project.setUri("");
project.setDefinition("");
project.setCreated(new Date());
project.setStatus(Project.Status.ACTIVE.getValue());
project.setModified(new Date());
project.setDescription(this.project.getDescription());
entity.setProject(project);
}
}
entity.setExtraProperties(this.extraProperties != null ? JSONObject.toJSONString(this.extraProperties) : null);
if (this.profiles != null) {
Set<DMPDatasetProfile> dmpDatasetProfiles = new HashSet<>();
for (AssociatedProfile profile : this.profiles) {
DMPDatasetProfile dmpDatasetProfile = new DMPDatasetProfile();
dmpDatasetProfile.setId(null);
dmpDatasetProfile.setDmp(entity);
dmpDatasetProfile.setDatasetprofile(profile.toData());
dmpDatasetProfile.setData(new ObjectMapper().writeValueAsString(profile.getData()));
dmpDatasetProfiles.add(dmpDatasetProfile);
}
entity.setAssociatedDmps(dmpDatasetProfiles);
}
// if (this.project != null) {
// if (this.project.getExistProject() != null && this.project.getLabel() == null && this.project.getDescription() == null)
// entity.setProject(this.project.getExistProject().toDataModel());
// else if (this.project.getLabel() != null) {
// Project project = new Project();
// project.setId(UUID.randomUUID());
// project.setAbbreviation("");
// project.setLabel(this.project.getLabel());
// project.setType(Project.ProjectType.INTERNAL.getValue());
// project.setReference("dmp:" + (this.project.getReference() != null ? this.project.getReference() : project.getId()));
// project.setUri("");
// project.setDefinition("");
// project.setCreated(new Date());
// project.setStatus(Project.Status.ACTIVE.getValue());
// project.setModified(new Date());
// project.setDescription(this.project.getDescription());
//
// entity.setProject(project);
// }
// }
//
// entity.setExtraProperties(this.extraProperties != null ? JSONObject.toJSONString(this.extraProperties) : null);
// if (this.profiles != null) {
// Set<DMPDatasetProfile> dmpDatasetProfiles = new HashSet<>();
// for (AssociatedProfile profile : this.profiles) {
// DMPDatasetProfile dmpDatasetProfile = new DMPDatasetProfile();
// dmpDatasetProfile.setId(null);
// dmpDatasetProfile.setDmp(entity);
// dmpDatasetProfile.setDatasetprofile(profile.toData());
// dmpDatasetProfile.setData(new ObjectMapper().writeValueAsString(profile.getData()));
// dmpDatasetProfiles.add(dmpDatasetProfile);
// }
// entity.setAssociatedDmps(dmpDatasetProfiles);
// }
return entity;
}

View File

@ -190,7 +190,7 @@ public class GrantListingModel implements DataModel<eu.eudat.data.old.Grant, Gra
this.modified = entity.getModified();
this.description = entity.getDescription();
this.files = entity.getContent() != null ? Arrays.asList(new ContentFile(entity.getContent().getLabel(), UUID.fromString(entity.getContent().getUri().split(":")[1]), "final", entity.getContent().getExtension())) : Arrays.asList(new ContentFile("default.png", null, null, null));
this.dmps = entity.getDmps().stream().map(item -> new DataManagementPlanUrlListing().fromDataModel(item)).collect(Collectors.toList());
//this.dmps = entity.getDmps().stream().map(item -> new DataManagementPlanUrlListing().fromDataModel(item)).collect(Collectors.toList()); //TODO
return this;
}

View File

@ -1,6 +1,6 @@
package eu.eudat.models.data.listingmodels;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.old.Grant;
import eu.eudat.models.DataModel;
import eu.eudat.models.data.urls.DatasetUrlListing;
@ -12,7 +12,7 @@ import java.util.UUID;
import java.util.stream.Collectors;
public class DataManagementPlanListingModel implements DataModel<DMP, DataManagementPlanListingModel> {
public class DataManagementPlanListingModel implements DataModel<DmpEntity, DataManagementPlanListingModel> {
private String id;
private String label;
private String grant;
@ -120,66 +120,66 @@ public class DataManagementPlanListingModel implements DataModel<DMP, DataManage
}
@Override
public DataManagementPlanListingModel fromDataModel(DMP entity) {
public DataManagementPlanListingModel fromDataModel(DmpEntity entity) {
this.id = entity.getId().toString();
this.label = entity.getLabel();
this.groupId = entity.getGroupId();
return this;
}
public DataManagementPlanListingModel fromDataModelAssociatedProfiles(DMP entity) {
public DataManagementPlanListingModel fromDataModelAssociatedProfiles(DmpEntity entity) {
this.id = entity.getId().toString();
this.label = entity.getLabel();
this.groupId = entity.getGroupId();
this.creationTime = entity.getCreated();
this.creationTime = Date.from(entity.getCreatedAt());
return this;
}
public DataManagementPlanListingModel fromDataModelAutoComplete(DMP entity) {
public DataManagementPlanListingModel fromDataModelAutoComplete(DmpEntity entity) {
this.id = entity.getId().toString();
this.label = entity.getLabel();
this.groupId = entity.getGroupId();
this.creationTime = entity.getCreated();
this.creationTime = Date.from(entity.getCreatedAt());
return this;
}
public DataManagementPlanListingModel fromDataModelDatasets(DMP entity) {
public DataManagementPlanListingModel fromDataModelDatasets(DmpEntity entity) {
this.fromDataModel(entity);
this.status = entity.getStatus();
this.status = entity.getStatus().getValue();
this.version = entity.getVersion();
this.grant = (entity.getGrant() != null) ? entity.getGrant().getLabel() : null;
this.creationTime = entity.getCreated();
this.modifiedTime = entity.getModified();
this.datasets = entity.getDataset().stream().map(x-> new DatasetUrlListing().fromDataModel(x)).collect(Collectors.toList());
this.users = entity.getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList());
this.finalizedAt = entity.getFinalizedAt();
this.isPublic = entity.isPublic();
this.publishedAt = entity.getPublishedAt();
this.creationTime = Date.from(entity.getCreatedAt());
this.modifiedTime = Date.from(entity.getUpdatedAt());
this.finalizedAt = Date.from(entity.getFinalizedAt());
// this.grant = (entity.getGrant() != null) ? entity.getGrant().getLabel() : null; //TODO
// this.datasets = entity.getDataset().stream().map(x-> new DatasetUrlListing().fromDataModel(x)).collect(Collectors.toList());
// this.users = entity.getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList());
// this.isPublic = entity.isPublic();
// this.publishedAt = entity.getPublishedAt();
return this;
}
@Override
public DMP toDataModel() {
DMP entity = new DMP();
public DmpEntity toDataModel() {
DmpEntity entity = new DmpEntity();
entity.setId(UUID.fromString(this.getId()));
entity.setLabel(this.getLabel());
entity.setGroupId(this.getGroupId());
entity.setStatus(Integer.valueOf(this.getStatus()).shortValue());
entity.setCreated(this.getCreationTime());
entity.setFinalizedAt(this.getFinalizedAt());
entity.setModified(this.getModifiedTime());
entity.setPublic(this.getPublic());
entity.setPublishedAt(this.getPublishedAt());
entity.setVersion(this.getVersion());
entity.setDataset(this.getDatasets().stream().map(DatasetUrlListing::toDataModel).collect(Collectors.toCollection(LinkedHashSet::new)));
if (this.getGrant() != null && !this.getGrant().isEmpty()) {
Grant grant = new Grant();
grant.setLabel(this.getGrant());
entity.setGrant(grant);
}
entity.setUsers(this.getUsers().stream().map(UserInfoListingModel::toDataModel).collect(Collectors.toSet()));
// entity.setStatus(Integer.valueOf(this.getStatus()).shortValue()); //TODO
// entity.setCreated(this.getCreationTime());
// entity.setFinalizedAt(this.getFinalizedAt());
// entity.setModified(this.getModifiedTime());
// entity.setPublic(this.getPublic());
// entity.setPublishedAt(this.getPublishedAt());
// entity.setVersion(this.getVersion());
//
// entity.setDataset(this.getDatasets().stream().map(DatasetUrlListing::toDataModel).collect(Collectors.toCollection(LinkedHashSet::new)));
// if (this.getGrant() != null && !this.getGrant().isEmpty()) {
// Grant grant = new Grant();
// grant.setLabel(this.getGrant());
// entity.setGrant(grant);
// }
// entity.setUsers(this.getUsers().stream().map(UserInfoListingModel::toDataModel).collect(Collectors.toSet()));
return entity;
}

View File

@ -4,8 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.old.DMP;
import eu.eudat.data.old.DMPDatasetProfile;
import eu.eudat.data.DmpEntity;
import eu.eudat.model.doi.Doi;
import eu.eudat.models.DataModel;
import eu.eudat.models.data.dataset.DatasetOverviewModel;
@ -14,10 +13,11 @@ import eu.eudat.models.data.dmp.Organisation;
import eu.eudat.models.data.dmp.Researcher;
import eu.eudat.models.data.grant.GrantOverviewModel;
import java.time.Instant;
import java.util.*;
import java.util.stream.Collectors;
public class DataManagementPlanOverviewModel implements DataModel<DMP, DataManagementPlanOverviewModel> {
public class DataManagementPlanOverviewModel implements DataModel<DmpEntity, DataManagementPlanOverviewModel> {
private String id;
private String label;
private String profile;
@ -173,62 +173,62 @@ public class DataManagementPlanOverviewModel implements DataModel<DMP, DataManag
}
@Override
public DataManagementPlanOverviewModel fromDataModel(DMP entity) {
public DataManagementPlanOverviewModel fromDataModel(DmpEntity entity) {
this.id = entity.getId().toString();
this.label = entity.getLabel();
this.groupId = entity.getGroupId();
this.status = entity.getStatus();
if (entity.getResearchers() != null) {
this.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList());
}
if(entity.getDois() != null){
this.dois = entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList());
}
this.status = entity.getStatus().getValue();
// if (entity.getResearchers() != null) { //TODO
// this.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList());
// }
// if(entity.getDois() != null){
// this.dois = entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList());
// }
return this;
}
public DataManagementPlanOverviewModel fromDataModelDatasets(DMP entity) {
public DataManagementPlanOverviewModel fromDataModelDatasets(DmpEntity entity) {
this.fromDataModel(entity);
this.version = entity.getVersion();
if (entity.getGrant() != null) this.grant = new GrantOverviewModel().fromDataModel(entity.getGrant());
if (entity.getProfile() != null) this.profile = entity.getProfile().getLabel();
this.creationTime = entity.getCreated();
this.modifiedTime = entity.getModified();
this.finalizedAt = entity.getFinalizedAt();
this.organisations = entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList());
this.datasets = entity.getDataset().stream().filter(dataset -> !dataset.getIsActive().equals(IsActive.Inactive) && !dataset.getStatus().equals(DescriptionStatus.Canceled)).map(x-> new DatasetOverviewModel().fromDataModel(x)).collect(Collectors.toList());
this.users = entity.getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList());
this.description = entity.getDescription();
if (entity.getResearchers() != null) {
this.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList());
}
if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) {
this.associatedProfiles = new LinkedList<>();
for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) {
AssociatedProfile associatedProfile = new AssociatedProfile().fromData(dmpDescriptionProfile.getDatasetprofile());
try {
associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference<Map<String, Object>>() {}));
}
catch (Exception e) {
associatedProfile.setData(null);
}
this.associatedProfiles.add(associatedProfile);
}
}
this.isPublic = entity.isPublic();
this.publishedAt = entity.getPublishedAt();
if (entity.getDois() != null) {
this.dois = entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList());
} else {
this.dois = new ArrayList<>();
}
// if (entity.getGrant() != null) this.grant = new GrantOverviewModel().fromDataModel(entity.getGrant());
// if (entity.getProfile() != null) this.profile = entity.getProfile().getLabel();
this.creationTime = Date.from(entity.getCreatedAt());
this.modifiedTime = Date.from(entity.getUpdatedAt());
this.finalizedAt = Date.from(entity.getFinalizedAt());
// this.organisations = entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList());
// this.datasets = entity.getDataset().stream().filter(dataset -> !dataset.getIsActive().equals(IsActive.Inactive) && !dataset.getStatus().equals(DescriptionStatus.Canceled)).map(x-> new DatasetOverviewModel().fromDataModel(x)).collect(Collectors.toList());
// this.users = entity.getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList());
// this.description = entity.getDescription();
// if (entity.getResearchers() != null) {
// this.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList());
// }
//
// if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) {
// this.associatedProfiles = new LinkedList<>();
// for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) {
// AssociatedProfile associatedProfile = new AssociatedProfile().fromData(dmpDescriptionProfile.getDatasetprofile());
// try {
// associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference<Map<String, Object>>() {}));
// }
// catch (Exception e) {
// associatedProfile.setData(null);
// }
// this.associatedProfiles.add(associatedProfile);
// }
// }
// this.isPublic = entity.isPublic();
// this.publishedAt = entity.getPublishedAt();
// if (entity.getDois() != null) {
// this.dois = entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList());
// } else {
// this.dois = new ArrayList<>();
// }
return this;
}
@Override
public DMP toDataModel() {
public DmpEntity toDataModel() {
return null;
}

View File

@ -1,18 +1,12 @@
package eu.eudat.models.data.listingmodels;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.old.Grant;
import eu.eudat.models.DataModel;
import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
public class DatasetListingModel implements DataModel<DescriptionEntity, DatasetListingModel> {

View File

@ -1,12 +1,14 @@
package eu.eudat.models.data.listingmodels;
import eu.eudat.data.old.UserDMP;
import eu.eudat.commons.enums.DmpUserRole;
import eu.eudat.data.DmpUserEntity;
import eu.eudat.data.old.UserInfo;
import eu.eudat.model.DmpUser;
import eu.eudat.models.DataModel;
import java.util.UUID;
public class UserInfoListingModel implements DataModel<UserDMP, UserInfoListingModel> {
public class UserInfoListingModel implements DataModel<DmpUserEntity, UserInfoListingModel> {
private UUID id;
private String name;
@ -42,23 +44,23 @@ public class UserInfoListingModel implements DataModel<UserDMP, UserInfoListingM
}
@Override
public UserInfoListingModel fromDataModel(UserDMP entity) {
this.id = entity.getUser().getId();
this.name = entity.getUser().getName();
this.role = entity.getRole();
this.email = entity.getUser().getEmail();
public UserInfoListingModel fromDataModel(DmpUserEntity entity) {
// this.id = entity.getUser().getId(); //TODO
// this.name = entity.getUser().getName();
// this.role = entity.getRole();
// this.email = entity.getUser().getEmail();
return this;
}
@Override
public UserDMP toDataModel() {
UserDMP entity = new UserDMP();
public DmpUserEntity toDataModel() {
DmpUserEntity entity = new DmpUserEntity();
entity.setId(this.getId());
entity.setRole(this.getRole());
entity.setRole(DmpUserRole.of((short) this.getRole()));
UserInfo userInfo = new UserInfo();
userInfo.setName(this.getName());
userInfo.setEmail(this.getEmail());
entity.setUser(userInfo);
// entity.setUser(userInfo);
return entity;
}

View File

@ -1,9 +1,9 @@
package eu.eudat.models.data.listingmodels;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DmpEntity;
import eu.eudat.models.DataModel;
public class VersionListingModel implements DataModel<DMP, VersionListingModel> {
public class VersionListingModel implements DataModel<DmpEntity, VersionListingModel> {
private String id;
private String groupId;
private Integer version;
@ -34,15 +34,15 @@ public class VersionListingModel implements DataModel<DMP, VersionListingModel>
}
@Override
public VersionListingModel fromDataModel(DMP entity) {
public VersionListingModel fromDataModel(DmpEntity entity) {
this.id = entity.getId().toString();
this.groupId = entity.getGroupId().toString();
this.version = entity.getVersion();
this.version = entity.getVersion().intValue();
return this;
}
@Override
public DMP toDataModel() throws Exception {
public DmpEntity toDataModel() throws Exception {
return null;
}

View File

@ -2,10 +2,9 @@ package eu.eudat.models.data.rda;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.EntityDoiEntity;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.old.UserDMP;
import eu.eudat.logic.managers.DatasetManager;
import java.text.SimpleDateFormat;
@ -128,46 +127,47 @@ public class DmpRDAExportModel {
this.title = title;
}
public DmpRDAExportModel fromDataModel(DMP entity, DatasetManager datasetManager) {
public DmpRDAExportModel fromDataModel(DmpEntity entity, DatasetManager datasetManager) {
DmpRDAExportModel dmpRda = new DmpRDAExportModel();
dmpRda.contact = new ContactRDAExportModel().fromDataModel(entity.getUsers().stream().filter(x -> x.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser());
if (entity.getUsers().stream().anyMatch(x -> x.getRole().equals(UserDMP.UserDMPRoles.USER.getValue()))) {
dmpRda.contributor = new LinkedList<>();
for (UserDMP userdmp : entity.getUsers().stream().filter(x -> x.getRole().equals(UserDMP.UserDMPRoles.USER.getValue())).collect(Collectors.toList())) {
dmpRda.contributor.add(new DmpContributorRDAExportModel().fromDataModel(userdmp.getUser(), UserDMP.UserDMPRoles.fromInteger(userdmp.getRole()).toString()));
}
}
dmpRda.cost = null;
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
dmpRda.created = formatter.format(entity.getCreated());
dmpRda.dataset = new LinkedList<>();
for (DescriptionEntity descriptionEntity : entity.getDataset()) {
if (descriptionEntity.getIsActive() != IsActive.Inactive && descriptionEntity.getStatus() != DescriptionStatus.Canceled)
dmpRda.dataset.add(new DatasetRDAExportModel().fromDataModel(descriptionEntity, datasetManager));
}
dmpRda.description = entity.getDescription().replace("\n", " ");
if (entity.getDois() != null && !entity.getDois().isEmpty()) {
boolean zenodoDoi = false;
for(EntityDoiEntity doi: entity.getDois()){
if(doi.getRepositoryId().equals("Zenodo")){
dmpRda.dmp_id = new IdRDAExportModel(doi.getDoi(), "zenodo");
zenodoDoi = true;
}
}
if(!zenodoDoi){
dmpRda.dmp_id = new IdRDAExportModel(entity.getId().toString(), "other");
}
}
else {
dmpRda.dmp_id = new IdRDAExportModel(entity.getId().toString(), "other");
}
// Mock up data on "language" and "ethical_issues_*" for now.
dmpRda.ethical_issues_exist = "unknown";
dmpRda.language = "en";
dmpRda.modified = formatter.format(new Date());
if (entity.getGrant() != null) {
dmpRda.project = new ProjectRDAExportModel().fromDataModel(entity.getGrant());
}
//TODO
// dmpRda.contact = new ContactRDAExportModel().fromDataModel(entity.getUsers().stream().filter(x -> x.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser());
// if (entity.getUsers().stream().anyMatch(x -> x.getRole().equals(UserDMP.UserDMPRoles.USER.getValue()))) {
// dmpRda.contributor = new LinkedList<>();
// for (UserDMP userdmp : entity.getUsers().stream().filter(x -> x.getRole().equals(UserDMP.UserDMPRoles.USER.getValue())).collect(Collectors.toList())) {
// dmpRda.contributor.add(new DmpContributorRDAExportModel().fromDataModel(userdmp.getUser(), UserDMP.UserDMPRoles.fromInteger(userdmp.getRole()).toString()));
// }
// }
// dmpRda.cost = null;
// SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
// dmpRda.created = formatter.format(entity.getCreated());
// dmpRda.dataset = new LinkedList<>();
// for (DescriptionEntity descriptionEntity : entity.getDataset()) {
// if (descriptionEntity.getIsActive() != IsActive.Inactive && descriptionEntity.getStatus() != DescriptionStatus.Canceled)
// dmpRda.dataset.add(new DatasetRDAExportModel().fromDataModel(descriptionEntity, datasetManager));
// }
// dmpRda.description = entity.getDescription().replace("\n", " ");
// if (entity.getDois() != null && !entity.getDois().isEmpty()) {
// boolean zenodoDoi = false;
// for(EntityDoiEntity doi: entity.getDois()){
// if(doi.getRepositoryId().equals("Zenodo")){
// dmpRda.dmp_id = new IdRDAExportModel(doi.getDoi(), "zenodo");
// zenodoDoi = true;
// }
// }
// if(!zenodoDoi){
// dmpRda.dmp_id = new IdRDAExportModel(entity.getId().toString(), "other");
// }
// }
// else {
// dmpRda.dmp_id = new IdRDAExportModel(entity.getId().toString(), "other");
// }
// // Mock up data on "language" and "ethical_issues_*" for now.
// dmpRda.ethical_issues_exist = "unknown";
// dmpRda.language = "en";
// dmpRda.modified = formatter.format(new Date());
// if (entity.getGrant() != null) {
// dmpRda.project = new ProjectRDAExportModel().fromDataModel(entity.getGrant());
// }
dmpRda.title = entity.getLabel();
return dmpRda;

View File

@ -1,6 +1,6 @@
package eu.eudat.models.data.rda;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DmpEntity;
import eu.eudat.logic.managers.DatasetManager;
public class RDAExportModel {
@ -13,7 +13,7 @@ public class RDAExportModel {
this.dmp = dmp;
}
public RDAExportModel fromDataModel(DMP dmp, DatasetManager datasetManager) {
public RDAExportModel fromDataModel(DmpEntity dmp, DatasetManager datasetManager) {
this.dmp = new DmpRDAExportModel().fromDataModel(dmp, datasetManager);
return this;
}

View File

@ -1,21 +1,21 @@
package eu.eudat.models.data.urls;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DmpEntity;
/**
* Created by ikalyvas on 3/19/2018.
*/
public class DataManagementPlanUrlListing extends UrlListing<DMP, DataManagementPlanUrlListing> {
public class DataManagementPlanUrlListing extends UrlListing<DmpEntity, DataManagementPlanUrlListing> {
@Override
public DataManagementPlanUrlListing fromDataModel(DMP entity) {
public DataManagementPlanUrlListing fromDataModel(DmpEntity entity) {
this.setLabel(entity.getLabel());
this.setUrl(entity.getId().toString());
return this;
}
@Override
public DMP toDataModel() throws Exception {
public DmpEntity toDataModel() throws Exception {
return null;
}

View File

@ -1,8 +1,8 @@
package eu.eudat.models.rda.mapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.data.DmpUserEntity;
import eu.eudat.data.old.Researcher;
import eu.eudat.data.old.UserDMP;
import eu.eudat.models.rda.Contributor;
import eu.eudat.models.rda.ContributorId;
import org.slf4j.Logger;
@ -14,15 +14,15 @@ import java.util.*;
public class ContributorRDAMapper {
private static final Logger logger = LoggerFactory.getLogger(ContributorRDAMapper.class);
public static Contributor toRDA(UserDMP userDMP) {
public static Contributor toRDA(DmpUserEntity userDMP) {
Contributor rda = new Contributor();
rda.setContributorId(ContributorIdRDAMapper.toRDA(userDMP.getUser().getId()));
if (userDMP.getUser().getName() == null) {
throw new IllegalArgumentException("Contributor Name is missing");
}
rda.setName(userDMP.getUser().getName());
rda.setMbox(userDMP.getUser().getEmail());
rda.setRole(new HashSet<>(Arrays.asList(UserDMP.UserDMPRoles.fromInteger(userDMP.getRole()).name())));
rda.setContributorId(ContributorIdRDAMapper.toRDA(userDMP.getUser()));
// if (userDMP.getUser().getName() == null) { //TODO
// throw new IllegalArgumentException("Contributor Name is missing");
// }
// rda.setName(userDMP.getUser().getName());
// rda.setMbox(userDMP.getUser().getEmail());
// rda.setRole(new HashSet<>(Arrays.asList(UserDMP.UserDMPRoles.fromInteger(userDMP.getRole()).name())));
return rda;
}

View File

@ -2,6 +2,8 @@ package eu.eudat.models.rda.mapper;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.data.DmpDescriptionTemplateEntity;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.EntityDoiEntity;
import eu.eudat.data.old.*;
import eu.eudat.logic.services.ApiContext;
@ -39,155 +41,155 @@ public class DmpRDAMapper {
}
@Transactional
public Dmp toRDA(DMP dmp) throws InvalidApplicationException {
if (dmp.getDataset() == null || dmp.getDataset().isEmpty()) {
throw new IllegalArgumentException("DMP has no Datasets");
}
Map<String, Object> extraProperties;
if (dmp.getExtraProperties() == null) {
throw new IllegalArgumentException("DMP is missing language and contact properties");
} else {
extraProperties = new org.json.JSONObject(dmp.getExtraProperties()).toMap();
/*if (extraProperties.get("language") == null) {
throw new IllegalArgumentException("DMP must have it's language property defined");
}*/
if (extraProperties.get("contact") == null) {
throw new IllegalArgumentException("DMP must have it's contact property defined");
}
}
public Dmp toRDA(DmpEntity dmp) throws InvalidApplicationException {
// if (dmp.getDataset() == null || dmp.getDataset().isEmpty()) { //TODO
// throw new IllegalArgumentException("DMP has no Datasets");
// }
// Map<String, Object> extraProperties;
// if (dmp.getExtraProperties() == null) {
// throw new IllegalArgumentException("DMP is missing language and contact properties");
// } else {
// extraProperties = new org.json.JSONObject(dmp.getExtraProperties()).toMap();
// /*if (extraProperties.get("language") == null) {
// throw new IllegalArgumentException("DMP must have it's language property defined");
// }*/
// if (extraProperties.get("contact") == null) {
// throw new IllegalArgumentException("DMP must have it's contact property defined");
// }
// }
Dmp rda = new Dmp();
if (dmp.getDois() != null && !dmp.getDois().isEmpty()) {
for(EntityDoiEntity doi: dmp.getDois()){
if(doi.getRepositoryId().equals("Zenodo")){
rda.setDmpId(DmpIdRDAMapper.toRDA(doi.getDoi()));
}
}
} else {
rda.setDmpId(DmpIdRDAMapper.toRDA(dmp.getId()));
}
if (dmp.getCreated() == null) {
// if (dmp.getDois() != null && !dmp.getDois().isEmpty()) {
// for(EntityDoiEntity doi: dmp.getDois()){
// if(doi.getRepositoryId().equals("Zenodo")){
// rda.setDmpId(DmpIdRDAMapper.toRDA(doi.getDoi()));
// }
// }
// } else {
// rda.setDmpId(DmpIdRDAMapper.toRDA(dmp.getId()));
// }
if (dmp.getCreatedAt() == null) {
throw new IllegalArgumentException("DMP Created is missing");
}
if (dmp.getModified() == null) {
if (dmp.getUpdatedAt() == null) {
throw new IllegalArgumentException("DMP Modified is missing");
}
if (dmp.getLabel() == null) {
throw new IllegalArgumentException("DMP Label is missing");
}
rda.setCreated(dmp.getCreated());
rda.setDescription(dmp.getDescription());
rda.setModified(dmp.getModified());
rda.setTitle(dmp.getLabel());
if (!extraProperties.isEmpty()) {
if (extraProperties.get("ethicalIssues") != null) {
rda.setEthicalIssuesExist(Dmp.EthicalIssuesExist.fromValue(extraProperties.get("ethicalIssues").toString()));
} else {
rda.setEthicalIssuesExist(Dmp.EthicalIssuesExist.UNKNOWN);
}
rda.setLanguage(LanguageRDAMapper.mapLanguageIsoToRDAIso(extraProperties.get("language") != null ? extraProperties.get("language").toString() : "en"));
if (extraProperties.get("costs") != null) {
rda.setCost(new ArrayList<>());
((List) extraProperties.get("costs")).forEach(costl -> {
rda.getCost().add(CostRDAMapper.toRDA((Map)costl));
});
}
try {
UserInfo contactDb = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(UUID.fromString((String) extraProperties.get("contact")));
UserInfo contact = new UserInfo();
contact.setId(contactDb.getId());
contact.setName(contactDb.getName());
contact.setEmail(contactDb.getEmail());
if (contact.getEmail() == null) {
for (UserDMP userDMP : dmp.getUsers()) {
if (userDMP.getDmp().getId() == dmp.getId() && userDMP.getUser().getEmail() != null) {
contact.setEmail(userDMP.getUser().getEmail());
break;
}
}
}
rda.setContact(ContactRDAMapper.toRDA(contact));
} catch (NoResultException e) {
logger.error(e.getMessage(), e);
}
}
/*UserInfo creator;
if (dmp.getCreator() != null) {
creator = dmp.getCreator();
} else {
creator = dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).map(UserDMP::getUser).findFirst().orElse(new UserInfo());
}
rda.setContact(ContactRDAMapper.toRDA(creator));*/
rda.setContributor(new ArrayList<>());
if (dmp.getResearchers() != null && !dmp.getResearchers().isEmpty()) {
rda.getContributor().addAll(dmp.getResearchers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList()));
}
// rda.getContributor().addAll(dmp.getUsers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList()));
rda.setDataset(dmp.getDataset().stream().filter(dataset -> dataset.getIsActive() != IsActive.Inactive).map(dataset -> datasetRDAMapper.toRDA(dataset, rda)).collect(Collectors.toList()));
if (dmp.getProject() != null) {
rda.setProject(Collections.singletonList(ProjectRDAMapper.toRDA(dmp.getProject(), dmp.getGrant())));
}
rda.setAdditionalProperty("templates", dmp.getAssociatedDmps().stream().map(datasetProfile -> datasetProfile.getId().toString()).toArray());
// rda.setCreated(dmp.getCreated()); //TODO
// rda.setDescription(dmp.getDescription());
// rda.setModified(dmp.getModified());
// rda.setTitle(dmp.getLabel());
//
// if (!extraProperties.isEmpty()) {
// if (extraProperties.get("ethicalIssues") != null) {
// rda.setEthicalIssuesExist(Dmp.EthicalIssuesExist.fromValue(extraProperties.get("ethicalIssues").toString()));
// } else {
// rda.setEthicalIssuesExist(Dmp.EthicalIssuesExist.UNKNOWN);
// }
// rda.setLanguage(LanguageRDAMapper.mapLanguageIsoToRDAIso(extraProperties.get("language") != null ? extraProperties.get("language").toString() : "en"));
// if (extraProperties.get("costs") != null) {
// rda.setCost(new ArrayList<>());
// ((List) extraProperties.get("costs")).forEach(costl -> {
// rda.getCost().add(CostRDAMapper.toRDA((Map)costl));
// });
// }
// try {
// UserInfo contactDb = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(UUID.fromString((String) extraProperties.get("contact")));
// UserInfo contact = new UserInfo();
// contact.setId(contactDb.getId());
// contact.setName(contactDb.getName());
// contact.setEmail(contactDb.getEmail());
// if (contact.getEmail() == null) {
// for (UserDMP userDMP : dmp.getUsers()) {
// if (userDMP.getDmp().getId() == dmp.getId() && userDMP.getUser().getEmail() != null) {
// contact.setEmail(userDMP.getUser().getEmail());
// break;
// }
// }
// }
// rda.setContact(ContactRDAMapper.toRDA(contact));
// } catch (NoResultException e) {
// logger.error(e.getMessage(), e);
// }
// }
//
// /*UserInfo creator;
// if (dmp.getCreator() != null) {
// creator = dmp.getCreator();
// } else {
// creator = dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).map(UserDMP::getUser).findFirst().orElse(new UserInfo());
// }
// rda.setContact(ContactRDAMapper.toRDA(creator));*/
// rda.setContributor(new ArrayList<>());
// if (dmp.getResearchers() != null && !dmp.getResearchers().isEmpty()) {
// rda.getContributor().addAll(dmp.getResearchers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList()));
// }
//// rda.getContributor().addAll(dmp.getUsers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList()));
// rda.setDataset(dmp.getDataset().stream().filter(dataset -> dataset.getIsActive() != IsActive.Inactive).map(dataset -> datasetRDAMapper.toRDA(dataset, rda)).collect(Collectors.toList()));
// if (dmp.getProject() != null) {
// rda.setProject(Collections.singletonList(ProjectRDAMapper.toRDA(dmp.getProject(), dmp.getGrant())));
// }
// rda.setAdditionalProperty("templates", dmp.getAssociatedDmps().stream().map(datasetProfile -> datasetProfile.getId().toString()).toArray());
return rda;
}
public DMP toEntity(Dmp rda, String[] profiles) throws InvalidApplicationException {
DMP entity = new DMP();
public DmpEntity toEntity(Dmp rda, String[] profiles) throws InvalidApplicationException {
DmpEntity entity = new DmpEntity();
entity.setLabel(rda.getTitle());
if (rda.getDmpId().getType() == DmpId.Type.DOI) {
try {
//TODO: Find from doi = rda.getDmpId().getIdentifier()
EntityDoiEntity doi = new EntityDoiEntity();
Set<EntityDoiEntity> dois = new HashSet<>();
dois.add(doi);
entity.setDois(dois);
}
catch (NoResultException e) {
logger.warn("No entity doi: " + rda.getDmpId().getIdentifier() + " found in database. No dois are added to dmp.");
entity.setDois(new HashSet<>());
}
}
if (((List<String>) rda.getAdditionalProperties().get("templates")) != null && !((List<String>) rda.getAdditionalProperties().get("templates")).isEmpty() && entity.getId() != null) {
entity.setAssociatedDmps(((List<String>) rda.getAdditionalProperties().get("templates")).stream().map(x -> {
try {
return this.getProfile(x, entity.getId());
} catch (InvalidApplicationException e) {
throw new RuntimeException(e);
}
}).filter(Objects::nonNull).collect(Collectors.toSet()));
}
if (entity.getAssociatedDmps() == null) {
entity.setAssociatedDmps(new HashSet<>());
}
if (profiles != null && entity.getId() != null) {
for (String profile : profiles) {
entity.getAssociatedDmps().add(this.getProfile(profile, entity.getId()));
}
}
if (rda.getContributor() != null && !rda.getContributor().isEmpty() && rda.getContributor().get(0).getContributorId() != null) {
entity.setResearchers(rda.getContributor().stream().filter(r -> r.getContributorId() != null).map(ContributorRDAMapper::toEntity).filter(StreamDistinctBy.distinctByKey(Researcher::getReference)).collect(Collectors.toSet()));
}
entity.setCreated(rda.getCreated());
entity.setModified(rda.getModified());
entity.setDescription(rda.getDescription());
DescriptionTemplateEntity defaultProfile = ((DescriptionTemplateEntity)entity.getAssociatedDmps().toArray()[0]);
entity.setDataset(rda.getDataset().stream().map(rda1 -> datasetRDAMapper.toEntity(rda1, defaultProfile)).collect(Collectors.toSet()));
if (rda.getProject().size() > 0) {
Map<String, Object> result = ProjectRDAMapper.toEntity(rda.getProject().get(0), apiContext);
entity.setProject((Project) result.get("project"));
result.entrySet().stream().filter(entry -> entry.getKey().startsWith("grant")).forEach(entry -> entity.setGrant((Grant) entry.getValue()));
}
Map<String, Object> extraProperties = new HashMap<>();
extraProperties.put("language", LanguageRDAMapper.mapRDAIsoToLanguageIso(rda.getLanguage()));
entity.setExtraProperties(JSONObject.toJSONString(extraProperties));
// if (rda.getDmpId().getType() == DmpId.Type.DOI) { //TODO
// try {
// //TODO: Find from doi = rda.getDmpId().getIdentifier()
// EntityDoiEntity doi = new EntityDoiEntity();
// Set<EntityDoiEntity> dois = new HashSet<>();
// dois.add(doi);
// entity.setDois(dois);
// }
// catch (NoResultException e) {
// logger.warn("No entity doi: " + rda.getDmpId().getIdentifier() + " found in database. No dois are added to dmp.");
// entity.setDois(new HashSet<>());
// }
// }
// if (((List<String>) rda.getAdditionalProperties().get("templates")) != null && !((List<String>) rda.getAdditionalProperties().get("templates")).isEmpty() && entity.getId() != null) {
// entity.setAssociatedDmps(((List<String>) rda.getAdditionalProperties().get("templates")).stream().map(x -> {
// try {
// return this.getProfile(x, entity.getId());
// } catch (InvalidApplicationException e) {
// throw new RuntimeException(e);
// }
// }).filter(Objects::nonNull).collect(Collectors.toSet()));
// }
// if (entity.getAssociatedDmps() == null) {
// entity.setAssociatedDmps(new HashSet<>());
// }
// if (profiles != null && entity.getId() != null) {
// for (String profile : profiles) {
// entity.getAssociatedDmps().add(this.getProfile(profile, entity.getId()));
// }
// }
// if (rda.getContributor() != null && !rda.getContributor().isEmpty() && rda.getContributor().get(0).getContributorId() != null) {
// entity.setResearchers(rda.getContributor().stream().filter(r -> r.getContributorId() != null).map(ContributorRDAMapper::toEntity).filter(StreamDistinctBy.distinctByKey(Researcher::getReference)).collect(Collectors.toSet()));
// }
// entity.setCreated(rda.getCreated());
// entity.setModified(rda.getModified());
// entity.setDescription(rda.getDescription());
// DescriptionTemplateEntity defaultProfile = ((DescriptionTemplateEntity)entity.getAssociatedDmps().toArray()[0]);
// entity.setDataset(rda.getDataset().stream().map(rda1 -> datasetRDAMapper.toEntity(rda1, defaultProfile)).collect(Collectors.toSet()));
// if (rda.getProject().size() > 0) {
// Map<String, Object> result = ProjectRDAMapper.toEntity(rda.getProject().get(0), apiContext);
// entity.setProject((Project) result.get("project"));
// result.entrySet().stream().filter(entry -> entry.getKey().startsWith("grant")).forEach(entry -> entity.setGrant((Grant) entry.getValue()));
// }
//
// Map<String, Object> extraProperties = new HashMap<>();
// extraProperties.put("language", LanguageRDAMapper.mapRDAIsoToLanguageIso(rda.getLanguage()));
//
// entity.setExtraProperties(JSONObject.toJSONString(extraProperties));
return entity;
}
private DMPDatasetProfile getProfile(String descriptionTemplateId, UUID dmpId) throws InvalidApplicationException {
private DmpDescriptionTemplateEntity getProfile(String descriptionTemplateId, UUID dmpId) throws InvalidApplicationException {
return apiContext.getOperationsContext().getDatabaseRepository().getDmpDatasetProfileDao().asQueryable().where(((builder, root) -> builder.and(
builder.equal(root.get("datasetprofile"), UUID.fromString(descriptionTemplateId)),
builder.equal(root.get("dmp"), dmpId))

View File

@ -1,14 +1,14 @@
package eu.eudat.publicapi.criteria.dmp;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.dao.criteria.Criteria;
import eu.eudat.data.old.DMP;
import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
import java.util.List;
import java.util.UUID;
public class DataManagementPlanPublicCriteria extends Criteria<DMP> {
public class DataManagementPlanPublicCriteria extends Criteria<DmpEntity> {
@ApiModelProperty(value = "periodStart", name = "periodStart", dataType = "Date", example = "2022-01-01T13:19:42.210Z")
private Date periodStart;
@ApiModelProperty(value = "periodEnd", name = "periodEnd", dataType = "Date", example = "2022-12-31T13:19:42.210Z")

View File

@ -1,6 +1,8 @@
package eu.eudat.publicapi.managers;
import eu.eudat.data.old.DMP;
import eu.eudat.commons.enums.DmpAccessType;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.DmpEntity;
import eu.eudat.exceptions.security.ForbiddenException;
import eu.eudat.logic.managers.PaginationManager;
import eu.eudat.logic.services.ApiContext;
@ -32,8 +34,8 @@ public class DataManagementPlanPublicManager {
public DataTableData<DataManagementPlanPublicListingModel> getPublicPaged(DataManagmentPlanPublicTableRequest dmpTableRequest, String fieldsGroup) throws Exception {
dmpTableRequest.setQuery(databaseRepository.getDmpDao().asQueryable().withHint(HintedModelFactory.getHint(DataManagementPlanPublicListingModel.class)));
QueryableList<DMP> items = dmpTableRequest.applyCriteria();
QueryableList<DMP> pagedItems = PaginationManager.applyPaging(items, dmpTableRequest);
QueryableList<DmpEntity> items = dmpTableRequest.applyCriteria();
QueryableList<DmpEntity> pagedItems = PaginationManager.applyPaging(items, dmpTableRequest);
DataTableData<DataManagementPlanPublicListingModel> dataTable = new DataTableData<>();
@ -62,11 +64,11 @@ public class DataManagementPlanPublicManager {
}
public DataManagementPlanPublicModel getOverviewSinglePublic(String id) throws Exception {
DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id));
if (dataManagementPlanEntity.getStatus() == DMP.DMPStatus.DELETED.getValue()) {
DmpEntity dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id));
if (dataManagementPlanEntity.getIsActive().equals(IsActive.Inactive)) {
throw new Exception("DMP is deleted.");
}
if (!dataManagementPlanEntity.isPublic()) {
if (!dataManagementPlanEntity.getAccessType().equals(DmpAccessType.Public)) {
throw new ForbiddenException("Selected DMP is not public");
}
DataManagementPlanPublicModel datamanagementPlan = new DataManagementPlanPublicModel();

View File

@ -1,6 +1,6 @@
package eu.eudat.publicapi.models.listingmodels;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.old.Grant;
import eu.eudat.models.DataModel;
import eu.eudat.publicapi.models.researcher.ResearcherPublicModel;
@ -9,7 +9,7 @@ import eu.eudat.publicapi.models.user.UserInfoPublicModel;
import java.util.*;
import java.util.stream.Collectors;
public class DataManagementPlanPublicListingModel implements DataModel<DMP, DataManagementPlanPublicListingModel> {
public class DataManagementPlanPublicListingModel implements DataModel<DmpEntity, DataManagementPlanPublicListingModel> {
private String id;
private String label;
private String grant;
@ -100,70 +100,70 @@ public class DataManagementPlanPublicListingModel implements DataModel<DMP, Data
}
@Override
public DataManagementPlanPublicListingModel fromDataModel(DMP entity) {
public DataManagementPlanPublicListingModel fromDataModel(DmpEntity entity) {
this.id = entity.getId().toString();
this.label = entity.getLabel();
this.groupId = entity.getGroupId();
return this;
}
public DataManagementPlanPublicListingModel fromDataModelAssociatedProfiles(DMP entity) {
public DataManagementPlanPublicListingModel fromDataModelAssociatedProfiles(DmpEntity entity) {
this.id = entity.getId().toString();
this.label = entity.getLabel();
this.groupId = entity.getGroupId();
this.createdAt = entity.getCreated();
this.createdAt = Date.from(entity.getCreatedAt());
return this;
}
public DataManagementPlanPublicListingModel fromDataModelAutoComplete(DMP entity) {
public DataManagementPlanPublicListingModel fromDataModelAutoComplete(DmpEntity entity) {
this.id = entity.getId().toString();
this.label = entity.getLabel();
this.groupId = entity.getGroupId();
this.createdAt = entity.getCreated();
this.createdAt = Date.from(entity.getCreatedAt());
return this;
}
public DataManagementPlanPublicListingModel fromDataModelNoDatasets(DMP entity) {
public DataManagementPlanPublicListingModel fromDataModelNoDatasets(DmpEntity entity) {
this.fromDataModel(entity);
this.version = entity.getVersion();
if (entity.getGrant() != null) {
this.grant = entity.getGrant().getLabel();
}
this.createdAt = entity.getCreated();
this.modifiedAt = entity.getModified();
try {
this.users = entity.getUsers() != null ? entity.getUsers().stream().map(x -> new UserInfoPublicModel().fromDataModel(x)).collect(Collectors.toList()) : new ArrayList<>();
this.researchers = entity.getResearchers() != null ? entity.getResearchers().stream().map(x -> new ResearcherPublicModel().fromDataModel(x)).collect(Collectors.toList()) : new ArrayList<>();
}
catch(Exception ex){
this.users = new ArrayList<>();
this.researchers = new ArrayList<>();
}
this.finalizedAt = entity.getFinalizedAt();
this.publishedAt = entity.getPublishedAt();
// this.version = entity.getVersion(); //TODO
// if (entity.getGrant() != null) {
// this.grant = entity.getGrant().getLabel();
// }
// this.createdAt = entity.getCreated();
// this.modifiedAt = entity.getModified();
// try {
// this.users = entity.getUsers() != null ? entity.getUsers().stream().map(x -> new UserInfoPublicModel().fromDataModel(x)).collect(Collectors.toList()) : new ArrayList<>();
// this.researchers = entity.getResearchers() != null ? entity.getResearchers().stream().map(x -> new ResearcherPublicModel().fromDataModel(x)).collect(Collectors.toList()) : new ArrayList<>();
// }
// catch(Exception ex){
// this.users = new ArrayList<>();
// this.researchers = new ArrayList<>();
// }
// this.finalizedAt = entity.getFinalizedAt();
// this.publishedAt = entity.getPublishedAt();
return this;
}
@Override
public DMP toDataModel() {
DMP entity = new DMP();
public DmpEntity toDataModel() {
DmpEntity entity = new DmpEntity();
entity.setId(UUID.fromString(this.getId()));
entity.setLabel(this.getLabel());
entity.setGroupId(this.getGroupId());
entity.setCreated(this.getCreatedAt());
entity.setFinalizedAt(this.getFinalizedAt());
entity.setModified(this.getModifiedAt());
entity.setPublishedAt(this.getPublishedAt());
entity.setVersion(this.getVersion());
if (this.getGrant() != null) {
Grant grant = new Grant();
grant.setLabel(this.getGrant());
entity.setGrant(grant);
}
entity.setUsers(this.getUsers().stream().map(UserInfoPublicModel::toDataModel).collect(Collectors.toSet()));
entity.setResearchers(this.getResearchers().stream().map(ResearcherPublicModel::toDataModel).collect(Collectors.toSet()));
// entity.setCreated(this.getCreatedAt()); //TODO
// entity.setFinalizedAt(this.getFinalizedAt());
// entity.setModified(this.getModifiedAt());
// entity.setPublishedAt(this.getPublishedAt());
// entity.setVersion(this.getVersion());
//
// if (this.getGrant() != null) {
// Grant grant = new Grant();
// grant.setLabel(this.getGrant());
// entity.setGrant(grant);
// }
// entity.setUsers(this.getUsers().stream().map(UserInfoPublicModel::toDataModel).collect(Collectors.toSet()));
// entity.setResearchers(this.getResearchers().stream().map(ResearcherPublicModel::toDataModel).collect(Collectors.toSet()));
return entity;
}

View File

@ -1,17 +1,12 @@
package eu.eudat.publicapi.models.listingmodels;
import eu.eudat.data.old.DMP;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.old.Grant;
import eu.eudat.models.DataModel;
import eu.eudat.publicapi.models.datasetprofile.DatasetProfilePublicModel;
import eu.eudat.publicapi.models.user.UserInfoPublicModel;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
public class DatasetPublicListingModel implements DataModel<DescriptionEntity, DatasetPublicListingModel> {
private String id;

View File

@ -5,11 +5,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity;
import eu.eudat.data.old.DMP;
import eu.eudat.data.old.DMPDatasetProfile;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.commons.types.xml.XmlBuilder;
import eu.eudat.data.DmpEntity;
import eu.eudat.models.DataModel;
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import eu.eudat.publicapi.models.associatedprofile.AssociatedProfilePublicModel;
@ -18,14 +17,13 @@ import eu.eudat.publicapi.models.grant.GrantPublicOverviewModel;
import eu.eudat.publicapi.models.organisation.OrganizationPublicModel;
import eu.eudat.publicapi.models.researcher.ResearcherPublicModel;
import eu.eudat.publicapi.models.user.UserInfoPublicModel;
import org.json.JSONObject;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.util.*;
import java.util.stream.Collectors;
public class DataManagementPlanPublicModel implements DataModel<DMP, DataManagementPlanPublicModel> {
public class DataManagementPlanPublicModel implements DataModel<DmpEntity, DataManagementPlanPublicModel> {
private String id;
private String label;
private String profile;
@ -165,56 +163,56 @@ public class DataManagementPlanPublicModel implements DataModel<DMP, DataManagem
}
@Override
public DataManagementPlanPublicModel fromDataModel(DMP entity) {
public DataManagementPlanPublicModel fromDataModel(DmpEntity entity) {
this.id = entity.getId().toString();
this.label = entity.getLabel();
this.groupId = entity.getGroupId();
if (entity.getResearchers() != null) {
this.researchers = entity.getResearchers().stream().map(item -> new ResearcherPublicModel().fromDataModel(item)).collect(Collectors.toList());
}
// if (entity.getResearchers() != null) { //TODO
// this.researchers = entity.getResearchers().stream().map(item -> new ResearcherPublicModel().fromDataModel(item)).collect(Collectors.toList());
// }
return this;
}
public DataManagementPlanPublicModel fromDataModelDatasets(DMP entity) {
public DataManagementPlanPublicModel fromDataModelDatasets(DmpEntity entity) {
this.fromDataModel(entity);
this.version = entity.getVersion();
if (entity.getGrant() != null) {
this.grant = new GrantPublicOverviewModel().fromDataModel(entity.getGrant());
}
if (entity.getProfile() != null) this.profile = entity.getProfile().getLabel();
this.createdAt = entity.getCreated();
this.modifiedAt = entity.getModified();
this.finalizedAt = entity.getFinalizedAt();
this.organisations = entity.getOrganisations().stream().map(item -> new OrganizationPublicModel().fromDataModel(item)).collect(Collectors.toList());
this.datasets = entity.getDataset().stream().filter(dataset -> !dataset.getIsActive().equals(IsActive.Inactive) && !dataset.getStatus().equals(DescriptionStatus.Canceled))
.map(datasetEntity-> {
DatasetPublicModel dataset = new DatasetPublicModel();
dataset.setDatasetProfileDefinition(this.getPagedProfile(dataset.getStatus().getValue(), datasetEntity));
dataset.fromDataModel(datasetEntity);
return dataset;
}).collect(Collectors.toList());
this.users = entity.getUsers().stream().map(x -> new UserInfoPublicModel().fromDataModel(x)).collect(Collectors.toList());
this.description = entity.getDescription();
if (entity.getResearchers() != null) {
this.researchers = entity.getResearchers().stream().map(item -> new ResearcherPublicModel().fromDataModel(item)).collect(Collectors.toList());
}
if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) {
this.associatedProfiles = new LinkedList<>();
for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) {
AssociatedProfilePublicModel associatedProfile = new AssociatedProfilePublicModel().fromData(dmpDescriptionProfile.getDatasetprofile());
associatedProfile.setId(dmpDescriptionProfile.getId());
try {
associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference<Map<String, Object>>() {}));
}
catch (Exception e) {
associatedProfile.setData(null);
}
this.associatedProfiles.add(associatedProfile);
}
}
this.publishedAt = entity.getPublishedAt();
this.dois = entity.getDois().stream().map(item -> new DoiPublicModel().fromDataModel(item)).collect(Collectors.toList());
this.version = entity.getVersion();//TODO
// if (entity.getGrant() != null) {
// this.grant = new GrantPublicOverviewModel().fromDataModel(entity.getGrant());
// }
// if (entity.getProfile() != null) this.profile = entity.getProfile().getLabel();
// this.createdAt = entity.getCreated();
// this.modifiedAt = entity.getModified();
// this.finalizedAt = entity.getFinalizedAt();
// this.organisations = entity.getOrganisations().stream().map(item -> new OrganizationPublicModel().fromDataModel(item)).collect(Collectors.toList());
// this.datasets = entity.getDataset().stream().filter(dataset -> !dataset.getIsActive().equals(IsActive.Inactive) && !dataset.getStatus().equals(DescriptionStatus.Canceled))
// .map(datasetEntity-> {
// DatasetPublicModel dataset = new DatasetPublicModel();
// dataset.setDatasetProfileDefinition(this.getPagedProfile(dataset.getStatus().getValue(), datasetEntity));
// dataset.fromDataModel(datasetEntity);
// return dataset;
// }).collect(Collectors.toList());
// this.users = entity.getUsers().stream().map(x -> new UserInfoPublicModel().fromDataModel(x)).collect(Collectors.toList());
// this.description = entity.getDescription();
// if (entity.getResearchers() != null) {
// this.researchers = entity.getResearchers().stream().map(item -> new ResearcherPublicModel().fromDataModel(item)).collect(Collectors.toList());
// }
//
// if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) {
// this.associatedProfiles = new LinkedList<>();
// for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) {
// AssociatedProfilePublicModel associatedProfile = new AssociatedProfilePublicModel().fromData(dmpDescriptionProfile.getDatasetprofile());
// associatedProfile.setId(dmpDescriptionProfile.getId());
// try {
// associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference<Map<String, Object>>() {}));
// }
// catch (Exception e) {
// associatedProfile.setData(null);
// }
// this.associatedProfiles.add(associatedProfile);
// }
// }
// this.publishedAt = entity.getPublishedAt();
// this.dois = entity.getDois().stream().map(item -> new DoiPublicModel().fromDataModel(item)).collect(Collectors.toList());
return this;
}
@ -245,7 +243,7 @@ public class DataManagementPlanPublicModel implements DataModel<DMP, DataManagem
}
@Override
public DMP toDataModel() {
public DmpEntity toDataModel() {
return null;
}

View File

@ -1,12 +1,14 @@
package eu.eudat.publicapi.models.user;
import eu.eudat.data.old.UserDMP;
import eu.eudat.commons.enums.DmpUserRole;
import eu.eudat.data.DmpUserEntity;
import eu.eudat.data.old.UserInfo;
import eu.eudat.model.DmpUser;
import eu.eudat.models.DataModel;
import java.util.UUID;
public class UserInfoPublicModel implements DataModel<UserDMP, UserInfoPublicModel> {
public class UserInfoPublicModel implements DataModel<DmpUserEntity, UserInfoPublicModel> {
private UUID id;
private String name;
private int role;
@ -41,23 +43,23 @@ public class UserInfoPublicModel implements DataModel<UserDMP, UserInfoPublicMod
}
@Override
public UserInfoPublicModel fromDataModel(UserDMP entity) {
this.id = entity.getUser().getId();
this.name = entity.getUser().getName();
this.role = entity.getRole();
this.email = entity.getUser().getEmail();
public UserInfoPublicModel fromDataModel(DmpUserEntity entity) {
// this.id = entity.getUser().getId(); //TODO
// this.name = entity.getUser().getName();
// this.role = entity.getRole().getValue();
// this.email = entity.getUser().getEmail();
return this;
}
@Override
public UserDMP toDataModel() {
UserDMP entity = new UserDMP();
public DmpUserEntity toDataModel() {
DmpUserEntity entity = new DmpUserEntity();
entity.setId(this.getId());
entity.setRole(this.getRole());
entity.setRole(DmpUserRole.of((short)this.getRole()));
UserInfo userInfo = new UserInfo();
userInfo.setName(this.getName());
userInfo.setEmail(this.getEmail());
entity.setUser(userInfo);
// entity.setUser(userInfo);
return entity;
}

View File

@ -1,6 +1,7 @@
package eu.eudat.publicapi.request.dmp;
import eu.eudat.data.old.DMP;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.query.PaginationService;
import eu.eudat.data.query.definition.TableQuery;
import eu.eudat.publicapi.criteria.dmp.DataManagementPlanPublicCriteria;
@ -11,10 +12,10 @@ import eu.eudat.queryable.types.SelectionField;
import jakarta.persistence.criteria.Predicate;
import java.util.*;
public class DataManagmentPlanPublicTableRequest extends TableQuery<DataManagementPlanPublicCriteria, DMP, UUID> {
public class DataManagmentPlanPublicTableRequest extends TableQuery<DataManagementPlanPublicCriteria, DmpEntity, UUID> {
public QueryableList<DMP> applyCriteria() {
QueryableList<DMP> query = this.getQuery();
public QueryableList<DmpEntity> applyCriteria() {
QueryableList<DmpEntity> query = this.getQuery();
query.where((builder, root) -> builder.equal(root.get("isPublic"), true));
if (this.getCriteria().getLike() != null && !this.getCriteria().getLike().isEmpty())
query.where((builder, root) -> builder.or(
@ -89,12 +90,12 @@ public class DataManagmentPlanPublicTableRequest extends TableQuery<DataManageme
if (this.getCriteria().getGroupIds() != null && !this.getCriteria().getGroupIds().isEmpty()) {
query.where((builder, root) -> root.get("groupId").in(this.getCriteria().getGroupIds()));
}
query.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()));
query.where((builder, root) -> builder.notEqual(root.get("isActive"), IsActive.Inactive));
return query;
}
@Override
public QueryableList<DMP> applyPaging(QueryableList<DMP> items) {
public QueryableList<DmpEntity> applyPaging(QueryableList<DmpEntity> items) {
return PaginationService.applyPaging(items, this);
}
}