RED-5624: migration
added class for migration
This commit is contained in:
parent
3af71f2760
commit
535f9ce8da
@ -0,0 +1,81 @@
|
||||
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 lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Setter
|
||||
@Service
|
||||
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;
|
||||
|
||||
|
||||
public AddTechnicalNameToJustifications20() {
|
||||
|
||||
super(NAME, VERSION);
|
||||
}
|
||||
|
||||
|
||||
@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()));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@ -7,8 +7,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.entity.configuration.LegalBasisEntity;
|
||||
@ -17,6 +15,7 @@ import com.iqser.red.service.persistence.management.v1.processor.exception.BadRe
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.LegalBasisMappingRepository;
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.legalbasis.LegalBasis;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Service
|
||||
@ -55,6 +54,13 @@ public class LegalBasisMappingPersistenceService {
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public List<LegalBasisMappingEntity> getAllLegalBasisMappingEntities() {
|
||||
|
||||
return this.legalBasisMappingRepository.findAll();
|
||||
}
|
||||
|
||||
|
||||
private LegalBasisMappingEntity getLegalBasisMappingOrCreate(String dossierTemplateId) {
|
||||
|
||||
return legalBasisMappingRepository.findById(dossierTemplateId)
|
||||
@ -112,7 +118,7 @@ public class LegalBasisMappingPersistenceService {
|
||||
throw new BadRequestException(String.format("The legal basis is too long (%s), max length %s", legalBasis.getReason().length(), MAX_LEGAL_BASIS_LENGTH));
|
||||
}
|
||||
|
||||
if(legalBasis.getTechnicalName().length() > MAX_LEGAL_BASIS_LENGTH) {
|
||||
if (legalBasis.getTechnicalName().length() > MAX_LEGAL_BASIS_LENGTH) {
|
||||
throw new BadRequestException(String.format("The legal basis is too long (%s), max length %s", legalBasis.getTechnicalName().length(), MAX_LEGAL_BASIS_LENGTH));
|
||||
}
|
||||
}
|
||||
|
||||
@ -197,6 +197,12 @@ public class EntityLogMongoService {
|
||||
}
|
||||
|
||||
|
||||
public List<EntityLogDocument> findAllEntityLogDocuments() {
|
||||
|
||||
return this.entityLogDocumentRepository.findAll();
|
||||
}
|
||||
|
||||
|
||||
public boolean entityLogDocumentExists(String dossierId, String fileId) {
|
||||
|
||||
return entityLogDocumentRepository.existsById(mapper.getLogId(dossierId, fileId));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user