From dec8f6354ca89d050c33a3b09a8ce2cbdda9159e Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Thu, 16 Nov 2023 14:01:39 +0200 Subject: [PATCH] remove old data entities --- .../data/DmpDescriptionTemplateEntity.java | 18 +- .../main/java/eu/eudat/data/DmpEntity.java | 20 +- .../java/eu/eudat/data/DmpUserEntity.java | 18 +- .../java/eu/eudat/data/EntityDoiEntity.java | 3 - .../src/main/java/eu/eudat/data/old/DMP.java | 401 ----- .../eu/eudat/data/old/DMPDatasetProfile.java | 75 - .../eu/eudat/data/old/DMPOrganisation.java | 60 - .../java/eu/eudat/data/old/DMPResearcher.java | 60 - .../main/java/eu/eudat/data/old/Grant.java | 46 +- .../java/eu/eudat/data/old/Invitation.java | 20 +- .../java/eu/eudat/data/old/Organisation.java | 38 +- .../main/java/eu/eudat/data/old/Project.java | 24 +- .../java/eu/eudat/data/old/Researcher.java | 24 +- .../main/java/eu/eudat/data/old/UserDMP.java | 113 -- .../main/java/eu/eudat/data/old/UserInfo.java | 26 +- .../eudat/model/DmpDescriptionTemplate.java | 5 +- .../mapper/deposit/DMPToDepositMapper.java | 54 +- .../deposit/DmpEntityDepositMapper.java | 22 +- .../java/eu/eudat/query/EntityDoiQuery.java | 1 - .../criteria/DataManagementPlanCriteria.java | 4 +- .../DataManagementPlanPublicCriteria.java | 4 +- .../DatasetWizardUserDmpCriteria.java | 4 +- .../eu/eudat/data/dao/entities/DMPDao.java | 10 +- .../eudat/data/dao/entities/DMPDaoImpl.java | 48 +- .../data/dao/entities/DatasetDaoImpl.java | 6 +- .../dao/entities/DmpDatasetProfileDao.java | 5 +- .../entities/DmpDatasetProfileDaoImpl.java | 25 +- .../eudat/data/dao/entities/GrantDaoImpl.java | 7 +- .../dao/entities/OrganisationDaoImpl.java | 7 +- .../eudat/data/dao/entities/UserDmpDao.java | 4 +- .../data/dao/entities/UserDmpDaoImpl.java | 24 +- .../DatasetWizardAutocompleteRequest.java | 8 +- .../DataManagementPlanCriteriaRequest.java | 11 +- .../dmp/DataManagementPlanTableRequest.java | 13 +- .../DataManagmentPlanPublicTableRequest.java | 10 +- .../main/java/eu/eudat/query/DMPQuery.java | 12 +- .../java/eu/eudat/query/DatasetQuery.java | 4 +- .../main/java/eu/eudat/controllers/DMPs.java | 40 +- .../eu/eudat/controllers/FileController.java | 14 +- .../controllers/QuickWizardController.java | 4 +- .../builders/entity/UserInfoBuilder.java | 8 +- .../logic/managers/DashBoardManager.java | 22 +- .../managers/DataManagementPlanManager.java | 1387 +++++++++-------- .../eudat/logic/managers/DatasetManager.java | 89 +- .../logic/managers/DatasetWizardManager.java | 9 +- .../eu/eudat/logic/managers/GrantManager.java | 8 +- .../logic/managers/InvitationsManager.java | 157 +- .../MergeEmailConfirmationManager.java | 7 +- .../logic/managers/QuickWizardManager.java | 108 +- .../eu/eudat/logic/managers/RDAManager.java | 6 +- .../eu/eudat/logic/managers/UserManager.java | 6 +- .../services/utilities/InvitationService.java | 13 +- .../utilities/InvitationServiceImpl.java | 34 +- .../utilities/documents/word/WordBuilder.java | 114 +- .../recent/model/RecentDmpModel.java | 38 +- .../DataManagentPlanListingModel.java | 8 +- .../models/data/dmp/DataManagementPlan.java | 382 ++--- .../dmp/DataManagementPlanEditorModel.java | 321 ++-- .../DataManagementPlanNewVersionModel.java | 198 +-- .../models/data/grant/GrantListingModel.java | 2 +- .../DataManagementPlanListingModel.java | 68 +- .../DataManagementPlanOverviewModel.java | 92 +- .../listingmodels/DatasetListingModel.java | 6 - .../listingmodels/UserInfoListingModel.java | 24 +- .../listingmodels/VersionListingModel.java | 10 +- .../models/data/rda/DmpRDAExportModel.java | 82 +- .../eudat/models/data/rda/RDAExportModel.java | 4 +- .../urls/DataManagementPlanUrlListing.java | 8 +- .../rda/mapper/ContributorRDAMapper.java | 18 +- .../eudat/models/rda/mapper/DmpRDAMapper.java | 268 ++-- .../dmp/DataManagementPlanPublicCriteria.java | 4 +- .../DataManagementPlanPublicManager.java | 14 +- .../DataManagementPlanPublicListingModel.java | 78 +- .../DatasetPublicListingModel.java | 5 - .../DataManagementPlanPublicModel.java | 94 +- .../models/user/UserInfoPublicModel.java | 24 +- .../DataManagmentPlanPublicTableRequest.java | 13 +- 77 files changed, 2240 insertions(+), 2781 deletions(-) delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/data/old/DMP.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/data/old/DMPDatasetProfile.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/data/old/DMPOrganisation.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/data/old/DMPResearcher.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/data/old/UserDMP.java diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/DmpDescriptionTemplateEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/DmpDescriptionTemplateEntity.java index 22d894750..3fa48aed6 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/DmpDescriptionTemplateEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/DmpDescriptionTemplateEntity.java @@ -2,14 +2,16 @@ package eu.eudat.data; import eu.eudat.commons.enums.IsActive; import eu.eudat.data.converters.enums.IsActiveConverter; +import eu.eudat.data.old.queryableentity.DataEntity; import jakarta.persistence.*; import java.time.Instant; +import java.util.List; import java.util.UUID; @Entity @Table(name = "\"DmpDescriptionTemplate\"") -public class DmpDescriptionTemplateEntity { +public class DmpDescriptionTemplateEntity implements DataEntity { @Id @Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @@ -104,4 +106,18 @@ public class DmpDescriptionTemplateEntity { this.isActive = isActive; } + @Override + public void update(DmpDescriptionTemplateEntity entity) { + + } + + @Override + public UUID getKeys() { + return null; + } + + @Override + public DmpDescriptionTemplateEntity buildFromTuple(List tuple, List fields, String base) { + return null; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/DmpEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/DmpEntity.java index 3af94b6a6..4c9e03fb0 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/DmpEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/DmpEntity.java @@ -8,14 +8,16 @@ import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.enums.DmpAccessTypeConverter; import eu.eudat.data.converters.enums.DmpStatusConverter; import eu.eudat.data.converters.enums.IsActiveConverter; +import eu.eudat.data.old.queryableentity.DataEntity; import jakarta.persistence.*; import java.time.Instant; +import java.util.List; import java.util.UUID; @Entity @Table(name = "\"Dmp\"") -public class DmpEntity { +public class DmpEntity implements DataEntity { @Id @Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @@ -244,4 +246,20 @@ public class DmpEntity { public void setVersionStatus(DmpVersionStatus versionStatus) { this.versionStatus = versionStatus; } + + + @Override + public void update(DmpEntity entity) { + + } + + @Override + public UUID getKeys() { + return null; + } + + @Override + public DmpEntity buildFromTuple(List tuple, List fields, String base) { + return null; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/DmpUserEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/DmpUserEntity.java index aac673e41..f1ae5c75b 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/DmpUserEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/DmpUserEntity.java @@ -4,14 +4,16 @@ import eu.eudat.commons.enums.DmpUserRole; import eu.eudat.commons.enums.IsActive; import eu.eudat.data.converters.enums.DmpUserRoleConverter; import eu.eudat.data.converters.enums.IsActiveConverter; +import eu.eudat.data.old.queryableentity.DataEntity; import jakarta.persistence.*; import java.time.Instant; +import java.util.List; import java.util.UUID; @Entity @Table(name = "\"DmpUser\"") -public class DmpUserEntity { +public class DmpUserEntity implements DataEntity { @Id @Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)") @@ -107,4 +109,18 @@ public class DmpUserEntity { this.isActive = isActive; } + @Override + public void update(Object entity) { + + } + + @Override + public Object getKeys() { + return null; + } + + @Override + public Object buildFromTuple(List tuple, List fields, String base) { + return null; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/EntityDoiEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/EntityDoiEntity.java index 2fd0edb7a..c096414b4 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/EntityDoiEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/EntityDoiEntity.java @@ -2,14 +2,11 @@ package eu.eudat.data; import eu.eudat.commons.enums.EntityType; import eu.eudat.commons.enums.IsActive; -import eu.eudat.data.converters.DateToUTCConverter; import eu.eudat.data.converters.enums.EntityTypeConverter; import eu.eudat.data.converters.enums.IsActiveConverter; -import eu.eudat.data.old.DMP; import jakarta.persistence.*; import java.time.Instant; -import java.util.Date; import java.util.UUID; @Entity 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 deleted file mode 100644 index abcea40b5..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMP.java +++ /dev/null @@ -1,401 +0,0 @@ -package eu.eudat.data.old; - - -import eu.eudat.data.DescriptionEntity; -import eu.eudat.data.DmpBlueprintEntity; -import eu.eudat.data.EntityDoiEntity; -import eu.eudat.data.converters.DateToUTCConverter; -import eu.eudat.data.old.queryableentity.DataEntity; - -import jakarta.persistence.*; -import java.util.*; -import java.util.stream.Collectors; - - -@Entity -@Table(name = "\"DMP\"") -@NamedEntityGraphs({ - @NamedEntityGraph( - name = "dataManagementPlanListingModel", - attributeNodes = { - @NamedAttributeNode("grant"), @NamedAttributeNode("creator"), @NamedAttributeNode("profile")}/*,*/ - /*subgraphs = { - @NamedSubgraph(name = "users", attributeNodes = {@NamedAttributeNode("user")}), - }*/ - ), - @NamedEntityGraph( - name = "fullyDetailed", - attributeNodes = { - @NamedAttributeNode("grant"), @NamedAttributeNode("profile"), - @NamedAttributeNode(value = "users", subgraph = "users"), @NamedAttributeNode("organisations"), @NamedAttributeNode("researchers") - }, - subgraphs = { - @NamedSubgraph(name = "users", attributeNodes = {@NamedAttributeNode("user")}) - } - ), - @NamedEntityGraph( - name = "dmpRecentActivity", - attributeNodes = { - @NamedAttributeNode("users"), @NamedAttributeNode("creator")}), -// @NamedEntityGraph( -// name = "recentDmpModel", -// attributeNodes = {@NamedAttributeNode("organisations"), @NamedAttributeNode("researchers"), @NamedAttributeNode("associatedDmps"), -// @NamedAttributeNode("grant"), @NamedAttributeNode(value = "users", subgraph = "users"), @NamedAttributeNode("creator"), @NamedAttributeNode("profile"), @NamedAttributeNode(value = "dataset", subgraph = "dataset")}, -// subgraphs = { -// @NamedSubgraph(name = "users", attributeNodes = {@NamedAttributeNode("user")}), -// @NamedSubgraph(name = "dataset", attributeNodes = {@NamedAttributeNode("id"), @NamedAttributeNode("label")}) -// } -// ), - @NamedEntityGraph( - name = "versionListingModel", - attributeNodes = {@NamedAttributeNode("id"), @NamedAttributeNode("groupId"), @NamedAttributeNode("version")} - ) - -}) -public class DMP implements DataEntity { - - public enum DMPStatus { - ACTIVE((short) 0), FINALISED((short) 1),DELETED((short) 99); - - private short value; - - private DMPStatus(short value) { - this.value = value; - } - - public short getValue() { - return value; - } - - public static DMPStatus fromInteger(short value) { - switch (value) { - case 0: - return ACTIVE; - case 1: - return FINALISED; - case 99: - return DELETED; - default: - throw new RuntimeException("Unsupported DMP Status"); - } - } - } - - public static Set getHints() { - return hints; - } - - private static final Set hints = new HashSet<>(Arrays.asList("dataManagementPlanListingModel", "fullyDetailed")); - - @Id - @GeneratedValue - @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") - private UUID id; - - @Column(name = "\"GroupId\"", columnDefinition = "BINARY(16)") - private UUID groupId; - - @Column(name = "\"Label\"") - private String label; - - @Column(name = "\"Version\"") - private Integer version; - - @Transient - private Set descriptionEntity; - - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "\"Grant\"") - private Grant grant; - - - /*@Type(type = "eu.eudat.configurations.typedefinition.XMLType") - @Column(name = "\"AssociatedDmps\"", columnDefinition = "xml", nullable = true) - private String associatedDmps;*/ - @OneToMany(fetch = FetchType.LAZY, mappedBy = "dmp") - private Set associatedDmps; - - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "\"Profile\"") - private DmpBlueprintEntity profile; - - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "\"Creator\"") - private UserInfo creator; - - - @OneToMany(fetch = FetchType.LAZY) - @JoinTable(name = "\"DMPOrganisation\"", - joinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")}, - inverseJoinColumns = {@JoinColumn(name = "\"Organisation\"", referencedColumnName = "\"ID\"")} - ) - private Set organisations; - - - @OneToMany(fetch = FetchType.LAZY) - @JoinTable(name = "\"DMPResearcher\"", - joinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")}, - inverseJoinColumns = {@JoinColumn(name = "\"Researcher\"", referencedColumnName = "\"ID\"")} - ) - private Set researchers; - - - @OneToMany(mappedBy = "dmp", fetch = FetchType.LAZY) - /*@OneToMany(fetch = FetchType.LAZY) - @JoinTable(name = "\"UserDMP\"", - joinColumns = {@JoinColumn(name = "dmp", referencedColumnName = "\"ID\"")}, - inverseJoinColumns = {@JoinColumn(name = "usr", referencedColumnName = "id")} - )*/ - private Set users; - - - @Column(name = "\"Status\"", nullable = false) - private Short status; - - @Column(name = "\"Properties\"") - private String properties; - - @Column(name = "\"DmpProperties\"") - private String dmpProperties; - - @Column(name = "\"Created\"") - @Convert(converter = DateToUTCConverter.class) - private Date created = null; - - @Column(name = "\"Modified\"") - @Convert(converter = DateToUTCConverter.class) - private Date modified = new Date(); - - @Column(name = "\"Description\"") - private String description; - - @Column(name= "\"FinalizedAt\"") - @Convert(converter = DateToUTCConverter.class) - private Date finalizedAt; - - @Column(name = "\"isPublic\"", nullable = false) - private boolean isPublic; - - @Column(name= "\"PublishedAt\"") - @Convert(converter = DateToUTCConverter.class) - private Date publishedAt; - - @Transient - private Set dois; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "\"Project\"") - private Project project; - - @Column(name = "\"extraProperties\"") - private String extraProperties; - - - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } - - public UserInfo getCreator() { - return creator; - } - public void setCreator(UserInfo creator) { - this.creator = creator; - } - - public Short getStatus() { - return status; - } - public void setStatus(Short status) { - this.status = status; - } - - public Date getCreated() { - return created; - } - public void setCreated(Date created) { - this.created = created; - } - - public Date getModified() { - return modified; - } - public void setModified(Date modified) { - this.modified = modified; - } - - public Set getUsers() { - return users; - } - public void setUsers(Set users) { - this.users = users; - } - - public UUID getId() { - return id; - } - public void setId(UUID id) { - this.id = id; - } - - public UUID getGroupId() { - return groupId; - } - public void setGroupId(UUID groupId) { - this.groupId = groupId; - } - - public String getLabel() { - return label; - } - public void setLabel(String label) { - this.label = label; - } - - public Integer getVersion() { - return version; - } - public void setVersion(Integer version) { - this.version = version; - } - - public Grant getGrant() { - return grant; - } - public void setGrant(Grant grant) { - this.grant = grant; - } - - public Set getAssociatedDmps() { - return associatedDmps; - } - public void setAssociatedDmps(Set associatedDmps) { - this.associatedDmps = associatedDmps; - } - - public DmpBlueprintEntity getProfile() { - return profile; - } - public void setProfile(DmpBlueprintEntity profile) { - this.profile = profile; - } - - public Set getDataset() { - return descriptionEntity; - } - public void setDataset(Set descriptionEntity) { - this.descriptionEntity = descriptionEntity; - } - - public Set getOrganisations() { - return organisations; - } - public void setOrganisations(Set organisations) { - this.organisations = organisations; - } - - public Set getResearchers() { - return researchers; - } - public void setResearchers(Set researchers) { - this.researchers = researchers; - } - - public String getProperties() { - return properties; - } - public void setProperties(String properties) { - this.properties = properties; - } - - public String getDmpProperties() { - return dmpProperties; - } - public void setDmpProperties(String dmpProperties) { - this.dmpProperties = dmpProperties; - } - - public Date getFinalizedAt() { - return finalizedAt; - } - public void setFinalizedAt(Date finalizedAt) { - this.finalizedAt = finalizedAt; - } - - public boolean isPublic() { - return isPublic; - } - public void setPublic(boolean aPublic) { - isPublic = aPublic; - } - - public Date getPublishedAt() { - return publishedAt; - } - public void setPublishedAt(Date publishedAt) { - this.publishedAt = publishedAt; - } - - public Set getDois() { - return dois; - } - public void setDois(Set dois) { - this.dois = dois; - } - - public Project getProject() { - return project; - } - public void setProject(Project project) { - this.project = project; - } - - public String getExtraProperties() { - return extraProperties; - } - - public void setExtraProperties(String extraProperties) { - this.extraProperties = extraProperties; - } - - @Override - public void update(DMP entity) { - this.associatedDmps = entity.associatedDmps; - this.label = entity.getLabel(); - this.profile = entity.getProfile(); - this.status = entity.getStatus(); - this.created = entity.created; - this.properties = entity.getProperties(); - this.grant = entity.getGrant(); - this.description = entity.getDescription(); - this.researchers = entity.getResearchers(); - this.organisations = entity.getOrganisations(); - this.dmpProperties = entity.getDmpProperties(); - this.isPublic = entity.isPublic; - this.project = entity.getProject(); - this.setModified(new Date()); - if (entity.getStatus().equals(DMPStatus.FINALISED.getValue())) this.setFinalizedAt(new Date()); - if (entity.isPublic) this.setPublishedAt(new Date()); - if (entity.getUsers() != null) this.users = entity.getUsers(); - this.dois = entity.getDois(); - this.extraProperties = entity.getExtraProperties(); - } - - @Override - public UUID getKeys() { - return this.id; - } - - @Override - public DMP buildFromTuple(List tuple, List fields, String base) { - this.id = tuple.get(0).get(base.isEmpty() ? "id" : base + "." + "id", UUID.class); - this.descriptionEntity = tuple.stream().map(x -> new DescriptionEntity().buildFromTuple(tuple, fields ,base.isEmpty() ? "dataset" : base + "." + "dataset")).collect(Collectors.toSet()); - this.creator = tuple.stream().map(x -> new UserInfo().buildFromTuple(tuple, fields , base.isEmpty() ? "creator" : base + "." + "creator")).collect(Collectors.toList()).get(0); - return this; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPDatasetProfile.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPDatasetProfile.java deleted file mode 100644 index db0204d66..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPDatasetProfile.java +++ /dev/null @@ -1,75 +0,0 @@ -package eu.eudat.data.old; - -import eu.eudat.data.DescriptionTemplateEntity; -import eu.eudat.data.old.queryableentity.DataEntity; - -import jakarta.persistence.*; -import java.util.List; -import java.util.UUID; - -@Entity -@Table(name = "\"DMPDatasetProfile\"") -public class DMPDatasetProfile implements DataEntity { - - @Id - @GeneratedValue - @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") - private UUID id; - - @ManyToOne - @JoinColumn(name = "\"dmp\"") - private DMP dmp; - - @ManyToOne - @JoinColumn(name = "\"datasetprofile\"") - private DescriptionTemplateEntity datasetprofile; - - @Column(name = "\"data\"") - private String data; - - public UUID getId() { - return id; - } - public void setId(UUID id) { - this.id = id; - } - - public DMP getDmp() { - return dmp; - } - public void setDmp(DMP dmp) { - this.dmp = dmp; - } - - public DescriptionTemplateEntity getDatasetprofile() { - return datasetprofile; - } - public void setDatasetprofile(DescriptionTemplateEntity datasetprofile) { - this.datasetprofile = datasetprofile; - } - - public String getData() { - return data; - } - public void setData(String data) { - this.data = data; - } - - @Override - public void update(DMPDatasetProfile entity) { - this.dmp = entity.getDmp(); - this.datasetprofile = entity.getDatasetprofile(); - this.data = entity.getData(); - } - - @Override - public UUID getKeys() { - return this.id; - } - - @Override - public DMPDatasetProfile buildFromTuple(List tuple, List fields, String base) { - this.id = UUID.fromString((String) tuple.get(0).get(base.isEmpty() ? base + "." + "id" : "id")); - return this; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPOrganisation.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPOrganisation.java deleted file mode 100644 index 920b6351b..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPOrganisation.java +++ /dev/null @@ -1,60 +0,0 @@ -package eu.eudat.data.old; - - -import jakarta.persistence.*; -import java.io.Serializable; -import java.util.UUID; - - -@Entity -@Table(name = "\"DMPOrganisation\"") -public class DMPOrganisation { - - @Id - @GeneratedValue - @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") - private UUID id; - - @Column(name = "\"DMP\"") - private UUID dmp; - - @Column(name = "\"Organisation\"") - private UUID organisation; - - @Column(name = "\"Role\"") - private Integer role; - - public UUID getId() { - return id; - } - - public void setId(UUID id) { - this.id = id; - } - - public UUID getDmp() { - return dmp; - } - - public void setDmp(UUID dmp) { - this.dmp = dmp; - } - - public UUID getOrganisation() { - return organisation; - } - - public void setOrganisation(UUID organisation) { - this.organisation = organisation; - } - - public Integer getRole() { - return role; - } - - public void setRole(Integer role) { - this.role = role; - } - - -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPResearcher.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPResearcher.java deleted file mode 100644 index e633606de..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/DMPResearcher.java +++ /dev/null @@ -1,60 +0,0 @@ -package eu.eudat.data.old; - - - -import jakarta.persistence.*; -import java.util.UUID; - - -@Entity -@Table(name = "\"DMPResearcher\"") -public class DMPResearcher { - - @Id - @GeneratedValue - @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") - private UUID id; - - @Column(name = "\"DMP\"") - private UUID dmp; - - @Column(name = "\"Researcher\"") - private UUID researcher; - - @Column(name = "\"Role\"") - private Integer role; - - public UUID getId() { - return id; - } - - public void setId(UUID id) { - this.id = id; - } - - public UUID getDmp() { - return dmp; - } - - public void setDmp(UUID dmp) { - this.dmp = dmp; - } - - public UUID getResearcher() { - return researcher; - } - - public void setResearcher(UUID researcher) { - this.researcher = researcher; - } - - public Integer getRole() { - return role; - } - - public void setRole(Integer role) { - this.role = role; - } - - -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Grant.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Grant.java index ab653339a..4ca962b6e 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Grant.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Grant.java @@ -12,18 +12,18 @@ import java.util.stream.Collectors; @Entity @Table(name = "\"Grant\"") -@NamedEntityGraphs({ - @NamedEntityGraph( - name = "grantRecentActivity", - attributeNodes = {@NamedAttributeNode(value = "dmps", subgraph = "dmps")}, - subgraphs = @NamedSubgraph(name = "dmps", attributeNodes = {@NamedAttributeNode("users")}) - ), - @NamedEntityGraph( - name = "grantListingItem", - attributeNodes = {@NamedAttributeNode(value = "dmps", subgraph = "dmps"), @NamedAttributeNode(value = "content")}, - subgraphs = @NamedSubgraph(name = "dmps", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("grant"), @NamedAttributeNode("users")}) - ) -}) +//@NamedEntityGraphs({ +// @NamedEntityGraph( +// name = "grantRecentActivity", +// attributeNodes = {@NamedAttributeNode(value = "dmps", subgraph = "dmps")}, +// subgraphs = @NamedSubgraph(name = "dmps", attributeNodes = {@NamedAttributeNode("users")}) +// ), +// @NamedEntityGraph( +// name = "grantListingItem", +// attributeNodes = {@NamedAttributeNode(value = "dmps", subgraph = "dmps"), @NamedAttributeNode(value = "content")}, +// subgraphs = @NamedSubgraph(name = "dmps", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("grant"), @NamedAttributeNode("users")}) +// ) +//}) public class Grant implements DataEntity { public enum Status { @@ -85,8 +85,8 @@ public class Grant implements DataEntity { private UUID id; - @OneToMany(mappedBy = "grant") - private Set dmps; +// @OneToMany(mappedBy = "grant") +// private Set dmps; @Column(name = "\"Label\"") private String label; @@ -229,12 +229,12 @@ public class Grant implements DataEntity { this.definition = definition; } - public Set getDmps() { - return dmps; - } - public void setDmps(Set dmps) { - this.dmps = dmps; - } +// public Set getDmps() { +// return dmps; +// } +// public void setDmps(Set dmps) { +// this.dmps = dmps; +// } public UserInfo getCreationUser() { return creationUser; @@ -271,7 +271,7 @@ public class Grant implements DataEntity { this.abbreviation = entity.getAbbreviation(); this.created = entity.getCreated(); this.definition = entity.getDefinition(); - this.dmps = entity.getDmps(); +// this.dmps = entity.getDmps(); this.startdate = entity.getStartdate(); this.enddate = entity.getEnddate(); this.modified = new Date(); @@ -289,8 +289,8 @@ public class Grant implements DataEntity { public Grant buildFromTuple(List tuple, List fields, String base) { String currentBase = base.isEmpty() ? "" : base + "."; if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id"); - if (fields.contains(currentBase + "dmps")) - this.dmps = tuple.stream().map(x -> new DMP().buildFromTuple(Arrays.asList(x), fields, currentBase + "dmps")).collect(Collectors.toSet()); +// if (fields.contains(currentBase + "dmps")) +// this.dmps = tuple.stream().map(x -> new DMP().buildFromTuple(Arrays.asList(x), fields, currentBase + "dmps")).collect(Collectors.toSet()); if (fields.contains(currentBase + "creationUser")) this.creationUser = tuple.stream().map(x -> new UserInfo().buildFromTuple(Arrays.asList(x), fields, currentBase + "creationUser")).collect(Collectors.toList()).get(0); return this; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Invitation.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Invitation.java index fd0f3f416..0bc0b1d29 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Invitation.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Invitation.java @@ -24,9 +24,9 @@ public class Invitation implements DataEntity { @JoinColumn(name = "\"CreationUser\"", nullable = false) private UserInfo user; - @OneToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "\"Dmp\"", nullable = false) - private DMP dmp; +// @OneToOne(fetch = FetchType.EAGER) +// @JoinColumn(name = "\"Dmp\"", nullable = false) +// private DMP dmp; @Column(name = "\"Token\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID token; @@ -61,13 +61,13 @@ public class Invitation implements DataEntity { this.user = user; } - public DMP getDmp() { - return dmp; - } - - public void setDmp(DMP dmp) { - this.dmp = dmp; - } +// public DMP getDmp() { +// return dmp; +// } +// +// public void setDmp(DMP dmp) { +// this.dmp = dmp; +// } public UUID getToken() { return token; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Organisation.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Organisation.java index 9ad772b76..db364f406 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Organisation.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Organisation.java @@ -12,13 +12,13 @@ import java.util.Set; import java.util.UUID; @Entity -@Table(name = "\"Organisation\"") -@NamedEntityGraphs({ - @NamedEntityGraph( - name = "organisationRecentActivity", - attributeNodes = {@NamedAttributeNode(value = "dmps")} - ) -}) +//@Table(name = "\"Organisation\"") +//@NamedEntityGraphs({ +// @NamedEntityGraph( +// name = "organisationRecentActivity", +// attributeNodes = {@NamedAttributeNode(value = "dmps")} +// ) +//}) public class Organisation implements Serializable, DataEntity { @Id @@ -41,12 +41,12 @@ public class Organisation implements Serializable, DataEntity @Column(name = "\"Definition\"", nullable = true) private String definition; - @OneToMany(fetch = FetchType.LAZY) - @JoinTable(name = "\"DMPOrganisation\"", - joinColumns = {@JoinColumn(name = "\"Organisation\"", referencedColumnName = "\"ID\"")}, - inverseJoinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")} - ) - private Set dmps; +// @OneToMany(fetch = FetchType.LAZY) +// @JoinTable(name = "\"DMPOrganisation\"", +// joinColumns = {@JoinColumn(name = "\"Organisation\"", referencedColumnName = "\"ID\"")}, +// inverseJoinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")} +// ) +// private Set dmps; @Column(name = "\"Status\"", nullable = false) private Short status; @@ -123,12 +123,12 @@ public class Organisation implements Serializable, DataEntity this.definition = definition; } - public Set getDmps() { - return dmps; - } - public void setDmps(Set dmps) { - this.dmps = dmps; - } +// public Set getDmps() { +// return dmps; +// } +// public void setDmps(Set dmps) { +// this.dmps = dmps; +// } @Override public void update(Organisation entity) { diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Project.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Project.java index a7b9fde41..130b4c28d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Project.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Project.java @@ -70,8 +70,8 @@ public class Project implements DataEntity { @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; - @OneToMany(mappedBy = "project") - private Set dmps; +// @OneToMany(mappedBy = "project") +// private Set dmps; @Column(name = "\"Label\"") private String label; @@ -131,12 +131,12 @@ public class Project implements DataEntity { this.id = id; } - public Set getDmps() { - return dmps; - } - public void setDmps(Set dmps) { - this.dmps = dmps; - } +// public Set getDmps() { +// return dmps; +// } +// public void setDmps(Set dmps) { +// this.dmps = dmps; +// } public String getLabel() { return label; @@ -243,7 +243,7 @@ public class Project implements DataEntity { this.abbreviation = entity.getAbbreviation(); this.created = entity.getCreated(); this.definition = entity.getDefinition(); - this.dmps = entity.getDmps(); +// this.dmps = entity.getDmps(); this.startdate = entity.getStartdate(); this.enddate = entity.getEnddate(); this.modified = new Date(); @@ -258,7 +258,7 @@ public class Project implements DataEntity { project.setAbbreviation(grant.getAbbreviation()); project.setCreated(new Date()); project.setDefinition(grant.getDefinition()); - project.setDmps(grant.getDmps()); +// project.setDmps(grant.getDmps()); project.setStartdate(grant.getStartdate()); project.setEnddate(grant.getEnddate()); project.setModified(new Date()); @@ -279,8 +279,8 @@ public class Project implements DataEntity { public Project buildFromTuple(List tuple, List fields, String base) { String currentBase = base.isEmpty() ? "" : base + "."; if (fields.contains(currentBase + "id")) this.id = EntityBinder.fromTuple(tuple, currentBase + "id"); - if (fields.contains(currentBase + "dmps")) - this.dmps = tuple.stream().map(x -> new DMP().buildFromTuple(Arrays.asList(x), fields, currentBase + "dmps")).collect(Collectors.toSet()); +// if (fields.contains(currentBase + "dmps")) +// this.dmps = tuple.stream().map(x -> new DMP().buildFromTuple(Arrays.asList(x), fields, currentBase + "dmps")).collect(Collectors.toSet()); if (fields.contains(currentBase + "creationUser")) this.creationUser = tuple.stream().map(x -> new UserInfo().buildFromTuple(Arrays.asList(x), fields, currentBase + "creationUser")).collect(Collectors.toList()).get(0); return this; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/Researcher.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/Researcher.java index d5d35adef..a04e35a30 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/Researcher.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/Researcher.java @@ -36,12 +36,12 @@ public class Researcher implements DataEntity { private String reference; - @OneToMany(fetch = FetchType.LAZY) - @JoinTable(name = "\"DMPResearcher\"", - joinColumns = {@JoinColumn(name = "\"Researcher\"", referencedColumnName = "\"ID\"")}, - inverseJoinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")} - ) - private Set dMPs; +// @OneToMany(fetch = FetchType.LAZY) +// @JoinTable(name = "\"DMPResearcher\"", +// joinColumns = {@JoinColumn(name = "\"Researcher\"", referencedColumnName = "\"ID\"")}, +// inverseJoinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")} +// ) +// private Set dMPs; @Column(name = "\"Status\"", nullable = false) @@ -123,12 +123,12 @@ public class Researcher implements DataEntity { this.definition = definition; } - public Set getdMPs() { - return dMPs; - } - public void setdMPs(Set dMPs) { - this.dMPs = dMPs; - } +// public Set getdMPs() { +// return dMPs; +// } +// public void setdMPs(Set dMPs) { +// this.dMPs = dMPs; +// } public UserInfo getCreationUser() { return creationUser; diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/old/UserDMP.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/UserDMP.java deleted file mode 100644 index dce89e3ce..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/UserDMP.java +++ /dev/null @@ -1,113 +0,0 @@ -package eu.eudat.data.old; - -import eu.eudat.data.old.helpers.EntityBinder; -import eu.eudat.data.old.queryableentity.DataEntity; - -import jakarta.persistence.*; -import java.util.LinkedList; -import java.util.List; -import java.util.UUID; - -@Entity -@Table(name = "\"UserDMP\"") -public class UserDMP implements DataEntity { - - public enum UserDMPRoles { - OWNER(0), USER(1); - - private Integer value; - - private UserDMPRoles(Integer value) { - this.value = value; - } - - public Integer getValue() { - return value; - } - - public static List getAllValues() { - List list = new LinkedList<>(); - for (Enum en : UserDMP.UserDMPRoles.values()) { - list.add(((UserDMPRoles) en).value); - } - return list; - } - - public static UserDMPRoles fromInteger(Integer value) { - switch (value) { - case 0: - return OWNER; - case 1: - return USER; - default: - throw new RuntimeException("Unsupported User Dmp Role Message Code"); - } - } - } - - - @Id - @GeneratedValue - @Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)") - private UUID id; - - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "usr") - private UserInfo user; - - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "dmp") - private DMP dmp; - - @Column(name = "role") - private Integer role; - - public UUID getId() { - return id; - } - - public void setId(UUID id) { - this.id = id; - } - - public UserInfo getUser() { - return user; - } - - public void setUser(UserInfo user) { - this.user = user; - } - - public DMP getDmp() { - return dmp; - } - - public void setDmp(DMP dmp) { - this.dmp = dmp; - } - - public Integer getRole() { - return role; - } - - public void setRole(Integer role) { - this.role = role; - } - - @Override - public void update(UserDMP entity) { - this.role = entity.getRole(); - } - - @Override - public UUID getKeys() { - return this.id; - } - - @Override - public UserDMP buildFromTuple(List tuple, 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/UserInfo.java b/dmp-backend/core/src/main/java/eu/eudat/data/old/UserInfo.java index f39657f36..e1f5d3b96 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/old/UserInfo.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/old/UserInfo.java @@ -66,12 +66,12 @@ public class UserInfo implements DataEntity { private String additionalinfo; public final static String _additionalinfo = "additionalinfo"; - @OneToMany(fetch = FetchType.LAZY) - @JoinTable(name = "\"UserDMP\"", - joinColumns = {@JoinColumn(name = "usr", referencedColumnName = "id")}, - inverseJoinColumns = {@JoinColumn(name = "dmp", referencedColumnName = "\"ID\"")} - ) - private Set dmps; +// @OneToMany(fetch = FetchType.LAZY) +// @JoinTable(name = "\"UserDMP\"", +// joinColumns = {@JoinColumn(name = "usr", referencedColumnName = "id")}, +// inverseJoinColumns = {@JoinColumn(name = "dmp", referencedColumnName = "\"ID\"")} +// ) +// private Set dmps; @OneToMany(fetch = FetchType.LAZY) @JoinColumn(name = "Id") @@ -86,13 +86,13 @@ public class UserInfo implements DataEntity { @OneToMany(mappedBy = "userId", fetch = FetchType.LAZY) private Set notifications = new HashSet<>(); - public Set getDmps() { - return dmps; - } - - public void setDmps(Set dmps) { - this.dmps = dmps; - } +// public Set getDmps() { +// return dmps; +// } +// +// public void setDmps(Set dmps) { +// this.dmps = dmps; +// } public UUID getId() { return id; diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/DmpDescriptionTemplate.java b/dmp-backend/core/src/main/java/eu/eudat/model/DmpDescriptionTemplate.java index ebe2db5e5..69995fc19 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/DmpDescriptionTemplate.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/DmpDescriptionTemplate.java @@ -1,11 +1,13 @@ package eu.eudat.model; import eu.eudat.commons.enums.IsActive; +import eu.eudat.data.old.queryableentity.DataEntity; import java.time.Instant; +import java.util.List; import java.util.UUID; -public class DmpDescriptionTemplate { +public class DmpDescriptionTemplate{ private UUID id; @@ -90,5 +92,4 @@ public class DmpDescriptionTemplate { public void setIsActive(IsActive isActive) { this.isActive = isActive; } - } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DMPToDepositMapper.java b/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DMPToDepositMapper.java index 72804b73f..4023c02e7 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DMPToDepositMapper.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DMPToDepositMapper.java @@ -3,6 +3,8 @@ package eu.eudat.model.mapper.deposit; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import eu.eudat.data.DescriptionEntity; +import eu.eudat.data.DmpEntity; +import eu.eudat.data.DmpUserEntity; import eu.eudat.data.old.*; import eu.eudat.depositinterface.models.*; import eu.eudat.commons.types.xml.XmlBuilder; @@ -28,27 +30,27 @@ public class DMPToDepositMapper { private static final ObjectMapper mapper = new ObjectMapper(); @Transactional - public static DMPDepositModel fromDMP(DMP entity, FileEnvelope pdfFile, FileEnvelope jsonFile, File supportingFilesZip, String previousDOI) { + public static DMPDepositModel fromDMP(DmpEntity entity, FileEnvelope pdfFile, FileEnvelope jsonFile, File supportingFilesZip, String previousDOI) { DMPDepositModel deposit = new DMPDepositModel(); - deposit.setId(entity.getId()); - deposit.setVersion(entity.getVersion()); - deposit.setLabel(entity.getLabel()); - deposit.setDescription(entity.getDescription()); - deposit.setPublic(entity.isPublic()); - deposit.setDatasets(entity.getDataset().stream().map(DMPToDepositMapper::fromDataset).collect(Collectors.toList())); - deposit.setUsers(entity.getUsers().stream().map(DMPToDepositMapper::fromUserDMP).collect(Collectors.toSet())); - deposit.setOrganisations(entity.getOrganisations().stream().map(DMPToDepositMapper::fromOrganisation).collect(Collectors.toSet())); - deposit.setResearchers(entity.getResearchers().stream().map(DMPToDepositMapper::fromResearcher).collect(Collectors.toSet())); - if (entity.getGrant() != null) { - deposit.setGrant(fromGrant(entity.getGrant())); - } - - deposit.setPdfFile(pdfFile); - deposit.setRdaJsonFile(jsonFile); - deposit.setSupportingFilesZip(supportingFilesZip); - deposit.setPreviousDOI(previousDOI); - - deposit.setExtraProperties(entity.getExtraProperties()); +// deposit.setId(entity.getId()); +// deposit.setVersion(entity.getVersion()); +// deposit.setLabel(entity.getLabel()); +// deposit.setDescription(entity.getDescription()); +// deposit.setPublic(entity.isPublic()); +// deposit.setDatasets(entity.getDataset().stream().map(DMPToDepositMapper::fromDataset).collect(Collectors.toList())); +// deposit.setUsers(entity.getUsers().stream().map(DMPToDepositMapper::fromUserDMP).collect(Collectors.toSet())); +// deposit.setOrganisations(entity.getOrganisations().stream().map(DMPToDepositMapper::fromOrganisation).collect(Collectors.toSet())); +// deposit.setResearchers(entity.getResearchers().stream().map(DMPToDepositMapper::fromResearcher).collect(Collectors.toSet())); +// if (entity.getGrant() != null) { +// deposit.setGrant(fromGrant(entity.getGrant())); +// } +// +// deposit.setPdfFile(pdfFile); +// deposit.setRdaJsonFile(jsonFile); +// deposit.setSupportingFilesZip(supportingFilesZip); +// deposit.setPreviousDOI(previousDOI); +// +// deposit.setExtraProperties(entity.getExtraProperties()); return deposit; } @@ -118,12 +120,12 @@ public class DMPToDepositMapper { return deposit; } - private static UserDMPDepositModel fromUserDMP(UserDMP entity){ - UserDMPDepositModel deposit = new UserDMPDepositModel(); - deposit.setUser(fromUserInfo(entity.getUser())); - deposit.setRole(entity.getRole()); - return deposit; - } +// private static UserDMPDepositModel fromUserDMP(DmpUserEntity entity){ +// UserDMPDepositModel deposit = new UserDMPDepositModel(); +// deposit.setUser(fromUserInfo(entity.getUser())); +// deposit.setRole(entity.getRole().getValue().intValue()); +// return deposit; +// } private static UserInfoDepositModel fromUserInfo(UserInfo entity){ UserInfoDepositModel deposit = new UserInfoDepositModel(); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DmpEntityDepositMapper.java b/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DmpEntityDepositMapper.java index 4f192a88f..1d7828d21 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DmpEntityDepositMapper.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/mapper/deposit/DmpEntityDepositMapper.java @@ -5,12 +5,12 @@ import com.fasterxml.jackson.databind.ObjectMapper; import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.types.xml.XmlBuilder; import eu.eudat.data.*; -import eu.eudat.data.old.UserDMP; import eu.eudat.data.old.UserInfo; import eu.eudat.depositinterface.models.*; import eu.eudat.query.DescriptionQuery; import eu.eudat.query.DescriptionTemplateQuery; import eu.eudat.query.DmpDescriptionTemplateQuery; +import eu.eudat.query.DmpUserQuery; import gr.cite.tools.data.query.QueryFactory; import jakarta.persistence.EntityManager; import jakarta.persistence.criteria.*; @@ -49,7 +49,7 @@ public class DmpEntityDepositMapper { public DMPDepositModel toDeposit(DmpEntity dmpEntity, File zip, FileEnvelope pdf, FileEnvelope json, String previousDOI) { DMPDepositModel model = new DMPDepositModel(); List desciptions = this.getDescriptions(dmpEntity.getId()); - List users = getUsers(dmpEntity.getId()); + List users = getUsers(dmpEntity.getId()); model.setId(dmpEntity.getId()); model.setLabel(dmpEntity.getLabel()); model.setDescription(dmpEntity.getDescription()); @@ -142,21 +142,17 @@ public class DmpEntityDepositMapper { return deposit; } - private List getUsers(UUID dmpId) { - CriteriaBuilder builder = entityManager.getCriteriaBuilder(); - CriteriaQuery query = builder.createQuery(UserDMP.class); - Root root = query.from(UserDMP.class); - Join join = root.join("user").join("id"); - query = query.multiselect(root.get("user"), root.get("role")); - return entityManager.createQuery(query).getResultList(); + private List getUsers(UUID dmpId) { + return this.queryFactory.query(DmpUserQuery.class).userIds(dmpId).collect(); } - private UserDMPDepositModel toUserDeposit(UserDMP user) { + private UserDMPDepositModel toUserDeposit(DmpUserEntity user) { UserDMPDepositModel userDMPDepositModel = new UserDMPDepositModel(); userDMPDepositModel.setUser(new UserInfoDepositModel()); - userDMPDepositModel.getUser().setName(user.getUser().getName()); - userDMPDepositModel.getUser().setEmail(user.getUser().getEmail()); - userDMPDepositModel.setRole(user.getRole()); + UserInfo userInfo = this.entityManager.find(UserInfo.class, user.getUser()); + userDMPDepositModel.getUser().setName(userInfo.getName()); + userDMPDepositModel.getUser().setEmail(userInfo.getEmail()); + userDMPDepositModel.setRole(user.getRole().getValue().intValue()); return userDMPDepositModel; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/EntityDoiQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/EntityDoiQuery.java index 46541a002..485e2e1d1 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/EntityDoiQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/EntityDoiQuery.java @@ -5,7 +5,6 @@ import eu.eudat.commons.enums.EntityType; import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.scope.user.UserScope; import eu.eudat.data.EntityDoiEntity; -import eu.eudat.data.old.DMP; import eu.eudat.model.EntityDoi; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.query.FieldResolver; diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/DataManagementPlanCriteria.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/DataManagementPlanCriteria.java index c44b1b695..348e2a4f4 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/DataManagementPlanCriteria.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/DataManagementPlanCriteria.java @@ -1,14 +1,14 @@ package eu.eudat.data.dao.criteria; -import eu.eudat.data.old.DMP; import eu.eudat.data.DmpBlueprintEntity; +import eu.eudat.data.DmpEntity; import eu.eudat.data.old.Grant; import java.util.Date; import java.util.List; import java.util.UUID; -public class DataManagementPlanCriteria extends Criteria { +public class DataManagementPlanCriteria extends Criteria { private Date periodStart; private Date periodEnd; private DmpBlueprintEntity profile; diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/DataManagementPlanPublicCriteria.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/DataManagementPlanPublicCriteria.java index db56ffdc6..a9a2d9d02 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/DataManagementPlanPublicCriteria.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/DataManagementPlanPublicCriteria.java @@ -1,12 +1,12 @@ package eu.eudat.data.dao.criteria; -import eu.eudat.data.old.DMP; +import eu.eudat.data.DmpEntity; import eu.eudat.types.grant.GrantStateType; import java.util.List; import java.util.UUID; -public class DataManagementPlanPublicCriteria extends Criteria { +public class DataManagementPlanPublicCriteria extends Criteria { private GrantStateType grantStatus; private List grants; public List datasetProfile; diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/DatasetWizardUserDmpCriteria.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/DatasetWizardUserDmpCriteria.java index d92440c88..60833102d 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/DatasetWizardUserDmpCriteria.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/DatasetWizardUserDmpCriteria.java @@ -1,10 +1,10 @@ package eu.eudat.data.dao.criteria; -import eu.eudat.data.old.DMP; +import eu.eudat.data.DmpEntity; import eu.eudat.data.old.UserInfo; -public class DatasetWizardUserDmpCriteria extends Criteria { +public class DatasetWizardUserDmpCriteria extends Criteria { private UserInfo userInfo; public UserInfo getUserInfo() { diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDao.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDao.java index 3946cc1cb..c183e55c7 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDao.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDao.java @@ -1,21 +1,21 @@ package eu.eudat.data.dao.entities; +import eu.eudat.data.DmpEntity; import eu.eudat.data.dao.DatabaseAccessLayer; import eu.eudat.data.dao.criteria.DataManagementPlanCriteria; import eu.eudat.data.dao.criteria.DatasetWizardUserDmpCriteria; -import eu.eudat.data.old.DMP; import eu.eudat.data.old.UserInfo; import eu.eudat.queryable.QueryableList; import java.util.List; import java.util.UUID; -public interface DMPDao extends DatabaseAccessLayer { +public interface DMPDao extends DatabaseAccessLayer { - QueryableList getWithCriteria(DataManagementPlanCriteria criteria); + QueryableList getWithCriteria(DataManagementPlanCriteria criteria); - QueryableList getUserDmps(DatasetWizardUserDmpCriteria datasetWizardAutocompleteRequest, UserInfo userInfo); + QueryableList getUserDmps(DatasetWizardUserDmpCriteria datasetWizardAutocompleteRequest, UserInfo userInfo); - QueryableList getAuthenticated(QueryableList query, UUID principalId, List roles); + QueryableList getAuthenticated(QueryableList query, UUID principalId, List roles); } \ No newline at end of file diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDaoImpl.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDaoImpl.java index efff8b70a..d2158f115 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDaoImpl.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDaoImpl.java @@ -1,10 +1,12 @@ package eu.eudat.data.dao.entities; +import eu.eudat.commons.enums.DmpStatus; +import eu.eudat.commons.enums.IsActive; +import eu.eudat.data.DmpEntity; import eu.eudat.data.dao.DatabaseAccess; import eu.eudat.data.dao.criteria.DataManagementPlanCriteria; import eu.eudat.data.dao.criteria.DatasetWizardUserDmpCriteria; import eu.eudat.data.dao.databaselayer.service.DatabaseService; -import eu.eudat.data.old.DMP; import eu.eudat.data.old.UserInfo; import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.types.FieldSelectionType; @@ -25,16 +27,16 @@ import java.util.UUID; import java.util.concurrent.CompletableFuture; @Component("dMPDao") -public class DMPDaoImpl extends DatabaseAccess implements DMPDao { +public class DMPDaoImpl extends DatabaseAccess implements DMPDao { @Autowired - public DMPDaoImpl(DatabaseService databaseService) { + public DMPDaoImpl(DatabaseService databaseService) { super(databaseService); } @Override - public QueryableList getWithCriteria(DataManagementPlanCriteria criteria) { - QueryableList query = getDatabaseService().getQueryable(DMP.getHints(), DMP.class); + public QueryableList getWithCriteria(DataManagementPlanCriteria criteria) { + QueryableList query = getDatabaseService().getQueryable(DmpEntity.class); if (criteria.getLike() != null && !criteria.getLike().isEmpty()) query.where((builder, root) -> builder.or( builder.like(builder.upper(root.get("label")), "%" + criteria.getLike().toUpperCase() + "%"), @@ -51,14 +53,14 @@ public class DMPDaoImpl extends DatabaseAccess implements DMPDao { query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("version"), query.subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.and( builder1.equal(externalRoot.get("groupId"), nestedRoot.get("groupId")), - builder1.notEqual(nestedRoot.get("status"), DMP.DMPStatus.DELETED.getValue())), Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "version")), Integer.class))); + builder1.notEqual(nestedRoot.get("isActive"), IsActive.Inactive.getValue())), Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "version")), Integer.class))); if (criteria.getGroupIds() != null && !criteria.getGroupIds().isEmpty()) query.where((builder, root) -> root.get("groupId").in(criteria.getGroupIds())); if (criteria.getStatus() != null) { - if (criteria.getStatus() == DMP.DMPStatus.FINALISED.getValue()) { - query.where((builder, root) -> builder.equal(root.get("status"), DMP.DMPStatus.FINALISED.getValue())); - } else if (criteria.getStatus() == DMP.DMPStatus.ACTIVE.getValue()) { - query.where((builder, root) -> builder.equal(root.get("status"), DMP.DMPStatus.ACTIVE.getValue())); + if (criteria.getStatus() == DmpStatus.Finalized.getValue().intValue()) { + query.where((builder, root) -> builder.equal(root.get("status"), DmpStatus.Finalized.getValue())); + } else if (criteria.getStatus() == DmpStatus.Draft.getValue().intValue()) { + query.where((builder, root) -> builder.equal(root.get("status"), DmpStatus.Draft.getValue())); } } if (criteria.getIsPublic()) { @@ -92,11 +94,11 @@ public class DMPDaoImpl extends DatabaseAccess implements DMPDao { if (criteria.hasDoi()) { query.where((builder, root) -> builder.not(builder.isNull(root.join("dois").get("id")))); } - query.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue())); + query.where((builder, root) -> builder.notEqual(root.get("isActive"), IsActive.Inactive)); return query; } - public QueryableList getAuthenticated(QueryableList query, UUID principal, List roles) { + public QueryableList getAuthenticated(QueryableList query, UUID principal, List roles) { if (roles != null && !roles.isEmpty()) { query.where((builder, root) -> { Join userJoin = root.join("users", JoinType.LEFT); @@ -111,18 +113,18 @@ public class DMPDaoImpl extends DatabaseAccess implements DMPDao { @Override @Transactional - public DMP createOrUpdate(DMP item) { - return this.getDatabaseService().createOrUpdate(item, DMP.class); + public DmpEntity createOrUpdate(DmpEntity item) { + return this.getDatabaseService().createOrUpdate(item, DmpEntity.class); } @Override - public DMP find(UUID id) throws InvalidApplicationException { - return getDatabaseService().getQueryable(DMP.class).where((builder, root) -> builder.equal((root.get("id")), id)).getSingle(); + public DmpEntity find(UUID id) throws InvalidApplicationException { + return getDatabaseService().getQueryable(DmpEntity.class).where((builder, root) -> builder.equal((root.get("id")), id)).getSingle(); } @Override - public QueryableList getUserDmps(DatasetWizardUserDmpCriteria datasetWizardUserDmpCriteria, UserInfo userInfo) { - QueryableList query = getDatabaseService().getQueryable(DMP.class).where((builder, root) -> builder.or(builder.equal(root.get("creator"), userInfo), builder.isMember(userInfo, root.get("users")))); + public QueryableList getUserDmps(DatasetWizardUserDmpCriteria datasetWizardUserDmpCriteria, UserInfo userInfo) { + QueryableList query = getDatabaseService().getQueryable(DmpEntity.class).where((builder, root) -> builder.or(builder.equal(root.get("creator"), userInfo), builder.isMember(userInfo, root.get("users")))); if (datasetWizardUserDmpCriteria.getLike() != null && !datasetWizardUserDmpCriteria.getLike().isEmpty()) { query.where((builder, root) -> builder.like(root.get("label"), "%" + datasetWizardUserDmpCriteria.getLike() + "%")); } @@ -130,23 +132,23 @@ public class DMPDaoImpl extends DatabaseAccess implements DMPDao { } @Override - public void delete(DMP item) { + public void delete(DmpEntity item) { this.getDatabaseService().delete(item); } @Override - public QueryableList asQueryable() { - return this.getDatabaseService().getQueryable(DMP.class); + public QueryableList asQueryable() { + return this.getDatabaseService().getQueryable(DmpEntity.class); } @Async @Override - public CompletableFuture createOrUpdateAsync(DMP item) { + public CompletableFuture createOrUpdateAsync(DmpEntity item) { return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item)); } @Override - public DMP find(UUID id, String hint) { + public DmpEntity find(UUID id, String hint) { throw new UnsupportedOperationException(); } } 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 8d827d91a..f33ec23de 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 @@ -2,10 +2,10 @@ package eu.eudat.data.dao.entities; import eu.eudat.commons.enums.DescriptionStatus; import eu.eudat.commons.enums.IsActive; +import eu.eudat.data.DmpEntity; import eu.eudat.data.dao.DatabaseAccess; import eu.eudat.data.dao.criteria.DatasetCriteria; import eu.eudat.data.dao.databaselayer.service.DatabaseService; -import eu.eudat.data.old.DMP; import eu.eudat.data.DescriptionEntity; import eu.eudat.data.old.UserInfo; import eu.eudat.queryable.QueryableList; @@ -52,7 +52,7 @@ public class DatasetDaoImpl extends DatabaseAccess implements if (criteria.getPeriodStart() != null) query.where((builder, root) -> builder.greaterThan(root.get("created"), criteria.getPeriodStart())); if (!criteria.getAllVersions()) - query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"), query.subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.and(builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), builder1.notEqual(nestedRoot.get("dmp").get("status"), DMP.DMPStatus.DELETED.getValue())), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), Integer.class))); + query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"), query.subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.and(builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), builder1.notEqual(nestedRoot.get("dmp").get("isActive"), IsActive.Inactive.getValue())), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), Integer.class))); if (criteria.getGroupIds() != null && !criteria.getGroupIds().isEmpty()) query.where((builder, root) -> root.get("dmp").get("groupId").in(criteria.getGroupIds())); if (criteria.getDmpIds() != null && !criteria.getDmpIds().isEmpty()) @@ -92,7 +92,7 @@ public class DatasetDaoImpl extends DatabaseAccess implements query.where(((builder, root) -> root.get("id").in(ids))); if (!criteria.getAllVersions()) - query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"), query.subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.and(builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), builder1.notEqual(nestedRoot.get("dmp").get("status"), DMP.DMPStatus.DELETED.getValue())), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class))); + query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"), query.subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.and(builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), builder1.notEqual(nestedRoot.get("dmp").get("isActive"), IsActive.Inactive.getValue())), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class))); return query; } diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DmpDatasetProfileDao.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DmpDatasetProfileDao.java index 0cc7afc41..4f23ff7c0 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DmpDatasetProfileDao.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DmpDatasetProfileDao.java @@ -1,9 +1,10 @@ package eu.eudat.data.dao.entities; +import eu.eudat.data.DmpDescriptionTemplateEntity; import eu.eudat.data.dao.DatabaseAccessLayer; -import eu.eudat.data.old.DMPDatasetProfile; +import eu.eudat.model.DmpDescriptionTemplate; import java.util.UUID; -public interface DmpDatasetProfileDao extends DatabaseAccessLayer { +public interface DmpDatasetProfileDao extends DatabaseAccessLayer { } diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DmpDatasetProfileDaoImpl.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DmpDatasetProfileDaoImpl.java index 2f6bd7bb3..30336493b 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DmpDatasetProfileDaoImpl.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DmpDatasetProfileDaoImpl.java @@ -1,8 +1,9 @@ package eu.eudat.data.dao.entities; +import eu.eudat.data.DmpDescriptionTemplateEntity; import eu.eudat.data.dao.DatabaseAccess; import eu.eudat.data.dao.databaselayer.service.DatabaseService; -import eu.eudat.data.old.DMPDatasetProfile; +import eu.eudat.model.DmpDescriptionTemplate; import eu.eudat.queryable.QueryableList; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; @@ -13,40 +14,40 @@ import java.util.UUID; import java.util.concurrent.CompletableFuture; @Service("dmpDatasetProfileDao") -public class DmpDatasetProfileDaoImpl extends DatabaseAccess implements DmpDatasetProfileDao { +public class DmpDatasetProfileDaoImpl extends DatabaseAccess implements DmpDatasetProfileDao { @Autowired - public DmpDatasetProfileDaoImpl(DatabaseService databaseService) { + public DmpDatasetProfileDaoImpl(DatabaseService databaseService) { super(databaseService); } @Override - public DMPDatasetProfile createOrUpdate(DMPDatasetProfile item) { - return this.getDatabaseService().createOrUpdate(item, DMPDatasetProfile.class); + public DmpDescriptionTemplateEntity createOrUpdate(DmpDescriptionTemplateEntity item) { + return this.getDatabaseService().createOrUpdate(item, DmpDescriptionTemplateEntity.class); } @Override @Async - public CompletableFuture createOrUpdateAsync(DMPDatasetProfile item) { + public CompletableFuture createOrUpdateAsync(DmpDescriptionTemplateEntity item) { return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item)); } @Override - public DMPDatasetProfile find(UUID id) throws InvalidApplicationException { - return this.getDatabaseService().getQueryable(DMPDatasetProfile.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle(); + public DmpDescriptionTemplateEntity find(UUID id) throws InvalidApplicationException { + return this.getDatabaseService().getQueryable(DmpDescriptionTemplateEntity.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle(); } @Override - public DMPDatasetProfile find(UUID id, String hint) { + public DmpDescriptionTemplateEntity find(UUID id, String hint) { throw new UnsupportedOperationException(); } @Override - public void delete(DMPDatasetProfile item) { + public void delete(DmpDescriptionTemplateEntity item) { this.getDatabaseService().delete(item); } @Override - public QueryableList asQueryable() { - return this.getDatabaseService().getQueryable(DMPDatasetProfile.class); + public QueryableList asQueryable() { + return this.getDatabaseService().getQueryable(DmpDescriptionTemplateEntity.class); } } diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/GrantDaoImpl.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/GrantDaoImpl.java index ecf83ba4a..3fa6fed93 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/GrantDaoImpl.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/GrantDaoImpl.java @@ -1,9 +1,10 @@ package eu.eudat.data.dao.entities; +import eu.eudat.commons.enums.DmpStatus; +import eu.eudat.commons.enums.IsActive; import eu.eudat.data.dao.DatabaseAccess; import eu.eudat.data.dao.criteria.GrantCriteria; import eu.eudat.data.dao.databaselayer.service.DatabaseService; -import eu.eudat.data.old.DMP; import eu.eudat.data.old.Grant; import eu.eudat.data.old.UserInfo; import eu.eudat.queryable.QueryableList; @@ -51,11 +52,11 @@ public class GrantDaoImpl extends DatabaseAccess implements GrantDao { , builder.isNull(root.get("enddate")))); } if (criteria.isPublic()) { - query.where((builder, root) -> builder.equal(root.join("dmps").get("status"), DMP.DMPStatus.FINALISED.getValue())).distinct(); + query.where((builder, root) -> builder.equal(root.join("dmps").get("status"), DmpStatus.Finalized.getValue())).distinct(); } if (criteria.isActive()) { - query.where((builder, root) -> builder.notEqual(root.join("dmps").get("status"), DMP.DMPStatus.DELETED.getValue())).distinct(); + query.where((builder, root) -> builder.notEqual(root.join("dmps").get("isActive"), IsActive.Inactive.getValue())).distinct(); } if (criteria.getFunderId() != null && !criteria.getFunderId().trim().isEmpty()) query.where((builder, root) -> builder.equal(root.get("funder").get("id"), UUID.fromString(criteria.getFunderId()))); diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/OrganisationDaoImpl.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/OrganisationDaoImpl.java index 9ecf10190..d8a5de2de 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/OrganisationDaoImpl.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/OrganisationDaoImpl.java @@ -1,9 +1,10 @@ package eu.eudat.data.dao.entities; +import eu.eudat.commons.enums.DmpStatus; +import eu.eudat.commons.enums.IsActive; import eu.eudat.data.dao.DatabaseAccess; import eu.eudat.data.dao.criteria.OrganisationCriteria; import eu.eudat.data.dao.databaselayer.service.DatabaseService; -import eu.eudat.data.old.DMP; import eu.eudat.data.old.Organisation; import eu.eudat.data.old.UserInfo; import eu.eudat.queryable.QueryableList; @@ -37,12 +38,12 @@ public class OrganisationDaoImpl extends DatabaseAccess implements query.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + criteria.getLabelLike().toUpperCase() + "%")); } if (criteria.getPublic() != null && criteria.getPublic()) { - query.where((builder, root) -> builder.equal(root.join("dmps", JoinType.LEFT).get("status"), DMP.DMPStatus.FINALISED.getValue())); + query.where((builder, root) -> builder.equal(root.join("dmps", JoinType.LEFT).get("status"), DmpStatus.Finalized.getValue())); } } if (criteria.isActive()) { - query.where((builder, root) -> builder.notEqual(root.join("dmps").get("status"), DMP.DMPStatus.DELETED.getValue())).distinct(); + query.where((builder, root) -> builder.notEqual(root.join("dmps").get("isActive"), IsActive.Inactive.getValue())).distinct(); } return query; diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/UserDmpDao.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/UserDmpDao.java index 7d782ddb4..b403535ae 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/UserDmpDao.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/UserDmpDao.java @@ -1,12 +1,12 @@ package eu.eudat.data.dao.entities; +import eu.eudat.data.DmpUserEntity; import eu.eudat.data.dao.DatabaseAccessLayer; -import eu.eudat.data.old.UserDMP; import java.util.UUID; /** * Created by ikalyvas on 2/8/2018. */ -public interface UserDmpDao extends DatabaseAccessLayer { +public interface UserDmpDao extends DatabaseAccessLayer { } diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/UserDmpDaoImpl.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/UserDmpDaoImpl.java index b5d7fd947..0ba524661 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/UserDmpDaoImpl.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/UserDmpDaoImpl.java @@ -1,8 +1,8 @@ package eu.eudat.data.dao.entities; +import eu.eudat.data.DmpUserEntity; import eu.eudat.data.dao.DatabaseAccess; import eu.eudat.data.dao.databaselayer.service.DatabaseService; -import eu.eudat.data.old.UserDMP; import eu.eudat.queryable.QueryableList; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; @@ -16,41 +16,41 @@ import java.util.concurrent.CompletableFuture; * Created by ikalyvas on 2/8/2018. */ @Component("userDmpDao") -public class UserDmpDaoImpl extends DatabaseAccess implements UserDmpDao { +public class UserDmpDaoImpl extends DatabaseAccess implements UserDmpDao { @Autowired - public UserDmpDaoImpl(DatabaseService databaseService) { + public UserDmpDaoImpl(DatabaseService databaseService) { super(databaseService); } @Override - public UserDMP createOrUpdate(UserDMP item) { - return this.getDatabaseService().createOrUpdate(item, UserDMP.class); + public DmpUserEntity createOrUpdate(DmpUserEntity item) { + return this.getDatabaseService().createOrUpdate(item, DmpUserEntity.class); } @Override - public UserDMP find(UUID id) throws InvalidApplicationException { - return this.getDatabaseService().getQueryable(UserDMP.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingleOrDefault(); + public DmpUserEntity find(UUID id) throws InvalidApplicationException { + return this.getDatabaseService().getQueryable(DmpUserEntity.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingleOrDefault(); } @Override - public void delete(UserDMP item) { + public void delete(DmpUserEntity item) { this.getDatabaseService().delete(item); } @Override - public QueryableList asQueryable() { - return this.getDatabaseService().getQueryable(UserDMP.class); + public QueryableList asQueryable() { + return this.getDatabaseService().getQueryable(DmpUserEntity.class); } @Async @Override - public CompletableFuture createOrUpdateAsync(UserDMP item) { + public CompletableFuture createOrUpdateAsync(DmpUserEntity item) { return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item)); } @Override - public UserDMP find(UUID id, String hint) { + public DmpUserEntity find(UUID id, String hint) { throw new UnsupportedOperationException(); } } diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/query/items/item/dataset/DatasetWizardAutocompleteRequest.java b/dmp-backend/data/src/main/java/eu/eudat/data/query/items/item/dataset/DatasetWizardAutocompleteRequest.java index 123c962b3..9cb1687db 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/query/items/item/dataset/DatasetWizardAutocompleteRequest.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/query/items/item/dataset/DatasetWizardAutocompleteRequest.java @@ -1,14 +1,14 @@ package eu.eudat.data.query.items.item.dataset; +import eu.eudat.data.DmpEntity; import eu.eudat.data.dao.criteria.DatasetWizardUserDmpCriteria; -import eu.eudat.data.old.DMP; import eu.eudat.data.query.definition.Query; import eu.eudat.queryable.QueryableList; -public class DatasetWizardAutocompleteRequest extends Query { +public class DatasetWizardAutocompleteRequest extends Query { @Override - public QueryableList applyCriteria() { - QueryableList query = this.getQuery().where((builder, root) -> builder.or(builder.equal(root.get("creator"), this.getCriteria().getUserInfo()), builder.isMember(this.getCriteria().getUserInfo(), root.get("users")))); + public QueryableList applyCriteria() { + QueryableList query = this.getQuery().where((builder, root) -> builder.or(builder.equal(root.get("creator"), this.getCriteria().getUserInfo()), builder.isMember(this.getCriteria().getUserInfo(), root.get("users")))); if (this.getCriteria().getLike() != null && !this.getCriteria().getLike().isEmpty()) { query.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + this.getCriteria().getLike().toUpperCase() + "%")); } diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/query/items/item/dmp/DataManagementPlanCriteriaRequest.java b/dmp-backend/data/src/main/java/eu/eudat/data/query/items/item/dmp/DataManagementPlanCriteriaRequest.java index 126bc5e84..511012538 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/query/items/item/dmp/DataManagementPlanCriteriaRequest.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/query/items/item/dmp/DataManagementPlanCriteriaRequest.java @@ -1,7 +1,8 @@ package eu.eudat.data.query.items.item.dmp; +import eu.eudat.commons.enums.IsActive; +import eu.eudat.data.DmpEntity; import eu.eudat.data.dao.criteria.DataManagementPlanCriteria; -import eu.eudat.data.old.DMP; import eu.eudat.data.query.definition.Query; import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.types.FieldSelectionType; @@ -9,10 +10,10 @@ import eu.eudat.queryable.types.SelectionField; import java.util.Arrays; -public class DataManagementPlanCriteriaRequest extends Query { +public class DataManagementPlanCriteriaRequest extends Query { @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() + "%"), @@ -27,7 +28,7 @@ public class DataManagementPlanCriteriaRequest extends Query builder.equal(root.get("version"), query.subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("groupId"), nestedRoot.get("groupId")), Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "version")), String.class))); if (this.getCriteria().getGroupIds() != null && !this.getCriteria().getGroupIds().isEmpty()) query.where((builder, root) -> root.get("groupId").in(this.getCriteria().getGroupIds())); - query.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue())); + query.where((builder, root) -> builder.notEqual(root.get("isActive"), IsActive.Inactive.getValue())); return query; } } diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/query/items/table/dmp/DataManagementPlanTableRequest.java b/dmp-backend/data/src/main/java/eu/eudat/data/query/items/table/dmp/DataManagementPlanTableRequest.java index 597bd4c4b..feeba453d 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/query/items/table/dmp/DataManagementPlanTableRequest.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/query/items/table/dmp/DataManagementPlanTableRequest.java @@ -1,7 +1,8 @@ package eu.eudat.data.query.items.table.dmp; +import eu.eudat.commons.enums.IsActive; +import eu.eudat.data.DmpEntity; import eu.eudat.data.dao.criteria.DataManagementPlanCriteria; -import eu.eudat.data.old.DMP; import eu.eudat.data.query.PaginationService; import eu.eudat.data.query.definition.TableQuery; import eu.eudat.queryable.QueryableList; @@ -11,10 +12,10 @@ import eu.eudat.queryable.types.SelectionField; import java.util.Arrays; import java.util.UUID; -public class DataManagementPlanTableRequest extends TableQuery { +public class DataManagementPlanTableRequest 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() + "%"), @@ -29,12 +30,12 @@ public class DataManagementPlanTableRequest extends TableQuery builder.equal(root.get("version"), query.subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("groupId"), nestedRoot.get("groupId")), Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "version")), String.class))); if (this.getCriteria().getGroupIds() != null && !this.getCriteria().getGroupIds().isEmpty()) query.where((builder, root) -> root.get("groupId").in(this.getCriteria().getGroupIds())); - query.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue())); + query.where((builder, root) -> builder.notEqual(root.get("isActive"), IsActive.Inactive.getValue())); return query; } @Override - public QueryableList applyPaging(QueryableList items) { + public QueryableList applyPaging(QueryableList items) { return PaginationService.applyPaging(items, this); } } diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/query/items/table/dmp/DataManagmentPlanPublicTableRequest.java b/dmp-backend/data/src/main/java/eu/eudat/data/query/items/table/dmp/DataManagmentPlanPublicTableRequest.java index e296f8798..a585af283 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/query/items/table/dmp/DataManagmentPlanPublicTableRequest.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/query/items/table/dmp/DataManagmentPlanPublicTableRequest.java @@ -1,7 +1,7 @@ package eu.eudat.data.query.items.table.dmp; +import eu.eudat.data.DmpEntity; import eu.eudat.data.dao.criteria.DataManagementPlanPublicCriteria; -import eu.eudat.data.old.DMP; import eu.eudat.data.query.PaginationService; import eu.eudat.data.query.definition.TableQuery; import eu.eudat.queryable.QueryableList; @@ -13,10 +13,10 @@ import java.util.Arrays; import java.util.Date; import java.util.UUID; -public class DataManagmentPlanPublicTableRequest extends TableQuery { +public class DataManagmentPlanPublicTableRequest extends TableQuery { - public QueryableList applyCriteria() { - QueryableList query = this.getQuery(); + public QueryableList applyCriteria() { + QueryableList query = this.getQuery(); query.where((builder, root) -> builder.equal(root.get("isPublic"), true)); if (this.getCriteria().getLike() != null && !this.getCriteria().getLike().isEmpty()) query.where((builder, root) -> builder.or( @@ -48,7 +48,7 @@ public class DataManagmentPlanPublicTableRequest extends TableQuery applyPaging(QueryableList items) { + public QueryableList applyPaging(QueryableList items) { return PaginationService.applyPaging(items, this); } } 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 208acaac8..de94fb815 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 @@ -1,7 +1,7 @@ package eu.eudat.query; +import eu.eudat.data.DmpEntity; import eu.eudat.data.dao.DatabaseAccessLayer; -import eu.eudat.data.old.DMP; import eu.eudat.data.DescriptionEntity; import eu.eudat.data.old.Grant; import eu.eudat.data.old.UserInfo; @@ -17,7 +17,7 @@ import java.util.Date; import java.util.List; import java.util.UUID; -public class DMPQuery extends Query { +public class DMPQuery extends Query { private UUID id; private UUID groupId; private String label; @@ -29,11 +29,11 @@ public class DMPQuery extends Query { private Date created; private Date modified; - public DMPQuery(DatabaseAccessLayer databaseAccessLayer) { + public DMPQuery(DatabaseAccessLayer databaseAccessLayer) { super(databaseAccessLayer); } - public DMPQuery(DatabaseAccessLayer databaseAccessLayer, List selectionFields) { + public DMPQuery(DatabaseAccessLayer databaseAccessLayer, List selectionFields) { super(databaseAccessLayer, selectionFields); } @@ -117,8 +117,8 @@ public class DMPQuery extends Query { this.datasetQuery = datasetQuery; } - 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/data/src/main/java/eu/eudat/query/DatasetQuery.java b/dmp-backend/data/src/main/java/eu/eudat/query/DatasetQuery.java index 0667f77e9..8775eb676 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 @@ -1,7 +1,7 @@ package eu.eudat.query; +import eu.eudat.data.DmpEntity; import eu.eudat.data.dao.DatabaseAccessLayer; -import eu.eudat.data.old.DMP; import eu.eudat.data.DescriptionEntity; import eu.eudat.queryable.QueryableList; import eu.eudat.queryable.types.FieldSelectionType; @@ -59,7 +59,7 @@ public class DatasetQuery extends Query { query.where((builder, root) -> builder.equal(root.get("id"), this.id)); } if (this.dmpQuery != null) { - Subquery dmpSubQuery = this.dmpQuery.getQuery().query(Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "id"))); + Subquery dmpSubQuery = this.dmpQuery.getQuery().query(Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "id"))); query.where((builder, root) -> root.get("dmp").get("id").in(dmpSubQuery)); } return query; 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 224225f93..12f6fb4bd 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 @@ -4,9 +4,9 @@ package eu.eudat.controllers; import eu.eudat.authorization.Permission; import eu.eudat.configurations.dynamicgrant.DynamicGrantConfiguration; import eu.eudat.criteria.DMPCriteria; +import eu.eudat.data.DmpEntity; import eu.eudat.data.dao.criteria.DynamicFieldsCriteria; import eu.eudat.data.dao.criteria.RequestItem; -import eu.eudat.data.old.DMP; import eu.eudat.data.DescriptionEntity; import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem; import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest; @@ -248,8 +248,8 @@ public class DMPs extends BaseController { public @ResponseBody ResponseEntity> createOrUpdate(@RequestBody eu.eudat.models.data.dmp.DataManagementPlanEditorModel dataManagementPlanEditorModel) throws Exception { this.authorizationService.authorizeForce(Permission.AuthenticatedRole); - - DMP dmp = this.dataManagementPlanManager.createOrUpdate(dataManagementPlanEditorModel); + + DmpEntity dmp = this.dataManagementPlanManager.createOrUpdate(dataManagementPlanEditorModel); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created").payload(new eu.eudat.models.data.dmp.DataManagementPlan().fromDataModel(dmp))); } @@ -258,8 +258,8 @@ public class DMPs extends BaseController { public @ResponseBody ResponseEntity> createOrUpdateWithDatasets(@RequestBody eu.eudat.models.data.dmp.DataManagementPlanEditorModel dataManagementPlanEditorModel) throws Exception { this.authorizationService.authorizeForce(Permission.AuthenticatedRole); - - DMP dmp = this.dataManagementPlanManager.createOrUpdateWithDatasets(dataManagementPlanEditorModel); + + DmpEntity dmp = this.dataManagementPlanManager.createOrUpdateWithDatasets(dataManagementPlanEditorModel); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created").payload(dmp.getId())); } @@ -286,14 +286,14 @@ public class DMPs extends BaseController { @RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json") public @ResponseBody - ResponseEntity> delete(@PathVariable UUID id) { + ResponseEntity> delete(@PathVariable UUID id) { this.authorizationService.authorizeForce(Permission.AuthenticatedRole); try { this.dataManagementPlanManager.delete(id); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Deleted Datamanagement Plan")); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Deleted Datamanagement Plan")); } catch (DMPWithDatasetsDeleteException | IOException | InvalidApplicationException exception) { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage())); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage())); } } @@ -313,55 +313,55 @@ public class DMPs extends BaseController { } @RequestMapping(method = RequestMethod.GET, value = {"/makepublic/{id}"}) - public ResponseEntity> makePublic(@PathVariable String id) { + public ResponseEntity> makePublic(@PathVariable String id) { this.authorizationService.authorizeForce(Permission.AuthenticatedRole); try { this.dataManagementPlanManager.makePublic(UUID.fromString(id)); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Data Datamanagement Plan made public.")); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Data Datamanagement Plan made public.")); } catch (Exception e) { logger.error(e.getMessage(), e); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to make Data Management Plan public.")); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to make Data Management Plan public.")); } } @RequestMapping(method = RequestMethod.POST, value = {"/finalize/{id}"}) - public ResponseEntity> makeFinalize(@PathVariable String id, @RequestBody DatasetsToBeFinalized datasetsToBeFinalized) { + public ResponseEntity> makeFinalize(@PathVariable String id, @RequestBody DatasetsToBeFinalized datasetsToBeFinalized) { this.authorizationService.authorizeForce(Permission.AuthenticatedRole); try { this.dataManagementPlanManager.makeFinalize(UUID.fromString(id), datasetsToBeFinalized); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Data Datamanagement Plan made finalized.")); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Data Datamanagement Plan made finalized.")); } catch (Exception e) { logger.error(e.getMessage(), e); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to finalize Data Management Plan.")); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to finalize Data Management Plan.")); } } @RequestMapping(method = RequestMethod.POST, value = {"/unfinalize/{id}"}) - public ResponseEntity> undoFinalize(@PathVariable String id) { + public ResponseEntity> undoFinalize(@PathVariable String id) { this.authorizationService.authorizeForce(Permission.AuthenticatedRole); try { this.dataManagementPlanManager.undoFinalize(UUID.fromString(id)); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Data Datamanagement Plan made active.")); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Data Datamanagement Plan made active.")); } catch (Exception e) { logger.error(e.getMessage(), e); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to unfinalize the Data Management Plan.")); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to unfinalize the Data Management Plan.")); } } @RequestMapping(method = RequestMethod.POST, value = {"/updateusers/{id}"}) - public ResponseEntity> updateUsers(@PathVariable String id, @RequestBody List users) { + public ResponseEntity> updateUsers(@PathVariable String id, @RequestBody List users) { this.authorizationService.authorizeForce(Permission.AuthenticatedRole); try { this.dataManagementPlanManager.updateUsers(UUID.fromString(id), users); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Updated Colaborators for Data Datamanagement Plan.")); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Updated Colaborators for Data Datamanagement Plan.")); } catch (Exception e) { logger.error(e.getMessage(), e); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to update the users of Data Management Plan.")); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to update the users of Data Management Plan.")); } } 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 a1e9f3cde..1fb4b5dc1 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 @@ -3,6 +3,7 @@ package eu.eudat.controllers; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.Permission; import eu.eudat.commons.XmlHandlingService; +import eu.eudat.commons.enums.DmpAccessType; import eu.eudat.commons.enums.FieldType; import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.scope.user.UserScope; @@ -11,7 +12,7 @@ import eu.eudat.commons.types.descriptiontemplate.FieldEntity; import eu.eudat.commons.types.descriptiontemplate.fielddata.UploadDataEntity; import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DescriptionTemplateEntity; -import eu.eudat.data.old.DMP; +import eu.eudat.data.DmpEntity; import eu.eudat.data.old.FileUpload; import eu.eudat.exceptions.security.UnauthorisedException; import eu.eudat.logic.managers.DatasetProfileManager; @@ -145,11 +146,14 @@ public class FileController { throw new NoSuchElementException("No dataset with id " + fileUpload.getEntityId() + " found. This dataset was related to the file with id " + id); } - DMP dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId()); + DmpEntity dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId()); - if (!dmp.isPublic() && dmp.getUsers() - .stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())) - .collect(Collectors.toList()).size() == 0) + if (!dmp.getAccessType().equals(DmpAccessType.Public) + //TODO +// && dmp.getUsers() +// .stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())) +// .collect(Collectors.toList()).size() == 0 + ) throw new UnauthorisedException(); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/QuickWizardController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/QuickWizardController.java index a4ca63488..966469ab4 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/QuickWizardController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/QuickWizardController.java @@ -4,7 +4,7 @@ package eu.eudat.controllers; import eu.eudat.authorization.Permission; import eu.eudat.commons.scope.user.UserScope; import eu.eudat.data.DescriptionTemplateEntity; -import eu.eudat.data.old.DMP; +import eu.eudat.data.DmpEntity; import eu.eudat.data.old.Funder; import eu.eudat.data.old.Project; import eu.eudat.data.old.Grant; @@ -90,7 +90,7 @@ public class QuickWizardController extends BaseController { //Create Dmp DataManagementPlan dataManagementPlan = quickWizard.getDmp().toDataDmp(grantEntity, projectEntity, userScope); - DMP dmpEntity = this.quickWizardManager.createOrUpdate(dataManagementPlan, funderEntity); + DmpEntity dmpEntity = this.quickWizardManager.createOrUpdate(dataManagementPlan, funderEntity); //Create Datasets quickWizard.getDmp().setId(dmpEntity.getId()); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/builders/entity/UserInfoBuilder.java b/dmp-backend/web/src/main/java/eu/eudat/logic/builders/entity/UserInfoBuilder.java index 0ab2ff17e..9fbc85e8c 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/builders/entity/UserInfoBuilder.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/builders/entity/UserInfoBuilder.java @@ -1,8 +1,8 @@ package eu.eudat.logic.builders.entity; import eu.eudat.data.CredentialEntity; +import eu.eudat.data.DmpEntity; import eu.eudat.logic.builders.Builder; -import eu.eudat.data.old.DMP; import eu.eudat.data.old.UserInfo; import eu.eudat.data.old.UserRole; @@ -34,7 +34,7 @@ public class UserInfoBuilder extends Builder { private String additionalinfo; - private Set dmps; + private Set dmps; private Set credentials = new HashSet<>(); @@ -87,7 +87,7 @@ public class UserInfoBuilder extends Builder { return this; } - public UserInfoBuilder dmps(Set dmps) { + public UserInfoBuilder dmps(Set dmps) { this.dmps = dmps; return this; } @@ -120,7 +120,7 @@ public class UserInfoBuilder extends Builder { userInfo.setAdditionalinfo(additionalinfo); userInfo.setUserRoles(userRoles); userInfo.setCredentials(credentials); - userInfo.setDmps(dmps); +// userInfo.setDmps(dmps); //TODO userInfo.setVerified_email(verified_email); userInfo.setUserStatus(userStatus); return userInfo; 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 1a60cd271..52c057799 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 @@ -3,6 +3,7 @@ package eu.eudat.logic.managers; import eu.eudat.commons.enums.DescriptionStatus; import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.scope.user.UserScope; +import eu.eudat.data.DmpEntity; import eu.eudat.data.dao.criteria.DataManagementPlanCriteria; import eu.eudat.data.dao.criteria.DatasetCriteria; import eu.eudat.data.dao.criteria.GrantCriteria; @@ -11,7 +12,6 @@ import eu.eudat.data.dao.entities.DMPDao; import eu.eudat.data.dao.entities.DatasetDao; import eu.eudat.data.dao.entities.GrantDao; import eu.eudat.data.dao.entities.OrganisationDao; -import eu.eudat.data.old.DMP; import eu.eudat.data.DescriptionEntity; import eu.eudat.data.old.Grant; import eu.eudat.data.old.UserInfo; @@ -86,7 +86,7 @@ public class DashBoardManager { publicCriteria.setOnlyPublic(true); publicCriteria.setAllVersions(false); - List dmps = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(publicCriteria).toList(); + List dmps = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(publicCriteria).toList(); // DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria(); OrganisationCriteria organisationCriteria = new OrganisationCriteria(); @@ -97,12 +97,12 @@ public class DashBoardManager { // List dmps = databaseRepository.getDmpDao().getWithCriteria(dataManagementPlanCriteria).toList(); long numberOfDatasets = 0; LinkedList grants = new LinkedList<>(); - for (DMP dmp : dmps) { - numberOfDatasets = numberOfDatasets + dmp.getDataset().stream() - .filter(item -> item.getStatus() == DescriptionStatus.Finalized).count(); - if (dmp.getGrant() != null) { - grants.add(dmp.getGrant()); - } + for (DmpEntity dmp : dmps) { +// numberOfDatasets = numberOfDatasets + dmp.getDataset().stream() //TODO +// .filter(item -> item.getStatus() == DescriptionStatus.Finalized).count(); +// if (dmp.getGrant() != null) { +// grants.add(dmp.getGrant()); +// } } statistics.setTotalDataManagementPlanCount((long) dmps.size()); @@ -201,7 +201,7 @@ public class DashBoardManager { .withHint("dmpRecentActivity") .orderBy((builder, root) -> builder.desc(root.get("modified"))) .take(numberofactivities) - .selectAsync(item -> recentActivityDataBuilder.label(item.getLabel()).timestamp(item.getModified()).id(item.getId().toString()).build()) + .selectAsync(item -> recentActivityDataBuilder.label(item.getLabel()).timestamp(Date.from(item.getUpdatedAt())).id(item.getId().toString()).build()) .whenComplete((dmpActivities, throwable) -> activity.setRecentDmpActivities(dmpActivities)); CompletableFuture> datasets = datasetRepository.getAuthenticated(datasetRepository.getWithCriteria(datasetCriteria), user, roles).distinct() @@ -311,7 +311,7 @@ public class DashBoardManager { CompletableFuture> publicDmps = dataManagementPlanRepository.asQueryable() .where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%")) - .where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue())) + .where((builder, root) -> builder.notEqual(root.get("isActive"), IsActive.Inactive)) .where((builder, root) -> builder.equal(root.get("isPublic"), true)) .orderBy((builder, root) -> builder.desc(root.get("modified"))) .selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.DMP.getValue(), true)) @@ -329,7 +329,7 @@ public class DashBoardManager { CompletableFuture> dmps = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.asQueryable(), this.userScope.getUserId(), roles) .withHint("dmpRecentActivity") .where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%")) - .where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue())) + .where((builder, root) -> builder.notEqual(root.get("isActive"), IsActive.Inactive)) .orderBy((builder, root) -> builder.desc(root.get("modified"))) .selectAsync(item -> new SearchBarItem(item.getId().toString(), item.getLabel(), SearchBarItemType.DMP.getValue(), false)) .whenComplete((dmpItems, throwable) -> searchBarItems.addAll(dmpItems)); 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 4d18533f9..592723eb1 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 @@ -2,19 +2,16 @@ package eu.eudat.logic.managers; 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.types.dmpblueprint.*; +import eu.eudat.commons.types.dmpblueprint.DescriptionTemplateEntity; 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.*; import eu.eudat.data.dao.criteria.*; import eu.eudat.data.dao.entities.*; -import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.old.*; import eu.eudat.data.old.Researcher; import eu.eudat.commons.enums.old.notification.ActiveStatus; @@ -156,8 +153,8 @@ public class DataManagementPlanManager { public DataTableData getPaged(DataManagementPlanTableRequest dataManagementPlanTableRequest, String fieldsGroup) throws Exception { UUID principalID = userScope.getUserIdSafe(); // List dmps = null; - QueryableList items = null; - QueryableList authItems = null; + QueryableList items = null; + QueryableList authItems = null; Long totalData = 0L; // if (apiContext.getOperationsContext().getElasticRepository().getDmpRepository() != null) { //TODO // try { @@ -203,7 +200,7 @@ public class DataManagementPlanManager { if (fieldsGroup.equals("listing")) { if (!dataManagementPlanTableRequest.getCriteria().isOnlyPublic()) { - List dmps1 = items.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class)) + List dmps1 = items.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class)) .distinct().toList(); dataTable.setData(dmps1.stream().map(dmp -> { DatasetCriteria datasetCriteria = new DatasetCriteria(); @@ -211,11 +208,11 @@ public class DataManagementPlanManager { datasetCriteria.setAllVersions(dataManagementPlanTableRequest.getCriteria().getAllVersions()); datasetCriteria.setIsPublic(dataManagementPlanTableRequest.getCriteria().getIsPublic()); datasetCriteria.setGroupIds(Collections.singletonList(dmp.getGroupId())); - try { - dmp.setDataset(retrieveRelevantDatasets(datasetCriteria, principalID)); - } catch (InvalidApplicationException e) { - throw new RuntimeException(e); - } +// try { //TODO +// dmp.setDataset(retrieveRelevantDatasets(datasetCriteria, principalID)); +// } catch (InvalidApplicationException e) { +// throw new RuntimeException(e); +// } return new DataManagementPlanListingModel().fromDataModelDatasets(dmp); @@ -232,7 +229,7 @@ public class DataManagementPlanManager { }) .whenComplete((resultList, throwable) -> dataTable.setData(resultList));*/ } else { - List dmps1 = items.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class)) + List dmps1 = items.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class)) .distinct().toList(); dataTable.setData(dmps1.stream().map(dmp -> { DatasetCriteria datasetCriteria = new DatasetCriteria(); @@ -240,11 +237,11 @@ public class DataManagementPlanManager { datasetCriteria.setIsPublic(true); datasetCriteria.setAllVersions(dataManagementPlanTableRequest.getCriteria().getAllVersions()); datasetCriteria.setGroupIds(Collections.singletonList(dmp.getGroupId())); - try { - dmp.setDataset(retrieveRelevantDatasets(datasetCriteria)); - } catch (InvalidApplicationException e) { - throw new RuntimeException(e); - } +// try { //TODO +// dmp.setDataset(retrieveRelevantDatasets(datasetCriteria)); +// } catch (InvalidApplicationException e) { +// throw new RuntimeException(e); +// } return new DataManagementPlanListingModel().fromDataModelDatasets(dmp); @@ -310,14 +307,15 @@ public class DataManagementPlanManager { public eu.eudat.models.data.dmp.DataManagementPlan getSingle(String id, boolean isPublic, boolean includeDatasets) throws Exception { eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = new eu.eudat.models.data.dmp.DataManagementPlan(); - DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id)); + DmpEntity dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id)); if (!isPublic && !this.userScope.isSet()) { throw new UnauthorisedException(); - } else if (!isPublic && (dataManagementPlanEntity.getUsers().stream().noneMatch(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())))) { - if (!dataManagementPlanEntity.isPublic()) { + //TODO + } else if (!isPublic /*&& (dataManagementPlanEntity.getUsers().stream().noneMatch(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())))*/ ) { + if (!dataManagementPlanEntity.getAccessType().equals(DmpAccessType.Public)) { throw new UnauthorisedException(); } - } else if (isPublic && !dataManagementPlanEntity.isPublic()) { + } else if (isPublic && !dataManagementPlanEntity.getAccessType().equals(DmpAccessType.Public)) { throw new ForbiddenException("Selected DMP is not public"); } if (includeDatasets) { @@ -348,7 +346,7 @@ public class DataManagementPlanManager { } else { dataManagementPlan.fromDataModelNoDatasets(dataManagementPlanEntity); } - Map dmpProperties = dataManagementPlanEntity.getDmpProperties() != null ? new org.json.JSONObject(dataManagementPlanEntity.getDmpProperties()).toMap() : null; + Map dmpProperties = new HashMap();//TODO dataManagementPlanEntity.getDmpProperties() != null ? new org.json.JSONObject(dataManagementPlanEntity.getDmpProperties()).toMap() : null; if (dmpProperties != null && dataManagementPlan.getDynamicFields() != null) dataManagementPlan.getDynamicFields().forEach(item -> { @@ -360,17 +358,18 @@ public class DataManagementPlanManager { } public DataManagementPlanOverviewModel getOverviewSingle(String id, boolean isPublic) throws Exception { - DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id)); - if (dataManagementPlanEntity.getStatus() == DMP.DMPStatus.DELETED.getValue()) { + DmpEntity dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id)); + if (dataManagementPlanEntity.getIsActive().equals(IsActive.Inactive)) { throw new Exception("DMP is deleted."); } if (!isPublic && !this.userScope.isSet()) { throw new UnauthorisedException(); } else - if (!isPublic && dataManagementPlanEntity.getUsers() - .stream().noneMatch(userInfo -> userInfo.getUser().getId().equals(this.userScope.getUserIdSafe()))) { + if (!isPublic //&& dataManagementPlanEntity.getUsers() //TODO + // .stream().noneMatch(userInfo -> userInfo.getUser().getId().equals(this.userScope.getUserIdSafe())) + ) { throw new UnauthorisedException(); - } else if (isPublic && !dataManagementPlanEntity.isPublic()) { + } else if (isPublic && !dataManagementPlanEntity.getAccessType().equals(DmpAccessType.Public)) { throw new ForbiddenException("Selected DMP is not public"); } DataManagementPlanOverviewModel datamanagementPlan = new DataManagementPlanOverviewModel(); @@ -430,7 +429,7 @@ public class DataManagementPlanManager { datasetProfileTableRequestItem.getCriteria().setFilter(DatasetProfileCriteria.DatasetProfileFilter.DMPs.getValue()); datasetProfileTableRequestItem.getCriteria().setUserId(this.userScope.getUserId()); - QueryableList items = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().getWithCriteria(datasetProfileTableRequestItem.getCriteria()); + QueryableList items = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().getWithCriteria(datasetProfileTableRequestItem.getCriteria()); List listingModels = items.select(item -> new DatasetProfileListingModel().fromDataModel(item)); DataTableData data = new DataTableData<>(); @@ -443,8 +442,8 @@ public class DataManagementPlanManager { public List getAllVersions(String groupId, Boolean isPublic) throws InvalidApplicationException { UUID principalId = this.userScope.getUserIdSafe(); List versions = new ArrayList<>(); - QueryableList items = null; - QueryableList authItems = null; + QueryableList items = null; + QueryableList authItems = null; List roles = new LinkedList<>(); DataManagementPlanCriteria criteria = new DataManagementPlanCriteria(); criteria.setGroupIds(Collections.singletonList(UUID.fromString(groupId))); @@ -472,13 +471,13 @@ public class DataManagementPlanManager { * */ @Transactional - public DMP createOrUpdate(DataManagementPlanEditorModel dataManagementPlan) throws Exception { + public DmpEntity createOrUpdate(DataManagementPlanEditorModel dataManagementPlan) throws Exception { boolean setNotification = false; if (dataManagementPlan.getId() != null) { - DMP dmp1 = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(dataManagementPlan.getId()); + DmpEntity dmp1 = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(dataManagementPlan.getId()); - Instant dbTime = Instant.ofEpochMilli(dmp1.getModified().getTime()).truncatedTo(ChronoUnit.SECONDS); - Instant modelTime = Instant.ofEpochMilli(dataManagementPlan.getModified().getTime()).truncatedTo(ChronoUnit.SECONDS); + Instant dbTime = dmp1.getUpdatedAt().truncatedTo(ChronoUnit.SECONDS); + Instant modelTime = dmp1.getUpdatedAt().truncatedTo(ChronoUnit.SECONDS); if (!isUserOwnerOfDmp(dmp1)) { throw new Exception("User not being the creator is not authorized to edit this DMP."); @@ -486,12 +485,15 @@ public class DataManagementPlanManager { if (dbTime.toEpochMilli() != modelTime.toEpochMilli()) { throw new Exception("Another user have already edit that DMP."); } - List descriptionEntityList = dmp1.getDataset().stream().filter(dataset -> dataset.getIsActive() != IsActive.Inactive).collect(Collectors.toList()); + DatasetCriteria datasetCriteria = new DatasetCriteria(); + datasetCriteria.setDmpIds(List.of(dmp1.getId())); + + List descriptionEntityList = this.databaseRepository.getDatasetDao().getWithCriteria(datasetCriteria).toList().stream().filter(dataset -> dataset.getIsActive() != IsActive.Inactive).collect(Collectors.toList()); for (DescriptionEntity descriptionEntity : descriptionEntityList) { if (dataManagementPlan.getProfiles().stream().filter(associatedProfile -> this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId().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())) + if (dataManagementPlan.getStatus() == DmpStatus.Finalized.getValue() && dmp1.getStatus().equals(DmpStatus.Finalized.getValue() )) throw new Exception("DMP is finalized, therefore cannot be edited."); setNotification = true; @@ -499,94 +501,97 @@ public class DataManagementPlanManager { metricsManager.increaseValue(MetricNames.DMP, 1, MetricNames.DRAFT); } - DMP newDmp = dataManagementPlan.toDataModel(); + DmpEntity newDmp = dataManagementPlan.toDataModel(); if(dataManagementPlan.getProfile() != null){ - DmpBlueprintEntity dmpBlueprint = this.queryFactory.query(DmpBlueprintQuery.class).ids(dataManagementPlan.getProfile().getId()).first(); - newDmp.setProfile(dmpBlueprint); + newDmp.setBlueprint(dataManagementPlan.getProfile().getId()); } - if (newDmp.getStatus() == (int) DMP.DMPStatus.FINALISED.getValue()) { + if (newDmp.getStatus().equals(DmpStatus.Finalized)) { checkDmpValidationRules(newDmp); } UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId()); - newDmp.setCreator(user); + newDmp.setCreator(user.getId()); + DmpBlueprintEntity dmpBlueprint = this.queryFactory.query(DmpBlueprintQuery.class).ids(newDmp.getBlueprint()).first(); - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Organizations)) { + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Organizations)) { createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao()); } - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Researchers)) { + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Researchers)) { createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao(), user); } - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Funder)) { + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Funder)) { createFunderIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getFunderDao()); } - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Grant)) { createGrantIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao()); - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Project)) { - if (newDmp.getProject() != null && newDmp.getGrant() != null && (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty())) { - newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant())); - } + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Project)) { +// if (newDmp.getProject() != null && newDmp.getGrant() != null && (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty())) { //TODO +// newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant())); +// } createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao()); } } - DMP dmp; + DmpEntity dmp; if (dataManagementPlan.getId() != null) { dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(dataManagementPlan.getId()); - } else dmp = new DMP(); + } else dmp = new DmpEntity(); - newDmp.setCreated(dmp.getCreated() == null ? new Date() : dmp.getCreated()); - if (newDmp.getUsers()!= null && newDmp.getUsers().stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())) + newDmp.setCreatedAt(dmp.getCreatedAt() == null ? Instant.now() : dmp.getCreatedAt()); + DmpEntity finalNewDmp = newDmp; + this.databaseRepository.getUserDmpDao().asQueryable().where((builder, root) -> root.get("dmp").in(finalNewDmp.getId())).toList(); + if (this.databaseRepository.getUserDmpDao().asQueryable().where((builder, root) -> root.get("dmp").in(finalNewDmp.getId())).toList()!= null && + this.databaseRepository.getUserDmpDao().asQueryable().where((builder, root) -> root.get("dmp").in(finalNewDmp.getId())).toList().stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser())) .collect(Collectors.toList()).size() == 0) { - List userDMPList = new ArrayList<>(newDmp.getUsers()); + List userDMPList = new ArrayList<>(this.databaseRepository.getUserDmpDao().asQueryable().where((builder, root) -> root.get("dmp").in(finalNewDmp.getId())).toList()); for (UserInfoListingModel userInfoListingModel : dataManagementPlan.getUsers()) { - for (UserDMP userDMP : userDMPList) { - if (!(userDMP.getUser().getId().equals(userInfoListingModel.getId()))) { + for (DmpUserEntity userDMP : userDMPList) { + if (!(userDMP.getUser().equals(userInfoListingModel.getId()))) { apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().delete(userDMP); } } } } - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { - if (newDmp.getGrant() != null && newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) { - checkIfUserCanEditGrant(newDmp, user); - } + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Grant)) { +// if (newDmp.getGrant() != null && newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) { +// checkIfUserCanEditGrant(newDmp, user); +// }//TODO assignGrandUserIfInternal(newDmp, user); } - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Funder)) { + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Funder)) { assignFunderUserIfInternal(newDmp, user); } - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Project)) { + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Project)) { assignProjectUserIfInternal(newDmp, user); } if(newDmp.getId() != null){ - for(DMPDatasetProfile dmpDatasetProfile : newDmp.getAssociatedDmps()){ - apiContext.getOperationsContext().getDatabaseRepository().getDmpDatasetProfileDao().createOrUpdate(dmpDatasetProfile); - } +// for(DMPDatasetProfile dmpDatasetProfile : newDmp.getAssociatedDmps()){ //TODO +// apiContext.getOperationsContext().getDatabaseRepository().getDmpDatasetProfileDao().createOrUpdate(dmpDatasetProfile); +// } } - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { - if (newDmp.getGrant() != null) { - apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant()); - } + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Grant)) { +// if (newDmp.getGrant() != null) { //TODO +// apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant()); +// } } newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp); - for(DMPDatasetProfile dmpDatasetProfile : newDmp.getAssociatedDmps()){ - apiContext.getOperationsContext().getDatabaseRepository().getDmpDatasetProfileDao().createOrUpdate(dmpDatasetProfile); - } +// for(DMPDatasetProfile dmpDatasetProfile : newDmp.getAssociatedDmps()){ //TODO +// apiContext.getOperationsContext().getDatabaseRepository().getDmpDatasetProfileDao().createOrUpdate(dmpDatasetProfile); +// } if (dataManagementPlan.getUsers() != null && !dataManagementPlan.getUsers().isEmpty()) { clearUsers(newDmp); for (UserInfoListingModel userListing : dataManagementPlan.getUsers()) { UserInfo tempUser = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userListing.getId()); - assignUser(dmp, tempUser, UserDMP.UserDMPRoles.fromInteger(userListing.getRole())); + assignUser(dmp, tempUser, DmpUserRole.of((short)userListing.getRole())); } } // Dataset manipulation for when the DMP is set to be finalized. - if (dataManagementPlan.getStatus() == DMP.DMPStatus.FINALISED.getValue()) { + if (dataManagementPlan.getStatus() == DmpStatus.Finalized.getValue()) { if (dataManagementPlan.getDatasetsToBeFinalized() != null && !dataManagementPlan.getDatasetsToBeFinalized().isEmpty()) { apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao() .asQueryable().where((builder, root) -> root.get("id").in(dataManagementPlan.getDatasetsToBeFinalized())) @@ -623,12 +628,13 @@ public class DataManagementPlanManager { assignUser(newDmp, user); UUID dmpId = newDmp.getId(); - newDmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); + //TODO +// newDmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); //this.updateIndex(newDmp); //TODO if (setNotification) { - if (newDmp.getStatus() != DMP.DMPStatus.FINALISED.getValue()) { + if (newDmp.getStatus().equals(DmpStatus.Finalized.getValue())) { this.sendNotification(newDmp, user, NotificationType.DMP_MODIFIED); } else { this.sendNotification(newDmp, user, NotificationType.DMP_MODIFIED_FINALISED); @@ -638,11 +644,11 @@ public class DataManagementPlanManager { return newDmp; } - public DMP createOrUpdateWithDatasets(DataManagementPlanEditorModel dataManagementPlan) throws Exception { + public DmpEntity createOrUpdateWithDatasets(DataManagementPlanEditorModel dataManagementPlan) throws Exception { if (dataManagementPlan.getId() != null) { - DMP dmp1 = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(dataManagementPlan.getId()); + DmpEntity dmp1 = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(dataManagementPlan.getId()); - Instant dbTime = Instant.ofEpochMilli(dmp1.getModified().getTime()).truncatedTo(ChronoUnit.SECONDS); + Instant dbTime = dmp1.getUpdatedAt().truncatedTo(ChronoUnit.SECONDS); Instant modelTime = Instant.ofEpochMilli(dataManagementPlan.getModified().getTime()).truncatedTo(ChronoUnit.SECONDS); if (!isUserOwnerOfDmp(dmp1)) { @@ -655,31 +661,33 @@ public class DataManagementPlanManager { if (dataManagementPlan.getProfiles().stream().filter(associatedProfile -> dataset.getProfile().getId().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())) + if (dataManagementPlan.getStatus() == (int) DmpStatus.Finalized.getValue() && dmp1.getStatus().equals(DmpStatus.Finalized.getValue())) throw new Exception("DMP is finalized, therefore cannot be edited."); } else { metricsManager.increaseValue(MetricNames.DMP, 1, MetricNames.DRAFT); } List descriptionEntities = new ArrayList<>(); - DMP tempDMP = dataManagementPlan.toDataModel(); - if (tempDMP.getStatus() == (int) DMP.DMPStatus.FINALISED.getValue()) { + DmpEntity tempDMP = dataManagementPlan.toDataModel(); + if (tempDMP.getStatus().equals(DmpStatus.Finalized)) { checkDmpValidationRules(tempDMP); } UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId()); - if(this.dmpBlueprintService.fieldInBlueprint(tempDMP.getProfile(), DmpBlueprintSystemFieldType.Organizations)) { + DmpBlueprintEntity dmpBlueprint = this.queryFactory.query(DmpBlueprintQuery.class).ids(tempDMP.getBlueprint()).first(); + + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Organizations)) { createOrganisationsIfTheyDontExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao()); } - if(this.dmpBlueprintService.fieldInBlueprint(tempDMP.getProfile(), DmpBlueprintSystemFieldType.Researchers)) { + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Researchers)) { createResearchersIfTheyDontExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao(), user); } - if(this.dmpBlueprintService.fieldInBlueprint(tempDMP.getProfile(), DmpBlueprintSystemFieldType.Funder)) { + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Funder)) { createFunderIfItDoesntExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getFunderDao()); } - if(this.dmpBlueprintService.fieldInBlueprint(tempDMP.getProfile(), DmpBlueprintSystemFieldType.Grant)) { + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Grant)) { createGrantIfItDoesntExist(tempDMP, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao()); } - DMP result = createOrUpdate(dataManagementPlan); + DmpEntity result = createOrUpdate(dataManagementPlan); for (DatasetWizardModel datasetWizardModel: dataManagementPlan.getDatasets()) { datasetWizardModel.setDmp(new DataManagementPlan().fromDataModel(result)); @@ -688,7 +696,7 @@ public class DataManagementPlanManager { } UUID dmpId = result.getId(); - result.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); + //result.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); //TODO //this.updateIndex(result); //TODO @@ -696,7 +704,7 @@ public class DataManagementPlanManager { } public UUID newVersion(UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan) throws Exception { - DMP oldDmp = databaseRepository.getDmpDao().find(uuid); + DmpEntity oldDmp = databaseRepository.getDmpDao().find(uuid); if (!isUserOwnerOfDmp(oldDmp)) { throw new Exception("User not being the creator is not authorized to perform this action."); } @@ -705,67 +713,72 @@ public class DataManagementPlanManager { list.push(oldDmp.getGroupId()); criteria.setGroupIds(list); criteria.setAllVersions(false); - QueryableList dataManagementPlanQueryableList = databaseRepository.getDmpDao().getWithCriteria(criteria); - List latestVersionDMP = dataManagementPlanQueryableList.toList(); + QueryableList dataManagementPlanQueryableList = databaseRepository.getDmpDao().getWithCriteria(criteria); + List latestVersionDMP = dataManagementPlanQueryableList.toList(); if (latestVersionDMP.get(0).getVersion().equals(oldDmp.getVersion())) { - DMP newDmp = dataManagementPlan.toDataModel(); - newDmp.setProfile(oldDmp.getProfile()); + DmpEntity newDmp = dataManagementPlan.toDataModel(); + newDmp.setBlueprint(oldDmp.getBlueprint()); + newDmp.setProperties(oldDmp.getProperties()); newDmp.setProperties(oldDmp.getProperties()); - newDmp.setDmpProperties(oldDmp.getDmpProperties()); UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(this.userScope.getUserId()).build(); - newDmp.setCreator(user); - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Organizations)) { + newDmp.setCreator(user.getId()); + DmpBlueprintEntity dmpBlueprint = this.queryFactory.query(DmpBlueprintQuery.class).ids(newDmp.getBlueprint()).first(); + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Organizations)) { createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao()); } - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Researchers)) { + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Researchers)) { createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao(), user); } - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Funder)) { + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Funder)) { createFunderIfItDoesntExist(newDmp, databaseRepository.getFunderDao()); } - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Grant)) { createGrantIfItDoesntExist(newDmp, databaseRepository.getGrantDao()); - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Project)) { - if (newDmp.getProject() != null && newDmp.getGrant() != null && (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty())) { - newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant())); - } + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Project)) { + //TODO +// if (newDmp.getProject() != null && newDmp.getGrant() != null && (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty())) { +// newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant())); +// } createProjectIfItDoesntExist(newDmp, databaseRepository.getProjectDao()); } } newDmp.setGroupId(oldDmp.getGroupId()); - newDmp.setVersion(oldDmp.getVersion() + 1); + newDmp.setVersion((short)(oldDmp.getVersion() + 1)); newDmp.setId(null); - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { - if (newDmp.getGrant() != null && newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) { - checkIfUserCanEditGrant(newDmp, user); - } + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Grant)) { + //TODO +// if (newDmp.getGrant() != null && newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) { +// checkIfUserCanEditGrant(newDmp, user); +// } assignGrandUserIfInternal(newDmp, user); } - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Funder)) { + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Funder)) { assignFunderUserIfInternal(newDmp, user); } - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Project)) { + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Project)) { assignProjectUserIfInternal(newDmp, user); } - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { - if (newDmp.getGrant() != null) { - if (newDmp.getGrant().getStartdate() == null) { - newDmp.getGrant().setStartdate(new Date()); - } - if (newDmp.getGrant().getEnddate() == null) { - newDmp.getGrant().setEnddate(Date.from(Instant.now().plus(365, ChronoUnit.DAYS))); - } - databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant()); - } + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Grant)) { + //TODO +// if (newDmp.getGrant() != null) { +// if (newDmp.getGrant().getStartdate() == null) { +// newDmp.getGrant().setStartdate(new Date()); +// } +// if (newDmp.getGrant().getEnddate() == null) { +// newDmp.getGrant().setEnddate(Date.from(Instant.now().plus(365, ChronoUnit.DAYS))); +// } +// databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant()); +// } } - DMP tempDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp); + DmpEntity tempDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp); newDmp.setId(tempDmp.getId()); - for(DMPDatasetProfile dmpDatasetProfile : newDmp.getAssociatedDmps()){ - apiContext.getOperationsContext().getDatabaseRepository().getDmpDatasetProfileDao().createOrUpdate(dmpDatasetProfile); - } + //TODO +// for(DMPDatasetProfile dmpDatasetProfile : newDmp.getAssociatedDmps()){ +// apiContext.getOperationsContext().getDatabaseRepository().getDmpDatasetProfileDao().createOrUpdate(dmpDatasetProfile); +// } // Assign creator. //assignUser(newDmp, user); @@ -775,18 +788,20 @@ public class DataManagementPlanManager { databaseRepository .getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), oldDmp.getId())) .toList().stream().forEach(userDMP -> { - UserDMP temp = new UserDMP(); + DmpUserEntity temp = new DmpUserEntity(); temp.setUser(userDMP.getUser()); temp.setRole(userDMP.getRole()); - temp.setDmp(newDmp); + temp.setDmp(newDmp.getId()); apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(temp); }); - newDmp.setUsers(new HashSet<>(databaseRepository.getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), newDmp.getId())).toList())); + //TODO + //newDmp.setUsers(new HashSet<>(databaseRepository.getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), newDmp.getId())).toList())); DatasetCriteria criteria1 = new DatasetCriteria(); criteria1.setDmpIds(Collections.singletonList(newDmp.getId())); - newDmp.setDataset(new HashSet<>(databaseRepository.getDatasetDao().getWithCriteria(criteria1).toList())); + //TODO + //newDmp.setDataset(new HashSet<>(databaseRepository.getDatasetDao().getWithCriteria(criteria1).toList())); this.updateGroupIndex(newDmp.getGroupId()); return newDmp.getId(); @@ -796,70 +811,78 @@ public class DataManagementPlanManager { } public UUID clone(UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan) throws Exception { - DMP oldDmp = databaseRepository.getDmpDao().find(uuid); - DMP newDmp = dataManagementPlan.toDataModel(); - newDmp.setProfile(oldDmp.getProfile()); + DmpEntity oldDmp = databaseRepository.getDmpDao().find(uuid); + DmpEntity newDmp = dataManagementPlan.toDataModel(); + newDmp.setBlueprint(oldDmp.getBlueprint()); + newDmp.setProperties(oldDmp.getProperties()); newDmp.setProperties(oldDmp.getProperties()); - newDmp.setDmpProperties(oldDmp.getDmpProperties()); UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(this.userScope.getUserId()).build(); - newDmp.setCreator(user); - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Organizations)) { + newDmp.setCreator(user.getId()); + DmpBlueprintEntity dmpBlueprint = this.queryFactory.query(DmpBlueprintQuery.class).ids(newDmp.getBlueprint()).first(); + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Organizations)) { createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao()); } - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Researchers)) { + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Researchers)) { createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao(), user); } - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Funder)) { + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Funder)) { createFunderIfItDoesntExist(newDmp, databaseRepository.getFunderDao()); } - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Grant)) { createGrantIfItDoesntExist(newDmp, databaseRepository.getGrantDao()); - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Project)) { - if (newDmp.getProject() != null && newDmp.getGrant() != null && (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty())) { - newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant())); - } - createProjectIfItDoesntExist(newDmp, databaseRepository.getProjectDao()); - } + //TODO +// if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Project)) { +// if (newDmp.getProject() != null && newDmp.getGrant() != null && (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty())) { +// newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant())); +// } +// createProjectIfItDoesntExist(newDmp, databaseRepository.getProjectDao()); +// } } newDmp.setGroupId(UUID.randomUUID()); - newDmp.setVersion(0); + newDmp.setVersion((short)0); newDmp.setId(null); - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { - if (newDmp.getGrant() != null && newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) { - checkIfUserCanEditGrant(newDmp, user); - } + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Grant)) { + //TODO +// if (newDmp.getGrant() != null && newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) { +// checkIfUserCanEditGrant(newDmp, user); +// } assignGrandUserIfInternal(newDmp, user); } - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Funder)) { + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Funder)) { assignFunderUserIfInternal(newDmp, user); } - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Project)) { + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Project)) { assignProjectUserIfInternal(newDmp, user); } - if(this.dmpBlueprintService.fieldInBlueprint(newDmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { - if (newDmp.getGrant() != null) { - databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant()); - } + if(this.dmpBlueprintService.fieldInBlueprint(dmpBlueprint, DmpBlueprintSystemFieldType.Grant)) { + //TODO +// if (newDmp.getGrant() != null) { +// databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant()); +// } } - DMP tempDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp); + DmpEntity tempDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp); newDmp.setId(tempDmp.getId()); - for(DMPDatasetProfile dmpDatasetProfile : newDmp.getAssociatedDmps()){ - apiContext.getOperationsContext().getDatabaseRepository().getDmpDatasetProfileDao().createOrUpdate(dmpDatasetProfile); - } + //TODO +// for(DMPDatasetProfile dmpDatasetProfile : newDmp.getAssociatedDmps()){ +// apiContext.getOperationsContext().getDatabaseRepository().getDmpDatasetProfileDao().createOrUpdate(dmpDatasetProfile); +// } assignUser(newDmp, user); copyDatasets(newDmp, databaseRepository.getDatasetDao()); - newDmp.setUsers(new HashSet<>(databaseRepository.getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), newDmp.getId())).toList())); + //TODO +// newDmp.setUsers(new HashSet<>(databaseRepository.getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), newDmp.getId())).toList())); DatasetCriteria criteria1 = new DatasetCriteria(); criteria1.setDmpIds(Collections.singletonList(newDmp.getId())); - newDmp.setDataset(new HashSet<>(databaseRepository.getDatasetDao().getWithCriteria(criteria1).toList())); + //TODO +// newDmp.setDataset(new HashSet<>(databaseRepository.getDatasetDao().getWithCriteria(criteria1).toList())); UUID dmpId = newDmp.getId(); - newDmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); + //TODO +// newDmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); //this.updateIndex(newDmp); //TODO metricsManager.increaseValue(MetricNames.DMP, 1, MetricNames.DRAFT); @@ -873,39 +896,42 @@ public class DataManagementPlanManager { criteria.setDmpIds(dmpIds); if (apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(criteria).toList().size() > 0) throw new DMPWithDatasetsDeleteException("You cannot Remove Datamanagement Plan with Datasets"); - DMP oldDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(uuid); + DmpEntity oldDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(uuid); switch (oldDmp.getStatus()) { - case 0: + case Draft: metricsManager.decreaseValue(MetricNames.DMP, 1, MetricNames.DRAFT); break; - case 1: - if (oldDmp.getDois() != null && !oldDmp.getDois().isEmpty()) { - metricsManager.decreaseValue(MetricNames.DMP, 1, MetricNames.DOIED); - } - if (oldDmp.isPublic()) { - metricsManager.decreaseValue(MetricNames.DMP, 1, MetricNames.PUBLISHED); - } + case Finalized: + //TODO +// if (oldDmp.getDois() != null && !oldDmp.getDois().isEmpty()) { +// metricsManager.decreaseValue(MetricNames.DMP, 1, MetricNames.DOIED); +// } +// if (oldDmp.isPublic()) { +// metricsManager.decreaseValue(MetricNames.DMP, 1, MetricNames.PUBLISHED); +// } metricsManager.decreaseValue(MetricNames.DMP, 1, MetricNames.FINALIZED); break; } - oldDmp.setStatus(DMP.DMPStatus.DELETED.getValue()); + oldDmp.setIsActive(IsActive.Inactive); apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(oldDmp); UUID dmpId = oldDmp.getId(); - oldDmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); +// oldDmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); //TODO // this.updateIndex(oldDmp); //TODO DataManagementPlanCriteria criteria1 = new DataManagementPlanCriteria(); criteria1.setAllVersions(true); criteria1.setGroupIds(Collections.singletonList(oldDmp.getGroupId())); apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(criteria1).toList().forEach(dmp -> { - try { - UUID tdmpId = dmp.getId(); - dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), tdmpId)).toList())); - //this.updateIndex(dmp); //TODO - } catch (InvalidApplicationException e) { - logger.error(e.getMessage(), e); - } - for (DescriptionEntity descriptionEntity : dmp.getDataset()) { - //TODO + //TODO +// try { +// UUID tdmpId = dmp.getId(); +// //TODO +// //dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), tdmpId)).toList())); +// //this.updateIndex(dmp); //TODO +// } catch (InvalidApplicationException e) { +// logger.error(e.getMessage(), e); +// } +// for (DescriptionEntity descriptionEntity : dmp.getDataset()) { +// // try { // List tags = new ArrayList<>(); // eu.eudat.elastic.entities.Dataset elastic = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(descriptionEntity.getId().toString()); @@ -917,112 +943,112 @@ public class DataManagementPlanManager { // } catch (Exception e) { // logger.error(e.getMessage(), e); // } - } +// } }); } - private void createResearchersIfTheyDontExist(DMP newDmp, ResearcherDao researcherRepository, UserInfo user) throws InvalidApplicationException { - if (newDmp.getResearchers() != null && !newDmp.getResearchers().isEmpty()) { - for (eu.eudat.data.old.Researcher researcher : newDmp.getResearchers()) { - ResearcherCriteria criteria = new ResearcherCriteria(); - criteria.setReference(researcher.getReference()); - List entries = researcherRepository.getWithCriteria(criteria).toList(); - if (entries != null && !entries.isEmpty()) researcher.setId(entries.get(0).getId()); - else { - researcher.setCreationUser(user); - researcherRepository.createOrUpdate(researcher); - metricsManager.increaseValue(MetricNames.RESEARCHER, 1, null); - } - } - } + private void createResearchersIfTheyDontExist(DmpEntity newDmp, ResearcherDao researcherRepository, UserInfo user) throws InvalidApplicationException { +// if (newDmp.getResearchers() != null && !newDmp.getResearchers().isEmpty()) { //TODO +// for (eu.eudat.data.old.Researcher researcher : newDmp.getResearchers()) { +// ResearcherCriteria criteria = new ResearcherCriteria(); +// criteria.setReference(researcher.getReference()); +// List entries = researcherRepository.getWithCriteria(criteria).toList(); +// if (entries != null && !entries.isEmpty()) researcher.setId(entries.get(0).getId()); +// else { +// researcher.setCreationUser(user); +// researcherRepository.createOrUpdate(researcher); +// metricsManager.increaseValue(MetricNames.RESEARCHER, 1, null); +// } +// } +// } } - private void createOrganisationsIfTheyDontExist(DMP newDmp, OrganisationDao organisationRepository) throws InvalidApplicationException { - if (newDmp.getOrganisations() != null && !newDmp.getOrganisations().isEmpty()) { - for (Organisation organisation : newDmp.getOrganisations()) { - boolean createNew = false; - if (organisation.getReference() != null) { - OrganisationCriteria criteria = new OrganisationCriteria(); - criteria.setLike(organisation.getReference()); - List entries = organisationRepository.getWithCriteria(criteria).toList(); - if (entries != null && !entries.isEmpty()) organisation.setId(entries.get(0).getId()); - else createNew = true; - } else { - createNew = true; - } - - if (createNew) { - if (organisation.getReference() == null) { - organisation.setReference("Internal:" + UUID.randomUUID().toString()); - } - organisationRepository.createOrUpdate(organisation); - } - } - } + private void createOrganisationsIfTheyDontExist(DmpEntity newDmp, OrganisationDao organisationRepository) throws InvalidApplicationException { +// if (newDmp.getOrganisations() != null && !newDmp.getOrganisations().isEmpty()) { //TODO +// for (Organisation organisation : newDmp.getOrganisations()) { +// boolean createNew = false; +// if (organisation.getReference() != null) { +// OrganisationCriteria criteria = new OrganisationCriteria(); +// criteria.setLike(organisation.getReference()); +// List entries = organisationRepository.getWithCriteria(criteria).toList(); +// if (entries != null && !entries.isEmpty()) organisation.setId(entries.get(0).getId()); +// else createNew = true; +// } else { +// createNew = true; +// } +// +// if (createNew) { +// if (organisation.getReference() == null) { +// organisation.setReference("Internal:" + UUID.randomUUID().toString()); +// } +// organisationRepository.createOrUpdate(organisation); +// } +// } +// } } - private void createGrantIfItDoesntExist(DMP newDmp, GrantDao grantDao) throws InvalidApplicationException { - if (newDmp.getGrant() != null) { - Grant grant = newDmp.getGrant(); - GrantCriteria criteria = new GrantCriteria(); - if (grant.getReference() != null) { - criteria.setReference(grant.getReference()); - Grant grantEntity = grantDao.getWithCriteria(criteria).toList().stream().max(Comparator.comparing(grant1 -> grant1.getModified().getTime())).orElse(null); - if (grantEntity != null) grant.setId(grantEntity.getId()); - else { - grant.setType(Grant.GrantType.EXTERNAL.getValue()); - grant.setCreationUser(null); - if (grant.getStartdate() == null) { - grant.setStartdate(new Date()); - } - if (grant.getEnddate() == null) { - grant.setEnddate(Date.from(Instant.now().plus(365, ChronoUnit.DAYS))); - } - grantDao.createOrUpdate(grant); - } - } - else { - grant.setType(Grant.GrantType.EXTERNAL.getValue()); - grant.setCreationUser(null); - grantDao.createOrUpdate(grant); - } - } + private void createGrantIfItDoesntExist(DmpEntity newDmp, GrantDao grantDao) throws InvalidApplicationException { +// if (newDmp.getGrant() != null) { //TODO +// Grant grant = newDmp.getGrant(); +// GrantCriteria criteria = new GrantCriteria(); +// if (grant.getReference() != null) { +// criteria.setReference(grant.getReference()); +// Grant grantEntity = grantDao.getWithCriteria(criteria).toList().stream().max(Comparator.comparing(grant1 -> grant1.getModified().getTime())).orElse(null); +// if (grantEntity != null) grant.setId(grantEntity.getId()); +// else { +// grant.setType(Grant.GrantType.EXTERNAL.getValue()); +// grant.setCreationUser(null); +// if (grant.getStartdate() == null) { +// grant.setStartdate(new Date()); +// } +// if (grant.getEnddate() == null) { +// grant.setEnddate(Date.from(Instant.now().plus(365, ChronoUnit.DAYS))); +// } +// grantDao.createOrUpdate(grant); +// } +// } +// else { +// grant.setType(Grant.GrantType.EXTERNAL.getValue()); +// grant.setCreationUser(null); +// grantDao.createOrUpdate(grant); +// } +// } } - private void createFunderIfItDoesntExist(DMP newDmp, FunderDao funderDao) throws InvalidApplicationException { - if (newDmp.getGrant() != null && newDmp.getGrant().getFunder() != null) { - Funder funder = newDmp.getGrant().getFunder(); - FunderCriteria criteria = new FunderCriteria(); - if (funder.getReference() != null) { - criteria.setReference(funder.getReference()); - Funder funderEntity = funderDao.getWithCritetia(criteria).toList().stream().max(Comparator.comparing(funder1 -> funder1.getModified().getTime())).orElse(null); - if (funderEntity != null) funder.setId(funderEntity.getId()); - else { - funderDao.createOrUpdate(funder); - } - } - else { - funderDao.createOrUpdate(funder); - } - } + private void createFunderIfItDoesntExist(DmpEntity newDmp, FunderDao funderDao) throws InvalidApplicationException { +// if (newDmp.getGrant() != null && newDmp.getGrant().getFunder() != null) { //TODO +// Funder funder = newDmp.getGrant().getFunder(); +// FunderCriteria criteria = new FunderCriteria(); +// if (funder.getReference() != null) { +// criteria.setReference(funder.getReference()); +// Funder funderEntity = funderDao.getWithCritetia(criteria).toList().stream().max(Comparator.comparing(funder1 -> funder1.getModified().getTime())).orElse(null); +// if (funderEntity != null) funder.setId(funderEntity.getId()); +// else { +// funderDao.createOrUpdate(funder); +// } +// } +// else { +// funderDao.createOrUpdate(funder); +// } +// } } - private void createProjectIfItDoesntExist(DMP newDmp, ProjectDao projectDao) throws InvalidApplicationException { - if (newDmp.getProject() != null) { - Project project = newDmp.getProject(); - ProjectCriteria criteria = new ProjectCriteria(); - if (project.getReference() != null) { - criteria.setReference(project.getReference()); - Project projectEntity = projectDao.getWithCritetia(criteria).toList().stream().max(Comparator.comparing(project1 -> project1.getModified().getTime())).orElse(null); - if (projectEntity != null) project.setId(projectEntity.getId()); - else { - createExternalProject(project, projectDao); - } - } - else { - createExternalProject(project, projectDao); - } - } + private void createProjectIfItDoesntExist(DmpEntity newDmp, ProjectDao projectDao) throws InvalidApplicationException { //TODO +// if (newDmp.getProject() != null) { +// Project project = newDmp.getProject(); +// ProjectCriteria criteria = new ProjectCriteria(); +// if (project.getReference() != null) { +// criteria.setReference(project.getReference()); +// Project projectEntity = projectDao.getWithCritetia(criteria).toList().stream().max(Comparator.comparing(project1 -> project1.getModified().getTime())).orElse(null); +// if (projectEntity != null) project.setId(projectEntity.getId()); +// else { +// createExternalProject(project, projectDao); +// } +// } +// else { +// createExternalProject(project, projectDao); +// } +// } } private void createExternalProject(Project project, ProjectDao projectDao) { @@ -1034,9 +1060,11 @@ public class DataManagementPlanManager { metricsManager.increaseValue(MetricNames.PROJECT, 1, null); } - private void copyDatasets(DMP newDmp, DatasetDao datasetDao) throws InvalidApplicationException { + private void copyDatasets(DmpEntity newDmp, DatasetDao datasetDao) throws InvalidApplicationException { List> futures = new LinkedList<>(); - for (DescriptionEntity descriptionEntity : newDmp.getDataset()) { + DatasetCriteria datasetCriteria = new DatasetCriteria(); + datasetCriteria.setDmpIds(List.of(newDmp.getId())); + for (DescriptionEntity descriptionEntity : this.databaseRepository.getDatasetDao().getWithCriteria(datasetCriteria).toList()) { DescriptionEntity tempDescriptionEntity = datasetDao.find(descriptionEntity.getId()); //TODO // try { @@ -1108,7 +1136,7 @@ public class DataManagementPlanManager { return newDescriptionEntity; }).thenApplyAsync(item -> { futures.add(datasetDao.createOrUpdateAsync(item).whenComplete(((dataset1, throwable) -> { - DMP dmp = null; + DmpEntity dmp = null; try { dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(dataset1.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId()); } catch (InvalidApplicationException e) { @@ -1169,23 +1197,25 @@ public class DataManagementPlanManager { } public void makePublic(UUID id) throws Exception { - DMP dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(id); + DmpEntity dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(id); // Check if dmp is finalized and if user is owner. if (!isUserOwnerOfDmp(dmp)) throw new Exception("User does not have the privilege to do this action."); - if (!dmp.getStatus().equals(DMP.DMPStatus.FINALISED.getValue())) + if (!dmp.getStatus().equals(DmpStatus.Finalized)) throw new Exception("DMP is not finalized"); - dmp.setPublic(true); + dmp.setAccessType(DmpAccessType.Public); apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp); UUID dmpId = dmp.getId(); - dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); + +// dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); //TODO //this.updateIndex(dmp); //TODO metricsManager.increaseValue(MetricNames.DMP, 1, MetricNames.PUBLISHED); DataManagementPlanCriteria criteria = new DataManagementPlanCriteria(); criteria.setGroupIds(Collections.singletonList(dmp.getGroupId())); criteria.setAllVersions(true); + apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(criteria).toList().stream().forEach(dmp1 -> { - dmp1.getDataset().forEach(dataset -> { +// dmp1.getDataset().forEach(dataset -> { //TODO // try { // List tags = new ArrayList<>(); @@ -1201,7 +1231,7 @@ public class DataManagementPlanManager { // } catch (Exception e) { // logger.error(e.getMessage(), e); // } - }); +// }); }); UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId()); sendNotification(dmp, user, NotificationType.DMP_PUBLISH); @@ -1209,10 +1239,10 @@ public class DataManagementPlanManager { @Transactional public void makeFinalize(UUID id, DatasetsToBeFinalized datasetsToBeFinalized) throws Exception { - DMP dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(id); + DmpEntity dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(id); if (!isUserOwnerOfDmp(dmp)) throw new Exception("User does not have the privilege to do this action."); - if (dmp.getStatus().equals(DMP.DMPStatus.FINALISED.getValue())) + if (dmp.getStatus().equals(DmpStatus.Finalized)) throw new Exception("DMP is already finalized"); List indexDescriptionEntities = new ArrayList<>(); if (datasetsToBeFinalized != null && datasetsToBeFinalized.getUuids() != null && !datasetsToBeFinalized.getUuids().isEmpty()) { @@ -1247,7 +1277,12 @@ public class DataManagementPlanManager { } );*/ indexDescriptionEntities.addAll(finalizedDescriptionEntities); List datasetsToBeCanceled = new LinkedList<>(); - for (DescriptionEntity descriptionEntity : dmp.getDataset()) { + DatasetCriteria datasetCriteria = new DatasetCriteria(); + datasetCriteria.setDmpIds(List.of(dmp.getId())); + + List descriptionEntityList = this.databaseRepository.getDatasetDao().getWithCriteria(datasetCriteria).toList().stream().collect(Collectors.toList()); + + for (DescriptionEntity descriptionEntity : descriptionEntityList) { if (!descriptionEntity.getStatus().equals(DescriptionStatus.Finalized) && !datasetsToBeFinalized.getUuids().contains(descriptionEntity.getId())) { datasetsToBeCanceled.add(descriptionEntity.getId()); } @@ -1256,13 +1291,16 @@ public class DataManagementPlanManager { apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao() .asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeCanceled)) .update(root -> root.get("status"), DescriptionStatus.Canceled); - List cancelledDescriptionEntities = dmp.getDataset().stream().filter(dataset -> datasetsToBeCanceled.contains(dataset.getId())).collect(Collectors.toList()); + List cancelledDescriptionEntities = descriptionEntityList.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 (DescriptionEntity descriptionEntity : dmp.getDataset()) { + DatasetCriteria datasetCriteria = new DatasetCriteria(); + datasetCriteria.setDmpIds(List.of(dmp.getId())); + List descriptionEntityList = this.databaseRepository.getDatasetDao().getWithCriteria(datasetCriteria).toList().stream().collect(Collectors.toList()); + for (DescriptionEntity descriptionEntity : descriptionEntityList) { if (!descriptionEntity.getStatus().equals(DescriptionStatus.Finalized)) { datasetsToBeCanceled.add(descriptionEntity.getId()); } @@ -1271,15 +1309,15 @@ public class DataManagementPlanManager { apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao() .asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeCanceled)) .update(root -> root.get("status"), DescriptionStatus.Canceled); - List cancelledDescriptionEntities = dmp.getDataset().stream().filter(dataset -> datasetsToBeCanceled.contains(dataset.getId())).collect(Collectors.toList()); + List cancelledDescriptionEntities = descriptionEntityList.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()); + dmp.setStatus(DmpStatus.Finalized); apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp); UUID dmpId = dmp.getId(); - dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); +// dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); //TODO //this.updateIndex(dmp); //TODO UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId()); sendNotification(dmp, user, NotificationType.DMP_FINALISED); @@ -1291,32 +1329,32 @@ public class DataManagementPlanManager { } public void undoFinalize(UUID id) throws Exception { - DMP dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(id); + DmpEntity dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(id); if (!isUserOwnerOfDmp(dmp)) throw new Exception("User does not have the privilege to do this action."); - if (dmp.getStatus().equals(DMP.DMPStatus.ACTIVE.getValue())) + if (dmp.getIsActive().equals(IsActive.Inactive)) throw new Exception("DMP is already Active"); - if (dmp.isPublic()) + if (dmp.getAccessType().equals(DmpAccessType.Public)) throw new Exception("DMP is publicly available"); - if (!dmp.getDois().isEmpty()) - throw new Exception("DMP is deposited"); - dmp.setStatus(DMP.DMPStatus.ACTIVE.getValue()); +// if (!dmp.getDois().isEmpty())//TODO +// throw new Exception("DMP is deposited"); + dmp.setStatus(DmpStatus.Draft); apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp); UUID dmpId = dmp.getId(); - dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); +// dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); //TODO //this.updateIndex(dmp); //TODO metricsManager.decreaseValue(MetricNames.DMP, 1, MetricNames.FINALIZED); metricsManager.increaseValue(MetricNames.DMP, 1, MetricNames.DRAFT); } public void updateUsers(UUID id, List users) throws Exception { - DMP dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(id); + DmpEntity dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(id); if (!isUserOwnerOfDmp(dmp)) throw new Exception("User does not have the privilege to do this action."); clearUsers(dmp); for (UserInfoListingModel userListing : users) { UserInfo tempUser = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userListing.getId()); - assignUser(dmp, tempUser, UserDMP.UserDMPRoles.fromInteger(userListing.getRole())); + assignUser(dmp, tempUser, DmpUserRole.of((short)userListing.getRole())); } } @@ -1335,8 +1373,10 @@ public class DataManagementPlanManager { DatasetWizardModel dataset = new DatasetWizardModel(); XWPFDocument document = configLoader.getDocument(); - DMP dmpEntity = databaseRepository.getDmpDao().find(UUID.fromString(id)); - if (!dmpEntity.isPublic() && dmpEntity.getUsers().stream().filter(userInfo -> userInfo.getUser().getId().equals(this.userScope.getUserIdSafe())).collect(Collectors.toList()).size() == 0) + DmpEntity dmpEntity = databaseRepository.getDmpDao().find(UUID.fromString(id)); + if (!dmpEntity.getAccessType().equals(DmpAccessType.Public) + //TODO && dmpEntity.getUsers().stream().filter(userInfo -> userInfo.getUser().getId().equals(this.userScope.getUserIdSafe())).collect(Collectors.toList()).size() == 0 + ) throw new UnauthorisedException(); wordBuilder.fillFirstPage(dmpEntity, null, document, false); @@ -1389,7 +1429,7 @@ public class DataManagementPlanManager { // // Space below Datasets. // XWPFParagraph parBreakDatasets = document.createParagraph(); - DefinitionEntity dmpBlueprint = this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, dmpEntity.getProfile().getDefinition()); + DefinitionEntity dmpBlueprint = this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, this.queryFactory.query(DmpBlueprintQuery.class).ids(dmpEntity.getBlueprint()).first().getDefinition()); for(SectionEntity section: dmpBlueprint.getSections()){ wordBuilder.addParagraphContent("Section " + section.getOrdinal(), document, ParagraphStyle.HEADER1, BigInteger.ZERO, 0); XWPFParagraph sectionInfoParagraph = document.createParagraph(); @@ -1448,66 +1488,69 @@ public class DataManagementPlanManager { runDescription.setColor("116a78"); break; case Researchers: - for(Researcher researcher: dmpEntity.getResearchers()){ - XWPFRun runResearcher = systemFieldInput.createRun(); - runResearcher.setText("• " + researcher.getLabel()); - runResearcher.setColor("116a78"); - } - break; - case Organizations: - for(Organisation organisation: dmpEntity.getOrganisations()){ - XWPFRun runOrganisation = systemFieldInput.createRun(); - runOrganisation.setText("• " + organisation.getLabel()); - runOrganisation.setColor("116a78"); - } - break; - case Language: - XWPFRun runLanguage = systemFieldInput.createRun(); - runLanguage.setText(objectMapper.readValue(dmpEntity.getExtraProperties(), HashMap.class).get("language").toString()); - runLanguage.setColor("116a78"); - break; - case Contact: - XWPFRun runContact = systemFieldInput.createRun(); - runContact.setText(dmpEntity.getCreator().getName()); - runContact.setColor("116a78"); - break; - case Funder: - if (dmpEntity.getGrant() != null && dmpEntity.getGrant().getFunder() != null) { - XWPFRun runFunder = systemFieldInput.createRun(); - runFunder.setText(dmpEntity.getGrant().getFunder().getLabel()); - runFunder.setColor("116a78"); - } - break; - case Grant: - if (dmpEntity.getGrant() != null) { - XWPFRun runGrant = systemFieldInput.createRun(); - runGrant.setText(dmpEntity.getGrant().getLabel()); - runGrant.setColor("116a78"); - } - break; - case Project: - if (dmpEntity.getProject() != null ) { - XWPFRun runProject = systemFieldInput.createRun(); - runProject.setText(dmpEntity.getProject().getLabel()); - runProject.setColor("116a78"); - } - break; - case License: - Map extraProperties = objectMapper.readValue(dmpEntity.getExtraProperties(), HashMap.class); - if (extraProperties.containsKey("license")) { - XWPFRun runLicense = systemFieldInput.createRun(); - runLicense.setText(extraProperties.get("license").toString()); - runLicense.setColor("116a78"); - } - break; - case AccessRights: - Map extraPropertiesMap = objectMapper.readValue(dmpEntity.getExtraProperties(), HashMap.class); - if (extraPropertiesMap.containsKey("visible")) { - XWPFRun runAccessRights = systemFieldInput.createRun(); - runAccessRights.setText(extraPropertiesMap.get("visible").toString()); - runAccessRights.setColor("116a78"); - } + //TODO +// for(Researcher researcher: dmpEntity.getResearchers()){ +// XWPFRun runResearcher = systemFieldInput.createRun(); +// runResearcher.setText("• " + researcher.getLabel()); +// runResearcher.setColor("116a78"); +// } break; + //TODO +// case Organizations: +// +// for(Organisation organisation: dmpEntity.getOrganisations()){ +// XWPFRun runOrganisation = systemFieldInput.createRun(); +// runOrganisation.setText("• " + organisation.getLabel()); +// runOrganisation.setColor("116a78"); +// } +// break; +// case Language: +// XWPFRun runLanguage = systemFieldInput.createRun(); +// runLanguage.setText(objectMapper.readValue(dmpEntity.getExtraProperties(), HashMap.class).get("language").toString()); +// runLanguage.setColor("116a78"); +// break; +// case Contact: +// XWPFRun runContact = systemFieldInput.createRun(); +// runContact.setText(dmpEntity.getCreator().getName()); +// runContact.setColor("116a78"); +// break; +// case Funder: +// if (dmpEntity.getGrant() != null && dmpEntity.getGrant().getFunder() != null) { +// XWPFRun runFunder = systemFieldInput.createRun(); +// runFunder.setText(dmpEntity.getGrant().getFunder().getLabel()); +// runFunder.setColor("116a78"); +// } +// break; +// case Grant: +// if (dmpEntity.getGrant() != null) { +// XWPFRun runGrant = systemFieldInput.createRun(); +// runGrant.setText(dmpEntity.getGrant().getLabel()); +// runGrant.setColor("116a78"); +// } +// break; +// case Project: +// if (dmpEntity.getProject() != null ) { +// XWPFRun runProject = systemFieldInput.createRun(); +// runProject.setText(dmpEntity.getProject().getLabel()); +// runProject.setColor("116a78"); +// } +// break; +// case License: +// Map extraProperties = objectMapper.readValue(dmpEntity.getExtraProperties(), HashMap.class); +// if (extraProperties.containsKey("license")) { +// XWPFRun runLicense = systemFieldInput.createRun(); +// runLicense.setText(extraProperties.get("license").toString()); +// runLicense.setColor("116a78"); +// } +// break; +// case AccessRights: +// Map extraPropertiesMap = objectMapper.readValue(dmpEntity.getExtraProperties(), HashMap.class); +// if (extraPropertiesMap.containsKey("visible")) { +// XWPFRun runAccessRights = systemFieldInput.createRun(); +// runAccessRights.setText(extraPropertiesMap.get("visible").toString()); +// runAccessRights.setColor("116a78"); +// } +// break; } document.createParagraph(); } @@ -1542,9 +1585,13 @@ public class DataManagementPlanManager { runTemplateLabel.setColor("116a78"); } - final Boolean isFinalized = dmpEntity.getStatus() == DMP.DMPStatus.FINALISED.getValue(); - final Boolean isPublic = dmpEntity.isPublic(); - dmpEntity.getDataset().stream() + final Boolean isFinalized = dmpEntity.getStatus().equals(DmpStatus.Finalized); + final Boolean isPublic = dmpEntity.getAccessType().equals(DmpAccessType.Public); + + DatasetCriteria datasetCriteria = new DatasetCriteria(); + datasetCriteria.setDmpIds(Collections.singletonList(dmpEntity.getId())); + List descriptionEntityList = this.databaseRepository.getDatasetDao().getWithCriteria(datasetCriteria).toList().stream().collect(Collectors.toList()); + descriptionEntityList.stream() .filter(item -> item.getStatus() != DescriptionStatus.Canceled) .filter(item -> item.getIsActive() != IsActive.Inactive) .filter(item -> !isPublic && !isFinalized || item.getStatus() == DescriptionStatus.Finalized) @@ -1686,16 +1733,17 @@ public class DataManagementPlanManager { wordBuilder.fillFooter(dmpEntity, null, document, false); - String fileName; - if (dmpEntity.getGrant() != null && dmpEntity.getGrant().getLabel() != null) { - fileName = "DMP_" + dmpEntity.getGrant().getLabel(); - } - else { - fileName = "DMP_" + dmpEntity.getLabel(); - } - if (versioned) { - fileName += "_" + dmpEntity.getVersion(); - } + String fileName =""; + //TODO +// if (dmpEntity.getGrant() != null && dmpEntity.getGrant().getLabel() != null) { +// fileName = "DMP_" + dmpEntity.getGrant().getLabel(); +// } +// else { +// fileName = "DMP_" + dmpEntity.getLabel(); +// } +// if (versioned) { +// fileName += "_" + dmpEntity.getVersion(); +// } // fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", ""); FileEnvelope exportEnvelope = new FileEnvelope(); exportEnvelope.setFilename(fileName + ".docx"); @@ -1712,12 +1760,19 @@ public class DataManagementPlanManager { private FileEnvelope getXmlDocument(String id) throws IOException, InvalidApplicationException { ExportXmlBuilder xmlBuilder = new ExportXmlBuilder(); VisibilityRuleService visibilityRuleService = new VisibilityRuleServiceImpl(); - DMP dmp = databaseRepository.getDmpDao().find(UUID.fromString(id)); - if (!dmp.isPublic() && dmp.getUsers().stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())).collect(Collectors.toList()).size() == 0) + DmpEntity dmp = databaseRepository.getDmpDao().find(UUID.fromString(id)); + if (!dmp.getAccessType().equals(DmpAccessType.Public) + //TODO && dmp.getUsers().stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())).collect(Collectors.toList()).size() == 0 + ) throw new UnauthorisedException(); - final Boolean isFinalized = dmp.getStatus() == DMP.DMPStatus.FINALISED.getValue(); - final Boolean isPublic = dmp.isPublic(); - List descriptionEntities = dmp.getDataset().stream() + final Boolean isFinalized = dmp.getStatus().equals(DmpStatus.Finalized); + final Boolean isPublic = dmp.getAccessType().equals(DmpAccessType.Public); + DatasetCriteria datasetCriteria = new DatasetCriteria(); + datasetCriteria.setDmpIds(List.of(dmp.getId())); + + List descriptionEntityList = this.databaseRepository.getDatasetDao().getWithCriteria(datasetCriteria).toList().stream().filter(dataset -> dataset.getIsActive() != IsActive.Inactive).collect(Collectors.toList()); + + List descriptionEntities = descriptionEntityList.stream() .filter(dataset -> dataset.getIsActive() != IsActive.Inactive && dataset.getStatus() != DescriptionStatus.Canceled) .filter(dataset -> !isPublic && !isFinalized || dataset.getStatus() == DescriptionStatus.Finalized) @@ -1736,23 +1791,24 @@ public class DataManagementPlanManager { dmpName.setTextContent(dmp.getLabel()); dmpElement.appendChild(dmpName); - if (dmp.getExtraProperties() != null && !dmp.getExtraProperties().isEmpty()) { - Map extraProperties = new ObjectMapper().readValue(dmp.getExtraProperties(), HashMap.class); - Element language = xmlDoc.createElement("language"); - language.setTextContent(extraProperties.get("language") != null ? extraProperties.get("language").toString() : null); - dmpElement.appendChild(language); - Element visibility = xmlDoc.createElement("visibility"); - visibility.setTextContent(extraProperties.get("visible") != null ? extraProperties.get("visible").toString() : null); - dmpElement.appendChild(visibility); - Element publicDate = xmlDoc.createElement("publicDate"); - publicDate.setTextContent(extraProperties.get("publicDate") != null ? extraProperties.get("publicDate").toString() : null); - dmpElement.appendChild(publicDate); - Element costs = xmlDoc.createElement("costs"); - costs.setTextContent(extraProperties.get("costs") != null ? extraProperties.get("costs").toString() : null); - dmpElement.appendChild(costs); - } + //TODO +// if (dmp.getExtraProperties() != null && !dmp.getExtraProperties().isEmpty()) { +// Map extraProperties = new ObjectMapper().readValue(dmp.getExtraProperties(), HashMap.class); +// Element language = xmlDoc.createElement("language"); +// language.setTextContent(extraProperties.get("language") != null ? extraProperties.get("language").toString() : null); +// dmpElement.appendChild(language); +// Element visibility = xmlDoc.createElement("visibility"); +// visibility.setTextContent(extraProperties.get("visible") != null ? extraProperties.get("visible").toString() : null); +// dmpElement.appendChild(visibility); +// Element publicDate = xmlDoc.createElement("publicDate"); +// publicDate.setTextContent(extraProperties.get("publicDate") != null ? extraProperties.get("publicDate").toString() : null); +// dmpElement.appendChild(publicDate); +// Element costs = xmlDoc.createElement("costs"); +// costs.setTextContent(extraProperties.get("costs") != null ? extraProperties.get("costs").toString() : null); +// dmpElement.appendChild(costs); +// } - DmpBlueprintEntity dmpBlueprint = dmp.getProfile(); + DmpBlueprintEntity dmpBlueprint = this.queryFactory.query(DmpBlueprintQuery.class).ids(dmp.getBlueprint()).first(); Element dmpProfileElement = xmlDoc.createElement("dmpProfile"); Element dmpProfileName = xmlDoc.createElement("dmpProfileName"); if (!(dmpBlueprint == null)) { @@ -1771,15 +1827,15 @@ public class DataManagementPlanManager { Element dmpContactName = xmlDoc.createElement("name"); Element dmpContactEmail = xmlDoc.createElement("email"); if(dmp.getCreator() != null){ - dmpContactName.setTextContent(dmp.getCreator().getName()); - dmpContactEmail.setTextContent(dmp.getCreator().getEmail()); + dmpContactName.setTextContent(this.databaseRepository.getUserInfoDao().find(dmp.getCreator()).getName()); + dmpContactEmail.setTextContent(this.databaseRepository.getUserInfoDao().find(dmp.getCreator()).getEmail()); } else{ - Iterator users = dmp.getUsers().iterator(); + Iterator users = new ArrayList().iterator(); //TODO dmp.getUsers().iterator(); if(users.hasNext()){ - UserDMP creator = users.next(); - dmpContactName.setTextContent(creator.getUser().getName()); - dmpContactEmail.setTextContent(creator.getUser().getEmail()); + DmpUserEntity creator = users.next(); + dmpContactName.setTextContent(this.databaseRepository.getUserInfoDao().find(creator.getUser()).getName()); + dmpContactEmail.setTextContent(this.databaseRepository.getUserInfoDao().find(creator.getUser()).getEmail()); } } dmpContactElement.appendChild(dmpContactName); @@ -1787,14 +1843,14 @@ public class DataManagementPlanManager { dmpElement.appendChild(dmpContactElement); Element dmpContributorsElement = xmlDoc.createElement("contributors"); - Iterator users = dmp.getUsers().iterator(); + Iterator users = new ArrayList().iterator(); //TODO dmp.getUsers().iterator(); while(users.hasNext()){ Element dmpContributorElement = xmlDoc.createElement("contributor"); Element dmpContributorName = xmlDoc.createElement("name"); Element dmpContributorEmail= xmlDoc.createElement("email"); - UserDMP contributor = users.next(); - dmpContributorName.setTextContent(contributor.getUser().getName()); - dmpContributorEmail.setTextContent(contributor.getUser().getEmail()); + DmpUserEntity contributor = users.next(); + dmpContributorName.setTextContent(this.databaseRepository.getUserInfoDao().find(contributor.getUser()).getName()); + dmpContributorEmail.setTextContent(this.databaseRepository.getUserInfoDao().find(contributor.getUser()).getEmail()); dmpContributorElement.appendChild(dmpContributorName); dmpContributorElement.appendChild(dmpContributorEmail); dmpContributorsElement.appendChild(dmpContributorElement); @@ -1803,53 +1859,57 @@ public class DataManagementPlanManager { // Funder. Element funder = xmlDoc.createElement("funder"); - if (this.dmpBlueprintService.fieldInBlueprint(dmp.getProfile(), DmpBlueprintSystemFieldType.Grant) && this.dmpBlueprintService.fieldInBlueprint(dmp.getProfile(), DmpBlueprintSystemFieldType.Funder)) { + if (this.dmpBlueprintService.fieldInBlueprint(this.queryFactory.query(DmpBlueprintQuery.class).ids(dmp.getBlueprint()).first(), DmpBlueprintSystemFieldType.Grant) && this.dmpBlueprintService.fieldInBlueprint(this.queryFactory.query(DmpBlueprintQuery.class).ids(dmp.getBlueprint()).first(), DmpBlueprintSystemFieldType.Funder)) { Element funderLabel = xmlDoc.createElement("label"); Element funderId = xmlDoc.createElement("id"); - funderLabel.setTextContent(dmp.getGrant().getFunder().getLabel()); - funderId.setTextContent(dmp.getGrant().getFunder().getId().toString()); - funder.appendChild(funderLabel); - funder.appendChild(funderId); - if (dmp.getGrant().getFunder().getReference() != null) { - String referencePrefix = dmp.getGrant().getFunder().getReference().split(":")[0]; - String shortReference = dmp.getGrant().getFunder().getReference().substring(referencePrefix.length() + 1); - Element funderReference = xmlDoc.createElement("reference"); - funderReference.setTextContent(shortReference); - funder.appendChild(funderReference); - } + //TODO +// funderLabel.setTextContent(dmp.getGrant().getFunder().getLabel()); +// funderId.setTextContent(dmp.getGrant().getFunder().getId().toString()); +// funder.appendChild(funderLabel); +// funder.appendChild(funderId); +// if (dmp.getGrant().getFunder().getReference() != null) { +// String referencePrefix = dmp.getGrant().getFunder().getReference().split(":")[0]; +// String shortReference = dmp.getGrant().getFunder().getReference().substring(referencePrefix.length() + 1); +// Element funderReference = xmlDoc.createElement("reference"); +// funderReference.setTextContent(shortReference); +// funder.appendChild(funderReference); +// } } dmpElement.appendChild(funder); // Grant. Element grant = xmlDoc.createElement("grant"); - if (this.dmpBlueprintService.fieldInBlueprint(dmp.getProfile(), DmpBlueprintSystemFieldType.Grant)) { + if (this.dmpBlueprintService.fieldInBlueprint(this.queryFactory.query(DmpBlueprintQuery.class).ids(dmp.getBlueprint()).first(), DmpBlueprintSystemFieldType.Grant)) { Element grantLabel = xmlDoc.createElement("label"); Element grantId = xmlDoc.createElement("id"); - grantLabel.setTextContent(dmp.getGrant().getLabel()); - grantId.setTextContent(dmp.getGrant().getId().toString()); - grant.appendChild(grantLabel); - grant.appendChild(grantId); - if (dmp.getGrant().getReference() != null) { - String referencePrefix = dmp.getGrant().getReference().split(":")[0]; - String shortReference = dmp.getGrant().getReference().substring(referencePrefix.length() + 1); - Element grantReference = xmlDoc.createElement("reference"); - grantReference.setTextContent(shortReference); - grant.appendChild(grantReference); - } + //TODO +// grantLabel.setTextContent(dmp.getGrant().getLabel()); +// grantId.setTextContent(dmp.getGrant().getId().toString()); +// grant.appendChild(grantLabel); +// grant.appendChild(grantId); +// if (dmp.getGrant().getReference() != null) { +// String referencePrefix = dmp.getGrant().getReference().split(":")[0]; +// String shortReference = dmp.getGrant().getReference().substring(referencePrefix.length() + 1); +// Element grantReference = xmlDoc.createElement("reference"); +// grantReference.setTextContent(shortReference); +// grant.appendChild(grantReference); +// } } dmpElement.appendChild(grant); // Project. Element project = xmlDoc.createElement("project"); - if (this.dmpBlueprintService.fieldInBlueprint(dmp.getProfile(), DmpBlueprintSystemFieldType.Project)) { + if (this.dmpBlueprintService.fieldInBlueprint(this.queryFactory.query(DmpBlueprintQuery.class).ids(dmp.getBlueprint()).first(), DmpBlueprintSystemFieldType.Project)) { Element projectId = xmlDoc.createElement("id"); Element projectLabel = xmlDoc.createElement("label"); Element projectDescription = xmlDoc.createElement("description"); Element projectStartDate = xmlDoc.createElement("start"); Element projectEndDate = xmlDoc.createElement("end"); - projectId.setTextContent(dmp.getProject().getId().toString()); - projectLabel.setTextContent(dmp.getProject().getLabel()); - projectDescription.setTextContent(dmp.getProject().getDescription()); - projectStartDate.setTextContent(dmp.getProject().getStartdate().toString()); - projectEndDate.setTextContent(dmp.getProject().getEnddate().toString()); + + //TODO +// projectId.setTextContent(dmp.getProject().getId().toString()); +// projectLabel.setTextContent(dmp.getProject().getLabel()); +// projectDescription.setTextContent(dmp.getProject().getDescription()); +// projectStartDate.setTextContent(dmp.getProject().getStartdate().toString()); +// projectEndDate.setTextContent(dmp.getProject().getEnddate().toString()); project.appendChild(projectId); project.appendChild(projectLabel); project.appendChild(projectDescription); @@ -1858,36 +1918,37 @@ public class DataManagementPlanManager { } dmpElement.appendChild(project); - Element organisationsElement = xmlDoc.createElement("organisations"); - for (Organisation organisation : dmp.getOrganisations()) { - Element organisationElement = xmlDoc.createElement("organisation"); - Element organisationNameElement = xmlDoc.createElement("name"); - organisationNameElement.setTextContent(organisation.getLabel()); - Element organisationReferenceElement = xmlDoc.createElement("reference"); - organisationReferenceElement.setTextContent(organisation.getReference()); - organisationElement.appendChild(organisationNameElement); - organisationElement.appendChild(organisationReferenceElement); - organisationsElement.appendChild(organisationElement); - } - dmpElement.appendChild(organisationsElement); - - Element researchersElement = xmlDoc.createElement("researchers"); - for (Researcher researcher : dmp.getResearchers()) { - Element researcherElement = xmlDoc.createElement("researcher"); - Element researcherNameElement = xmlDoc.createElement("name"); - researcherNameElement.setTextContent(researcher.getLabel()); - Element researcherReferenceElement = xmlDoc.createElement("reference"); - researcherReferenceElement.setTextContent(researcher.getReference()); - researcherElement.appendChild(researcherNameElement); - researcherElement.appendChild(researcherReferenceElement); - researchersElement.appendChild(researcherElement); - } - dmpElement.appendChild(researchersElement); + //TODO +// Element organisationsElement = xmlDoc.createElement("organisations"); +// for (Organisation organisation : dmp.getOrganisations()) { +// Element organisationElement = xmlDoc.createElement("organisation"); +// Element organisationNameElement = xmlDoc.createElement("name"); +// organisationNameElement.setTextContent(organisation.getLabel()); +// Element organisationReferenceElement = xmlDoc.createElement("reference"); +// organisationReferenceElement.setTextContent(organisation.getReference()); +// organisationElement.appendChild(organisationNameElement); +// organisationElement.appendChild(organisationReferenceElement); +// organisationsElement.appendChild(organisationElement); +// } +// dmpElement.appendChild(organisationsElement); +// +// Element researchersElement = xmlDoc.createElement("researchers"); +// for (Researcher researcher : dmp.getResearchers()) { +// Element researcherElement = xmlDoc.createElement("researcher"); +// Element researcherNameElement = xmlDoc.createElement("name"); +// researcherNameElement.setTextContent(researcher.getLabel()); +// Element researcherReferenceElement = xmlDoc.createElement("reference"); +// researcherReferenceElement.setTextContent(researcher.getReference()); +// researcherElement.appendChild(researcherNameElement); +// researcherElement.appendChild(researcherReferenceElement); +// researchersElement.appendChild(researcherElement); +// } +// dmpElement.appendChild(researchersElement); Element extraFields = xmlDoc.createElement("extraFields"); Map dmpProperties = new ObjectMapper().readValue(dmp.getProperties(), new TypeReference>() {}); - DefinitionEntity blueprint = new DefinitionEntity().fromXml(XmlBuilder.fromXml(dmp.getProfile().getDefinition()).getDocumentElement()); + DefinitionEntity blueprint = new DefinitionEntity().fromXml(XmlBuilder.fromXml(this.queryFactory.query(DmpBlueprintQuery.class).ids(dmp.getBlueprint()).first().getDefinition()).getDocumentElement()); blueprint.getSections().forEach(section -> { section.getFields().forEach(fieldModel -> { @@ -1948,32 +2009,33 @@ public class DataManagementPlanManager { Element profiles = xmlDoc.createElement("profiles"); // Get DatasetProfiles from DMP to add to XML. - for (DMPDatasetProfile dmpDescriptionProfile : dmp.getAssociatedDmps()) { - DescriptionTemplateEntity descriptionTemplateEntity = dmpDescriptionProfile.getDatasetprofile(); - Element profile = xmlDoc.createElement("profile"); - Element profileId = xmlDoc.createElement("profileId"); - profileId.setTextContent(descriptionTemplateEntity.getId().toString()); - profile.appendChild(profileId); - Element profileGroupId = xmlDoc.createElement("profileGroupId"); - profileGroupId.setTextContent(descriptionTemplateEntity.getGroupId().toString()); - profile.appendChild(profileGroupId); - Element profileLabel = xmlDoc.createElement("profileLabel"); - profileLabel.setTextContent(descriptionTemplateEntity.getLabel()); - profile.appendChild(profileLabel); - Element profileVersion = xmlDoc.createElement("profileVersion"); - profileVersion.setTextContent(String.valueOf(descriptionTemplateEntity.getVersion())); - profile.appendChild(profileVersion); - Element profileInSections = xmlDoc.createElement("profileInSections"); - Map data = new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference>() {}); - List sections = (List) data.get("dmpSectionIndex"); - for(int section: sections) { - Element profileInSection = xmlDoc.createElement("section"); - profileInSection.setTextContent(String.valueOf(section)); - profileInSections.appendChild(profileInSection); - } - profile.appendChild(profileInSections); - profiles.appendChild(profile); - } + //TODO +// for (DMPDatasetProfile dmpDescriptionProfile : dmp.getAssociatedDmps()) { +// DescriptionTemplateEntity descriptionTemplateEntity = dmpDescriptionProfile.getDatasetprofile(); +// Element profile = xmlDoc.createElement("profile"); +// Element profileId = xmlDoc.createElement("profileId"); +// profileId.setTextContent(descriptionTemplateEntity.getId().toString()); +// profile.appendChild(profileId); +// Element profileGroupId = xmlDoc.createElement("profileGroupId"); +// profileGroupId.setTextContent(descriptionTemplateEntity.getGroupId().toString()); +// profile.appendChild(profileGroupId); +// Element profileLabel = xmlDoc.createElement("profileLabel"); +// profileLabel.setTextContent(descriptionTemplateEntity.getLabel()); +// profile.appendChild(profileLabel); +// Element profileVersion = xmlDoc.createElement("profileVersion"); +// profileVersion.setTextContent(String.valueOf(descriptionTemplateEntity.getVersion())); +// profile.appendChild(profileVersion); +// Element profileInSections = xmlDoc.createElement("profileInSections"); +// Map data = new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference>() {}); +// List sections = (List) data.get("dmpSectionIndex"); +// for(int section: sections) { +// Element profileInSection = xmlDoc.createElement("section"); +// profileInSection.setTextContent(String.valueOf(section)); +// profileInSections.appendChild(profileInSection); +// } +// profile.appendChild(profileInSections); +// profiles.appendChild(profile); +// } dmpElement.appendChild(profiles); dmpElement.appendChild(datasetsElement); xmlDoc.appendChild(dmpElement); @@ -1982,37 +2044,42 @@ public class DataManagementPlanManager { writer.close(); FileEnvelope fileEnvelope = new FileEnvelope(); fileEnvelope.setFile(xmlFile); - if (dmp.getGrant() != null && dmp.getGrant().getLabel() != null) { - fileEnvelope.setFilename("DMP_" + dmp.getGrant().getLabel() + "_" + dmp.getVersion() + ".xml"); - } - else { - fileEnvelope.setFilename("DMP_" + dmp.getLabel() + "_" + dmp.getVersion() + ".xml"); - } + //TODO +// if (dmp.getGrant() != null && dmp.getGrant().getLabel() != null) { +// fileEnvelope.setFilename("DMP_" + dmp.getGrant().getLabel() + "_" + dmp.getVersion() + ".xml"); +// } +// else { +// fileEnvelope.setFilename("DMP_" + dmp.getLabel() + "_" + dmp.getVersion() + ".xml"); +// } return fileEnvelope; } @Transactional public FileEnvelope getRDAJsonDocument(String id) throws Exception { - DMP dmp = databaseRepository.getDmpDao().find(UUID.fromString(id)); - if (!dmp.isPublic() && dmp.getUsers().stream().noneMatch(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId()))) + DmpEntity dmp = databaseRepository.getDmpDao().find(UUID.fromString(id)); + if (!dmp.getAccessType().equals(DmpAccessType.Public) + //TODO && dmp.getUsers().stream().noneMatch(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())) + ) throw new UnauthorisedException(); - final boolean isFinalized = dmp.getStatus() == DMP.DMPStatus.FINALISED.getValue(); - final boolean isPublic = dmp.isPublic(); - dmp.setDataset(dmp.getDataset().stream() - .filter(dataset -> dataset.getIsActive() != IsActive.Inactive && - dataset.getStatus() != DescriptionStatus.Canceled) - .filter(dataset -> !isPublic && !isFinalized || dataset.getStatus() == DescriptionStatus.Finalized) - .collect(Collectors.toSet())); + final boolean isFinalized = dmp.getStatus() == DmpStatus.Finalized; + final boolean isPublic = dmp.getAccessType().equals(DmpAccessType.Public); + //TODO +// dmp.setDataset(dmp.getDataset().stream() +// .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); - String fileName; - if (dmp.getGrant() != null && dmp.getGrant().getLabel() != null) { - fileName = "DMP_" + dmp.getGrant().getLabel() + "_" + dmp.getVersion(); - } - else { - fileName = "DMP_" + dmp.getLabel() + "_" + dmp.getVersion(); - } + String fileName = ""; + //TODO +// if (dmp.getGrant() != null && dmp.getGrant().getLabel() != null) { +// fileName = "DMP_" + dmp.getGrant().getLabel() + "_" + dmp.getVersion(); +// } +// else { +// fileName = "DMP_" + dmp.getLabel() + "_" + dmp.getVersion(); +// } fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "").replace(" ", "_").replace(",", "_"); String uuid = UUID.randomUUID().toString(); File file = new File(this.environment.getProperty("temp.temp") + uuid + ".json"); @@ -2151,7 +2218,7 @@ public class DataManagementPlanManager { for (AssociatedProfileImportModels a : dataManagementPlans.get(0).getProfilesImportModels()) { try { - DescriptionTemplateEntity exProfile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(a.getId()); + eu.eudat.data.DescriptionTemplateEntity exProfile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(a.getId()); AssociatedProfile associatedProfile = new AssociatedProfile().fromData(exProfile); Map data = new HashMap<>(); List sections = new ArrayList<>(a.getSection()); @@ -2210,22 +2277,22 @@ public class DataManagementPlanManager { dm.setExtraProperties(extraPropertiesMap); //createOrUpdate(apiContext, dm, principal); - DMP dmp = this.createOrUpdate(dm); - if (dmp.getOrganisations() == null) { - dmp.setOrganisations(new HashSet<>()); - } - if (dmp.getResearchers() == null) { - dmp.setResearchers(new HashSet<>()); - } - if (dmp.getDataset() == null) { - dmp.setDataset(new HashSet<>()); - } - if (dmp.getUsers() == null) { - dmp.setUsers(new HashSet<>()); - } - if (dmp.getAssociatedDmps() == null) { - dmp.setAssociatedDmps(new HashSet<>()); - } + DmpEntity dmp = this.createOrUpdate(dm); +// if (dmp.getOrganisations() == null) { //TODO +// dmp.setOrganisations(new HashSet<>()); +// } +// if (dmp.getResearchers() == null) { +// dmp.setResearchers(new HashSet<>()); +// } +// if (dmp.getDataset() == null) { +// dmp.setDataset(new HashSet<>()); +// } +// if (dmp.getUsers() == null) { +// dmp.setUsers(new HashSet<>()); +// } +// if (dmp.getAssociatedDmps() == null) { +// dmp.setAssociatedDmps(new HashSet<>()); +// } List datasets = new LinkedList<>(); for (DatasetImportModels das: dataManagementPlans.get(0).getDatasetImportModels()) { @@ -2256,61 +2323,62 @@ public class DataManagementPlanManager { return dataManagementPlans; } - public List createFromRDA(MultipartFile[] files, String[] profiles) throws IOException, InvalidApplicationException { + public List createFromRDA(MultipartFile[] files, String[] profiles) throws IOException, InvalidApplicationException { if (!this.userScope.isSet()) { throw new UnauthorisedException("No user is logged in"); } - List result = new ArrayList<>(); + List result = new ArrayList<>(); for (MultipartFile file: files) { - DMP dmp = rdaManager.convertToEntity(new String(file.getBytes(), "UTF-8"), profiles); + DmpEntity dmp = rdaManager.convertToEntity(new String(file.getBytes(), "UTF-8"), profiles); dmp.setLabel(file.getOriginalFilename()); UserInfo me = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId()); - dmp.setModified(new Date()); - dmp.setCreator(me); - Map extraProperties = objectMapper.readValue(dmp.getExtraProperties(), HashMap.class); - extraProperties.put("contact", me.getId().toString()); - dmp.setExtraProperties(objectMapper.writeValueAsString(extraProperties)); - dmp.setVersion(0); - dmp.setStatus((short)0); - dmp.setGroupId(UUID.randomUUID()); - if (dmp.getResearchers() != null && !dmp.getResearchers().isEmpty()) { - dmp.getResearchers().stream().filter(Objects::nonNull).forEach(researcher -> { - researcher.setId(UUID.randomUUID()); - researcher.setCreated(new Date()); - researcher.setModified(new Date()); - researcher.setStatus((short) 0); - apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao().createOrUpdate(researcher); - }); - } - databaseRepository.getDmpDao().createOrUpdate(dmp); - assignUser(dmp, me); + dmp.setUpdatedAt(Instant.now()); + dmp.setCreator(me.getId()); //TODO -// if (this.apiContext.getOperationsContext().getElasticRepository().getDmpRepository().getClient() != null) { -// UUID dmpId = dmp.getId(); -// dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); -// this.updateIndex(dmp); +// Map extraProperties = objectMapper.readValue(dmp.getExtraProperties(), HashMap.class); +// extraProperties.put("contact", me.getId().toString()); +// dmp.setExtraProperties(objectMapper.writeValueAsString(extraProperties)); +// dmp.setVersion(0); +// dmp.setStatus((short)0); +// dmp.setGroupId(UUID.randomUUID()); +// if (dmp.getResearchers() != null && !dmp.getResearchers().isEmpty()) { +// dmp.getResearchers().stream().filter(Objects::nonNull).forEach(researcher -> { +// researcher.setId(UUID.randomUUID()); +// researcher.setCreated(new Date()); +// researcher.setModified(new Date()); +// researcher.setStatus((short) 0); +// apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao().createOrUpdate(researcher); +// }); // } - dmp.getDataset().forEach(dataset -> { - dataset.setStatus(DescriptionStatus.Draft); - dataset.setCreatedAt(Instant.now()); - dataset.setUpdatedAt(Instant.now()); - //dataset.setDmpId(dmp.getId()); //TODO - dataset = databaseRepository.getDatasetDao().createOrUpdate(dataset); -// dataset.setRegistries(new HashSet<>()); -// dataset.setDatasetDataRepositories(new HashSet<>()); -// dataset.setDatasetExternalDatasets(new HashSet<>()); -// dataset.setServices(new HashSet<>()); - if (dmp.getOrganisations() == null) { - dmp.setOrganisations(new HashSet<>()); - } - if (dmp.getResearchers() == null) { - dmp.setResearchers(new HashSet<>()); - } - try { - dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmp.getId())).toList())); - } catch (InvalidApplicationException e) { - throw new RuntimeException(e); - } +// databaseRepository.getDmpDao().createOrUpdate(dmp); +// assignUser(dmp, me); +// //TODO +//// if (this.apiContext.getOperationsContext().getElasticRepository().getDmpRepository().getClient() != null) { +//// UUID dmpId = dmp.getId(); +//// dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); +//// this.updateIndex(dmp); +//// } +// dmp.getDataset().forEach(dataset -> { +// dataset.setStatus(DescriptionStatus.Draft); +// dataset.setCreatedAt(Instant.now()); +// dataset.setUpdatedAt(Instant.now()); +// //dataset.setDmpId(dmp.getId()); //TODO +// dataset = databaseRepository.getDatasetDao().createOrUpdate(dataset); +//// dataset.setRegistries(new HashSet<>()); +//// dataset.setDatasetDataRepositories(new HashSet<>()); +//// dataset.setDatasetExternalDatasets(new HashSet<>()); +//// dataset.setServices(new HashSet<>()); +// if (dmp.getOrganisations() == null) { +// dmp.setOrganisations(new HashSet<>()); +// } +// if (dmp.getResearchers() == null) { +// dmp.setResearchers(new HashSet<>()); +// } +// try { +// dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmp.getId())).toList())); +// } catch (InvalidApplicationException e) { +// throw new RuntimeException(e); +// } //TODO // try { // List tags = new ArrayList<>(); @@ -2325,7 +2393,7 @@ public class DataManagementPlanManager { // } catch (Exception e) { // logger.error(e.getMessage(), e); // } - }); +// }); result.add(dmp); } @@ -2336,39 +2404,42 @@ public class DataManagementPlanManager { * Data assignments * */ - private void assignUser(DMP dmp, UserInfo userInfo) { - this.assignUser(dmp, userInfo, UserDMP.UserDMPRoles.OWNER); + private void assignUser(DmpEntity dmp, UserInfo userInfo) { + this.assignUser(dmp, userInfo, DmpUserRole.Owner); } - private void assignUser(DMP dmp, UserInfo userInfo, UserDMP.UserDMPRoles role) { - UserDMP userDMP = new UserDMP(); - userDMP.setDmp(dmp); - userDMP.setUser(userInfo); - userDMP.setRole(role.getValue()); + private void assignUser(DmpEntity dmp, UserInfo userInfo, DmpUserRole role) { + DmpUserEntity userDMP = new DmpUserEntity(); + userDMP.setDmp(dmp.getId()); + userDMP.setUser(userInfo.getId()); + userDMP.setRole(role); databaseRepository.getUserDmpDao().createOrUpdate(userDMP); } - private void clearUsers(DMP dmp) throws InvalidApplicationException { - List userDMPs = apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where(((builder, root) -> builder.equal(root.get("dmp").get("id"), dmp.getId()))).toList(); + private void clearUsers(DmpEntity dmp) throws InvalidApplicationException { + List userDMPs = apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where(((builder, root) -> builder.equal(root.get("dmp").get("id"), dmp.getId()))).toList(); userDMPs.forEach(userDMP -> apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().delete(userDMP)); } - private void assignGrandUserIfInternal(DMP dmp, UserInfo user) { - if (dmp.getGrant() != null && dmp.getGrant().getCreationUser() == null && (dmp.getGrant().getReference() != null && dmp.getGrant().getReference().startsWith("dmp:"))) { - dmp.getGrant().setCreationUser(user); - } + private void assignGrandUserIfInternal(DmpEntity dmp, UserInfo user) { + //TODO +// if (dmp.getGrant() != null && dmp.getGrant().getCreationUser() == null && (dmp.getGrant().getReference() != null && dmp.getGrant().getReference().startsWith("dmp:"))) { +// dmp.getGrant().setCreationUser(user); +// } } - private void assignFunderUserIfInternal(DMP dmp, UserInfo user) { - if (dmp.getGrant() != null && dmp.getGrant().getFunder() != null && dmp.getGrant().getFunder().getCreationUser() == null && ( dmp.getGrant().getFunder().getReference() != null && dmp.getGrant().getFunder().getReference().startsWith("dmp:"))) { - dmp.getGrant().getFunder().setCreationUser(user); - } + private void assignFunderUserIfInternal(DmpEntity dmp, UserInfo user) { + //TODO +// if (dmp.getGrant() != null && dmp.getGrant().getFunder() != null && dmp.getGrant().getFunder().getCreationUser() == null && ( dmp.getGrant().getFunder().getReference() != null && dmp.getGrant().getFunder().getReference().startsWith("dmp:"))) { +// dmp.getGrant().getFunder().setCreationUser(user); +// } } - private void assignProjectUserIfInternal(DMP dmp, UserInfo user) { - if (dmp.getProject() != null && dmp.getProject().getCreationUser() == null && (dmp.getProject().getReference() != null && dmp.getProject().getReference().startsWith("dmp:"))) { - dmp.getProject().setCreationUser(user); - } + private void assignProjectUserIfInternal(DmpEntity dmp, UserInfo user) { + //TODO +// if (dmp.getProject() != null && dmp.getProject().getCreationUser() == null && (dmp.getProject().getReference() != null && dmp.getProject().getReference().startsWith("dmp:"))) { +// dmp.getProject().setCreationUser(user); +// } } /* @@ -2379,17 +2450,17 @@ public class DataManagementPlanManager { DataManagementPlanCriteria criteria = new DataManagementPlanCriteria(); criteria.setGroupIds(Collections.singletonList(groupId)); criteria.setAllVersions(true); - List dmps = databaseRepository.getDmpDao().getWithCriteria(criteria).toList(); - for (DMP dmp: dmps) { - try { - if (dmp.getUsers() == null) { - UUID dmpId = dmp.getId(); - dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); - } -// this.updateIndex(dmp); //TODO - } catch (InvalidApplicationException e) { - logger.error(e.getMessage(), e); - } + List dmps = databaseRepository.getDmpDao().getWithCriteria(criteria).toList(); + for (DmpEntity dmp: dmps) { +// try { //TODO +// if (dmp.getUsers() == null) { +// UUID dmpId = dmp.getId(); +// dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); +// } +//// this.updateIndex(dmp); //TODO +// } catch (InvalidApplicationException e) { +// logger.error(e.getMessage(), e); +// } } } @@ -2446,35 +2517,37 @@ public class DataManagementPlanManager { * Data Checkup * */ - private void checkIfUserCanEditGrant(DMP dmp, UserInfo user) throws Exception{ - if (dmp.getGrant() != null && dmp.getGrant().getId() != null) { - Grant grant = apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().find(dmp.getGrant().getId()); - if (grant.getFunder() != null && dmp.getGrant().getFunder() != null - && !grant.getFunder().getId().equals(dmp.getGrant().getFunder().getId())) { - if (grant.getCreationUser() == null) { - throw new Exception("Grant has no user, therefore, cannot be edited."); - } - if (!grant.getCreationUser().getId().equals(user.getId())) { - throw new Exception("User is not the owner of the Grant, therefore, cannot edit it."); - } - } - } + private void checkIfUserCanEditGrant(DmpEntity dmp, UserInfo user) throws Exception{ +// if (dmp.getGrant() != null && dmp.getGrant().getId() != null) { //TODO +// Grant grant = apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().find(dmp.getGrant().getId()); +// if (grant.getFunder() != null && dmp.getGrant().getFunder() != null +// && !grant.getFunder().getId().equals(dmp.getGrant().getFunder().getId())) { +// if (grant.getCreationUser() == null) { +// throw new Exception("Grant has no user, therefore, cannot be edited."); +// } +// if (!grant.getCreationUser().getId().equals(user.getId())) { +// throw new Exception("User is not the owner of the Grant, therefore, cannot edit it."); +// } +// } +// } } - private void checkDmpValidationRules(DMP dmp) throws Exception { + private void checkDmpValidationRules(DmpEntity dmp) throws Exception { if (dmp.getLabel() == null || dmp.getLabel().trim().isEmpty()) { throw new Exception("DMP has no label."); } - if (dmp.getAssociatedDmps().size() == 0) { - throw new Exception("DMP does not contain Dataset Templates."); - } - if (dmp.getGrant() == null) { - throw new Exception("DMP has no Grant assigned."); - } + //TODO +// if (dmp.getAssociatedDmps().size() == 0) { +// throw new Exception("DMP does not contain Dataset Templates."); +// } +// if (dmp.getGrant() == null) { +// throw new Exception("DMP has no Grant assigned."); +// } } - private boolean isUserOwnerOfDmp(DMP dmp) throws InvalidApplicationException { - return this.userScope.isSet() && (dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).map(userDMP -> userDMP.getUser().getId())).collect(Collectors.toList()).contains(this.userScope.getUserId()); + private boolean isUserOwnerOfDmp(DmpEntity dmp) throws InvalidApplicationException { + return this.userScope.isSet() ; + //TODO && (dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).map(userDMP -> userDMP.getUser().getId())).collect(Collectors.toList()).contains(this.userScope.getUserId(); } /* @@ -2487,18 +2560,18 @@ public class DataManagementPlanManager { groupIds.add(groupId); criteria.setGroupIds(groupIds); criteria.setAllVersions(true); - List dmps = this.databaseRepository.getDmpDao().getWithCriteria(criteria).toList(); - dmps.sort((DMP d1, DMP d2) -> d2.getVersion() - d1.getVersion()); - for (DMP dmp: dmps) { + List dmps = this.databaseRepository.getDmpDao().getWithCriteria(criteria).toList(); + dmps.sort((DmpEntity d1, DmpEntity d2) -> d2.getVersion() - d1.getVersion()); + for (DmpEntity dmp: dmps) { if (!dmp.getId().equals(selfId)) { - if (dmp.getDois() != null && !dmp.getDois().isEmpty()) { - for (Iterator it = dmp.getDois().iterator(); it.hasNext(); ) { - EntityDoiEntity entityDoi = it.next(); - if(entityDoi.getRepositoryId().equals(repositoryId)){ - return entityDoi.getDoi(); - } - } - } +// if (dmp.getDois() != null && !dmp.getDois().isEmpty()) { //TODO +// for (Iterator it = dmp.getDois().iterator(); it.hasNext(); ) { +// EntityDoiEntity entityDoi = it.next(); +// if(entityDoi.getRepositoryId().equals(repositoryId)){ +// return entityDoi.getDoi(); +// } +// } +// } } } @@ -2508,10 +2581,10 @@ public class DataManagementPlanManager { @Transactional public Doi createDoi(DepositRequest depositRequest) throws Exception { - DMP dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(UUID.fromString(depositRequest.getDmpId())); + DmpEntity dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(UUID.fromString(depositRequest.getDmpId())); if (!isUserOwnerOfDmp(dmp)) throw new Exception("User is not authorized to invoke this action"); - if (!dmp.getStatus().equals(DMP.DMPStatus.FINALISED.getValue())) + if (!dmp.getStatus().equals(DmpStatus.Finalized)) throw new Exception("DMP is not finalized"); /*if (dmp.getDoi() != null) throw new Exception("DMP already has a DOI");*/ @@ -2561,7 +2634,7 @@ public class DataManagementPlanManager { //TODO: Save doi // apiContext.getOperationsContext().getDatabaseRepository().getEntityDoiDao().createOrUpdate(doiEntity); - dmp.getDois().add(doiEntity); +// dmp.getDois().add(doiEntity); apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp); doiModel = new Doi().fromDataModel(doiEntity); @@ -2578,12 +2651,12 @@ public class DataManagementPlanManager { } - private File createSupportingFilesZip(DMP dmp) throws IOException, InvalidApplicationException { + private File createSupportingFilesZip(DmpEntity dmp) throws IOException, InvalidApplicationException { FileOutputStream fout = new FileOutputStream(this.environment.getProperty("temp.temp") + "supportingFiles.zip"); ZipOutputStream zout = new ZipOutputStream(fout); boolean hasFileUploaded = false; - Set descriptionEntities = dmp.getDataset(); + Set descriptionEntities = new HashSet<>(); //TODO dmp.getDataset(); for (DescriptionEntity descriptionEntity : descriptionEntities) { List files = this.apiContext.getOperationsContext().getDatabaseRepository().getFileUploadDao().getFileUploads(descriptionEntity.getId()); for (FileUpload f : files) { @@ -2610,25 +2683,25 @@ public class DataManagementPlanManager { * Misc * */ - private void sendNotification(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())) { + private void sendNotification(DmpEntity 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 (DmpUserEntity userDMP : userDMPS) { + if (!userDMP.getUser().equals(user.getId())) { Notification notification = new Notification(); notification.setUserId(user); notification.setType(notificationType); notification.setNotifyState(NotifyState.PENDING); notification.setIsActive(ActiveStatus.ACTIVE); notification.setData("{" + - "\"userId\": \"" + userDMP.getUser().getId() + "\"" + - ", \"id\": \"" + userDMP.getDmp().getId() + "\"" + - ", \"name\": \"" + userDMP.getDmp().getLabel() + "\"" + + "\"userId\": \"" + userDMP.getId() + "\"" + +// ", \"id\": \"" + userDMP.getDmp().getId() + "\"" + //TODO +// ", \"name\": \"" + userDMP.getDmp().getLabel() + "\"" + ", \"path\": \"" + notificationPaths.get(notificationType) +"\"" + "}"); notification.setCreatedAt(new Date()); notification.setUpdatedAt(notification.getCreatedAt()); notification.setContactTypeHint(ContactType.EMAIL); - notification.setContactHint(userDMP.getUser().getEmail()); + //notification.setContactHint(userDMP.getUser().getEmail()); //TODO databaseRepository.getNotificationDao().createOrUpdate(notification); } } 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 4e347a0a5..43cf1c8c6 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 @@ -6,11 +6,11 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import eu.eudat.authorization.Permission; import eu.eudat.commons.enums.DescriptionStatus; +import eu.eudat.commons.enums.DmpAccessType; +import eu.eudat.commons.enums.DmpStatus; import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.scope.user.UserScope; -import eu.eudat.data.DescriptionEntity; -import eu.eudat.data.DescriptionTemplateEntity; -import eu.eudat.data.TagEntity; +import eu.eudat.data.*; import eu.eudat.data.dao.criteria.*; import eu.eudat.data.dao.entities.DataRepositoryDao; import eu.eudat.data.dao.entities.DatasetDao; @@ -300,10 +300,13 @@ public class DatasetManager { DatasetWizardModel dataset = new DatasetWizardModel(); DescriptionEntity descriptionEntityEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); ; - DMP dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId()); - if (dmp.getUsers() - .stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())) - .collect(Collectors.toList()).size() == 0 && !dmp.isPublic()) + DmpEntity dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId()); + if ( + //TODO +// dmp.getUsers() +// .stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())) +// .collect(Collectors.toList()).size() == 0 && + !dmp.getAccessType().equals(DmpAccessType.Public)) throw new UnauthorisedException(); dataset.setDatasetProfileDefinition(getPagedProfile(dataset, descriptionEntityEntity)); dataset.fromDataModel(descriptionEntityEntity); @@ -365,8 +368,8 @@ public class DatasetManager { public DatasetWizardModel getSinglePublic(String id) throws Exception { DatasetWizardModel dataset = new DatasetWizardModel(); DescriptionEntity descriptionEntityEntity = databaseRepository.getDatasetDao().isPublicDataset(UUID.fromString(id)); - DMP dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getId()).isActive(IsActive.Active).first().getDmpId()); - if (descriptionEntityEntity != null && descriptionEntityEntity.getStatus() == DescriptionStatus.Finalized && dmp.getStatus() == 1) { + DmpEntity dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getId()).isActive(IsActive.Active).first().getDmpId()); + if (descriptionEntityEntity != null && descriptionEntityEntity.getStatus() == DescriptionStatus.Finalized && dmp.getStatus().getValue() == 1) { dataset.setDatasetProfileDefinition(getPagedProfile(dataset, descriptionEntityEntity)); dataset.fromDataModel(descriptionEntityEntity); return dataset; @@ -380,14 +383,17 @@ public class DatasetManager { if (descriptionEntityEntity.getIsActive() == IsActive.Inactive) { throw new Exception("Dataset is deleted."); } - DMP dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId()); + DmpEntity dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId()); if (!isPublic && !this.userScope.isSet()) { throw new UnauthorisedException(); } else - if (!isPublic && dmp.getUsers() - .stream().noneMatch(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId()))) { + if (!isPublic + //TODO +// && dmp.getUsers() +// .stream().noneMatch(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())) + ) { throw new UnauthorisedException(); - } else if (isPublic && !dmp.isPublic()) { + } else if (isPublic && !dmp.getAccessType().equals(DmpAccessType.Public)) { throw new ForbiddenException("Selected Dataset is not public"); } DatasetOverviewModel dataset = new DatasetOverviewModel(); @@ -418,8 +424,11 @@ public class DatasetManager { DatasetWizardModel dataset = new DatasetWizardModel(); XWPFDocument document = configLoader.getDatasetDocument(); - DMP dmpEntity = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId()); - if (!dmpEntity.isPublic() && dmpEntity.getUsers().stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())).collect(Collectors.toList()).size() == 0) + DmpEntity dmpEntity = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId()); + if (!dmpEntity.getAccessType().equals(DmpAccessType.Public) + //TODO +// && dmpEntity.getUsers().stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())).collect(Collectors.toList()).size() == 0 + ) throw new UnauthorisedException(); wordBuilder.fillFirstPage(dmpEntity, descriptionEntityEntity, document, true); @@ -556,10 +565,13 @@ public class DatasetManager { public FileEnvelope getWordDocumentFile(ConfigLoader configLoader, String id, VisibilityRuleService visibilityRuleService) throws IOException, InvalidApplicationException { DescriptionEntity descriptionEntityEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); - DMP dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId()); - if (!dmp.isPublic() && dmp.getUsers() - .stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())) - .collect(Collectors.toList()).size() == 0) + DmpEntity dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId()); + if (!dmp.getAccessType().equals(DmpAccessType.Public) + //TODO +// && dmp.getUsers() +// .stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())) +// .collect(Collectors.toList()).size() == 0 + ) throw new UnauthorisedException(); String label = descriptionEntityEntity.getLabel().replaceAll("[^a-zA-Z0-9+ ]", ""); FileEnvelope exportEnvelope = new FileEnvelope(); @@ -586,10 +598,13 @@ public class DatasetManager { ExportXmlBuilder xmlBuilder = new ExportXmlBuilder(); DatasetWizardModel dataset = new DatasetWizardModel(); DescriptionEntity descriptionEntityEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); - DMP dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId()); - if (!dmp.isPublic() && dmp.getUsers() - .stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())) - .collect(Collectors.toList()).size() == 0) + DmpEntity dmp = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId()); + if (!dmp.getAccessType().equals(DmpAccessType.Public) + //TODO +// && dmp.getUsers() +// .stream().filter(userInfo -> this.userScope.getUserIdSafe().equals(userInfo.getUser().getId())) +// .collect(Collectors.toList()).size() == 0 + ) throw new UnauthorisedException(); Map properties = new HashMap<>(); if (descriptionEntityEntity.getProperties() != null) { @@ -610,7 +625,7 @@ public class DatasetManager { public DescriptionEntity createOrUpdate(DatasetWizardModel datasetWizardModel) throws Exception { Boolean sendNotification = false; DescriptionEntity tempDescriptionEntity = null; - DMP dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(datasetWizardModel.getDmp().getId()); + DmpEntity dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(datasetWizardModel.getDmp().getId()); if (datasetWizardModel.getId() != null) { tempDescriptionEntity = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(datasetWizardModel.getId()); if (tempDescriptionEntity != null) { @@ -625,7 +640,7 @@ public class DatasetManager { } else { metricsManager.increaseValue(MetricNames.DATASET, 1, MetricNames.DRAFT); } - if (dmp.getStatus().equals(DMP.DMPStatus.FINALISED.getValue()) && datasetWizardModel.getId() != null) + if (dmp.getStatus().equals(DmpStatus.Finalized) && datasetWizardModel.getId() != null) throw new Exception("DMP is finalized, therefore Dataset cannot be edited."); DescriptionEntity descriptionEntity = datasetWizardModel.toDataModel(); // descriptionEntity.setDmpId(dmp.getId()); //TODO @@ -649,15 +664,15 @@ public class DatasetManager { DescriptionEntity descriptionEntity1 = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(descriptionEntity); datasetWizardModel.setId(descriptionEntity1.getId()); if (datasetWizardModel.getDmp().getGrant() == null) { - DMP dmp1 = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity1.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId()); + DmpEntity dmp1 = databaseRepository.getDmpDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity1.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId()); datasetWizardModel.setDmp(new DataManagementPlan().fromDataModelNoDatasets(dmp1)); } // descriptionEntity1.setDescriptionTemplateId(datasetWizardModel.getProfile().getId()); //TODO // datasetWizardModel.setDatasetProfileDefinition(getPagedProfile(datasetWizardModel, dataset1)); UUID dmpId = this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity1.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId(); - DMP dmp1 = databaseRepository.getDmpDao().find(dmpId); - dmp1.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); + DmpEntity dmp1 = databaseRepository.getDmpDao().find(dmpId); +// dmp1.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList()));//TODO //updateTags(descriptionEntity1, datasetWizardModel.getTags()); //TODO if (sendNotification) { if (descriptionEntity1.getStatus() != DescriptionStatus.Finalized) { @@ -711,17 +726,17 @@ public class DatasetManager { }); } - private void sendNotification(DescriptionEntity descriptionEntity, DMP dmp, UserInfo user, NotificationType notificationType) throws InvalidApplicationException { - List userDMPS = databaseRepository.getUserDmpDao().asQueryable().where(((builder, root) -> builder.equal(root.get("dmp").get("id"), dmp.getId()))).toList(); - for (UserDMP userDMP : userDMPS) { - if (!userDMP.getUser().getId().equals(user.getId())) { + private void sendNotification(DescriptionEntity descriptionEntity, DmpEntity dmp, UserInfo user, NotificationType notificationType) throws InvalidApplicationException { + List userDMPS = databaseRepository.getUserDmpDao().asQueryable().where(((builder, root) -> builder.equal(root.get("dmp").get("id"), dmp.getId()))).toList(); + for (DmpUserEntity userDMP : userDMPS) { + if (!userDMP.getUser().equals(user.getId())) { Notification notification = new Notification(); notification.setUserId(user); notification.setType(notificationType); notification.setNotifyState(NotifyState.PENDING); notification.setIsActive(ActiveStatus.ACTIVE); notification.setData("{" + - "\"userId\": \"" + userDMP.getUser().getId() + "\"" + + "\"userId\": \"" + userDMP.getUser() + "\"" + ", \"id\": \"" + descriptionEntity.getId() + "\"" + ", \"name\": \"" + descriptionEntity.getLabel() + "\"" + ", \"path\": \"" + notificationPaths.get(notificationType) + "\"" + @@ -729,7 +744,7 @@ public class DatasetManager { notification.setCreatedAt(new Date()); notification.setUpdatedAt(notification.getCreatedAt()); notification.setContactTypeHint(ContactType.EMAIL); - notification.setContactHint(userDMP.getUser().getEmail()); + notification.setContactHint(databaseRepository.getUserInfoDao().find(userDMP.getUser()).getEmail()); databaseRepository.getNotificationDao().createOrUpdate(notification); } } @@ -1029,7 +1044,7 @@ public class DatasetManager { DescriptionEntity entity = new DescriptionEntity(); entity.setProperties(jsonDatasetProperties.toString()); entity.setLabel(importFile.getOriginalFilename()); - DMP dmp = new DMP(); + DmpEntity dmp = new DmpEntity(); dmp.setId(UUID.fromString(dmpId)); // entity.setDmpId(dmp.getId()); //TODO entity.setStatus(DescriptionStatus.Draft); @@ -1091,8 +1106,8 @@ public class DatasetManager { descriptionEntityEntities.forEach(datasetEntity -> { try { UUID dmpId = this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(datasetEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDmpId(); - DMP dmp = databaseRepository.getDmpDao().find(dmpId); - dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); + DmpEntity dmp = databaseRepository.getDmpDao().find(dmpId); + //dmp.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), dmpId)).toList())); //TODO // eu.eudat.elastic.entities.Dataset dataset = apiContext.getOperationsContext().getElasticRepository().getDatasetRepository().findDocument(datasetEntity.getId().toString()); //TODO // updateTags(datasetEntity, dataset != null ? dataset.getTags() : null); } catch (Exception e) { 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 2096facfa..9fcd7714f 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,12 +1,13 @@ package eu.eudat.logic.managers; import eu.eudat.commons.enums.DescriptionStatus; +import eu.eudat.commons.enums.DmpStatus; import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.scope.user.UserScope; +import eu.eudat.data.DmpEntity; import eu.eudat.data.dao.criteria.DatasetProfileCriteria; import eu.eudat.data.dao.entities.DMPDao; import eu.eudat.data.dao.entities.DatasetProfileDao; -import eu.eudat.data.old.DMP; import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.old.UserInfo; @@ -34,7 +35,7 @@ public class DatasetWizardManager { public static List getUserDmps(DMPDao dmpRepository, DatasetWizardAutocompleteRequest datasetWizardAutocompleteRequest, UserScope userScope) throws InstantiationException, IllegalAccessException, InvalidApplicationException { UserInfo userInfo = new UserInfo(); userInfo.setId(userScope.getUserId()); - QueryableList items = dmpRepository.getUserDmps(datasetWizardAutocompleteRequest.getCriteria(), userInfo); + QueryableList items = dmpRepository.getUserDmps(datasetWizardAutocompleteRequest.getCriteria(), userInfo); List dataManagementPlans = items.select(item -> new DataManagentPlanListingModel().fromDataModel(item)); return dataManagementPlans; } @@ -56,8 +57,8 @@ public class DatasetWizardManager { public void unlock(ApiContext apiContext, QueryFactory queryFactory, UUID uuid) throws DatasetWizardCannotUnlockException, InvalidApplicationException { DescriptionEntity descriptionEntity = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(uuid); - DMP dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()); - if(dmp.getStatus() == DMP.DMPStatus.FINALISED.getValue()) throw new DatasetWizardCannotUnlockException("To perform this action you will need to revert DMP's finalisation"); + DmpEntity dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()); + if(dmp.getStatus().equals(DmpStatus.Finalized)) throw new DatasetWizardCannotUnlockException("To perform this action you will need to revert DMP's finalisation"); descriptionEntity.setStatus(DescriptionStatus.Draft); apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(descriptionEntity); return; diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/GrantManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/GrantManager.java index 1f9e7d7a5..b16aa7500 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/GrantManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/GrantManager.java @@ -6,7 +6,6 @@ import eu.eudat.data.query.items.table.grant.GrantTableRequest; import eu.eudat.exceptions.grant.GrantWithDMPsDeleteException; import eu.eudat.logic.builders.model.models.GrantBuilder; import eu.eudat.data.dao.entities.GrantDao; -import eu.eudat.data.old.DMP; import eu.eudat.logic.proxy.config.ExternalUrlCriteria; import eu.eudat.logic.services.operations.DatabaseRepository; import eu.eudat.logic.utilities.helpers.ListHelper; @@ -180,9 +179,10 @@ public class GrantManager { public void delete(UUID uuid) throws InvalidApplicationException { eu.eudat.data.old.Grant oldGrant = apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().find(uuid); - if (oldGrant.getDmps().size() > 0) - throw new GrantWithDMPsDeleteException("You cannot Remove Grants with DMPs"); - oldGrant.setStatus(DMP.DMPStatus.DELETED.getValue()); + //TODO +// if (oldGrant.getDmps().size() > 0) +// throw new GrantWithDMPsDeleteException("You cannot Remove Grants with DMPs"); +// oldGrant.setStatus(DMP.DMPStatus.DELETED.getValue()); apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(oldGrant); } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/InvitationsManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/InvitationsManager.java index b1f9b7c0a..b67c27f52 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/InvitationsManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/InvitationsManager.java @@ -1,13 +1,16 @@ package eu.eudat.logic.managers; +import eu.eudat.commons.enums.DmpUserRole; +import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.scope.user.UserScope; -import eu.eudat.data.old.DMP; -import eu.eudat.data.old.UserDMP; +import eu.eudat.data.DmpEntity; +import eu.eudat.data.DmpUserEntity; import eu.eudat.data.old.UserInfo; import eu.eudat.data.query.items.item.userinfo.UserInfoRequestItem; import eu.eudat.exceptions.security.UnauthorisedException; import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.utilities.helpers.StreamDistinctBy; +import eu.eudat.model.DmpUser; import eu.eudat.models.data.invitation.Invitation; import eu.eudat.models.data.invitation.Properties; import eu.eudat.models.data.userinfo.UserInfoInvitationModel; @@ -56,11 +59,11 @@ public class InvitationsManager { }); List alreadySignedInUsers = invitation.getUsers().stream().filter(item -> item.getId() != null).collect(Collectors.toList()); List alreadySignedInUsersEntities = alreadySignedInUsers.stream().map(UserInfoInvitationModel::toDataModel).collect(Collectors.toList()); - List userInfoToUserDmp = new LinkedList<>(); + List userInfoToUserDmp = new LinkedList<>(); for (UserInfo userInfo : alreadySignedInUsersEntities) { - UserDMP userDMP = new UserDMP(); - userDMP.setUser(userInfo); - userDMP.setRole(invitation.getRole()); + DmpUserEntity userDMP = new DmpUserEntity(); + userDMP.setUser(userInfo.getId()); + userDMP.setRole(DmpUserRole.of(invitation.getRole().shortValue())); userInfoToUserDmp.add(userDMP); /*if (!apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().areAssociated(principalUser, userInfo)) { UserAssociation userAssociation = new UserAssociation(); @@ -69,7 +72,7 @@ public class InvitationsManager { apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().createOrUpdate(userAssociation); }*/ } - DMP dataManagementPlan = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(invitation.getDataManagementPlan()); + DmpEntity dataManagementPlan = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(invitation.getDataManagementPlan()); apiContext.getUtilitiesService().getInvitationService().createInvitations(apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao(), apiContext.getUtilitiesService().getMailService(), invitation.getUsers().stream().map(UserInfoInvitationModel::toDataModel).collect(Collectors.toList()), dataManagementPlan, invitation.getRole(), principalUser); apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), userInfoToUserDmp, dataManagementPlan); } @@ -83,80 +86,86 @@ public class InvitationsManager { return userAssociation.getFirstUser(); } }).collect(Collectors.toList());*/ - List users = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao() - .getAuthenticated(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().asQueryable() - .where(((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()))), this.userScope.getUserId(), Stream.of(0, 1).collect(Collectors.toList())) - .toList().stream().map(DMP::getUsers).flatMap(Collection::stream).map(UserDMP::getUser) - .filter(userInfo -> !userInfo.getId().equals(this.userScope.getUserIdSafe())).filter(StreamDistinctBy.distinctByKey(UserInfo::getId)).collect(Collectors.toList()); + List users = new ArrayList<>(); + //TODO +// apiContext.getOperationsContext().getDatabaseRepository().getDmpDao() +// .getAuthenticated(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().asQueryable() +// .where(((builder, root) -> builder.notEqual(root.get("isActive"), IsActive.Inactive))), this.userScope.getUserId(), Stream.of(0, 1).collect(Collectors.toList())) +// .toList().stream().map(DmpEntity::getUsers).flatMap(Collection::stream).map(DmpUser::getUser) +// .filter(userInfo -> !userInfo.getId().equals(this.userScope.getUserIdSafe())).filter(StreamDistinctBy.distinctByKey(UserInfo::getId)).collect(Collectors.toList()); List userModels = users.stream().map(userInfo -> new UserInfoInvitationModel().fromDataModel(userInfo)).collect(Collectors.toList()); return userModels; } public List getUsersWithCriteria(UserInfoRequestItem userInfoRequestItem) throws IllegalAccessException, InstantiationException, InvalidApplicationException { - List users = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao() - .getAuthenticated(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().asQueryable() - .where(((builder, root) -> - builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()))), this.userScope.getUserId(), Stream.of(0, 1).collect(Collectors.toList())) - .toList().stream().map(DMP::getUsers).flatMap(Collection::stream).map(UserDMP::getUser) - .filter(userInfo -> !userInfo.getId().equals(this.userScope.getUserIdSafe())).filter(StreamDistinctBy.distinctByKey(UserInfo::getId)) - .filter(userInfo -> (userInfoRequestItem == null || userInfoRequestItem.getCriteria() == null || userInfoRequestItem.getCriteria().getLike() == null - || userInfo.getName().toLowerCase().contains(userInfoRequestItem.getCriteria().getLike().toLowerCase()) - || (userInfo.getEmail().toLowerCase().contains(userInfoRequestItem.getCriteria().getLike().toLowerCase())))) - .collect(Collectors.toList()); -// .where((builder, root) -> builder.like(builder.upper(root.get("name")), "%" + userInfoRequestItem.getCriteria().getLike().toUpperCase() + "%")) - - List userModels = users.stream().map(userInfo -> new UserInfoInvitationModel().fromDataModel(userInfo)).collect(Collectors.toList()); - return userModels; + //TODO +// List users = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao() +// .getAuthenticated(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().asQueryable() +// .where(((builder, root) -> +// builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()))), this.userScope.getUserId(), Stream.of(0, 1).collect(Collectors.toList())) +// .toList().stream().map(DMP::getUsers).flatMap(Collection::stream).map(UserDMP::getUser) +// .filter(userInfo -> !userInfo.getId().equals(this.userScope.getUserIdSafe())).filter(StreamDistinctBy.distinctByKey(UserInfo::getId)) +// .filter(userInfo -> (userInfoRequestItem == null || userInfoRequestItem.getCriteria() == null || userInfoRequestItem.getCriteria().getLike() == null +// || userInfo.getName().toLowerCase().contains(userInfoRequestItem.getCriteria().getLike().toLowerCase()) +// || (userInfo.getEmail().toLowerCase().contains(userInfoRequestItem.getCriteria().getLike().toLowerCase())))) +// .collect(Collectors.toList()); +//// .where((builder, root) -> builder.like(builder.upper(root.get("name")), "%" + userInfoRequestItem.getCriteria().getLike().toUpperCase() + "%")) +// +// List userModels = users.stream().map(userInfo -> new UserInfoInvitationModel().fromDataModel(userInfo)).collect(Collectors.toList()); +// return userModels; + return new ArrayList<>(); } public UUID assignUserAcceptedInvitation(UUID invitationID) throws UnauthorisedException, JAXBException, IOException, InvalidApplicationException { - eu.eudat.data.old.Invitation invitation = apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().find(invitationID); - if (invitation == null) - throw new UnauthorisedException("There is no Data Management Plan assigned to this Link"); - if (invitation.getAcceptedInvitation()) return invitation.getDmp().getId(); //throw new UnauthorisedException("This Url Has Expired"); - JAXBContext context = JAXBContext.newInstance(Properties.class); - Unmarshaller unmarshaller = context.createUnmarshaller(); - Properties properties = (Properties) unmarshaller.unmarshal(new StringReader(invitation.getProperties())); - UserInfo invitedUser = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId()); - QueryableList userDMPQueryableList = apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where(((builder, root) -> builder.and(builder.equal(root.get("dmp").get("id"), invitation.getDmp().getId()), builder.equal(root.get("user").get("id"), invitedUser.getId())))); - UserDMP existingUserDMP = userDMPQueryableList.getSingleOrDefault(); - if (existingUserDMP != null) { - if (properties.getRole() != null && existingUserDMP.getRole() > properties.getRole()) { - existingUserDMP.setRole(properties.getRole()); - DMP datamanagementPlan = invitation.getDmp(); - apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(existingUserDMP); - apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), existingUserDMP, datamanagementPlan); - invitation.setAcceptedInvitation(true); - apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().createOrUpdate(invitation); - datamanagementPlan.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), datamanagementPlan.getId())).toList())); - //dataManagementPlanManager.updateIndex(datamanagementPlan); //TODO - return datamanagementPlan.getId(); - } - } else { - UserDMP userDMP = new UserDMP(); - userDMP.setUser(invitedUser); - userDMP.setDmp(invitation.getDmp()); - - if (properties.getRole() != null) { - userDMP.setRole(properties.getRole()); - } else { - userDMP.setRole(UserDMP.UserDMPRoles.USER.getValue()); - } - /*if (!apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().areAssociated(invitedUser, invitation.getUser())) { - UserAssociation userAssociation = new UserAssociation(); - userAssociation.setFirstUser(invitedUser); - userAssociation.setSecondUser(invitation.getUser()); - apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().createOrUpdate(userAssociation); - }*/ - DMP datamanagementPlan = invitation.getDmp(); - apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP); - apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), userDMP, datamanagementPlan); - invitation.setAcceptedInvitation(true); - apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().createOrUpdate(invitation); - datamanagementPlan.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), datamanagementPlan.getId())).toList())); -// dataManagementPlanManager.updateIndex(datamanagementPlan); //TODo - return datamanagementPlan.getId(); - } - return invitation.getDmp().getId(); + //TODO +// eu.eudat.data.old.Invitation invitation = apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().find(invitationID); +// if (invitation == null) +// throw new UnauthorisedException("There is no Data Management Plan assigned to this Link"); +// if (invitation.getAcceptedInvitation()) return invitation.getDmp().getId(); //throw new UnauthorisedException("This Url Has Expired"); +// JAXBContext context = JAXBContext.newInstance(Properties.class); +// Unmarshaller unmarshaller = context.createUnmarshaller(); +// Properties properties = (Properties) unmarshaller.unmarshal(new StringReader(invitation.getProperties())); +// UserInfo invitedUser = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId()); +// QueryableList userDMPQueryableList = apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where(((builder, root) -> builder.and(builder.equal(root.get("dmp").get("id"), invitation.getDmp().getId()), builder.equal(root.get("user").get("id"), invitedUser.getId())))); +// UserDMP existingUserDMP = userDMPQueryableList.getSingleOrDefault(); +// if (existingUserDMP != null) { +// if (properties.getRole() != null && existingUserDMP.getRole() > properties.getRole()) { +// existingUserDMP.setRole(properties.getRole()); +// DMP datamanagementPlan = invitation.getDmp(); +// apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(existingUserDMP); +// apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), existingUserDMP, datamanagementPlan); +// invitation.setAcceptedInvitation(true); +// apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().createOrUpdate(invitation); +// datamanagementPlan.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), datamanagementPlan.getId())).toList())); +// //dataManagementPlanManager.updateIndex(datamanagementPlan); //TODO +// return datamanagementPlan.getId(); +// } +// } else { +// UserDMP userDMP = new UserDMP(); +// userDMP.setUser(invitedUser); +// userDMP.setDmp(invitation.getDmp()); +// +// if (properties.getRole() != null) { +// userDMP.setRole(properties.getRole()); +// } else { +// userDMP.setRole(UserDMP.UserDMPRoles.USER.getValue()); +// } +// /*if (!apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().areAssociated(invitedUser, invitation.getUser())) { +// UserAssociation userAssociation = new UserAssociation(); +// userAssociation.setFirstUser(invitedUser); +// userAssociation.setSecondUser(invitation.getUser()); +// apiContext.getOperationsContext().getDatabaseRepository().getUserAssociationDao().createOrUpdate(userAssociation); +// }*/ +// DmpEntity datamanagementPlan = invitation.getDmp(); +// apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP); +// apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), userDMP, datamanagementPlan); +// invitation.setAcceptedInvitation(true); +// apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().createOrUpdate(invitation); +// datamanagementPlan.setUsers(new HashSet<>(apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("dmp").get("id"), datamanagementPlan.getId())).toList())); +//// dataManagementPlanManager.updateIndex(datamanagementPlan); //TODo +// return datamanagementPlan.getId(); +// } +// return invitation.getDmp().getId(); + return null; } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MergeEmailConfirmationManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MergeEmailConfirmationManager.java index a91b2e2f7..dc0d6db61 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MergeEmailConfirmationManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MergeEmailConfirmationManager.java @@ -2,8 +2,8 @@ package eu.eudat.logic.managers; import eu.eudat.commons.scope.user.UserScope; import eu.eudat.data.CredentialEntity; +import eu.eudat.data.DmpUserEntity; import eu.eudat.data.old.EmailConfirmation; -import eu.eudat.data.old.UserDMP; import eu.eudat.data.old.UserInfo; import eu.eudat.exceptions.emailconfirmation.HasConfirmedEmailException; import eu.eudat.exceptions.emailconfirmation.TokenExpiredException; @@ -20,7 +20,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.transaction.Transactional; import javax.management.InvalidApplicationException; -import java.io.IOException; import java.util.*; @Component @@ -88,9 +87,9 @@ public class MergeEmailConfirmationManager { CredentialEntity credential = databaseRepository.getCredentialDao().asQueryable().where((builder, root) -> builder.and(builder.equal(root.get("userId"), oldUser.getId()), builder.equal(root.get("provider"), provider))).getSingle(); credential.setUserId(newUser.getId()); databaseRepository.getCredentialDao().createOrUpdate(credential); - List userDmps = databaseRepository.getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("user"), oldUser)).toList(); + List userDmps = databaseRepository.getUserDmpDao().asQueryable().where((builder, root) -> builder.equal(root.get("user"), oldUser)).toList(); userDmps.forEach(userDmp -> { - userDmp.setUser(newUser); + userDmp.setUser(newUser.getId()); databaseRepository.getUserDmpDao().createOrUpdate(userDmp); }); //TODO diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/QuickWizardManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/QuickWizardManager.java index 4756fd290..8027ef3d5 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/QuickWizardManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/QuickWizardManager.java @@ -1,6 +1,9 @@ package eu.eudat.logic.managers; +import eu.eudat.commons.enums.DmpUserRole; import eu.eudat.commons.scope.user.UserScope; +import eu.eudat.data.DmpEntity; +import eu.eudat.data.DmpUserEntity; import eu.eudat.data.dao.criteria.FunderCriteria; import eu.eudat.data.dao.criteria.GrantCriteria; import eu.eudat.data.dao.criteria.ProjectCriteria; @@ -50,22 +53,25 @@ public class QuickWizardManager { return databaseRepository.getProjectDao().createOrUpdate(projectEntity); } - public DMP createOrUpdate(DataManagementPlan dataManagementPlan, Funder funderEntity) throws Exception { - DMP newDmp = dataManagementPlan.toDataModel(); + public DmpEntity createOrUpdate(DataManagementPlan dataManagementPlan, Funder funderEntity) throws Exception { + DmpEntity newDmp = dataManagementPlan.toDataModel(); if (funderEntity != null) { - newDmp.getGrant().setFunder(funderEntity); + //TODO + //newDmp.getGrant().setFunder(funderEntity); } UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId()); createFunderIfItDoesntExist(newDmp, user); createGrantIfItDoesntExist(newDmp, user); - if (newDmp.getProject() == null) { - newDmp.setProject(new Project()); - newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant())); - } + //TODO +// if (newDmp.getProject() == null) { +// newDmp.setProject(new Project()); +// newDmp.setProject(newDmp.getProject().projectFromGrant(newDmp.getGrant())); +// } createProjectIfItDoesntExist(newDmp, user); - apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant()); - DMP dmpret = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp); + //TODO + //apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant()); + DmpEntity dmpret = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp); if (dataManagementPlan.getAssociatedUsers().size() == 0) assignUser(newDmp, user, apiContext); @@ -80,54 +86,54 @@ public class QuickWizardManager { // apiContext.getOperationsContext().getElasticRepository().getDmpRepository().createOrUpdate(elastic); // } - private void assignUser(DMP dmp, UserInfo userInfo, ApiContext apiContext) { - UserDMP userDMP = new UserDMP(); - userDMP.setDmp(dmp); - userDMP.setUser(userInfo); - userDMP.setRole(UserDMP.UserDMPRoles.OWNER.getValue()); + private void assignUser(DmpEntity dmp, UserInfo userInfo, ApiContext apiContext) { + DmpUserEntity userDMP = new DmpUserEntity(); + userDMP.setDmp(dmp.getId()); + userDMP.setUser(userInfo.getId()); + userDMP.setRole(DmpUserRole.User); apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP); } - private void createGrantIfItDoesntExist(DMP newDmp, UserInfo userInfo) throws InvalidApplicationException { - if (newDmp.getGrant() != null) { - Grant grant = newDmp.getGrant(); - GrantCriteria criteria = new GrantCriteria(); - criteria.setReference(grant.getReference()); - Grant grantEntity = databaseRepository.getGrantDao().getWithCriteria(criteria).getSingleOrDefault(); - if (grantEntity != null) grant.setId(grantEntity.getId()); - else { - grant.setType(Grant.GrantType.EXTERNAL.getValue()); - databaseRepository.getGrantDao().createOrUpdate(grant); - } - } + private void createGrantIfItDoesntExist(DmpEntity newDmp, UserInfo userInfo) throws InvalidApplicationException { +// if (newDmp.getGrant() != null) { +// Grant grant = newDmp.getGrant(); +// GrantCriteria criteria = new GrantCriteria(); +// criteria.setReference(grant.getReference()); +// Grant grantEntity = databaseRepository.getGrantDao().getWithCriteria(criteria).getSingleOrDefault(); +// if (grantEntity != null) grant.setId(grantEntity.getId()); +// else { +// grant.setType(Grant.GrantType.EXTERNAL.getValue()); +// databaseRepository.getGrantDao().createOrUpdate(grant); +// } +// } } - private void createFunderIfItDoesntExist(DMP newDmp, UserInfo userInfo) throws InvalidApplicationException { - if (newDmp.getGrant().getFunder() != null) { - Funder funder = newDmp.getGrant().getFunder(); - FunderCriteria criteria = new FunderCriteria(); - criteria.setReference(funder.getReference()); - Funder funderEntity = databaseRepository.getFunderDao().getWithCritetia(criteria).getSingleOrDefault(); - if (funderEntity != null) funder.setId(funderEntity.getId()); - else { - funder.setType(Funder.FunderType.EXTERNAL.getValue()); - databaseRepository.getFunderDao().createOrUpdate(funder); - } - } + private void createFunderIfItDoesntExist(DmpEntity newDmp, UserInfo userInfo) throws InvalidApplicationException { +// if (newDmp.getGrant().getFunder() != null) { //TODO +// Funder funder = newDmp.getGrant().getFunder(); +// FunderCriteria criteria = new FunderCriteria(); +// criteria.setReference(funder.getReference()); +// Funder funderEntity = databaseRepository.getFunderDao().getWithCritetia(criteria).getSingleOrDefault(); +// if (funderEntity != null) funder.setId(funderEntity.getId()); +// else { +// funder.setType(Funder.FunderType.EXTERNAL.getValue()); +// databaseRepository.getFunderDao().createOrUpdate(funder); +// } +// } } - private void createProjectIfItDoesntExist(DMP newDmp, UserInfo userInfo) throws InvalidApplicationException { - if (newDmp.getProject() != null) { - Project project = newDmp.getProject(); - ProjectCriteria criteria = new ProjectCriteria(); - criteria.setReference(project.getReference()); - Project projectEntity = databaseRepository.getProjectDao().getWithCritetia(criteria).getSingleOrDefault(); - if (projectEntity != null) project.setId(projectEntity.getId()); - else { - if (project.getId() == null) project.setId(UUID.randomUUID()); - project.setType(Project.ProjectType.EXTERNAL.getValue()); - databaseRepository.getProjectDao().createOrUpdate(project); - } - } + private void createProjectIfItDoesntExist(DmpEntity newDmp, UserInfo userInfo) throws InvalidApplicationException { +// if (newDmp.getProject() != null) { //TODO +// Project project = newDmp.getProject(); +// ProjectCriteria criteria = new ProjectCriteria(); +// criteria.setReference(project.getReference()); +// Project projectEntity = databaseRepository.getProjectDao().getWithCritetia(criteria).getSingleOrDefault(); +// if (projectEntity != null) project.setId(projectEntity.getId()); +// else { +// if (project.getId() == null) project.setId(UUID.randomUUID()); +// project.setType(Project.ProjectType.EXTERNAL.getValue()); +// databaseRepository.getProjectDao().createOrUpdate(project); +// } +// } } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/RDAManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/RDAManager.java index 3ef75fff1..6d9c99a79 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/RDAManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/RDAManager.java @@ -2,7 +2,7 @@ package eu.eudat.logic.managers; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import eu.eudat.data.old.DMP; +import eu.eudat.data.DmpEntity; import eu.eudat.models.rda.Dmp; import eu.eudat.models.rda.RDAModel; import eu.eudat.models.rda.mapper.DmpRDAMapper; @@ -26,7 +26,7 @@ public class RDAManager { } @Transactional - public String convertToRDA(DMP dmp) throws JsonProcessingException, InvalidApplicationException { + public String convertToRDA(DmpEntity dmp) throws JsonProcessingException, InvalidApplicationException { String result = ""; Dmp rdaDmp = dmpRDAMapper.toRDA(dmp); @@ -41,7 +41,7 @@ public class RDAManager { return result; } - public DMP convertToEntity(String json, String[] profiles) throws IOException, InvalidApplicationException { + public DmpEntity convertToEntity(String json, String[] profiles) throws IOException, InvalidApplicationException { ObjectMapper mapper = new ObjectMapper(); Dmp rda = mapper.readValue(json, RDAModel.class).getDmp(); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/UserManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/UserManager.java index 559e669cf..2a063bd6e 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/UserManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/UserManager.java @@ -5,9 +5,9 @@ import eu.eudat.authorization.Permission; import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity; import eu.eudat.data.CredentialEntity; +import eu.eudat.data.DmpEntity; import eu.eudat.data.dao.criteria.DataManagementPlanCriteria; import eu.eudat.data.dao.entities.UserInfoDao; -import eu.eudat.data.old.DMP; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.old.UserInfo; import eu.eudat.data.old.UserRole; @@ -98,8 +98,8 @@ public class UserManager { List roles = new LinkedList<>(); DataManagementPlanCriteria criteria = new DataManagementPlanCriteria(); criteria.setAllVersions(false); - QueryableList items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(criteria); - List dmps = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getAuthenticated(items, userId, roles).take(5).toList(); + QueryableList items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(criteria); + List dmps = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getAuthenticated(items, userId, roles).take(5).toList(); profile.setAssociatedDmps(dmps.stream().map(x -> new DataManagementPlan().fromDataModel(x)).collect(Collectors.toList())); return profile; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/InvitationService.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/InvitationService.java index 56ba8f49b..90e48cc91 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/InvitationService.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/InvitationService.java @@ -1,13 +1,14 @@ package eu.eudat.logic.services.utilities; +import eu.eudat.data.DmpEntity; +import eu.eudat.data.DmpUserEntity; import eu.eudat.data.dao.entities.DMPDao; import eu.eudat.data.dao.entities.InvitationDao; -import eu.eudat.data.old.DMP; import eu.eudat.data.old.Invitation; -import eu.eudat.data.old.UserDMP; import eu.eudat.data.old.UserInfo; +import eu.eudat.models.rda.Dmp; import eu.eudat.service.mail.MailService; import jakarta.mail.MessagingException; import java.util.List; @@ -15,11 +16,11 @@ import java.util.concurrent.CompletableFuture; public interface InvitationService { - void assignToDmp(DMPDao dmpDao, List users, DMP dmp); + void assignToDmp(DMPDao dmpDao, List users, DmpEntity dmp); - void assignToDmp(DMPDao dmpDao, UserDMP user, DMP dmp); + void assignToDmp(DMPDao dmpDao, DmpUserEntity user, DmpEntity dmp); - void createInvitations(InvitationDao invitationDao, MailService mailService, List users, DMP dmp, Integer role, UserInfo creator) throws MessagingException; + void createInvitations(InvitationDao invitationDao, MailService mailService, List users, DmpEntity dmp, Integer role, UserInfo creator) throws MessagingException; - CompletableFuture sendInvitationAsync(DMP dmp, Invitation invitation, String recipient, MailService mailService, Integer role) throws MessagingException; + CompletableFuture sendInvitationAsync(DmpEntity dmp, Invitation invitation, String recipient, MailService mailService, Integer role) throws MessagingException; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/InvitationServiceImpl.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/InvitationServiceImpl.java index 96db56535..c0ff4b482 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/InvitationServiceImpl.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/InvitationServiceImpl.java @@ -1,11 +1,11 @@ package eu.eudat.logic.services.utilities; +import eu.eudat.data.DmpEntity; +import eu.eudat.data.DmpUserEntity; import eu.eudat.data.dao.entities.DMPDao; import eu.eudat.data.dao.entities.InvitationDao; -import eu.eudat.data.old.DMP; import eu.eudat.data.old.Invitation; -import eu.eudat.data.old.UserDMP; import eu.eudat.data.old.UserInfo; import eu.eudat.models.data.invitation.Properties; import eu.eudat.service.mail.MailService; @@ -37,26 +37,26 @@ public class InvitationServiceImpl implements InvitationService { } @Override - public void assignToDmp(DMPDao dmpDao, List users, DMP dmp) { - for (UserDMP user : users) { - dmp.getUsers().add(user); - } + public void assignToDmp(DMPDao dmpDao, List users, DmpEntity dmp) { +// for (DmpUserEntity user : users) { +// dmp.getUsers().add(user); +// } //TODO dmpDao.createOrUpdate(dmp); } @Override - public void assignToDmp(DMPDao dmpDao, UserDMP user, DMP dmp) { - if (!dmp.getUsers().stream().map(x -> x.getUser().getId()).collect(Collectors.toList()).contains(user.getId())) { - dmp.getUsers().add(user); - dmpDao.createOrUpdate(dmp); - } + public void assignToDmp(DMPDao dmpDao, DmpUserEntity user, DmpEntity dmp) { +// if (!dmp.getUsers().stream().map(x -> x.getUser().getId()).collect(Collectors.toList()).contains(user.getId())) { +// dmp.getUsers().add(user); +// dmpDao.createOrUpdate(dmp); +// } //TODO } @Override - public void createInvitations(InvitationDao invitationDao, MailService mailService, List users, DMP dmp, Integer role, UserInfo creator) throws MessagingException { + public void createInvitations(InvitationDao invitationDao, MailService mailService, List users, DmpEntity dmp, Integer role, UserInfo creator) throws MessagingException { for (UserInfo userInfo : users) { Invitation invitation = new Invitation(); - invitation.setDmp(dmp); +// invitation.setDmp(dmp); //TODO invitation.setInvitationEmail(userInfo.getEmail()); invitation.setUser(creator); invitation.setToken(UUID.randomUUID()); @@ -78,7 +78,7 @@ public class InvitationServiceImpl implements InvitationService { } @Override - public CompletableFuture sendInvitationAsync(DMP dmp, Invitation invitation, String recipient, MailService mailService, Integer role) { + public CompletableFuture sendInvitationAsync(DmpEntity dmp, Invitation invitation, String recipient, MailService mailService, Integer role) { return CompletableFuture.runAsync(() -> { SimpleMail mail = new SimpleMail(); mail.setSubject(createSubject(dmp, mailService.getMailTemplateSubject())); @@ -92,17 +92,17 @@ public class InvitationServiceImpl implements InvitationService { }); } - private String createSubject(DMP dmp, String templateSubject) { + private String createSubject(DmpEntity dmp, String templateSubject) { String subject = templateSubject.replace("{dmpname}", dmp.getLabel()); return subject; } - private String createContent(UUID invitationID, DMP dmp, String recipient, String templateContent, Integer role) { + private String createContent(UUID invitationID, DmpEntity dmp, String recipient, String templateContent, Integer role) { String content = templateContent.replace("{dmpname}", dmp.getLabel()); content = content.replace("{invitationID}", invitationID.toString()); content = content.replace("{recipient}", recipient); content = content.replace("{host}", this.environment.getProperty("dmp.domain")); - content = content.replace("{dmprole}", UserDMP.UserDMPRoles.fromInteger(role).name()); +// content = content.replace("{dmprole}", UserDMP.UserDMPRoles.fromInteger(role).name()); //TODO return content; } 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 7991b6ff6..3e7a392fd 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 @@ -5,8 +5,8 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import eu.eudat.commons.enums.FieldDataComboBoxType; import eu.eudat.commons.types.descriptiontemplate.fielddata.*; -import eu.eudat.data.old.DMP; import eu.eudat.data.DescriptionEntity; +import eu.eudat.data.DmpEntity; import eu.eudat.data.old.Organisation; import eu.eudat.data.old.Researcher; import eu.eudat.logic.proxy.config.configloaders.ConfigLoader; @@ -1014,7 +1014,7 @@ public class WordBuilder { return -1; } - public void fillFirstPage(DMP dmpEntity, DescriptionEntity descriptionEntityEntity, XWPFDocument document, boolean isDataset) { + public void fillFirstPage(DmpEntity dmpEntity, DescriptionEntity descriptionEntityEntity, XWPFDocument document, boolean isDataset) { int parPos = 0; int descrParPos = -1; XWPFParagraph descrPar = null; @@ -1046,23 +1046,25 @@ public class WordBuilder { r.setText(text, 0); } else if(text.equals("{ARGOS.DMP.RESEARCHERS}")) { String researchersNames = ""; - Set researchers = dmpEntity.getResearchers(); - int i = 0; - for(Researcher researcher : researchers){ - i++; - researchersNames += researcher.getLabel() + (i < researchers.size() ? ", " : ""); - } + //TODO +// Set researchers = dmpEntity.getResearchers(); +// int i = 0; +// for(Researcher researcher : researchers){ +// i++; +// researchersNames += researcher.getLabel() + (i < researchers.size() ? ", " : ""); +// } text = text.replace("{ARGOS.DMP.RESEARCHERS}", researchersNames); r.setText(text, 0); r.setFontSize(17); } else if(text.equals("{ARGOS.DMP.ORGANIZATIONS}")) { String organisationsNames = ""; - Set organisations = dmpEntity.getOrganisations(); - int i = 0; - for(Organisation organisation : organisations){ - i++; - organisationsNames += organisation.getLabel() + (i < organisations.size() ? ", " : ""); - } + //TODO +// Set organisations = dmpEntity.getOrganisations(); +// int i = 0; +// for(Organisation organisation : organisations){ +// i++; +// organisationsNames += organisation.getLabel() + (i < organisations.size() ? ", " : ""); +// } text = text.replace("{ARGOS.DMP.ORGANIZATIONS}", organisationsNames); r.setText(text, 0); r.setFontSize(17); @@ -1092,31 +1094,32 @@ public class WordBuilder { XWPFTable tbl = document.getTables().get(0); Iterator it = tbl.getRows().iterator(); it.next(); // skip first row - if(it.hasNext() && dmpEntity.getGrant() != null){ - XWPFParagraph p = it.next().getCell(0).getParagraphs().get(0); - XWPFRun run = p.createRun(); - run.setText(dmpEntity.getGrant().getFunder().getLabel()); - run.setFontSize(17); - p.setAlignment(ParagraphAlignment.CENTER); - } - it = tbl.getRows().iterator(); - it.next(); - if(it.hasNext() && dmpEntity.getGrant() != null){ - XWPFParagraph p = it.next().getCell(1).getParagraphs().get(0); - XWPFRun run = p.createRun(); - String text = dmpEntity.getGrant().getLabel(); - String reference = dmpEntity.getGrant().getReference(); - if(reference != null) { - String[] parts = reference.split("::"); - text += parts.length > 1 ? "/ No "+parts[parts.length - 1] : ""; - } - run.setText(text); - run.setFontSize(17); - p.setAlignment(ParagraphAlignment.CENTER); - } + //TODO +// if(it.hasNext() && dmpEntity.getGrant() != null){ +// XWPFParagraph p = it.next().getCell(0).getParagraphs().get(0); +// XWPFRun run = p.createRun(); +// run.setText(dmpEntity.getGrant().getFunder().getLabel()); +// run.setFontSize(17); +// p.setAlignment(ParagraphAlignment.CENTER); +// } +// it = tbl.getRows().iterator(); +// it.next(); +// if(it.hasNext() && dmpEntity.getGrant() != null){ +// XWPFParagraph p = it.next().getCell(1).getParagraphs().get(0); +// XWPFRun run = p.createRun(); +// String text = dmpEntity.getGrant().getLabel(); +// String reference = dmpEntity.getGrant().getReference(); +// if(reference != null) { +// String[] parts = reference.split("::"); +// text += parts.length > 1 ? "/ No "+parts[parts.length - 1] : ""; +// } +// run.setText(text); +// run.setFontSize(17); +// p.setAlignment(ParagraphAlignment.CENTER); +// } } - public void fillFooter(DMP dmpEntity, DescriptionEntity descriptionEntityEntity, XWPFDocument document, boolean isDataset) { + public void fillFooter(DmpEntity dmpEntity, DescriptionEntity descriptionEntityEntity, XWPFDocument document, boolean isDataset) { document.getFooterList().forEach(xwpfFooter -> { List runs = xwpfFooter.getParagraphs().get(0).getRuns(); if(runs != null){ @@ -1131,26 +1134,27 @@ public class WordBuilder { text = text.replace("{ARGOS.DATASET.TITLE}", descriptionEntityEntity.getLabel()); r.setText(text, 0); } - if(text.contains("{ARGOS.DMP.LICENSE}")){ - try{ - Map license = ((Map) mapper.readValue(dmpEntity.getExtraProperties(), Map.class).get("license")); - text = text.replace("{ARGOS.DMP.LICENSE}", license.get("pid")); - } - catch (JsonProcessingException | NullPointerException e){ - text = text.replace("{ARGOS.DMP.LICENSE}", "License: -"); - } - r.setText(text, 0); - } - if(text.contains("{ARGOS.DMP.DOI}")){ - if(dmpEntity.getDois() != null && !dmpEntity.getDois().isEmpty()) - text = text.replace("{ARGOS.DMP.DOI}", dmpEntity.getDois().iterator().next().getDoi()); - else - text = text.replace("{ARGOS.DMP.DOI}", "-"); - r.setText(text, 0); - } + //TODO +// if(text.contains("{ARGOS.DMP.LICENSE}")){ +// try{ +// Map license = ((Map) mapper.readValue(dmpEntity.getExtraProperties(), Map.class).get("license")); +// text = text.replace("{ARGOS.DMP.LICENSE}", license.get("pid")); +// } +// catch (JsonProcessingException | NullPointerException e){ +// text = text.replace("{ARGOS.DMP.LICENSE}", "License: -"); +// } +// r.setText(text, 0); +// } +// if(text.contains("{ARGOS.DMP.DOI}")){ +// if(dmpEntity.getDois() != null && !dmpEntity.getDois().isEmpty()) +// text = text.replace("{ARGOS.DMP.DOI}", dmpEntity.getDois().iterator().next().getDoi()); +// else +// text = text.replace("{ARGOS.DMP.DOI}", "-"); +// r.setText(text, 0); +// } if(text.contains("{ARGOS.DMP.LAST_MODIFIED}")){ DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); - text = text.replace("{ARGOS.DMP.LAST_MODIFIED}", formatter.format(dmpEntity.getModified())); + text = text.replace("{ARGOS.DMP.LAST_MODIFIED}", formatter.format(dmpEntity.getUpdatedAt())); r.setText(text, 0); } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/dashboard/recent/model/RecentDmpModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/dashboard/recent/model/RecentDmpModel.java index 537f0558f..4a183110c 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/dashboard/recent/model/RecentDmpModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/dashboard/recent/model/RecentDmpModel.java @@ -1,6 +1,6 @@ package eu.eudat.models.data.dashboard.recent.model; -import eu.eudat.data.old.DMP; +import eu.eudat.data.DmpEntity; import eu.eudat.models.data.listingmodels.UserInfoListingModel; import eu.eudat.models.data.urls.DatasetUrlListing; @@ -10,7 +10,7 @@ import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; -public class RecentDmpModel extends RecentActivityModel { +public class RecentDmpModel extends RecentActivityModel { private Map extraProperties; private List datasets; private UUID groupId; @@ -41,33 +41,33 @@ public class RecentDmpModel extends RecentActivityModel { @Override @Transactional - public RecentActivityModel fromEntity(DMP entity) { + public RecentActivityModel fromEntity(DmpEntity entity) { this.setType(RecentActivityType.DMP.getIndex()); this.setId(entity.getId().toString()); - this.setTitle(entity.getLabel()); - this.setCreated(entity.getCreated()); - this.setModified(entity.getModified()); - this.setStatus(entity.getStatus()); - this.setVersion(entity.getVersion()); - this.datasets = entity.getDataset().stream().map(dataset -> new DatasetUrlListing().fromDataModel(dataset)).collect(Collectors.toList()); - this.setFinalizedAt(entity.getFinalizedAt()); - if (entity.getGrant() != null) { - this.setGrant(entity.getGrant().getLabel()); - } - this.groupId = entity.getGroupId(); - this.setPublic(entity.isPublic()); - this.setPublishedAt(entity.getPublishedAt()); - this.setUsers(entity.getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList())); + this.setTitle(entity.getLabel()); //TODO +// this.setCreated(entity.getCreated()); +// this.setModified(entity.getModified()); +// this.setStatus(entity.getStatus()); +// this.setVersion(entity.getVersion()); +// this.datasets = entity.getDataset().stream().map(dataset -> new DatasetUrlListing().fromDataModel(dataset)).collect(Collectors.toList()); +// this.setFinalizedAt(entity.getFinalizedAt()); +// if (entity.getGrant() != null) { +// this.setGrant(entity.getGrant().getLabel()); +// } +// this.groupId = entity.getGroupId(); +// this.setPublic(entity.isPublic()); +// this.setPublishedAt(entity.getPublishedAt()); +// this.setUsers(entity.getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList())); return this; } @Override - public RecentDmpModel fromDataModel(DMP entity) { + public RecentDmpModel fromDataModel(DmpEntity entity) { return (RecentDmpModel) this.fromEntity(entity); } @Override - public DMP toDataModel() throws Exception { + public DmpEntity toDataModel() throws Exception { return null; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetwizard/DataManagentPlanListingModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetwizard/DataManagentPlanListingModel.java index a7a86c7d7..e6c019a58 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetwizard/DataManagentPlanListingModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetwizard/DataManagentPlanListingModel.java @@ -1,10 +1,10 @@ package eu.eudat.models.data.datasetwizard; -import eu.eudat.data.old.DMP; +import eu.eudat.data.DmpEntity; import eu.eudat.models.DataModel; -public class DataManagentPlanListingModel implements DataModel { +public class DataManagentPlanListingModel implements DataModel { private String id; private String label; @@ -26,14 +26,14 @@ public class DataManagentPlanListingModel implements DataModel { +public class DataManagementPlan implements DataModel { private UUID id; private String label; private UUID groupId; @@ -235,204 +236,205 @@ public class DataManagementPlan implements DataModel { } @Override - public DataManagementPlan fromDataModel(DMP entity) { + public DataManagementPlan fromDataModel(DmpEntity entity) { this.id = entity.getId(); - this.profile = entity.getProfile() != null ? new Tuple(entity.getProfile().getId(), entity.getProfile().getLabel()) : null; - this.organisations = entity.getOrganisations() != null ? entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); - this.researchers = entity.getResearchers() != null ? entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>(); - this.version = entity.getVersion(); - this.groupId = this.groupId == null ? null : entity.getGroupId(); - this.label = entity.getLabel(); - this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null; - if(entity.getGrant() != null) { - this.grant = new Grant(); - this.grant.fromDataModel(entity.getGrant()); - } - else { - this.grant = null; - } - this.creator = new eu.eudat.models.data.userinfo.UserInfo(); - this.groupId = entity.getGroupId(); - this.lockable = entity.getDataset() != null && entity.getDataset().stream().findAny().isPresent(); - if (this.properties != null) { - this.extraFields = new ArrayList<>(); - this.properties.forEach((id, value) -> { - if (value != null) { - ExtraFieldModel extraField = new ExtraFieldModel(); - extraField.setId(id); - extraField.setValue(value.toString()); - this.extraFields.add(extraField); - } - }); - } - if (entity.getUsers() != null && entity.getUsers().stream().anyMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue()))) - this.creator.fromDataModel(entity.getUsers().stream().filter(user -> user.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser()); - - if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) { - this.profiles = new LinkedList<>(); - for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) { - AssociatedProfile associatedProfile = new AssociatedProfile().fromData(dmpDescriptionProfile.getDatasetprofile()); - associatedProfile.setId(dmpDescriptionProfile.getId()); - try { - associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference>() {})); - } - catch (Exception e) { - associatedProfile.setData(null); - } - this.profiles.add(associatedProfile); - } - } - if (entity.getDataset() != null) { - if (entity.isPublic()) { - this.datasets = entity.getDataset().stream() - .filter(dataset -> !dataset.getIsActive().equals(IsActive.Inactive) && !dataset.getStatus().equals(DescriptionStatus.Canceled) && !dataset.getStatus().equals(DescriptionStatus.Draft)) - .map(x -> new DatasetWizardModel().fromDataModelNoDmp(x)).collect(Collectors.toList()); - } else { - this.datasets = entity.getDataset().stream() - .filter(dataset -> !dataset.getIsActive().equals(IsActive.Inactive) && !dataset.getStatus().equals(DescriptionStatus.Draft)) - .map(x -> new DatasetWizardModel().fromDataModelNoDmp(x)).collect(Collectors.toList()); - } - } - this.modified = entity.getModified(); - this.created = entity.getCreated(); - this.description = entity.getDescription(); - this.status = entity.getStatus(); - this.associatedUsers = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()) : new ArrayList<>(); - this.users = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); - this.dois = entity.getDois() != null ? entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>(); - - if (entity.getProject() != null) { - this.project = new Project(); - this.project = new Project().fromDataModel(entity.getProject()); - } - - if (entity.getGrant() != null && entity.getGrant().getFunder() != null) { - this.funder = new Funder(); - this.funder.fromDataModel(entity.getGrant().getFunder()); - } - this.isPublic = entity.isPublic(); - - this.extraProperties = entity.getExtraProperties() != null ? new org.json.JSONObject(entity.getExtraProperties()).toMap() : null; + //TODO +// this.profile = entity.getProfile() != null ? new Tuple(entity.getProfile().getId(), entity.getProfile().getLabel()) : null; +// this.organisations = entity.getOrganisations() != null ? entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); +// this.researchers = entity.getResearchers() != null ? entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>(); +// this.version = entity.getVersion(); +// this.groupId = this.groupId == null ? null : entity.getGroupId(); +// this.label = entity.getLabel(); +// this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null; +// if(entity.getGrant() != null) { +// this.grant = new Grant(); +// this.grant.fromDataModel(entity.getGrant()); +// } +// else { +// this.grant = null; +// } +// this.creator = new eu.eudat.models.data.userinfo.UserInfo(); +// this.groupId = entity.getGroupId(); +// this.lockable = entity.getDataset() != null && entity.getDataset().stream().findAny().isPresent(); +// if (this.properties != null) { +// this.extraFields = new ArrayList<>(); +// this.properties.forEach((id, value) -> { +// if (value != null) { +// ExtraFieldModel extraField = new ExtraFieldModel(); +// extraField.setId(id); +// extraField.setValue(value.toString()); +// this.extraFields.add(extraField); +// } +// }); +// } +// if (entity.getUsers() != null && entity.getUsers().stream().anyMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue()))) +// this.creator.fromDataModel(entity.getUsers().stream().filter(user -> user.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser()); +// +// if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) { +// this.profiles = new LinkedList<>(); +// for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) { +// AssociatedProfile associatedProfile = new AssociatedProfile().fromData(dmpDescriptionProfile.getDatasetprofile()); +// associatedProfile.setId(dmpDescriptionProfile.getId()); +// try { +// associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference>() {})); +// } +// catch (Exception e) { +// associatedProfile.setData(null); +// } +// this.profiles.add(associatedProfile); +// } +// } +// if (entity.getDataset() != null) { +// if (entity.isPublic()) { +// this.datasets = entity.getDataset().stream() +// .filter(dataset -> !dataset.getIsActive().equals(IsActive.Inactive) && !dataset.getStatus().equals(DescriptionStatus.Canceled) && !dataset.getStatus().equals(DescriptionStatus.Draft)) +// .map(x -> new DatasetWizardModel().fromDataModelNoDmp(x)).collect(Collectors.toList()); +// } else { +// this.datasets = entity.getDataset().stream() +// .filter(dataset -> !dataset.getIsActive().equals(IsActive.Inactive) && !dataset.getStatus().equals(DescriptionStatus.Draft)) +// .map(x -> new DatasetWizardModel().fromDataModelNoDmp(x)).collect(Collectors.toList()); +// } +// } +// this.modified = entity.getModified(); +// this.created = entity.getCreated(); +// this.description = entity.getDescription(); +// this.status = entity.getStatus(); +// this.associatedUsers = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()) : new ArrayList<>(); +// this.users = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); +// this.dois = entity.getDois() != null ? entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>(); +// +// if (entity.getProject() != null) { +// this.project = new Project(); +// this.project = new Project().fromDataModel(entity.getProject()); +// } +// +// if (entity.getGrant() != null && entity.getGrant().getFunder() != null) { +// this.funder = new Funder(); +// this.funder.fromDataModel(entity.getGrant().getFunder()); +// } +// this.isPublic = entity.isPublic(); +// +// this.extraProperties = entity.getExtraProperties() != null ? new org.json.JSONObject(entity.getExtraProperties()).toMap() : null; return this; } @Override - public DMP toDataModel() throws Exception { - DMP dataManagementPlanEntity = new DMP(); - if (this.profile != null) { - DmpBlueprintEntity dmpBlueprint = new DmpBlueprintEntity(); - dmpBlueprint.setId(this.profile.getId()); - dataManagementPlanEntity.setProfile(dmpBlueprint); - } - dataManagementPlanEntity.setId(this.id); - if (this.organisations != null && !this.organisations.isEmpty()) - dataManagementPlanEntity.setOrganisations(new HashSet<>(this.organisations.stream().map(item -> item.toDataModel()).collect(Collectors.toList()))); - if (this.researchers != null && !this.researchers.isEmpty()) - dataManagementPlanEntity.setResearchers(new HashSet<>(this.researchers.stream().map(item -> item.toDataModel()).collect(Collectors.toList()))); - dataManagementPlanEntity.setVersion(this.version); - dataManagementPlanEntity.setLabel(this.label); - if (this.grant != null) dataManagementPlanEntity.setGrant(this.grant.toDataModel()); - dataManagementPlanEntity.setStatus((short) this.status); - dataManagementPlanEntity.setDescription(this.description); - if (this.project != null) { - dataManagementPlanEntity.setProject(this.project.toDataModel()); - } - if (this.profiles != null) { - Set dmpDatasetProfiles = new HashSet<>(); - for (AssociatedProfile profile : this.profiles) { - DMPDatasetProfile dmpDatasetProfile = new DMPDatasetProfile(); - dmpDatasetProfile.setId(profile.getId()); - dmpDatasetProfile.setDmp(dataManagementPlanEntity); - dmpDatasetProfile.setDatasetprofile(profile.toData()); - dmpDatasetProfile.setData(new ObjectMapper().writeValueAsString(profile.getData())); - dmpDatasetProfiles.add(dmpDatasetProfile); - } - dataManagementPlanEntity.setAssociatedDmps(dmpDatasetProfiles); - } - if(this.extraFields != null) { - this.properties = this.extraFields.stream().collect(Collectors.toMap(ExtraFieldModel::getId, ExtraFieldModel::getValue)); - } - dataManagementPlanEntity.setProperties(this.properties != null ? JSONObject.toJSONString(this.properties) : null); - dataManagementPlanEntity.setGroupId(this.groupId != null ? this.groupId : UUID.randomUUID()); - dataManagementPlanEntity.setModified(this.modified != null ? this.modified : new Date()); - dataManagementPlanEntity.setCreated(this.created != null ? this.created : new Date()); - if (this.dynamicFields != null) - dataManagementPlanEntity.setDmpProperties(JSONObject.toJSONString(this.dynamicFields.stream().filter(item -> item.getValue() != null).collect(Collectors.toMap(DynamicFieldWithValue::getId, DynamicFieldWithValue::getValue)))); - - if (this.isPublic != null) { - dataManagementPlanEntity.setPublic(this.isPublic); - } - - dataManagementPlanEntity.setExtraProperties(this.extraProperties != null ? JSONObject.toJSONString(this.extraProperties) : null); + public DmpEntity toDataModel() throws Exception { + DmpEntity dataManagementPlanEntity = new DmpEntity(); //TODO +// if (this.profile != null) { +// DmpBlueprintEntity dmpBlueprint = new DmpBlueprintEntity(); +// dmpBlueprint.setId(this.profile.getId()); +// dataManagementPlanEntity.setProfile(dmpBlueprint); +// } +// dataManagementPlanEntity.setId(this.id); +// if (this.organisations != null && !this.organisations.isEmpty()) +// dataManagementPlanEntity.setOrganisations(new HashSet<>(this.organisations.stream().map(item -> item.toDataModel()).collect(Collectors.toList()))); +// if (this.researchers != null && !this.researchers.isEmpty()) +// dataManagementPlanEntity.setResearchers(new HashSet<>(this.researchers.stream().map(item -> item.toDataModel()).collect(Collectors.toList()))); +// dataManagementPlanEntity.setVersion(this.version); +// dataManagementPlanEntity.setLabel(this.label); +// if (this.grant != null) dataManagementPlanEntity.setGrant(this.grant.toDataModel()); +// dataManagementPlanEntity.setStatus((short) this.status); +// dataManagementPlanEntity.setDescription(this.description); +// if (this.project != null) { +// dataManagementPlanEntity.setProject(this.project.toDataModel()); +// } +// if (this.profiles != null) { +// Set dmpDatasetProfiles = new HashSet<>(); +// for (AssociatedProfile profile : this.profiles) { +// DMPDatasetProfile dmpDatasetProfile = new DMPDatasetProfile(); +// dmpDatasetProfile.setId(profile.getId()); +// dmpDatasetProfile.setDmp(dataManagementPlanEntity); +// dmpDatasetProfile.setDatasetprofile(profile.toData()); +// dmpDatasetProfile.setData(new ObjectMapper().writeValueAsString(profile.getData())); +// dmpDatasetProfiles.add(dmpDatasetProfile); +// } +// dataManagementPlanEntity.setAssociatedDmps(dmpDatasetProfiles); +// } +// if(this.extraFields != null) { +// this.properties = this.extraFields.stream().collect(Collectors.toMap(ExtraFieldModel::getId, ExtraFieldModel::getValue)); +// } +// dataManagementPlanEntity.setProperties(this.properties != null ? JSONObject.toJSONString(this.properties) : null); +// dataManagementPlanEntity.setGroupId(this.groupId != null ? this.groupId : UUID.randomUUID()); +// dataManagementPlanEntity.setModified(this.modified != null ? this.modified : new Date()); +// dataManagementPlanEntity.setCreated(this.created != null ? this.created : new Date()); +// if (this.dynamicFields != null) +// dataManagementPlanEntity.setDmpProperties(JSONObject.toJSONString(this.dynamicFields.stream().filter(item -> item.getValue() != null).collect(Collectors.toMap(DynamicFieldWithValue::getId, DynamicFieldWithValue::getValue)))); +// +// if (this.isPublic != null) { +// dataManagementPlanEntity.setPublic(this.isPublic); +// } +// +// dataManagementPlanEntity.setExtraProperties(this.extraProperties != null ? JSONObject.toJSONString(this.extraProperties) : null); return dataManagementPlanEntity; } - public DataManagementPlan fromDataModelNoDatasets(DMP entity) { - this.id = entity.getId(); - this.profile = entity.getProfile() != null ? new Tuple(entity.getProfile().getId(), entity.getProfile().getLabel()) : null; - this.organisations = entity.getOrganisations() != null ? entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); - this.researchers = entity.getResearchers() != null ? entity.getResearchers().stream().filter(Objects::nonNull).map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); - this.version = entity.getVersion(); - this.label = entity.getLabel(); - this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null; - this.creator = new eu.eudat.models.data.userinfo.UserInfo(); - this.groupId = entity.getGroupId(); - this.lockable = entity.getDataset() != null && entity.getDataset().stream().findAny().isPresent(); - if (this.properties != null) { - this.extraFields = new ArrayList<>(); - this.properties.forEach((id, value) -> { - if (value != null) { - ExtraFieldModel extraField = new ExtraFieldModel(); - extraField.setId(id); - extraField.setValue(value.toString()); - this.extraFields.add(extraField); - } - }); - } - if (entity.getUsers() != null && entity.getUsers().stream().anyMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue()))) - this.creator.fromDataModel(entity.getUsers().stream().filter(user -> user.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser()); - - if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) { - this.profiles = new LinkedList<>(); - for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) { - AssociatedProfile associatedProfile = new AssociatedProfile().fromData(dmpDescriptionProfile.getDatasetprofile()); - associatedProfile.setId(dmpDescriptionProfile.getId()); - try { - associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference>() {})); - } - catch (Exception e) { - associatedProfile.setData(null); - } - this.profiles.add(associatedProfile); - } - } - this.modified = entity.getModified(); - this.created = entity.getCreated(); - this.description = entity.getDescription(); - this.status = entity.getStatus(); - this.associatedUsers = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()) : new ArrayList<>(); - this.users = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); - this.dois = entity.getDois() != null ? entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>(); - if(entity.getGrant() != null) { - this.grant = new Grant(); - this.grant.fromDataModel(entity.getGrant()); - } - else { - this.grant = null; - } - - if (entity.getProject() != null) { - this.project = new Project(); - this.project = new Project().fromDataModel(entity.getProject()); - } - if (entity.getGrant() != null && entity.getGrant().getFunder() != null) { - this.funder = new Funder(); - this.funder.fromDataModel(entity.getGrant().getFunder()); - } - this.isPublic = entity.isPublic(); - - this.extraProperties = entity.getExtraProperties() != null ? new org.json.JSONObject(entity.getExtraProperties()).toMap() : null; + public DataManagementPlan fromDataModelNoDatasets(DmpEntity entity) { + this.id = entity.getId(); //TODO +// this.profile = entity.getProfile() != null ? new Tuple(entity.getProfile().getId(), entity.getProfile().getLabel()) : null; +// this.organisations = entity.getOrganisations() != null ? entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); +// this.researchers = entity.getResearchers() != null ? entity.getResearchers().stream().filter(Objects::nonNull).map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); +// this.version = entity.getVersion(); +// this.label = entity.getLabel(); +// this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null; +// this.creator = new eu.eudat.models.data.userinfo.UserInfo(); +// this.groupId = entity.getGroupId(); +// this.lockable = entity.getDataset() != null && entity.getDataset().stream().findAny().isPresent(); +// if (this.properties != null) { +// this.extraFields = new ArrayList<>(); +// this.properties.forEach((id, value) -> { +// if (value != null) { +// ExtraFieldModel extraField = new ExtraFieldModel(); +// extraField.setId(id); +// extraField.setValue(value.toString()); +// this.extraFields.add(extraField); +// } +// }); +// } +// if (entity.getUsers() != null && entity.getUsers().stream().anyMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue()))) +// this.creator.fromDataModel(entity.getUsers().stream().filter(user -> user.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser()); +// +// if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) { +// this.profiles = new LinkedList<>(); +// for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) { +// AssociatedProfile associatedProfile = new AssociatedProfile().fromData(dmpDescriptionProfile.getDatasetprofile()); +// associatedProfile.setId(dmpDescriptionProfile.getId()); +// try { +// associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference>() {})); +// } +// catch (Exception e) { +// associatedProfile.setData(null); +// } +// this.profiles.add(associatedProfile); +// } +// } +// this.modified = entity.getModified(); +// this.created = entity.getCreated(); +// this.description = entity.getDescription(); +// this.status = entity.getStatus(); +// this.associatedUsers = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()) : new ArrayList<>(); +// this.users = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); +// this.dois = entity.getDois() != null ? entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>(); +// if(entity.getGrant() != null) { +// this.grant = new Grant(); +// this.grant.fromDataModel(entity.getGrant()); +// } +// else { +// this.grant = null; +// } +// +// if (entity.getProject() != null) { +// this.project = new Project(); +// this.project = new Project().fromDataModel(entity.getProject()); +// } +// if (entity.getGrant() != null && entity.getGrant().getFunder() != null) { +// this.funder = new Funder(); +// this.funder.fromDataModel(entity.getGrant().getFunder()); +// } +// this.isPublic = entity.isPublic(); +// +// this.extraProperties = entity.getExtraProperties() != null ? new org.json.JSONObject(entity.getExtraProperties()).toMap() : null; return this; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlanEditorModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlanEditorModel.java index 66bea5320..7908ca5bb 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlanEditorModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlanEditorModel.java @@ -3,6 +3,7 @@ package eu.eudat.models.data.dmp; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import eu.eudat.data.DmpBlueprintEntity; +import eu.eudat.data.DmpEntity; import eu.eudat.data.old.*; import eu.eudat.models.DataModel; import eu.eudat.models.data.datasetwizard.DatasetWizardModel; @@ -18,7 +19,7 @@ import net.minidev.json.JSONObject; import java.util.*; import java.util.stream.Collectors; -public class DataManagementPlanEditorModel implements DataModel { +public class DataManagementPlanEditorModel implements DataModel { private UUID id; private String label; private UUID groupId; @@ -223,171 +224,171 @@ public class DataManagementPlanEditorModel implements DataModel(entity.getProfile().getId(), entity.getProfile().getLabel()) : null; - this.organisations = entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()); - this.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()); - this.version = entity.getVersion(); - this.groupId = this.groupId == null ? null : entity.getGroupId(); - this.label = entity.getLabel(); - this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null; - if (entity.getGrant() != null) { - this.grant = new GrantDMPEditorModel(); - this.grant.getExistGrant().fromDataModel(entity.getGrant()); - this.grant.getExistGrant().setSource(""); - } - this.creator = new eu.eudat.models.data.userinfo.UserInfo(); - this.groupId = entity.getGroupId(); - this.lockable = entity.getDataset().stream().findAny().isPresent(); - if (this.properties != null) { - this.extraFields = new ArrayList<>(); - this.properties.forEach((id, value) -> { - ExtraFieldModel extraField = new ExtraFieldModel(); - extraField.setId(id); - extraField.setValue(value.toString()); - this.extraFields.add(extraField); - }); - } - if (entity.getUsers().stream().anyMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue()))) - this.creator.fromDataModel(entity.getUsers().stream().filter(user -> user.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser()); - - if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) { - this.profiles = new LinkedList<>(); - for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) { - AssociatedProfile associatedProfile = new AssociatedProfile().fromData(dmpDescriptionProfile.getDatasetprofile()); - try { - associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference>() {})); - } - catch (Exception e) { - associatedProfile.setData(null); - } - this.profiles.add(associatedProfile); - } - } - this.datasets = entity.getDataset().stream().map(item -> new DatasetWizardModel().fromDataModelNoDmp(item)).collect(Collectors.toList()); - this.modified = entity.getModified(); - this.created = entity.getCreated(); - this.description = entity.getDescription(); - this.status = entity.getStatus(); - this.project = new ProjectDMPEditorModel(); - this.project.getExistProject().fromDataModel(entity.getProject()); - this.associatedUsers = entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()); - this.users = entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()); - if (entity.getGrant() != null) { - this.funder = new FunderDMPEditorModel(); - this.funder.getExistFunder().fromDataModel(entity.getGrant().getFunder()); - } - this.extraProperties = entity.getExtraProperties() != null ? new org.json.JSONObject(entity.getExtraProperties()).toMap() : null; +// this.profile = entity.getProfile() != null ? new Tuple(entity.getProfile().getId(), entity.getProfile().getLabel()) : null; //TODO +// this.organisations = entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()); +// this.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()); +// this.version = entity.getVersion(); +// this.groupId = this.groupId == null ? null : entity.getGroupId(); +// this.label = entity.getLabel(); +// this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null; +// if (entity.getGrant() != null) { +// this.grant = new GrantDMPEditorModel(); +// this.grant.getExistGrant().fromDataModel(entity.getGrant()); +// this.grant.getExistGrant().setSource(""); +// } +// this.creator = new eu.eudat.models.data.userinfo.UserInfo(); +// this.groupId = entity.getGroupId(); +// this.lockable = entity.getDataset().stream().findAny().isPresent(); +// if (this.properties != null) { +// this.extraFields = new ArrayList<>(); +// this.properties.forEach((id, value) -> { +// ExtraFieldModel extraField = new ExtraFieldModel(); +// extraField.setId(id); +// extraField.setValue(value.toString()); +// this.extraFields.add(extraField); +// }); +// } +// if (entity.getUsers().stream().anyMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue()))) +// this.creator.fromDataModel(entity.getUsers().stream().filter(user -> user.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser()); +// +// if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) { +// this.profiles = new LinkedList<>(); +// for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) { +// AssociatedProfile associatedProfile = new AssociatedProfile().fromData(dmpDescriptionProfile.getDatasetprofile()); +// try { +// associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference>() {})); +// } +// catch (Exception e) { +// associatedProfile.setData(null); +// } +// this.profiles.add(associatedProfile); +// } +// } +// this.datasets = entity.getDataset().stream().map(item -> new DatasetWizardModel().fromDataModelNoDmp(item)).collect(Collectors.toList()); +// this.modified = entity.getModified(); +// this.created = entity.getCreated(); +// this.description = entity.getDescription(); +// this.status = entity.getStatus(); +// this.project = new ProjectDMPEditorModel(); +// this.project.getExistProject().fromDataModel(entity.getProject()); +// this.associatedUsers = entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()); +// this.users = entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()); +// if (entity.getGrant() != null) { +// this.funder = new FunderDMPEditorModel(); +// this.funder.getExistFunder().fromDataModel(entity.getGrant().getFunder()); +// } +// this.extraProperties = entity.getExtraProperties() != null ? new org.json.JSONObject(entity.getExtraProperties()).toMap() : null; return this; } @Override - public DMP toDataModel() throws Exception { - DMP dataManagementPlanEntity = new DMP(); - if (this.profile != null) { - DmpBlueprintEntity dmpBlueprint = new DmpBlueprintEntity(); - dmpBlueprint.setId(this.profile.getId()); - dataManagementPlanEntity.setProfile(dmpBlueprint); - } - dataManagementPlanEntity.setId(this.id); - if (this.organisations != null && !this.organisations.isEmpty()) - dataManagementPlanEntity.setOrganisations(new HashSet<>(this.organisations.stream().map(Organisation::toDataModel).collect(Collectors.toList()))); - if (this.researchers != null && !this.researchers.isEmpty()) - dataManagementPlanEntity.setResearchers(new HashSet<>(this.researchers.stream().map(Researcher::toDataModel).collect(Collectors.toList()))); - dataManagementPlanEntity.setVersion(this.version); - dataManagementPlanEntity.setLabel(this.label); - if (this.grant != null) { - if (this.grant.getExistGrant() != null && this.grant.getLabel() == null && this.grant.getDescription() == null) - dataManagementPlanEntity.setGrant(this.grant.getExistGrant().toDataModel()); - else if (this.grant.getLabel() != null) { - Grant grant = new Grant(); - grant.setId(UUID.randomUUID()); - grant.setAbbreviation(""); - grant.setLabel(this.grant.getLabel()); - grant.setType(Grant.GrantType.INTERNAL.getValue()); - grant.setReference("dmp:" + (this.grant.getReference() != null ? this.grant.getReference() : grant.getId())); - grant.setUri(""); - grant.setDefinition(""); - grant.setCreated(new Date()); - grant.setStatus(Grant.Status.ACTIVE.getValue()); - grant.setModified(new Date()); - grant.setDescription(this.grant.getDescription()); - - dataManagementPlanEntity.setGrant(grant); - } - } - - if (this.funder != null) { - if (this.funder.getLabel() != null) { - Funder funder = new Funder(); - funder.setId(UUID.randomUUID()); - funder.setLabel(this.funder.getLabel()); - funder.setType(Funder.FunderType.INTERNAL.getValue()); - funder.setReference("dmp:" + (this.funder.getReference() != null ? this.funder.getReference() : funder.getId())); - funder.setDefinition(""); - funder.setCreated(new Date()); - funder.setStatus(Funder.Status.ACTIVE.getValue()); - funder.setModified(new Date()); - - dataManagementPlanEntity.getGrant().setFunder(funder); - } else if (this.funder.getExistFunder() != null && this.funder.getLabel() == null){ - dataManagementPlanEntity.getGrant().setFunder(this.funder.getExistFunder().toDataModel()); - dataManagementPlanEntity.getGrant().getFunder().setType(Funder.FunderType.EXTERNAL.getValue()); - } - } - - if (this.project != null) { - if (this.project.getExistProject() != null && this.project.getLabel() == null && this.project.getDescription() == null) - dataManagementPlanEntity.setProject(this.project.getExistProject().toDataModel()); - else if (this.project.getLabel() != null) { - Project project = new Project(); - project.setId(UUID.randomUUID()); - project.setAbbreviation(""); - project.setLabel(this.project.getLabel()); - project.setType(Project.ProjectType.INTERNAL.getValue()); - project.setReference("dmp:" + (this.project.getReference() != null ? this.project.getReference() : project.getId())); - project.setUri(""); - project.setDefinition(""); - project.setCreated(new Date()); - project.setStatus(Project.Status.ACTIVE.getValue()); - project.setModified(new Date()); - project.setDescription(this.project.getDescription()); - - dataManagementPlanEntity.setProject(project); - } - } - - dataManagementPlanEntity.setStatus((short) this.status); - if (this.status == (int) DMP.DMPStatus.FINALISED.getValue()) { - dataManagementPlanEntity.setFinalizedAt(new Date()); - } - dataManagementPlanEntity.setDescription(this.description); - if (this.profiles != null) { - Set dmpDatasetProfiles = new HashSet<>(); - for (AssociatedProfile profile : this.profiles) { - DMPDatasetProfile dmpDatasetProfile = new DMPDatasetProfile(); - dmpDatasetProfile.setId(profile.getId()); - dmpDatasetProfile.setDmp(dataManagementPlanEntity); - dmpDatasetProfile.setDatasetprofile(profile.toData()); - dmpDatasetProfile.setData(new ObjectMapper().writeValueAsString(profile.getData())); - dmpDatasetProfiles.add(dmpDatasetProfile); - } - dataManagementPlanEntity.setAssociatedDmps(dmpDatasetProfiles); - } - if(this.extraFields != null) { - this.properties = new HashMap<>(); - this.extraFields.forEach((extraField) -> this.properties.put(extraField.getId(), extraField.getValue())); - } - dataManagementPlanEntity.setProperties(this.properties != null ? JSONObject.toJSONString(this.properties) : null); - dataManagementPlanEntity.setGroupId(this.groupId != null ? this.groupId : UUID.randomUUID()); - dataManagementPlanEntity.setModified(this.modified != null ? this.modified : new Date()); - dataManagementPlanEntity.setCreated(this.created != null ? this.created : new Date()); - if (this.dynamicFields != null) - dataManagementPlanEntity.setDmpProperties(JSONObject.toJSONString(this.dynamicFields.stream().filter(item -> item.getValue() != null).collect(Collectors.toMap(DynamicFieldWithValue::getId, DynamicFieldWithValue::getValue)))); - - dataManagementPlanEntity.setExtraProperties(this.extraProperties != null ? JSONObject.toJSONString(this.extraProperties) : null); + public DmpEntity toDataModel() throws Exception { + DmpEntity dataManagementPlanEntity = new DmpEntity();//TODO +// if (this.profile != null) { +// DmpBlueprintEntity dmpBlueprint = new DmpBlueprintEntity(); +// dmpBlueprint.setId(this.profile.getId()); +// dataManagementPlanEntity.setProfile(dmpBlueprint); +// } +// dataManagementPlanEntity.setId(this.id); +// if (this.organisations != null && !this.organisations.isEmpty()) +// dataManagementPlanEntity.setOrganisations(new HashSet<>(this.organisations.stream().map(Organisation::toDataModel).collect(Collectors.toList()))); +// if (this.researchers != null && !this.researchers.isEmpty()) +// dataManagementPlanEntity.setResearchers(new HashSet<>(this.researchers.stream().map(Researcher::toDataModel).collect(Collectors.toList()))); +// dataManagementPlanEntity.setVersion(this.version); +// dataManagementPlanEntity.setLabel(this.label); +// if (this.grant != null) { +// if (this.grant.getExistGrant() != null && this.grant.getLabel() == null && this.grant.getDescription() == null) +// dataManagementPlanEntity.setGrant(this.grant.getExistGrant().toDataModel()); +// else if (this.grant.getLabel() != null) { +// Grant grant = new Grant(); +// grant.setId(UUID.randomUUID()); +// grant.setAbbreviation(""); +// grant.setLabel(this.grant.getLabel()); +// grant.setType(Grant.GrantType.INTERNAL.getValue()); +// grant.setReference("dmp:" + (this.grant.getReference() != null ? this.grant.getReference() : grant.getId())); +// grant.setUri(""); +// grant.setDefinition(""); +// grant.setCreated(new Date()); +// grant.setStatus(Grant.Status.ACTIVE.getValue()); +// grant.setModified(new Date()); +// grant.setDescription(this.grant.getDescription()); +// +// dataManagementPlanEntity.setGrant(grant); +// } +// } +// +// if (this.funder != null) { +// if (this.funder.getLabel() != null) { +// Funder funder = new Funder(); +// funder.setId(UUID.randomUUID()); +// funder.setLabel(this.funder.getLabel()); +// funder.setType(Funder.FunderType.INTERNAL.getValue()); +// funder.setReference("dmp:" + (this.funder.getReference() != null ? this.funder.getReference() : funder.getId())); +// funder.setDefinition(""); +// funder.setCreated(new Date()); +// funder.setStatus(Funder.Status.ACTIVE.getValue()); +// funder.setModified(new Date()); +// +// dataManagementPlanEntity.getGrant().setFunder(funder); +// } else if (this.funder.getExistFunder() != null && this.funder.getLabel() == null){ +// dataManagementPlanEntity.getGrant().setFunder(this.funder.getExistFunder().toDataModel()); +// dataManagementPlanEntity.getGrant().getFunder().setType(Funder.FunderType.EXTERNAL.getValue()); +// } +// } +// +// if (this.project != null) { +// if (this.project.getExistProject() != null && this.project.getLabel() == null && this.project.getDescription() == null) +// dataManagementPlanEntity.setProject(this.project.getExistProject().toDataModel()); +// else if (this.project.getLabel() != null) { +// Project project = new Project(); +// project.setId(UUID.randomUUID()); +// project.setAbbreviation(""); +// project.setLabel(this.project.getLabel()); +// project.setType(Project.ProjectType.INTERNAL.getValue()); +// project.setReference("dmp:" + (this.project.getReference() != null ? this.project.getReference() : project.getId())); +// project.setUri(""); +// project.setDefinition(""); +// project.setCreated(new Date()); +// project.setStatus(Project.Status.ACTIVE.getValue()); +// project.setModified(new Date()); +// project.setDescription(this.project.getDescription()); +// +// dataManagementPlanEntity.setProject(project); +// } +// } +// +// dataManagementPlanEntity.setStatus((short) this.status); +// if (this.status == (int) DMP.DMPStatus.FINALISED.getValue()) { +// dataManagementPlanEntity.setFinalizedAt(new Date()); +// } +// dataManagementPlanEntity.setDescription(this.description); +// if (this.profiles != null) { +// Set dmpDatasetProfiles = new HashSet<>(); +// for (AssociatedProfile profile : this.profiles) { +// DMPDatasetProfile dmpDatasetProfile = new DMPDatasetProfile(); +// dmpDatasetProfile.setId(profile.getId()); +// dmpDatasetProfile.setDmp(dataManagementPlanEntity); +// dmpDatasetProfile.setDatasetprofile(profile.toData()); +// dmpDatasetProfile.setData(new ObjectMapper().writeValueAsString(profile.getData())); +// dmpDatasetProfiles.add(dmpDatasetProfile); +// } +// dataManagementPlanEntity.setAssociatedDmps(dmpDatasetProfiles); +// } +// if(this.extraFields != null) { +// this.properties = new HashMap<>(); +// this.extraFields.forEach((extraField) -> this.properties.put(extraField.getId(), extraField.getValue())); +// } +// dataManagementPlanEntity.setProperties(this.properties != null ? JSONObject.toJSONString(this.properties) : null); +// dataManagementPlanEntity.setGroupId(this.groupId != null ? this.groupId : UUID.randomUUID()); +// dataManagementPlanEntity.setModified(this.modified != null ? this.modified : new Date()); +// dataManagementPlanEntity.setCreated(this.created != null ? this.created : new Date()); +// if (this.dynamicFields != null) +// dataManagementPlanEntity.setDmpProperties(JSONObject.toJSONString(this.dynamicFields.stream().filter(item -> item.getValue() != null).collect(Collectors.toMap(DynamicFieldWithValue::getId, DynamicFieldWithValue::getValue)))); +// +// dataManagementPlanEntity.setExtraProperties(this.extraProperties != null ? JSONObject.toJSONString(this.extraProperties) : null); return dataManagementPlanEntity; } 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 482ebff1a..acc41f13d 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,7 +1,10 @@ package eu.eudat.models.data.dmp; import com.fasterxml.jackson.databind.ObjectMapper; +import eu.eudat.commons.enums.DmpStatus; import eu.eudat.data.DescriptionEntity; +import eu.eudat.data.DmpEntity; +import eu.eudat.data.DmpUserEntity; import eu.eudat.data.old.*; import eu.eudat.models.DataModel; import eu.eudat.models.data.dataset.Dataset; @@ -14,13 +17,14 @@ import net.minidev.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.time.Instant; import java.util.*; import java.util.stream.Collectors; /** * Created by ikalyvas on 2/5/2018. */ -public class DataManagementPlanNewVersionModel implements DataModel { +public class DataManagementPlanNewVersionModel implements DataModel { private static final Logger logger = LoggerFactory.getLogger(DataManagementPlanNewVersionModel.class); private UUID id; @@ -162,112 +166,112 @@ public class DataManagementPlanNewVersionModel implements DataModel(new ArrayList<>(this.associatedUsers))); entity.setDescription(this.description); - entity.setStatus((short) this.status); + entity.setStatus(DmpStatus.of((short)this.status)); entity.setGroupId(this.groupId == null ? UUID.randomUUID() : this.groupId); - entity.setCreated(new Date()); + entity.setCreatedAt(Instant.now()); + entity.setUpdatedAt(Instant.now()); entity.setLabel(this.label); - entity.setModified(new Date()); - List descriptionEntities = new LinkedList<>(); - if (this.datasets != null) { - for (Dataset dataset : this.datasets) { - DescriptionEntity entityDescriptionEntity = new DescriptionEntity(); - entityDescriptionEntity.setId(dataset.getId()); - descriptionEntities.add(entityDescriptionEntity); - } - entity.setDataset(new HashSet<>(descriptionEntities)); - } - if (this.organisations != null && !this.organisations.isEmpty()) - entity.setOrganisations(new HashSet<>(this.organisations.stream().map(item -> item.toDataModel()).collect(Collectors.toList()))); - if (this.researchers != null && !this.researchers.isEmpty()) - entity.setResearchers(new HashSet<>(this.researchers.stream().map(item -> item.toDataModel()).collect(Collectors.toList()))); - /*if (this.grant != null) { - entity.setGrant(this.grant.toDataModel()); - }*/ + List descriptionEntities = new LinkedList<>();//TODO +// if (this.datasets != null) { +// for (Dataset dataset : this.datasets) { +// DescriptionEntity entityDescriptionEntity = new DescriptionEntity(); +// entityDescriptionEntity.setId(dataset.getId()); +// descriptionEntities.add(entityDescriptionEntity); +// } +// entity.setDataset(new HashSet<>(descriptionEntities)); +// } +// if (this.organisations != null && !this.organisations.isEmpty()) +// entity.setOrganisations(new HashSet<>(this.organisations.stream().map(item -> item.toDataModel()).collect(Collectors.toList()))); +// if (this.researchers != null && !this.researchers.isEmpty()) +// entity.setResearchers(new HashSet<>(this.researchers.stream().map(item -> item.toDataModel()).collect(Collectors.toList()))); +// /*if (this.grant != null) { +// entity.setGrant(this.grant.toDataModel()); +// }*/ +// +// if (this.grant != null) { +// if (this.grant.getExistGrant() != null && this.grant.getLabel() == null && this.grant.getDescription() == null) +// entity.setGrant(this.grant.getExistGrant().toDataModel()); +// else if (this.grant.getLabel() != null) { +// Grant grant = new Grant(); +// grant.setId(UUID.randomUUID()); +// grant.setAbbreviation(""); +// grant.setLabel(this.grant.getLabel()); +// grant.setType(Grant.GrantType.INTERNAL.getValue()); +// grant.setReference("dmp:" + (this.grant.getReference() != null ? this.grant.getReference() : grant.getId())); +// grant.setUri(""); +// grant.setDefinition(""); +// grant.setCreated(new Date()); +// grant.setStatus(Grant.Status.ACTIVE.getValue()); +// grant.setModified(new Date()); +// grant.setDescription(this.grant.getDescription()); +// +// entity.setGrant(grant); +// } +// } +// +// if (this.funder != null) { +// if (this.funder.getLabel() != null) { +// Funder funder = new Funder(); +// funder.setId(UUID.randomUUID()); +// funder.setLabel(this.funder.getLabel()); +// funder.setType(Funder.FunderType.INTERNAL.getValue()); +// funder.setReference("dmp:" + (this.funder.getReference() != null ? this.funder.getReference() : funder.getId())); +// funder.setDefinition(""); +// funder.setCreated(new Date()); +// funder.setStatus(Funder.Status.ACTIVE.getValue()); +// funder.setModified(new Date()); +// +// entity.getGrant().setFunder(funder); +// } else if (this.funder.getExistFunder() != null && this.funder.getLabel() == null) { +// entity.getGrant().setFunder(this.funder.getExistFunder().toDataModel()); +// entity.getGrant().getFunder().setType(Funder.FunderType.EXTERNAL.getValue()); +// } +// } - if (this.grant != null) { - if (this.grant.getExistGrant() != null && this.grant.getLabel() == null && this.grant.getDescription() == null) - entity.setGrant(this.grant.getExistGrant().toDataModel()); - else if (this.grant.getLabel() != null) { - Grant grant = new Grant(); - grant.setId(UUID.randomUUID()); - grant.setAbbreviation(""); - grant.setLabel(this.grant.getLabel()); - grant.setType(Grant.GrantType.INTERNAL.getValue()); - grant.setReference("dmp:" + (this.grant.getReference() != null ? this.grant.getReference() : grant.getId())); - grant.setUri(""); - grant.setDefinition(""); - grant.setCreated(new Date()); - grant.setStatus(Grant.Status.ACTIVE.getValue()); - grant.setModified(new Date()); - grant.setDescription(this.grant.getDescription()); - - entity.setGrant(grant); - } - } - - if (this.funder != null) { - if (this.funder.getLabel() != null) { - Funder funder = new Funder(); - funder.setId(UUID.randomUUID()); - funder.setLabel(this.funder.getLabel()); - funder.setType(Funder.FunderType.INTERNAL.getValue()); - funder.setReference("dmp:" + (this.funder.getReference() != null ? this.funder.getReference() : funder.getId())); - funder.setDefinition(""); - funder.setCreated(new Date()); - funder.setStatus(Funder.Status.ACTIVE.getValue()); - funder.setModified(new Date()); - - entity.getGrant().setFunder(funder); - } else if (this.funder.getExistFunder() != null && this.funder.getLabel() == null) { - entity.getGrant().setFunder(this.funder.getExistFunder().toDataModel()); - entity.getGrant().getFunder().setType(Funder.FunderType.EXTERNAL.getValue()); - } - } - - if (this.project != null) { - if (this.project.getExistProject() != null && this.project.getLabel() == null && this.project.getDescription() == null) - entity.setProject(this.project.getExistProject().toDataModel()); - else if (this.project.getLabel() != null) { - Project project = new Project(); - project.setId(UUID.randomUUID()); - project.setAbbreviation(""); - project.setLabel(this.project.getLabel()); - project.setType(Project.ProjectType.INTERNAL.getValue()); - project.setReference("dmp:" + (this.project.getReference() != null ? this.project.getReference() : project.getId())); - project.setUri(""); - project.setDefinition(""); - project.setCreated(new Date()); - project.setStatus(Project.Status.ACTIVE.getValue()); - project.setModified(new Date()); - project.setDescription(this.project.getDescription()); - - entity.setProject(project); - } - } - - entity.setExtraProperties(this.extraProperties != null ? JSONObject.toJSONString(this.extraProperties) : null); - if (this.profiles != null) { - Set dmpDatasetProfiles = new HashSet<>(); - for (AssociatedProfile profile : this.profiles) { - DMPDatasetProfile dmpDatasetProfile = new DMPDatasetProfile(); - dmpDatasetProfile.setId(null); - dmpDatasetProfile.setDmp(entity); - dmpDatasetProfile.setDatasetprofile(profile.toData()); - dmpDatasetProfile.setData(new ObjectMapper().writeValueAsString(profile.getData())); - dmpDatasetProfiles.add(dmpDatasetProfile); - } - entity.setAssociatedDmps(dmpDatasetProfiles); - } +// if (this.project != null) { +// if (this.project.getExistProject() != null && this.project.getLabel() == null && this.project.getDescription() == null) +// entity.setProject(this.project.getExistProject().toDataModel()); +// else if (this.project.getLabel() != null) { +// Project project = new Project(); +// project.setId(UUID.randomUUID()); +// project.setAbbreviation(""); +// project.setLabel(this.project.getLabel()); +// project.setType(Project.ProjectType.INTERNAL.getValue()); +// project.setReference("dmp:" + (this.project.getReference() != null ? this.project.getReference() : project.getId())); +// project.setUri(""); +// project.setDefinition(""); +// project.setCreated(new Date()); +// project.setStatus(Project.Status.ACTIVE.getValue()); +// project.setModified(new Date()); +// project.setDescription(this.project.getDescription()); +// +// entity.setProject(project); +// } +// } +// +// entity.setExtraProperties(this.extraProperties != null ? JSONObject.toJSONString(this.extraProperties) : null); +// if (this.profiles != null) { +// Set dmpDatasetProfiles = new HashSet<>(); +// for (AssociatedProfile profile : this.profiles) { +// DMPDatasetProfile dmpDatasetProfile = new DMPDatasetProfile(); +// dmpDatasetProfile.setId(null); +// dmpDatasetProfile.setDmp(entity); +// dmpDatasetProfile.setDatasetprofile(profile.toData()); +// dmpDatasetProfile.setData(new ObjectMapper().writeValueAsString(profile.getData())); +// dmpDatasetProfiles.add(dmpDatasetProfile); +// } +// entity.setAssociatedDmps(dmpDatasetProfiles); +// } return entity; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/grant/GrantListingModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/grant/GrantListingModel.java index 905d1faf2..559d46a3d 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/grant/GrantListingModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/grant/GrantListingModel.java @@ -190,7 +190,7 @@ public class GrantListingModel implements DataModel new DataManagementPlanUrlListing().fromDataModel(item)).collect(Collectors.toList()); + //this.dmps = entity.getDmps().stream().map(item -> new DataManagementPlanUrlListing().fromDataModel(item)).collect(Collectors.toList()); //TODO return this; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/DataManagementPlanListingModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/DataManagementPlanListingModel.java index 730717f79..c917628d4 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/DataManagementPlanListingModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/DataManagementPlanListingModel.java @@ -1,6 +1,6 @@ package eu.eudat.models.data.listingmodels; -import eu.eudat.data.old.DMP; +import eu.eudat.data.DmpEntity; import eu.eudat.data.old.Grant; import eu.eudat.models.DataModel; import eu.eudat.models.data.urls.DatasetUrlListing; @@ -12,7 +12,7 @@ import java.util.UUID; import java.util.stream.Collectors; -public class DataManagementPlanListingModel implements DataModel { +public class DataManagementPlanListingModel implements DataModel { private String id; private String label; private String grant; @@ -120,66 +120,66 @@ public class DataManagementPlanListingModel implements DataModel new DatasetUrlListing().fromDataModel(x)).collect(Collectors.toList()); - this.users = entity.getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList()); - this.finalizedAt = entity.getFinalizedAt(); - this.isPublic = entity.isPublic(); - this.publishedAt = entity.getPublishedAt(); + this.creationTime = Date.from(entity.getCreatedAt()); + this.modifiedTime = Date.from(entity.getUpdatedAt()); + this.finalizedAt = Date.from(entity.getFinalizedAt()); +// this.grant = (entity.getGrant() != null) ? entity.getGrant().getLabel() : null; //TODO +// this.datasets = entity.getDataset().stream().map(x-> new DatasetUrlListing().fromDataModel(x)).collect(Collectors.toList()); +// this.users = entity.getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList()); +// this.isPublic = entity.isPublic(); +// this.publishedAt = entity.getPublishedAt(); return this; } @Override - public DMP toDataModel() { - DMP entity = new DMP(); + public DmpEntity toDataModel() { + DmpEntity entity = new DmpEntity(); entity.setId(UUID.fromString(this.getId())); entity.setLabel(this.getLabel()); entity.setGroupId(this.getGroupId()); - entity.setStatus(Integer.valueOf(this.getStatus()).shortValue()); - entity.setCreated(this.getCreationTime()); - entity.setFinalizedAt(this.getFinalizedAt()); - entity.setModified(this.getModifiedTime()); - entity.setPublic(this.getPublic()); - entity.setPublishedAt(this.getPublishedAt()); - entity.setVersion(this.getVersion()); - - entity.setDataset(this.getDatasets().stream().map(DatasetUrlListing::toDataModel).collect(Collectors.toCollection(LinkedHashSet::new))); - if (this.getGrant() != null && !this.getGrant().isEmpty()) { - Grant grant = new Grant(); - grant.setLabel(this.getGrant()); - entity.setGrant(grant); - } - entity.setUsers(this.getUsers().stream().map(UserInfoListingModel::toDataModel).collect(Collectors.toSet())); +// entity.setStatus(Integer.valueOf(this.getStatus()).shortValue()); //TODO +// entity.setCreated(this.getCreationTime()); +// entity.setFinalizedAt(this.getFinalizedAt()); +// entity.setModified(this.getModifiedTime()); +// entity.setPublic(this.getPublic()); +// entity.setPublishedAt(this.getPublishedAt()); +// entity.setVersion(this.getVersion()); +// +// entity.setDataset(this.getDatasets().stream().map(DatasetUrlListing::toDataModel).collect(Collectors.toCollection(LinkedHashSet::new))); +// if (this.getGrant() != null && !this.getGrant().isEmpty()) { +// Grant grant = new Grant(); +// grant.setLabel(this.getGrant()); +// entity.setGrant(grant); +// } +// entity.setUsers(this.getUsers().stream().map(UserInfoListingModel::toDataModel).collect(Collectors.toSet())); return entity; } 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 aeea68b25..f1680b11f 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 @@ -4,8 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import eu.eudat.commons.enums.DescriptionStatus; import eu.eudat.commons.enums.IsActive; -import eu.eudat.data.old.DMP; -import eu.eudat.data.old.DMPDatasetProfile; +import eu.eudat.data.DmpEntity; import eu.eudat.model.doi.Doi; import eu.eudat.models.DataModel; import eu.eudat.models.data.dataset.DatasetOverviewModel; @@ -14,10 +13,11 @@ import eu.eudat.models.data.dmp.Organisation; import eu.eudat.models.data.dmp.Researcher; import eu.eudat.models.data.grant.GrantOverviewModel; +import java.time.Instant; import java.util.*; import java.util.stream.Collectors; -public class DataManagementPlanOverviewModel implements DataModel { +public class DataManagementPlanOverviewModel implements DataModel { private String id; private String label; private String profile; @@ -173,62 +173,62 @@ public class DataManagementPlanOverviewModel implements DataModel new Researcher().fromDataModel(item)).collect(Collectors.toList()); - } - if(entity.getDois() != null){ - this.dois = entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList()); - } + this.status = entity.getStatus().getValue(); +// if (entity.getResearchers() != null) { //TODO +// this.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()); +// } +// if(entity.getDois() != null){ +// this.dois = entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList()); +// } return this; } - public DataManagementPlanOverviewModel fromDataModelDatasets(DMP entity) { + public DataManagementPlanOverviewModel fromDataModelDatasets(DmpEntity entity) { this.fromDataModel(entity); this.version = entity.getVersion(); - if (entity.getGrant() != null) this.grant = new GrantOverviewModel().fromDataModel(entity.getGrant()); - if (entity.getProfile() != null) this.profile = entity.getProfile().getLabel(); - this.creationTime = entity.getCreated(); - this.modifiedTime = entity.getModified(); - this.finalizedAt = entity.getFinalizedAt(); - this.organisations = entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()); - this.datasets = entity.getDataset().stream().filter(dataset -> !dataset.getIsActive().equals(IsActive.Inactive) && !dataset.getStatus().equals(DescriptionStatus.Canceled)).map(x-> new DatasetOverviewModel().fromDataModel(x)).collect(Collectors.toList()); - this.users = entity.getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList()); - this.description = entity.getDescription(); - if (entity.getResearchers() != null) { - this.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()); - } - - if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) { - this.associatedProfiles = new LinkedList<>(); - for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) { - AssociatedProfile associatedProfile = new AssociatedProfile().fromData(dmpDescriptionProfile.getDatasetprofile()); - try { - associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference>() {})); - } - catch (Exception e) { - associatedProfile.setData(null); - } - this.associatedProfiles.add(associatedProfile); - } - } - this.isPublic = entity.isPublic(); - this.publishedAt = entity.getPublishedAt(); - if (entity.getDois() != null) { - this.dois = entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList()); - } else { - this.dois = new ArrayList<>(); - } +// if (entity.getGrant() != null) this.grant = new GrantOverviewModel().fromDataModel(entity.getGrant()); +// if (entity.getProfile() != null) this.profile = entity.getProfile().getLabel(); + this.creationTime = Date.from(entity.getCreatedAt()); + this.modifiedTime = Date.from(entity.getUpdatedAt()); + this.finalizedAt = Date.from(entity.getFinalizedAt()); +// this.organisations = entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()); +// this.datasets = entity.getDataset().stream().filter(dataset -> !dataset.getIsActive().equals(IsActive.Inactive) && !dataset.getStatus().equals(DescriptionStatus.Canceled)).map(x-> new DatasetOverviewModel().fromDataModel(x)).collect(Collectors.toList()); +// this.users = entity.getUsers().stream().map(x -> new UserInfoListingModel().fromDataModel(x)).collect(Collectors.toList()); +// this.description = entity.getDescription(); +// if (entity.getResearchers() != null) { +// this.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()); +// } +// +// if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) { +// this.associatedProfiles = new LinkedList<>(); +// for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) { +// AssociatedProfile associatedProfile = new AssociatedProfile().fromData(dmpDescriptionProfile.getDatasetprofile()); +// try { +// associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference>() {})); +// } +// catch (Exception e) { +// associatedProfile.setData(null); +// } +// this.associatedProfiles.add(associatedProfile); +// } +// } +// this.isPublic = entity.isPublic(); +// this.publishedAt = entity.getPublishedAt(); +// if (entity.getDois() != null) { +// this.dois = entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList()); +// } else { +// this.dois = new ArrayList<>(); +// } return this; } @Override - public DMP toDataModel() { + public DmpEntity toDataModel() { return null; } 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 dfbb04622..127b4f525 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,18 +1,12 @@ package eu.eudat.models.data.listingmodels; import eu.eudat.commons.enums.DescriptionStatus; -import eu.eudat.data.old.DMP; import eu.eudat.data.DescriptionEntity; -import eu.eudat.data.old.Grant; import eu.eudat.models.DataModel; import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel; import java.time.Instant; -import java.util.ArrayList; -import java.util.Date; import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; public class DatasetListingModel implements DataModel { diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/UserInfoListingModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/UserInfoListingModel.java index dc17cdaf3..7dd342cb7 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/UserInfoListingModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/listingmodels/UserInfoListingModel.java @@ -1,12 +1,14 @@ package eu.eudat.models.data.listingmodels; -import eu.eudat.data.old.UserDMP; +import eu.eudat.commons.enums.DmpUserRole; +import eu.eudat.data.DmpUserEntity; import eu.eudat.data.old.UserInfo; +import eu.eudat.model.DmpUser; import eu.eudat.models.DataModel; import java.util.UUID; -public class UserInfoListingModel implements DataModel { +public class UserInfoListingModel implements DataModel { private UUID id; private String name; @@ -42,23 +44,23 @@ public class UserInfoListingModel implements DataModel { +public class VersionListingModel implements DataModel { private String id; private String groupId; private Integer version; @@ -34,15 +34,15 @@ public class VersionListingModel implements DataModel } @Override - public VersionListingModel fromDataModel(DMP entity) { + public VersionListingModel fromDataModel(DmpEntity entity) { this.id = entity.getId().toString(); this.groupId = entity.getGroupId().toString(); - this.version = entity.getVersion(); + this.version = entity.getVersion().intValue(); return this; } @Override - public DMP toDataModel() throws Exception { + public DmpEntity toDataModel() throws Exception { return null; } 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 7a10a1e3d..ee351689a 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 @@ -2,10 +2,9 @@ package eu.eudat.models.data.rda; import eu.eudat.commons.enums.DescriptionStatus; import eu.eudat.commons.enums.IsActive; +import eu.eudat.data.DmpEntity; import eu.eudat.data.EntityDoiEntity; -import eu.eudat.data.old.DMP; import eu.eudat.data.DescriptionEntity; -import eu.eudat.data.old.UserDMP; import eu.eudat.logic.managers.DatasetManager; import java.text.SimpleDateFormat; @@ -128,46 +127,47 @@ public class DmpRDAExportModel { this.title = title; } - public DmpRDAExportModel fromDataModel(DMP entity, DatasetManager datasetManager) { + public DmpRDAExportModel fromDataModel(DmpEntity entity, DatasetManager datasetManager) { DmpRDAExportModel dmpRda = new DmpRDAExportModel(); - dmpRda.contact = new ContactRDAExportModel().fromDataModel(entity.getUsers().stream().filter(x -> x.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser()); - if (entity.getUsers().stream().anyMatch(x -> x.getRole().equals(UserDMP.UserDMPRoles.USER.getValue()))) { - dmpRda.contributor = new LinkedList<>(); - for (UserDMP userdmp : entity.getUsers().stream().filter(x -> x.getRole().equals(UserDMP.UserDMPRoles.USER.getValue())).collect(Collectors.toList())) { - dmpRda.contributor.add(new DmpContributorRDAExportModel().fromDataModel(userdmp.getUser(), UserDMP.UserDMPRoles.fromInteger(userdmp.getRole()).toString())); - } - } - dmpRda.cost = null; - SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy"); - dmpRda.created = formatter.format(entity.getCreated()); - dmpRda.dataset = new LinkedList<>(); - for (DescriptionEntity descriptionEntity : entity.getDataset()) { - if (descriptionEntity.getIsActive() != IsActive.Inactive && descriptionEntity.getStatus() != DescriptionStatus.Canceled) - dmpRda.dataset.add(new DatasetRDAExportModel().fromDataModel(descriptionEntity, datasetManager)); - } - dmpRda.description = entity.getDescription().replace("\n", " "); - if (entity.getDois() != null && !entity.getDois().isEmpty()) { - boolean zenodoDoi = false; - for(EntityDoiEntity doi: entity.getDois()){ - if(doi.getRepositoryId().equals("Zenodo")){ - dmpRda.dmp_id = new IdRDAExportModel(doi.getDoi(), "zenodo"); - zenodoDoi = true; - } - } - if(!zenodoDoi){ - dmpRda.dmp_id = new IdRDAExportModel(entity.getId().toString(), "other"); - } - } - else { - dmpRda.dmp_id = new IdRDAExportModel(entity.getId().toString(), "other"); - } - // Mock up data on "language" and "ethical_issues_*" for now. - dmpRda.ethical_issues_exist = "unknown"; - dmpRda.language = "en"; - dmpRda.modified = formatter.format(new Date()); - if (entity.getGrant() != null) { - dmpRda.project = new ProjectRDAExportModel().fromDataModel(entity.getGrant()); - } + //TODO +// dmpRda.contact = new ContactRDAExportModel().fromDataModel(entity.getUsers().stream().filter(x -> x.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser()); +// if (entity.getUsers().stream().anyMatch(x -> x.getRole().equals(UserDMP.UserDMPRoles.USER.getValue()))) { +// dmpRda.contributor = new LinkedList<>(); +// for (UserDMP userdmp : entity.getUsers().stream().filter(x -> x.getRole().equals(UserDMP.UserDMPRoles.USER.getValue())).collect(Collectors.toList())) { +// dmpRda.contributor.add(new DmpContributorRDAExportModel().fromDataModel(userdmp.getUser(), UserDMP.UserDMPRoles.fromInteger(userdmp.getRole()).toString())); +// } +// } +// dmpRda.cost = null; +// SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy"); +// dmpRda.created = formatter.format(entity.getCreated()); +// dmpRda.dataset = new LinkedList<>(); +// for (DescriptionEntity descriptionEntity : entity.getDataset()) { +// if (descriptionEntity.getIsActive() != IsActive.Inactive && descriptionEntity.getStatus() != DescriptionStatus.Canceled) +// dmpRda.dataset.add(new DatasetRDAExportModel().fromDataModel(descriptionEntity, datasetManager)); +// } +// dmpRda.description = entity.getDescription().replace("\n", " "); +// if (entity.getDois() != null && !entity.getDois().isEmpty()) { +// boolean zenodoDoi = false; +// for(EntityDoiEntity doi: entity.getDois()){ +// if(doi.getRepositoryId().equals("Zenodo")){ +// dmpRda.dmp_id = new IdRDAExportModel(doi.getDoi(), "zenodo"); +// zenodoDoi = true; +// } +// } +// if(!zenodoDoi){ +// dmpRda.dmp_id = new IdRDAExportModel(entity.getId().toString(), "other"); +// } +// } +// else { +// dmpRda.dmp_id = new IdRDAExportModel(entity.getId().toString(), "other"); +// } +// // Mock up data on "language" and "ethical_issues_*" for now. +// dmpRda.ethical_issues_exist = "unknown"; +// dmpRda.language = "en"; +// dmpRda.modified = formatter.format(new Date()); +// if (entity.getGrant() != null) { +// dmpRda.project = new ProjectRDAExportModel().fromDataModel(entity.getGrant()); +// } dmpRda.title = entity.getLabel(); return dmpRda; diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/RDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/RDAExportModel.java index 7981de564..cfa83ff4a 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/RDAExportModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/RDAExportModel.java @@ -1,6 +1,6 @@ package eu.eudat.models.data.rda; -import eu.eudat.data.old.DMP; +import eu.eudat.data.DmpEntity; import eu.eudat.logic.managers.DatasetManager; public class RDAExportModel { @@ -13,7 +13,7 @@ public class RDAExportModel { this.dmp = dmp; } - public RDAExportModel fromDataModel(DMP dmp, DatasetManager datasetManager) { + public RDAExportModel fromDataModel(DmpEntity dmp, DatasetManager datasetManager) { this.dmp = new DmpRDAExportModel().fromDataModel(dmp, datasetManager); return this; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/urls/DataManagementPlanUrlListing.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/urls/DataManagementPlanUrlListing.java index b1ce27542..e79b201ad 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/urls/DataManagementPlanUrlListing.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/urls/DataManagementPlanUrlListing.java @@ -1,21 +1,21 @@ package eu.eudat.models.data.urls; -import eu.eudat.data.old.DMP; +import eu.eudat.data.DmpEntity; /** * Created by ikalyvas on 3/19/2018. */ -public class DataManagementPlanUrlListing extends UrlListing { +public class DataManagementPlanUrlListing extends UrlListing { @Override - public DataManagementPlanUrlListing fromDataModel(DMP entity) { + public DataManagementPlanUrlListing fromDataModel(DmpEntity entity) { this.setLabel(entity.getLabel()); this.setUrl(entity.getId().toString()); return this; } @Override - public DMP toDataModel() throws Exception { + public DmpEntity toDataModel() throws Exception { return null; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/ContributorRDAMapper.java b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/ContributorRDAMapper.java index 88d41802e..9044a8913 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/ContributorRDAMapper.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/ContributorRDAMapper.java @@ -1,8 +1,8 @@ package eu.eudat.models.rda.mapper; import com.fasterxml.jackson.databind.ObjectMapper; +import eu.eudat.data.DmpUserEntity; import eu.eudat.data.old.Researcher; -import eu.eudat.data.old.UserDMP; import eu.eudat.models.rda.Contributor; import eu.eudat.models.rda.ContributorId; import org.slf4j.Logger; @@ -14,15 +14,15 @@ import java.util.*; public class ContributorRDAMapper { private static final Logger logger = LoggerFactory.getLogger(ContributorRDAMapper.class); - public static Contributor toRDA(UserDMP userDMP) { + public static Contributor toRDA(DmpUserEntity userDMP) { Contributor rda = new Contributor(); - rda.setContributorId(ContributorIdRDAMapper.toRDA(userDMP.getUser().getId())); - if (userDMP.getUser().getName() == null) { - throw new IllegalArgumentException("Contributor Name is missing"); - } - rda.setName(userDMP.getUser().getName()); - rda.setMbox(userDMP.getUser().getEmail()); - rda.setRole(new HashSet<>(Arrays.asList(UserDMP.UserDMPRoles.fromInteger(userDMP.getRole()).name()))); + rda.setContributorId(ContributorIdRDAMapper.toRDA(userDMP.getUser())); +// if (userDMP.getUser().getName() == null) { //TODO +// throw new IllegalArgumentException("Contributor Name is missing"); +// } +// rda.setName(userDMP.getUser().getName()); +// rda.setMbox(userDMP.getUser().getEmail()); +// rda.setRole(new HashSet<>(Arrays.asList(UserDMP.UserDMPRoles.fromInteger(userDMP.getRole()).name()))); return rda; } 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 a5da59ac2..57105b220 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 @@ -2,6 +2,8 @@ package eu.eudat.models.rda.mapper; import eu.eudat.commons.enums.IsActive; import eu.eudat.data.DescriptionTemplateEntity; +import eu.eudat.data.DmpDescriptionTemplateEntity; +import eu.eudat.data.DmpEntity; import eu.eudat.data.EntityDoiEntity; import eu.eudat.data.old.*; import eu.eudat.logic.services.ApiContext; @@ -39,155 +41,155 @@ public class DmpRDAMapper { } @Transactional - public Dmp toRDA(DMP dmp) throws InvalidApplicationException { - if (dmp.getDataset() == null || dmp.getDataset().isEmpty()) { - throw new IllegalArgumentException("DMP has no Datasets"); - } - Map extraProperties; - if (dmp.getExtraProperties() == null) { - throw new IllegalArgumentException("DMP is missing language and contact properties"); - } else { - extraProperties = new org.json.JSONObject(dmp.getExtraProperties()).toMap(); - /*if (extraProperties.get("language") == null) { - throw new IllegalArgumentException("DMP must have it's language property defined"); - }*/ - if (extraProperties.get("contact") == null) { - throw new IllegalArgumentException("DMP must have it's contact property defined"); - } - } + public Dmp toRDA(DmpEntity dmp) throws InvalidApplicationException { +// if (dmp.getDataset() == null || dmp.getDataset().isEmpty()) { //TODO +// throw new IllegalArgumentException("DMP has no Datasets"); +// } +// Map extraProperties; +// if (dmp.getExtraProperties() == null) { +// throw new IllegalArgumentException("DMP is missing language and contact properties"); +// } else { +// extraProperties = new org.json.JSONObject(dmp.getExtraProperties()).toMap(); +// /*if (extraProperties.get("language") == null) { +// throw new IllegalArgumentException("DMP must have it's language property defined"); +// }*/ +// if (extraProperties.get("contact") == null) { +// throw new IllegalArgumentException("DMP must have it's contact property defined"); +// } +// } Dmp rda = new Dmp(); - if (dmp.getDois() != null && !dmp.getDois().isEmpty()) { - for(EntityDoiEntity doi: dmp.getDois()){ - if(doi.getRepositoryId().equals("Zenodo")){ - rda.setDmpId(DmpIdRDAMapper.toRDA(doi.getDoi())); - } - } - } else { - rda.setDmpId(DmpIdRDAMapper.toRDA(dmp.getId())); - } - if (dmp.getCreated() == null) { +// if (dmp.getDois() != null && !dmp.getDois().isEmpty()) { +// for(EntityDoiEntity doi: dmp.getDois()){ +// if(doi.getRepositoryId().equals("Zenodo")){ +// rda.setDmpId(DmpIdRDAMapper.toRDA(doi.getDoi())); +// } +// } +// } else { +// rda.setDmpId(DmpIdRDAMapper.toRDA(dmp.getId())); +// } + if (dmp.getCreatedAt() == null) { throw new IllegalArgumentException("DMP Created is missing"); } - if (dmp.getModified() == null) { + if (dmp.getUpdatedAt() == null) { throw new IllegalArgumentException("DMP Modified is missing"); } if (dmp.getLabel() == null) { throw new IllegalArgumentException("DMP Label is missing"); } - rda.setCreated(dmp.getCreated()); - rda.setDescription(dmp.getDescription()); - rda.setModified(dmp.getModified()); - rda.setTitle(dmp.getLabel()); - - if (!extraProperties.isEmpty()) { - if (extraProperties.get("ethicalIssues") != null) { - rda.setEthicalIssuesExist(Dmp.EthicalIssuesExist.fromValue(extraProperties.get("ethicalIssues").toString())); - } else { - rda.setEthicalIssuesExist(Dmp.EthicalIssuesExist.UNKNOWN); - } - rda.setLanguage(LanguageRDAMapper.mapLanguageIsoToRDAIso(extraProperties.get("language") != null ? extraProperties.get("language").toString() : "en")); - if (extraProperties.get("costs") != null) { - rda.setCost(new ArrayList<>()); - ((List) extraProperties.get("costs")).forEach(costl -> { - rda.getCost().add(CostRDAMapper.toRDA((Map)costl)); - }); - } - try { - UserInfo contactDb = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(UUID.fromString((String) extraProperties.get("contact"))); - UserInfo contact = new UserInfo(); - contact.setId(contactDb.getId()); - contact.setName(contactDb.getName()); - contact.setEmail(contactDb.getEmail()); - if (contact.getEmail() == null) { - for (UserDMP userDMP : dmp.getUsers()) { - if (userDMP.getDmp().getId() == dmp.getId() && userDMP.getUser().getEmail() != null) { - contact.setEmail(userDMP.getUser().getEmail()); - break; - } - } - } - rda.setContact(ContactRDAMapper.toRDA(contact)); - } catch (NoResultException e) { - logger.error(e.getMessage(), e); - } - } - - /*UserInfo creator; - if (dmp.getCreator() != null) { - creator = dmp.getCreator(); - } else { - creator = dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).map(UserDMP::getUser).findFirst().orElse(new UserInfo()); - } - rda.setContact(ContactRDAMapper.toRDA(creator));*/ - rda.setContributor(new ArrayList<>()); - if (dmp.getResearchers() != null && !dmp.getResearchers().isEmpty()) { - rda.getContributor().addAll(dmp.getResearchers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList())); - } -// rda.getContributor().addAll(dmp.getUsers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList())); - rda.setDataset(dmp.getDataset().stream().filter(dataset -> dataset.getIsActive() != IsActive.Inactive).map(dataset -> datasetRDAMapper.toRDA(dataset, rda)).collect(Collectors.toList())); - if (dmp.getProject() != null) { - rda.setProject(Collections.singletonList(ProjectRDAMapper.toRDA(dmp.getProject(), dmp.getGrant()))); - } - rda.setAdditionalProperty("templates", dmp.getAssociatedDmps().stream().map(datasetProfile -> datasetProfile.getId().toString()).toArray()); +// rda.setCreated(dmp.getCreated()); //TODO +// rda.setDescription(dmp.getDescription()); +// rda.setModified(dmp.getModified()); +// rda.setTitle(dmp.getLabel()); +// +// if (!extraProperties.isEmpty()) { +// if (extraProperties.get("ethicalIssues") != null) { +// rda.setEthicalIssuesExist(Dmp.EthicalIssuesExist.fromValue(extraProperties.get("ethicalIssues").toString())); +// } else { +// rda.setEthicalIssuesExist(Dmp.EthicalIssuesExist.UNKNOWN); +// } +// rda.setLanguage(LanguageRDAMapper.mapLanguageIsoToRDAIso(extraProperties.get("language") != null ? extraProperties.get("language").toString() : "en")); +// if (extraProperties.get("costs") != null) { +// rda.setCost(new ArrayList<>()); +// ((List) extraProperties.get("costs")).forEach(costl -> { +// rda.getCost().add(CostRDAMapper.toRDA((Map)costl)); +// }); +// } +// try { +// UserInfo contactDb = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(UUID.fromString((String) extraProperties.get("contact"))); +// UserInfo contact = new UserInfo(); +// contact.setId(contactDb.getId()); +// contact.setName(contactDb.getName()); +// contact.setEmail(contactDb.getEmail()); +// if (contact.getEmail() == null) { +// for (UserDMP userDMP : dmp.getUsers()) { +// if (userDMP.getDmp().getId() == dmp.getId() && userDMP.getUser().getEmail() != null) { +// contact.setEmail(userDMP.getUser().getEmail()); +// break; +// } +// } +// } +// rda.setContact(ContactRDAMapper.toRDA(contact)); +// } catch (NoResultException e) { +// logger.error(e.getMessage(), e); +// } +// } +// +// /*UserInfo creator; +// if (dmp.getCreator() != null) { +// creator = dmp.getCreator(); +// } else { +// creator = dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).map(UserDMP::getUser).findFirst().orElse(new UserInfo()); +// } +// rda.setContact(ContactRDAMapper.toRDA(creator));*/ +// rda.setContributor(new ArrayList<>()); +// if (dmp.getResearchers() != null && !dmp.getResearchers().isEmpty()) { +// rda.getContributor().addAll(dmp.getResearchers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList())); +// } +//// rda.getContributor().addAll(dmp.getUsers().stream().map(ContributorRDAMapper::toRDA).collect(Collectors.toList())); +// rda.setDataset(dmp.getDataset().stream().filter(dataset -> dataset.getIsActive() != IsActive.Inactive).map(dataset -> datasetRDAMapper.toRDA(dataset, rda)).collect(Collectors.toList())); +// if (dmp.getProject() != null) { +// rda.setProject(Collections.singletonList(ProjectRDAMapper.toRDA(dmp.getProject(), dmp.getGrant()))); +// } +// rda.setAdditionalProperty("templates", dmp.getAssociatedDmps().stream().map(datasetProfile -> datasetProfile.getId().toString()).toArray()); return rda; } - public DMP toEntity(Dmp rda, String[] profiles) throws InvalidApplicationException { - DMP entity = new DMP(); + public DmpEntity toEntity(Dmp rda, String[] profiles) throws InvalidApplicationException { + DmpEntity entity = new DmpEntity(); entity.setLabel(rda.getTitle()); - if (rda.getDmpId().getType() == DmpId.Type.DOI) { - try { - //TODO: Find from doi = rda.getDmpId().getIdentifier() - EntityDoiEntity doi = new EntityDoiEntity(); - Set dois = new HashSet<>(); - dois.add(doi); - entity.setDois(dois); - } - catch (NoResultException e) { - logger.warn("No entity doi: " + rda.getDmpId().getIdentifier() + " found in database. No dois are added to dmp."); - entity.setDois(new HashSet<>()); - } - } - if (((List) rda.getAdditionalProperties().get("templates")) != null && !((List) rda.getAdditionalProperties().get("templates")).isEmpty() && entity.getId() != null) { - entity.setAssociatedDmps(((List) rda.getAdditionalProperties().get("templates")).stream().map(x -> { - try { - return this.getProfile(x, entity.getId()); - } catch (InvalidApplicationException e) { - throw new RuntimeException(e); - } - }).filter(Objects::nonNull).collect(Collectors.toSet())); - } - if (entity.getAssociatedDmps() == null) { - entity.setAssociatedDmps(new HashSet<>()); - } - if (profiles != null && entity.getId() != null) { - for (String profile : profiles) { - entity.getAssociatedDmps().add(this.getProfile(profile, entity.getId())); - } - } - if (rda.getContributor() != null && !rda.getContributor().isEmpty() && rda.getContributor().get(0).getContributorId() != null) { - entity.setResearchers(rda.getContributor().stream().filter(r -> r.getContributorId() != null).map(ContributorRDAMapper::toEntity).filter(StreamDistinctBy.distinctByKey(Researcher::getReference)).collect(Collectors.toSet())); - } - entity.setCreated(rda.getCreated()); - entity.setModified(rda.getModified()); - entity.setDescription(rda.getDescription()); - DescriptionTemplateEntity defaultProfile = ((DescriptionTemplateEntity)entity.getAssociatedDmps().toArray()[0]); - entity.setDataset(rda.getDataset().stream().map(rda1 -> datasetRDAMapper.toEntity(rda1, defaultProfile)).collect(Collectors.toSet())); - if (rda.getProject().size() > 0) { - Map result = ProjectRDAMapper.toEntity(rda.getProject().get(0), apiContext); - entity.setProject((Project) result.get("project")); - result.entrySet().stream().filter(entry -> entry.getKey().startsWith("grant")).forEach(entry -> entity.setGrant((Grant) entry.getValue())); - } - - Map extraProperties = new HashMap<>(); - extraProperties.put("language", LanguageRDAMapper.mapRDAIsoToLanguageIso(rda.getLanguage())); - - entity.setExtraProperties(JSONObject.toJSONString(extraProperties)); +// if (rda.getDmpId().getType() == DmpId.Type.DOI) { //TODO +// try { +// //TODO: Find from doi = rda.getDmpId().getIdentifier() +// EntityDoiEntity doi = new EntityDoiEntity(); +// Set dois = new HashSet<>(); +// dois.add(doi); +// entity.setDois(dois); +// } +// catch (NoResultException e) { +// logger.warn("No entity doi: " + rda.getDmpId().getIdentifier() + " found in database. No dois are added to dmp."); +// entity.setDois(new HashSet<>()); +// } +// } +// if (((List) rda.getAdditionalProperties().get("templates")) != null && !((List) rda.getAdditionalProperties().get("templates")).isEmpty() && entity.getId() != null) { +// entity.setAssociatedDmps(((List) rda.getAdditionalProperties().get("templates")).stream().map(x -> { +// try { +// return this.getProfile(x, entity.getId()); +// } catch (InvalidApplicationException e) { +// throw new RuntimeException(e); +// } +// }).filter(Objects::nonNull).collect(Collectors.toSet())); +// } +// if (entity.getAssociatedDmps() == null) { +// entity.setAssociatedDmps(new HashSet<>()); +// } +// if (profiles != null && entity.getId() != null) { +// for (String profile : profiles) { +// entity.getAssociatedDmps().add(this.getProfile(profile, entity.getId())); +// } +// } +// if (rda.getContributor() != null && !rda.getContributor().isEmpty() && rda.getContributor().get(0).getContributorId() != null) { +// entity.setResearchers(rda.getContributor().stream().filter(r -> r.getContributorId() != null).map(ContributorRDAMapper::toEntity).filter(StreamDistinctBy.distinctByKey(Researcher::getReference)).collect(Collectors.toSet())); +// } +// entity.setCreated(rda.getCreated()); +// entity.setModified(rda.getModified()); +// entity.setDescription(rda.getDescription()); +// DescriptionTemplateEntity defaultProfile = ((DescriptionTemplateEntity)entity.getAssociatedDmps().toArray()[0]); +// entity.setDataset(rda.getDataset().stream().map(rda1 -> datasetRDAMapper.toEntity(rda1, defaultProfile)).collect(Collectors.toSet())); +// if (rda.getProject().size() > 0) { +// Map result = ProjectRDAMapper.toEntity(rda.getProject().get(0), apiContext); +// entity.setProject((Project) result.get("project")); +// result.entrySet().stream().filter(entry -> entry.getKey().startsWith("grant")).forEach(entry -> entity.setGrant((Grant) entry.getValue())); +// } +// +// Map extraProperties = new HashMap<>(); +// extraProperties.put("language", LanguageRDAMapper.mapRDAIsoToLanguageIso(rda.getLanguage())); +// +// entity.setExtraProperties(JSONObject.toJSONString(extraProperties)); return entity; } - private DMPDatasetProfile getProfile(String descriptionTemplateId, UUID dmpId) throws InvalidApplicationException { + private DmpDescriptionTemplateEntity getProfile(String descriptionTemplateId, UUID dmpId) throws InvalidApplicationException { return apiContext.getOperationsContext().getDatabaseRepository().getDmpDatasetProfileDao().asQueryable().where(((builder, root) -> builder.and( builder.equal(root.get("datasetprofile"), UUID.fromString(descriptionTemplateId)), builder.equal(root.get("dmp"), dmpId)) diff --git a/dmp-backend/web/src/main/java/eu/eudat/publicapi/criteria/dmp/DataManagementPlanPublicCriteria.java b/dmp-backend/web/src/main/java/eu/eudat/publicapi/criteria/dmp/DataManagementPlanPublicCriteria.java index 9c2cc721c..c9a4e3a26 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/publicapi/criteria/dmp/DataManagementPlanPublicCriteria.java +++ b/dmp-backend/web/src/main/java/eu/eudat/publicapi/criteria/dmp/DataManagementPlanPublicCriteria.java @@ -1,14 +1,14 @@ package eu.eudat.publicapi.criteria.dmp; +import eu.eudat.data.DmpEntity; import eu.eudat.data.dao.criteria.Criteria; -import eu.eudat.data.old.DMP; import io.swagger.annotations.ApiModelProperty; import java.util.Date; import java.util.List; import java.util.UUID; -public class DataManagementPlanPublicCriteria extends Criteria { +public class DataManagementPlanPublicCriteria 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/DataManagementPlanPublicManager.java b/dmp-backend/web/src/main/java/eu/eudat/publicapi/managers/DataManagementPlanPublicManager.java index d92c98324..bee4a9bbc 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/publicapi/managers/DataManagementPlanPublicManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/publicapi/managers/DataManagementPlanPublicManager.java @@ -1,6 +1,8 @@ package eu.eudat.publicapi.managers; -import eu.eudat.data.old.DMP; +import eu.eudat.commons.enums.DmpAccessType; +import eu.eudat.commons.enums.IsActive; +import eu.eudat.data.DmpEntity; import eu.eudat.exceptions.security.ForbiddenException; import eu.eudat.logic.managers.PaginationManager; import eu.eudat.logic.services.ApiContext; @@ -32,8 +34,8 @@ public class DataManagementPlanPublicManager { public DataTableData getPublicPaged(DataManagmentPlanPublicTableRequest dmpTableRequest, String fieldsGroup) throws Exception { dmpTableRequest.setQuery(databaseRepository.getDmpDao().asQueryable().withHint(HintedModelFactory.getHint(DataManagementPlanPublicListingModel.class))); - QueryableList items = dmpTableRequest.applyCriteria(); - QueryableList pagedItems = PaginationManager.applyPaging(items, dmpTableRequest); + QueryableList items = dmpTableRequest.applyCriteria(); + QueryableList pagedItems = PaginationManager.applyPaging(items, dmpTableRequest); DataTableData dataTable = new DataTableData<>(); @@ -62,11 +64,11 @@ public class DataManagementPlanPublicManager { } public DataManagementPlanPublicModel getOverviewSinglePublic(String id) throws Exception { - DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id)); - if (dataManagementPlanEntity.getStatus() == DMP.DMPStatus.DELETED.getValue()) { + DmpEntity dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id)); + if (dataManagementPlanEntity.getIsActive().equals(IsActive.Inactive)) { throw new Exception("DMP is deleted."); } - if (!dataManagementPlanEntity.isPublic()) { + if (!dataManagementPlanEntity.getAccessType().equals(DmpAccessType.Public)) { throw new ForbiddenException("Selected DMP is not public"); } DataManagementPlanPublicModel datamanagementPlan = new DataManagementPlanPublicModel(); diff --git a/dmp-backend/web/src/main/java/eu/eudat/publicapi/models/listingmodels/DataManagementPlanPublicListingModel.java b/dmp-backend/web/src/main/java/eu/eudat/publicapi/models/listingmodels/DataManagementPlanPublicListingModel.java index a2ec2b725..3b9934352 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/publicapi/models/listingmodels/DataManagementPlanPublicListingModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/publicapi/models/listingmodels/DataManagementPlanPublicListingModel.java @@ -1,6 +1,6 @@ package eu.eudat.publicapi.models.listingmodels; -import eu.eudat.data.old.DMP; +import eu.eudat.data.DmpEntity; import eu.eudat.data.old.Grant; import eu.eudat.models.DataModel; import eu.eudat.publicapi.models.researcher.ResearcherPublicModel; @@ -9,7 +9,7 @@ import eu.eudat.publicapi.models.user.UserInfoPublicModel; import java.util.*; import java.util.stream.Collectors; -public class DataManagementPlanPublicListingModel implements DataModel { +public class DataManagementPlanPublicListingModel implements DataModel { private String id; private String label; private String grant; @@ -100,70 +100,70 @@ public class DataManagementPlanPublicListingModel implements DataModel new UserInfoPublicModel().fromDataModel(x)).collect(Collectors.toList()) : new ArrayList<>(); - this.researchers = entity.getResearchers() != null ? entity.getResearchers().stream().map(x -> new ResearcherPublicModel().fromDataModel(x)).collect(Collectors.toList()) : new ArrayList<>(); - } - catch(Exception ex){ - this.users = new ArrayList<>(); - this.researchers = new ArrayList<>(); - } - this.finalizedAt = entity.getFinalizedAt(); - this.publishedAt = entity.getPublishedAt(); +// this.version = entity.getVersion(); //TODO +// if (entity.getGrant() != null) { +// this.grant = entity.getGrant().getLabel(); +// } +// this.createdAt = entity.getCreated(); +// this.modifiedAt = entity.getModified(); +// try { +// this.users = entity.getUsers() != null ? entity.getUsers().stream().map(x -> new UserInfoPublicModel().fromDataModel(x)).collect(Collectors.toList()) : new ArrayList<>(); +// this.researchers = entity.getResearchers() != null ? entity.getResearchers().stream().map(x -> new ResearcherPublicModel().fromDataModel(x)).collect(Collectors.toList()) : new ArrayList<>(); +// } +// catch(Exception ex){ +// this.users = new ArrayList<>(); +// this.researchers = new ArrayList<>(); +// } +// this.finalizedAt = entity.getFinalizedAt(); +// this.publishedAt = entity.getPublishedAt(); return this; } @Override - public DMP toDataModel() { - DMP entity = new DMP(); + public DmpEntity toDataModel() { + DmpEntity entity = new DmpEntity(); entity.setId(UUID.fromString(this.getId())); entity.setLabel(this.getLabel()); entity.setGroupId(this.getGroupId()); - entity.setCreated(this.getCreatedAt()); - entity.setFinalizedAt(this.getFinalizedAt()); - entity.setModified(this.getModifiedAt()); - entity.setPublishedAt(this.getPublishedAt()); - entity.setVersion(this.getVersion()); - - if (this.getGrant() != null) { - Grant grant = new Grant(); - grant.setLabel(this.getGrant()); - entity.setGrant(grant); - } - entity.setUsers(this.getUsers().stream().map(UserInfoPublicModel::toDataModel).collect(Collectors.toSet())); - entity.setResearchers(this.getResearchers().stream().map(ResearcherPublicModel::toDataModel).collect(Collectors.toSet())); +// entity.setCreated(this.getCreatedAt()); //TODO +// entity.setFinalizedAt(this.getFinalizedAt()); +// entity.setModified(this.getModifiedAt()); +// entity.setPublishedAt(this.getPublishedAt()); +// entity.setVersion(this.getVersion()); +// +// if (this.getGrant() != null) { +// Grant grant = new Grant(); +// grant.setLabel(this.getGrant()); +// entity.setGrant(grant); +// } +// entity.setUsers(this.getUsers().stream().map(UserInfoPublicModel::toDataModel).collect(Collectors.toSet())); +// entity.setResearchers(this.getResearchers().stream().map(ResearcherPublicModel::toDataModel).collect(Collectors.toSet())); return entity; } 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 d07501c70..1fb90f6ab 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,17 +1,12 @@ package eu.eudat.publicapi.models.listingmodels; -import eu.eudat.data.old.DMP; import eu.eudat.data.DescriptionEntity; -import eu.eudat.data.old.Grant; import eu.eudat.models.DataModel; import eu.eudat.publicapi.models.datasetprofile.DatasetProfilePublicModel; import eu.eudat.publicapi.models.user.UserInfoPublicModel; -import java.util.ArrayList; import java.util.Date; import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; public class DatasetPublicListingModel implements DataModel { private String id; 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 66c70e2fc..9ba70c9af 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 @@ -5,11 +5,10 @@ import com.fasterxml.jackson.databind.ObjectMapper; import eu.eudat.commons.enums.DescriptionStatus; import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity; -import eu.eudat.data.old.DMP; -import eu.eudat.data.old.DMPDatasetProfile; import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.commons.types.xml.XmlBuilder; +import eu.eudat.data.DmpEntity; import eu.eudat.models.DataModel; import eu.eudat.models.data.user.composite.PagedDatasetProfile; import eu.eudat.publicapi.models.associatedprofile.AssociatedProfilePublicModel; @@ -18,14 +17,13 @@ import eu.eudat.publicapi.models.grant.GrantPublicOverviewModel; import eu.eudat.publicapi.models.organisation.OrganizationPublicModel; import eu.eudat.publicapi.models.researcher.ResearcherPublicModel; import eu.eudat.publicapi.models.user.UserInfoPublicModel; -import org.json.JSONObject; import org.w3c.dom.Document; import org.w3c.dom.Element; import java.util.*; import java.util.stream.Collectors; -public class DataManagementPlanPublicModel implements DataModel { +public class DataManagementPlanPublicModel implements DataModel { private String id; private String label; private String profile; @@ -165,56 +163,56 @@ public class DataManagementPlanPublicModel implements DataModel new ResearcherPublicModel().fromDataModel(item)).collect(Collectors.toList()); - } +// if (entity.getResearchers() != null) { //TODO +// this.researchers = entity.getResearchers().stream().map(item -> new ResearcherPublicModel().fromDataModel(item)).collect(Collectors.toList()); +// } return this; } - public DataManagementPlanPublicModel fromDataModelDatasets(DMP entity) { + public DataManagementPlanPublicModel fromDataModelDatasets(DmpEntity entity) { this.fromDataModel(entity); - this.version = entity.getVersion(); - if (entity.getGrant() != null) { - this.grant = new GrantPublicOverviewModel().fromDataModel(entity.getGrant()); - } - if (entity.getProfile() != null) this.profile = entity.getProfile().getLabel(); - this.createdAt = entity.getCreated(); - this.modifiedAt = entity.getModified(); - this.finalizedAt = entity.getFinalizedAt(); - this.organisations = entity.getOrganisations().stream().map(item -> new OrganizationPublicModel().fromDataModel(item)).collect(Collectors.toList()); - this.datasets = entity.getDataset().stream().filter(dataset -> !dataset.getIsActive().equals(IsActive.Inactive) && !dataset.getStatus().equals(DescriptionStatus.Canceled)) - .map(datasetEntity-> { - DatasetPublicModel dataset = new DatasetPublicModel(); - dataset.setDatasetProfileDefinition(this.getPagedProfile(dataset.getStatus().getValue(), datasetEntity)); - dataset.fromDataModel(datasetEntity); - return dataset; - }).collect(Collectors.toList()); - this.users = entity.getUsers().stream().map(x -> new UserInfoPublicModel().fromDataModel(x)).collect(Collectors.toList()); - this.description = entity.getDescription(); - if (entity.getResearchers() != null) { - this.researchers = entity.getResearchers().stream().map(item -> new ResearcherPublicModel().fromDataModel(item)).collect(Collectors.toList()); - } - - if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) { - this.associatedProfiles = new LinkedList<>(); - for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) { - AssociatedProfilePublicModel associatedProfile = new AssociatedProfilePublicModel().fromData(dmpDescriptionProfile.getDatasetprofile()); - associatedProfile.setId(dmpDescriptionProfile.getId()); - try { - associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference>() {})); - } - catch (Exception e) { - associatedProfile.setData(null); - } - this.associatedProfiles.add(associatedProfile); - } - } - this.publishedAt = entity.getPublishedAt(); - this.dois = entity.getDois().stream().map(item -> new DoiPublicModel().fromDataModel(item)).collect(Collectors.toList()); + this.version = entity.getVersion();//TODO +// if (entity.getGrant() != null) { +// this.grant = new GrantPublicOverviewModel().fromDataModel(entity.getGrant()); +// } +// if (entity.getProfile() != null) this.profile = entity.getProfile().getLabel(); +// this.createdAt = entity.getCreated(); +// this.modifiedAt = entity.getModified(); +// this.finalizedAt = entity.getFinalizedAt(); +// this.organisations = entity.getOrganisations().stream().map(item -> new OrganizationPublicModel().fromDataModel(item)).collect(Collectors.toList()); +// this.datasets = entity.getDataset().stream().filter(dataset -> !dataset.getIsActive().equals(IsActive.Inactive) && !dataset.getStatus().equals(DescriptionStatus.Canceled)) +// .map(datasetEntity-> { +// DatasetPublicModel dataset = new DatasetPublicModel(); +// dataset.setDatasetProfileDefinition(this.getPagedProfile(dataset.getStatus().getValue(), datasetEntity)); +// dataset.fromDataModel(datasetEntity); +// return dataset; +// }).collect(Collectors.toList()); +// this.users = entity.getUsers().stream().map(x -> new UserInfoPublicModel().fromDataModel(x)).collect(Collectors.toList()); +// this.description = entity.getDescription(); +// if (entity.getResearchers() != null) { +// this.researchers = entity.getResearchers().stream().map(item -> new ResearcherPublicModel().fromDataModel(item)).collect(Collectors.toList()); +// } +// +// if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) { +// this.associatedProfiles = new LinkedList<>(); +// for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) { +// AssociatedProfilePublicModel associatedProfile = new AssociatedProfilePublicModel().fromData(dmpDescriptionProfile.getDatasetprofile()); +// associatedProfile.setId(dmpDescriptionProfile.getId()); +// try { +// associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference>() {})); +// } +// catch (Exception e) { +// associatedProfile.setData(null); +// } +// this.associatedProfiles.add(associatedProfile); +// } +// } +// this.publishedAt = entity.getPublishedAt(); +// this.dois = entity.getDois().stream().map(item -> new DoiPublicModel().fromDataModel(item)).collect(Collectors.toList()); return this; } @@ -245,7 +243,7 @@ public class DataManagementPlanPublicModel implements DataModel { +public class UserInfoPublicModel implements DataModel { private UUID id; private String name; private int role; @@ -41,23 +43,23 @@ public class UserInfoPublicModel implements DataModel { +public class DataManagmentPlanPublicTableRequest extends TableQuery { - public QueryableList applyCriteria() { - QueryableList query = this.getQuery(); + public QueryableList applyCriteria() { + QueryableList query = this.getQuery(); query.where((builder, root) -> builder.equal(root.get("isPublic"), true)); if (this.getCriteria().getLike() != null && !this.getCriteria().getLike().isEmpty()) query.where((builder, root) -> builder.or( @@ -89,12 +90,12 @@ public class DataManagmentPlanPublicTableRequest extends TableQuery root.get("groupId").in(this.getCriteria().getGroupIds())); } - query.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue())); + query.where((builder, root) -> builder.notEqual(root.get("isActive"), IsActive.Inactive)); return query; } @Override - public QueryableList applyPaging(QueryableList items) { + public QueryableList applyPaging(QueryableList items) { return PaginationService.applyPaging(items, this); } }