RED-5624: migration
working on migration
This commit is contained in:
parent
535f9ce8da
commit
cff6826424
@ -1,13 +1,10 @@
|
||||
package com.iqser.red.service.persistence.management.v1.processor.migration.migrations;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.migration.Migration;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.LegalBasisMappingPersistenceService;
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.mongo.service.EntityLogMongoService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.LegalBasisMigrationService;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -19,33 +16,8 @@ public class AddTechnicalNameToJustifications20 extends Migration {
|
||||
|
||||
private static final String NAME = "Migration to add a technical name to justifications";
|
||||
private static final long VERSION = 20;
|
||||
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"),
|
||||
Map.entry("1.2 vertebrate study related personal data (incl. geolocation); Article 39(e)(2)",
|
||||
"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
|
||||
);
|
||||
@Autowired
|
||||
private LegalBasisMappingPersistenceService legalBasisMappingPersistenceService;
|
||||
@Autowired
|
||||
private EntityLogMongoService entityLogMongoService;
|
||||
private LegalBasisMigrationService legalBasisMigrationService;
|
||||
|
||||
|
||||
public AddTechnicalNameToJustifications20() {
|
||||
@ -56,26 +28,9 @@ public class AddTechnicalNameToJustifications20 extends Migration {
|
||||
|
||||
@Override
|
||||
protected void migrate() {
|
||||
//migrate all existing legalbasismappings
|
||||
this.legalBasisMappingPersistenceService.getAllLegalBasisMappingEntities()
|
||||
.stream()
|
||||
.forEach(entry -> {
|
||||
entry.getLegalBasis()
|
||||
.stream()
|
||||
.forEach(lb -> {
|
||||
lb.setTechnicalName(technicalNameMapping.get(lb.getName()));
|
||||
});
|
||||
});
|
||||
|
||||
//migrate entitylogs
|
||||
this.entityLogMongoService.findAllEntityLogDocuments()
|
||||
.stream()
|
||||
.forEach(doc -> {
|
||||
doc.getLegalBasis()
|
||||
.forEach(lb -> {
|
||||
lb.setTechnicalName(technicalNameMapping.get(lb.getName()));
|
||||
});
|
||||
});
|
||||
this.legalBasisMigrationService.migrate();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,79 @@
|
||||
package com.iqser.red.service.persistence.management.v1.processor.service.persistence;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
|
||||
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.service.v1.api.shared.mongo.repository.EntityLogDocumentRepository;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class LegalBasisMigrationService {
|
||||
|
||||
private static final HashFunction hashFunction = Hashing.murmur3_128();
|
||||
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"),
|
||||
Map.entry("1.2 vertebrate study related personal data (incl. geolocation); Article 39(e)(2)",
|
||||
"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
|
||||
);
|
||||
private final LegalBasisMappingRepository legalBasisMappingRepository;
|
||||
private final EntityLogDocumentRepository entityLogDocumentRepository;
|
||||
private final FileRepository fileRepository;
|
||||
|
||||
|
||||
public void migrate() {
|
||||
|
||||
log.info("Starting migration: Adding technical names to legal basis");
|
||||
this.legalBasisMappingRepository.findAll()
|
||||
.stream()
|
||||
.peek(entry -> entry.getLegalBasis()
|
||||
.forEach(lb -> {
|
||||
lb.setTechnicalName(getOrDefault(lb.getName()));
|
||||
}))
|
||||
.forEach(legalBasisMappingRepository::save);
|
||||
this.entityLogDocumentRepository.findAll()
|
||||
.stream()
|
||||
.peek(entry -> entry.getLegalBasis()
|
||||
.forEach(lb -> {
|
||||
lb.setTechnicalName(getOrDefault(lb.getName()));
|
||||
}))
|
||||
.forEach(entityLogDocumentRepository::save);
|
||||
log.info("Finishing migration: Adding technical names to legal basis");
|
||||
}
|
||||
|
||||
|
||||
private static String getOrDefault(String lbName) {
|
||||
|
||||
return technicalNameMapping.getOrDefault(lbName, String.valueOf(hashFunction.hashBytes(lbName.getBytes(StandardCharsets.UTF_8))));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user