From a6d175dcb3a5e5e3a5acc7b7fe8c44ff20a5c5d3 Mon Sep 17 00:00:00 2001 From: Thomas Georgios Giannos Date: Fri, 24 Nov 2023 11:36:43 +0200 Subject: [PATCH 1/4] Adding migration for reference middle tables --- .../entities/DatasetDataRepositoryDao.java | 10 + .../DatasetDataRepositoryDaoImpl.java | 51 ++++ .../data/dao/entities/DatasetRegistryDao.java | 10 + .../dao/entities/DatasetRegistryDaoImpl.java | 51 ++++ .../eudat/data/entities/DatasetRegistry.java | 43 +++- .../operations/DatabaseRepository.java | 4 + .../operations/DatabaseRepositoryImpl.java | 22 ++ .../migration/ReferenceMigrationService.java | 237 ++++++++++++++++++ .../migration/MigrationController.java | 24 +- 9 files changed, 436 insertions(+), 16 deletions(-) create mode 100644 dmp-migration-tool/data/src/main/java/eu/old/eudat/data/dao/entities/DatasetDataRepositoryDao.java create mode 100644 dmp-migration-tool/data/src/main/java/eu/old/eudat/data/dao/entities/DatasetDataRepositoryDaoImpl.java create mode 100644 dmp-migration-tool/data/src/main/java/eu/old/eudat/data/dao/entities/DatasetRegistryDao.java create mode 100644 dmp-migration-tool/data/src/main/java/eu/old/eudat/data/dao/entities/DatasetRegistryDaoImpl.java create mode 100644 dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ReferenceMigrationService.java diff --git a/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/dao/entities/DatasetDataRepositoryDao.java b/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/dao/entities/DatasetDataRepositoryDao.java new file mode 100644 index 000000000..aee107ee8 --- /dev/null +++ b/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/dao/entities/DatasetDataRepositoryDao.java @@ -0,0 +1,10 @@ +package eu.old.eudat.data.dao.entities; + +import eu.old.eudat.data.dao.DatabaseAccessLayer; +import eu.old.eudat.data.entities.DatasetDataRepository; + +import java.util.UUID; + +public interface DatasetDataRepositoryDao extends DatabaseAccessLayer { + +} diff --git a/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/dao/entities/DatasetDataRepositoryDaoImpl.java b/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/dao/entities/DatasetDataRepositoryDaoImpl.java new file mode 100644 index 000000000..d37f0eba0 --- /dev/null +++ b/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/dao/entities/DatasetDataRepositoryDaoImpl.java @@ -0,0 +1,51 @@ +package eu.old.eudat.data.dao.entities; + +import eu.old.eudat.data.dao.DatabaseAccess; +import eu.old.eudat.data.dao.databaselayer.service.DatabaseService; +import eu.old.eudat.data.entities.DatasetDataRepository; +import eu.old.eudat.queryable.QueryableList; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +import java.util.UUID; +import java.util.concurrent.CompletableFuture; + +@Component +public class DatasetDataRepositoryDaoImpl extends DatabaseAccess implements DatasetDataRepositoryDao{ + + public DatasetDataRepositoryDaoImpl(DatabaseService databaseService) { + super(databaseService); + } + + @Override + public DatasetDataRepository createOrUpdate(DatasetDataRepository item) { + return this.getDatabaseService().createOrUpdate(item,DatasetDataRepository.class); + } + + @Override + public CompletableFuture createOrUpdateAsync(DatasetDataRepository item) { + return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item)); + } + + @Override + @Async + public DatasetDataRepository find(UUID id) { + return getDatabaseService().getQueryable(DatasetDataRepository.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle(); + } + + @Override + public DatasetDataRepository find(UUID id, String hint) { + throw new UnsupportedOperationException(); + } + + + @Override + public void delete(DatasetDataRepository item) { + this.getDatabaseService().delete(item); + } + + @Override + public QueryableList asQueryable() { + return this.getDatabaseService().getQueryable(DatasetDataRepository.class); + } +} diff --git a/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/dao/entities/DatasetRegistryDao.java b/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/dao/entities/DatasetRegistryDao.java new file mode 100644 index 000000000..bca4b5f4b --- /dev/null +++ b/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/dao/entities/DatasetRegistryDao.java @@ -0,0 +1,10 @@ +package eu.old.eudat.data.dao.entities; + +import eu.old.eudat.data.dao.DatabaseAccessLayer; +import eu.old.eudat.data.entities.DatasetRegistry; + +import java.util.UUID; + +public interface DatasetRegistryDao extends DatabaseAccessLayer { + +} diff --git a/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/dao/entities/DatasetRegistryDaoImpl.java b/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/dao/entities/DatasetRegistryDaoImpl.java new file mode 100644 index 000000000..35c58bccb --- /dev/null +++ b/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/dao/entities/DatasetRegistryDaoImpl.java @@ -0,0 +1,51 @@ +package eu.old.eudat.data.dao.entities; + +import eu.old.eudat.data.dao.DatabaseAccess; +import eu.old.eudat.data.dao.databaselayer.service.DatabaseService; +import eu.old.eudat.data.entities.DatasetRegistry; +import eu.old.eudat.queryable.QueryableList; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +import java.util.UUID; +import java.util.concurrent.CompletableFuture; + +@Component +public class DatasetRegistryDaoImpl extends DatabaseAccess implements DatasetRegistryDao { + + public DatasetRegistryDaoImpl(DatabaseService databaseService) { + super(databaseService); + } + + @Override + public DatasetRegistry createOrUpdate(DatasetRegistry item) { + return this.getDatabaseService().createOrUpdate(item,DatasetRegistry.class); + } + + @Override + public CompletableFuture createOrUpdateAsync(DatasetRegistry item) { + return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item)); + } + + @Override + @Async + public DatasetRegistry find(UUID id) { + return getDatabaseService().getQueryable(DatasetRegistry.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle(); + } + + @Override + public DatasetRegistry find(UUID id, String hint) { + throw new UnsupportedOperationException(); + } + + + @Override + public void delete(DatasetRegistry item) { + this.getDatabaseService().delete(item); + } + + @Override + public QueryableList asQueryable() { + return this.getDatabaseService().getQueryable(DatasetRegistry.class); + } +} diff --git a/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/DatasetRegistry.java b/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/DatasetRegistry.java index 4a4d39334..f8504989c 100644 --- a/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/DatasetRegistry.java +++ b/dmp-migration-tool/data/src/main/java/eu/old/eudat/data/entities/DatasetRegistry.java @@ -1,17 +1,19 @@ package eu.old.eudat.data.entities; +import eu.old.eudat.queryable.queryableentity.DataEntity; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Type; import jakarta.persistence.*; import java.io.Serializable; +import java.util.List; import java.util.UUID; @Entity @Table(name = "\"DatasetRegistry\"") -public class DatasetRegistry { +public class DatasetRegistry implements DataEntity { @Id @GeneratedValue @@ -19,13 +21,13 @@ public class DatasetRegistry { @Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)") private UUID id; - //DEPWARN dependency to Hibernate and PostgreSQL - @Column(name = "\"Dataset\"", nullable = false) - private UUID dataset; + @ManyToOne + @JoinColumn(name = "\"Dataset\"", nullable = false) + private Dataset dataset; - //DEPWARN dependency to Hibernate and PostgreSQL - @Column(name = "\"Registry\"", nullable = false) - private UUID registry; + @ManyToOne + @JoinColumn(name = "\"Registry\"", nullable = false) + private Registry registry; @Column(name = "\"Role\"") private Integer role; @@ -41,19 +43,19 @@ public class DatasetRegistry { this.id = id; } - public UUID getDataset() { + public Dataset getDataset() { return dataset; } - public void setDataset(UUID dataset) { + public void setDataset(Dataset dataset) { this.dataset = dataset; } - public UUID getRegistry() { + public Registry getRegistry() { return registry; } - public void setRegistry(UUID registry) { + public void setRegistry(Registry registry) { this.registry = registry; } @@ -72,4 +74,23 @@ public class DatasetRegistry { public void setData(String data) { this.data = data; } + + @Override + public void update(DatasetRegistry entity) { + this.dataset = entity.getDataset(); + this.registry = entity.getRegistry(); + this.role = entity.getRole(); + } + + @Override + public UUID getKeys() { + return this.id; + } + + @Override + public DatasetRegistry buildFromTuple(List tuple, List fields, String base) { + String currentBase = base.isEmpty() ? "" : base + "."; + if(fields.contains(currentBase + "id")) this.id = UUID.fromString((String) tuple.get(0).get(currentBase + "id")); + return this; + } } diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/logic/services/operations/DatabaseRepository.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/logic/services/operations/DatabaseRepository.java index a7562153b..43893e142 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/logic/services/operations/DatabaseRepository.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/logic/services/operations/DatabaseRepository.java @@ -48,8 +48,12 @@ public interface DatabaseRepository { DatasetExternalDatasetDao getDatasetExternalDatasetDao(); + DatasetDataRepositoryDao getDatasetDataRepositoryDao(); + DatasetServiceDao getDatasetServiceDao(); + DatasetRegistryDao getDatasetRegistryDao(); + EmailConfirmationDao getLoginConfirmationEmailDao(); ProjectDao getProjectDao(); diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/logic/services/operations/DatabaseRepositoryImpl.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/logic/services/operations/DatabaseRepositoryImpl.java index ef8006f81..6e22d5b57 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/logic/services/operations/DatabaseRepositoryImpl.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/logic/services/operations/DatabaseRepositoryImpl.java @@ -33,7 +33,9 @@ public class DatabaseRepositoryImpl implements DatabaseRepository { private ContentDao contentDao; private DMPProfileDao dmpProfileDao; private DatasetExternalDatasetDao datasetExternalDatasetDao; + private DatasetDataRepositoryDao datasetDataRepositoryDao; private DatasetServiceDao datasetServiceDao; + private DatasetRegistryDao datasetRegistryDao; private EmailConfirmationDao loginConfirmationEmailDao; private ProjectDao projectDao; private FunderDao funderDao; @@ -250,6 +252,16 @@ public class DatabaseRepositoryImpl implements DatabaseRepository { this.datasetExternalDatasetDao = datasetExternalDatasetDao; } + @Override + public DatasetDataRepositoryDao getDatasetDataRepositoryDao() { + return datasetDataRepositoryDao; + } + + @Autowired + public void setDatasetDataRepositoryDao(DatasetDataRepositoryDao datasetDataRepositoryDao) { + this.datasetDataRepositoryDao = datasetDataRepositoryDao; + } + @Override public DatasetServiceDao getDatasetServiceDao() { return datasetServiceDao; @@ -260,6 +272,16 @@ public class DatabaseRepositoryImpl implements DatabaseRepository { this.datasetServiceDao = datasetServiceDao; } + @Override + public DatasetRegistryDao getDatasetRegistryDao() { + return datasetRegistryDao; + } + + @Autowired + public void setDatasetRegistryDao(DatasetRegistryDao datasetRegistryDao) { + this.datasetRegistryDao = datasetRegistryDao; + } + @Override public EmailConfirmationDao getLoginConfirmationEmailDao() { return loginConfirmationEmailDao; diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ReferenceMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ReferenceMigrationService.java new file mode 100644 index 000000000..d7b6d2e5b --- /dev/null +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/ReferenceMigrationService.java @@ -0,0 +1,237 @@ +package eu.old.eudat.migration; + +import eu.eudat.commons.enums.IsActive; +import eu.eudat.data.DescriptionReferenceEntity; +import eu.eudat.data.DmpReferenceEntity; +import eu.old.eudat.data.dao.entities.*; +import eu.old.eudat.data.entities.*; +import eu.old.eudat.logic.services.operations.DatabaseRepository; +import gr.cite.tools.data.query.QueryFactory; +import gr.cite.tools.logging.LoggerService; +import jakarta.persistence.EntityManager; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import java.time.Instant; +import java.util.List; +import java.util.UUID; + +@Service +public class ReferenceMigrationService { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpDatasetProfileMigrationService.class)); + private final DatabaseRepository databaseRepository; + private final QueryFactory queryFactory; + private static final int PageSize = 500; + private static final boolean TestMode = false; + private final EntityManager entityManager; + + public ReferenceMigrationService(DatabaseRepository databaseRepository, QueryFactory queryFactory, EntityManager entityManager) { + this.databaseRepository = databaseRepository; + this.queryFactory = queryFactory; + this.entityManager = entityManager; + } + + public void migrateDmpReferences() { + migrateDmpOrganizations(); + migrateDmpResearchers(); + } + + public void migrateDatasetReferences() { + migrateDatasetDataRepositories(); + migrateDatasetExternalDatasets(); + migrateDatasetRegistries(); + migrateDatasetServices(); + } + + public void migrateDmpOrganizations() { + OrganisationDao organisationDao = databaseRepository.getOrganisationDao(); + long total = organisationDao.asQueryable().count(); + logger.debug("Migrate Dmp Organisation (from Organization) Total : " + total); + int page = 0; + + List items; + do { + items = organisationDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList(); + if (items != null && !items.isEmpty()) { + logger.debug("Migrate Dmp Organisation " + page * PageSize + " of " + total); + + for (Organisation item : items) { +// entityManager.detach(item); + + for (DMP dmp : item.getDmps()) { + DmpReferenceEntity data = new DmpReferenceEntity(); + data.setId(UUID.randomUUID()); + data.setDmpId(dmp.getId()); + data.setReferenceId(item.getId()); + data.setCreatedAt(dmp.getCreated() != null ? dmp.getCreated().toInstant() : Instant.now()); + data.setUpdatedAt(dmp.getModified() != null ? dmp.getModified().toInstant() : Instant.now()); + data.setIsActive(IsActive.Active); + this.entityManager.persist(data); + } + } + this.entityManager.flush(); + + page++; + } + } while (items != null && !items.isEmpty()); + } + + public void migrateDmpResearchers() { + ResearcherDao researcherDao = databaseRepository.getResearcherDao(); + long total = researcherDao.asQueryable().count(); + logger.debug("Migrate Dmp Researcher (from Researcher) Total : " + total); + int page = 0; + + List items; + do { + items = researcherDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList(); + if (items != null && !items.isEmpty()) { + logger.debug("Migrate Dmp Researcher " + page * PageSize + " of " + total); + + for (Researcher item : items) { +// entityManager.detach(item); + + for (DMP dmp : item.getdMPs()) { + DmpReferenceEntity data = new DmpReferenceEntity(); + data.setId(UUID.randomUUID()); + data.setDmpId(dmp.getId()); + data.setReferenceId(item.getId()); + data.setCreatedAt(dmp.getCreated() != null ? dmp.getCreated().toInstant() : Instant.now()); + data.setUpdatedAt(dmp.getModified() != null ? dmp.getModified().toInstant() : Instant.now()); + data.setIsActive(IsActive.Active); + this.entityManager.persist(data); + } + } + this.entityManager.flush(); + + page++; + } + } while (items != null && !items.isEmpty()); + } + + public void migrateDatasetDataRepositories() { + DatasetDataRepositoryDao datasetDataRepositoryDao = databaseRepository.getDatasetDataRepositoryDao(); + long total = datasetDataRepositoryDao.asQueryable().count(); + logger.debug("Migrate Dataset DataRepository (from DatasetDataRepository) Total : " + total); + int page = 0; + + List items; + do { + items = datasetDataRepositoryDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("id"))).skip(page * PageSize).take(PageSize).toList(); + if (items != null && !items.isEmpty()) { + logger.debug("Migrate Dataset DataRepository " + page * PageSize + " of " + total); + + for (DatasetDataRepository item : items) { +// entityManager.detach(item); + + DescriptionReferenceEntity data = new DescriptionReferenceEntity(); + data.setId(UUID.randomUUID()); + data.setDescriptionId(item.getDataset().getId()); + data.setReferenceId(item.getDataRepository().getId()); + data.setCreatedAt(item.getDataset().getCreated() != null ? item.getDataset().getCreated().toInstant() : Instant.now()); + data.setUpdatedAt(item.getDataset().getModified() != null ? item.getDataset().getModified().toInstant() : Instant.now()); + data.setIsActive(IsActive.Active); + this.entityManager.persist(data); + } + this.entityManager.flush(); + + page++; + } + } while (items != null && !items.isEmpty()); + } + + public void migrateDatasetExternalDatasets() { + DatasetExternalDatasetDao datasetExternalDatasetDao = databaseRepository.getDatasetExternalDatasetDao(); + long total = datasetExternalDatasetDao.asQueryable().count(); + logger.debug("Migrate Dataset ExternalDataset (from DatasetExternalDataset) Total : " + total); + int page = 0; + + List items; + do { + items = datasetExternalDatasetDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("id"))).skip(page * PageSize).take(PageSize).toList(); + if (items != null && !items.isEmpty()) { + logger.debug("Migrate Dataset ExternalDataset " + page * PageSize + " of " + total); + + for (DatasetExternalDataset item : items) { +// entityManager.detach(item); + + DescriptionReferenceEntity data = new DescriptionReferenceEntity(); + data.setId(UUID.randomUUID()); + data.setDescriptionId(item.getDataset().getId()); + data.setReferenceId(item.getExternalDataset().getId()); + data.setCreatedAt(item.getDataset().getCreated() != null ? item.getDataset().getCreated().toInstant() : Instant.now()); + data.setUpdatedAt(item.getDataset().getModified() != null ? item.getDataset().getModified().toInstant() : Instant.now()); + data.setIsActive(IsActive.Active); + this.entityManager.persist(data); + } + this.entityManager.flush(); + + page++; + } + } while (items != null && !items.isEmpty()); + } + + public void migrateDatasetRegistries() { + DatasetRegistryDao datasetRegistryDao = databaseRepository.getDatasetRegistryDao(); + long total = datasetRegistryDao.asQueryable().count(); + logger.debug("Migrate Dataset Registry (from DatasetRegistry) Total : " + total); + int page = 0; + + List items; + do { + items = datasetRegistryDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("id"))).skip(page * PageSize).take(PageSize).toList(); + if (items != null && !items.isEmpty()) { + logger.debug("Migrate Dataset Registry " + page * PageSize + " of " + total); + + for (DatasetRegistry item : items) { +// entityManager.detach(item); + + DescriptionReferenceEntity data = new DescriptionReferenceEntity(); + data.setId(UUID.randomUUID()); + data.setDescriptionId(item.getDataset().getId()); + data.setReferenceId(item.getRegistry().getId()); + data.setCreatedAt(item.getDataset().getCreated() != null ? item.getDataset().getCreated().toInstant() : Instant.now()); + data.setUpdatedAt(item.getDataset().getModified() != null ? item.getDataset().getModified().toInstant() : Instant.now()); + data.setIsActive(IsActive.Active); + this.entityManager.persist(data); + } + this.entityManager.flush(); + + page++; + } + } while (items != null && !items.isEmpty()); + } + + public void migrateDatasetServices() { + DatasetServiceDao datasetServiceDao = databaseRepository.getDatasetServiceDao(); + long total = datasetServiceDao.asQueryable().count(); + logger.debug("Migrate Dataset Service (from DatasetService) Total : " + total); + int page = 0; + + List items; + do { + items = datasetServiceDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("id"))).skip(page * PageSize).take(PageSize).toList(); + if (items != null && !items.isEmpty()) { + logger.debug("Migrate Dataset Service " + page * PageSize + " of " + total); + + for (DatasetService item : items) { +// entityManager.detach(item); + + DescriptionReferenceEntity data = new DescriptionReferenceEntity(); + data.setId(UUID.randomUUID()); + data.setDescriptionId(item.getDataset().getId()); + data.setReferenceId(item.getService().getId()); + data.setCreatedAt(item.getDataset().getCreated() != null ? item.getDataset().getCreated().toInstant() : Instant.now()); + data.setUpdatedAt(item.getDataset().getModified() != null ? item.getDataset().getModified().toInstant() : Instant.now()); + data.setIsActive(IsActive.Active); + this.entityManager.persist(data); + } + this.entityManager.flush(); + + page++; + } + } while (items != null && !items.isEmpty()); + } + +} diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/publicapi/migration/MigrationController.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/publicapi/migration/MigrationController.java index 17ea9321a..df7fd0718 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/publicapi/migration/MigrationController.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/publicapi/migration/MigrationController.java @@ -32,6 +32,7 @@ public class MigrationController { private final DatasetMigrationService datasetMigrationService; private final DmpDatasetProfileMigrationService dmpDatasetProfileMigrationService; private final OrganizationMigrationService organizationMigrationService; + private final ReferenceMigrationService referenceMigrationService; public MigrationController( DmpMigrationService dmpMigrationService, @@ -45,8 +46,8 @@ public class MigrationController { RegistryMigrationService registryMigrationService, ResearcherMigrationService researcherMigrationService, ServiceMigrationService serviceMigrationService, - OrganizationMigrationService organizationMigrationService - ) { + OrganizationMigrationService organizationMigrationService, + ReferenceMigrationService referenceMigrationService) { this.dmpMigrationService = dmpMigrationService; this.datasetMigrationService = datasetMigrationService; this.dmpDatasetProfileMigrationService = dmpDatasetProfileMigrationService; @@ -59,6 +60,7 @@ public class MigrationController { this.researcherMigrationService = researcherMigrationService; this.serviceMigrationService = serviceMigrationService; this.organizationMigrationService = organizationMigrationService; + this.referenceMigrationService = referenceMigrationService; } @GetMapping("dmps") @@ -79,11 +81,9 @@ public class MigrationController { @Transactional public boolean migrateDmpDatasetProfiles() throws IOException, JAXBException, ParserConfigurationException, InstantiationException, IllegalAccessException, SAXException { this.dmpDatasetProfileMigrationService.migrate(); - return true; } - @GetMapping("references") @Transactional public boolean migrateReferences() { @@ -97,7 +97,21 @@ public class MigrationController { this.researcherMigrationService.migrate(); this.serviceMigrationService.migrate(); return true; - } + } + + @GetMapping("dmp-references") + @Transactional + public boolean migrateDmpReferences() { + this.referenceMigrationService.migrateDmpReferences(); + return true; + } + + @GetMapping("dataset-references") + @Transactional + public boolean migrateDatasetReferences() { + this.referenceMigrationService.migrateDatasetReferences(); + return true; + } @GetMapping("organizations") @Transactional From c60e90d6380aa95b2dbf717de79453a2cae97a2d Mon Sep 17 00:00:00 2001 From: Thomas Georgios Giannos Date: Fri, 24 Nov 2023 12:15:57 +0200 Subject: [PATCH 2/4] Removing possible duplicate records after DmpDatasetProfile migration --- .../DmpDatasetProfileMigrationService.java | 34 ++++++++++++++++++- .../migration/MigrationController.java | 2 +- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpDatasetProfileMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpDatasetProfileMigrationService.java index c91a3fb3e..7fe610249 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpDatasetProfileMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpDatasetProfileMigrationService.java @@ -16,12 +16,14 @@ import eu.eudat.data.ReferenceEntity; import eu.eudat.model.DmpBlueprint; import eu.eudat.query.DescriptionTemplateQuery; import eu.eudat.query.DmpBlueprintQuery; +import eu.eudat.query.DmpDescriptionTemplateQuery; import eu.old.eudat.data.dao.entities.DmpDatasetProfileDao; import eu.old.eudat.data.dao.entities.ResearcherDao; import eu.old.eudat.data.entities.DMPDatasetProfile; import eu.old.eudat.data.entities.Researcher; import eu.old.eudat.logic.services.operations.DatabaseRepository; import eu.old.eudat.queryable.QueryableList; +import gr.cite.tools.data.query.Paging; import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.logging.LoggerService; @@ -120,9 +122,39 @@ public class DmpDatasetProfileMigrationService { } } while (items != null && !items.isEmpty() && !TestMode); + removeDuplicates(); + } + private void removeDuplicates() { + logger.debug("Checking for duplicates on DmpDescriptionTemplate table after migration"); + int page = 0; - //TODO CLEAN Duplicates dmp, DescriptionTemplate, SectionId + DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class); + List dmpDescriptionTemplateEntities; + do { + dmpDescriptionTemplateQuery.setPage(new Paging(page * PageSize, PageSize)); + dmpDescriptionTemplateEntities = dmpDescriptionTemplateQuery.collect(); + + DmpDescriptionTemplateEntity previousEntity = null; + for(DmpDescriptionTemplateEntity currentEntity : dmpDescriptionTemplateEntities) { + if (previousEntity == null) { + previousEntity = currentEntity; + continue; + } + if (currentEntity.getDmpId().equals(previousEntity.getDmpId()) + && currentEntity.getDescriptionTemplateId().equals(previousEntity.getDescriptionTemplateId()) + && currentEntity.getSectionId().equals(previousEntity.getSectionId()) + ) { + logger.warn("Removing found duplicate DmpDescriptionTemplate entity ({}) after DmpDatasetProfiles migration", currentEntity.getId()); + this.entityManager.remove(currentEntity); + } else { + previousEntity = currentEntity; + } + } + entityManager.flush(); + + page++; + } while (!dmpDescriptionTemplateEntities.isEmpty() && !TestMode); } @JsonIgnoreProperties({"validationErrorModel"}) diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/publicapi/migration/MigrationController.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/publicapi/migration/MigrationController.java index df7fd0718..5940961a5 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/publicapi/migration/MigrationController.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/publicapi/migration/MigrationController.java @@ -81,7 +81,7 @@ public class MigrationController { @Transactional public boolean migrateDmpDatasetProfiles() throws IOException, JAXBException, ParserConfigurationException, InstantiationException, IllegalAccessException, SAXException { this.dmpDatasetProfileMigrationService.migrate(); - return true; + return true; } @GetMapping("references") From e698b198e720a133fd6ab0fcecaef7522f2a2413 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Fri, 24 Nov 2023 12:39:26 +0200 Subject: [PATCH 3/4] add description template to description --- .../java/eu/eudat/data/DescriptionEntity.java | 62 ++++---------- .../data/DmpDescriptionTemplateEntity.java | 14 +-- .../DescriptionElasticBuilder.java | 14 +-- .../elasticbuilder/DmpElasticBuilder.java | 4 +- .../main/java/eu/eudat/model/Description.java | 12 +++ .../eudat/model/DmpDescriptionTemplate.java | 37 ++++++-- .../eu/eudat/model/PublicDescription.java | 12 +++ .../model/PublicDmpDescriptionTemplate.java | 11 --- .../model/builder/DescriptionBuilder.java | 36 +++++++- .../DmpDescriptionTemplateBuilder.java | 85 ++++++++++++------- .../builder/PublicDescriptionBuilder.java | 38 ++++++++- .../PublicDmpDescriptionTemplateBuilder.java | 30 ------- .../model/censorship/DescriptionCensor.java | 3 + .../DmpDescriptionTemplateCensor.java | 6 +- .../censorship/PublicDescriptionCensor.java | 4 + .../PublicDmpDescriptionTemplateCensor.java | 2 - .../censorship/UserAdditionalInfoCensor.java | 9 +- .../deleter/DescriptionTemplateDeleter.java | 3 +- .../deposit/DmpEntityDepositMapper.java | 7 +- .../model/persist/DescriptionPersist.java | 12 +++ .../DmpDescriptionTemplatePersist.java | 31 ++----- .../java/eu/eudat/query/DescriptionQuery.java | 4 + .../eudat/query/DescriptionTemplateQuery.java | 4 +- .../query/DmpDescriptionTemplateQuery.java | 31 ++++--- .../description/DescriptionServiceImpl.java | 3 + .../eu/eudat/service/dmp/DmpServiceImpl.java | 58 +++++-------- .../managers/DataManagementPlanManager.java | 10 +-- .../eudat/logic/managers/DatasetManager.java | 10 +-- .../logic/managers/DatasetWizardManager.java | 2 +- .../eudat/logic/managers/MetricsManager.java | 2 +- .../models/rda/mapper/DatasetRDAMapper.java | 2 +- .../eudat/models/rda/mapper/DmpRDAMapper.java | 6 +- ...012_Add_Dmp_description_template_table.sql | 6 +- .../updates/00.01.014_sync_Description.sql | 10 +++ 34 files changed, 326 insertions(+), 254 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionEntity.java index 59ccd8c68..e8265d54a 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/DescriptionEntity.java @@ -80,6 +80,12 @@ public class DescriptionEntity implements DataEntity { @Column(name = "dmp", columnDefinition = "uuid", nullable = false) private UUID dmpId; + @Column(name = "description_template", columnDefinition = "uuid", nullable = false) + private UUID descriptionTemplateId; + + public static final String _descriptionTemplateId = "descriptionTemplateId"; + + public static final String _dmpId = "dmpId"; public UUID getId() { @@ -178,55 +184,17 @@ public class DescriptionEntity implements DataEntity { this.dmpId = dmpId; } + public UUID getDescriptionTemplateId() { + return descriptionTemplateId; + } + + public void setDescriptionTemplateId(UUID descriptionTemplateId) { + this.descriptionTemplateId = descriptionTemplateId; + } + @Override public void update(DescriptionEntity entity) { -// this.setUri(entity.getUri()); -// this.setDescription(entity.getDescription()); -// this.setLabel(entity.getLabel()); -// this.setProperties(entity.getProperties()); -// -// if (entity.getDatasetDataRepositories() == null || entity.getDatasetDataRepositories().size() < 1) { -// if (this.getDatasetDataRepositories() != null) this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories()); -// } else { -// if (this.getDatasetDataRepositories() != null) { -// this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories()); -// } else { -// this.setDatasetDataRepositories(new HashSet<>()); -// } -// this.getDatasetDataRepositories().addAll(entity.getDatasetDataRepositories().stream().peek(item -> item.setDataset(this)).collect(Collectors.toList())); -// } -// -// if (entity.getDatasetExternalDatasets() == null || entity.getDatasetExternalDatasets().size() < 1) { -// if (this.getDatasetExternalDatasets() != null) this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets()); -// } else { -// if (this.getDatasetExternalDatasets() != null) { -// this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets()); -// } else { -// this.setDatasetExternalDatasets(new HashSet<>()); -// } -// this.getDatasetExternalDatasets().addAll(entity.getDatasetExternalDatasets().stream().peek(item -> item.setDataset(this)).collect(Collectors.toList())); -// } -// -// if (entity.getServices() == null || entity.getServices().size() < 1) { -// if (this.getServices() != null) this.getServices().removeAll(this.getServices()); -// } else { -// if (this.getServices() != null) { -// this.getServices().removeAll(this.getServices()); -// } else { -// this.setServices(new HashSet<>()); -// } -// this.getServices().addAll(entity.getServices().stream().peek(item -> item.setDataset(this)).collect(Collectors.toList())); -// } -// -// this.setRegistries(entity.getRegistries()); -// -// this.setDmp(entity.getDmp()); -// this.setDmpSectionIndex(entity.getDmpSectionIndex()); -// this.setStatus(entity.getStatus()); -// this.setProfile(entity.getProfile()); -// this.setModified(new Date()); -// if (entity.getStatus().equals(Status.FINALISED.getValue())) this.setFinalizedAt(new Date()); -// if (entity.getCreator() != null) this.creator = entity.getCreator(); + } @Override 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 ee532bb7e..760a5bb78 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 @@ -24,10 +24,10 @@ public class DmpDescriptionTemplateEntity { public static final String _dmpId = "dmpId"; - @Column(name = "description_template", columnDefinition = "uuid", nullable = false) - private UUID descriptionTemplateId; + @Column(name = "description_template_group", columnDefinition = "uuid", nullable = false) + private UUID descriptionTemplateGroupId; - public static final String _descriptionTemplateId = "descriptionTemplateId"; + public static final String _descriptionTemplateGroupId = "descriptionTemplateGroupId"; @Column(name = "section_id") private UUID sectionId; @@ -66,12 +66,12 @@ public class DmpDescriptionTemplateEntity { this.dmpId = dmpId; } - public UUID getDescriptionTemplateId() { - return descriptionTemplateId; + public UUID getDescriptionTemplateGroupId() { + return descriptionTemplateGroupId; } - public void setDescriptionTemplateId(UUID descriptionTemplateId) { - this.descriptionTemplateId = descriptionTemplateId; + public void setDescriptionTemplateGroupId(UUID descriptionTemplateGroupId) { + this.descriptionTemplateGroupId = descriptionTemplateGroupId; } public UUID getSectionId() { diff --git a/dmp-backend/core/src/main/java/eu/eudat/elastic/elasticbuilder/DescriptionElasticBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/elastic/elasticbuilder/DescriptionElasticBuilder.java index ef5ce69ed..82807d757 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/elastic/elasticbuilder/DescriptionElasticBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/elastic/elasticbuilder/DescriptionElasticBuilder.java @@ -127,23 +127,15 @@ public class DescriptionElasticBuilder extends BaseElasticBuilder collectDescriptionTemplates(List data) throws MyApplicationException { if (data.isEmpty()) return null; this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName()); - DmpDescriptionTemplateQuery associationQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(data.stream().map(DescriptionEntity::getDmpDescriptionTemplateId).collect(Collectors.toList())).isActive(IsActive.Active); - List associationEntities = associationQuery.collect(); + Map itemMap; + DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).ids(data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(NestedDescriptionTemplateElasticBuilder.class).asForeignKey(q, NestedDescriptionTemplateElasticEntity::getId); - DescriptionTemplateQuery query = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).ids(associationEntities.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList())); - Map itemMapById = this.builderFactory.builder(NestedDescriptionTemplateElasticBuilder.class).asForeignKey(query, NestedDescriptionTemplateElasticEntity::getId); - - Map itemMap = new HashMap<>(); - for (DmpDescriptionTemplateEntity associationEntity : associationEntities){ - itemMap.put(associationEntity.getId(), itemMapById.getOrDefault(associationEntity.getDescriptionTemplateId(), null)); - } return itemMap; } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/elastic/elasticbuilder/DmpElasticBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/elastic/elasticbuilder/DmpElasticBuilder.java index f75f6acff..ee37e23ad 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/elastic/elasticbuilder/DmpElasticBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/elastic/elasticbuilder/DmpElasticBuilder.java @@ -99,13 +99,13 @@ public class DmpElasticBuilder extends BaseElasticBuilder associationEntities = associationQuery.collect(); - DescriptionTemplateQuery query = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).ids(associationEntities.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList())); + DescriptionTemplateQuery query = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).groupIds(associationEntities.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateGroupId).distinct().collect(Collectors.toList())); Map itemMapById = this.builderFactory.builder(NestedDescriptionTemplateElasticBuilder.class).asForeignKey(query, NestedDescriptionTemplateElasticEntity::getId); Map> itemMap = new HashMap<>(); for (DmpDescriptionTemplateEntity associationEntity : associationEntities){ if (!itemMap.containsKey(associationEntity.getDmpId())) itemMap.put(associationEntity.getDmpId(), new ArrayList<>()); - NestedDescriptionTemplateElasticEntity item = itemMapById.getOrDefault(associationEntity.getDescriptionTemplateId(), null); + NestedDescriptionTemplateElasticEntity item = itemMapById.getOrDefault(associationEntity.getDescriptionTemplateGroupId(), null); if (item != null) itemMap.get(associationEntity.getDmpId()).add(item); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/Description.java b/dmp-backend/core/src/main/java/eu/eudat/model/Description.java index e0d526396..40ae2681a 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/Description.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/Description.java @@ -67,6 +67,10 @@ public class Description { public static final String _dmpDescriptionTemplate = "dmpDescriptionTemplate"; + private DescriptionTemplate descriptionTemplate; + + public static final String _descriptionTemplate = "descriptionTemplate"; + private Dmp dmp; public static final String _dmp = "dmp"; @@ -191,4 +195,12 @@ public class Description { public void setDmp(Dmp dmp) { this.dmp = dmp; } + + public DescriptionTemplate getDescriptionTemplate() { + return descriptionTemplate; + } + + public void setDescriptionTemplate(DescriptionTemplate descriptionTemplate) { + this.descriptionTemplate = descriptionTemplate; + } } 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 11f5bf736..9d494af57 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 @@ -17,14 +17,23 @@ public class DmpDescriptionTemplate{ public static final String _dmp = "dmp"; - private DescriptionTemplate descriptionTemplate; + private DescriptionTemplate currentDescriptionTemplate; - public static final String _descriptionTemplate = "descriptionTemplate"; + public static final String _currentDescriptionTemplate = "currentDescriptionTemplate"; + + + private List descriptionTemplates; + + public static final String _descriptionTemplates = "descriptionTemplates"; private UUID sectionId; public static final String _sectionId = "sectionId"; + private UUID descriptionTemplateGroupId; + + public static final String _descriptionTemplateGroupId = "descriptionTemplateGroupId"; + private Instant createdAt; public static final String _createdAt = "createdAt"; @@ -56,12 +65,28 @@ public class DmpDescriptionTemplate{ this.dmp = dmp; } - public DescriptionTemplate getDescriptionTemplate() { - return descriptionTemplate; + public DescriptionTemplate getCurrentDescriptionTemplate() { + return currentDescriptionTemplate; } - public void setDescriptionTemplate(DescriptionTemplate descriptionTemplate) { - this.descriptionTemplate = descriptionTemplate; + public void setCurrentDescriptionTemplate(DescriptionTemplate currentDescriptionTemplate) { + this.currentDescriptionTemplate = currentDescriptionTemplate; + } + + public List getDescriptionTemplates() { + return descriptionTemplates; + } + + public void setDescriptionTemplates(List descriptionTemplates) { + this.descriptionTemplates = descriptionTemplates; + } + + public UUID getDescriptionTemplateGroupId() { + return descriptionTemplateGroupId; + } + + public void setDescriptionTemplateGroupId(UUID descriptionTemplateGroupId) { + this.descriptionTemplateGroupId = descriptionTemplateGroupId; } public UUID getSectionId() { diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/PublicDescription.java b/dmp-backend/core/src/main/java/eu/eudat/model/PublicDescription.java index fb38337a2..ec332e564 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/PublicDescription.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/PublicDescription.java @@ -39,6 +39,11 @@ public class PublicDescription { public static final String _dmpDescriptionTemplate = "dmpDescriptionTemplate"; + private PublicDescriptionTemplate descriptionTemplate; + + public static final String _descriptionTemplate = "descriptionTemplate"; + + public UUID getId() { return id; } @@ -104,4 +109,11 @@ public class PublicDescription { this.dmpDescriptionTemplate = dmpDescriptionTemplate; } + public PublicDescriptionTemplate getDescriptionTemplate() { + return descriptionTemplate; + } + + public void setDescriptionTemplate(PublicDescriptionTemplate descriptionTemplate) { + this.descriptionTemplate = descriptionTemplate; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/PublicDmpDescriptionTemplate.java b/dmp-backend/core/src/main/java/eu/eudat/model/PublicDmpDescriptionTemplate.java index 0d1be79a9..0300241a6 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/PublicDmpDescriptionTemplate.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/PublicDmpDescriptionTemplate.java @@ -15,10 +15,6 @@ public class PublicDmpDescriptionTemplate { public static final String _dmp = "dmp"; - private PublicDescriptionTemplate descriptionTemplate; - - public static final String _descriptionTemplate = "descriptionTemplate"; - public UUID getId() { return id; } @@ -35,11 +31,4 @@ public class PublicDmpDescriptionTemplate { this.dmp = dmp; } - public PublicDescriptionTemplate getDescriptionTemplate() { - return descriptionTemplate; - } - - public void setDescriptionTemplate(PublicDescriptionTemplate descriptionTemplate) { - this.descriptionTemplate = descriptionTemplate; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionBuilder.java index e7d5d83bc..66629b89d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DescriptionBuilder.java @@ -62,9 +62,12 @@ public class DescriptionBuilder extends BaseBuilder dmpDescriptionTemplateItemsMap = this.collectDmpDescriptionTemplates(dmpDescriptionTemplateFields, data); - FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(Description._dmpDescriptionTemplate)); + FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(Description._dmp)); Map dmpItemsMap = this.collectDmps(dmpFields, data); + FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asPrefix(Description._descriptionTemplate)); + Map descriptionTemplateItemsMap = this.collectDescriptionTemplates(descriptionTemplateFields, data); + FieldSet descriptionReferencesFields = fields.extractPrefixed(this.asPrefix(Description._descriptionReferences)); Map> descriptionReferencesMap = this.collectDescriptionReferences(descriptionReferencesFields, data); @@ -89,6 +92,7 @@ public class DescriptionBuilder extends BaseBuilder collectDescriptionTemplates(FieldSet fields, List data) throws MyApplicationException { + if (fields.isEmpty() || data.isEmpty()) + return null; + this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName()); + + Map itemMap; + if (!fields.hasOtherField(this.asIndexer(DescriptionTemplate._id))) { + itemMap = this.asEmpty( + data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()), + x -> { + DescriptionTemplate item = new DescriptionTemplate(); + item.setId(x); + return item; + }, + DescriptionTemplate::getId); + } else { + FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(DescriptionTemplate._id); + DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(this.authorize).asForeignKey(q, clone, DescriptionTemplate::getId); + } + if (!fields.hasField(DescriptionTemplate._id)) { + itemMap.forEach((id, item) -> { + if (item != null) + item.setId(null); + }); + } + + return itemMap; + } + private Map collectDmps(FieldSet fields, List data) throws MyApplicationException { if (fields.isEmpty() || data.isEmpty()) return null; diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpDescriptionTemplateBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpDescriptionTemplateBuilder.java index 067ccdbf3..731be14fc 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpDescriptionTemplateBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpDescriptionTemplateBuilder.java @@ -1,11 +1,14 @@ package eu.eudat.model.builder; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.enums.DescriptionTemplateVersionStatus; import eu.eudat.convention.ConventionService; import eu.eudat.data.DmpDescriptionTemplateEntity; +import eu.eudat.data.DmpEntity; import eu.eudat.model.*; import eu.eudat.query.DescriptionTemplateQuery; import eu.eudat.query.DmpQuery; +import eu.eudat.query.DmpUserQuery; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.exception.MyApplicationException; @@ -53,8 +56,11 @@ public class DmpDescriptionTemplateBuilder extends BaseBuilder(); - FieldSet templateFields = fields.extractPrefixed(this.asPrefix(DmpDescriptionTemplate._descriptionTemplate)); - Map templateItemsMap = this.collectTemplates(templateFields, data); + FieldSet templateFields = fields.extractPrefixed(this.asPrefix(DmpDescriptionTemplate._descriptionTemplates)); + Map> templateItemsMap = this.collectDescriptionTemplates(templateFields, data); + + FieldSet currentDescriptionTemplateFields = fields.extractPrefixed(this.asPrefix(DmpDescriptionTemplate._currentDescriptionTemplate)); + Map currentDescriptionTemplateItemsMap = this.collectCurrentDescriptionTemplates(currentDescriptionTemplateFields, data); FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(DmpDescriptionTemplate._dmp)); Map dmpItemsMap = this.collectDmps(dmpFields, data); @@ -67,7 +73,8 @@ public class DmpDescriptionTemplateBuilder extends BaseBuilder collectTemplates(FieldSet fields, List data) throws MyApplicationException { - if (fields.isEmpty() || data.isEmpty()) - return null; - this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName()); - - Map itemMap; - if (!fields.hasOtherField(this.asIndexer(DescriptionTemplate._id))) { - itemMap = this.asEmpty( - data.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()), - x -> { - DescriptionTemplate item = new DescriptionTemplate(); - item.setId(x); - return item; - }, - DescriptionTemplate::getId); - } else { - FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(DescriptionTemplate._id); - DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).ids(data.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList())); - itemMap = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(this.authorize).asForeignKey(q, clone, DescriptionTemplate::getId); - } - if (!fields.hasField(DescriptionTemplate._id)) { - itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList()); - } - - return itemMap; - } private Map collectDmps(FieldSet fields, List data) throws MyApplicationException { if (fields.isEmpty() || data.isEmpty()) @@ -129,4 +110,50 @@ public class DmpDescriptionTemplateBuilder extends BaseBuilder> collectDescriptionTemplates(FieldSet fields, List data) throws MyApplicationException { + if (fields.isEmpty() || data.isEmpty()) + return null; + this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName()); + + Map> itemMap; + FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(DescriptionTemplate._groupId); + DescriptionTemplateQuery query = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).groupIds(data.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateGroupId).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(this.authorize).asMasterKey(query, clone, DescriptionTemplate::getGroupId); + + if (!fields.hasField(DescriptionTemplate._groupId)) { + itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getGroupId() != null).peek(x -> { + x.setGroupId(null); + }); + } + + return itemMap; + } + + private Map collectCurrentDescriptionTemplates(FieldSet fields, List data) throws MyApplicationException { + if (fields.isEmpty() || data.isEmpty()) + return null; + this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName()); + + Map itemMap; + if (!fields.hasOtherField(this.asIndexer(DescriptionTemplate._groupId))) { + itemMap = this.asEmpty( + data.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateGroupId).distinct().collect(Collectors.toList()), + x -> { + DescriptionTemplate item = new DescriptionTemplate(); + item.setGroupId(x); + return item; + }, + DescriptionTemplate::getGroupId); + } else { + FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(DescriptionTemplate._id); + DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).versionStatuses(DescriptionTemplateVersionStatus.Current).groupIds(data.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateGroupId).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(this.authorize).asForeignKey(q, clone, DescriptionTemplate::getGroupId); + } + if (!fields.hasField(DescriptionTemplate._groupId)) { + itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setGroupId(null)).collect(Collectors.toList()); + } + + return itemMap; + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/PublicDescriptionBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/PublicDescriptionBuilder.java index bbdf82cd3..1c9b33d22 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/PublicDescriptionBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/PublicDescriptionBuilder.java @@ -3,8 +3,8 @@ package eu.eudat.model.builder; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.convention.ConventionService; import eu.eudat.data.DescriptionEntity; -import eu.eudat.model.PublicDescription; -import eu.eudat.model.PublicDmpDescriptionTemplate; +import eu.eudat.model.*; +import eu.eudat.query.DescriptionTemplateQuery; import eu.eudat.query.DmpDescriptionTemplateQuery; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.query.QueryFactory; @@ -56,6 +56,9 @@ public class PublicDescriptionBuilder extends BaseBuilder dmpDescriptionTemplateItemsMap = this.collectDmpDescriptionTemplates(dmpDescriptionTemplateFields, data); + FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asPrefix(Description._descriptionTemplate)); + Map descriptionTemplateItemsMap = this.collectDescriptionTemplates(descriptionTemplateFields, data); + List models = new ArrayList<>(); for (DescriptionEntity d : data) { PublicDescription m = new PublicDescription(); @@ -67,6 +70,7 @@ public class PublicDescriptionBuilder extends BaseBuilder collectDescriptionTemplates(FieldSet fields, List data) throws MyApplicationException { + if (fields.isEmpty() || data.isEmpty()) + return null; + this.logger.debug("checking related - {}", PublicDescriptionTemplate.class.getSimpleName()); + + Map itemMap; + if (!fields.hasOtherField(this.asIndexer(PublicDescriptionTemplate._id))) { + itemMap = this.asEmpty( + data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()), + x -> { + PublicDescriptionTemplate item = new PublicDescriptionTemplate(); + item.setId(x); + return item; + }, + PublicDescriptionTemplate::getId); + } else { + FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(PublicDescriptionTemplate._id); + DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(PublicDescriptionTemplateBuilder.class).authorize(this.authorize).asForeignKey(q, clone, PublicDescriptionTemplate::getId); + } + if (!fields.hasField(PublicDescriptionTemplate._id)) { + itemMap.forEach((id, item) -> { + if (item != null) + item.setId(null); + }); + } + + return itemMap; + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/PublicDmpDescriptionTemplateBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/PublicDmpDescriptionTemplateBuilder.java index 9294a639d..c44a5024c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/PublicDmpDescriptionTemplateBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/PublicDmpDescriptionTemplateBuilder.java @@ -55,8 +55,6 @@ public class PublicDmpDescriptionTemplateBuilder extends BaseBuilder(); - FieldSet templateFields = fields.extractPrefixed(this.asPrefix(PublicDmpDescriptionTemplate._descriptionTemplate)); - Map templateItemsMap = this.collectTemplates(templateFields, data); FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(PublicDmpDescriptionTemplate._dmp)); Map dmpItemsMap = this.collectDmps(dmpFields, data); @@ -65,7 +63,6 @@ public class PublicDmpDescriptionTemplateBuilder extends BaseBuilder collectTemplates(FieldSet fields, List data) throws MyApplicationException { - if (fields.isEmpty() || data.isEmpty()) - return null; - this.logger.debug("checking related - {}", PublicDescriptionTemplate.class.getSimpleName()); - - Map itemMap; - if (!fields.hasOtherField(this.asIndexer(PublicDescriptionTemplate._id))) { - itemMap = this.asEmpty( - data.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()), - x -> { - PublicDescriptionTemplate item = new PublicDescriptionTemplate(); - item.setId(x); - return item; - }, - PublicDescriptionTemplate::getId); - } else { - FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(PublicDescriptionTemplate._id); - DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).ids(data.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList())); - itemMap = this.builderFactory.builder(PublicDescriptionTemplateBuilder.class).authorize(this.authorize).asForeignKey(q, clone, PublicDescriptionTemplate::getId); - } - if (!fields.hasField(PublicDescriptionTemplate._id)) { - itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList()); - } - - return itemMap; - } - private Map collectDmps(FieldSet fields, List data) throws MyApplicationException { if (fields.isEmpty() || data.isEmpty()) return null; diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DescriptionCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DescriptionCensor.java index 31d6d6fa7..62adac6d8 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DescriptionCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DescriptionCensor.java @@ -48,6 +48,9 @@ public class DescriptionCensor extends BaseCensor { FieldSet dmpDescriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(Description._dmpDescriptionTemplate)); this.censorFactory.censor(DmpDescriptionTemplateCensor.class).censor(dmpDescriptionTemplateFields, userId); + FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(Description._descriptionTemplate)); + this.censorFactory.censor(DescriptionTemplateCensor.class).censor(descriptionTemplateFields, userId); + FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(Description._dmp)); this.censorFactory.censor(DmpCensor.class).censor(dmpFields, userId); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpDescriptionTemplateCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpDescriptionTemplateCensor.java index 40236fa5b..a731055d5 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpDescriptionTemplateCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpDescriptionTemplateCensor.java @@ -42,8 +42,10 @@ public class DmpDescriptionTemplateCensor extends BaseCensor{ this.authService.authorizeForce(Permission.BrowseDescription); FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(DmpDescriptionTemplate._dmp)); this.censorFactory.censor(DmpCensor.class).censor(dmpFields, userId); - FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(DmpDescriptionTemplate._descriptionTemplate)); - this.censorFactory.censor(DescriptionTemplateCensor.class).censor(descriptionTemplateFields, userId); + FieldSet descriptionTemplatesFields = fields.extractPrefixed(this.asIndexerPrefix(DmpDescriptionTemplate._descriptionTemplates)); + this.censorFactory.censor(DescriptionTemplateCensor.class).censor(descriptionTemplatesFields, userId); + FieldSet currentDescriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(DmpDescriptionTemplate._currentDescriptionTemplate)); + this.censorFactory.censor(DescriptionTemplateCensor.class).censor(currentDescriptionTemplateFields, userId); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/PublicDescriptionCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/PublicDescriptionCensor.java index 39a94f021..e655a871b 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/PublicDescriptionCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/PublicDescriptionCensor.java @@ -2,6 +2,7 @@ package eu.eudat.model.censorship; import eu.eudat.authorization.Permission; import eu.eudat.convention.ConventionService; +import eu.eudat.model.Description; import eu.eudat.model.PublicDescription; import eu.eudat.model.censorship.descriptionproperties.PropertyDefinitionCensor; import gr.cite.commons.web.authz.service.AuthorizationService; @@ -42,6 +43,9 @@ public class PublicDescriptionCensor extends BaseCensor { FieldSet dmpDescriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(PublicDescription._dmpDescriptionTemplate)); this.censorFactory.censor(PublicDmpDescriptionTemplateCensor.class).censor(dmpDescriptionTemplateFields); + FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(PublicDescription._descriptionTemplate)); + this.censorFactory.censor(PublicDescriptionTemplateCensor.class).censor(descriptionTemplateFields); + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/PublicDmpDescriptionTemplateCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/PublicDmpDescriptionTemplateCensor.java index b3cdbe301..829bae0f9 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/PublicDmpDescriptionTemplateCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/PublicDmpDescriptionTemplateCensor.java @@ -43,8 +43,6 @@ public class PublicDmpDescriptionTemplateCensor extends BaseCensor{ this.authService.authorizeForce(Permission.PublicBrowseDescription); FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(PublicDmpDescriptionTemplate._dmp)); this.censorFactory.censor(PublicDmpCensor.class).censor(dmpFields); - FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(PublicDmpDescriptionTemplate._descriptionTemplate)); - this.censorFactory.censor(PublicDescriptionTemplateCensor.class).censor(descriptionTemplateFields); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/UserAdditionalInfoCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/UserAdditionalInfoCensor.java index 53bc93fac..6dc44e130 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/UserAdditionalInfoCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/UserAdditionalInfoCensor.java @@ -4,7 +4,6 @@ import eu.eudat.authorization.OwnedResource; import eu.eudat.authorization.Permission; import eu.eudat.convention.ConventionService; import eu.eudat.model.UserAdditionalInfo; -import eu.eudat.model.UserContactInfo; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.censor.CensorFactory; import gr.cite.tools.fieldset.FieldSet; @@ -26,10 +25,13 @@ public class UserAdditionalInfoCensor extends BaseCensor { protected final AuthorizationService authService; + protected final CensorFactory censorFactory; - public UserAdditionalInfoCensor(ConventionService conventionService, AuthorizationService authService) { + + public UserAdditionalInfoCensor(ConventionService conventionService, AuthorizationService authService, CensorFactory censorFactory) { super(conventionService); this.authService = authService; + this.censorFactory = censorFactory; } public void censor(FieldSet fields, UUID userId) { @@ -37,6 +39,9 @@ public class UserAdditionalInfoCensor extends BaseCensor { if (fields == null || fields.isEmpty()) return; this.authService.authorizeAtLeastOneForce(userId != null ? List.of(new OwnedResource(userId)) : null, Permission.BrowseUser); + + FieldSet descriptionReferenceFields = fields.extractPrefixed(this.asIndexerPrefix(UserAdditionalInfo._organization)); + this.censorFactory.censor(ReferenceCensor.class).censor(descriptionReferenceFields, userId); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionTemplateDeleter.java b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionTemplateDeleter.java index 85df578ed..efaccb06c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionTemplateDeleter.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DescriptionTemplateDeleter.java @@ -71,6 +71,7 @@ public class DescriptionTemplateDeleter implements Deleter { return; List ids = data.stream().map(DescriptionTemplateEntity::getId).distinct().collect(Collectors.toList()); + List groupIds = data.stream().map(DescriptionTemplateEntity::getGroupId).distinct().collect(Collectors.toList()); { logger.debug("checking related - {}", UserDescriptionTemplateEntity.class.getSimpleName()); List items = this.queryFactory.query(UserDescriptionTemplateQuery.class).descriptionTemplateIds(ids).collect(); @@ -79,7 +80,7 @@ public class DescriptionTemplateDeleter implements Deleter { } { logger.debug("checking related - {}", DmpDescriptionTemplateEntity.class.getSimpleName()); - List items = this.queryFactory.query(DmpDescriptionTemplateQuery.class).descriptionTemplateIds(ids).collect(); + List items = this.queryFactory.query(DmpDescriptionTemplateQuery.class).descriptionTemplateGroupIds(groupIds).collect(); DmpDescriptionTemplateDeleter deleter = this.deleterFactory.deleter(DmpDescriptionTemplateDeleter.class); deleter.delete(items); } 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 79a93eb8d..73a7c51e4 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 @@ -74,16 +74,15 @@ public class DmpEntityDepositMapper { model.setLabel(entity.getLabel()); model.setDescription(entity.getDescription()); model.setProperties(entity.getProperties()); - DescriptionTemplateEntity descriptionTemplateEntity = getDescriptionTemplate(entity.getDmpDescriptionTemplateId()); + DescriptionTemplateEntity descriptionTemplateEntity = getDescriptionTemplate(entity.getDescriptionTemplateId()); model.setProfileDefinition(descriptionTemplateEntity.getDefinition()); model.setFields(fromDefinitionAndProperties(descriptionTemplateEntity.getDefinition(), entity.getProperties())); return model; } - private DescriptionTemplateEntity getDescriptionTemplate(UUID dmpDescriptionTemplateId) { - DmpDescriptionTemplateEntity dmpDescriptionTemplate = this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(dmpDescriptionTemplateId).isActive(IsActive.Active).first(); + private DescriptionTemplateEntity getDescriptionTemplate(UUID descriptionTemplateId) { DescriptionTemplateQuery descriptionTemplateQuery = this.queryFactory.query(DescriptionTemplateQuery.class); - return descriptionTemplateQuery.ids(dmpDescriptionTemplate.getDescriptionTemplateId()).isActive(IsActive.Active).first(); + return descriptionTemplateQuery.ids(descriptionTemplateId).isActive(IsActive.Active).first(); } private List fromDefinitionAndProperties(String definition, String properties){ diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionPersist.java index 8addd1ab7..af6a8c9e8 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionPersist.java @@ -33,6 +33,10 @@ public class DescriptionPersist { @ValidId(message = "{validation.invalidid}") private UUID dmpDescriptionTemplateId; + @NotNull(message = "{validation.empty}") + @ValidId(message = "{validation.invalidid}") + private UUID descriptionTemplateId; + @ValidEnum(message = "{validation.empty}") private DescriptionStatus status; @@ -131,4 +135,12 @@ public class DescriptionPersist { public void setHash(String hash) { this.hash = hash; } + + public UUID getDescriptionTemplateId() { + return descriptionTemplateId; + } + + public void setDescriptionTemplateId(UUID descriptionTemplateId) { + this.descriptionTemplateId = descriptionTemplateId; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpDescriptionTemplatePersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpDescriptionTemplatePersist.java index 8c753f8df..c34538289 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpDescriptionTemplatePersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DmpDescriptionTemplatePersist.java @@ -9,33 +9,20 @@ import java.util.UUID; @FieldNotNullIfOtherSet(message = "{validation.hashempty}") public class DmpDescriptionTemplatePersist { - @ValidId(message = "{validation.invalidid}") - private UUID id; - @ValidId(message = "{validation.invalidid}") @NotNull(message = "{validation.empty}") - private UUID descriptionTemplate; + private UUID descriptionTemplateGroupId; @ValidId(message = "{validation.invalidid}") @NotNull(message = "{validation.empty}") private UUID sectionId; - private String hash; - - public UUID getId() { - return id; + public UUID getDescriptionTemplateGroupId() { + return descriptionTemplateGroupId; } - public void setId(UUID id) { - this.id = id; - } - - public UUID getDescriptionTemplate() { - return descriptionTemplate; - } - - public void setDescriptionTemplate(UUID descriptionTemplate) { - this.descriptionTemplate = descriptionTemplate; + public void setDescriptionTemplateGroupId(UUID descriptionTemplateGroupId) { + this.descriptionTemplateGroupId = descriptionTemplateGroupId; } public UUID getSectionId() { @@ -46,12 +33,4 @@ public class DmpDescriptionTemplatePersist { this.sectionId = sectionId; } - public String getHash() { - return hash; - } - - public void setHash(String hash) { - this.hash = hash; - } - } diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionQuery.java index 552fc54a4..7966001e2 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionQuery.java @@ -270,6 +270,9 @@ public class DescriptionQuery extends QueryBase { else if (item.match(Description._hash)) return DescriptionEntity._updatedAt; else if (item.match(Description._finalizedAt) || item.match(PublicDescription._finalizedAt)) return DescriptionEntity._finalizedAt; else if (item.prefix(Description._dmpDescriptionTemplate) || item.prefix(PublicDescription._dmpDescriptionTemplate)) return DescriptionEntity._dmpDescriptionTemplateId; + else if (item.match(Description._dmpDescriptionTemplate) || item.match(PublicDescription._dmpDescriptionTemplate)) return DescriptionEntity._dmpDescriptionTemplateId; + else if (item.prefix(Description._descriptionTemplate) || item.prefix(PublicDescription._descriptionTemplate)) return DescriptionEntity._descriptionTemplateId; + else if (item.match(Description._descriptionTemplate) || item.match(PublicDescription._descriptionTemplate)) return DescriptionEntity._descriptionTemplateId; else if (item.prefix(Description._dmp)) return DescriptionEntity._dmpId; else return null; } @@ -287,6 +290,7 @@ public class DescriptionQuery extends QueryBase { item.setIsActive(QueryBase.convertSafe(tuple, columns, DescriptionEntity._isActive, IsActive.class)); item.setFinalizedAt(QueryBase.convertSafe(tuple, columns, DescriptionEntity._finalizedAt, Instant.class)); item.setDmpDescriptionTemplateId(QueryBase.convertSafe(tuple, columns, DescriptionEntity._dmpDescriptionTemplateId, UUID.class)); + item.setDescriptionTemplateId(QueryBase.convertSafe(tuple, columns, DescriptionEntity._descriptionTemplateId, UUID.class)); item.setDmpId(QueryBase.convertSafe(tuple, columns, DescriptionEntity._dmpId, UUID.class)); return item; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionTemplateQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionTemplateQuery.java index 8aeac222a..c623a0cf8 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionTemplateQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionTemplateQuery.java @@ -197,12 +197,12 @@ public class DescriptionTemplateQuery extends QueryBase dmpDescriptionTemplateSubquery = queryUtilsService.buildSubQuery(new BuildSubQueryInput<>( new BuildSubQueryInput.Builder<>(DmpDescriptionTemplateEntity.class, UUID.class, queryContext) - .keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpDescriptionTemplateEntity._descriptionTemplateId)) + .keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpDescriptionTemplateEntity._descriptionTemplateGroupId)) .filterFunc((subQueryRoot, cb) -> cb.in(subQueryRoot.get(DmpDescriptionTemplateEntity._dmpId)).value(queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, usePublic)) ) )); - predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateEntity._id)).value(dmpDescriptionTemplateSubquery)); + predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateEntity._groupId)).value(dmpDescriptionTemplateSubquery)); } if (!predicates.isEmpty()) { Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/DmpDescriptionTemplateQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/DmpDescriptionTemplateQuery.java index b45168275..eaf4c5ee4 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/DmpDescriptionTemplateQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/DmpDescriptionTemplateQuery.java @@ -36,7 +36,7 @@ public class DmpDescriptionTemplateQuery extends QueryBase dmpIds; - private Collection descriptionTemplateIds; + private Collection descriptionTemplateGroupIds; private Collection isActives; @@ -105,18 +105,18 @@ public class DmpDescriptionTemplateQuery extends QueryBase values) { - this.descriptionTemplateIds = values; + public DmpDescriptionTemplateQuery descriptionTemplateGroupIds(Collection values) { + this.descriptionTemplateGroupIds = values; return this; } @@ -143,7 +143,7 @@ public class DmpDescriptionTemplateQuery extends QueryBase inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._descriptionTemplateId)); - for (UUID item : this.descriptionTemplateIds) + if (this.descriptionTemplateGroupIds != null) { + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._descriptionTemplateGroupId)); + for (UUID item : this.descriptionTemplateGroupIds) inClause.value(item); predicates.add(inClause); } @@ -212,7 +212,7 @@ public class DmpDescriptionTemplateQuery extends QueryBase models, UUID dmpId) throws InvalidApplicationException { - if (models == null || models.isEmpty()) - return; - - List templates = this.queryFactory.query(DmpDescriptionTemplateQuery.class).dmpIds(dmpId).collect(); - Map> templatesLookup = this.conventionService.toDictionaryOfList(templates, DmpDescriptionTemplateEntity::getDmpId); - - List existingTemplates; - if (templatesLookup.containsKey(dmpId)) - existingTemplates = this.queryFactory.query(DescriptionTemplateQuery.class).ids(templatesLookup.get(dmpId).stream().map(DmpDescriptionTemplateEntity::getId).toList()).collect(); - else existingTemplates = new ArrayList<>(); - - List updatedTemplatesIds = models.stream().map(DmpDescriptionTemplatePersist::getDescriptionTemplate).filter(this.conventionService::isValidGuid).distinct().toList(); - List toDelete = existingTemplates.stream().filter(x -> !updatedTemplatesIds.contains(x.getId())).toList(); - List dmpDescriptionTemplateRecordsToDelete = this.queryFactory.query(DmpDescriptionTemplateQuery.class).descriptionTemplateIds(toDelete.stream().map(DescriptionTemplateEntity::getId).toList()).collect(); - this.deleterFactory.deleter(DmpDescriptionTemplateDeleter.class).delete(dmpDescriptionTemplateRecordsToDelete); + private void patchAndSaveTemplates(UUID id, List models) throws InvalidApplicationException { + if (models == null) models = new ArrayList<>(); + List items = this.queryFactory.query(DmpDescriptionTemplateQuery.class).isActive(IsActive.Active).dmpIds(id).collect(); + List updatedCreatedIds = new ArrayList<>(); for (DmpDescriptionTemplatePersist model : models) { - boolean shouldAdd = existingTemplates.stream().noneMatch(x -> x.getId().equals(model.getDescriptionTemplate())); - - if (shouldAdd) { - DmpDescriptionTemplateEntity dmpTemplate = new DmpDescriptionTemplateEntity(); - dmpTemplate.setDescriptionTemplateId(model.getDescriptionTemplate()); - dmpTemplate.setDmpId(dmpId); - dmpTemplate.setSectionId(model.getSectionId()); - dmpTemplate.setCreatedAt(Instant.now()); - dmpTemplate.setUpdatedAt(Instant.now()); - dmpTemplate.setIsActive(IsActive.Active); - this.entityManager.persist(dmpTemplate); + DmpDescriptionTemplateEntity data = items.stream().filter(x -> x.getDescriptionTemplateGroupId().equals(model.getDescriptionTemplateGroupId()) && x.getSectionId().equals(model.getSectionId())).findFirst().orElse(null); + if (data == null){ + data = new DmpDescriptionTemplateEntity(); + data.setId(UUID.randomUUID()); + data.setIsActive(IsActive.Active); + data.setCreatedAt(Instant.now()); + data.setDmpId(id); + data.setSectionId(model.getSectionId()); + data.setDescriptionTemplateGroupId(model.getDescriptionTemplateGroupId()); + this.entityManager.persist(data); } - + updatedCreatedIds.add(data.getId()); } - this.entityManager.flush(); + List toDelete = items.stream().filter(x-> updatedCreatedIds.stream().noneMatch(y-> y.equals(x.getId()))).collect(Collectors.toList()); + + this.deleterFactory.deleter(DmpDescriptionTemplateDeleter.class).delete(toDelete); } private @NotNull DefinitionEntity buildDefinitionEntity(DefinitionPersist persist){ 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 a494b2858..4cb87126d 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 @@ -485,7 +485,7 @@ public class DataManagementPlanManager { 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) + if (dataManagementPlan.getProfiles().stream().filter(associatedProfile -> descriptionEntity.getDescriptionTemplateId().equals(associatedProfile.getDescriptionTemplateId())).findAny().orElse(null) == null) throw new Exception("Dataset Template for Dataset Description is missing from the DMP."); } if (dataManagementPlan.getStatus() == DmpStatus.Finalized.getValue() && dmp1.getStatus().equals(DmpStatus.Finalized.getValue() )) @@ -1639,7 +1639,7 @@ public class DataManagementPlanManager { //runDatasetTemplate1.setBold(true); //runDatasetTemplate1.setFontSize(12); XWPFRun runDatasetTemplate = datasetTemplateParagraph.createRun(); - runDatasetTemplate.setText(this.queryFactory.query(DescriptionTemplateQuery.class).ids(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(datasetEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).first().getLabel()); + runDatasetTemplate.setText(this.queryFactory.query(DescriptionTemplateQuery.class).ids(datasetEntity.getDescriptionTemplateId()).first().getLabel()); runDatasetTemplate.setColor("116a78"); //runDatasetTemplate.setBold(true); //runDatasetTemplate.setFontSize(12); @@ -1685,7 +1685,7 @@ public class DataManagementPlanManager { runDatasetDescription1.setText("Description: "); runDatasetDescription1.setColor("000000"); XWPFRun runDatasetDescription = datasetDescParagraph.createRun(); - runDatasetDescription.setText(this.queryFactory.query(DescriptionTemplateQuery.class).ids(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(datasetEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).first().getLabel()); + runDatasetDescription.setText(this.queryFactory.query(DescriptionTemplateQuery.class).ids(datasetEntity.getDescriptionTemplateId()).first().getLabel()); runDatasetDescription.setColor("116a78"); //wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO, 0); @@ -1981,11 +1981,11 @@ public class DataManagementPlanManager { Element datsetProfileElement = xmlDoc.createElement("profile-id"); datasetElement.appendChild(datsetProfileElement); - datsetProfileElement.setTextContent(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId().toString()); + datsetProfileElement.setTextContent(descriptionEntity.getDescriptionTemplateId().toString()); Element datsetProfileLabelElement = xmlDoc.createElement("profile-label"); datasetElement.appendChild(datsetProfileLabelElement); - datsetProfileLabelElement.setTextContent(this.queryFactory.query(DescriptionTemplateQuery.class).ids(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).first().getLabel()); + datsetProfileLabelElement.setTextContent(this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntity.getDescriptionTemplateId()).first().getLabel()); DatasetWizardModel datasetWizardModel = new DatasetWizardModel(); Map properties = new HashMap<>(); 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 9c466cad1..3ec4d2ef4 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 @@ -315,7 +315,7 @@ public class DatasetManager { // Creates the Criteria to get all version of DescriptionTemplate in question. DatasetProfileCriteria profileCriteria = new DatasetProfileCriteria(); - UUID profileId = this.queryFactory.query(DescriptionTemplateQuery.class).ids(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).first().getGroupId(); + UUID profileId = this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDescriptionTemplateId()).first().getGroupId(); List uuidList = new LinkedList<>(); uuidList.add(profileId); profileCriteria.setGroupIds(uuidList); @@ -346,7 +346,7 @@ public class DatasetManager { DescriptionTemplateEntity profile = profiles.get(0); // Check if the dataset is on the latest Version. - boolean latestVersion = profile.getVersion().toString().equals(this.queryFactory.query(DescriptionTemplateQuery.class).ids(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).first().getVersion()); + boolean latestVersion = profile.getVersion().toString().equals(this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDescriptionTemplateId()).first().getVersion()); dataset.setIsProfileLatestVersion(latestVersion); // eu.eudat.elastic.entities.Dataset datasetElastic; //TODO @@ -409,7 +409,7 @@ public class DatasetManager { } public PagedDatasetProfile getPagedProfile(DatasetWizardModel dataset, DescriptionEntity descriptionEntityEntity) { - eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(this.queryFactory.query(DescriptionTemplateQuery.class).ids(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).first()); + eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDescriptionTemplateId()).first()); datasetprofile.setStatus(dataset.getStatus().getValue()); if (descriptionEntityEntity.getProperties() != null) { JSONObject jObject = new JSONObject(descriptionEntityEntity.getProperties()); @@ -616,7 +616,7 @@ public class DatasetManager { PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset, descriptionEntityEntity); visibilityRuleService.setProperties(properties); visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules()); - File file = xmlBuilder.build(pagedDatasetProfile, this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId(), visibilityRuleService, environment); + File file = xmlBuilder.build(pagedDatasetProfile, descriptionEntityEntity.getDescriptionTemplateId(), visibilityRuleService, environment); FileEnvelope fileEnvelope = new FileEnvelope(); fileEnvelope.setFile(file); String label = descriptionEntityEntity.getLabel().replaceAll("[^a-zA-Z0-9+ ]", ""); @@ -758,7 +758,7 @@ public class DatasetManager { public String checkDatasetValidation(DescriptionEntity descriptionEntity) throws Exception { List datasetProfileValidators = new LinkedList<>(); - DescriptionTemplateEntity profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()); + DescriptionTemplateEntity profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(descriptionEntity.getDescriptionTemplateId()); DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); Document xmlDocument = builder.parse(new ByteArrayInputStream(profile.getDefinition().getBytes())); 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 a2b008280..f290235e6 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 @@ -57,7 +57,7 @@ public class DatasetWizardManager { public void unlock(ApiContext apiContext, QueryFactory queryFactory, UUID uuid) throws DatasetWizardCannotUnlockException, InvalidApplicationException { DescriptionEntity descriptionEntity = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(uuid); - DmpEntity dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()); + DmpEntity dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(descriptionEntity.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); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MetricsManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MetricsManager.java index 8f1bc49c2..3d3e7d0be 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MetricsManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MetricsManager.java @@ -414,7 +414,7 @@ public class MetricsManager { List descriptionTemplateEntities = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().getWithCriteria(criteria).withFields(Collections.singletonList("id")).toList(); DatasetCriteria datasetCriteria = new DatasetCriteria(); datasetCriteria.setDatasetTemplates(descriptionTemplateEntities.stream().map(DescriptionTemplateEntity::getId).collect(Collectors.toList())); - return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(datasetCriteria).select(root -> this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(root.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).stream().distinct().count(); + return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(datasetCriteria).select(root -> root.getDescriptionTemplateId()).stream().distinct().count(); } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetRDAMapper.java b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetRDAMapper.java index 71a7e8c24..d07762e76 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetRDAMapper.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetRDAMapper.java @@ -55,7 +55,7 @@ public class DatasetRDAMapper { } rda.setTitle(descriptionEntity.getLabel()); rda.setDescription(descriptionEntity.getDescription()); - rda.setAdditionalProperty("template", this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()); //TODO + rda.setAdditionalProperty("template", this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDescriptionTemplateId())); //TODO try { JSONObject jObject = new JSONObject(descriptionEntity.getProperties()); Map templateIdsToValues = jObject.toMap(); 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 88b19da0e..5198d453f 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 @@ -184,7 +184,7 @@ public class DmpRDAMapper { return entity; } - private DmpDescriptionTemplateEntity getProfile(String descriptionTemplateId, UUID dmpId) throws InvalidApplicationException { - return this.queryFactory.query(DmpDescriptionTemplateQuery.class).dmpIds(dmpId).descriptionTemplateIds(UUID.fromString(descriptionTemplateId)).first(); - } +// private DmpDescriptionTemplateEntity getProfile(String descriptionTemplateId, UUID dmpId) throws InvalidApplicationException { +// return this.queryFactory.query(DmpDescriptionTemplateQuery.class).dmpIds(dmpId).descriptionTemplateIds(UUID.fromString(descriptionTemplateId)).first(); +// } } diff --git a/dmp-db-scema/updates/00.01.012_Add_Dmp_description_template_table.sql b/dmp-db-scema/updates/00.01.012_Add_Dmp_description_template_table.sql index b771053d3..36477e12e 100644 --- a/dmp-db-scema/updates/00.01.012_Add_Dmp_description_template_table.sql +++ b/dmp-db-scema/updates/00.01.012_Add_Dmp_description_template_table.sql @@ -8,16 +8,14 @@ CREATE TABLE IF NOT EXISTS public."DmpDescriptionTemplate" ( "id" uuid NOT NULL, "dmp" uuid NOT NULL, - "description_template" uuid NOT NULL, + "description_template_group" uuid NOT NULL, "section_id" uuid NOT NULL, "created_at" timestamp without time zone NOT NULL DEFAULT now(), "updated_at" timestamp without time zone NOT NULL DEFAULT now(), "is_active" smallint NOT NULL DEFAULT 1, CONSTRAINT "DmpDescriptionTemplate_pkey" PRIMARY KEY (id), CONSTRAINT "DmpDescriptionTemplate_dmp_fkey" FOREIGN KEY (dmp) - REFERENCES public."Dmp" (id), - CONSTRAINT "DmpDescriptionTemplate_description_template_fkey" FOREIGN KEY (description_template) - REFERENCES public."DescriptionTemplate" (id) + REFERENCES public."Dmp" (id) ); INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.012', '2023-11-02 12:00:00.000000+02', now(), 'Add Dmp Description Template table (former DMPDatasetProfile).'); diff --git a/dmp-db-scema/updates/00.01.014_sync_Description.sql b/dmp-db-scema/updates/00.01.014_sync_Description.sql index 1a6519e2a..c1c1c6da5 100644 --- a/dmp-db-scema/updates/00.01.014_sync_Description.sql +++ b/dmp-db-scema/updates/00.01.014_sync_Description.sql @@ -14,6 +14,9 @@ BEGIN ALTER TABLE public."Description" DROP COLUMN dmp_section_index; + ALTER TABLE public."Description" ADD COLUMN description_template uuid NOT NULL; + + ALTER TABLE public."Description" ALTER COLUMN dmp SET NOT NULL; @@ -37,6 +40,13 @@ BEGIN ON DELETE NO ACTION NOT VALID; + ALTER TABLE public."Description" + ADD FOREIGN KEY (description_template) + REFERENCES public."DescriptionTemplate" (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION + NOT VALID; + INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.014', '2023-11-20 12:00:00.000000+02', now(), 'Sync table Description.'); From 58d224b73979f84fb14a5c696492e02491b61a00 Mon Sep 17 00:00:00 2001 From: Thomas Georgios Giannos Date: Fri, 24 Nov 2023 12:45:29 +0200 Subject: [PATCH 4/4] Small fix --- .../eudat/migration/DmpDatasetProfileMigrationService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpDatasetProfileMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpDatasetProfileMigrationService.java index 7fe610249..83eb43d11 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpDatasetProfileMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DmpDatasetProfileMigrationService.java @@ -107,7 +107,7 @@ public class DmpDatasetProfileMigrationService { DmpDescriptionTemplateEntity data = new DmpDescriptionTemplateEntity(); data.setId(UUID.randomUUID()); - data.setDescriptionTemplateId(item.getDatasetprofile().getId()); + data.setDescriptionTemplateGroupId(item.getDatasetprofile().getId()); data.setDmpId(item.getDmp().getId()); data.setCreatedAt(Instant.now()); data.setUpdatedAt(Instant.now()); @@ -130,8 +130,10 @@ public class DmpDatasetProfileMigrationService { int page = 0; DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class); + long total = dmpDescriptionTemplateQuery.count(); List dmpDescriptionTemplateEntities; do { + logger.debug("Checking " + page * PageSize + " of " + total); dmpDescriptionTemplateQuery.setPage(new Paging(page * PageSize, PageSize)); dmpDescriptionTemplateEntities = dmpDescriptionTemplateQuery.collect(); @@ -142,7 +144,7 @@ public class DmpDatasetProfileMigrationService { continue; } if (currentEntity.getDmpId().equals(previousEntity.getDmpId()) - && currentEntity.getDescriptionTemplateId().equals(previousEntity.getDescriptionTemplateId()) + && currentEntity.getDescriptionTemplateGroupId().equals(previousEntity.getDescriptionTemplateGroupId()) && currentEntity.getSectionId().equals(previousEntity.getSectionId()) ) { logger.warn("Removing found duplicate DmpDescriptionTemplate entity ({}) after DmpDatasetProfiles migration", currentEntity.getId());