migration changes

This commit is contained in:
Efstratios Giannopoulos 2023-11-24 18:19:22 +02:00
parent c67e4c8c9f
commit aa0a86b4d1
5 changed files with 15 additions and 13 deletions

View File

@ -26,7 +26,7 @@ public class DmpUserEntity {
public static final String _dmp = "dmp";
@Column(name = "user", columnDefinition = "uuid", nullable = false)
@Column(name = "\"user\"", columnDefinition = "uuid", nullable = false)
private UUID userId;
public static final String _userId = "userId";

View File

@ -7,7 +7,7 @@ BEGIN
CREATE TABLE IF NOT EXISTS public."DescriptionReference"
(
"id" uuid NOT NULL,
"data" text COLLATE pg_catalog."default" NOT NULL,
"data" text COLLATE pg_catalog."default",
"description_id" uuid NOT NULL,
"reference_id" uuid NOT NULL,
"created_at" timestamp without time zone NOT NULL DEFAULT now(),

View File

@ -115,7 +115,7 @@ public class DmpDatasetProfileMigrationService {
}
} while (items != null && !items.isEmpty() && !TestMode);
//removeDuplicates();
removeDuplicates();
}
private void removeDuplicates() {
@ -128,8 +128,8 @@ public class DmpDatasetProfileMigrationService {
CriteriaBuilder b = this.entityManager.getCriteriaBuilder();
CriteriaQuery<Tuple> criteria = b.createQuery(Tuple.class);
Root<DmpDescriptionTemplateEntity> root = criteria.from(DmpDescriptionTemplateEntity.class);
criteria.groupBy(Arrays.asList(root.get("dmp"), root.get("descriptionTemplateGroupId"), root.get("sectionId")));
criteria.multiselect(root.get("dmp"), root.get("descriptionTemplateGroupId"), root.get("sectionId"), b.count(root));
criteria.groupBy(Arrays.asList(root.get(DmpDescriptionTemplateEntity._dmpId), root.get(DmpDescriptionTemplateEntity._descriptionTemplateGroupId), root.get(DmpDescriptionTemplateEntity._sectionId)));
criteria.multiselect(root.get(DmpDescriptionTemplateEntity._dmpId), root.get(DmpDescriptionTemplateEntity._descriptionTemplateGroupId), root.get(DmpDescriptionTemplateEntity._sectionId), b.count(root));
List<Tuple> resultList = this.entityManager.createQuery(criteria).getResultList();
List<Tuple> duplicatesList = resultList.stream().filter(x -> (long) x.get(3) > 1).toList();
@ -143,9 +143,8 @@ public class DmpDatasetProfileMigrationService {
.collect();
List<UUID> toDelete = new ArrayList<>(duplicateEntities.stream().map(DmpDescriptionTemplateEntity::getId).toList());
int random = new SecureRandom().nextInt(0, toDelete.size());
toDelete.remove(random);
delete.where(root1.get("id").in(toDelete));
toDelete.remove(0);
delete.where(root1.get(DmpDescriptionTemplateEntity._id).in(toDelete));
this.entityManager.createQuery(delete).executeUpdate();
}

View File

@ -44,15 +44,15 @@ public class DmpUserMigrationService {
if (items != null && !items.isEmpty()) {
logger.debug("Migrate UserDMP " + page * PageSize + " of " + total);
for (UserDMP item : items) {
entityManager.detach(item);
//entityManager.detach(item);
DmpUserEntity data = new DmpUserEntity();
data.setId(item.getId());
data.setDmp(item.getDmp().getId());
data.setUserId(item.getUser().getId());
data.setRole(DmpUserRole.of(item.getRole().shortValue()));
data.setCreatedAt(Instant.now());
data.setUpdatedAt(Instant.now());
data.setCreatedAt(item.getDmp().getCreated() != null ? item.getDmp().getCreated().toInstant() : Instant.now());
data.setUpdatedAt(item.getDmp().getModified() != null ? item.getDmp().getModified().toInstant() : Instant.now());
data.setIsActive(IsActive.Active);
this.entityManager.persist(data);
}

View File

@ -86,12 +86,15 @@ public class MigrationController {
this.dmpDatasetProfileMigrationService.migrate();
this.datasetMigrationService.migrate();
this.dmpUserMigrationService.migrate();
this.referenceMigrationService.migrateDatasetReferences();
this.referenceMigrationService.migrateDmpReferences();
this.userContactInfoMigrationService.migrate();
return true;
}
@GetMapping("contacts")
@Transactional
public boolean migrateContacts() {