Merge branch 'RED-10442' into 'release/2.589.x'
RED-10442: Migration Issue: False Warnings appears when re-approve migrated... See merge request redactmanager/persistence-service!852
This commit is contained in:
commit
ded782850a
@ -1,18 +1,13 @@
|
||||
package com.iqser.red.service.persistence.management.v1.processor.service.persistence;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.google.common.hash.HashFunction;
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.FileRepository;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.LegalBasisMappingRepository;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.annotationentity.LegalBasisChangeRepository;
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.mongo.repository.EntityLogDocumentRepository;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -26,87 +21,66 @@ 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)",
|
||||
private static final Map<String, String> technicalNameMapping = Map.ofEntries(Map.entry("Article 39(e)(3) of Regulation (EC) No 178/2002",
|
||||
"personal_data_geolocation_article_39e3"),
|
||||
Map.entry("1.2 vertebrate study related personal data (incl. geolocation); Article 39(e)(2)",
|
||||
Map.entry("Article 39(e)(2) of Regulation (EC) No 178/2002",
|
||||
"vertebrate_study_personal_data_geolocation_article_39e2"),
|
||||
Map.entry("2. proprietary information", "proprietary_information"),
|
||||
Map.entry("2. manufacturing or production process", "manufacturing_production_process"),
|
||||
Map.entry("2. methods of analysis for impurities", "methods_analysis_impurities"),
|
||||
Map.entry("3. method of manufacture", "method_manufacture"),
|
||||
Map.entry("3. n/a", "n_a"),
|
||||
Map.entry("3. links between a producer and applicant", "links_producer_applicant"),
|
||||
Map.entry("4. commercial information", "commercial_information"),
|
||||
Map.entry("4. composition of a plant protection product", "composition_plant_protection_product"),
|
||||
Map.entry("5. quantitative composition", "quantitative_composition"),
|
||||
Map.entry("5. results of production batches", "results_production_batches"),
|
||||
Map.entry("6. specification of impurity of the active substance",
|
||||
"specification_impurity_active_substance"),
|
||||
Map.entry("6. specification of impurity", "specification_impurity"),
|
||||
Map.entry("7. links between a producer and applicant", "links_producer_applicant"),
|
||||
Map.entry("7. results of production batches", "results_production_batches"),
|
||||
Map.entry("8. composition of a plant protection product", "composition_plant_protection_product")
|
||||
// Add any additional mappings here
|
||||
);
|
||||
Map.entry(
|
||||
"Article 63(2)(a) of Regulation (EC) No 1107/2009 (reference to Article 39 of Regulation EC No 178/2002)",
|
||||
"manufacturing_production_process"),
|
||||
Map.entry(
|
||||
"Article 63(2)(a) of Regulation (EC) No 1107/2009 (making reference to Article 39 of Regulation EC No 178/2002)",
|
||||
"links_producer_applicant"),
|
||||
Map.entry(
|
||||
"Article 63(2)(a) of Regulation (EC) No1107/2009 (making reference to Article 39 of Regulation EC No 178/2002)",
|
||||
"links_producer_applicant"),
|
||||
Map.entry(
|
||||
"Article 63(2)(a) of Regulation (EC) No 1107/2009 (making reference to Article 39 of Regulation EC No 178/2002)",
|
||||
"commercial_information"),
|
||||
Map.entry(
|
||||
"Article 63(2)(a) of Regulation (EC) No 1107/2009 (making reference to Article 39 of Regulation EC No 178/2002)",
|
||||
"commercial_information"),
|
||||
Map.entry(
|
||||
"Article 63(2)(a) of Regulation (EC) No 1107/2009 (making reference to Article 39 of Regulation EC No 178/2002)",
|
||||
"quantitative_composition"),
|
||||
Map.entry(
|
||||
"Article 63(2)(a) of Regulation (EC) No 1107/2009 (making reference to Article 39 of Regulation EC No 178/2002)",
|
||||
"quantitative_composition"),
|
||||
Map.entry("Article 63(2)(b) of Regulation (EC) No 1107/2009", "specification_impurity"),
|
||||
Map.entry("Article 63(2)(c) of Regulation (EC) No 1107/2009", "results_production_batches"),
|
||||
Map.entry("Article 63(2)(d) of Regulation (EC) No 1107/2009",
|
||||
"composition_plant_protection_product"),
|
||||
Map.entry("Reg (EC) No 1107/2009 Art. 63 (2g)", "names_addresses_persons"),
|
||||
Map.entry("Reg (EC) No 1107/2009 Art. 63 (2d)", "methods_analysis_impurities"),
|
||||
Map.entry("Reg (EC) No 1107/2009 Art. 63 (2a)", "method_manufacture"),
|
||||
Map.entry("Reg (EC) No 1107/2009 Art. 63 (2b)", "specification_impurity_active_substance"),
|
||||
Map.entry("Article 4(1)(b), Regulation (EC) No 1049/2001 (Personal data)",
|
||||
"personal_data_geolocation"),
|
||||
Map.entry("Article 4(2), first indent, Regulation (EC) No 1049/2001 (commercial interest)",
|
||||
"proprietary_information"),
|
||||
Map.entry("3. n/a", "n_a"));
|
||||
|
||||
private final LegalBasisMappingRepository legalBasisMappingRepository;
|
||||
private final EntityLogDocumentRepository entityLogDocumentRepository;
|
||||
private final FileRepository fileRepository;
|
||||
private final LegalBasisChangeRepository legalBasisChangeRepository;
|
||||
|
||||
|
||||
public void migrate() {
|
||||
|
||||
// log.info("Starting migration: Adding technical names to legal basis");
|
||||
log.info("Starting 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");
|
||||
this.legalBasisMappingRepository.findAll()
|
||||
.stream()
|
||||
.peek(entry -> entry.getLegalBasis()
|
||||
.forEach(lb -> {
|
||||
lb.setTechnicalName(getTechnicalNameOrHash(lb.getReason()));
|
||||
}))
|
||||
.forEach(legalBasisMappingRepository::save);
|
||||
log.info("Finishing migration: Adding technical names to legal basis");
|
||||
}
|
||||
|
||||
|
||||
private static String getOrDefault(String lbName) {
|
||||
private static String getTechnicalNameOrHash(String reason) {
|
||||
|
||||
return technicalNameMapping.getOrDefault(lbName, String.valueOf(hashFunction.hashBytes(lbName.getBytes(StandardCharsets.UTF_8))));
|
||||
return technicalNameMapping.getOrDefault(reason, String.valueOf(hashFunction.hashString(reason, StandardCharsets.UTF_8)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user