RED-10094: Revert back migration for technical name of justifiactions

This commit is contained in:
Dominique Eifländer 2024-09-24 15:53:11 +02:00
parent 25a8bb0610
commit bea853cbf2

View File

@ -25,6 +25,8 @@ import lombok.extern.slf4j.Slf4j;
public class LegalBasisMigrationService {
private static final HashFunction hashFunction = Hashing.murmur3_128();
//FIXME mapping table needs to be based on reason, not name.
private static final Map<String, String> technicalNameMapping = Map.ofEntries(Map.entry("1. names and addresses of persons", "names_addresses_persons"),
Map.entry("1.1 personal data (incl. geolocation); Article 39(e)(3)",
"personal_data_geolocation_article_39e3"),
@ -56,43 +58,49 @@ public class LegalBasisMigrationService {
public void migrate() {
log.info("Starting migration: Adding technical names to legal basis");
List<String> approvedFileIds = fileRepository.getApprovedFiles()
.stream()
.map(file -> file.getId())
.collect(Collectors.toList());
List<String> hardDeletedFileIds = fileRepository.getHardDeletedFiles()
.stream()
.map(file -> file.getId())
.collect(Collectors.toList());
this.legalBasisMappingRepository.findAll()
.stream()
.peek(entry -> entry.getLegalBasis()
.forEach(lb -> {
lb.setTechnicalName(getOrDefault(lb.getName()));
}))
.forEach(legalBasisMappingRepository::save);
this.entityLogDocumentRepository.findAll()
.stream()
.filter(ent -> {
if (approvedFileIds.contains(ent.getFileId()) || hardDeletedFileIds.contains(ent.getFileId())) {
return false;
}
return true;
})
.peek(entry -> entry.getLegalBasis()
.forEach(lb -> {
lb.setTechnicalName(getOrDefault(lb.getName()));
}))
.forEach(entityLogDocumentRepository::save);
this.legalBasisChangeRepository.findAll()
.stream()
.peek(entry -> {
entry.setLegalBasis(technicalNameMapping.getOrDefault(entry.getLegalBasis(), entry.getLegalBasis()));
})
.forEach(legalBasisChangeRepository::save);
// log.info("Starting migration: Adding technical names to legal basis");
log.info("Finishing migration: Adding technical names to legal basis");
// Removed all the code, because the logic is completely wrong.
// The correct lookup needs to be on the reason field. With the hash value based on the name, we can not lookup anything.
// The technical name in the entityLog makes only sense if we can look it up in the entitylog entries legalbasis field, that is equal to the reason, not the name.
// Since rules are not updated to technical names and feature is too incomplete for production, we decided to put it in a future release.
// List<String> approvedFileIds = fileRepository.getApprovedFiles()
// .stream()
// .map(file -> file.getId())
// .collect(Collectors.toList());
// List<String> hardDeletedFileIds = fileRepository.getHardDeletedFiles()
// .stream()
// .map(file -> file.getId())
// .collect(Collectors.toList());
// this.legalBasisMappingRepository.findAll()
// .stream()
// .peek(entry -> entry.getLegalBasis()
// .forEach(lb -> {
// lb.setTechnicalName(getOrDefault(lb.getName()));
// }))
// .forEach(legalBasisMappingRepository::save);
// this.entityLogDocumentRepository.findAll()
// .stream()
// .filter(ent -> {
// if (approvedFileIds.contains(ent.getFileId()) || hardDeletedFileIds.contains(ent.getFileId())) {
// return false;
// }
// return true;
// })
// .peek(entry -> entry.getLegalBasis()
// .forEach(lb -> {
// lb.setTechnicalName(getOrDefault(lb.getName()));
// }))
// .forEach(entityLogDocumentRepository::save);
// this.legalBasisChangeRepository.findAll()
// .stream()
// .peek(entry -> {
// entry.setLegalBasis(technicalNameMapping.getOrDefault(entry.getLegalBasis(), entry.getLegalBasis()));
// })
// .forEach(legalBasisChangeRepository::save);
// log.info("Finishing migration: Adding technical names to legal basis");
}