RED-8727 - Add rank de-duplication to migration

- add more logs and change the save to saveAndFlush when updating a type

Signed-off-by: Corina Olariu <corina.olariu.ext@knecon.com>
This commit is contained in:
Corina Olariu 2024-04-04 11:43:55 +03:00
parent 025b59e348
commit 0b2d067c93
2 changed files with 6 additions and 5 deletions

View File

@ -39,6 +39,7 @@ public class RankDeDuplicationService {
private void deduplicate(String dossierTemplateId) {
log.info("deduplicate for dossierTemplateID: {}", dossierTemplateId);
List<TypeEntity> allDossierTemplateTypes = dictionaryPersistenceService.getAllTypesForDossierTemplate(dossierTemplateId, false);
TreeMap<Integer, List<TypeEntity>> typesSortedByRank = new TreeMap<>(allDossierTemplateTypes.stream()
.collect(Collectors.groupingBy(TypeEntity::getRank, Collectors.toList())));
@ -47,9 +48,9 @@ public class RankDeDuplicationService {
// we create a map with every rank that needs to be updated and the value is the starting point for that rank
Map<Integer, Integer> rankToNewRankUpdateMap = new TreeMap<>(Collections.reverseOrder());
for (var typesByRankEntry : typesSortedByRank.entrySet()) {
log.debug(" {} - {}", typesByRankEntry.getKey(), typesByRankEntry.getValue().size());
log.info(" {} - {}", typesByRankEntry.getKey(), typesByRankEntry.getValue().size());
typesByRankEntry.getValue()
.forEach(t -> log.debug("type: {} - dtId: {} - dId: {}", t.getType(), t.getDossierTemplateId(), t.getDossierId()));
.forEach(t -> log.info("type: {} - dtId: {} - dId: {} typeId: {}", t.getType(), t.getDossierTemplateId(), t.getDossierId(), t.getId()));
if (typesByRankEntry.getValue().size() > 1) {
if (typesByRankEntry.getKey() > lastRankOk) {
@ -74,7 +75,7 @@ public class RankDeDuplicationService {
for (TypeEntity t : typesSortedByRank.get(rankToUpdateEntry.getKey())) {
if (newRank != t.getRank()) {
log.info("Type {} with rank: {} will be updated to rank: {}", t.getType(), t.getRank(), newRank);
log.info("Type {} with rank: {} will be updated to rank: {} - typeId {}", t.getType(), t.getRank(), newRank, t.getId());
t.setRank(newRank);
dictionaryPersistenceService.updateType(t.getId(), t);
var dossierTypes = dictionaryPersistenceService.getAllDossierTypesForDossierTemplateAndType(dossierTemplateId, t.getType(), false);

View File

@ -90,7 +90,7 @@ public class DictionaryPersistenceService {
if (!existingTypesForRank.isEmpty()) {
for (var existingTypeValueForRank : existingTypesForRank) {
if (!existingTypeValueForRank.isDeleted() && !existingTypeValueForRank.getType().equalsIgnoreCase(type)) {
throw new ConflictException("Rank already exists: " + rank + " on type: " + existingTypeValueForRank.getType());
throw new ConflictException("Rank already exists: " + rank + " on type: " + existingTypeValueForRank.getType() + " type id: " + existingTypeValueForRank.getId());
}
}
}
@ -140,7 +140,7 @@ public class DictionaryPersistenceService {
"version",
"dossierDictionaryOnly");
}
typeRepository.save(type);
typeRepository.saveAndFlush(type);
});
}