diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionEntity.java index 02ed4fc09..7f49b18f5 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionEntity.java @@ -1,217 +1,295 @@ package eu.eudat.data; + import eu.eudat.commons.enums.DescriptionStatus; import eu.eudat.commons.enums.IsActive; import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.enums.DescriptionStatusConverter; import eu.eudat.data.converters.enums.IsActiveConverter; +import eu.eudat.data.old.*; +import eu.eudat.data.old.helpers.EntityBinder; +import eu.eudat.queryable.queryableentity.DataEntity; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.Type; + import jakarta.persistence.*; import java.time.Instant; -import java.util.UUID; +import java.util.*; +import java.util.stream.Collectors; + @Entity @Table(name = "\"Description\"") -public class DescriptionEntity { +public class DescriptionEntity implements DataEntity { - @Id - @Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false) - private UUID id; + public static Set getHints() { + return hints; + } - public static final String _id = "id"; + private static final Set hints = new HashSet<>(Arrays.asList("datasetListingModel")); - @Column(name = "label", length = 250, nullable = false) - private String label; + @Id + @Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false) + private UUID id; - public static final String _label = "label"; + public static final String _id = "id"; - @Column(name = "dmp", columnDefinition = "uuid") - private UUID dmp; + @Column(name = "label", length = 250, nullable = false) + private String label; - public static final String _dmp = "dmp"; + public static final String _label = "label"; - @Column(name = "uri", length = 250) - private String uri; + @Column(name = "dmp", columnDefinition = "uuid") + private UUID dmp; - public static final String _uri = "uri"; + public static final String _dmp = "dmp"; - @Column(name = "properties") - private String properties; + @Column(name = "uri", length = 250) + private String uri; - public static final String _properties = "properties"; + public static final String _uri = "uri"; - //TODO: (thgiannos) Previously 'DescriptionTemplate' - @Column(name = "profile", columnDefinition = "uuid") - private UUID profile; + @Column(name = "properties") + private String properties; - public static final String _profile = "profile"; + public static final String _properties = "properties"; - @Column(name = "reference") - private String reference; + //TODO: (thgiannos) Previously 'DescriptionTemplate' + @Column(name = "profile", columnDefinition = "uuid") + private UUID profile; - public static final String _reference = "reference"; + public static final String _profile = "profile"; - @Column(name = "status", nullable = false) - @Convert(converter = DescriptionStatusConverter.class) - private DescriptionStatus status; + @Column(name = "reference") + private String reference; - public static final String _status = "status"; + public static final String _reference = "reference"; - @Column(name = "description") - private String description; + @Column(name = "status", nullable = false) + @Convert(converter = DescriptionStatusConverter.class) + private DescriptionStatus status; - public static final String _description = "description"; + public static final String _status = "status"; - @Column(name = "dmp_section_index", nullable = false) - private Integer dmpSectionIndex; + @Column(name = "description") + private String description; - public static final String _dmpSectionIndex = "dmpSectionIndex"; + public static final String _description = "description"; - @Column(name = "creator", columnDefinition = "uuid") - private UUID creator; + @Column(name = "dmp_section_index", nullable = false) + private Integer dmpSectionIndex; - public static final String _creator = "creator"; + public static final String _dmpSectionIndex = "dmpSectionIndex"; - @Column(name = "created_at", nullable = false) - private Instant createdAt; + @Column(name = "creator", columnDefinition = "uuid") + private UUID creator; - public static final String _createdAt = "createdAt"; + public static final String _creator = "creator"; - @Column(name = "updated_at", nullable = false) - private Instant updatedAt; + @Column(name = "created_at", nullable = false) + private Instant createdAt; - public static final String _updatedAt = "updatedAt"; + public static final String _createdAt = "createdAt"; - @Column(name = "is_active", nullable = false) - @Convert(converter = IsActiveConverter.class) - private IsActive isActive; + @Column(name = "updated_at", nullable = false) + private Instant updatedAt; - public static final String _isActive = "isActive"; + public static final String _updatedAt = "updatedAt"; - @Column(name = "\"finalized_at\"") - @Convert(converter = DateToUTCConverter.class) - private Instant finalizedAt; + @Column(name = "is_active", nullable = false) + @Convert(converter = IsActiveConverter.class) + private IsActive isActive; - public static final String _finalizedAt = "finalizedAt"; + public static final String _isActive = "isActive"; - public UUID getId() { - return id; - } + @Column(name = "\"finalized_at\"") + @Convert(converter = DateToUTCConverter.class) + private Instant finalizedAt; - public void setId(UUID id) { - this.id = id; - } + public static final String _finalizedAt = "finalizedAt"; - public String getLabel() { - return label; - } + public UUID getId() { + return id; + } - public void setLabel(String label) { - this.label = label; - } + public void setId(UUID id) { + this.id = id; + } - public UUID getDmp() { - return dmp; - } + public String getLabel() { + return label; + } - public void setDmp(UUID dmp) { - this.dmp = dmp; - } + public void setLabel(String label) { + this.label = label; + } - public String getUri() { - return uri; - } + public UUID getDmp() { + return dmp; + } - public void setUri(String uri) { - this.uri = uri; - } + public void setDmp(UUID dmp) { + this.dmp = dmp; + } - public String getProperties() { - return properties; - } + public String getUri() { + return uri; + } - public void setProperties(String properties) { - this.properties = properties; - } + public void setUri(String uri) { + this.uri = uri; + } - public UUID getProfile() { - return profile; - } + public String getProperties() { + return properties; + } - public void setProfile(UUID profile) { - this.profile = profile; - } + public void setProperties(String properties) { + this.properties = properties; + } - public String getReference() { - return reference; - } + public UUID getProfile() { + return profile; + } - public void setReference(String reference) { - this.reference = reference; - } + public void setProfile(UUID profile) { + this.profile = profile; + } - public DescriptionStatus getStatus() { - return status; - } + public String getReference() { + return reference; + } - public void setStatus(DescriptionStatus status) { - this.status = status; - } + public void setReference(String reference) { + this.reference = reference; + } - public String getDescription() { - return description; - } + public DescriptionStatus getStatus() { + return status; + } - public void setDescription(String description) { - this.description = description; - } + public void setStatus(DescriptionStatus status) { + this.status = status; + } - public Integer getDmpSectionIndex() { - return dmpSectionIndex; - } + public String getDescription() { + return description; + } - public void setDmpSectionIndex(Integer dmpSectionIndex) { - this.dmpSectionIndex = dmpSectionIndex; - } + public void setDescription(String description) { + this.description = description; + } - public UUID getCreator() { - return creator; - } + public Integer getDmpSectionIndex() { + return dmpSectionIndex; + } - public void setCreator(UUID creator) { - this.creator = creator; - } + public void setDmpSectionIndex(Integer dmpSectionIndex) { + this.dmpSectionIndex = dmpSectionIndex; + } - public Instant getCreatedAt() { - return createdAt; - } + public UUID getCreator() { + return creator; + } - public void setCreatedAt(Instant createdAt) { - this.createdAt = createdAt; - } + public void setCreator(UUID creator) { + this.creator = creator; + } - public Instant getUpdatedAt() { - return updatedAt; - } + public Instant getCreatedAt() { + return createdAt; + } - public void setUpdatedAt(Instant updatedAt) { - this.updatedAt = updatedAt; - } + public void setCreatedAt(Instant createdAt) { + this.createdAt = createdAt; + } - public IsActive getIsActive() { - return isActive; - } + public Instant getUpdatedAt() { + return updatedAt; + } - public void setIsActive(IsActive isActive) { - this.isActive = isActive; - } + public void setUpdatedAt(Instant updatedAt) { + this.updatedAt = updatedAt; + } - public Instant getFinalizedAt() { - return finalizedAt; - } + public IsActive getIsActive() { + return isActive; + } - public void setFinalizedAt(Instant finalizedAt) { - this.finalizedAt = finalizedAt; - } + public void setIsActive(IsActive isActive) { + this.isActive = isActive; + } + public Instant getFinalizedAt() { + return finalizedAt; + } + + public void setFinalizedAt(Instant finalizedAt) { + this.finalizedAt = finalizedAt; + } + + @Override + public void update(DescriptionEntity entity) { +// this.setUri(entity.getUri()); +// this.setDescription(entity.getDescription()); +// this.setLabel(entity.getLabel()); +// this.setProperties(entity.getProperties()); +// +// if (entity.getDatasetDataRepositories() == null || entity.getDatasetDataRepositories().size() < 1) { +// if (this.getDatasetDataRepositories() != null) this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories()); +// } else { +// if (this.getDatasetDataRepositories() != null) { +// this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories()); +// } else { +// this.setDatasetDataRepositories(new HashSet<>()); +// } +// this.getDatasetDataRepositories().addAll(entity.getDatasetDataRepositories().stream().peek(item -> item.setDataset(this)).collect(Collectors.toList())); +// } +// +// if (entity.getDatasetExternalDatasets() == null || entity.getDatasetExternalDatasets().size() < 1) { +// if (this.getDatasetExternalDatasets() != null) this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets()); +// } else { +// if (this.getDatasetExternalDatasets() != null) { +// this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets()); +// } else { +// this.setDatasetExternalDatasets(new HashSet<>()); +// } +// this.getDatasetExternalDatasets().addAll(entity.getDatasetExternalDatasets().stream().peek(item -> item.setDataset(this)).collect(Collectors.toList())); +// } +// +// if (entity.getServices() == null || entity.getServices().size() < 1) { +// if (this.getServices() != null) this.getServices().removeAll(this.getServices()); +// } else { +// if (this.getServices() != null) { +// this.getServices().removeAll(this.getServices()); +// } else { +// this.setServices(new HashSet<>()); +// } +// this.getServices().addAll(entity.getServices().stream().peek(item -> item.setDataset(this)).collect(Collectors.toList())); +// } +// +// this.setRegistries(entity.getRegistries()); +// +// this.setDmp(entity.getDmp()); +// this.setDmpSectionIndex(entity.getDmpSectionIndex()); +// this.setStatus(entity.getStatus()); +// this.setProfile(entity.getProfile()); +// this.setModified(new Date()); +// if (entity.getStatus().equals(Status.FINALISED.getValue())) this.setFinalizedAt(new Date()); +// if (entity.getCreator() != null) this.creator = entity.getCreator(); + } + + @Override + public UUID getKeys() { + return this.id; + } + + @Override + public DescriptionEntity buildFromTuple(List tuple, List fields, String base) { + String currentBase = base.isEmpty() ? "" : base + "."; + if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id"); + return this; + } } + diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMP.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/DMP.java index ca1fa280b..9c715d48d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMP.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/DMP.java @@ -1,6 +1,7 @@ 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; @@ -103,7 +104,7 @@ public class DMP implements DataEntity { private Integer version; @OneToMany(mappedBy = "dmp", fetch = FetchType.LAZY) - private Set dataset; + private Set descriptionEntity; @ManyToOne(fetch = FetchType.LAZY) @@ -286,11 +287,11 @@ public class DMP implements DataEntity { this.profile = profile; } - public Set getDataset() { - return dataset; + public Set getDataset() { + return descriptionEntity; } - public void setDataset(Set dataset) { - this.dataset = dataset; + public void setDataset(Set descriptionEntity) { + this.descriptionEntity = descriptionEntity; } public Set getOrganisations() { @@ -395,7 +396,7 @@ public class DMP implements DataEntity { @Override public DMP buildFromTuple(List tuple, List fields, String base) { this.id = tuple.get(0).get(base.isEmpty() ? "id" : base + "." + "id", UUID.class); - this.dataset = tuple.stream().map(x -> new Dataset().buildFromTuple(tuple, fields ,base.isEmpty() ? "dataset" : base + "." + "dataset")).collect(Collectors.toSet()); + 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; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Dataset.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Dataset.java deleted file mode 100644 index cbca307f7..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Dataset.java +++ /dev/null @@ -1,360 +0,0 @@ -package eu.eudat.data.old; - - -import eu.eudat.data.DescriptionTemplateEntity; -import eu.eudat.data.converters.DateToUTCConverter; -import eu.eudat.data.old.helpers.EntityBinder; -import eu.eudat.queryable.queryableentity.DataEntity; -import org.hibernate.annotations.GenericGenerator; -import org.hibernate.annotations.Type; - -import jakarta.persistence.*; -import java.util.*; -import java.util.stream.Collectors; - -@Entity -@Table(name = "\"Dataset\"") -@NamedEntityGraphs({ - @NamedEntityGraph( - name = "datasetListingModel", - attributeNodes = {/*@NamedAttributeNode("services"), @NamedAttributeNode(value = "datasetDataRepositories", subgraph = "datasetDataRepositories"), - @NamedAttributeNode(value = "datasetExternalDatasets", subgraph = "datasetExternalDatasets"), @NamedAttributeNode("registries"),*/ - @NamedAttributeNode(value = "dmp", subgraph = "dmp"), @NamedAttributeNode(value = "profile", subgraph = "profile"), @NamedAttributeNode("creator")}, - subgraphs = { - @NamedSubgraph(name = "dmp", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("users"), @NamedAttributeNode("grant"), @NamedAttributeNode("organisations")}), - @NamedSubgraph(name = "datasetDataRepositories", attributeNodes = {@NamedAttributeNode("dataRepository")}), - @NamedSubgraph(name = "datasetExternalDatasets", attributeNodes = {@NamedAttributeNode("externalDataset")}), - @NamedSubgraph(name = "profile", attributeNodes = {@NamedAttributeNode("label")}) - }), - - @NamedEntityGraph( - name = "datasetWizardModel", - attributeNodes = {@NamedAttributeNode("services"), @NamedAttributeNode("datasetDataRepositories"), @NamedAttributeNode("datasetExternalDatasets"), @NamedAttributeNode("registries"), - @NamedAttributeNode("dmp"), @NamedAttributeNode("profile"), @NamedAttributeNode("creator")}), - @NamedEntityGraph( - name = "datasetRecentActivity", - attributeNodes = {@NamedAttributeNode(value = "dmp", subgraph = "dmp")}, - subgraphs = @NamedSubgraph(name = "dmp", attributeNodes = {@NamedAttributeNode("users")})), - @NamedEntityGraph( - name = "datasetDataRepositories", - attributeNodes = {@NamedAttributeNode(value = "dmp", subgraph = "dmp"), @NamedAttributeNode("creator")}, - subgraphs = @NamedSubgraph(name = "dmp", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("users")})), - @NamedEntityGraph( - name = "recentDatasetModel", - attributeNodes = {@NamedAttributeNode("services"), @NamedAttributeNode(value = "datasetDataRepositories", subgraph = "datasetDataRepositories"), - @NamedAttributeNode(value = "datasetExternalDatasets", subgraph = "datasetExternalDatasets"), @NamedAttributeNode("registries"), - @NamedAttributeNode(value = "dmp", subgraph = "dmp"), @NamedAttributeNode("profile"), @NamedAttributeNode("creator")}, - subgraphs = { - @NamedSubgraph(name = "dmp", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("users"), @NamedAttributeNode("grant"), @NamedAttributeNode("organisations")}), - @NamedSubgraph(name = "datasetDataRepositories", attributeNodes = {@NamedAttributeNode("dataRepository")}), - @NamedSubgraph(name = "datasetExternalDatasets", attributeNodes = {@NamedAttributeNode("externalDataset")}) - }) -}) -public class Dataset implements DataEntity { - - public static Set getHints() { - return hints; - } - - private static final Set hints = new HashSet<>(Arrays.asList("datasetListingModel")); - - public enum Status { - SAVED((short) 0), FINALISED((short) 1), CANCELED((short) 2), DELETED((short) 99),; - - private short value; - - private Status(short value) { - this.value = value; - } - - public short getValue() { - return value; - } - - public static Status fromInteger(int value) { - switch (value) { - case 0: - return SAVED; - case 1: - return FINALISED; - case 2: - return CANCELED; - case 99: - return DELETED; - default: - throw new RuntimeException("Unsupported Dataset Status"); - } - } - } - - @Id - @GeneratedValue - @GenericGenerator(name = "uuid2", strategy = "uuid2") - @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") - private UUID id; - - @Column(name = "\"Label\"", nullable = false) - private String label; - - @ManyToOne(fetch = FetchType.LAZY) -// @Cascade(value=org.hibernate.annotations.CascadeType.ALL) - @JoinColumn(name = "\"DMP\"", nullable = false) - private DMP dmp; - - @Column(name = "\"DmpSectionIndex\"") - private Integer dmpSectionIndex; - - @Column(name = "\"Uri\"") - private String uri; - - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Properties\"", columnDefinition = "xml") - private String properties; - - @ManyToOne(fetch = FetchType.LAZY) - //@Cascade(value=org.hibernate.annotations.CascadeType.ALL) - @JoinColumn(name = "\"Profile\"") - private DescriptionTemplateEntity profile; - - @Type(eu.eudat.configurations.typedefinition.XMLType.class) - @Column(name = "\"Reference\"", columnDefinition = "xml") - private String reference; - - @OneToMany(fetch = FetchType.LAZY) - @JoinTable(name = "\"DatasetRegistry\"", - joinColumns = {@JoinColumn(name = "\"Dataset\"", referencedColumnName = "\"ID\"")}, - inverseJoinColumns = {@JoinColumn(name = "\"Registry\"", referencedColumnName = "\"ID\"")} - ) - private Set registries; - - @OneToMany(mappedBy = "dataset", cascade = CascadeType.ALL, orphanRemoval = true) - private Set datasetDataRepositories; - - @OneToMany(mappedBy = "dataset", cascade = CascadeType.ALL, orphanRemoval = true) - private Set services; - - @OneToMany(mappedBy = "dataset", cascade = CascadeType.ALL, orphanRemoval = true) - private Set datasetExternalDatasets; - - @Column(name = "\"Status\"", nullable = false) - private Short status; - - - @Column(name = "\"Created\"", nullable = false) - @Convert(converter = DateToUTCConverter.class) - private Date created = null; - - @Column(name = "\"Modified\"", nullable = false) - @Convert(converter = DateToUTCConverter.class) - private Date modified = new Date(); - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "\"Creator\"") - private UserInfo creator; - - @Column(name = "\"Description\"") - private String description; - - @Column(name= "\"FinalizedAt\"") - @Convert(converter = DateToUTCConverter.class) - private Date finalizedAt; - - - 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 getRegistries() { - return registries; - } - public void setRegistries(Set registries) { - this.registries = registries; - } - - public Set getServices() { - return services; - } - public void setServices(Set services) { - this.services = services; - } - - public UUID getId() { - return id; - } - public void setId(UUID id) { - this.id = id; - } - - - public String getLabel() { - return label; - } - public void setLabel(String label) { - this.label = label; - } - - - public DMP getDmp() { - return dmp; - } - public void setDmp(DMP dmp) { - this.dmp = dmp; - } - - public Integer getDmpSectionIndex() { - return dmpSectionIndex; - } - public void setDmpSectionIndex(Integer dmpSectionIndex) { - this.dmpSectionIndex = dmpSectionIndex; - } - - public String getUri() { - return uri; - } - public void setUri(String uri) { - this.uri = uri; - } - - - public String getProperties() { - return properties; - } - public void setProperties(String properties) { - this.properties = properties; - } - - - public DescriptionTemplateEntity getProfile() { - return profile; - } - public void setProfile(DescriptionTemplateEntity profile) { - this.profile = profile; - } - - - public Set getDatasetDataRepositories() { - return datasetDataRepositories; - } - public void setDatasetDataRepositories(Set datasetDataRepositories) { - this.datasetDataRepositories = datasetDataRepositories; - } - - public String getReference() { - return reference; - } - public void setReference(String reference) { - this.reference = reference; - } - - public Set getDatasetExternalDatasets() { - return datasetExternalDatasets; - } - public void setDatasetExternalDatasets(Set datasetExternalDatasets) { - this.datasetExternalDatasets = datasetExternalDatasets; - } - - public Date getFinalizedAt() { - return finalizedAt; - } - public void setFinalizedAt(Date finalizedAt) { - this.finalizedAt = finalizedAt; - } - - @Override - public void update(Dataset entity) { - this.setUri(entity.getUri()); - this.setDescription(entity.getDescription()); - this.setLabel(entity.getLabel()); - this.setProperties(entity.getProperties()); - - if (entity.getDatasetDataRepositories() == null || entity.getDatasetDataRepositories().size() < 1) { - if (this.getDatasetDataRepositories() != null) this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories()); - } else { - if (this.getDatasetDataRepositories() != null) { - this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories()); - } else { - this.setDatasetDataRepositories(new HashSet<>()); - } - this.getDatasetDataRepositories().addAll(entity.getDatasetDataRepositories().stream().peek(item -> item.setDataset(this)).collect(Collectors.toList())); - } - - if (entity.getDatasetExternalDatasets() == null || entity.getDatasetExternalDatasets().size() < 1) { - if (this.getDatasetExternalDatasets() != null) this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets()); - } else { - if (this.getDatasetExternalDatasets() != null) { - this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets()); - } else { - this.setDatasetExternalDatasets(new HashSet<>()); - } - this.getDatasetExternalDatasets().addAll(entity.getDatasetExternalDatasets().stream().peek(item -> item.setDataset(this)).collect(Collectors.toList())); - } - - if (entity.getServices() == null || entity.getServices().size() < 1) { - if (this.getServices() != null) this.getServices().removeAll(this.getServices()); - } else { - if (this.getServices() != null) { - this.getServices().removeAll(this.getServices()); - } else { - this.setServices(new HashSet<>()); - } - this.getServices().addAll(entity.getServices().stream().peek(item -> item.setDataset(this)).collect(Collectors.toList())); - } - - this.setRegistries(entity.getRegistries()); - - this.setDmp(entity.getDmp()); - this.setDmpSectionIndex(entity.getDmpSectionIndex()); - this.setStatus(entity.getStatus()); - this.setProfile(entity.getProfile()); - this.setModified(new Date()); - if (entity.getStatus().equals(Status.FINALISED.getValue())) this.setFinalizedAt(new Date()); - if (entity.getCreator() != null) this.creator = entity.getCreator(); - } - - @Override - public UUID getKeys() { - return this.id; - } - - @Override - public Dataset buildFromTuple(List tuple, List fields, String base) { - String currentBase = base.isEmpty() ? "" : base + "."; - if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id"); - return this; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/DatasetDataRepository.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/DatasetDataRepository.java index f74f462dc..7a4e55a39 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/DatasetDataRepository.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/DatasetDataRepository.java @@ -1,5 +1,6 @@ package eu.eudat.data.old; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; import org.hibernate.annotations.GenericGenerator; @@ -24,7 +25,7 @@ public class DatasetDataRepository implements DataEntity { @ManyToOne @JoinColumn(name = "\"Dataset\"", nullable = false) - private Dataset dataset; + private DescriptionEntity descriptionEntity; @ManyToOne @JoinColumn(name = "\"Service\"", nullable = false) @@ -43,12 +44,12 @@ public class DatasetService implements DataEntity { this.id = id; } - public Dataset getDataset() { - return dataset; + public DescriptionEntity getDataset() { + return descriptionEntity; } - public void setDataset(Dataset dataset) { - this.dataset = dataset; + public void setDataset(DescriptionEntity descriptionEntity) { + this.descriptionEntity = descriptionEntity; } public Service getService() { @@ -77,7 +78,7 @@ public class DatasetService implements DataEntity { @Override public void update(DatasetService entity) { - this.dataset = entity.getDataset(); + this.descriptionEntity = entity.getDataset(); this.service = entity.getService(); this.role = entity.getRole(); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Registry.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Registry.java index e70916dd1..92db305af 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Registry.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Registry.java @@ -1,6 +1,7 @@ package eu.eudat.data.old; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.old.helpers.EntityBinder; import eu.eudat.queryable.queryableentity.DataEntity; @@ -42,7 +43,7 @@ public class Registry implements DataEntity { joinColumns = {@JoinColumn(name = "\"Registry\"", referencedColumnName = "\"ID\"")}, inverseJoinColumns = {@JoinColumn(name = "\"Dataset\"", referencedColumnName = "\"ID\"")} ) - private Set datasets; + private Set descriptionEntities; @Column(name = "\"Status\"", nullable = false) private Short status; @@ -123,11 +124,11 @@ public class Registry implements DataEntity { this.definition = definition; } - public Set getDatasets() { - return datasets; + public Set getDatasets() { + return descriptionEntities; } - public void setDatasets(Set datasets) { - this.datasets = datasets; + public void setDatasets(Set descriptionEntities) { + this.descriptionEntities = descriptionEntities; } public UserInfo getCreationUser() { diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionBuilder.java index add5e0c10..59dc49387 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionBuilder.java @@ -3,14 +3,12 @@ package eu.eudat.model.builder; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.convention.ConventionService; import eu.eudat.data.DescriptionEntity; -import eu.eudat.data.DmpEntity; import eu.eudat.model.Description; import eu.eudat.model.DescriptionReference; import eu.eudat.model.Dmp; import eu.eudat.model.DmpReference; import eu.eudat.query.DescriptionReferenceQuery; import eu.eudat.query.DmpQuery; -import eu.eudat.query.DmpReferenceQuery; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.exception.MyApplicationException; diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/DatasetCriteria.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/DatasetCriteria.java index f78caa2dd..19316d26d 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/DatasetCriteria.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/DatasetCriteria.java @@ -1,6 +1,6 @@ package eu.eudat.data.dao.criteria; -import eu.eudat.data.old.Dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.elastic.entities.Tag; import java.util.Date; @@ -8,7 +8,7 @@ import java.util.List; import java.util.UUID; -public class DatasetCriteria extends Criteria { +public class DatasetCriteria extends Criteria { private Integer status; private Date periodStart; private Date periodEnd; diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/DatasetPublicCriteria.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/DatasetPublicCriteria.java index e0a034de2..75cc8c2e7 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/DatasetPublicCriteria.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/DatasetPublicCriteria.java @@ -1,6 +1,6 @@ package eu.eudat.data.dao.criteria; -import eu.eudat.data.old.Dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.elastic.entities.Tag; import eu.eudat.types.grant.GrantStateType; @@ -10,7 +10,7 @@ import java.util.UUID; /** * Created by ikalyvas on 10/2/2018. */ -public class DatasetPublicCriteria extends Criteria{ +public class DatasetPublicCriteria extends Criteria{ private GrantStateType grantStatus; private List grants; private List datasetProfile; diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DatasetDao.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DatasetDao.java index 2d66b03f9..d2c87cfe6 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DatasetDao.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DatasetDao.java @@ -2,7 +2,7 @@ package eu.eudat.data.dao.entities; import eu.eudat.data.dao.DatabaseAccessLayer; import eu.eudat.data.dao.criteria.DatasetCriteria; -import eu.eudat.data.old.Dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.old.UserInfo; import eu.eudat.queryable.QueryableList; @@ -10,14 +10,14 @@ import javax.management.InvalidApplicationException; import java.util.List; import java.util.UUID; -public interface DatasetDao extends DatabaseAccessLayer { +public interface DatasetDao extends DatabaseAccessLayer { - QueryableList getWithCriteria(DatasetCriteria criteria); + QueryableList getWithCriteria(DatasetCriteria criteria); - QueryableList filterFromElastic(DatasetCriteria criteria, List ids); + QueryableList filterFromElastic(DatasetCriteria criteria, List ids); - QueryableList getAuthenticated(QueryableList query, UserInfo principal, List roles); + QueryableList getAuthenticated(QueryableList query, UserInfo principal, List roles); - Dataset isPublicDataset(UUID id) throws InvalidApplicationException; + DescriptionEntity isPublicDataset(UUID id) throws InvalidApplicationException; } \ No newline at end of file diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DatasetDaoImpl.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DatasetDaoImpl.java index 98c6b2abc..ef18a6652 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DatasetDaoImpl.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DatasetDaoImpl.java @@ -1,10 +1,12 @@ package eu.eudat.data.dao.entities; +import eu.eudat.commons.enums.DescriptionStatus; +import eu.eudat.commons.enums.IsActive; 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.old.Dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.old.UserInfo; import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.types.FieldSelectionType; @@ -25,17 +27,17 @@ import java.util.UUID; import java.util.concurrent.CompletableFuture; @Component("datasetDao") -public class DatasetDaoImpl extends DatabaseAccess implements DatasetDao { +public class DatasetDaoImpl extends DatabaseAccess implements DatasetDao { @Autowired - public DatasetDaoImpl(DatabaseService databaseService) { super(databaseService); } + public DatasetDaoImpl(DatabaseService databaseService) { super(databaseService); } @Override - public QueryableList getWithCriteria(DatasetCriteria criteria) { - QueryableList query = getDatabaseService().getQueryable(Dataset.getHints(), Dataset.class); + public QueryableList getWithCriteria(DatasetCriteria criteria) { + QueryableList query = getDatabaseService().getQueryable(DescriptionEntity.getHints(), DescriptionEntity.class); if (criteria.getIsPublic() != null && criteria.getIsPublic()) { query.where((builder, root) -> builder.equal(root.get("dmp").get("isPublic"), true)); - query.where((builder, root) -> builder.equal(root.get("status"), Dataset.Status.FINALISED.getValue())); + query.where((builder, root) -> builder.equal(root.get("status"), DescriptionStatus.Finalized)); /*query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"), query.subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class)));*/ @@ -83,13 +85,13 @@ public class DatasetDaoImpl extends DatabaseAccess implements DatasetDa if (criteria.hasDoi()) { query.where((builder, root) -> builder.not(builder.isNull(root.join("dmp").join("dois").get("id")))); } - query.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.DELETED.getValue())); - query.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.CANCELED.getValue())); + query.where((builder, root) -> builder.notEqual(root.get(DescriptionEntity._isActive), IsActive.Inactive)); + query.where((builder, root) -> builder.notEqual(root.get("status"), DescriptionStatus.Canceled)); return query; } - public QueryableList filterFromElastic(DatasetCriteria criteria, List ids) { - QueryableList query = getDatabaseService().getQueryable(Dataset.getHints(), Dataset.class); + public QueryableList filterFromElastic(DatasetCriteria criteria, List ids) { + QueryableList query = getDatabaseService().getQueryable(DescriptionEntity.getHints(), DescriptionEntity.class); query.where(((builder, root) -> root.get("id").in(ids))); if (!criteria.getAllVersions()) @@ -99,32 +101,32 @@ public class DatasetDaoImpl extends DatabaseAccess implements DatasetDa } @Override - public Dataset createOrUpdate(Dataset item) { - return getDatabaseService().createOrUpdate(item, Dataset.class); + public DescriptionEntity createOrUpdate(DescriptionEntity item) { + return getDatabaseService().createOrUpdate(item, DescriptionEntity.class); } @Override - public Dataset find(UUID id) throws InvalidApplicationException { - return getDatabaseService().getQueryable(Dataset.class) - .where((builder, root) -> builder.and(builder.notEqual(root.get("status"),Dataset.Status.DELETED.getValue()), builder.notEqual(root.get("status"),Dataset.Status.CANCELED.getValue()), builder.equal((root.get("id")), id))).getSingle(); + public DescriptionEntity find(UUID id) throws InvalidApplicationException { + return getDatabaseService().getQueryable(DescriptionEntity.class) + .where((builder, root) -> builder.and(builder.notEqual(root.get(DescriptionEntity._isActive), IsActive.Inactive), builder.notEqual(root.get("status"), DescriptionStatus.Canceled), builder.equal((root.get("id")), id))).getSingle(); } @Override - public Dataset find(UUID id, String hint) throws InvalidApplicationException { - return getDatabaseService().getQueryable(Dataset.getHints(), Dataset.class).withHint(hint) - .where((builder, root) -> builder.and(builder.notEqual(root.get("status"),Dataset.Status.DELETED.getValue()), builder.notEqual(root.get("status"),Dataset.Status.CANCELED.getValue()), builder.equal((root.get("id")), id))).getSingle(); + public DescriptionEntity find(UUID id, String hint) throws InvalidApplicationException { + return getDatabaseService().getQueryable(DescriptionEntity.getHints(), DescriptionEntity.class).withHint(hint) + .where((builder, root) -> builder.and(builder.notEqual(root.get(DescriptionEntity._isActive), IsActive.Inactive), builder.notEqual(root.get("status"), DescriptionStatus.Canceled), builder.equal((root.get("id")), id))).getSingle(); } @Override - public Dataset isPublicDataset(UUID id) throws InvalidApplicationException { - QueryableList query = getDatabaseService().getQueryable(Dataset.getHints(), Dataset.class); + public DescriptionEntity isPublicDataset(UUID id) throws InvalidApplicationException { + QueryableList query = getDatabaseService().getQueryable(DescriptionEntity.getHints(), DescriptionEntity.class); query.where(((builder, root) -> builder.equal(root.get("id"), id))); return query.withHint("datasetListingModel").getSingle(); } @Override - public QueryableList getAuthenticated(QueryableList query, UserInfo principal, List roles) { + public QueryableList getAuthenticated(QueryableList query, UserInfo principal, List roles) { if (roles != null && !roles.isEmpty()) { query.where((builder, root) -> { Join userJoin = root.join("dmp", JoinType.LEFT).join("users", JoinType.LEFT); @@ -138,17 +140,17 @@ public class DatasetDaoImpl extends DatabaseAccess implements DatasetDa } @Override - public void delete(Dataset item) { + public void delete(DescriptionEntity item) { this.getDatabaseService().delete(item); } @Override - public QueryableList asQueryable() { - return this.getDatabaseService().getQueryable(Dataset.class); + public QueryableList asQueryable() { + return this.getDatabaseService().getQueryable(DescriptionEntity.class); } @Async - public CompletableFuture createOrUpdateAsync(Dataset item) { + public CompletableFuture createOrUpdateAsync(DescriptionEntity item) { return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item)); } } diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/query/items/table/dataset/DatasetPublicTableRequest.java b/dmp-backend/data/src/main/java/eu/eudat/data/query/items/table/dataset/DatasetPublicTableRequest.java index b0d4e91a1..879abf9a7 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/query/items/table/dataset/DatasetPublicTableRequest.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/query/items/table/dataset/DatasetPublicTableRequest.java @@ -1,7 +1,9 @@ package eu.eudat.data.query.items.table.dataset; +import eu.eudat.commons.enums.DescriptionStatus; +import eu.eudat.commons.enums.IsActive; import eu.eudat.data.dao.criteria.DatasetPublicCriteria; -import eu.eudat.data.old.Dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.query.definition.TableQuery; import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.types.FieldSelectionType; @@ -15,12 +17,12 @@ import java.util.UUID; /** * Created by ikalyvas on 10/2/2018. */ -public class DatasetPublicTableRequest extends TableQuery { +public class DatasetPublicTableRequest extends TableQuery { @Override - public QueryableList applyCriteria() { - QueryableList query = this.getQuery(); + public QueryableList applyCriteria() { + QueryableList query = this.getQuery(); query.where((builder, root) -> builder.equal(root.get("dmp").get("isPublic"), true)); - query.where((builder, root) -> builder.equal(root.get("status"), Dataset.Status.FINALISED.getValue())); + query.where((builder, root) -> builder.equal(root.get("status"), DescriptionStatus.Finalized.getValue())); query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"), query.subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class))); @@ -45,12 +47,12 @@ public class DatasetPublicTableRequest extends TableQuery root.get("profile").get("id").in(this.getCriteria().getDatasetProfile()))); if (this.getCriteria().getDmpOrganisations() != null && !this.getCriteria().getDmpOrganisations().isEmpty()) query .where(((builder, root) -> root.join("dmp").join("organisations").get("reference").in(this.getCriteria().getDmpOrganisations()))); - query.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.DELETED.getValue())); + query.where((builder, root) -> builder.notEqual(root.get(DescriptionEntity._isActive), IsActive.Inactive)); return query; } @Override - public QueryableList applyPaging(QueryableList items) { + public QueryableList applyPaging(QueryableList items) { return null; } } diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/query/items/table/dataset/DatasetTableRequest.java b/dmp-backend/data/src/main/java/eu/eudat/data/query/items/table/dataset/DatasetTableRequest.java index aa0350107..8aed206f2 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/query/items/table/dataset/DatasetTableRequest.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/query/items/table/dataset/DatasetTableRequest.java @@ -1,7 +1,8 @@ package eu.eudat.data.query.items.table.dataset; +import eu.eudat.commons.enums.DescriptionStatus; import eu.eudat.data.dao.criteria.DatasetCriteria; -import eu.eudat.data.old.Dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.query.definition.TableQuery; import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.types.FieldSelectionType; @@ -10,10 +11,10 @@ import eu.eudat.queryable.types.SelectionField; import java.util.Arrays; import java.util.UUID; -public class DatasetTableRequest extends TableQuery { +public class DatasetTableRequest extends TableQuery { @Override - public QueryableList applyCriteria() { - QueryableList query = this.getQuery(); + public QueryableList applyCriteria() { + QueryableList 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() + "%"), @@ -28,12 +29,12 @@ public class DatasetTableRequest extends TableQuery builder.equal(root.get("dmp").get("version"), query.subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class))); if (this.getCriteria().getDmpIds() != null && !this.getCriteria().getDmpIds().isEmpty()) query.where((builder, root) -> root.get("dmp").get("id").in(this.getCriteria().getDmpIds())); - query.where((builder, root) -> builder.equal(root.get("status"), Dataset.Status.FINALISED)); + query.where((builder, root) -> builder.equal(root.get("status"), DescriptionStatus.Finalized)); return query; } @Override - public QueryableList applyPaging(QueryableList items) { + public QueryableList applyPaging(QueryableList items) { return null; } } diff --git a/dmp-backend/data/src/main/java/eu/eudat/query/DMPQuery.java b/dmp-backend/data/src/main/java/eu/eudat/query/DMPQuery.java index 3c7597285..208acaac8 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/query/DMPQuery.java +++ b/dmp-backend/data/src/main/java/eu/eudat/query/DMPQuery.java @@ -2,7 +2,7 @@ package eu.eudat.query; import eu.eudat.data.dao.DatabaseAccessLayer; import eu.eudat.data.old.DMP; -import eu.eudat.data.old.Dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.old.Grant; import eu.eudat.data.old.UserInfo; import eu.eudat.queryable.QueryableList; @@ -134,7 +134,7 @@ public class DMPQuery extends Query { query.where((builder, root) -> root.get("creator").get("id").in(userInfoSubQuery)); } if(this.datasetQuery != null){ - Subquery datasetSubQuery = this.datasetQuery.getQuery().query(Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:id"))); + Subquery datasetSubQuery = this.datasetQuery.getQuery().query(Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:id"))); query.where((builder, root) -> root.get("id").in(datasetSubQuery )); } if (!this.getSelectionFields().isEmpty() && this.getSelectionFields() != null) { diff --git a/dmp-backend/data/src/main/java/eu/eudat/query/DatasetQuery.java b/dmp-backend/data/src/main/java/eu/eudat/query/DatasetQuery.java index a2f577f30..0667f77e9 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/query/DatasetQuery.java +++ b/dmp-backend/data/src/main/java/eu/eudat/query/DatasetQuery.java @@ -2,7 +2,7 @@ package eu.eudat.query; import eu.eudat.data.dao.DatabaseAccessLayer; import eu.eudat.data.old.DMP; -import eu.eudat.data.old.Dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.types.FieldSelectionType; import eu.eudat.queryable.types.SelectionField; @@ -14,17 +14,17 @@ import java.util.Arrays; import java.util.List; import java.util.UUID; -public class DatasetQuery extends Query { +public class DatasetQuery extends Query { private UUID id; private String label; private DMPQuery dmpQuery; - public DatasetQuery(DatabaseAccessLayer databaseAccessLayer) { + public DatasetQuery(DatabaseAccessLayer databaseAccessLayer) { super(databaseAccessLayer); } - public DatasetQuery(DatabaseAccessLayer databaseAccessLayer, List selectionFields) { + public DatasetQuery(DatabaseAccessLayer databaseAccessLayer, List selectionFields) { super(databaseAccessLayer, selectionFields); } @@ -53,8 +53,8 @@ public class DatasetQuery extends Query { } @Override - public QueryableList getQuery() throws InvalidApplicationException { - QueryableList query = this.databaseAccessLayer.asQueryable(); + public QueryableList getQuery() throws InvalidApplicationException { + QueryableList query = this.databaseAccessLayer.asQueryable(); if (this.id != null) { query.where((builder, root) -> builder.equal(root.get("id"), this.id)); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java index dd31b1823..928e421a0 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java @@ -7,7 +7,7 @@ import eu.eudat.criteria.DMPCriteria; import eu.eudat.data.dao.criteria.DynamicFieldsCriteria; import eu.eudat.data.dao.criteria.RequestItem; import eu.eudat.data.old.DMP; -import eu.eudat.data.old.Dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem; import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest; import eu.eudat.exceptions.datamanagementplan.DMPNewVersionException; @@ -31,7 +31,6 @@ import eu.eudat.models.data.listingmodels.UserInfoListingModel; import eu.eudat.models.data.listingmodels.VersionListingModel; import eu.eudat.query.DMPQuery; import eu.eudat.types.ApiMessageCode; -import eu.eudat.types.Authorities; import gr.cite.commons.web.authz.service.AuthorizationService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -373,21 +372,21 @@ public class DMPs extends BaseController { @Transactional @RequestMapping(method = RequestMethod.POST, value = {"/index"}) public @ResponseBody - ResponseEntity> generateIndex() throws Exception { + ResponseEntity> generateIndex() throws Exception { this.authorizationService.authorizeForce(Permission.AuthenticatedRole); this.dataManagementPlanManager.generateIndex(); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Generated").payload(null)); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Generated").payload(null)); } @Transactional @RequestMapping(method = RequestMethod.DELETE, value = {"/index"}) public @ResponseBody - ResponseEntity> clearIndex() throws Exception { + ResponseEntity> clearIndex() throws Exception { this.authorizationService.authorizeForce(Permission.AuthenticatedRole); this.dataManagementPlanManager.clearIndex(); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Cleared").payload(null)); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Cleared").payload(null)); } /* diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfileController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfileController.java index 5bb6d6a14..77c0ed8f6 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfileController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfileController.java @@ -38,7 +38,7 @@ public class DatasetProfileController extends BaseController { /* @Transactional @RequestMapping(method = RequestMethod.POST, value = {"/datasetprofile/save/{id}"}, consumes = "application/json", produces = "application/json") public ResponseEntity updateDataset(@PathVariable String id, @RequestBody PropertiesModel properties) { - eu.eudat.data.old.Dataset dataset = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao().find(UUID.fromString(id)); + eu.eudat.data.Dataset dataset = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao().find(UUID.fromString(id)); Map values = new HashMap<>(); properties.toMap(values); JSONObject jobject = new JSONObject(values); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/Datasets.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/Datasets.java index 9bdec08b6..3cea26486 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/Datasets.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/Datasets.java @@ -2,7 +2,7 @@ package eu.eudat.controllers; import eu.eudat.authorization.Permission; import eu.eudat.commons.scope.user.UserScope; -import eu.eudat.data.old.Dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.query.items.item.dataset.DatasetWizardAutocompleteRequest; import eu.eudat.data.query.items.item.datasetprofile.DatasetProfileWizardAutocompleteRequest; @@ -289,33 +289,33 @@ public class Datasets extends BaseController { @Transactional @RequestMapping(method = RequestMethod.GET, value = {"/makepublic/{id}"}, produces = "application/json") public @ResponseBody - ResponseEntity> makePublic(@PathVariable UUID id, Locale locale) throws Exception { + ResponseEntity> makePublic(@PathVariable UUID id, Locale locale) throws Exception { this.authorizationService.authorizeForce(Permission.AuthenticatedRole); this.datasetManager.makePublic(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), id); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message(this.getApiContext().getHelpersService().getMessageSource().getMessage("dataset.public", new Object[]{}, locale))); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message(this.getApiContext().getHelpersService().getMessageSource().getMessage("dataset.public", new Object[]{}, locale))); } @Transactional @RequestMapping(method = RequestMethod.DELETE, value = {"/delete/{id}"}, produces = "application/json") public @ResponseBody - ResponseEntity> delete(@PathVariable(value = "id") UUID id) throws Exception { + ResponseEntity> delete(@PathVariable(value = "id") UUID id) throws Exception { new DatasetWizardManager().delete(this.getApiContext(), id); this.fileManager.markAllFilesOfEntityIdAsDeleted(id); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Deleted")); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Deleted")); } @Transactional @RequestMapping(method = RequestMethod.GET, value = {"/{id}/unlock"}, produces = "application/json") public @ResponseBody - ResponseEntity> unlock(@PathVariable(value = "id") UUID id) throws Exception { + ResponseEntity> unlock(@PathVariable(value = "id") UUID id) throws Exception { this.authorizationService.authorizeForce(Permission.AuthenticatedRole); try { new DatasetWizardManager().unlock(this.getApiContext(), id); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Unlocked")); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Unlocked")); } catch (DatasetWizardCannotUnlockException datasetWizardCannotUnlockException) { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(datasetWizardCannotUnlockException.getMessage())); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(datasetWizardCannotUnlockException.getMessage())); } } @@ -324,8 +324,8 @@ public class Datasets extends BaseController { ResponseEntity> validate(@PathVariable(value = "id") UUID id) throws Exception { this.authorizationService.authorizeForce(Permission.AuthenticatedRole); - Dataset dataset = datasetManager.getEntitySingle(id); - String failedField = datasetManager.checkDatasetValidation(dataset); + DescriptionEntity descriptionEntity = datasetManager.getEntitySingle(id); + String failedField = datasetManager.checkDatasetValidation(descriptionEntity); if (failedField == null) { return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Valid")); } else { @@ -342,8 +342,8 @@ public class Datasets extends BaseController { this.authorizationService.authorizeForce(Permission.AuthenticatedRole); try { - Dataset dataset = this.datasetManager.createDatasetFromXml(file, dmpId, datasetProfileId); - if (dataset != null){ + DescriptionEntity descriptionEntity = this.datasetManager.createDatasetFromXml(file, dmpId, datasetProfileId); + if (descriptionEntity != null){ return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE)); } else { @@ -362,21 +362,21 @@ public class Datasets extends BaseController { @Transactional @RequestMapping(method = RequestMethod.POST, value = {"/index"}) public @ResponseBody - ResponseEntity> generateIndex() throws Exception { + ResponseEntity> generateIndex() throws Exception { this.authorizationService.authorizeForce(Permission.AuthenticatedRole); this.datasetManager.generateIndex(); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Generated").payload(null)); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Generated").payload(null)); } @Transactional @RequestMapping(method = RequestMethod.DELETE, value = {"/index"}) public @ResponseBody - ResponseEntity> clearIndex() throws Exception { + ResponseEntity> clearIndex() throws Exception { this.authorizationService.authorizeForce(Permission.AuthenticatedRole); this.datasetManager.clearIndex(); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Cleared").payload(null)); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Cleared").payload(null)); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/FileController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/FileController.java index 25c93c066..71ca835ef 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/FileController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/FileController.java @@ -1,8 +1,5 @@ package eu.eudat.controllers; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.Permission; import eu.eudat.commons.XmlHandlingService; @@ -10,29 +7,27 @@ import eu.eudat.commons.enums.FieldType; import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity; import eu.eudat.commons.types.descriptiontemplate.FieldEntity; -import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity; -import eu.eudat.commons.types.descriptiontemplate.SectionEntity; import eu.eudat.commons.types.descriptiontemplate.fielddata.UploadDataEntity; import eu.eudat.data.DescriptionTemplateEntity; -import eu.eudat.data.old.Dataset; +import eu.eudat.data.DescriptionEntity; +import eu.eudat.data.DmpEntity; +import eu.eudat.data.old.DMP; import eu.eudat.data.old.FileUpload; import eu.eudat.exceptions.security.UnauthorisedException; import eu.eudat.logic.managers.DatasetProfileManager; import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.operations.DatabaseRepository; import eu.eudat.logic.utilities.documents.helpers.FileEnvelope; -import eu.eudat.logic.utilities.json.JsonSearcher; import eu.eudat.models.HintedModelFactory; import eu.eudat.models.data.datasetwizard.DatasetWizardModel; import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.query.DescriptionTemplateQuery; +import eu.eudat.query.DmpQuery; import eu.eudat.types.ApiMessageCode; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.query.QueryFactory; import jakarta.xml.bind.JAXBException; import org.apache.poi.util.IOUtils; -import org.json.JSONArray; -import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.http.HttpHeaders; @@ -40,7 +35,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.util.unit.DataSize; -import org.springframework.util.unit.DataUnit; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -147,11 +141,14 @@ public class FileController { } if(fileUpload.getEntityType().name().equals(FileUpload.EntityType.DATASET.name())) { - Dataset datasetEntity = databaseRepository.getDatasetDao().find(fileUpload.getEntityId(), HintedModelFactory.getHint(DatasetWizardModel.class)); - if (datasetEntity == null) { + DescriptionEntity descriptionEntityEntity = databaseRepository.getDatasetDao().find(fileUpload.getEntityId(), HintedModelFactory.getHint(DatasetWizardModel.class)); + if (descriptionEntityEntity == null) { throw new NoSuchElementException("No dataset with id " + fileUpload.getEntityId() + " found. This dataset was related to the file with id " + id); } - if (!datasetEntity.getDmp().isPublic() && datasetEntity.getDmp().getUsers() + + DMP dmp = databaseRepository.getDmpDao().find(descriptionEntityEntity.getDmp()); + + if (!dmp.isPublic() && dmp.getUsers() .stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())) .collect(Collectors.toList()).size() == 0) throw new UnauthorisedException(); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionTemplateController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionTemplateController.java index 42e33cd00..e4f763683 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionTemplateController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionTemplateController.java @@ -3,6 +3,7 @@ package eu.eudat.controllers.v2; import com.fasterxml.jackson.core.JsonProcessingException; import eu.eudat.audit.AuditableAction; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.authorization.Permission; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.model.DescriptionTemplate; import eu.eudat.model.DmpBlueprint; @@ -12,9 +13,11 @@ import eu.eudat.model.censorship.DmpBlueprintCensor; import eu.eudat.model.persist.DescriptionTemplatePersist; import eu.eudat.model.persist.NewVersionDescriptionTemplatePersist; import eu.eudat.model.result.QueryResult; +import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.query.DescriptionTemplateQuery; import eu.eudat.query.lookup.DescriptionTemplateLookup; import eu.eudat.service.descriptiontemplate.DescriptionTemplateService; +import eu.eudat.types.ApiMessageCode; import gr.cite.tools.auditing.AuditService; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.censor.CensorFactory; @@ -30,6 +33,7 @@ import jakarta.xml.bind.JAXBException; import org.slf4j.LoggerFactory; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.transaction.annotation.Transactional; diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DashBoardManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DashBoardManager.java index 7e090371e..b71b9a1c7 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DashBoardManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DashBoardManager.java @@ -1,5 +1,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.dao.criteria.DataManagementPlanCriteria; import eu.eudat.data.dao.criteria.DatasetCriteria; @@ -10,7 +12,7 @@ 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.old.Dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.old.Grant; import eu.eudat.data.old.UserInfo; import eu.eudat.data.query.items.table.dataset.DatasetTableRequest; @@ -97,7 +99,7 @@ public class DashBoardManager { LinkedList grants = new LinkedList<>(); for (DMP dmp : dmps) { numberOfDatasets = numberOfDatasets + dmp.getDataset().stream() - .filter(item -> item.getStatus() == Dataset.Status.FINALISED.getValue()).count(); + .filter(item -> item.getStatus() == DescriptionStatus.Finalized).count(); if (dmp.getGrant() != null) { grants.add(dmp.getGrant()); } @@ -206,7 +208,7 @@ public class DashBoardManager { .withHint("datasetRecentActivity") .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((datasetActivities, throwable) -> activity.setRecentDatasetActivities(datasetActivities)); CompletableFuture> grants = grantRepository.getAuthenticated(grantRepository.getWithCriteria(grantCriteria), user) @@ -317,7 +319,7 @@ public class DashBoardManager { CompletableFuture> publicDatasets = datasetRepository.asQueryable() .where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%")) - .where((builder, root) -> builder.equal(root.get("status"), Dataset.Status.FINALISED.getValue())) + .where((builder, root) -> builder.equal(root.get("status"), DescriptionStatus.Finalized)) .where((builder, root) -> builder.equal(root.get("dmp").get("isPublic"), true)) .orderBy((builder, root) -> builder.desc(root.get("modified"))) .selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.DATASET.getValue(), true)) @@ -335,8 +337,8 @@ public class DashBoardManager { CompletableFuture> datasets = datasetRepository.getAuthenticated(datasetRepository.asQueryable(), user, roles) .withHint("datasetRecentActivity") .where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%")) - .where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.DELETED.getValue())) - .where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.CANCELED.getValue())) + .where((builder, root) -> builder.notEqual(root.get(DescriptionEntity._isActive), IsActive.Inactive)) + .where((builder, root) -> builder.notEqual(root.get("status"), DescriptionStatus.Canceled)) .orderBy((builder, root) -> builder.desc(root.get("modified"))) .selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.DATASET.getValue(), false)) .whenComplete((dataSetItems, throwable) -> searchBarItems.addAll(dataSetItems)); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java index 73f512fde..235db7ff4 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java @@ -4,11 +4,12 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import eu.eudat.authorization.Permission; import eu.eudat.commons.XmlHandlingService; +import eu.eudat.commons.enums.*; import eu.eudat.commons.scope.user.UserScope; -import eu.eudat.commons.enums.EntityType; import eu.eudat.commons.types.dmpblueprint.*; import eu.eudat.configurations.dynamicgrant.DynamicGrantConfiguration; import eu.eudat.configurations.dynamicgrant.entities.Property; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DmpBlueprintEntity; import eu.eudat.data.EntityDoiEntity; import eu.eudat.data.dao.criteria.*; @@ -59,8 +60,6 @@ import eu.eudat.models.data.dmp.*; import eu.eudat.models.data.doi.DepositRequest; import eu.eudat.models.data.doi.Doi; import eu.eudat.models.data.dynamicfields.DynamicFieldWithValue; -import eu.eudat.commons.enums.DmpBlueprintFieldCategory; -import eu.eudat.commons.enums.DmpBlueprintSystemFieldType; import eu.eudat.models.data.funder.FunderDMPEditorModel; import eu.eudat.models.data.grant.GrantDMPEditorModel; import eu.eudat.models.data.helpermodels.Tuple; @@ -69,6 +68,7 @@ import eu.eudat.models.data.listingmodels.*; import eu.eudat.models.data.project.ProjectDMPEditorModel; import eu.eudat.models.data.user.composite.PagedDatasetProfile; import eu.eudat.models.data.userinfo.UserListingModel; +import eu.eudat.query.DescriptionTemplateQuery; import eu.eudat.query.DmpBlueprintQuery; import eu.eudat.queryable.QueryableList; import eu.eudat.service.dmpblueprint.DmpBlueprintService; @@ -279,12 +279,12 @@ public class DataManagementPlanManager { return dataTable; } - private Set retrieveRelevantDatasets(DatasetCriteria datasetCriteria) throws InvalidApplicationException { + private Set retrieveRelevantDatasets(DatasetCriteria datasetCriteria) throws InvalidApplicationException { return retrieveRelevantDatasets(datasetCriteria, null); } - private Set retrieveRelevantDatasets (DatasetCriteria datasetCriteria, UUID principal) throws InvalidApplicationException { - QueryableList datasetItems = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(datasetCriteria) + private Set retrieveRelevantDatasets (DatasetCriteria datasetCriteria, UUID principal) throws InvalidApplicationException { + QueryableList datasetItems = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(datasetCriteria) .orderBy((builder, root) -> builder.desc(root.get("modified"))); if (principal != null) { UserInfo userInfo = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal); @@ -297,13 +297,13 @@ public class DataManagementPlanManager { DatasetTableRequest datasetTableRequest = new DatasetTableRequest(); datasetTableRequest.setOffset(0); datasetTableRequest.setLength(3); - Set datasetsSet = new LinkedHashSet<>(); + Set datasetsSet = new LinkedHashSet<>(); try { datasetItems = PaginationManager.applyPaging(datasetItems, datasetTableRequest); - List datasets = datasetItems.distinct().toList(); - datasetsSet.addAll(datasets); - for (int i = 0; i < maxDatasets - datasets.size(); i++) { - Dataset fakedataset = new Dataset(); + List descriptionEntities = datasetItems.distinct().toList(); + datasetsSet.addAll(descriptionEntities); + for (int i = 0; i < maxDatasets - descriptionEntities.size(); i++) { + DescriptionEntity fakedataset = new DescriptionEntity(); fakedataset.setId(UUID.randomUUID()); datasetsSet.add(fakedataset); } @@ -349,7 +349,7 @@ public class DataManagementPlanManager { }); });*/ if (isPublic) { - dataManagementPlan.setDatasets(dataManagementPlan.getDatasets().stream().filter(dataset -> dataset.getStatus() == Dataset.Status.FINALISED.getValue()).collect(Collectors.toList())); + dataManagementPlan.setDatasets(dataManagementPlan.getDatasets().stream().filter(dataset -> dataset.getStatus() == DescriptionStatus.Finalized).collect(Collectors.toList())); } } else { dataManagementPlan.fromDataModelNoDatasets(dataManagementPlanEntity); @@ -383,7 +383,7 @@ public class DataManagementPlanManager { datamanagementPlan.fromDataModelDatasets(dataManagementPlanEntity); datamanagementPlan.setDatasets(datamanagementPlan.getDatasets().stream().sorted(Comparator.comparing(DatasetOverviewModel::getCreated).reversed()).collect(Collectors.toList())); if (isPublic) { - datamanagementPlan.setDatasets(datamanagementPlan.getDatasets().stream().filter(dataset -> dataset.getStatus() == Dataset.Status.FINALISED.getValue()).collect(Collectors.toList())); + datamanagementPlan.setDatasets(datamanagementPlan.getDatasets().stream().filter(dataset -> dataset.getStatus() == DescriptionStatus.Finalized).collect(Collectors.toList())); } return datamanagementPlan; @@ -492,9 +492,9 @@ public class DataManagementPlanManager { if (dbTime.toEpochMilli() != modelTime.toEpochMilli()) { throw new Exception("Another user have already edit that DMP."); } - List datasetList = dmp1.getDataset().stream().filter(dataset -> dataset.getStatus() != 99).collect(Collectors.toList()); - for (Dataset dataset : datasetList) { - if (dataManagementPlan.getProfiles().stream().filter(associatedProfile -> dataset.getProfile().getId().equals(associatedProfile.getDescriptionTemplateId())).findAny().orElse(null) == null) + List descriptionEntityList = dmp1.getDataset().stream().filter(dataset -> dataset.getIsActive() != IsActive.Inactive).collect(Collectors.toList()); + for (DescriptionEntity descriptionEntity : descriptionEntityList) { + if (dataManagementPlan.getProfiles().stream().filter(associatedProfile -> descriptionEntity.getProfile().equals(associatedProfile.getDescriptionTemplateId())).findAny().orElse(null) == null) throw new Exception("Dataset Template for Dataset Description is missing from the DMP."); } if (dataManagementPlan.getStatus() == (int) DMP.DMPStatus.FINALISED.getValue() && dmp1.getStatus().equals(DMP.DMPStatus.FINALISED.getValue())) @@ -596,32 +596,32 @@ public class DataManagementPlanManager { if (dataManagementPlan.getDatasetsToBeFinalized() != null && !dataManagementPlan.getDatasetsToBeFinalized().isEmpty()) { apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao() .asQueryable().where((builder, root) -> root.get("id").in(dataManagementPlan.getDatasetsToBeFinalized())) - .update(root -> root.get("status"), Dataset.Status.FINALISED.getValue()); + .update(root -> root.get("status"), DescriptionStatus.Finalized); apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao() .asQueryable().where((builder, root) -> root.get("id").in(dataManagementPlan.getDatasetsToBeFinalized())) .update(root -> root.get("finalizedat"), new Date()); List datasetsToBeCanceled = new LinkedList<>(); for (DatasetWizardModel dataset : dataManagementPlan.getDatasets()) { - if (!(dataset.getStatus() == (int) Dataset.Status.FINALISED.getValue()) && !dataManagementPlan.getDatasetsToBeFinalized().contains(dataset.getId())) { + if (!(dataset.getStatus() == DescriptionStatus.Finalized) && !dataManagementPlan.getDatasetsToBeFinalized().contains(dataset.getId())) { datasetsToBeCanceled.add(UUID.fromString(dataset.getId().toString())); } } if (!datasetsToBeCanceled.isEmpty()) apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao() .asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeCanceled)) - .update(root -> root.get("status"), Dataset.Status.CANCELED.getValue()); + .update(root -> root.get("status"), DescriptionStatus.Canceled); } else { List datasetsToBeCanceled = new LinkedList<>(); for (DatasetWizardModel dataset : dataManagementPlan.getDatasets()) { - if (!(dataset.getStatus() == (int) Dataset.Status.FINALISED.getValue())) { + if (!(dataset.getStatus() == DescriptionStatus.Finalized)) { datasetsToBeCanceled.add(dataset.getId()); } } if (!datasetsToBeCanceled.isEmpty()) apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao() .asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeCanceled)) - .update(root -> root.get("status"), Dataset.Status.CANCELED.getValue()); + .update(root -> root.get("status"), DescriptionStatus.Canceled); } } @@ -666,7 +666,7 @@ public class DataManagementPlanManager { } else { metricsManager.increaseValue(MetricNames.DMP, 1, MetricNames.DRAFT); } - List datasets = new ArrayList<>(); + List descriptionEntities = new ArrayList<>(); DMP tempDMP = dataManagementPlan.toDataModel(); if (tempDMP.getStatus() == (int) DMP.DMPStatus.FINALISED.getValue()) { checkDmpValidationRules(tempDMP); @@ -689,8 +689,8 @@ public class DataManagementPlanManager { for (DatasetWizardModel datasetWizardModel: dataManagementPlan.getDatasets()) { datasetWizardModel.setDmp(new DataManagementPlan().fromDataModel(result)); - Dataset dataset = datasetManager.createOrUpdate(datasetWizardModel); - datasets.add(dataset); + DescriptionEntity descriptionEntity = datasetManager.createOrUpdate(datasetWizardModel); + descriptionEntities.add(descriptionEntity); } UUID dmpId = result.getId(); @@ -910,15 +910,15 @@ public class DataManagementPlanManager { } catch (IOException | InvalidApplicationException e) { logger.error(e.getMessage(), e); } - for (Dataset dataset: dmp.getDataset()) { + for (DescriptionEntity descriptionEntity : dmp.getDataset()) { try { List tags = new ArrayList<>(); - eu.eudat.elastic.entities.Dataset elastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(dataset.getId().toString()); + eu.eudat.elastic.entities.Dataset elastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(descriptionEntity.getId().toString()); if (elastic != null) { tags = elastic.getTags(); } - dataset.setDmp(dmp); - this.datasetManager.updateTags(dataset, tags); + descriptionEntity.setDmp(dmp.getId()); + this.datasetManager.updateTags(descriptionEntity, tags); } catch (Exception e) { logger.error(e.getMessage(), e); } @@ -1040,89 +1040,97 @@ public class DataManagementPlanManager { } private void copyDatasets(DMP newDmp, DatasetDao datasetDao) throws InvalidApplicationException { - List> futures = new LinkedList<>(); - for (Dataset dataset : newDmp.getDataset()) { - Dataset tempDataset = datasetDao.find(dataset.getId()); + List> futures = new LinkedList<>(); + for (DescriptionEntity descriptionEntity : newDmp.getDataset()) { + DescriptionEntity tempDescriptionEntity = datasetDao.find(descriptionEntity.getId()); try { List tags = new ArrayList<>(); - eu.eudat.elastic.entities.Dataset elastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(dataset.getId().toString()); + eu.eudat.elastic.entities.Dataset elastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(descriptionEntity.getId().toString()); if (elastic != null) { tags = elastic.getTags(); } - UUID dmpId = tempDataset.getDmp().getId(); - tempDataset.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); - this.datasetManager.updateTags(tempDataset, tags); + UUID dmpId = tempDescriptionEntity.getDmp(); + //TODO + //tempDescriptionEntity.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); + this.datasetManager.updateTags(tempDescriptionEntity, tags); } catch (Exception e) { logger.error(e.getMessage(), e); } - datasetDao.asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class)).where((builder, root) -> builder.equal(root.get("id"), dataset.getId())).getSingleAsync() + datasetDao.asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class)).where((builder, root) -> builder.equal(root.get("id"), descriptionEntity.getId())).getSingleAsync() .thenApplyAsync(entityDataset -> { - Dataset newDataset = new Dataset(); - newDataset.update(entityDataset); - newDataset.setDmp(newDmp); - newDataset.setStatus(Dataset.Status.SAVED.getValue()); - if (newDataset.getDatasetDataRepositories() != null) { - newDataset.setDatasetDataRepositories(newDataset.getDatasetDataRepositories().stream().map(item -> { - DataRepository dataRepository = new DataRepository(); - dataRepository.setId(item.getDataRepository().getId()); - - DatasetDataRepository datasetDataRepository = new DatasetDataRepository(); - datasetDataRepository.setDataRepository(dataRepository); - datasetDataRepository.setDataset(newDataset); - datasetDataRepository.setData(item.getData()); - return datasetDataRepository; - }).collect(Collectors.toSet())); - } - - if (newDataset.getDatasetExternalDatasets() != null) { - newDataset.setDatasetExternalDatasets(newDataset.getDatasetExternalDatasets().stream().map(item -> { - ExternalDataset externalDataset = new ExternalDataset(); - externalDataset.setId(item.getExternalDataset().getId()); - DatasetExternalDataset datasetExternalDataset = new DatasetExternalDataset(); - datasetExternalDataset.setExternalDataset(externalDataset); - datasetExternalDataset.setDataset(newDataset); - datasetExternalDataset.setData(item.getData()); - return datasetExternalDataset; - }).collect(Collectors.toSet())); - } - - if (newDataset.getRegistries() != null) { - newDataset.setRegistries(newDataset.getRegistries().stream().map(item -> { - Registry registry = new Registry(); - registry.setId(item.getId()); - return registry; - }).collect(Collectors.toSet())); - } - - if (newDataset.getServices() != null) { - newDataset.setServices(newDataset.getServices().stream().map(item -> { - Service service = new Service(); - service.setId(item.getId()); - DatasetService datasetService = new DatasetService(); - datasetService.setService(service); - datasetService.setDataset(newDataset); - datasetService.setData(item.getData()); - return datasetService; - }).collect(Collectors.toSet())); - } - newDataset.setCreated(new Date()); - return newDataset; + DescriptionEntity newDescriptionEntity = new DescriptionEntity(); + newDescriptionEntity.update(entityDataset); + newDescriptionEntity.setDmp(newDmp.getId()); + newDescriptionEntity.setStatus(DescriptionStatus.Saved); + //TODO +// if (newDescriptionEntity.getDatasetDataRepositories() != null) { +// newDescriptionEntity.setDatasetDataRepositories(newDescriptionEntity.getDatasetDataRepositories().stream().map(item -> { +// DataRepository dataRepository = new DataRepository(); +// dataRepository.setId(item.getDataRepository().getId()); +// +// DatasetDataRepository datasetDataRepository = new DatasetDataRepository(); +// datasetDataRepository.setDataRepository(dataRepository); +// datasetDataRepository.setDataset(newDescriptionEntity); +// datasetDataRepository.setData(item.getData()); +// return datasetDataRepository; +// }).collect(Collectors.toSet())); +// } +// +// if (newDescriptionEntity.getDatasetExternalDatasets() != null) { +// newDescriptionEntity.setDatasetExternalDatasets(newDescriptionEntity.getDatasetExternalDatasets().stream().map(item -> { +// ExternalDataset externalDataset = new ExternalDataset(); +// externalDataset.setId(item.getExternalDataset().getId()); +// DatasetExternalDataset datasetExternalDataset = new DatasetExternalDataset(); +// datasetExternalDataset.setExternalDataset(externalDataset); +// datasetExternalDataset.setDataset(newDescriptionEntity); +// datasetExternalDataset.setData(item.getData()); +// return datasetExternalDataset; +// }).collect(Collectors.toSet())); +// } +// +// if (newDescriptionEntity.getRegistries() != null) { +// newDescriptionEntity.setRegistries(newDescriptionEntity.getRegistries().stream().map(item -> { +// Registry registry = new Registry(); +// registry.setId(item.getId()); +// return registry; +// }).collect(Collectors.toSet())); +// } +// +// if (newDescriptionEntity.getServices() != null) { +// newDescriptionEntity.setServices(newDescriptionEntity.getServices().stream().map(item -> { +// Service service = new Service(); +// service.setId(item.getId()); +// DatasetService datasetService = new DatasetService(); +// datasetService.setService(service); +// datasetService.setDataset(newDescriptionEntity); +// datasetService.setData(item.getData()); +// return datasetService; +// }).collect(Collectors.toSet())); +// } + newDescriptionEntity.setCreatedAt(Instant.now()); + return newDescriptionEntity; }).thenApplyAsync(item -> { futures.add(datasetDao.createOrUpdateAsync(item).whenComplete(((dataset1, throwable) -> { + DMP dmp = null; + try { + dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(dataset1.getDmp()); + } catch (InvalidApplicationException e) { + throw new RuntimeException(e); + } metricsManager.increaseValue(MetricNames.DATASET, 1, MetricNames.DRAFT); eu.eudat.elastic.entities.Dataset datasetElastic = new eu.eudat.elastic.entities.Dataset(); datasetElastic.setId(dataset1.getId().toString()); datasetElastic.setLabel(dataset1.getLabel()); datasetElastic.setDescription(dataset1.getDescription()); - datasetElastic.setTemplate(dataset1.getProfile().getId()); - datasetElastic.setStatus(dataset1.getStatus()); - datasetElastic.setDmp(dataset1.getDmp().getId()); - datasetElastic.setGroup(dataset1.getDmp().getGroupId()); - if(this.dmpBlueprintService.fieldInBlueprint(dataset1.getDmp().getProfile(), DmpBlueprintSystemFieldType.Grant)) { - datasetElastic.setGrant(dataset1.getDmp().getGrant().getId()); + datasetElastic.setTemplate(dataset1.getProfile()); + datasetElastic.setStatus(dataset1.getStatus().getValue()); + datasetElastic.setDmp(dataset1.getDmp()); + datasetElastic.setGroup(dmp.getGroupId()); + if(this.dmpBlueprintService.fieldInBlueprint(dmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { + datasetElastic.setGrant(dmp.getGrant().getId()); } - if (dataset1.getDmp().getUsers() != null) { - datasetElastic.setCollaborators(dataset1.getDmp().getUsers().stream().map(user -> { + if (dmp.getUsers() != null) { + datasetElastic.setCollaborators(dmp.getUsers().stream().map(user -> { Collaborator collaborator = new Collaborator(); collaborator.setId(user.getId().toString()); collaborator.setRole(user.getRole()); @@ -1132,21 +1140,21 @@ public class DataManagementPlanManager { } datasetElastic.setLastVersion(true); datasetElastic.setLastPublicVersion(false); - if (dataset1.getDmp().getOrganisations() != null) { - datasetElastic.setOrganizations(dataset1.getDmp().getOrganisations().stream().map(org -> { + if (dmp.getOrganisations() != null) { + datasetElastic.setOrganizations(dmp.getOrganisations().stream().map(org -> { Organization organization = new Organization(); organization.setId(org.getId().toString()); organization.setName(org.getLabel()); return organization; }).collect(Collectors.toList())); } - datasetElastic.setPublic(dataset1.getDmp().isPublic()); - if(this.dmpBlueprintService.fieldInBlueprint(dataset1.getDmp().getProfile(), DmpBlueprintSystemFieldType.Grant)) { - datasetElastic.setGrantStatus(dataset1.getDmp().getGrant().getStatus()); + datasetElastic.setPublic(dmp.isPublic()); + if(this.dmpBlueprintService.fieldInBlueprint(dmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { + datasetElastic.setGrantStatus(dmp.getGrant().getStatus()); } try { - eu.eudat.elastic.entities.Dataset oldDatasetElastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(dataset.getId().toString()); + eu.eudat.elastic.entities.Dataset oldDatasetElastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(descriptionEntity.getId().toString()); if (oldDatasetElastic != null) { datasetElastic.setTags(oldDatasetElastic.getTags()); } @@ -1186,8 +1194,9 @@ public class DataManagementPlanManager { if (elastic != null) { tags = elastic.getTags(); } - UUID tmdmpId = dataset.getDmp().getId(); - dataset.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), tmdmpId)).toList())); + UUID tmdmpId = dataset.getDmp(); + //TODO + //dataset.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), tmdmpId)).toList())); this.datasetManager.updateTags(dataset, tags); metricsManager.increaseValue(MetricNames.DATASET, 1, MetricNames.PUBLISHED); } catch (Exception e) { @@ -1206,27 +1215,27 @@ public class DataManagementPlanManager { throw new Exception("User does not have the privilege to do this action."); if (dmp.getStatus().equals(DMP.DMPStatus.FINALISED.getValue())) throw new Exception("DMP is already finalized"); - List indexDatasets = new ArrayList<>(); + List indexDescriptionEntities = new ArrayList<>(); if (datasetsToBeFinalized != null && datasetsToBeFinalized.getUuids() != null && !datasetsToBeFinalized.getUuids().isEmpty()) { - List finalizedDatasets = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao() + List finalizedDescriptionEntities = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao() .asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeFinalized.getUuids())) .toList(); - for (Dataset dataset: finalizedDatasets) { - Dataset.Status status = Dataset.Status.fromInteger(dataset.getStatus()); - Date finalizedDate = dataset.getFinalizedAt(); - dataset.setStatus(Dataset.Status.FINALISED.getValue()); - dataset.setFinalizedAt(new Date()); + for (DescriptionEntity descriptionEntity : finalizedDescriptionEntities) { + DescriptionStatus status = descriptionEntity.getStatus(); + Instant finalizedDate = descriptionEntity.getFinalizedAt(); + descriptionEntity.setStatus(DescriptionStatus.Finalized); + descriptionEntity.setFinalizedAt(Instant.now()); DatasetWizardModel wizardModel = new DatasetWizardModel(); - wizardModel = wizardModel.fromDataModel(dataset); - wizardModel.setDatasetProfileDefinition(this.datasetManager.getPagedProfile(wizardModel, dataset)); + wizardModel = wizardModel.fromDataModel(descriptionEntity); + wizardModel.setDatasetProfileDefinition(this.datasetManager.getPagedProfile(wizardModel, descriptionEntity)); try { datasetManager.createOrUpdate(wizardModel); } catch (Exception e) { - dataset.setStatus(status.getValue()); - dataset.setFinalizedAt(finalizedDate); + descriptionEntity.setStatus(status); + descriptionEntity.setFinalizedAt(finalizedDate); throw e; } - dataset.setModified(new Date()); + descriptionEntity.setUpdatedAt(Instant.now()); } /*apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao() .asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeFinalized.getUuids())) @@ -1237,35 +1246,35 @@ public class DataManagementPlanManager { dataset.setFinalizedAt(new Date()); dataset.setModified(new Date()); } );*/ - indexDatasets.addAll(finalizedDatasets); + indexDescriptionEntities.addAll(finalizedDescriptionEntities); List datasetsToBeCanceled = new LinkedList<>(); - for (Dataset dataset : dmp.getDataset()) { - if (!dataset.getStatus().equals(Dataset.Status.FINALISED.getValue()) && !datasetsToBeFinalized.getUuids().contains(dataset.getId())) { - datasetsToBeCanceled.add(dataset.getId()); + for (DescriptionEntity descriptionEntity : dmp.getDataset()) { + if (!descriptionEntity.getStatus().equals(DescriptionStatus.Finalized) && !datasetsToBeFinalized.getUuids().contains(descriptionEntity.getId())) { + datasetsToBeCanceled.add(descriptionEntity.getId()); } } if (!datasetsToBeCanceled.isEmpty()) { apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao() .asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeCanceled)) - .update(root -> root.get("status"), Dataset.Status.CANCELED.getValue()); - List cancelledDatasets = dmp.getDataset().stream().filter(dataset -> datasetsToBeCanceled.contains(dataset.getId())).collect(Collectors.toList()); - cancelledDatasets.forEach(dataset -> dataset.setStatus(Dataset.Status.CANCELED.getValue())); - indexDatasets.addAll(cancelledDatasets); + .update(root -> root.get("status"), DescriptionStatus.Canceled); + List cancelledDescriptionEntities = dmp.getDataset().stream().filter(dataset -> datasetsToBeCanceled.contains(dataset.getId())).collect(Collectors.toList()); + cancelledDescriptionEntities.forEach(dataset -> dataset.setStatus(DescriptionStatus.Canceled)); + indexDescriptionEntities.addAll(cancelledDescriptionEntities); } } else { List datasetsToBeCanceled = new LinkedList<>(); - for (Dataset dataset : dmp.getDataset()) { - if (!dataset.getStatus().equals(Dataset.Status.FINALISED.getValue())) { - datasetsToBeCanceled.add(dataset.getId()); + for (DescriptionEntity descriptionEntity : dmp.getDataset()) { + if (!descriptionEntity.getStatus().equals(DescriptionStatus.Finalized)) { + datasetsToBeCanceled.add(descriptionEntity.getId()); } } if (!datasetsToBeCanceled.isEmpty()) { apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao() .asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeCanceled)) - .update(root -> root.get("status"), Dataset.Status.CANCELED.getValue()); - List cancelledDatasets = dmp.getDataset().stream().filter(dataset -> datasetsToBeCanceled.contains(dataset.getId())).collect(Collectors.toList()); - cancelledDatasets.forEach(dataset -> dataset.setStatus(Dataset.Status.CANCELED.getValue())); - indexDatasets.addAll(cancelledDatasets); + .update(root -> root.get("status"), DescriptionStatus.Canceled); + List cancelledDescriptionEntities = dmp.getDataset().stream().filter(dataset -> datasetsToBeCanceled.contains(dataset.getId())).collect(Collectors.toList()); + cancelledDescriptionEntities.forEach(dataset -> dataset.setStatus(DescriptionStatus.Canceled)); + indexDescriptionEntities.addAll(cancelledDescriptionEntities); } } dmp.setStatus(DMP.DMPStatus.FINALISED.getValue()); @@ -1277,9 +1286,9 @@ public class DataManagementPlanManager { sendNotification(dmp, user, NotificationType.DMP_FINALISED); metricsManager.decreaseValue(MetricNames.DMP, 1, MetricNames.DRAFT); metricsManager.increaseValue(MetricNames.DMP, 1, MetricNames.FINALIZED); - this.updateDatasetsIndex(indexDatasets); - metricsManager.decreaseValue(MetricNames.DATASET, indexDatasets.size(), MetricNames.DRAFT); - metricsManager.increaseValue(MetricNames.DATASET, indexDatasets.size(), MetricNames.FINALIZED); + this.updateDatasetsIndex(indexDescriptionEntities); + metricsManager.decreaseValue(MetricNames.DATASET, indexDescriptionEntities.size(), MetricNames.DRAFT); + metricsManager.increaseValue(MetricNames.DATASET, indexDescriptionEntities.size(), MetricNames.FINALIZED); } public void undoFinalize(UUID id) throws Exception { @@ -1537,11 +1546,11 @@ public class DataManagementPlanManager { final Boolean isFinalized = dmpEntity.getStatus() == DMP.DMPStatus.FINALISED.getValue(); final Boolean isPublic = dmpEntity.isPublic(); dmpEntity.getDataset().stream() - .filter(item -> item.getStatus() != Dataset.Status.CANCELED.getValue()) - .filter(item -> item.getStatus() != Dataset.Status.DELETED.getValue()) - .filter(item -> !isPublic && !isFinalized || item.getStatus() == Dataset.Status.FINALISED.getValue()) + .filter(item -> item.getStatus() != DescriptionStatus.Canceled) + .filter(item -> item.getIsActive() != IsActive.Inactive) + .filter(item -> !isPublic && !isFinalized || item.getStatus() == DescriptionStatus.Finalized) .filter(item -> item.getDmpSectionIndex().equals(section.getOrdinal() - 1)) - .sorted(Comparator.comparing(Dataset::getCreated)) + .sorted(Comparator.comparing(DescriptionEntity::getCreatedAt)) .forEach(datasetEntity -> { Map properties = new HashMap<>(); if (datasetEntity.getProperties() != null) { @@ -1591,7 +1600,7 @@ public class DataManagementPlanManager { //runDatasetTemplate1.setBold(true); //runDatasetTemplate1.setFontSize(12); XWPFRun runDatasetTemplate = datasetTemplateParagraph.createRun(); - runDatasetTemplate.setText(datasetEntity.getProfile().getLabel()); + runDatasetTemplate.setText(this.queryFactory.query(DescriptionTemplateQuery.class).ids(datasetEntity.getProfile()).first().getLabel()); runDatasetTemplate.setColor("116a78"); //runDatasetTemplate.setBold(true); //runDatasetTemplate.setFontSize(12); @@ -1637,7 +1646,7 @@ public class DataManagementPlanManager { runDatasetDescription1.setText("Description: "); runDatasetDescription1.setColor("000000"); XWPFRun runDatasetDescription = datasetDescParagraph.createRun(); - runDatasetDescription.setText(datasetEntity.getProfile().getLabel()); + runDatasetDescription.setText(this.queryFactory.query(DescriptionTemplateQuery.class).ids(datasetEntity.getProfile()).first().getLabel()); runDatasetDescription.setColor("116a78"); //wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO, 0); @@ -1709,10 +1718,10 @@ public class DataManagementPlanManager { throw new UnauthorisedException(); final Boolean isFinalized = dmp.getStatus() == DMP.DMPStatus.FINALISED.getValue(); final Boolean isPublic = dmp.isPublic(); - List datasets = dmp.getDataset().stream() - .filter(dataset -> dataset.getStatus() != Dataset.Status.DELETED.getValue() && - dataset.getStatus() != Dataset.Status.CANCELED.getValue()) - .filter(dataset -> !isPublic && !isFinalized || dataset.getStatus() == Dataset.Status.FINALISED.getValue()) + List descriptionEntities = dmp.getDataset().stream() + .filter(dataset -> dataset.getIsActive() != IsActive.Inactive && + dataset.getStatus() != DescriptionStatus.Canceled) + .filter(dataset -> !isPublic && !isFinalized || dataset.getStatus() == DescriptionStatus.Finalized) .collect(Collectors.toList()); /*String fileName = dmp.getLabel(); fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");*/ @@ -1904,33 +1913,33 @@ public class DataManagementPlanManager { dmpElement.appendChild(extraFields); Element datasetsElement = xmlDoc.createElement("datasets"); - for (Dataset dataset : datasets) { + for (DescriptionEntity descriptionEntity : descriptionEntities) { Element datasetElement = xmlDoc.createElement("dataset"); - datasetElement.setAttribute("name", dataset.getLabel()); + datasetElement.setAttribute("name", descriptionEntity.getLabel()); Element datasetDescriptionElement = xmlDoc.createElement("description"); datasetElement.appendChild(datasetDescriptionElement); - datasetDescriptionElement.setTextContent(dataset.getDescription()); + datasetDescriptionElement.setTextContent(descriptionEntity.getDescription()); Element datasetDmpSectionIndex = xmlDoc.createElement("dmpSectionIndex"); datasetElement.appendChild(datasetDmpSectionIndex); - datasetDmpSectionIndex.setTextContent(String.valueOf(dataset.getDmpSectionIndex())); + datasetDmpSectionIndex.setTextContent(String.valueOf(descriptionEntity.getDmpSectionIndex())); Element datsetProfileElement = xmlDoc.createElement("profile-id"); datasetElement.appendChild(datsetProfileElement); - datsetProfileElement.setTextContent(dataset.getProfile().getId().toString()); + datsetProfileElement.setTextContent(descriptionEntity.getProfile().toString()); Element datsetProfileLabelElement = xmlDoc.createElement("profile-label"); datasetElement.appendChild(datsetProfileLabelElement); - datsetProfileLabelElement.setTextContent(dataset.getProfile().getLabel()); + datsetProfileLabelElement.setTextContent(this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntity.getProfile()).first().getLabel()); DatasetWizardModel datasetWizardModel = new DatasetWizardModel(); Map properties = new HashMap<>(); - if (dataset.getProperties() != null) { - JSONObject jobject = new JSONObject(dataset.getProperties()); + if (descriptionEntity.getProperties() != null) { + JSONObject jobject = new JSONObject(descriptionEntity.getProperties()); properties = jobject.toMap(); } - PagedDatasetProfile pagedDatasetProfile = datasetManager.getPagedProfile(datasetWizardModel, dataset); + PagedDatasetProfile pagedDatasetProfile = datasetManager.getPagedProfile(datasetWizardModel, descriptionEntity); visibilityRuleService.setProperties(properties); visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules()); datasetElement.appendChild(xmlBuilder.createPages(pagedDatasetProfile.getPages(), visibilityRuleService, xmlDoc)); @@ -1991,9 +2000,9 @@ public class DataManagementPlanManager { final boolean isFinalized = dmp.getStatus() == DMP.DMPStatus.FINALISED.getValue(); final boolean isPublic = dmp.isPublic(); dmp.setDataset(dmp.getDataset().stream() - .filter(dataset -> dataset.getStatus() != Dataset.Status.DELETED.getValue() && - dataset.getStatus() != Dataset.Status.CANCELED.getValue()) - .filter(dataset -> !isPublic && !isFinalized || dataset.getStatus() == Dataset.Status.FINALISED.getValue()) + .filter(dataset -> dataset.getIsActive() != IsActive.Inactive && + dataset.getStatus() != DescriptionStatus.Canceled) + .filter(dataset -> !isPublic && !isFinalized || dataset.getStatus() == DescriptionStatus.Finalized) .collect(Collectors.toSet())); String result = rdaManager.convertToRDA(dmp); @@ -2220,24 +2229,24 @@ public class DataManagementPlanManager { List datasets = new LinkedList<>(); for (DatasetImportModels das: dataManagementPlans.get(0).getDatasetImportModels()) { - Dataset dataset = new Dataset(); - dataset.setLabel(das.getName()); - dataset.setDmpSectionIndex(das.getDmpSectionIndex()); + DescriptionEntity descriptionEntity = new DescriptionEntity(); + descriptionEntity.setLabel(das.getName()); + descriptionEntity.setDmpSectionIndex(das.getDmpSectionIndex()); try { - dataset.setProfile(databaseRepository.getDatasetProfileDao().find(das.getProfile())); + descriptionEntity.setProfile(das.getProfile()); } catch (Exception ignored) { - dataset.setProfile(databaseRepository.getDatasetProfileDao().find(associatedProfiles.get(0).getDescriptionTemplateId())); + descriptionEntity.setProfile(associatedProfiles.get(0).getDescriptionTemplateId()); } - dataset.setProperties(objectMapper.writeValueAsString(das.getFieldImportModels())); - dataset.setStatus((short) 0); - dataset.setRegistries(new HashSet<>()); - dataset.setDatasetDataRepositories(new HashSet<>()); - dataset.setServices(new HashSet<>()); - dataset.setDatasetExternalDatasets(new HashSet<>()); - dataset.setDmp(dmp); + descriptionEntity.setProperties(objectMapper.writeValueAsString(das.getFieldImportModels())); + descriptionEntity.setStatus(DescriptionStatus.Saved); +// descriptionEntity.setRegistries(new HashSet<>()); +// descriptionEntity.setDatasetDataRepositories(new HashSet<>()); +// descriptionEntity.setServices(new HashSet<>()); +// descriptionEntity.setDatasetExternalDatasets(new HashSet<>()); + descriptionEntity.setDmp(dmp.getId()); DatasetWizardModel datasetWizard = new DatasetWizardModel(); - datasetWizard.setDatasetProfileDefinition(this.datasetManager.getPagedProfile(datasetWizard, dataset)); - datasetWizard.fromDataModel(dataset); + datasetWizard.setDatasetProfileDefinition(this.datasetManager.getPagedProfile(datasetWizard, descriptionEntity)); + datasetWizard.fromDataModel(descriptionEntity); this.datasetManager.createOrUpdate(datasetWizard); // datasets.add(new DatasetListingModel().fromDataModel(dataset)); } @@ -2280,15 +2289,15 @@ public class DataManagementPlanManager { this.updateIndex(dmp); } dmp.getDataset().forEach(dataset -> { - dataset.setStatus(Dataset.Status.SAVED.getValue()); - dataset.setCreated(new Date()); - dataset.setModified(new Date()); - dataset.setDmp(dmp); + dataset.setStatus(DescriptionStatus.Saved); + dataset.setCreatedAt(Instant.now()); + dataset.setUpdatedAt(Instant.now()); + dataset.setDmp(dmp.getId()); dataset = databaseRepository.getDatasetDao().createOrUpdate(dataset); - dataset.setRegistries(new HashSet<>()); - dataset.setDatasetDataRepositories(new HashSet<>()); - dataset.setDatasetExternalDatasets(new HashSet<>()); - dataset.setServices(new HashSet<>()); +// dataset.setRegistries(new HashSet<>()); +// dataset.setDatasetDataRepositories(new HashSet<>()); +// dataset.setDatasetExternalDatasets(new HashSet<>()); +// dataset.setServices(new HashSet<>()); if (dmp.getOrganisations() == null) { dmp.setOrganisations(new HashSet<>()); } @@ -2381,8 +2390,8 @@ public class DataManagementPlanManager { } } - private void updateDatasetsIndex(List datasets) { - datasets.forEach(dataset -> { + private void updateDatasetsIndex(List descriptionEntities) { + descriptionEntities.forEach(dataset -> { List tags = new ArrayList<>(); eu.eudat.elastic.entities.Dataset elastic = null; try { @@ -2390,8 +2399,9 @@ public class DataManagementPlanManager { if (elastic != null) { tags = elastic.getTags(); } - UUID dmpId = dataset.getDmp().getId(); - dataset.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); + UUID dmpId = dataset.getDmp(); + //TODO + //dataset.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); this.datasetManager.updateTags(dataset, tags); } catch (Exception e) { logger.error(e.getMessage(), e); @@ -2570,9 +2580,9 @@ public class DataManagementPlanManager { ZipOutputStream zout = new ZipOutputStream(fout); boolean hasFileUploaded = false; - Set datasets = dmp.getDataset(); - for (Dataset dataset : datasets) { - List files = this.apiContext.getOperationsContext().getDatabaseRepository().getFileUploadDao().getFileUploads(dataset.getId()); + Set descriptionEntities = dmp.getDataset(); + for (DescriptionEntity descriptionEntity : descriptionEntities) { + List files = this.apiContext.getOperationsContext().getDatabaseRepository().getFileUploadDao().getFileUploads(descriptionEntity.getId()); for (FileUpload f : files) { if(!f.getIsDeleted()){ File exportFile = new File(this.environment.getProperty("file.storage") + f.getId()); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java index 55c6af695..7fc2fdef4 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java @@ -5,7 +5,10 @@ import com.fasterxml.jackson.core.JsonProcessingException; 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.IsActive; import eu.eudat.commons.scope.user.UserScope; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.dao.criteria.*; import eu.eudat.data.dao.entities.DataRepositoryDao; @@ -51,9 +54,11 @@ import eu.eudat.models.data.dmp.DataManagementPlan; import eu.eudat.models.data.helpers.common.DataTableData; import eu.eudat.models.data.listingmodels.DatasetListingModel; import eu.eudat.models.data.user.composite.PagedDatasetProfile; +import eu.eudat.query.DescriptionTemplateQuery; import eu.eudat.queryable.QueryableList; import eu.eudat.types.MetricNames; import gr.cite.commons.web.authz.service.AuthorizationService; +import gr.cite.tools.data.query.QueryFactory; import org.apache.poi.xwpf.extractor.XWPFWordExtractor; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFParagraph; @@ -117,10 +122,11 @@ public class DatasetManager { private final FileManager fileManager; private final UserScope userScope; private final AuthorizationService authorizationService; + private final QueryFactory queryFactory; @Autowired public DatasetManager(ApiContext apiContext, UserManager userManager, ConfigLoader configLoader, Environment environment, MetricsManager metricsManager, - FileManager fileManager, UserScope userScope, AuthorizationService authorizationService) { + FileManager fileManager, UserScope userScope, AuthorizationService authorizationService, QueryFactory queryFactory) { this.apiContext = apiContext; this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository(); this.datasetRepository = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository(); @@ -132,6 +138,7 @@ public class DatasetManager { this.fileManager = fileManager; this.userScope = userScope; this.authorizationService = authorizationService; + this.queryFactory = queryFactory; } public DataTableData getPaged(DatasetTableRequest datasetTableRequest) throws Exception { @@ -176,8 +183,8 @@ public class DatasetManager { } UserInfo userInfo = builderFactory.getBuilder(UserInfoBuilder.class).id(this.userScope.getUserIdSafe()).build(); -// QueryableList items = databaseRepository.getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria()).withHint(HintedModelFactory.getHint(DatasetListingModel.class)); - QueryableList items; +// QueryableList items = databaseRepository.getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria()).withHint(HintedModelFactory.getHint(DatasetListingModel.class)); + QueryableList items; if (datasets != null) { if (!datasets.isEmpty()) { @@ -193,8 +200,8 @@ public class DatasetManager { items = databaseRepository.getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria()).withHint(HintedModelFactory.getHint(DatasetListingModel.class));//.withFields(Collections.singletonList("id")); } List roles = new LinkedList<>(); - QueryableList pagedItems; - QueryableList authItems; + QueryableList pagedItems; + QueryableList authItems; if (!datasetTableRequest.getCriteria().getIsPublic()) { if (this.userScope.getUserIdSafe() == null) { throw new UnauthorisedException("You are not allowed to access those datasets"); @@ -251,7 +258,7 @@ public class DatasetManager { } /*datasetTableRequest.setQuery(databaseRepository.getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class))); QueryableList items = datasetTableRequest.applyCriteria();*/ - QueryableList items; + QueryableList items; if (datasets != null) { if (!datasets.isEmpty()) { items = databaseRepository.getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class)); @@ -276,7 +283,7 @@ public class DatasetManager { if (count == 0L) { count = items.count(); } - QueryableList pagedItems = PaginationManager.applyPaging(items, datasetTableRequest); + QueryableList pagedItems = PaginationManager.applyPaging(items, datasetTableRequest); DataTableData dataTable = new DataTableData<>(); List datasetListis = pagedItems. @@ -291,17 +298,18 @@ public class DatasetManager { public DatasetWizardModel getSingle(String id) throws InvalidApplicationException { DatasetWizardModel dataset = new DatasetWizardModel(); - Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); - if (datasetEntity.getDmp().getUsers() + DescriptionEntity descriptionEntityEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); + DMP dmp = databaseRepository.getDmpDao().find(descriptionEntityEntity.getDmp()); + if (dmp.getUsers() .stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())) - .collect(Collectors.toList()).size() == 0 && !datasetEntity.getDmp().isPublic()) + .collect(Collectors.toList()).size() == 0 && !dmp.isPublic()) throw new UnauthorisedException(); - dataset.setDatasetProfileDefinition(getPagedProfile(dataset, datasetEntity)); - dataset.fromDataModel(datasetEntity); + dataset.setDatasetProfileDefinition(getPagedProfile(dataset, descriptionEntityEntity)); + dataset.fromDataModel(descriptionEntityEntity); // Creates the Criteria to get all version of DescriptionTemplate in question. DatasetProfileCriteria profileCriteria = new DatasetProfileCriteria(); - UUID profileId = datasetEntity.getProfile().getGroupId(); + UUID profileId = this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntityEntity.getProfile()).first().getGroupId(); List uuidList = new LinkedList<>(); uuidList.add(profileId); profileCriteria.setGroupIds(uuidList); @@ -332,7 +340,7 @@ public class DatasetManager { DescriptionTemplateEntity profile = profiles.get(0); // Check if the dataset is on the latest Version. - boolean latestVersion = profile.getVersion().toString().equals(datasetEntity.getProfile().getVersion().toString()); + boolean latestVersion = profile.getVersion().toString().equals(this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntityEntity.getProfile()).first().getVersion()); dataset.setIsProfileLatestVersion(latestVersion); eu.eudat.elastic.entities.Dataset datasetElastic; @@ -355,11 +363,11 @@ public class DatasetManager { public DatasetWizardModel getSinglePublic(String id) throws Exception { DatasetWizardModel dataset = new DatasetWizardModel(); - Dataset datasetEntity = databaseRepository.getDatasetDao().isPublicDataset(UUID.fromString(id)); - - if (datasetEntity != null && datasetEntity.getStatus() == 1 && datasetEntity.getDmp().getStatus() == 1) { - dataset.setDatasetProfileDefinition(getPagedProfile(dataset, datasetEntity)); - dataset.fromDataModel(datasetEntity); + DescriptionEntity descriptionEntityEntity = databaseRepository.getDatasetDao().isPublicDataset(UUID.fromString(id)); + DMP dmp = databaseRepository.getDmpDao().find(descriptionEntityEntity.getDmp()); + if (descriptionEntityEntity != null && descriptionEntityEntity.getStatus() == DescriptionStatus.Finalized && dmp.getStatus() == 1) { + dataset.setDatasetProfileDefinition(getPagedProfile(dataset, descriptionEntityEntity)); + dataset.fromDataModel(descriptionEntityEntity); return dataset; } else { throw new Exception("Selected dataset is not public"); @@ -367,34 +375,35 @@ public class DatasetManager { } public DatasetOverviewModel getOverviewSingle(String id, boolean isPublic) throws Exception { - Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id)); - if (datasetEntity.getStatus() == Dataset.Status.DELETED.getValue()) { + DescriptionEntity descriptionEntityEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id)); + if (descriptionEntityEntity.getIsActive() == IsActive.Inactive) { throw new Exception("Dataset is deleted."); } + DMP dmp = databaseRepository.getDmpDao().find(descriptionEntityEntity.getDmp()); if (!isPublic && !this.userScope.isSet()) { throw new UnauthorisedException(); } else - if (!isPublic && datasetEntity.getDmp().getUsers() + if (!isPublic && dmp.getUsers() .stream().noneMatch(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId()))) { throw new UnauthorisedException(); - } else if (isPublic && !datasetEntity.getDmp().isPublic()) { + } else if (isPublic && !dmp.isPublic()) { throw new ForbiddenException("Selected Dataset is not public"); } DatasetOverviewModel dataset = new DatasetOverviewModel(); - dataset.fromDataModel(datasetEntity); + dataset.fromDataModel(descriptionEntityEntity); return dataset; } - public Dataset getEntitySingle(UUID id) throws InvalidApplicationException { + public DescriptionEntity getEntitySingle(UUID id) throws InvalidApplicationException { return databaseRepository.getDatasetDao().find(id); } - public PagedDatasetProfile getPagedProfile(DatasetWizardModel dataset, Dataset datasetEntity) { - eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(datasetEntity.getProfile()); - datasetprofile.setStatus(dataset.getStatus()); - if (datasetEntity.getProperties() != null) { - JSONObject jObject = new JSONObject(datasetEntity.getProperties()); + public PagedDatasetProfile getPagedProfile(DatasetWizardModel dataset, DescriptionEntity descriptionEntityEntity) { + eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntityEntity.getProfile()).first()); + datasetprofile.setStatus(dataset.getStatus().getValue()); + if (descriptionEntityEntity.getProperties() != null) { + JSONObject jObject = new JSONObject(descriptionEntityEntity.getProperties()); Map properties = jObject.toMap(); datasetprofile.fromJsonObject(properties); } @@ -403,18 +412,17 @@ public class DatasetManager { return pagedDatasetProfile; } - private XWPFDocument getWordDocument(ConfigLoader configLoader, Dataset datasetEntity, VisibilityRuleService visibilityRuleService) throws IOException { + private XWPFDocument getWordDocument(ConfigLoader configLoader, DescriptionEntity descriptionEntityEntity, VisibilityRuleService visibilityRuleService) throws IOException, InvalidApplicationException { WordBuilder wordBuilder = new WordBuilder(this.environment, configLoader); DatasetWizardModel dataset = new DatasetWizardModel(); XWPFDocument document = configLoader.getDatasetDocument(); - DMP dmpEntity = datasetEntity.getDmp(); - + DMP dmpEntity = databaseRepository.getDmpDao().find(descriptionEntityEntity.getDmp()); if (!dmpEntity.isPublic() && dmpEntity.getUsers().stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())).collect(Collectors.toList()).size() == 0) throw new UnauthorisedException(); - wordBuilder.fillFirstPage(dmpEntity, datasetEntity, document, true); - wordBuilder.fillFooter(dmpEntity, datasetEntity, document, true); + wordBuilder.fillFirstPage(dmpEntity, descriptionEntityEntity, document, true); + wordBuilder.fillFooter(dmpEntity, descriptionEntityEntity, document, true); int powered_pos = wordBuilder.findPosOfPoweredBy(document); XWPFParagraph powered_par = null; @@ -478,17 +486,17 @@ public class DatasetManager { }*/ Map properties = new HashMap<>(); - if (datasetEntity.getProperties() != null) { - JSONObject jObject = new JSONObject(datasetEntity.getProperties()); + if (descriptionEntityEntity.getProperties() != null) { + JSONObject jObject = new JSONObject(descriptionEntityEntity.getProperties()); properties = jObject.toMap(); } // wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER2, BigInteger.ZERO); - PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset, datasetEntity); + PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset, descriptionEntityEntity); visibilityRuleService.setProperties(properties); visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules()); wordBuilder.build(document, pagedDatasetProfile, visibilityRuleService); - String label = datasetEntity.getLabel().replaceAll("[^a-zA-Z0-9+ ]", ""); + String label = descriptionEntityEntity.getLabel().replaceAll("[^a-zA-Z0-9+ ]", ""); // File exportFile = new File(label + ".docx"); // Removes the top empty headings. @@ -546,17 +554,18 @@ public class DatasetManager { } public FileEnvelope getWordDocumentFile(ConfigLoader configLoader, String id, VisibilityRuleService visibilityRuleService) throws IOException, InvalidApplicationException { - Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); - if (!datasetEntity.getDmp().isPublic() && datasetEntity.getDmp().getUsers() + DescriptionEntity descriptionEntityEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); + DMP dmp = databaseRepository.getDmpDao().find(descriptionEntityEntity.getDmp()); + if (!dmp.isPublic() && dmp.getUsers() .stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())) .collect(Collectors.toList()).size() == 0) throw new UnauthorisedException(); - String label = datasetEntity.getLabel().replaceAll("[^a-zA-Z0-9+ ]", ""); + String label = descriptionEntityEntity.getLabel().replaceAll("[^a-zA-Z0-9+ ]", ""); FileEnvelope exportEnvelope = new FileEnvelope(); exportEnvelope.setFilename(label + ".docx"); String uuid = UUID.randomUUID().toString(); File exportFile = new File(this.environment.getProperty("temp.temp") + uuid + ".docx"); - XWPFDocument document = getWordDocument(configLoader, datasetEntity, visibilityRuleService); + XWPFDocument document = getWordDocument(configLoader, descriptionEntityEntity, visibilityRuleService); FileOutputStream out = new FileOutputStream(exportFile); document.write(out); out.close(); @@ -564,9 +573,9 @@ public class DatasetManager { return exportEnvelope; } - public String getWordDocumentText (Dataset datasetEntity) throws Exception { - DatasetWizardModel datasetWizardModel = new DatasetWizardModel().fromDataModel(datasetEntity); - datasetWizardModel.setDatasetProfileDefinition(this.getPagedProfile(datasetWizardModel, datasetEntity)); + public String getWordDocumentText (DescriptionEntity descriptionEntityEntity) throws Exception { + DatasetWizardModel datasetWizardModel = new DatasetWizardModel().fromDataModel(descriptionEntityEntity); + datasetWizardModel.setDatasetProfileDefinition(this.getPagedProfile(datasetWizardModel, descriptionEntityEntity)); XWPFDocument document = getLightWordDocument(this.configLoader, datasetWizardModel, new VisibilityRuleServiceImpl()); XWPFWordExtractor extractor = new XWPFWordExtractor(document); return extractor.getText();/*.replaceAll("\n\\s*", " ");*/ @@ -575,37 +584,38 @@ public class DatasetManager { public FileEnvelope getXmlDocument(String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException, InvalidApplicationException { ExportXmlBuilder xmlBuilder = new ExportXmlBuilder(); DatasetWizardModel dataset = new DatasetWizardModel(); - Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); - if (!datasetEntity.getDmp().isPublic() && datasetEntity.getDmp().getUsers() + DescriptionEntity descriptionEntityEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); + DMP dmp = databaseRepository.getDmpDao().find(descriptionEntityEntity.getDmp()); + if (!dmp.isPublic() && dmp.getUsers() .stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())) .collect(Collectors.toList()).size() == 0) throw new UnauthorisedException(); Map properties = new HashMap<>(); - if (datasetEntity.getProperties() != null) { - JSONObject jobject = new JSONObject(datasetEntity.getProperties()); + if (descriptionEntityEntity.getProperties() != null) { + JSONObject jobject = new JSONObject(descriptionEntityEntity.getProperties()); properties = jobject.toMap(); } - PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset, datasetEntity); + PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset, descriptionEntityEntity); visibilityRuleService.setProperties(properties); visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules()); - File file = xmlBuilder.build(pagedDatasetProfile, datasetEntity.getProfile().getId(), visibilityRuleService, environment); + File file = xmlBuilder.build(pagedDatasetProfile, descriptionEntityEntity.getProfile(), visibilityRuleService, environment); FileEnvelope fileEnvelope = new FileEnvelope(); fileEnvelope.setFile(file); - String label = datasetEntity.getLabel().replaceAll("[^a-zA-Z0-9+ ]", ""); + String label = descriptionEntityEntity.getLabel().replaceAll("[^a-zA-Z0-9+ ]", ""); fileEnvelope.setFilename(label); return fileEnvelope; } - public Dataset createOrUpdate(DatasetWizardModel datasetWizardModel) throws Exception { + public DescriptionEntity createOrUpdate(DatasetWizardModel datasetWizardModel) throws Exception { Boolean sendNotification = false; - Dataset tempDataset = null; + DescriptionEntity tempDescriptionEntity = null; DMP dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(datasetWizardModel.getDmp().getId()); if (datasetWizardModel.getId() != null) { - tempDataset = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(datasetWizardModel.getId()); - if (tempDataset != null) { + tempDescriptionEntity = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(datasetWizardModel.getId()); + if (tempDescriptionEntity != null) { - Instant dbTime = Instant.ofEpochMilli(tempDataset.getModified().getTime()).truncatedTo(ChronoUnit.SECONDS); - Instant modelTime = Instant.ofEpochMilli(datasetWizardModel.getModified().getTime()).truncatedTo(ChronoUnit.SECONDS); + Instant dbTime = tempDescriptionEntity.getCreatedAt().truncatedTo(ChronoUnit.SECONDS); + Instant modelTime = datasetWizardModel.getModified().truncatedTo(ChronoUnit.SECONDS); if (modelTime.toEpochMilli() != dbTime.toEpochMilli()) { throw new Exception("Dataset has been modified already by another user."); } @@ -616,47 +626,50 @@ public class DatasetManager { } if (dmp.getStatus().equals(DMP.DMPStatus.FINALISED.getValue()) && datasetWizardModel.getId() != null) throw new Exception("DMP is finalized, therefore Dataset cannot be edited."); - Dataset dataset = datasetWizardModel.toDataModel(); - dataset.setDmp(dmp); - dataset.setProperties(propertiesModelToString(datasetWizardModel.getDatasetProfileDefinition())); + DescriptionEntity descriptionEntity = datasetWizardModel.toDataModel(); + descriptionEntity.setDmp(dmp.getId()); + descriptionEntity.setProperties(propertiesModelToString(datasetWizardModel.getDatasetProfileDefinition())); if (this.apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().getClient() != null) { - this.getTagsFromProfile(datasetWizardModel, dataset); + this.getTagsFromProfile(datasetWizardModel, descriptionEntity); } - if (datasetWizardModel.getStatus() == (int) Dataset.Status.FINALISED.getValue()) { - String failedField = checkDatasetValidation(dataset); + if (datasetWizardModel.getStatus() == DescriptionStatus.Finalized) { + String failedField = checkDatasetValidation(descriptionEntity); if (failedField != null) { throw new Exception("Field value of " + failedField + " must be filled."); } } UserInfo userInfo = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(this.userScope.getUserId()).build(); - dataset.setCreator(userInfo); + descriptionEntity.setCreator(userInfo.getId()); - createDataRepositoriesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao(), dataset); - createExternalDatasetsIfTheyDontExist(dataset); - createRegistriesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao(), dataset); - createServicesIfTheyDontExist(dataset); - Dataset dataset1 = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(dataset); - datasetWizardModel.setId(dataset1.getId()); + createDataRepositoriesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao(), descriptionEntity); + createExternalDatasetsIfTheyDontExist(descriptionEntity); + createRegistriesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao(), descriptionEntity); + createServicesIfTheyDontExist(descriptionEntity); + DescriptionEntity descriptionEntity1 = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(descriptionEntity); + datasetWizardModel.setId(descriptionEntity1.getId()); if (datasetWizardModel.getDmp().getGrant() == null) { - datasetWizardModel.setDmp(new DataManagementPlan().fromDataModelNoDatasets(dataset1.getDmp())); + DMP dmp1 = databaseRepository.getDmpDao().find(descriptionEntity1.getDmp()); + + datasetWizardModel.setDmp(new DataManagementPlan().fromDataModelNoDatasets(dmp1)); } - dataset1.setProfile(this.apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(datasetWizardModel.getProfile().getId())); + descriptionEntity1.setProfile(datasetWizardModel.getProfile().getId()); // datasetWizardModel.setDatasetProfileDefinition(getPagedProfile(datasetWizardModel, dataset1)); - UUID dmpId = dataset1.getDmp().getId(); - dataset1.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); - updateTags(dataset1, datasetWizardModel.getTags()); + UUID dmpId = descriptionEntity1.getDmp(); + DMP dmp1 = databaseRepository.getDmpDao().find(descriptionEntity1.getDmp()); + dmp1.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); + updateTags(descriptionEntity1, datasetWizardModel.getTags()); if (sendNotification) { - if (dataset1.getStatus() != Dataset.Status.FINALISED.getValue()) { - this.sendNotification(dataset1, dataset1.getDmp(), userInfo, NotificationType.DATASET_MODIFIED); + if (descriptionEntity1.getStatus() != DescriptionStatus.Finalized) { + this.sendNotification(descriptionEntity1, dmp1, userInfo, NotificationType.DATASET_MODIFIED); } else { - this.sendNotification(dataset1, dataset1.getDmp(), userInfo, NotificationType.DATASET_MODIFIED_FINALISED); + this.sendNotification(descriptionEntity1, dmp1, userInfo, NotificationType.DATASET_MODIFIED_FINALISED); } } this.deleteOldFilesAndAddNew(datasetWizardModel, userInfo); - return dataset1; + return descriptionEntity1; } private void deleteOldFilesAndAddNew(DatasetWizardModel datasetWizardModel, UserInfo userInfo) throws JsonProcessingException, InvalidApplicationException { @@ -697,7 +710,7 @@ public class DatasetManager { }); } - private void sendNotification(Dataset dataset, DMP dmp, UserInfo user, NotificationType notificationType) throws InvalidApplicationException { + private void sendNotification(DescriptionEntity descriptionEntity, DMP dmp, UserInfo user, NotificationType notificationType) throws InvalidApplicationException { List 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())) { @@ -708,8 +721,8 @@ public class DatasetManager { notification.setIsActive(ActiveStatus.ACTIVE); notification.setData("{" + "\"userId\": \"" + userDMP.getUser().getId() + "\"" + - ", \"id\": \"" + dataset.getId() + "\"" + - ", \"name\": \"" + dataset.getLabel() + "\"" + + ", \"id\": \"" + descriptionEntity.getId() + "\"" + + ", \"name\": \"" + descriptionEntity.getLabel() + "\"" + ", \"path\": \"" + notificationPaths.get(notificationType) + "\"" + "}"); notification.setCreatedAt(new Date()); @@ -722,9 +735,9 @@ public class DatasetManager { } - public String checkDatasetValidation(Dataset dataset) throws Exception { + public String checkDatasetValidation(DescriptionEntity descriptionEntity) throws Exception { List datasetProfileValidators = new LinkedList<>(); - DescriptionTemplateEntity profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(dataset.getProfile().getId()); + DescriptionTemplateEntity profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(descriptionEntity.getProfile()); DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); Document xmlDocument = builder.parse(new ByteArrayInputStream(profile.getDefinition().getBytes())); @@ -742,12 +755,12 @@ public class DatasetManager { nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET); - JSONObject obj = new JSONObject(dataset.getProperties()); + JSONObject obj = new JSONObject(descriptionEntity.getProperties()); VisibilityRuleService visibilityRuleService = new VisibilityRuleServiceImpl(); visibilityRuleService.setProperties(obj.toMap()); - dataset.setProfile(profile); - PagedDatasetProfile pagedDatasetProfile = this.getPagedProfile(new DatasetWizardModel(), dataset); + descriptionEntity.setProfile(profile.getId()); + PagedDatasetProfile pagedDatasetProfile = this.getPagedProfile(new DatasetWizardModel(), descriptionEntity); visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules()); @@ -798,7 +811,7 @@ public class DatasetManager { return jobject.toString(); } - public void updateTags(Dataset datasetEntity, List tags) throws Exception { + public void updateTags(DescriptionEntity descriptionEntityEntity, List tags) throws Exception { // if (datasetWizardModel.getTags() != null && !datasetWizardModel.getTags().isEmpty()) { /*eu.eudat.elastic.entities.Dataset dataset = new eu.eudat.elastic.entities.Dataset(); dataset.setId(datasetWizardModel.getId().toString()); @@ -854,92 +867,96 @@ public class DatasetManager { dataset.setGrantStatus(datasetWizardModel.getDmp().getGrant().getStatus()); dataset.setFormData(this.getWordDocumentText(datasetWizardModel));*/ DatasetMapper mapper = new DatasetMapper(apiContext, this); - eu.eudat.elastic.entities.Dataset dataset = mapper.toElastic(datasetEntity, tags); + eu.eudat.elastic.entities.Dataset dataset = mapper.toElastic(descriptionEntityEntity, tags); apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().createOrUpdate(dataset); // } } - private void createRegistriesIfTheyDontExist(RegistryDao registryDao, Dataset dataset) throws InvalidApplicationException { - if (dataset.getRegistries() != null && !dataset.getRegistries().isEmpty()) { - for (Registry registry : dataset.getRegistries()) { - RegistryCriteria criteria = new RegistryCriteria(); - criteria.setLike(registry.getReference()); - List entries = registryDao.getWithCriteria(criteria).toList(); - if (entries != null && !entries.isEmpty()) registry.setId(entries.get(0).getId()); - else { - registry.setCreated(new Date()); - registryDao.createOrUpdate(registry); - } - } - } + private void createRegistriesIfTheyDontExist(RegistryDao registryDao, DescriptionEntity descriptionEntity) throws InvalidApplicationException { + //TODO implement it on create +// if (descriptionEntity.getRegistries() != null && !descriptionEntity.getRegistries().isEmpty()) { +// for (Registry registry : descriptionEntity.getRegistries()) { +// RegistryCriteria criteria = new RegistryCriteria(); +// criteria.setLike(registry.getReference()); +// List entries = registryDao.getWithCriteria(criteria).toList(); +// if (entries != null && !entries.isEmpty()) registry.setId(entries.get(0).getId()); +// else { +// registry.setCreated(new Date()); +// registryDao.createOrUpdate(registry); +// } +// } +// } } - private void createDataRepositoriesIfTheyDontExist(DataRepositoryDao dataRepositoryDao, Dataset dataset) throws InvalidApplicationException { - if (dataset.getDatasetDataRepositories() != null && !dataset.getDatasetDataRepositories().isEmpty()) { - for (DatasetDataRepository datasetDataRepository : dataset.getDatasetDataRepositories()) { - DataRepositoryCriteria criteria = new DataRepositoryCriteria(); - criteria.setLike(datasetDataRepository.getDataRepository().getReference()); - List entries = dataRepositoryDao.getWithCriteria(criteria).toList(); - if (entries != null && !entries.isEmpty()) { - datasetDataRepository.getDataRepository().setId(entries.get(0).getId()); - datasetDataRepository.setDataset(dataset); - dataset.getDatasetDataRepositories().add(datasetDataRepository); - } else { - datasetDataRepository.getDataRepository().setId(UUID.randomUUID()); - DataRepository dataRepository = dataRepositoryDao.createOrUpdate(datasetDataRepository.getDataRepository()); - datasetDataRepository.setDataset(dataset); - datasetDataRepository.setDataRepository(dataRepository); - dataset.getDatasetDataRepositories().add(datasetDataRepository); - } - } - } + private void createDataRepositoriesIfTheyDontExist(DataRepositoryDao dataRepositoryDao, DescriptionEntity descriptionEntity) throws InvalidApplicationException { + //TODO implement it on create +// if (descriptionEntity.getDatasetDataRepositories() != null && !descriptionEntity.getDatasetDataRepositories().isEmpty()) { +// for (DatasetDataRepository datasetDataRepository : descriptionEntity.getDatasetDataRepositories()) { +// DataRepositoryCriteria criteria = new DataRepositoryCriteria(); +// criteria.setLike(datasetDataRepository.getDataRepository().getReference()); +// List entries = dataRepositoryDao.getWithCriteria(criteria).toList(); +// if (entries != null && !entries.isEmpty()) { +// datasetDataRepository.getDataRepository().setId(entries.get(0).getId()); +// datasetDataRepository.setDataset(descriptionEntity); +// descriptionEntity.getDatasetDataRepositories().add(datasetDataRepository); +// } else { +// datasetDataRepository.getDataRepository().setId(UUID.randomUUID()); +// DataRepository dataRepository = dataRepositoryDao.createOrUpdate(datasetDataRepository.getDataRepository()); +// datasetDataRepository.setDataset(descriptionEntity); +// datasetDataRepository.setDataRepository(dataRepository); +// descriptionEntity.getDatasetDataRepositories().add(datasetDataRepository); +// } +// } +// } } - private void createServicesIfTheyDontExist(Dataset dataset) throws InvalidApplicationException { - if (dataset.getServices() != null && !dataset.getServices().isEmpty()) { - for (DatasetService service : dataset.getServices()) { - ServiceCriteria criteria = new ServiceCriteria(); - criteria.setLike(service.getService().getReference()); - List entries = databaseRepository.getServiceDao().getWithCriteria(criteria).toList(); - if (entries != null && !entries.isEmpty()) { - service.setDataset(dataset); - service.getService().setCreated(new Date()); - service.setService(service.getService()); - this.databaseRepository.getServiceDao().createOrUpdate(service.getService()); - dataset.getServices().add(service); - } - } - } + private void createServicesIfTheyDontExist(DescriptionEntity descriptionEntity) throws InvalidApplicationException { + //TODO implement it on create +// if (descriptionEntity.getServices() != null && !descriptionEntity.getServices().isEmpty()) { +// for (DatasetService service : descriptionEntity.getServices()) { +// ServiceCriteria criteria = new ServiceCriteria(); +// criteria.setLike(service.getService().getReference()); +// List entries = databaseRepository.getServiceDao().getWithCriteria(criteria).toList(); +// if (entries != null && !entries.isEmpty()) { +// service.setDataset(descriptionEntity); +// service.getService().setCreated(new Date()); +// service.setService(service.getService()); +// this.databaseRepository.getServiceDao().createOrUpdate(service.getService()); +// descriptionEntity.getServices().add(service); +// } +// } +// } } - private void createExternalDatasetsIfTheyDontExist(Dataset dataset) throws InvalidApplicationException { - if (dataset.getDatasetExternalDatasets() != null && !dataset.getDatasetExternalDatasets().isEmpty()) { - for (DatasetExternalDataset datasetExternalDataset : dataset.getDatasetExternalDatasets()) { - ExternalDatasetCriteria criteria = new ExternalDatasetCriteria(); - criteria.setLike(datasetExternalDataset.getExternalDataset().getReference()); - List entries = databaseRepository.getExternalDatasetDao().getWithCriteria(criteria).toList(); - if (entries != null && !entries.isEmpty()) { - datasetExternalDataset.getExternalDataset().setId(entries.get(0).getId()); - datasetExternalDataset.setDataset(dataset); - dataset.getDatasetExternalDatasets().add(datasetExternalDataset); - } else { - datasetExternalDataset.getExternalDataset().setId(UUID.randomUUID()); - datasetExternalDataset.setDataset(dataset); - ExternalDataset externalDataset = databaseRepository.getExternalDatasetDao().createOrUpdate(datasetExternalDataset.getExternalDataset()); - datasetExternalDataset.setExternalDataset(externalDataset); - dataset.getDatasetExternalDatasets().add(datasetExternalDataset); - } - } - } + private void createExternalDatasetsIfTheyDontExist(DescriptionEntity descriptionEntity) throws InvalidApplicationException { + //TODO implement it on create +// if (descriptionEntity.getDatasetExternalDatasets() != null && !descriptionEntity.getDatasetExternalDatasets().isEmpty()) { +// for (DatasetExternalDataset datasetExternalDataset : descriptionEntity.getDatasetExternalDatasets()) { +// ExternalDatasetCriteria criteria = new ExternalDatasetCriteria(); +// criteria.setLike(datasetExternalDataset.getExternalDataset().getReference()); +// List entries = databaseRepository.getExternalDatasetDao().getWithCriteria(criteria).toList(); +// if (entries != null && !entries.isEmpty()) { +// datasetExternalDataset.getExternalDataset().setId(entries.get(0).getId()); +// datasetExternalDataset.setDataset(descriptionEntity); +// descriptionEntity.getDatasetExternalDatasets().add(datasetExternalDataset); +// } else { +// datasetExternalDataset.getExternalDataset().setId(UUID.randomUUID()); +// datasetExternalDataset.setDataset(descriptionEntity); +// ExternalDataset externalDataset = databaseRepository.getExternalDatasetDao().createOrUpdate(datasetExternalDataset.getExternalDataset()); +// datasetExternalDataset.setExternalDataset(externalDataset); +// descriptionEntity.getDatasetExternalDatasets().add(datasetExternalDataset); +// } +// } +// } } public void makePublic(DatasetDao datasetDao, UUID id) throws Exception { - Dataset dataset = datasetDao.find(id); - if (dataset.getStatus() != Dataset.Status.FINALISED.getValue()) + DescriptionEntity descriptionEntity = datasetDao.find(id); + if (descriptionEntity.getStatus() != DescriptionStatus.Finalized) throw new Exception("You cannot make public a Dataset That Has not Been Finalised"); - datasetDao.createOrUpdate(dataset); + datasetDao.createOrUpdate(descriptionEntity); metricsManager.increaseValue(MetricNames.DATASET, 1, MetricNames.PUBLISHED); } @@ -965,7 +982,7 @@ public class DatasetManager { HttpStatus.OK); } - public Dataset createDatasetFromXml(MultipartFile importFile, String dmpId, String datasetProfileId) throws JAXBException, IOException, InvalidApplicationException { + public DescriptionEntity createDatasetFromXml(MultipartFile importFile, String dmpId, String datasetProfileId) throws JAXBException, IOException, InvalidApplicationException { DatasetImportPagedDatasetProfile importModel = new DatasetImportPagedDatasetProfile(); JAXBContext jaxbContext; @@ -1008,21 +1025,21 @@ public class DatasetManager { JSONObject jsonDatasetProperties = new JSONObject(importMap); // Creates the entity data set to save. - Dataset entity = new Dataset(); + DescriptionEntity entity = new DescriptionEntity(); entity.setProperties(jsonDatasetProperties.toString()); entity.setLabel(importFile.getOriginalFilename()); DMP dmp = new DMP(); dmp.setId(UUID.fromString(dmpId)); - entity.setDmp(dmp); - entity.setStatus((short) 0); - entity.setCreated(new Date()); - entity.setModified(new Date()); + entity.setDmp(dmp.getId()); + entity.setStatus(DescriptionStatus.Saved); + entity.setCreatedAt(Instant.now()); + entity.setUpdatedAt(Instant.now()); DescriptionTemplateEntity profile = new DescriptionTemplateEntity(); profile.setId(UUID.fromString(datasetProfileId)); - entity.setProfile(profile); + entity.setProfile(profile.getId()); UserInfo userInfo = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(this.userScope.getUserId()).build(); - entity.setCreator(userInfo); + entity.setCreator(userInfo.getId()); updateTagsXmlImportDataset(apiContext.getOperationsContext().getElasticRepository().getDatasetRepository(), entity); createRegistriesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao(), entity); @@ -1034,19 +1051,20 @@ public class DatasetManager { return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(entity); } - public void updateTagsXmlImportDataset(DatasetRepository datasetRepository, Dataset dataset) throws IOException { + public void updateTagsXmlImportDataset(DatasetRepository datasetRepository, DescriptionEntity descriptionEntity) throws IOException { // TODO: When tags functionality return. } public DatasetWizardModel datasetUpdateProfile(String id) throws InvalidApplicationException { DatasetWizardModel dataset = new DatasetWizardModel(); - Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); - dataset.setDatasetProfileDefinition(getPagedProfile(dataset, datasetEntity)); - dataset.fromDataModel(datasetEntity); + DescriptionEntity descriptionEntityEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); + dataset.setDatasetProfileDefinition(getPagedProfile(dataset, descriptionEntityEntity)); + dataset.fromDataModel(descriptionEntityEntity); // Creates the Criteria to get all version of DescriptionTemplate in question. DatasetProfileCriteria profileCriteria = new DatasetProfileCriteria(); - UUID profileId = datasetEntity.getProfile().getGroupId(); + + UUID profileId = this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntityEntity.getProfile()).first().getGroupId(); List uuidList = new LinkedList<>(); uuidList.add(profileId); profileCriteria.setGroupIds(uuidList); @@ -1055,7 +1073,7 @@ public class DatasetManager { DescriptionTemplateEntity item = databaseRepository.getDatasetProfileDao().getWithCriteria(profileCriteria).getSingle(); // Sets the latest version of dataet Profile to the Dataset in question. - dataset.setDatasetProfileDefinition(getLatestDatasetProfile(datasetEntity, item)); + dataset.setDatasetProfileDefinition(getLatestDatasetProfile(descriptionEntityEntity, item)); dataset.setProfile(new DatasetProfileOverviewModel().fromDataModel(item)); // Now at latest version. @@ -1078,11 +1096,11 @@ public class DatasetManager { return dataset; } - public PagedDatasetProfile getLatestDatasetProfile(Dataset datasetEntity, DescriptionTemplateEntity profile) { + public PagedDatasetProfile getLatestDatasetProfile(DescriptionEntity descriptionEntityEntity, DescriptionTemplateEntity profile) { eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(profile); - datasetprofile.setStatus(datasetEntity.getStatus()); - if (datasetEntity.getProperties() != null) { - JSONObject jobject = new JSONObject(datasetEntity.getProperties()); + datasetprofile.setStatus(descriptionEntityEntity.getStatus().getValue()); + if (descriptionEntityEntity.getProperties() != null) { + JSONObject jobject = new JSONObject(descriptionEntityEntity.getProperties()); Map properties = jobject.toMap(); datasetprofile.fromJsonObject(properties); } @@ -1108,12 +1126,13 @@ public class DatasetManager { public void generateIndex() throws InvalidApplicationException { if (this.authorizationService.authorize(Permission.AdminRole)) { this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().asQueryable().toList(); - List datasetEntities = new ArrayList<>(this.apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().asQueryable().toList()); - datasetEntities.forEach(datasetEntity -> { + List descriptionEntityEntities = new ArrayList<>(this.apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().asQueryable().toList()); + descriptionEntityEntities.forEach(datasetEntity -> { try { eu.eudat.elastic.entities.Dataset dataset = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(datasetEntity.getId().toString()); - UUID dmpId = datasetEntity.getDmp().getId(); - datasetEntity.getDmp().setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); + UUID dmpId = datasetEntity.getDmp(); + DMP dmp = databaseRepository.getDmpDao().find(datasetEntity.getDmp()); + dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); updateTags(datasetEntity, dataset != null ? dataset.getTags() : null); } catch (Exception e) { logger.error(e.getMessage(), e); @@ -1132,9 +1151,9 @@ public class DatasetManager { } } - public void getTagsFromProfile(DatasetWizardModel wizardModel, Dataset dataset) throws IOException, InvalidApplicationException { - dataset.setProfile(apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(dataset.getProfile().getId())); - wizardModel.setDatasetProfileDefinition(this.getPagedProfile(wizardModel, dataset)); + public void getTagsFromProfile(DatasetWizardModel wizardModel, DescriptionEntity descriptionEntity) throws IOException, InvalidApplicationException { + descriptionEntity.setProfile(descriptionEntity.getProfile()); + wizardModel.setDatasetProfileDefinition(this.getPagedProfile(wizardModel, descriptionEntity)); ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(wizardModel.getDatasetProfileDefinition()); JsonNode propertiesJson = mapper.readTree(json); @@ -1184,7 +1203,7 @@ public class DatasetManager { } @Transactional - private DatasetListingModel mapModel(Dataset item) { + private DatasetListingModel mapModel(DescriptionEntity item) { /*if (item.getProfile() == null) return null;*/ DatasetListingModel listingModel = new DatasetListingModel().fromDataModel(item); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetWizardManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetWizardManager.java index a81ee9701..f1eb4c86f 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetWizardManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetWizardManager.java @@ -1,11 +1,13 @@ 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.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.old.Dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.old.UserInfo; import eu.eudat.data.query.items.item.dataset.DatasetWizardAutocompleteRequest; @@ -51,20 +53,21 @@ public class DatasetWizardManager { } public void unlock(ApiContext apiContext, UUID uuid) throws DatasetWizardCannotUnlockException, InvalidApplicationException { - Dataset dataset = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(uuid); - if(dataset.getDmp().getStatus() == DMP.DMPStatus.FINALISED.getValue()) throw new DatasetWizardCannotUnlockException("To perform this action you will need to revert DMP's finalisation"); - dataset.setStatus(Dataset.Status.SAVED.getValue()); - apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(dataset); + DescriptionEntity descriptionEntity = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(uuid); + DMP dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(descriptionEntity.getDmp()); + if(dmp.getStatus() == DMP.DMPStatus.FINALISED.getValue()) throw new DatasetWizardCannotUnlockException("To perform this action you will need to revert DMP's finalisation"); + descriptionEntity.setStatus(DescriptionStatus.Saved); + apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(descriptionEntity); return; } public void delete(ApiContext apiContext, UUID uuid) throws IOException, InvalidApplicationException { - Dataset oldDataset = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(uuid); + DescriptionEntity oldDescriptionEntity = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(uuid); eu.eudat.elastic.entities.Dataset oldDatasetElasitc = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(uuid.toString()); - oldDataset.setStatus(Dataset.Status.DELETED.getValue()); - apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(oldDataset); + oldDescriptionEntity.setIsActive(IsActive.Inactive); + apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(oldDescriptionEntity); if (oldDatasetElasitc != null && uuid != null && oldDatasetElasitc.getId()!= null) { - oldDatasetElasitc.setStatus(oldDataset.getStatus()); + oldDatasetElasitc.setStatus(oldDescriptionEntity.getStatus().getValue()); apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().createOrUpdate(oldDatasetElasitc); } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MetricsManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MetricsManager.java index 5fa429a96..899980333 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MetricsManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MetricsManager.java @@ -412,7 +412,7 @@ public class MetricsManager { List descriptionTemplateEntities = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().getWithCriteria(criteria).withFields(Collections.singletonList("id")).toList(); DatasetCriteria datasetCriteria = new DatasetCriteria(); datasetCriteria.setDatasetTemplates(descriptionTemplateEntities.stream().map(DescriptionTemplateEntity::getId).collect(Collectors.toList())); - return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(datasetCriteria).select(root -> root.getProfile().getId()).stream().distinct().count(); + return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(datasetCriteria).select(root -> root.getProfile()).stream().distinct().count(); } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/elastic/DatasetMapper.java b/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/elastic/DatasetMapper.java index 310ff1247..16788b972 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/elastic/DatasetMapper.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/elastic/DatasetMapper.java @@ -1,5 +1,6 @@ package eu.eudat.logic.mapper.elastic; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.dao.criteria.DataManagementPlanCriteria; import eu.eudat.data.old.DMP; import eu.eudat.elastic.criteria.DatasetCriteria; @@ -22,64 +23,65 @@ public class DatasetMapper { this.datasetManager = datasetManager; } - public Dataset toElastic(eu.eudat.data.old.Dataset dataset, List tags) throws Exception { - if (dataset.getProfile() == null) { + public Dataset toElastic(DescriptionEntity descriptionEntity, List tags) throws Exception { + if (descriptionEntity.getProfile() == null) { return null; } + //TODO Dataset elastic = new Dataset(); - elastic.setId(dataset.getId().toString()); - if (tags != null && !tags.isEmpty()) { - DatasetCriteria criteria = new DatasetCriteria(); - criteria.setTags(tags); - criteria.setHasTags(true); - List tags1 = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().query(criteria).stream().map(eu.eudat.elastic.entities.Dataset::getTags).flatMap(Collection::stream) - .filter(StreamDistinctBy.distinctByKey(Tag::getId)).filter(tag -> tags.stream().anyMatch(tag1 -> tag1.getName().equals(tag.getName()))).collect(Collectors.toList()); - if (tags1.isEmpty()) { - tags.forEach(tag -> tag.setId(UUID.randomUUID().toString())); - elastic.setTags(tags); - } else { - if (tags1.size() < tags.size()) { - tags.stream().filter(tag -> tag.getId() == null || tag.getId().equals("")).forEach(tag -> tags1.add(new Tag(UUID.randomUUID().toString(), tag.getName()))); - } - elastic.setTags(tags1); - } - } - elastic.setLabel(dataset.getLabel()); - elastic.setDescription(dataset.getDescription()); - elastic.setTemplate(dataset.getProfile().getId()); - elastic.setStatus(dataset.getStatus()); - elastic.setDmp(dataset.getDmp().getId()); - elastic.setGroup(dataset.getDmp().getGroupId()); - if (dataset.getDmp().getGrant() != null) { - elastic.setGrant(dataset.getDmp().getGrant().getId()); - } - elastic.setCreated(dataset.getCreated()); - elastic.setModified(dataset.getModified()); - elastic.setFinalizedAt(dataset.getFinalizedAt()); - if (dataset.getDmp().getUsers() != null) { - elastic.setCollaborators(dataset.getDmp().getUsers().stream().map(user -> CollaboratorMapper.toElastic(user.getUser(), user.getRole())).collect(Collectors.toList())); - } - DataManagementPlanCriteria dmpCriteria = new DataManagementPlanCriteria(); - dmpCriteria.setAllVersions(true); - dmpCriteria.setGroupIds(Collections.singletonList(dataset.getDmp().getGroupId())); - apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dmpCriteria).toList().stream() - .max(Comparator.comparing(DMP::getVersion)).ifPresent(dmp -> elastic.setLastVersion(dmp.getId().equals(dataset.getDmp().getId()))); - apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dmpCriteria).toList().stream().filter(DMP::isPublic) - .max(Comparator.comparing(DMP::getVersion)).ifPresent(dmp -> elastic.setLastPublicVersion(dmp.getId().equals(dataset.getDmp().getId()))); - if (elastic.getLastVersion() == null) { - elastic.setLastVersion(true); - } - if (elastic.getLastPublicVersion() == null) { - elastic.setLastPublicVersion(false); - } - if (dataset.getDmp().getOrganisations() != null) { - elastic.setOrganizations(dataset.getDmp().getOrganisations().stream().map(OrganizationMapper::toElastic).collect(Collectors.toList())); - } - elastic.setPublic(dataset.getDmp().isPublic()); - if (dataset.getDmp().getGrant() != null) { - elastic.setGrantStatus(dataset.getDmp().getGrant().getStatus()); - } - elastic.setFormData(datasetManager.getWordDocumentText(dataset)); +// elastic.setId(descriptionEntity.getId().toString()); +// if (tags != null && !tags.isEmpty()) { +// DatasetCriteria criteria = new DatasetCriteria(); +// criteria.setTags(tags); +// criteria.setHasTags(true); +// List tags1 = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().query(criteria).stream().map(eu.eudat.elastic.entities.Dataset::getTags).flatMap(Collection::stream) +// .filter(StreamDistinctBy.distinctByKey(Tag::getId)).filter(tag -> tags.stream().anyMatch(tag1 -> tag1.getName().equals(tag.getName()))).collect(Collectors.toList()); +// if (tags1.isEmpty()) { +// tags.forEach(tag -> tag.setId(UUID.randomUUID().toString())); +// elastic.setTags(tags); +// } else { +// if (tags1.size() < tags.size()) { +// tags.stream().filter(tag -> tag.getId() == null || tag.getId().equals("")).forEach(tag -> tags1.add(new Tag(UUID.randomUUID().toString(), tag.getName()))); +// } +// elastic.setTags(tags1); +// } +// } +// elastic.setLabel(descriptionEntity.getLabel()); +// elastic.setDescription(descriptionEntity.getDescription()); +// elastic.setTemplate(descriptionEntity.getProfile().getId()); +// elastic.setStatus(descriptionEntity.getStatus()); +// elastic.setDmp(descriptionEntity.getDmp().getId()); +// elastic.setGroup(descriptionEntity.getDmp().getGroupId()); +// if (descriptionEntity.getDmp().getGrant() != null) { +// elastic.setGrant(descriptionEntity.getDmp().getGrant().getId()); +// } +// elastic.setCreated(descriptionEntity.getCreated()); +// elastic.setModified(descriptionEntity.getModified()); +// elastic.setFinalizedAt(descriptionEntity.getFinalizedAt()); +// if (descriptionEntity.getDmp().getUsers() != null) { +// elastic.setCollaborators(descriptionEntity.getDmp().getUsers().stream().map(user -> CollaboratorMapper.toElastic(user.getUser(), user.getRole())).collect(Collectors.toList())); +// } +// DataManagementPlanCriteria dmpCriteria = new DataManagementPlanCriteria(); +// dmpCriteria.setAllVersions(true); +// dmpCriteria.setGroupIds(Collections.singletonList(descriptionEntity.getDmp().getGroupId())); +// apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dmpCriteria).toList().stream() +// .max(Comparator.comparing(DMP::getVersion)).ifPresent(dmp -> elastic.setLastVersion(dmp.getId().equals(descriptionEntity.getDmp().getId()))); +// apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dmpCriteria).toList().stream().filter(DMP::isPublic) +// .max(Comparator.comparing(DMP::getVersion)).ifPresent(dmp -> elastic.setLastPublicVersion(dmp.getId().equals(descriptionEntity.getDmp().getId()))); +// if (elastic.getLastVersion() == null) { +// elastic.setLastVersion(true); +// } +// if (elastic.getLastPublicVersion() == null) { +// elastic.setLastPublicVersion(false); +// } +// if (descriptionEntity.getDmp().getOrganisations() != null) { +// elastic.setOrganizations(descriptionEntity.getDmp().getOrganisations().stream().map(OrganizationMapper::toElastic).collect(Collectors.toList())); +// } +// elastic.setPublic(descriptionEntity.getDmp().isPublic()); +// if (descriptionEntity.getDmp().getGrant() != null) { +// elastic.setGrantStatus(descriptionEntity.getDmp().getGrant().getStatus()); +// } +// elastic.setFormData(datasetManager.getWordDocumentText(descriptionEntity)); return elastic; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/elastic/DmpMapper.java b/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/elastic/DmpMapper.java index bec5ec468..5ec02a294 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/elastic/DmpMapper.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/elastic/DmpMapper.java @@ -70,7 +70,7 @@ public class DmpMapper { if (dataset1 != null) { tags = dataset1.getTags(); } - dataset.setDmp(dmp); + dataset.setDmp(dmp.getId()); return datasetMapper.toElastic(dataset, tags); } catch (Exception e) { logger.error(e.getMessage(), e); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/prefilling/PrefillingMapper.java b/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/prefilling/PrefillingMapper.java index 36d85d510..0d21cb83c 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/prefilling/PrefillingMapper.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/mapper/prefilling/PrefillingMapper.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import eu.eudat.data.old.Dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.elastic.entities.Tag; import eu.eudat.logic.managers.DatasetManager; @@ -52,10 +52,10 @@ public class PrefillingMapper { DescriptionTemplateEntity profile, DatasetManager datasetManager, LicenseManager licenseManager) throws Exception { DatasetWizardModel datasetWizardModel = new DatasetWizardModel(); datasetWizardModel.setProfile(new DatasetProfileOverviewModel().fromDataModel(profile)); - Dataset dataset = new Dataset(); - dataset.setProfile(profile); + DescriptionEntity descriptionEntity = new DescriptionEntity(); + descriptionEntity.setProfile(profile.getId()); Map properties = new HashMap<>(); - JsonNode parentNode = mapper.readTree(mapper.writeValueAsString(datasetManager.getPagedProfile(datasetWizardModel, dataset))); + JsonNode parentNode = mapper.readTree(mapper.writeValueAsString(datasetManager.getPagedProfile(datasetWizardModel, descriptionEntity))); for (DefaultPrefillingMapping prefillingMapping: prefillingGet.getMappings()) { List sourceKeys = Arrays.asList(prefillingMapping.getSource().split("\\.")); Object sourceValue = null; @@ -81,8 +81,8 @@ public class PrefillingMapper { for (PrefillingFixedMapping fixedMapping: prefillingGet.getFixedMappings()) { setValue(fixedMapping, fixedMapping.getValue(), datasetWizardModel, parentNode, properties, type, licenseManager); } - dataset.setProperties(mapper.writeValueAsString(properties)); - datasetWizardModel.setDatasetProfileDefinition(datasetManager.getPagedProfile(datasetWizardModel, dataset)); + descriptionEntity.setProperties(mapper.writeValueAsString(properties)); + datasetWizardModel.setDatasetProfileDefinition(datasetManager.getPagedProfile(datasetWizardModel, descriptionEntity)); return datasetWizardModel; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/security/repositorydeposit/mapper/DMPToDepositMapper.java b/dmp-backend/web/src/main/java/eu/eudat/logic/security/repositorydeposit/mapper/DMPToDepositMapper.java index e26ffbfdf..4a57784f6 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/security/repositorydeposit/mapper/DMPToDepositMapper.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/security/repositorydeposit/mapper/DMPToDepositMapper.java @@ -2,6 +2,7 @@ package eu.eudat.logic.security.repositorydeposit.mapper; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.old.*; import eu.eudat.depositinterface.models.*; import eu.eudat.commons.types.xml.XmlBuilder; @@ -52,11 +53,12 @@ public class DMPToDepositMapper { } @Transactional - private static DatasetDepositModel fromDataset(Dataset entity){ + private static DatasetDepositModel fromDataset(DescriptionEntity entity){ DatasetDepositModel deposit = new DatasetDepositModel(); deposit.setLabel(entity.getLabel()); deposit.setDescription(entity.getDescription()); - deposit.setProfileDefinition(entity.getProfile().getDefinition()); + //TODO + //deposit.setProfileDefinition(entity.getProfile().getDefinition()); deposit.setProperties(entity.getProperties()); deposit.setFields(fromDefinitionAndProperties(deposit.getProfileDefinition(), deposit.getProperties())); return deposit; diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java index 92ae8e04a..7991b6ff6 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java @@ -6,7 +6,7 @@ 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.old.Dataset; +import eu.eudat.data.DescriptionEntity; 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, Dataset datasetEntity, XWPFDocument document, boolean isDataset) { + public void fillFirstPage(DMP dmpEntity, DescriptionEntity descriptionEntityEntity, XWPFDocument document, boolean isDataset) { int parPos = 0; int descrParPos = -1; XWPFParagraph descrPar = null; @@ -1030,17 +1030,17 @@ public class WordBuilder { } else if(text.contains("{ARGOS.DMP.VERSION}")) { text = text.replace("{ARGOS.DMP.VERSION}", "Version " + dmpEntity.getVersion()); r.setText(text, 0); - } else if(datasetEntity != null && text.contains("{ARGOS.DATASET.TITLE}")) { - text = text.replace("{ARGOS.DATASET.TITLE}", datasetEntity.getLabel()); + } else if(descriptionEntityEntity != null && text.contains("{ARGOS.DATASET.TITLE}")) { + text = text.replace("{ARGOS.DATASET.TITLE}", descriptionEntityEntity.getLabel()); r.setText(text, 0); // } else if(text.equals("Description") && ((!isDataset && (dmpEntity == null || dmpEntity.getDescription() != null)) || (isDataset && (datasetEntity == null || datasetEntity.getDescription() == null)))) { // r.setText("", 0); - } else if((dmpEntity != null && text.contains("{ARGOS.DMP.DESCRIPTION}") && !isDataset) || (datasetEntity != null && text.contains("{ARGOS.DATASET.DESCRIPTION}") && isDataset)) { + } else if((dmpEntity != null && text.contains("{ARGOS.DMP.DESCRIPTION}") && !isDataset) || (descriptionEntityEntity != null && text.contains("{ARGOS.DATASET.DESCRIPTION}") && isDataset)) { descrParPos = parPos; descrPar = p; if(dmpEntity != null && !isDataset) { text = text.replace("{ARGOS.DMP.DESCRIPTION}", ""); - } else if(datasetEntity != null && isDataset) { + } else if(descriptionEntityEntity != null && isDataset) { text = text.replace("{ARGOS.DATASET.DESCRIPTION}", ""); } r.setText(text, 0); @@ -1080,10 +1080,10 @@ public class WordBuilder { HtmlToWorldBuilder htmlToWorldBuilder = new HtmlToWorldBuilder(descrPar, 0, cursor); NodeTraversor.traverse(htmlToWorldBuilder, htmlDoc); } - if((descrParPos != -1) && (datasetEntity != null) && (datasetEntity.getDescription() != null) && isDataset) { + if((descrParPos != -1) && (descriptionEntityEntity != null) && (descriptionEntityEntity.getDescription() != null) && isDataset) { XmlCursor cursor = descrPar.getCTP().newCursor(); cursor.toNextSibling(); - Document htmlDoc = Jsoup.parse(((String)datasetEntity.getDescription()).replaceAll("\n", "
")); + Document htmlDoc = Jsoup.parse(((String) descriptionEntityEntity.getDescription()).replaceAll("\n", "
")); HtmlToWorldBuilder htmlToWorldBuilder = new HtmlToWorldBuilder(descrPar, 0, cursor); NodeTraversor.traverse(htmlToWorldBuilder, htmlDoc); } @@ -1116,7 +1116,7 @@ public class WordBuilder { } } - public void fillFooter(DMP dmpEntity, Dataset datasetEntity, XWPFDocument document, boolean isDataset) { + public void fillFooter(DMP dmpEntity, DescriptionEntity descriptionEntityEntity, XWPFDocument document, boolean isDataset) { document.getFooterList().forEach(xwpfFooter -> { List runs = xwpfFooter.getParagraphs().get(0).getRuns(); if(runs != null){ @@ -1127,8 +1127,8 @@ public class WordBuilder { text = text.replace("{ARGOS.DMP.TITLE}", dmpEntity.getLabel()); r.setText(text, 0); } - if(text.contains("{ARGOS.DATASET.TITLE}") && datasetEntity != null){ - text = text.replace("{ARGOS.DATASET.TITLE}", datasetEntity.getLabel()); + if(text.contains("{ARGOS.DATASET.TITLE}") && descriptionEntityEntity != null){ + text = text.replace("{ARGOS.DATASET.TITLE}", descriptionEntityEntity.getLabel()); r.setText(text, 0); } if(text.contains("{ARGOS.DMP.LICENSE}")){ diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/dashboard/recent/model/RecentDatasetModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/dashboard/recent/model/RecentDatasetModel.java index d0304d0f2..a6f965c67 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/dashboard/recent/model/RecentDatasetModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/dashboard/recent/model/RecentDatasetModel.java @@ -1,13 +1,13 @@ package eu.eudat.models.data.dashboard.recent.model; -import eu.eudat.data.old.Dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel; import eu.eudat.models.data.listingmodels.UserInfoListingModel; import java.util.Date; import java.util.stream.Collectors; -public class RecentDatasetModel extends RecentActivityModel { +public class RecentDatasetModel extends RecentActivityModel { private String dmp; private String dmpId; @@ -28,54 +28,56 @@ public class RecentDatasetModel extends RecentActivityModel new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList())); +// this.setId(entity.getId().toString()); +// this.setTitle(entity.getLabel()); +// this.setCreated(entity.getCreated()); +// this.setModified(entity.getModified()); +// this.setStatus(entity.getStatus()); +// this.setVersion(entity.getDmp() != null ? entity.getDmp().getVersion(): 0); +// this.setFinalizedAt(entity.getFinalizedAt()); +// this.setPublishedAt(entity.getDmp() != null ? entity.getDmp().getPublishedAt() : new Date()); +// this.setProfile(entity.getProfile() != null ? new DatasetProfileOverviewModel().fromDataModel(entity.getProfile()): null); +// if (entity.getDmp() != null && entity.getDmp().getGrant() != null) { +// this.setGrant(entity.getDmp().getGrant().getLabel()); +// } +// this.setDmp( entity.getDmp() != null ? entity.getDmp().getLabel() : ""); +// this.setDmpId(entity.getDmp() != null ? entity.getDmp().getId().toString() : ""); +// this.setPublic(entity.getDmp().isPublic()); +// this.setUsers(entity.getDmp().getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList())); return this; } - public RecentDatasetModel fromDmpEntity(Dataset entity) { + public RecentDatasetModel fromDmpEntity(DescriptionEntity entity) { + //TODO this.setType(RecentActivityType.DATASET.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.getDmp() != null ? entity.getDmp().getVersion(): 0); - this.setFinalizedAt(entity.getFinalizedAt()); - this.setPublishedAt(entity.getDmp() != null ? entity.getDmp().getPublishedAt() : new Date()); - this.setProfile(entity.getProfile() != null ? new DatasetProfileOverviewModel().fromDataModel(entity.getProfile()) : null); - if (entity.getDmp() != null && entity.getDmp().getGrant() != null) { - this.setGrant(entity.getDmp().getGrant().getLabel()); - } - this.setDmp( entity.getDmp() != null ? entity.getDmp().getLabel() : ""); - this.setDmpId(entity.getDmp() != null ? entity.getDmp().getId().toString() : ""); +// this.setId(entity.getId().toString()); +// this.setTitle(entity.getLabel()); +// this.setCreated(entity.getCreated()); +// this.setModified(entity.getModified()); +// this.setStatus(entity.getStatus()); +// this.setVersion(entity.getDmp() != null ? entity.getDmp().getVersion(): 0); +// this.setFinalizedAt(entity.getFinalizedAt()); +// this.setPublishedAt(entity.getDmp() != null ? entity.getDmp().getPublishedAt() : new Date()); +// this.setProfile(entity.getProfile() != null ? new DatasetProfileOverviewModel().fromDataModel(entity.getProfile()) : null); +// if (entity.getDmp() != null && entity.getDmp().getGrant() != null) { +// this.setGrant(entity.getDmp().getGrant().getLabel()); +// } +// this.setDmp( entity.getDmp() != null ? entity.getDmp().getLabel() : ""); +// this.setDmpId(entity.getDmp() != null ? entity.getDmp().getId().toString() : ""); return this; } @Override - public RecentDatasetModel fromDataModel(Dataset entity) { + public RecentDatasetModel fromDataModel(DescriptionEntity entity) { return (RecentDatasetModel) this.fromEntity(entity); } @Override - public Dataset toDataModel() throws Exception { + public DescriptionEntity toDataModel() throws Exception { return null; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/dataset/Dataset.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/dataset/Dataset.java index 59e0e92b5..9678024f6 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/dataset/Dataset.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/dataset/Dataset.java @@ -1,5 +1,6 @@ package eu.eudat.models.data.dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.old.DatasetDataRepository; import eu.eudat.data.old.DatasetService; import eu.eudat.models.DataModel; @@ -12,7 +13,7 @@ import java.util.List; import java.util.UUID; import java.util.stream.Collectors; -public class Dataset implements DataModel { +public class Dataset implements DataModel { private UUID id; private String label; private String reference; @@ -131,60 +132,62 @@ public class Dataset implements DataModel { this.profile = profile; } - public Dataset fromDataModel(eu.eudat.data.old.Dataset entity) { - this.id = entity.getId(); - this.label = entity.getLabel(); - this.properties = entity.getProperties(); - this.reference = entity.getReference(); - this.description = entity.getDescription(); - this.profile = new DatasetProfileListingModel(); - this.profile.fromDataModel(entity.getProfile()); - this.registries = entity.getRegistries().stream().map(item -> new Registry().fromDataModel(item)).collect(Collectors.toList()); - this.dataRepositories = entity.getDatasetDataRepositories().stream().map(item -> new DataRepository().fromDataModel(item.getDataRepository())).collect(Collectors.toList()); - this.services = entity.getServices().stream().map(item -> new Service().fromDataModel(item.getService())).collect(Collectors.toList()); - this.created = entity.getCreated(); + public Dataset fromDataModel(DescriptionEntity entity) { + //TODO +// this.id = entity.getId(); +// this.label = entity.getLabel(); +// this.properties = entity.getProperties(); +// this.reference = entity.getReference(); +// this.description = entity.getDescription(); +// this.profile = new DatasetProfileListingModel(); +// this.profile.fromDataModel(entity.getProfile()); +// this.registries = entity.getRegistries().stream().map(item -> new Registry().fromDataModel(item)).collect(Collectors.toList()); +// this.dataRepositories = entity.getDatasetDataRepositories().stream().map(item -> new DataRepository().fromDataModel(item.getDataRepository())).collect(Collectors.toList()); +// this.services = entity.getServices().stream().map(item -> new Service().fromDataModel(item.getService())).collect(Collectors.toList()); +// this.created = entity.getCreated(); return this; } - public eu.eudat.data.old.Dataset toDataModel() throws Exception { - eu.eudat.data.old.Dataset entity = new eu.eudat.data.old.Dataset(); - entity.setId(this.id); - entity.setLabel(this.label); - entity.setReference(this.reference); - entity.setUri(this.uri); - entity.setProperties(this.properties); - entity.setStatus(this.status); - entity.setDmp(dmp.toDataModel()); - entity.setDescription(this.description); - entity.setCreated(this.created != null ? this.created : new Date()); - entity.setModified(new Date()); - entity.setProfile(profile.toDataModel()); ///TODO - if (!this.registries.isEmpty()) { - entity.setRegistries(new HashSet()); - for (Registry registry : this.registries) { - entity.getRegistries().add(registry.toDataModel()); - } - } - - if (!this.dataRepositories.isEmpty()) { - entity.setDatasetDataRepositories(new HashSet<>()); - for (DataRepository dataRepositoryModel : this.dataRepositories) { - DatasetDataRepository datasetDataRepository = new DatasetDataRepository(); - eu.eudat.data.old.DataRepository dataRepository = dataRepositoryModel.toDataModel(); - datasetDataRepository.setDataRepository(dataRepository); - entity.getDatasetDataRepositories().add(datasetDataRepository); - } - } - - if (!this.services.isEmpty()) { - entity.setServices(new HashSet()); - for (Service serviceModel : this.services) { - eu.eudat.data.old.Service service = serviceModel.toDataModel(); - DatasetService datasetService = new DatasetService(); - datasetService.setService(service); - entity.getServices().add(datasetService); - } - } + public DescriptionEntity toDataModel() throws Exception { + DescriptionEntity entity = new DescriptionEntity(); + //TODO +// entity.setId(this.id); +// entity.setLabel(this.label); +// entity.setReference(this.reference); +// entity.setUri(this.uri); +// entity.setProperties(this.properties); +// entity.setStatus(this.status); +// entity.setDmp(dmp.toDataModel()); +// entity.setDescription(this.description); +// entity.setCreated(this.created != null ? this.created : new Date()); +// entity.setModified(new Date()); +// entity.setProfile(profile.toDataModel()); ///TODO +// if (!this.registries.isEmpty()) { +// entity.setRegistries(new HashSet()); +// for (Registry registry : this.registries) { +// entity.getRegistries().add(registry.toDataModel()); +// } +// } +// +// if (!this.dataRepositories.isEmpty()) { +// entity.setDatasetDataRepositories(new HashSet<>()); +// for (DataRepository dataRepositoryModel : this.dataRepositories) { +// DatasetDataRepository datasetDataRepository = new DatasetDataRepository(); +// eu.eudat.data.old.DataRepository dataRepository = dataRepositoryModel.toDataModel(); +// datasetDataRepository.setDataRepository(dataRepository); +// entity.getDatasetDataRepositories().add(datasetDataRepository); +// } +// } +// +// if (!this.services.isEmpty()) { +// entity.setServices(new HashSet()); +// for (Service serviceModel : this.services) { +// eu.eudat.data.old.Service service = serviceModel.toDataModel(); +// DatasetService datasetService = new DatasetService(); +// datasetService.setService(service); +// entity.getServices().add(datasetService); +// } +// } return entity; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/dataset/DatasetOverviewModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/dataset/DatasetOverviewModel.java index b989a8083..b0b74354c 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/dataset/DatasetOverviewModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/dataset/DatasetOverviewModel.java @@ -1,30 +1,32 @@ package eu.eudat.models.data.dataset; -import eu.eudat.data.old.Dataset; +import eu.eudat.commons.enums.DescriptionStatus; +import eu.eudat.data.DescriptionEntity; import eu.eudat.models.DataModel; import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel; import eu.eudat.models.data.grant.GrantOverviewModel; import eu.eudat.models.data.listingmodels.DataManagementPlanOverviewModel; import eu.eudat.models.data.listingmodels.UserInfoListingModel; +import java.time.Instant; import java.util.Date; import java.util.List; import java.util.UUID; import java.util.stream.Collectors; -public class DatasetOverviewModel implements DataModel { +public class DatasetOverviewModel implements DataModel { private UUID id; private String label; - private short status; + private DescriptionStatus status; private DatasetProfileOverviewModel datasetTemplate; private List users; private DataManagementPlanOverviewModel dmp; private GrantOverviewModel grant; private String description; private Boolean isPublic; - private Date modified; - private Date created; + private Instant modified; + private Instant created; public UUID getId() { return id; @@ -40,10 +42,10 @@ public class DatasetOverviewModel implements DataModel new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList()); - this.dmp = new DataManagementPlanOverviewModel().fromDataModel(entity.getDmp()); - if (entity.getDmp().getGrant() != null) { - this.grant = new GrantOverviewModel().fromDataModel(entity.getDmp().getGrant()); - } - this.description = entity.getDescription(); - this.isPublic = entity.getDmp().isPublic(); - this.modified = entity.getModified(); - this.created = entity.getCreated(); + public DatasetOverviewModel fromDataModel(DescriptionEntity entity) { + //TODO Implement it on transfer +// this.id = entity.getId(); +// this.label = entity.getLabel(); +// this.status = entity.getStatus(); +// this.datasetTemplate = new DatasetProfileOverviewModel().fromDataModel(entity.getProfile()); +// this.users = entity.getDmp().getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList()); +// this.dmp = new DataManagementPlanOverviewModel().fromDataModel(entity.getDmp()); +// if (entity.getDmp().getGrant() != null) { +// this.grant = new GrantOverviewModel().fromDataModel(entity.getDmp().getGrant()); +// } +// this.description = entity.getDescription(); +// this.isPublic = entity.getDmp().isPublic(); +// this.modified = entity.getCreatedAt(); +// this.created = entity.getUpdatedAt(); return this; } @Override - public Dataset toDataModel() throws Exception { + public DescriptionEntity toDataModel() throws Exception { return null; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetwizard/DatasetWizardModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetwizard/DatasetWizardModel.java index b5968274e..37b68a66c 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetwizard/DatasetWizardModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetwizard/DatasetWizardModel.java @@ -1,5 +1,7 @@ package eu.eudat.models.data.datasetwizard; +import eu.eudat.commons.enums.DescriptionStatus; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.old.*; import eu.eudat.elastic.entities.Tag; @@ -13,19 +15,20 @@ import eu.eudat.models.data.externaldataset.ExternalDatasetListingModel; import eu.eudat.models.data.user.composite.PagedDatasetProfile; import net.minidev.json.JSONValue; +import java.time.Instant; import java.util.*; import java.util.stream.Collectors; -public class DatasetWizardModel implements DataModel { +public class DatasetWizardModel implements DataModel { private UUID id; private String label; private String reference; private String uri; private String description; - private short status; - private Date created; + private DescriptionStatus status; + private Instant created; private DataManagementPlan dmp; private Integer dmpSectionIndex; private PagedDatasetProfile datasetProfileDefinition; @@ -36,7 +39,7 @@ public class DatasetWizardModel implements DataModel externalDatasets; private DatasetProfileOverviewModel profile; private Boolean isProfileLatestVersion; - private Date modified; + private Instant modified; public UUID getId() { return id; @@ -73,17 +76,17 @@ public class DatasetWizardModel implements DataModel new Registry().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); - this.dataRepositories = entity.getDatasetDataRepositories() != null ? entity.getDatasetDataRepositories().stream().map(item -> { - DataRepository dataRepository = new DataRepository().fromDataModel(item.getDataRepository()); - if (item.getData() != null) { - Map> data = (Map>) JSONValue.parse(item.getData()); - Map values = data.get("data"); - dataRepository.setInfo(values.get("info")); - } - return dataRepository; - }).collect(Collectors.toList()) : new ArrayList<>(); - this.services = entity.getServices() != null ? entity.getServices().stream().map(item -> new Service().fromDataModel(item.getService())).collect(Collectors.toList()) : new ArrayList<>(); - this.created = entity.getCreated(); - this.dmp = new DataManagementPlan().fromDataModelNoDatasets(entity.getDmp()); - this.dmpSectionIndex = entity.getDmpSectionIndex(); - this.externalDatasets = entity.getDatasetExternalDatasets() != null ? entity.getDatasetExternalDatasets().stream().map(item -> { - ExternalDatasetListingModel externalDatasetListingModel = new ExternalDatasetListingModel().fromDataModel(item.getExternalDataset()); - if (item.getData() != null) { - Map> data = (Map>) JSONValue.parse(item.getData()); - Map values = data.get("data"); - externalDatasetListingModel.setInfo(values.get("info")); - externalDatasetListingModel.setType(Integer.parseInt(values.get("type"))); - } - return externalDatasetListingModel; - }).collect(Collectors.toList()) : new ArrayList<>(); - this.modified = entity.getModified(); + public DatasetWizardModel fromDataModel(DescriptionEntity entity) { + //TODO Implement it on transfer +// this.id = entity.getId(); +// this.label = entity.getLabel(); +// this.status = entity.getStatus(); +// this.reference = entity.getReference(); +// this.description = entity.getDescription(); +// this.profile = new DatasetProfileOverviewModel(); +// this.profile = this.profile.fromDataModel(entity.getProfile()); +// this.uri = entity.getUri(); +// this.registries = entity.getRegistries() != null ? entity.getRegistries().stream().map(item -> new Registry().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); +// this.dataRepositories = entity.getDatasetDataRepositories() != null ? entity.getDatasetDataRepositories().stream().map(item -> { +// DataRepository dataRepository = new DataRepository().fromDataModel(item.getDataRepository()); +// if (item.getData() != null) { +// Map> data = (Map>) JSONValue.parse(item.getData()); +// Map values = data.get("data"); +// dataRepository.setInfo(values.get("info")); +// } +// return dataRepository; +// }).collect(Collectors.toList()) : new ArrayList<>(); +// this.services = entity.getServices() != null ? entity.getServices().stream().map(item -> new Service().fromDataModel(item.getService())).collect(Collectors.toList()) : new ArrayList<>(); +// this.created = entity.getCreated(); +// this.dmp = new DataManagementPlan().fromDataModelNoDatasets(entity.getDmp()); +// this.dmpSectionIndex = entity.getDmpSectionIndex(); +// this.externalDatasets = entity.getDatasetExternalDatasets() != null ? entity.getDatasetExternalDatasets().stream().map(item -> { +// ExternalDatasetListingModel externalDatasetListingModel = new ExternalDatasetListingModel().fromDataModel(item.getExternalDataset()); +// if (item.getData() != null) { +// Map> data = (Map>) JSONValue.parse(item.getData()); +// Map values = data.get("data"); +// externalDatasetListingModel.setInfo(values.get("info")); +// externalDatasetListingModel.setType(Integer.parseInt(values.get("type"))); +// } +// return externalDatasetListingModel; +// }).collect(Collectors.toList()) : new ArrayList<>(); +// this.modified = entity.getUpdatedAt(); return this; } - public DatasetWizardModel fromDataModelNoDmp(Dataset entity) { - this.id = entity.getId(); - this.label = entity.getLabel(); - this.status = entity.getStatus(); - this.reference = entity.getReference(); - this.description = entity.getDescription(); - this.profile = new DatasetProfileOverviewModel(); - this.profile = this.profile.fromDataModel(entity.getProfile()); - this.uri = entity.getUri(); - this.dmpSectionIndex = entity.getDmpSectionIndex(); - this.registries = entity.getRegistries() != null ? entity.getRegistries().stream().map(item -> new Registry().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); - this.dataRepositories = entity.getDatasetDataRepositories() != null ? entity.getDatasetDataRepositories().stream().map(item -> { - DataRepository dataRepository = new DataRepository().fromDataModel(item.getDataRepository()); - if (item.getData() != null) { - Map> data = (Map>) JSONValue.parse(item.getData()); - Map values = data.get("data"); - dataRepository.setInfo(values.get("info")); - } - return dataRepository; - }).collect(Collectors.toList()) : new ArrayList<>(); - this.services = entity.getServices() != null ? entity.getServices().stream().map(item -> new Service().fromDataModel(item.getService())).collect(Collectors.toList()) : new ArrayList<>(); - this.created = entity.getCreated(); - this.externalDatasets = entity.getDatasetExternalDatasets() != null ? entity.getDatasetExternalDatasets().stream().map(item -> { - ExternalDatasetListingModel externalDatasetListingModel = new ExternalDatasetListingModel().fromDataModel(item.getExternalDataset()); - if (item.getData() != null) { - Map> data = (Map>) JSONValue.parse(item.getData()); - Map values = data.get("data"); - externalDatasetListingModel.setInfo(values.get("info")); - externalDatasetListingModel.setType(Integer.parseInt(values.get("type"))); - } - return externalDatasetListingModel; - }).collect(Collectors.toList()) : new ArrayList<>(); - this.modified = entity.getModified(); + public DatasetWizardModel fromDataModelNoDmp(DescriptionEntity entity) { + //TODO Implement it on transfer +// this.id = entity.getId(); +// this.label = entity.getLabel(); +// this.status = entity.getStatus(); +// this.reference = entity.getReference(); +// this.description = entity.getDescription(); +// this.profile = new DatasetProfileOverviewModel(); +// this.profile = this.profile.fromDataModel(entity.getProfile()); +// this.uri = entity.getUri(); +// this.dmpSectionIndex = entity.getDmpSectionIndex(); +// this.registries = entity.getRegistries() != null ? entity.getRegistries().stream().map(item -> new Registry().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); +// this.dataRepositories = entity.getDatasetDataRepositories() != null ? entity.getDatasetDataRepositories().stream().map(item -> { +// DataRepository dataRepository = new DataRepository().fromDataModel(item.getDataRepository()); +// if (item.getData() != null) { +// Map> data = (Map>) JSONValue.parse(item.getData()); +// Map values = data.get("data"); +// dataRepository.setInfo(values.get("info")); +// } +// return dataRepository; +// }).collect(Collectors.toList()) : new ArrayList<>(); +// this.services = entity.getServices() != null ? entity.getServices().stream().map(item -> new Service().fromDataModel(item.getService())).collect(Collectors.toList()) : new ArrayList<>(); +// this.created = entity.getCreated(); +// this.externalDatasets = entity.getDatasetExternalDatasets() != null ? entity.getDatasetExternalDatasets().stream().map(item -> { +// ExternalDatasetListingModel externalDatasetListingModel = new ExternalDatasetListingModel().fromDataModel(item.getExternalDataset()); +// if (item.getData() != null) { +// Map> data = (Map>) JSONValue.parse(item.getData()); +// Map values = data.get("data"); +// externalDatasetListingModel.setInfo(values.get("info")); +// externalDatasetListingModel.setType(Integer.parseInt(values.get("type"))); +// } +// return externalDatasetListingModel; +// }).collect(Collectors.toList()) : new ArrayList<>(); +// this.modified = entity.getModified(); return this; } @Override - public Dataset toDataModel() throws Exception { - Dataset entity = new Dataset(); - entity.setId(this.id); - entity.setLabel(this.label); - entity.setReference(this.reference); - entity.setUri(this.uri); - entity.setStatus(this.status); - if (this.status == (int) Dataset.Status.FINALISED.getValue()) - entity.setFinalizedAt(new Date()); - DMP dmp = new DMP(); - dmp.setId(this.dmp.getId()); - entity.setDmp(dmp); - entity.setDmpSectionIndex(this.dmpSectionIndex); - entity.setDescription(this.description); - entity.setCreated(this.created != null ? this.created : new Date()); - entity.setModified(new Date()); - DescriptionTemplateEntity profile = new DescriptionTemplateEntity(); - profile.setId(this.profile.getId()); - entity.setProfile(profile); - if (this.registries != null && !this.registries.isEmpty()) { - entity.setRegistries(new HashSet<>()); - for (Registry registry : this.registries) { - entity.getRegistries().add(registry.toDataModel()); - } - } - - if (this.dataRepositories != null && !this.dataRepositories.isEmpty()) { - entity.setDatasetDataRepositories(new HashSet<>()); - for (DataRepository dataRepositoryModel : this.dataRepositories) { - eu.eudat.data.old.DataRepository dataRepository = dataRepositoryModel.toDataModel(); - DatasetDataRepository datasetDataRepository = new DatasetDataRepository(); - datasetDataRepository.setDataRepository(dataRepository); - Map> data = new HashMap<>(); - Map values = new HashMap<>(); - values.put("info", dataRepositoryModel.getInfo()); - data.put("data", values); - datasetDataRepository.setData(JSONValue.toJSONString(data)); - entity.getDatasetDataRepositories().add(datasetDataRepository); - } - } - - if (this.services != null && !this.services.isEmpty()) { - entity.setServices(new HashSet<>()); - for (Service serviceModel : this.services) { - eu.eudat.data.old.Service service = serviceModel.toDataModel(); - DatasetService datasetService = new DatasetService(); - datasetService.setService(service); - entity.getServices().add(datasetService); - } - } - - if (this.externalDatasets != null && !this.externalDatasets.isEmpty()) { - entity.setDatasetExternalDatasets(new HashSet<>()); - for (ExternalDatasetListingModel externalDataset : this.externalDatasets) { - ExternalDataset externalDatasetEntity = externalDataset.toDataModel(); - DatasetExternalDataset datasetExternalDataset = new DatasetExternalDataset(); - datasetExternalDataset.setExternalDataset(externalDatasetEntity); - Map> data = new HashMap<>(); - Map values = new HashMap<>(); - values.put("info",externalDataset.getInfo()); - values.put("type",externalDataset.getType().toString()); - data.put("data",values); - datasetExternalDataset.setData(JSONValue.toJSONString(data)); - entity.getDatasetExternalDatasets().add(datasetExternalDataset); - } - } + public DescriptionEntity toDataModel() throws Exception { + DescriptionEntity entity = new DescriptionEntity(); + //TODO Implement it on transfer +// entity.setId(this.id); +// entity.setLabel(this.label); +// entity.setReference(this.reference); +// entity.setUri(this.uri); +// entity.setStatus(this.status); +// if (this.status == (int) DescriptionEntity.Status.FINALISED.getValue()) +// entity.setFinalizedAt(new Date()); +// DMP dmp = new DMP(); +// dmp.setId(this.dmp.getId()); +// entity.setDmp(dmp); +// entity.setDmpSectionIndex(this.dmpSectionIndex); +// entity.setDescription(this.description); +// entity.setCreated(this.created != null ? this.created : new Date()); +// entity.setModified(new Date()); +// DescriptionTemplateEntity profile = new DescriptionTemplateEntity(); +// profile.setId(this.profile.getId()); +// entity.setProfile(profile); +// if (this.registries != null && !this.registries.isEmpty()) { +// entity.setRegistries(new HashSet<>()); +// for (Registry registry : this.registries) { +// entity.getRegistries().add(registry.toDataModel()); +// } +// } +// +// if (this.dataRepositories != null && !this.dataRepositories.isEmpty()) { +// entity.setDatasetDataRepositories(new HashSet<>()); +// for (DataRepository dataRepositoryModel : this.dataRepositories) { +// eu.eudat.data.old.DataRepository dataRepository = dataRepositoryModel.toDataModel(); +// DatasetDataRepository datasetDataRepository = new DatasetDataRepository(); +// datasetDataRepository.setDataRepository(dataRepository); +// Map> data = new HashMap<>(); +// Map values = new HashMap<>(); +// values.put("info", dataRepositoryModel.getInfo()); +// data.put("data", values); +// datasetDataRepository.setData(JSONValue.toJSONString(data)); +// entity.getDatasetDataRepositories().add(datasetDataRepository); +// } +// } +// +// if (this.services != null && !this.services.isEmpty()) { +// entity.setServices(new HashSet<>()); +// for (Service serviceModel : this.services) { +// eu.eudat.data.old.Service service = serviceModel.toDataModel(); +// DatasetService datasetService = new DatasetService(); +// datasetService.setService(service); +// entity.getServices().add(datasetService); +// } +// } +// +// if (this.externalDatasets != null && !this.externalDatasets.isEmpty()) { +// entity.setDatasetExternalDatasets(new HashSet<>()); +// for (ExternalDatasetListingModel externalDataset : this.externalDatasets) { +// ExternalDataset externalDatasetEntity = externalDataset.toDataModel(); +// DatasetExternalDataset datasetExternalDataset = new DatasetExternalDataset(); +// datasetExternalDataset.setExternalDataset(externalDatasetEntity); +// Map> data = new HashMap<>(); +// Map values = new HashMap<>(); +// values.put("info",externalDataset.getInfo()); +// values.put("type",externalDataset.getType().toString()); +// data.put("data",values); +// datasetExternalDataset.setData(JSONValue.toJSONString(data)); +// entity.getDatasetExternalDatasets().add(datasetExternalDataset); +// } +// } return entity; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlan.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlan.java index b3382f65d..124468e37 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlan.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlan.java @@ -2,6 +2,9 @@ package eu.eudat.models.data.dmp; 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.DescriptionEntity; import eu.eudat.data.DmpBlueprintEntity; import eu.eudat.data.old.*; import eu.eudat.models.DataModel; @@ -283,11 +286,11 @@ public class DataManagementPlan implements DataModel { if (entity.getDataset() != null) { if (entity.isPublic()) { this.datasets = entity.getDataset().stream() - .filter(dataset -> !dataset.getStatus().equals(Dataset.Status.DELETED.getValue()) && !dataset.getStatus().equals(Dataset.Status.CANCELED.getValue()) && !dataset.getStatus().equals(Dataset.Status.SAVED.getValue())) + .filter(dataset -> !dataset.getIsActive().equals(IsActive.Inactive) && !dataset.getStatus().equals(DescriptionStatus.Canceled) && !dataset.getStatus().equals(DescriptionStatus.Saved)) .map(x -> new DatasetWizardModel().fromDataModelNoDmp(x)).collect(Collectors.toList()); } else { this.datasets = entity.getDataset().stream() - .filter(dataset -> !dataset.getStatus().equals(Dataset.Status.DELETED.getValue()) && !dataset.getStatus().equals(Dataset.Status.CANCELED.getValue())) + .filter(dataset -> !dataset.getIsActive().equals(IsActive.Inactive) && !dataset.getStatus().equals(DescriptionStatus.Saved)) .map(x -> new DatasetWizardModel().fromDataModelNoDmp(x)).collect(Collectors.toList()); } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlanNewVersionModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlanNewVersionModel.java index 796e8ef06..482ebff1a 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlanNewVersionModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlanNewVersionModel.java @@ -1,6 +1,7 @@ package eu.eudat.models.data.dmp; import com.fasterxml.jackson.databind.ObjectMapper; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.old.*; import eu.eudat.models.DataModel; import eu.eudat.models.data.dataset.Dataset; @@ -176,14 +177,14 @@ public class DataManagementPlanNewVersionModel implements DataModel datasets = new LinkedList<>(); + List descriptionEntities = new LinkedList<>(); if (this.datasets != null) { for (Dataset dataset : this.datasets) { - eu.eudat.data.old.Dataset entityDataset = new eu.eudat.data.old.Dataset(); - entityDataset.setId(dataset.getId()); - datasets.add(entityDataset); + DescriptionEntity entityDescriptionEntity = new DescriptionEntity(); + entityDescriptionEntity.setId(dataset.getId()); + descriptionEntities.add(entityDescriptionEntity); } - entity.setDataset(new HashSet<>(datasets)); + 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()))); diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/DataManagementPlanOverviewModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/DataManagementPlanOverviewModel.java index 8c0911773..fdded6905 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/DataManagementPlanOverviewModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/DataManagementPlanOverviewModel.java @@ -2,9 +2,11 @@ package eu.eudat.models.data.listingmodels; 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.old.Dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.models.DataModel; import eu.eudat.models.data.dataset.DatasetOverviewModel; import eu.eudat.models.data.dmp.AssociatedProfile; @@ -195,7 +197,7 @@ public class DataManagementPlanOverviewModel implements DataModel new Organisation().fromDataModel(item)).collect(Collectors.toList()); - this.datasets = entity.getDataset().stream().filter(dataset -> !dataset.getStatus().equals(Dataset.Status.DELETED.getValue()) && !dataset.getStatus().equals(Dataset.Status.CANCELED.getValue())).map(x-> new DatasetOverviewModel().fromDataModel(x)).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) { diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/DatasetListingModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/DatasetListingModel.java index 5e6944f10..dfbb04622 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/DatasetListingModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/DatasetListingModel.java @@ -1,11 +1,13 @@ package eu.eudat.models.data.listingmodels; +import eu.eudat.commons.enums.DescriptionStatus; import eu.eudat.data.old.DMP; -import eu.eudat.data.old.Dataset; +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; @@ -13,19 +15,19 @@ import java.util.UUID; import java.util.stream.Collectors; -public class DatasetListingModel implements DataModel { +public class DatasetListingModel implements DataModel { private String id; private String label; private String grant; private String dmp; private String dmpId; private DatasetProfileOverviewModel profile; - private int status; - private Date created; - private Date modified; + private DescriptionStatus status; + private Instant created; + private Instant modified; private String description; - private Date finalizedAt; - private Date dmpPublishedAt; + private Instant finalizedAt; + private Instant dmpPublishedAt; private int version; private List users; private Boolean isPublic; @@ -73,24 +75,24 @@ public class DatasetListingModel implements DataModel new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList()) : new ArrayList<>(); - this.isPublic = entity.getDmp() != null ? entity.getDmp().isPublic() : false; + public DatasetListingModel fromDataModel(DescriptionEntity entity) { + //TODO Implement it on transfer +// this.id = entity.getId() != null ? entity.getId().toString() : ""; +// this.label = entity.getLabel(); +// this.created = entity.getCreatedAt(); +// this.modified = entity.getUpdatedAt(); +// this.grant = (entity.getDmp() != null && entity.getDmp().getGrant() != null) ? entity.getDmp().getGrant().getLabel() : ""; +// this.dmp = entity.getDmp() != null ? entity.getDmp().getLabel() : ""; +// this.dmpId = entity.getDmp() != null ? entity.getDmp().getId().toString() : ""; +// this.profile = entity.getProfile() != null ? new DatasetProfileOverviewModel().fromDataModel(entity.getProfile()) : null; +// this.description = entity.getDescription(); +// this.status = entity.getStatus(); +// if (entity.getFinalizedAt() == null && entity.getStatus() == DescriptionStatus.Finalized) { +// this.finalizedAt = entity.getDmp().getFinalizedAt(); +// } else { +// this.finalizedAt = entity.getFinalizedAt(); +// } +// this.dmpPublishedAt = entity.getDmp().getPublishedAt(); +// this.version = entity.getDmp().getVersion(); +// this.users = entity.getDmp() != null ? entity.getDmp().getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList()) : new ArrayList<>(); +// this.isPublic = entity.getDmp() != null ? entity.getDmp().isPublic() : false; return this; } @Override - public Dataset toDataModel() { - Dataset entity = new Dataset(); - entity.setId(UUID.fromString(this.getId())); - entity.setLabel(this.getLabel()); - entity.setCreated(this.getCreated()); - entity.setModified(this.getModified()); - entity.setDescription(this.getDescription()); - entity.setFinalizedAt(this.getFinalizedAt()); - entity.setStatus(Integer.valueOf(this.getStatus()).shortValue()); - DMP dmp = new DMP(); - if (this.getGrant() != null && !this.getGrant().isEmpty()) { - Grant grant = new Grant(); - grant.setLabel(this.getGrant()); - dmp.setGrant(grant); - } - dmp.setLabel(this.getDmp()); - dmp.setId(UUID.fromString(this.getDmpId())); - dmp.setPublishedAt(this.getDmpPublishedAt()); - dmp.setVersion(this.getVersion()); - dmp.setUsers(this.getUsers().stream().map(UserInfoListingModel::toDataModel).collect(Collectors.toSet())); - dmp.setPublic(this.getPublic()); - dmp.setFinalizedAt(this.getFinalizedAt()); - entity.setDmp(dmp); - entity.setProfile(this.getProfile() != null ? this.getProfile().toDataModel() : null); + public DescriptionEntity toDataModel() { + //TODO Implement it on transfer + DescriptionEntity entity = new DescriptionEntity(); +// entity.setId(UUID.fromString(this.getId())); +// entity.setLabel(this.getLabel()); +// entity.setCreatedAt(this.getCreated()); +// entity.setUpdatedAt(this.getModified()); +// entity.setDescription(this.getDescription()); +// entity.setFinalizedAt(this.getFinalizedAt()); +// entity.setStatus(this.getStatus()); +// DMP dmp = new DMP(); +// if (this.getGrant() != null && !this.getGrant().isEmpty()) { +// Grant grant = new Grant(); +// grant.setLabel(this.getGrant()); +// dmp.setGrant(grant); +// } +// dmp.setLabel(this.getDmp()); +// dmp.setId(UUID.fromString(this.getDmpId())); +// dmp.setPublishedAt(this.getDmpPublishedAt()); +// dmp.setVersion(this.getVersion()); +// dmp.setUsers(this.getUsers().stream().map(UserInfoListingModel::toDataModel).collect(Collectors.toSet())); +// dmp.setPublic(this.getPublic()); +// dmp.setFinalizedAt(this.getFinalizedAt()); +// entity.setDmp(dmp); +// entity.setProfile(this.getProfile() != null ? this.getProfile().toDataModel() : null); return entity; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/quickwizard/DatasetDescriptionQuickWizardModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/quickwizard/DatasetDescriptionQuickWizardModel.java index 7372c810f..3c9d6709b 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/quickwizard/DatasetDescriptionQuickWizardModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/quickwizard/DatasetDescriptionQuickWizardModel.java @@ -1,12 +1,14 @@ package eu.eudat.models.data.quickwizard; +import eu.eudat.commons.enums.DescriptionStatus; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel; import eu.eudat.models.data.dmp.DataManagementPlan; import eu.eudat.models.data.datasetwizard.DatasetWizardModel; import eu.eudat.models.data.user.composite.PagedDatasetProfile; +import java.time.Instant; import java.util.Date; public class DatasetDescriptionQuickWizardModel extends PagedDatasetProfile { @@ -25,10 +27,10 @@ public class DatasetDescriptionQuickWizardModel extends PagedDatasetProfile { public DatasetWizardModel toDataModel(DataManagementPlan dmp, DescriptionTemplateEntity profile){ DatasetWizardModel newDataset = new DatasetWizardModel(); newDataset.setLabel(datasetLabel); - newDataset.setCreated(new Date()); + newDataset.setCreated(Instant.now()); newDataset.setProfile(new DatasetProfileOverviewModel().fromDataModel(profile)); newDataset.setDmp(dmp); - newDataset.setStatus((short) this.getStatus()); + newDataset.setStatus(DescriptionStatus.of((short)this.getStatus())); //newDataset.setStatus(Dataset.Status.SAVED.getValue()); diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetRDAExportModel.java index dd34750d4..ed5588813 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetRDAExportModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetRDAExportModel.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.jayway.jsonpath.JsonPath; -import eu.eudat.data.old.Dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.logic.managers.DatasetManager; import eu.eudat.commons.types.xml.XmlBuilder; import org.json.JSONArray; @@ -150,23 +150,23 @@ public class DatasetRDAExportModel { } - public DatasetRDAExportModel fromDataModel(Dataset dataset, DatasetManager datasetManager) { + public DatasetRDAExportModel fromDataModel(DescriptionEntity descriptionEntity, DatasetManager datasetManager) { // Map of template Ids to rda values. - JSONObject jObject = new JSONObject(dataset.getProperties()); + JSONObject jObject = new JSONObject(descriptionEntity.getProperties()); Map templateIdsToValues = jObject.toMap(); /*--------- Building dataset rda export model ---------*/ DatasetRDAExportModel datasetRDAExportModel = new DatasetRDAExportModel(); - datasetRDAExportModel.setDataset_id(new IdRDAExportModel(dataset.getId().toString(), "other")); - if (dataset.getDescription() != null) datasetRDAExportModel.setDescription(dataset.getDescription().replace("\n", " ")); - datasetRDAExportModel.setIssued(DateFormat.getDateInstance(DateFormat.SHORT).format(dataset.getCreated())); + datasetRDAExportModel.setDataset_id(new IdRDAExportModel(descriptionEntity.getId().toString(), "other")); + if (descriptionEntity.getDescription() != null) datasetRDAExportModel.setDescription(descriptionEntity.getDescription().replace("\n", " ")); + datasetRDAExportModel.setIssued(DateFormat.getDateInstance(DateFormat.SHORT).format(descriptionEntity.getCreatedAt())); datasetRDAExportModel.setLanguage("en"); // mock data - datasetRDAExportModel.setTitle(dataset.getLabel()); + datasetRDAExportModel.setTitle(descriptionEntity.getLabel()); // Transform the answered dataset description to json so we can parse it and fill the rda model. JSONObject datasetDescriptionJson = null; try { - String jsonResult = mapper.writeValueAsString(datasetManager.getSingle(dataset.getId().toString()).getDatasetProfileDefinition()); + String jsonResult = mapper.writeValueAsString(datasetManager.getSingle(descriptionEntity.getId().toString()).getDatasetProfileDefinition()); datasetDescriptionJson = new JSONObject(jsonResult); } catch (JsonProcessingException | InvalidApplicationException e) { logger.error(e.getMessage(), e); @@ -192,26 +192,27 @@ public class DatasetRDAExportModel { datasetRDAExportModel.setSensitive_data("unknown"); } + //TODO /*--------- Building type. ---------*/ - datasetRDAExportModel.setType(buildSingleProperties("dataset.type", datasetDescriptionJson, templateIdsToValues)); - - /*--------- Building data_quality_assurance. ---------*/ - datasetRDAExportModel.setData_quality_assurance(buildDataQualityAssurance(datasetDescriptionJson, templateIdsToValues, dataset.getProfile().getDefinition())); - - /*--------- Building distribution. ---------*/ - datasetRDAExportModel.setDistribution(buildDistribution(datasetDescriptionJson, templateIdsToValues, dataset.getProfile().getDefinition())); - - /*--------- Building keywords. ---------*/ - datasetRDAExportModel.setKeyword(buildKeywords(datasetDescriptionJson, templateIdsToValues, dataset.getProfile().getDefinition())); - - /*--------- Building metadata items. ---------*/ - datasetRDAExportModel.setMetadata(buildMetadata(datasetDescriptionJson, templateIdsToValues, dataset.getProfile().getDefinition())); - - /*--------- Building security and privacy items. ---------*/ - datasetRDAExportModel.setSecurity_and_privacy(buildSecurityAndPrivacy(datasetDescriptionJson, templateIdsToValues, dataset.getProfile().getDefinition())); - - /*--------- Building technical_resource. ---------*/ - datasetRDAExportModel.setTechnical_resource(buildTechnicalResource(datasetDescriptionJson, templateIdsToValues, dataset.getProfile().getDefinition())); +// datasetRDAExportModel.setType(buildSingleProperties("dataset.type", datasetDescriptionJson, templateIdsToValues)); +// +// /*--------- Building data_quality_assurance. ---------*/ +// datasetRDAExportModel.setData_quality_assurance(buildDataQualityAssurance(datasetDescriptionJson, templateIdsToValues, descriptionEntity.getProfile().getDefinition())); +// +// /*--------- Building distribution. ---------*/ +// datasetRDAExportModel.setDistribution(buildDistribution(datasetDescriptionJson, templateIdsToValues, descriptionEntity.getProfile().getDefinition())); +// +// /*--------- Building keywords. ---------*/ +// datasetRDAExportModel.setKeyword(buildKeywords(datasetDescriptionJson, templateIdsToValues, descriptionEntity.getProfile().getDefinition())); +// +// /*--------- Building metadata items. ---------*/ +// datasetRDAExportModel.setMetadata(buildMetadata(datasetDescriptionJson, templateIdsToValues, descriptionEntity.getProfile().getDefinition())); +// +// /*--------- Building security and privacy items. ---------*/ +// datasetRDAExportModel.setSecurity_and_privacy(buildSecurityAndPrivacy(datasetDescriptionJson, templateIdsToValues, descriptionEntity.getProfile().getDefinition())); +// +// /*--------- Building technical_resource. ---------*/ +// datasetRDAExportModel.setTechnical_resource(buildTechnicalResource(datasetDescriptionJson, templateIdsToValues, descriptionEntity.getProfile().getDefinition())); return datasetRDAExportModel; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DmpRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DmpRDAExportModel.java index 0f37aaeea..7a10a1e3d 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DmpRDAExportModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DmpRDAExportModel.java @@ -1,8 +1,10 @@ package eu.eudat.models.data.rda; +import eu.eudat.commons.enums.DescriptionStatus; +import eu.eudat.commons.enums.IsActive; import eu.eudat.data.EntityDoiEntity; import eu.eudat.data.old.DMP; -import eu.eudat.data.old.Dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.old.UserDMP; import eu.eudat.logic.managers.DatasetManager; @@ -139,9 +141,9 @@ public class DmpRDAExportModel { SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy"); dmpRda.created = formatter.format(entity.getCreated()); dmpRda.dataset = new LinkedList<>(); - for (Dataset dataset : entity.getDataset()) { - if (dataset.getStatus() != Dataset.Status.DELETED.getValue() && dataset.getStatus() != Dataset.Status.CANCELED.getValue()) - dmpRda.dataset.add(new DatasetRDAExportModel().fromDataModel(dataset, datasetManager)); + 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()) { diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/urls/DatasetUrlListing.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/urls/DatasetUrlListing.java index 2474da421..9ec92723c 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/urls/DatasetUrlListing.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/urls/DatasetUrlListing.java @@ -1,23 +1,23 @@ package eu.eudat.models.data.urls; -import eu.eudat.data.old.Dataset; +import eu.eudat.data.DescriptionEntity; import java.util.UUID; /** * Created by ikalyvas on 7/23/2018. */ -public class DatasetUrlListing extends UrlListing { +public class DatasetUrlListing extends UrlListing { @Override - public DatasetUrlListing fromDataModel(Dataset entity) { + public DatasetUrlListing fromDataModel(DescriptionEntity entity) { this.setLabel(entity.getLabel()); this.setUrl(entity.getId().toString()); return this; } @Override - public Dataset toDataModel() { - Dataset entity = new Dataset(); + public DescriptionEntity toDataModel() { + DescriptionEntity entity = new DescriptionEntity(); entity.setId(UUID.fromString(this.getUrl())); entity.setLabel(this.getLabel()); return entity; diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetRDAMapper.java b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetRDAMapper.java index 8f1badcf3..b2d626de8 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetRDAMapper.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetRDAMapper.java @@ -3,6 +3,7 @@ package eu.eudat.models.rda.mapper; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.elastic.criteria.DatasetCriteria; import eu.eudat.elastic.entities.Tag; @@ -43,20 +44,20 @@ public class DatasetRDAMapper { } @Transactional - public Dataset toRDA(eu.eudat.data.old.Dataset dataset, eu.eudat.models.rda.Dmp dmp) { + public Dataset toRDA(DescriptionEntity descriptionEntity, eu.eudat.models.rda.Dmp dmp) { Dataset rda = new Dataset(); // rda.setDatasetId(DatasetIdRDAMapper.toRDA(dataset.getId())); - if (dataset.getLabel() == null) { + if (descriptionEntity.getLabel() == null) { throw new IllegalArgumentException("Dataset Label is missing"); } - rda.setTitle(dataset.getLabel()); - rda.setDescription(dataset.getDescription()); - rda.setAdditionalProperty("template", dataset.getProfile().getId()); + rda.setTitle(descriptionEntity.getLabel()); + rda.setDescription(descriptionEntity.getDescription()); + rda.setAdditionalProperty("template", descriptionEntity.getProfile()); try { - JSONObject jObject = new JSONObject(dataset.getProperties()); + JSONObject jObject = new JSONObject(descriptionEntity.getProperties()); Map templateIdsToValues = jObject.toMap(); - DatasetWizardModel datasetWizardModel = new DatasetWizardModel().fromDataModel(dataset); - datasetWizardModel.setDatasetProfileDefinition(datasetManager.getPagedProfile(datasetWizardModel, dataset)); + DatasetWizardModel datasetWizardModel = new DatasetWizardModel().fromDataModel(descriptionEntity); + datasetWizardModel.setDatasetProfileDefinition(datasetManager.getPagedProfile(datasetWizardModel, descriptionEntity)); ObjectMapper mapper = new ObjectMapper(); String datasetDescriptionJson = mapper.writeValueAsString(datasetWizardModel.getDatasetProfileDefinition()); JsonNode datasetDescriptionObj = mapper.readTree(datasetDescriptionJson); @@ -65,7 +66,7 @@ public class DatasetRDAMapper { rda.setDatasetId(DatasetIdRDAMapper.toRDA(idNodes)); } if (rda.getDatasetId() == null) { - rda.setDatasetId(new DatasetId(dataset.getId().toString(), DatasetId.Type.OTHER)); + rda.setDatasetId(new DatasetId(descriptionEntity.getId().toString(), DatasetId.Type.OTHER)); } List typeNodes = JsonSearcher.findNodes(datasetDescriptionObj, "schematics", "rda.dataset.type"); if (!typeNodes.isEmpty() && !typeNodes.get(0).get("value").asText().isEmpty()) { @@ -80,11 +81,13 @@ public class DatasetRDAMapper { rda.setLanguage(Language.fromValue(lang)); } catch (IllegalArgumentException e){ - logger.warn("Language " + lang + " from semantic rda.dataset.language was not found. Setting '" + dataset.getProfile().getLanguage() +"' as language from the dataset profile."); - rda.setLanguage(LanguageRDAMapper.mapLanguageIsoToRDAIso(dataset.getProfile().getLanguage())); + //TODO +// logger.warn("Language " + lang + " from semantic rda.dataset.language was not found. Setting '" + descriptionEntity.getProfile().getLanguage() +"' as language from the dataset profile."); +// rda.setLanguage(LanguageRDAMapper.mapLanguageIsoToRDAIso(descriptionEntity.getProfile().getLanguage())); } } else { - rda.setLanguage(LanguageRDAMapper.mapLanguageIsoToRDAIso(dataset.getProfile().getLanguage())); + //TODO +// rda.setLanguage(LanguageRDAMapper.mapLanguageIsoToRDAIso(descriptionEntity.getProfile().getLanguage())); } List metadataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "schematics", "rda.dataset.metadata"); if (!metadataNodes.isEmpty()) { @@ -147,7 +150,7 @@ public class DatasetRDAMapper { rda.setAdditionalProperty("keyword" + (i + 1), keywordNodes.get(i).get("id").asText()); } } else if (apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().exists()) { - List tags = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(dataset.getId().toString()).getTags().stream().map(Tag::getName).collect(Collectors.toList()); + List tags = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(descriptionEntity.getId().toString()).getTags().stream().map(Tag::getName).collect(Collectors.toList()); rda.setKeyword(tags); } List personalDataNodes = JsonSearcher.findNodes(datasetDescriptionObj, "schematics", "rda.dataset.personal_data"); @@ -280,21 +283,22 @@ public class DatasetRDAMapper { } - public eu.eudat.data.old.Dataset toEntity(Dataset rda, DescriptionTemplateEntity defaultProfile) { - eu.eudat.data.old.Dataset entity = new eu.eudat.data.old.Dataset(); + public DescriptionEntity toEntity(Dataset rda, DescriptionTemplateEntity defaultProfile) { + DescriptionEntity entity = new DescriptionEntity(); entity.setLabel(rda.getTitle()); entity.setDescription(rda.getDescription()); try { DescriptionTemplateEntity profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(rda.getAdditionalProperties().get("template").toString())); - entity.setProfile(profile); + entity.setProfile(profile.getId()); }catch(Exception e) { logger.warn(e.getMessage(), e); - entity.setProfile(defaultProfile); + entity.setProfile(defaultProfile.getId()); } try { Map properties = new HashMap<>(); DatasetWizardModel datasetWizardModel = new DatasetWizardModel(); - datasetWizardModel.setProfile(new DatasetProfileOverviewModel().fromDataModel(entity.getProfile())); + //TODO + //datasetWizardModel.setProfile(new DatasetProfileOverviewModel().fromDataModel(entity.getProfile())); datasetWizardModel.setDatasetProfileDefinition(datasetManager.getPagedProfile(datasetWizardModel, entity)); ObjectMapper mapper = new ObjectMapper(); String datasetDescriptionJson = mapper.writeValueAsString(datasetWizardModel.getDatasetProfileDefinition()); diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DmpRDAMapper.java b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DmpRDAMapper.java index f0ddaafe5..7c38f5a8c 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DmpRDAMapper.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DmpRDAMapper.java @@ -123,7 +123,7 @@ public class DmpRDAMapper { 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.getStatus() != eu.eudat.elastic.entities.Dmp.DMPStatus.DELETED.getValue()).map(dataset -> datasetRDAMapper.toRDA(dataset, rda)).collect(Collectors.toList())); + rda.setDataset(dmp.getDataset().stream().filter(dataset -> dataset.getStatus().getValue() != eu.eudat.elastic.entities.Dmp.DMPStatus.DELETED.getValue()).map(dataset -> datasetRDAMapper.toRDA(dataset, rda)).collect(Collectors.toList())); if (dmp.getProject() != null) { rda.setProject(Collections.singletonList(ProjectRDAMapper.toRDA(dmp.getProject(), dmp.getGrant()))); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/publicapi/criteria/dataset/DatasetPublicCriteria.java b/dmp-backend/web/src/main/java/eu/eudat/publicapi/criteria/dataset/DatasetPublicCriteria.java index 16e63d2b0..c4016b9b4 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/publicapi/criteria/dataset/DatasetPublicCriteria.java +++ b/dmp-backend/web/src/main/java/eu/eudat/publicapi/criteria/dataset/DatasetPublicCriteria.java @@ -1,7 +1,7 @@ package eu.eudat.publicapi.criteria.dataset; import eu.eudat.data.dao.criteria.Criteria; -import eu.eudat.data.old.Dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.elastic.entities.Tag; import io.swagger.annotations.ApiModelProperty; @@ -10,7 +10,7 @@ import java.util.List; import java.util.UUID; -public class DatasetPublicCriteria extends Criteria { +public class DatasetPublicCriteria extends Criteria { @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") diff --git a/dmp-backend/web/src/main/java/eu/eudat/publicapi/managers/DatasetPublicManager.java b/dmp-backend/web/src/main/java/eu/eudat/publicapi/managers/DatasetPublicManager.java index f3a922522..b7d129650 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/publicapi/managers/DatasetPublicManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/publicapi/managers/DatasetPublicManager.java @@ -1,7 +1,9 @@ package eu.eudat.publicapi.managers; +import eu.eudat.commons.enums.DescriptionStatus; +import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity; -import eu.eudat.data.old.Dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.query.definition.helpers.ColumnOrderings; import eu.eudat.elastic.criteria.DatasetCriteria; @@ -61,7 +63,7 @@ public class DatasetPublicManager { } datasetCriteria.setGroupIds(datasetTableRequest.getCriteria().getGroupIds()); datasetCriteria.setGrantStatus(GrantStateType.ONGOING.getValue().shortValue()); // grant status ongoing - datasetCriteria.setStatus(Dataset.Status.FINALISED.getValue()); // dataset status finalized + datasetCriteria.setStatus(DescriptionStatus.Finalized.getValue()); // dataset status finalized if (datasetTableRequest.getOrderings() != null) { datasetCriteria.setSortCriteria(DmpPublicCriteriaMapper.toElasticSorting(datasetTableRequest.getOrderings())); } @@ -83,7 +85,7 @@ public class DatasetPublicManager { /*datasetTableRequest.setQuery(databaseRepository.getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetPublicListingModel.class))); QueryableList items = datasetTableRequest.applyCriteria();*/ datasetTableRequest.setQuery(databaseRepository.getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetPublicListingModel.class))); - QueryableList items; + QueryableList items; if (datasets != null) { if (!datasets.isEmpty()) { items = databaseRepository.getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetPublicListingModel.class)); @@ -108,7 +110,7 @@ public class DatasetPublicManager { if (count == 0L) { count = items.count(); } - QueryableList pagedItems = PaginationManager.applyPaging(items, datasetTableRequest); + QueryableList pagedItems = PaginationManager.applyPaging(items, datasetTableRequest); DataTableData dataTable = new DataTableData<>(); List datasetLists = pagedItems. @@ -120,22 +122,23 @@ public class DatasetPublicManager { } public DatasetPublicModel getOverviewSinglePublic(String id) throws Exception { - Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id)); - if (datasetEntity.getStatus() == Dataset.Status.DELETED.getValue()) { + DescriptionEntity descriptionEntityEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id)); + if (descriptionEntityEntity.getIsActive() == IsActive.Inactive) { throw new Exception("Dataset is deleted."); } - if (!datasetEntity.getDmp().isPublic()) { - throw new ForbiddenException("Selected Dataset is not public"); - } + //TODO +// if (!descriptionEntityEntity.getDmp().isPublic()) { +// throw new ForbiddenException("Selected Dataset is not public"); +// } DatasetPublicModel dataset = new DatasetPublicModel(); - dataset.setDatasetProfileDefinition(this.getPagedProfile(dataset.getStatus(), datasetEntity)); - dataset.fromDataModel(datasetEntity); + dataset.setDatasetProfileDefinition(this.getPagedProfile(dataset.getStatus(), descriptionEntityEntity)); + dataset.fromDataModel(descriptionEntityEntity); return dataset; } @Transactional - private DatasetPublicListingModel mapPublicModel(Dataset item) { + private DatasetPublicListingModel mapPublicModel(DescriptionEntity item) { /*if (item.getProfile() == null) return null;*/ DatasetPublicListingModel listingPublicModel = new DatasetPublicListingModel().fromDataModel(item); @@ -151,16 +154,17 @@ public class DatasetPublicManager { return listingPublicModel; } - private PagedDatasetProfile getPagedProfile(int status, Dataset datasetEntity){ - eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = this.generateDatasetProfileModel(datasetEntity.getProfile()); - datasetprofile.setStatus(status); - if (datasetEntity.getProperties() != null) { - JSONObject jObject = new JSONObject(datasetEntity.getProperties()); - Map properties = jObject.toMap(); - datasetprofile.fromJsonObject(properties); - } + private PagedDatasetProfile getPagedProfile(DescriptionStatus status, DescriptionEntity descriptionEntityEntity){ + //TODO +// eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = this.generateDatasetProfileModel(descriptionEntityEntity.getProfile()); +// datasetprofile.setStatus(status.getValue()); +// if (descriptionEntityEntity.getProperties() != null) { +// JSONObject jObject = new JSONObject(descriptionEntityEntity.getProperties()); +// Map properties = jObject.toMap(); +// datasetprofile.fromJsonObject(properties); +// } PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile(); - pagedDatasetProfile.buildPagedDatasetProfile(datasetprofile); +// pagedDatasetProfile.buildPagedDatasetProfile(datasetprofile); return pagedDatasetProfile; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/publicapi/models/listingmodels/DatasetPublicListingModel.java b/dmp-backend/web/src/main/java/eu/eudat/publicapi/models/listingmodels/DatasetPublicListingModel.java index 9744fb82b..d07501c70 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/publicapi/models/listingmodels/DatasetPublicListingModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/publicapi/models/listingmodels/DatasetPublicListingModel.java @@ -1,7 +1,7 @@ package eu.eudat.publicapi.models.listingmodels; import eu.eudat.data.old.DMP; -import eu.eudat.data.old.Dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.old.Grant; import eu.eudat.models.DataModel; import eu.eudat.publicapi.models.datasetprofile.DatasetProfilePublicModel; @@ -13,7 +13,7 @@ import java.util.List; import java.util.UUID; import java.util.stream.Collectors; -public class DatasetPublicListingModel implements DataModel { +public class DatasetPublicListingModel implements DataModel { private String id; private String label; private String grant; @@ -121,53 +121,55 @@ public class DatasetPublicListingModel implements DataModel new UserInfoPublicModel().fromDataModel(x)).collect(Collectors.toList()) : new ArrayList<>(); + public DatasetPublicListingModel fromDataModel(DescriptionEntity entity) { + //TODO +// this.id = entity.getId() != null ? entity.getId().toString() : ""; +// this.label = entity.getLabel(); +// this.createdAt = entity.getCreated(); +// this.modifiedAt = entity.getModified(); +// if(entity.getDmp() != null && entity.getDmp().getGrant() != null) { +// this.grant = entity.getDmp().getGrant().getLabel(); +// } +// this.dmp = entity.getDmp() != null ? entity.getDmp().getLabel() : ""; +// this.dmpId = entity.getDmp() != null ? entity.getDmp().getId().toString() : ""; +// this.profile = entity.getProfile() != null ? new DatasetProfilePublicModel().fromDataModel(entity.getProfile()) : null; +// this.description = entity.getDescription(); +// if (entity.getFinalizedAt() == null && entity.getStatus() == DescriptionEntity.Status.FINALISED.getValue()) { +// this.finalizedAt = entity.getDmp().getFinalizedAt(); +// } else { +// this.finalizedAt = entity.getFinalizedAt(); +// } +// this.dmpPublishedAt = entity.getDmp().getPublishedAt(); +// this.version = entity.getDmp().getVersion(); +// this.users = entity.getDmp() != null ? entity.getDmp().getUsers().stream().map(x -> new UserInfoPublicModel().fromDataModel(x)).collect(Collectors.toList()) : new ArrayList<>(); return this; } @Override - public Dataset toDataModel() { - Dataset entity = new Dataset(); - entity.setId(UUID.fromString(this.getId())); - entity.setLabel(this.getLabel()); - entity.setCreated(this.getCreatedAt()); - entity.setModified(this.getModifiedAt()); - entity.setDescription(this.getDescription()); - entity.setFinalizedAt(this.getFinalizedAt()); - entity.setStatus(Dataset.Status.FINALISED.getValue()); - DMP dmp = new DMP(); - if (this.getGrant() != null && !this.getGrant().isEmpty()) { - Grant grant = new Grant(); - grant.setLabel(this.getGrant()); - dmp.setGrant(grant); - } - dmp.setLabel(this.getDmp()); - dmp.setId(UUID.fromString(this.getDmpId())); - dmp.setPublishedAt(this.getDmpPublishedAt()); - dmp.setVersion(this.getVersion()); - dmp.setUsers(this.getUsers().stream().map(UserInfoPublicModel::toDataModel).collect(Collectors.toSet())); - dmp.setFinalizedAt(this.getFinalizedAt()); - entity.setDmp(dmp); - entity.setProfile(this.getProfile() != null ? this.getProfile().toDataModel() : null); + public DescriptionEntity toDataModel() { + //TODO + DescriptionEntity entity = new DescriptionEntity(); +// entity.setId(UUID.fromString(this.getId())); +// entity.setLabel(this.getLabel()); +// entity.setCreated(this.getCreatedAt()); +// entity.setModified(this.getModifiedAt()); +// entity.setDescription(this.getDescription()); +// entity.setFinalizedAt(this.getFinalizedAt()); +// entity.setStatus(DescriptionEntity.Status.FINALISED.getValue()); +// DMP dmp = new DMP(); +// if (this.getGrant() != null && !this.getGrant().isEmpty()) { +// Grant grant = new Grant(); +// grant.setLabel(this.getGrant()); +// dmp.setGrant(grant); +// } +// dmp.setLabel(this.getDmp()); +// dmp.setId(UUID.fromString(this.getDmpId())); +// dmp.setPublishedAt(this.getDmpPublishedAt()); +// dmp.setVersion(this.getVersion()); +// dmp.setUsers(this.getUsers().stream().map(UserInfoPublicModel::toDataModel).collect(Collectors.toSet())); +// dmp.setFinalizedAt(this.getFinalizedAt()); +// entity.setDmp(dmp); +// entity.setProfile(this.getProfile() != null ? this.getProfile().toDataModel() : null); return entity; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/publicapi/models/overviewmodels/DataManagementPlanPublicModel.java b/dmp-backend/web/src/main/java/eu/eudat/publicapi/models/overviewmodels/DataManagementPlanPublicModel.java index 2ea6acb06..66c70e2fc 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/publicapi/models/overviewmodels/DataManagementPlanPublicModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/publicapi/models/overviewmodels/DataManagementPlanPublicModel.java @@ -2,10 +2,12 @@ package eu.eudat.publicapi.models.overviewmodels; 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.commons.types.descriptiontemplate.DefinitionEntity; import eu.eudat.data.old.DMP; import eu.eudat.data.old.DMPDatasetProfile; -import eu.eudat.data.old.Dataset; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.commons.types.xml.XmlBuilder; import eu.eudat.models.DataModel; @@ -184,10 +186,10 @@ public class DataManagementPlanPublicModel implements DataModel new OrganizationPublicModel().fromDataModel(item)).collect(Collectors.toList()); - this.datasets = entity.getDataset().stream().filter(dataset -> !dataset.getStatus().equals(Dataset.Status.DELETED.getValue()) && !dataset.getStatus().equals(Dataset.Status.CANCELED.getValue())) + 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(), datasetEntity)); + dataset.setDatasetProfileDefinition(this.getPagedProfile(dataset.getStatus().getValue(), datasetEntity)); dataset.fromDataModel(datasetEntity); return dataset; }).collect(Collectors.toList()); @@ -217,16 +219,17 @@ public class DataManagementPlanPublicModel implements DataModel properties = jObject.toMap(); - datasetprofile.fromJsonObject(properties); - } + private PagedDatasetProfile getPagedProfile(int status, DescriptionEntity descriptionEntityEntity){ + //TODO +// eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = this.generateDatasetProfileModel(descriptionEntityEntity.getProfile()); +// datasetprofile.setStatus(status); +// if (descriptionEntityEntity.getProperties() != null) { +// JSONObject jObject = new JSONObject(descriptionEntityEntity.getProperties()); +// Map properties = jObject.toMap(); +// datasetprofile.fromJsonObject(properties); +// } PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile(); - pagedDatasetProfile.buildPagedDatasetProfile(datasetprofile); + //pagedDatasetProfile.buildPagedDatasetProfile(datasetprofile); return pagedDatasetProfile; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/publicapi/models/overviewmodels/DatasetPublicModel.java b/dmp-backend/web/src/main/java/eu/eudat/publicapi/models/overviewmodels/DatasetPublicModel.java index ba7eb2967..4755b2b04 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/publicapi/models/overviewmodels/DatasetPublicModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/publicapi/models/overviewmodels/DatasetPublicModel.java @@ -1,5 +1,7 @@ package eu.eudat.publicapi.models.overviewmodels; +import eu.eudat.commons.enums.DescriptionStatus; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.old.*; import eu.eudat.elastic.entities.Tag; @@ -16,13 +18,13 @@ import net.minidev.json.JSONValue; import java.util.*; import java.util.stream.Collectors; -public class DatasetPublicModel implements DataModel { +public class DatasetPublicModel implements DataModel { private UUID id; private String label; private String reference; private String uri; private String description; - private short status; + private DescriptionStatus status; private Date createdAt; private DataManagementPlanPublicListingModel dmp; private PagedDatasetProfile datasetProfileDefinition; @@ -69,10 +71,10 @@ public class DatasetPublicModel implements DataModel new RegistryPublicModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); - this.dataRepositories = entity.getDatasetDataRepositories() != null ? entity.getDatasetDataRepositories().stream().map(item -> { - DataRepositoryPublicModel dataRepository = new DataRepositoryPublicModel().fromDataModel(item.getDataRepository()); - if (item.getData() != null) { - Map> data = (Map>) JSONValue.parse(item.getData()); - Map values = data.get("data"); - dataRepository.setInfo(values.get("info")); - } - return dataRepository; - }).collect(Collectors.toList()) : new ArrayList<>(); - this.services = entity.getServices() != null ? entity.getServices().stream().map(item -> new ServicePublicModel().fromDataModel(item.getService())).collect(Collectors.toList()) : new ArrayList<>(); - this.createdAt = entity.getCreated(); - this.dmp = new DataManagementPlanPublicListingModel().fromDataModelNoDatasets(entity.getDmp()); - this.externalDatasets = entity.getDatasetExternalDatasets() != null ? entity.getDatasetExternalDatasets().stream().map(item -> { - ExternalDatasetPublicListingModel externalDatasetListingModel = new ExternalDatasetPublicListingModel().fromDataModel(item.getExternalDataset()); - if (item.getData() != null) { - Map> data = (Map>) JSONValue.parse(item.getData()); - Map values = data.get("data"); - externalDatasetListingModel.setInfo(values.get("info")); - externalDatasetListingModel.setType(Integer.parseInt(values.get("type"))); - } - return externalDatasetListingModel; - }).collect(Collectors.toList()) : new ArrayList<>(); - this.modifiedAt = entity.getModified(); + public DatasetPublicModel fromDataModel(DescriptionEntity entity) { + //TODO: +// this.id = entity.getId(); +// this.label = entity.getLabel(); +// this.reference = entity.getReference(); +// this.description = entity.getDescription(); +// this.status = entity.getStatus(); +// this.profile = new DatasetProfilePublicModel(); +// this.profile = this.profile.fromDataModel(entity.getProfile()); +// this.uri = entity.getUri(); +// this.registries = entity.getRegistries() != null ? entity.getRegistries().stream().map(item -> new RegistryPublicModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); +// this.dataRepositories = entity.getDatasetDataRepositories() != null ? entity.getDatasetDataRepositories().stream().map(item -> { +// DataRepositoryPublicModel dataRepository = new DataRepositoryPublicModel().fromDataModel(item.getDataRepository()); +// if (item.getData() != null) { +// Map> data = (Map>) JSONValue.parse(item.getData()); +// Map values = data.get("data"); +// dataRepository.setInfo(values.get("info")); +// } +// return dataRepository; +// }).collect(Collectors.toList()) : new ArrayList<>(); +// this.services = entity.getServices() != null ? entity.getServices().stream().map(item -> new ServicePublicModel().fromDataModel(item.getService())).collect(Collectors.toList()) : new ArrayList<>(); +// this.createdAt = entity.getCreated(); +// this.dmp = new DataManagementPlanPublicListingModel().fromDataModelNoDatasets(entity.getDmp()); +// this.externalDatasets = entity.getDatasetExternalDatasets() != null ? entity.getDatasetExternalDatasets().stream().map(item -> { +// ExternalDatasetPublicListingModel externalDatasetListingModel = new ExternalDatasetPublicListingModel().fromDataModel(item.getExternalDataset()); +// if (item.getData() != null) { +// Map> data = (Map>) JSONValue.parse(item.getData()); +// Map values = data.get("data"); +// externalDatasetListingModel.setInfo(values.get("info")); +// externalDatasetListingModel.setType(Integer.parseInt(values.get("type"))); +// } +// return externalDatasetListingModel; +// }).collect(Collectors.toList()) : new ArrayList<>(); +// this.modifiedAt = entity.getModified(); return this; } - public DatasetPublicModel fromDataModelNoDmp(Dataset entity) { - this.id = entity.getId(); - this.label = entity.getLabel(); - this.reference = entity.getReference(); - this.description = entity.getDescription(); - this.status = entity.getStatus(); - this.profile = new DatasetProfilePublicModel(); - this.profile = this.profile.fromDataModel(entity.getProfile()); - this.uri = entity.getUri(); - this.registries = entity.getRegistries() != null ? entity.getRegistries().stream().map(item -> new RegistryPublicModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); - this.dataRepositories = entity.getDatasetDataRepositories() != null ? entity.getDatasetDataRepositories().stream().map(item -> { - DataRepositoryPublicModel dataRepository = new DataRepositoryPublicModel().fromDataModel(item.getDataRepository()); - if (item.getData() != null) { - Map> data = (Map>) JSONValue.parse(item.getData()); - Map values = data.get("data"); - dataRepository.setInfo(values.get("info")); - } - return dataRepository; - }).collect(Collectors.toList()) : new ArrayList<>(); - this.services = entity.getServices() != null ? entity.getServices().stream().map(item -> new ServicePublicModel().fromDataModel(item.getService())).collect(Collectors.toList()) : new ArrayList<>(); - this.createdAt = entity.getCreated(); - this.externalDatasets = entity.getDatasetExternalDatasets() != null ? entity.getDatasetExternalDatasets().stream().map(item -> { - ExternalDatasetPublicListingModel externalDatasetListingModel = new ExternalDatasetPublicListingModel().fromDataModel(item.getExternalDataset()); - if (item.getData() != null) { - Map> data = (Map>) JSONValue.parse(item.getData()); - Map values = data.get("data"); - externalDatasetListingModel.setInfo(values.get("info")); - externalDatasetListingModel.setType(Integer.parseInt(values.get("type"))); - } - return externalDatasetListingModel; - }).collect(Collectors.toList()) : new ArrayList<>(); - this.modifiedAt = entity.getModified(); + public DatasetPublicModel fromDataModelNoDmp(DescriptionEntity entity) { + //TODO: +// this.id = entity.getId(); +// this.label = entity.getLabel(); +// this.reference = entity.getReference(); +// this.description = entity.getDescription(); +// this.status = entity.getStatus(); +// this.profile = new DatasetProfilePublicModel(); +// this.profile = this.profile.fromDataModel(entity.getProfile()); +// this.uri = entity.getUri(); +// this.registries = entity.getRegistries() != null ? entity.getRegistries().stream().map(item -> new RegistryPublicModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); +// this.dataRepositories = entity.getDatasetDataRepositories() != null ? entity.getDatasetDataRepositories().stream().map(item -> { +// DataRepositoryPublicModel dataRepository = new DataRepositoryPublicModel().fromDataModel(item.getDataRepository()); +// if (item.getData() != null) { +// Map> data = (Map>) JSONValue.parse(item.getData()); +// Map values = data.get("data"); +// dataRepository.setInfo(values.get("info")); +// } +// return dataRepository; +// }).collect(Collectors.toList()) : new ArrayList<>(); +// this.services = entity.getServices() != null ? entity.getServices().stream().map(item -> new ServicePublicModel().fromDataModel(item.getService())).collect(Collectors.toList()) : new ArrayList<>(); +// this.createdAt = entity.getCreated(); +// this.externalDatasets = entity.getDatasetExternalDatasets() != null ? entity.getDatasetExternalDatasets().stream().map(item -> { +// ExternalDatasetPublicListingModel externalDatasetListingModel = new ExternalDatasetPublicListingModel().fromDataModel(item.getExternalDataset()); +// if (item.getData() != null) { +// Map> data = (Map>) JSONValue.parse(item.getData()); +// Map values = data.get("data"); +// externalDatasetListingModel.setInfo(values.get("info")); +// externalDatasetListingModel.setType(Integer.parseInt(values.get("type"))); +// } +// return externalDatasetListingModel; +// }).collect(Collectors.toList()) : new ArrayList<>(); +// this.modifiedAt = entity.getModified(); return this; } @Override - public Dataset toDataModel() throws Exception { - Dataset entity = new Dataset(); - entity.setId(this.id); - entity.setLabel(this.label); - entity.setStatus(this.status); - entity.setReference(this.reference); - entity.setUri(this.uri); - entity.setFinalizedAt(new Date()); - DMP dmp = new DMP(); - dmp.setId(UUID.fromString(this.dmp.getId())); - entity.setDmp(dmp); - entity.setDescription(this.description); - entity.setCreated(this.createdAt != null ? this.createdAt : new Date()); - entity.setModified(new Date()); - DescriptionTemplateEntity profile = new DescriptionTemplateEntity(); - profile.setId(this.profile.getId()); - entity.setProfile(profile); - if (this.registries != null && !this.registries.isEmpty()) { - entity.setRegistries(new HashSet<>()); - for (RegistryPublicModel registry : this.registries) { - entity.getRegistries().add(registry.toDataModel()); - } - } - - if (this.dataRepositories != null && !this.dataRepositories.isEmpty()) { - entity.setDatasetDataRepositories(new HashSet<>()); - for (DataRepositoryPublicModel dataRepositoryModel : this.dataRepositories) { - DataRepository dataRepository = dataRepositoryModel.toDataModel(); - DatasetDataRepository datasetDataRepository = new DatasetDataRepository(); - datasetDataRepository.setDataRepository(dataRepository); - Map> data = new HashMap<>(); - Map values = new HashMap<>(); - values.put("info", dataRepositoryModel.getInfo()); - data.put("data", values); - datasetDataRepository.setData(JSONValue.toJSONString(data)); - entity.getDatasetDataRepositories().add(datasetDataRepository); - } - } - - if (this.services != null && !this.services.isEmpty()) { - entity.setServices(new HashSet<>()); - for (ServicePublicModel serviceModel : this.services) { - Service service = serviceModel.toDataModel(); - DatasetService datasetService = new DatasetService(); - datasetService.setService(service); - entity.getServices().add(datasetService); - } - } - - if (this.externalDatasets != null && !this.externalDatasets.isEmpty()) { - entity.setDatasetExternalDatasets(new HashSet<>()); - for (ExternalDatasetPublicListingModel externalDataset : this.externalDatasets) { - ExternalDataset externalDatasetEntity = externalDataset.toDataModel(); - DatasetExternalDataset datasetExternalDataset = new DatasetExternalDataset(); - datasetExternalDataset.setExternalDataset(externalDatasetEntity); - Map> data = new HashMap<>(); - Map values = new HashMap<>(); - values.put("info",externalDataset.getInfo()); - values.put("type",externalDataset.getType().toString()); - data.put("data",values); - datasetExternalDataset.setData(JSONValue.toJSONString(data)); - entity.getDatasetExternalDatasets().add(datasetExternalDataset); - } - } + public DescriptionEntity toDataModel() throws Exception { + //TODO: + DescriptionEntity entity = new DescriptionEntity(); +// entity.setId(this.id); +// entity.setLabel(this.label); +// entity.setStatus(this.status); +// entity.setReference(this.reference); +// entity.setUri(this.uri); +// entity.setFinalizedAt(new Date()); +// DMP dmp = new DMP(); +// dmp.setId(UUID.fromString(this.dmp.getId())); +// entity.setDmp(dmp); +// entity.setDescription(this.description); +// entity.setCreated(this.createdAt != null ? this.createdAt : new Date()); +// entity.setModified(new Date()); +// DescriptionTemplateEntity profile = new DescriptionTemplateEntity(); +// profile.setId(this.profile.getId()); +// entity.setProfile(profile); +// if (this.registries != null && !this.registries.isEmpty()) { +// entity.setRegistries(new HashSet<>()); +// for (RegistryPublicModel registry : this.registries) { +// entity.getRegistries().add(registry.toDataModel()); +// } +// } +// +// if (this.dataRepositories != null && !this.dataRepositories.isEmpty()) { +// entity.setDatasetDataRepositories(new HashSet<>()); +// for (DataRepositoryPublicModel dataRepositoryModel : this.dataRepositories) { +// DataRepository dataRepository = dataRepositoryModel.toDataModel(); +// DatasetDataRepository datasetDataRepository = new DatasetDataRepository(); +// datasetDataRepository.setDataRepository(dataRepository); +// Map> data = new HashMap<>(); +// Map values = new HashMap<>(); +// values.put("info", dataRepositoryModel.getInfo()); +// data.put("data", values); +// datasetDataRepository.setData(JSONValue.toJSONString(data)); +// entity.getDatasetDataRepositories().add(datasetDataRepository); +// } +// } +// +// if (this.services != null && !this.services.isEmpty()) { +// entity.setServices(new HashSet<>()); +// for (ServicePublicModel serviceModel : this.services) { +// Service service = serviceModel.toDataModel(); +// DatasetService datasetService = new DatasetService(); +// datasetService.setService(service); +// entity.getServices().add(datasetService); +// } +// } +// +// if (this.externalDatasets != null && !this.externalDatasets.isEmpty()) { +// entity.setDatasetExternalDatasets(new HashSet<>()); +// for (ExternalDatasetPublicListingModel externalDataset : this.externalDatasets) { +// ExternalDataset externalDatasetEntity = externalDataset.toDataModel(); +// DatasetExternalDataset datasetExternalDataset = new DatasetExternalDataset(); +// datasetExternalDataset.setExternalDataset(externalDatasetEntity); +// Map> data = new HashMap<>(); +// Map values = new HashMap<>(); +// values.put("info",externalDataset.getInfo()); +// values.put("type",externalDataset.getType().toString()); +// data.put("data",values); +// datasetExternalDataset.setData(JSONValue.toJSONString(data)); +// entity.getDatasetExternalDatasets().add(datasetExternalDataset); +// } +// } return entity; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/publicapi/request/dataset/DatasetPublicTableRequest.java b/dmp-backend/web/src/main/java/eu/eudat/publicapi/request/dataset/DatasetPublicTableRequest.java index 73e61ff8e..3c5284306 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/publicapi/request/dataset/DatasetPublicTableRequest.java +++ b/dmp-backend/web/src/main/java/eu/eudat/publicapi/request/dataset/DatasetPublicTableRequest.java @@ -1,6 +1,8 @@ package eu.eudat.publicapi.request.dataset; -import eu.eudat.data.old.Dataset; +import eu.eudat.commons.enums.DescriptionStatus; +import eu.eudat.commons.enums.IsActive; +import eu.eudat.data.DescriptionEntity; import eu.eudat.data.query.definition.TableQuery; import eu.eudat.publicapi.criteria.dataset.DatasetPublicCriteria; import eu.eudat.queryable.QueryableList; @@ -12,12 +14,12 @@ import java.util.Date; import java.util.UUID; -public class DatasetPublicTableRequest extends TableQuery { +public class DatasetPublicTableRequest extends TableQuery { @Override - public QueryableList applyCriteria() { - QueryableList query = this.getQuery(); + public QueryableList applyCriteria() { + QueryableList query = this.getQuery(); query.where((builder, root) -> builder.equal(root.get("dmp").get("isPublic"), true)); - query.where((builder, root) -> builder.equal(root.get("status"), Dataset.Status.FINALISED.getValue())); + query.where((builder, root) -> builder.equal(root.get("status"), DescriptionStatus.Finalized)); // query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"), // query.subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), // Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class))); @@ -54,12 +56,12 @@ public class DatasetPublicTableRequest extends TableQuerysubQueryMax((builder1, externalRoot, nestedRoot) -> builder1.and(builder1.equal(externalRoot.get("profile").get("groupId"), nestedRoot.get("profile").get("groupId")), builder1.equal(nestedRoot.get("dmp").get("isPublic"), true)), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "profile:version")), String.class))); } - query.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.DELETED.getValue())); + query.where((builder, root) -> builder.notEqual(root.get("isActive"), IsActive.Inactive)); return query; } @Override - public QueryableList applyPaging(QueryableList items) { + public QueryableList applyPaging(QueryableList items) { return null; } }