Removing possible duplicate records after DmpDatasetProfile migration

This commit is contained in:
Thomas Georgios Giannos 2023-11-24 12:15:57 +02:00
parent a6d175dcb3
commit c60e90d638
2 changed files with 34 additions and 2 deletions

View File

@ -16,12 +16,14 @@ import eu.eudat.data.ReferenceEntity;
import eu.eudat.model.DmpBlueprint; import eu.eudat.model.DmpBlueprint;
import eu.eudat.query.DescriptionTemplateQuery; import eu.eudat.query.DescriptionTemplateQuery;
import eu.eudat.query.DmpBlueprintQuery; 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.DmpDatasetProfileDao;
import eu.old.eudat.data.dao.entities.ResearcherDao; import eu.old.eudat.data.dao.entities.ResearcherDao;
import eu.old.eudat.data.entities.DMPDatasetProfile; import eu.old.eudat.data.entities.DMPDatasetProfile;
import eu.old.eudat.data.entities.Researcher; import eu.old.eudat.data.entities.Researcher;
import eu.old.eudat.logic.services.operations.DatabaseRepository; import eu.old.eudat.logic.services.operations.DatabaseRepository;
import eu.old.eudat.queryable.QueryableList; import eu.old.eudat.queryable.QueryableList;
import gr.cite.tools.data.query.Paging;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
@ -120,9 +122,39 @@ public class DmpDatasetProfileMigrationService {
} }
} while (items != null && !items.isEmpty() && !TestMode); } 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<DmpDescriptionTemplateEntity> 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"}) @JsonIgnoreProperties({"validationErrorModel"})

View File

@ -81,7 +81,7 @@ public class MigrationController {
@Transactional @Transactional
public boolean migrateDmpDatasetProfiles() throws IOException, JAXBException, ParserConfigurationException, InstantiationException, IllegalAccessException, SAXException { public boolean migrateDmpDatasetProfiles() throws IOException, JAXBException, ParserConfigurationException, InstantiationException, IllegalAccessException, SAXException {
this.dmpDatasetProfileMigrationService.migrate(); this.dmpDatasetProfileMigrationService.migrate();
return true; return true;
} }
@GetMapping("references") @GetMapping("references")