From 6583c6d07a663c981b1bf25473f9ba1e5f2e1ed1 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Mon, 13 May 2024 14:57:08 +0300 Subject: [PATCH 1/2] bug fix --- .../inbox/notify/NotifyIntegrationEventHandlerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/notify/NotifyIntegrationEventHandlerImpl.java b/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/notify/NotifyIntegrationEventHandlerImpl.java index 19b6a91a2..bc8ae7b5f 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/notify/NotifyIntegrationEventHandlerImpl.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/integrationevent/inbox/notify/NotifyIntegrationEventHandlerImpl.java @@ -122,7 +122,7 @@ public class NotifyIntegrationEventHandlerImpl implements NotifyIntegrationEvent notificationService.persist(model, new BaseFieldSet()); auditService.track(AuditableAction.Notification_Persist, Map.ofEntries( - new AbstractMap.SimpleEntry("id", event.getUserId()) + new AbstractMap.SimpleEntry("id", event.getUserId() != null ? event.getUserId() : event.getContactHint()) )); } catch (Exception ex) { status = EventProcessingStatus.Error; From a1cb8efe1dccabe13f5dac2e490e762e1bb100ab Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Mon, 13 May 2024 14:58:32 +0300 Subject: [PATCH 2/2] migration fixes --- .../migration/DatasetMigrationService.java | 29 ++++++++++--------- .../StorageFileMigrationService.java | 13 ++++----- .../migration/MigrationController.java | 10 +++---- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DatasetMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DatasetMigrationService.java index b6699a062..336c67802 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DatasetMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/DatasetMigrationService.java @@ -167,7 +167,7 @@ public class DatasetMigrationService { private List getOrCreateDmpDescriptionTemplateEntity(Dataset item, UUID sectionId, List dmpDescriptionTemplateEntities){ List itemDescriptionTemplates = dmpDescriptionTemplateEntities.stream().filter(x-> x.getDescriptionTemplateGroupId().equals(item.getProfile().getGroupId()) && x.getDmpId().equals(item.getDmp().getId()) && x.getSectionId().equals(sectionId)).toList(); if (itemDescriptionTemplates.isEmpty()) { - logger.warn("Migrate Dataset " + item.getId() + " cannot found DmpDescriptionTemplateEntity for section " + item.getDmpSectionIndex()); + if (!item.getStatus().equals(Dataset.Status.DELETED.getValue())) logger.warn("Migrate Dataset " + item.getId() + " cannot found DmpDescriptionTemplateEntity for section " + item.getDmpSectionIndex()); if (dmpDescriptionTemplateEntities.stream().anyMatch(x -> x.getDmpId().equals(item.getDmp().getId()) && x.getSectionId().equals(sectionId))) { DmpDescriptionTemplateEntity dmpDescriptionTemplateEntity = new DmpDescriptionTemplateEntity(); dmpDescriptionTemplateEntity.setId(UUID.randomUUID()); @@ -176,7 +176,7 @@ public class DatasetMigrationService { dmpDescriptionTemplateEntity.setCreatedAt(item.getCreated() != null ? item.getCreated().toInstant() : Instant.now()); dmpDescriptionTemplateEntity.setUpdatedAt(item.getModified() != null ? item.getModified().toInstant() : Instant.now()); dmpDescriptionTemplateEntity.setSectionId(sectionId); - dmpDescriptionTemplateEntity.setIsActive(IsActive.Active); + dmpDescriptionTemplateEntity.setIsActive(!item.getStatus().equals(Dataset.Status.DELETED.getValue()) ? IsActive.Active : IsActive.Inactive); this.entityManager.persist(dmpDescriptionTemplateEntity); itemDescriptionTemplates = List.of(dmpDescriptionTemplateEntity); } else { @@ -189,8 +189,9 @@ public class DatasetMigrationService { private PropertyDefinitionEntity buildPropertyDefinitionEntity(Dataset item, org.opencdmp.commons.types.descriptiontemplate.DefinitionEntity descriptionTemplateDefinitionEntity, Map referenceTypeDefinitionEntityMap, Map referenceMap) { if (this.conventionService.isNullOrEmpty(item.getProperties())) return null; JSONObject jObject = new JSONObject(item.getProperties()); - Map properties = jObject.toMap(); - + Map properties = new HashMap<>(); + for (Map.Entry entry : jObject.toMap().entrySet()) properties.put(entry.getKey().trim(), entry.getValue()); + PropertyDefinitionEntity propertyDefinitionEntity = new PropertyDefinitionEntity(); propertyDefinitionEntity.setFieldSets(new HashMap<>()); @@ -225,7 +226,7 @@ public class DatasetMigrationService { continue; } - this.addSimpleField(item, propertyDefinitionEntity, currentFieldSet, currentField, properties, referenceTypeDefinitionEntityMap, referenceMap); + this.addSimpleField(item, propertyDefinitionEntity, currentFieldSet, currentField, properties.get(key), referenceTypeDefinitionEntityMap, referenceMap); } } } @@ -315,13 +316,13 @@ public class DatasetMigrationService { if (ordinal == SimpleFieldSetOrdinal) throw new MyApplicationException("Fieldset has migration simple fieldset ordinal " + SimpleFieldSetOrdinal); - this.addMultipleField(item, propertyDefinitionFieldSetEntity, ordinal, currentField, properties, referenceTypeDefinitionEntityMap, referenceMap); + this.addMultipleField(item, propertyDefinitionFieldSetEntity, ordinal, currentField, properties.get(key), referenceTypeDefinitionEntityMap, referenceMap); } } } - private void addMultipleField(Dataset item, PropertyDefinitionFieldSetEntity propertyDefinitionFieldSetEntity, int ordinal, org.opencdmp.commons.types.descriptiontemplate.FieldEntity currentField, Map properties, Map referenceTypeDefinitionEntityMap, Map referenceMap){ + private void addMultipleField(Dataset item, PropertyDefinitionFieldSetEntity propertyDefinitionFieldSetEntity, int ordinal, org.opencdmp.commons.types.descriptiontemplate.FieldEntity currentField, Object propertyValue, Map referenceTypeDefinitionEntityMap, Map referenceMap){ PropertyDefinitionFieldSetItemEntity propertyDefinitionFieldSetItemEntity = propertyDefinitionFieldSetEntity.getItems().stream().filter(x-> x.getOrdinal() == ordinal).findFirst().orElse(null); if (propertyDefinitionFieldSetItemEntity == null){ @@ -331,10 +332,10 @@ public class DatasetMigrationService { propertyDefinitionFieldSetEntity.getItems().add(propertyDefinitionFieldSetItemEntity); } - propertyDefinitionFieldSetItemEntity.getFields().put(currentField.getId().trim(), this.buildField(item, currentField, properties, referenceTypeDefinitionEntityMap, referenceMap)); + propertyDefinitionFieldSetItemEntity.getFields().put(currentField.getId().trim(), this.buildField(item, currentField, propertyValue, referenceTypeDefinitionEntityMap, referenceMap)); } - private void addSimpleField(Dataset item, PropertyDefinitionEntity propertyDefinitionEntity, FieldSetEntity currentFieldSet, org.opencdmp.commons.types.descriptiontemplate.FieldEntity currentField, Map properties, Map referenceTypeDefinitionEntityMap, Map referenceMap){ + private void addSimpleField(Dataset item, PropertyDefinitionEntity propertyDefinitionEntity, FieldSetEntity currentFieldSet, org.opencdmp.commons.types.descriptiontemplate.FieldEntity currentField, Object propertyValue, Map referenceTypeDefinitionEntityMap, Map referenceMap){ PropertyDefinitionFieldSetEntity propertyDefinitionFieldSetEntity = propertyDefinitionEntity.getFieldSets().getOrDefault(currentFieldSet.getId().trim(), null); if (propertyDefinitionFieldSetEntity == null) { propertyDefinitionFieldSetEntity = new PropertyDefinitionFieldSetEntity(); @@ -352,7 +353,7 @@ public class DatasetMigrationService { propertyDefinitionFieldSetItemEntity = propertyDefinitionFieldSetEntity.getItems().getFirst(); } - propertyDefinitionFieldSetItemEntity.getFields().put(currentField.getId().trim(), this.buildField(item, currentField, properties, referenceTypeDefinitionEntityMap, referenceMap)); + propertyDefinitionFieldSetItemEntity.getFields().put(currentField.getId().trim(), this.buildField(item, currentField, propertyValue, referenceTypeDefinitionEntityMap, referenceMap)); } @@ -377,9 +378,9 @@ public class DatasetMigrationService { propertyDefinitionFieldSetItemEntity.setComment(comment); } - private FieldEntity buildField(Dataset item, org.opencdmp.commons.types.descriptiontemplate.FieldEntity currentField, Map properties, Map referenceTypeDefinitionEntityMap, Map referenceMap){ + private FieldEntity buildField(Dataset item, org.opencdmp.commons.types.descriptiontemplate.FieldEntity currentField, Object propertyValue, Map referenceTypeDefinitionEntityMap, Map referenceMap){ FieldEntity fieldEntity = new FieldEntity(); - String textValue = properties.get(currentField.getId()) != null ? properties.get(currentField.getId()).toString() : null; + String textValue = propertyValue != null ? propertyValue.toString() : null; if (textValue == null || textValue.isEmpty()) return fieldEntity; switch (currentField.getData().getFieldType()){ case FREE_TEXT, TEXT_AREA, RICH_TEXT_AREA, RADIO_BOX -> fieldEntity.setTextValue(textValue.trim()); @@ -416,7 +417,7 @@ public class DatasetMigrationService { if(!this.conventionService.isNullOrEmpty(textValue)) { Map valuesParsed = migrationTools.tryParseJsonAsObjectString(Map.class, textValue); if (valuesParsed == null) { - valuesParsed = (Map) properties.get(currentField.getId()); + valuesParsed = (Map) propertyValue; } if (valuesParsed == null) throw new MyApplicationException("Could not parse upload : " + textValue); String id = valuesParsed.getOrDefault("id", null); @@ -999,7 +1000,7 @@ public class DatasetMigrationService { data.setSourceType(ReferenceSourceType.Internal); data.setSource("Internal"); if (dataset.getCreator() != null) data.setCreatedById(dataset.getCreator().getId()); - logger.warn("Migrate Dataset " + dataset.getId() + " " + dataset.getLabel() + " reference auto created as internal " + referenceTypeDataEntity.getReferenceTypeId() + " for value " + this.jsonHandlingService.toJsonSafe(item)); + //logger.warn("Migrate Dataset " + dataset.getId() + " " + dataset.getLabel() + " reference auto created as internal " + referenceTypeDataEntity.getReferenceTypeId() + " for value " + this.jsonHandlingService.toJsonSafe(item)); } ReferenceEntity existingEntity = referenceMap.getOrDefault(new ReferenceKey(data), null); diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/StorageFileMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/StorageFileMigrationService.java index c301362ce..bd4d602ad 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/StorageFileMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/StorageFileMigrationService.java @@ -63,9 +63,8 @@ public class StorageFileMigrationService { logger.debug("Migrate FileUpload " + page * PageSize + " of " + total); for (FileUpload item : items) { entityManager.detach(item); -// File file = new File(this.environment.getProperty("file.storage") + item.getId().toString()); -// if (!file.exists()) file = new File(this.environment.getProperty("temp.temp") + item.getId().toString()); -// if (!file.exists()) throw new MyApplicationException("Storage file not exist " + item.getId().toString()); + File file = new File(this.environment.getProperty("file.migration-storage") + item.getId().toString()); + if (!file.exists()) throw new MyApplicationException("Storage file not exist " + item.getId().toString()); StorageFileEntity data = new StorageFileEntity(); data.setId(item.getId()); @@ -80,11 +79,11 @@ public class StorageFileMigrationService { data.setPurgedAt(null); if (item.getCreator() == null) data.setOwnerId(item.getCreator().getId()); -// File destinationFile = new File(Paths.get(this.environment.getProperty("file.mainstorage"), data.getFileRef()).toString()); -// boolean fileCopied = FileCopyUtils.copy(file, destinationFile) > 0; -// if (!fileCopied) throw new MyApplicationException("Storage file not copied " + data.getId().toString()); + File destinationFile = new File(Paths.get(this.environment.getProperty("file.migrated-storage"), data.getFileRef()).toString()); + boolean fileCopied = FileCopyUtils.copy(file, destinationFile) > 0; + if (!fileCopied) throw new MyApplicationException("Storage file not copied " + data.getId().toString()); // -// filesToDelete.add(file); + filesToDelete.add(file); this.entityManager.persist(data); } 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 91a56b536..6eeb6991f 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 @@ -113,12 +113,12 @@ public class MigrationController { // this.dmpMigrationService.migrate(); // this.dmpDatasetProfileMigrationService.migrate(); // this.dmpUserMigrationService.migrate(); -// - //Description - this.datasetMigrationService.migrate(); - this.datasetReferenceMigrationService.migrateDatasetReferences(); - this.tagMigrationService.migrate(); +// //Description +// this.datasetMigrationService.migrate(); +// this.datasetReferenceMigrationService.migrateDatasetReferences(); +// this.tagMigrationService.migrate(); +// this.storageFileMigrationService.migrate(); // throw new RuntimeException("");