RED-8727 - Add rank de-duplication to migration
- add an update rank for type query because the updateType will not cover the update of ranks of system managed types (which is not possible for the user) - update the tests Signed-off-by: Corina Olariu <corina.olariu.ext@knecon.com>
This commit is contained in:
parent
0b2d067c93
commit
ec8dd4f260
@ -48,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.info(" {} - {}", typesByRankEntry.getKey(), typesByRankEntry.getValue().size());
|
||||
log.debug("Rank: {} - number of types {}", typesByRankEntry.getKey(), typesByRankEntry.getValue().size());
|
||||
typesByRankEntry.getValue()
|
||||
.forEach(t -> log.info("type: {} - dtId: {} - dId: {} typeId: {}", t.getType(), t.getDossierTemplateId(), t.getDossierId(), t.getId()));
|
||||
.forEach(t -> log.debug("type: {} - dtId: {} - dId: {} typeId: {}", t.getType(), t.getDossierTemplateId(), t.getDossierId(), t.getId()));
|
||||
|
||||
if (typesByRankEntry.getValue().size() > 1) {
|
||||
if (typesByRankEntry.getKey() > lastRankOk) {
|
||||
@ -76,13 +76,12 @@ public class RankDeDuplicationService {
|
||||
|
||||
if (newRank != t.getRank()) {
|
||||
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);
|
||||
dictionaryPersistenceService.updateRankForType(t.getId(), newRank);
|
||||
var dossierTypes = dictionaryPersistenceService.getAllDossierTypesForDossierTemplateAndType(dossierTemplateId, t.getType(), false);
|
||||
|
||||
for (TypeEntity td : dossierTypes) {
|
||||
td.setRank(newRank);
|
||||
dictionaryPersistenceService.updateType(td.getId(), td);
|
||||
log.info("Type {} with rank: {} will be updated to rank: {} - typeId {}", td.getType(), td.getRank(), newRank, td.getId());
|
||||
dictionaryPersistenceService.updateRankForType(td.getId(), newRank);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -287,4 +287,10 @@ public class DictionaryPersistenceService {
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void updateRankForType(String typeId, int newRank) {
|
||||
|
||||
typeRepository.updateRankForType(typeId, newRank);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -67,9 +67,9 @@ public interface TypeRepository extends JpaRepository<TypeEntity, String> {
|
||||
|
||||
|
||||
@Query("""
|
||||
select new com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.type.TypeRankSummary(t.dossierTemplateId, t.dossierId, t.rank, count(t))
|
||||
from TypeEntity t where t.dossierTemplateId = :dossierTemplateId and t.softDeletedTime is null
|
||||
group by t.dossierTemplateId, t.dossierId, t.rank
|
||||
select new com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.type.TypeRankSummary(t.dossierTemplateId, t.dossierId, t.rank, count(t))
|
||||
from TypeEntity t where t.dossierTemplateId = :dossierTemplateId and t.softDeletedTime is null
|
||||
group by t.dossierTemplateId, t.dossierId, t.rank
|
||||
order by t.rank""")
|
||||
List<TypeRankSummary> findTypeRankSummaryList(@Param("dossierTemplateId") String dossierTemplateId);
|
||||
|
||||
@ -83,4 +83,9 @@ public interface TypeRepository extends JpaRepository<TypeEntity, String> {
|
||||
@Query("Update TypeEntity t set t.softDeletedTime = null where t.id = :typeId and t.softDeletedTime is not null")
|
||||
int unSoftDeleteTypeById(@Param("typeId") String typeId);
|
||||
|
||||
|
||||
@Modifying
|
||||
@Query("Update TypeEntity t set t.rank = :newRank, t.version = t.version + 1 where t.id = :typeId")
|
||||
void updateRankForType(@Param("typeId") String typeId, @Param("newRank") int newRank);
|
||||
|
||||
}
|
||||
|
||||
@ -104,7 +104,7 @@ public class DossierTemplateCloneAndExportWithDuplicateRanksTest {
|
||||
private String dossierTemplateName = "Clone of " + dossierTemplateId;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<TypeEntity> captor;
|
||||
private ArgumentCaptor<Integer> captor;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@ -221,63 +221,47 @@ public class DossierTemplateCloneAndExportWithDuplicateRanksTest {
|
||||
|
||||
rankDeDuplicationService.deduplicate();
|
||||
|
||||
TypeEntity caughtType;
|
||||
verify(dictionaryPersistenceService, times(1)).updateRankForType(eq(toTypeId("type01", dossierTemplateId)), captor.capture());
|
||||
Assertions.assertEquals(captor.getValue(), 1);
|
||||
|
||||
verify(dictionaryPersistenceService, times(1)).updateType(eq(toTypeId("type01", dossierTemplateId)), captor.capture());
|
||||
caughtType = captor.getValue();
|
||||
Assertions.assertEquals(caughtType.getRank(), 1);
|
||||
verify(dictionaryPersistenceService, times(1)).updateRankForType(eq(toTypeId("type02", dossierTemplateId)), captor.capture());
|
||||
Assertions.assertEquals(captor.getValue(), 2);
|
||||
|
||||
verify(dictionaryPersistenceService, times(1)).updateType(eq(toTypeId("type02", dossierTemplateId)), captor.capture());
|
||||
caughtType = captor.getValue();
|
||||
Assertions.assertEquals(caughtType.getRank(), 2);
|
||||
verify(dictionaryPersistenceService, times(1)).updateRankForType(eq(toTypeId("type02", dossierTemplateId, dossierId)), captor.capture());
|
||||
Assertions.assertEquals(captor.getValue(), 2);
|
||||
|
||||
verify(dictionaryPersistenceService, times(1)).updateType(eq(toTypeId("type02", dossierTemplateId, dossierId)), captor.capture());
|
||||
caughtType = captor.getValue();
|
||||
Assertions.assertEquals(caughtType.getRank(), 2);
|
||||
verify(dictionaryPersistenceService, times(1)).updateRankForType(eq(toTypeId("type22", dossierTemplateId)), captor.capture());
|
||||
Assertions.assertEquals(captor.getValue(), 3);
|
||||
|
||||
verify(dictionaryPersistenceService, times(1)).updateType(eq(toTypeId("type22", dossierTemplateId)), captor.capture());
|
||||
caughtType = captor.getValue();
|
||||
Assertions.assertEquals(caughtType.getRank(), 3);
|
||||
verify(dictionaryPersistenceService, times(1)).updateRankForType(eq(toTypeId("type2", dossierTemplateId)), captor.capture());
|
||||
Assertions.assertEquals(captor.getValue(), 51);
|
||||
|
||||
verify(dictionaryPersistenceService, times(1)).updateType(eq(toTypeId("type2", dossierTemplateId)), captor.capture());
|
||||
caughtType = captor.getValue();
|
||||
Assertions.assertEquals(caughtType.getRank(), 51);
|
||||
verify(dictionaryPersistenceService, times(1)).updateRankForType(eq(toTypeId("type3", dossierTemplateId)), captor.capture());
|
||||
Assertions.assertEquals(captor.getValue(), 52);
|
||||
|
||||
verify(dictionaryPersistenceService, times(1)).updateType(eq(toTypeId("type3", dossierTemplateId)), captor.capture());
|
||||
caughtType = captor.getValue();
|
||||
Assertions.assertEquals(caughtType.getRank(), 52);
|
||||
verify(dictionaryPersistenceService, times(1)).updateRankForType(eq(toTypeId("type4", dossierTemplateId)), captor.capture());
|
||||
Assertions.assertEquals(captor.getValue(), 53);
|
||||
|
||||
verify(dictionaryPersistenceService, times(1)).updateType(eq(toTypeId("type4", dossierTemplateId)), captor.capture());
|
||||
caughtType = captor.getValue();
|
||||
Assertions.assertEquals(caughtType.getRank(), 53);
|
||||
verify(dictionaryPersistenceService, times(1)).updateRankForType(eq(toTypeId("type5", dossierTemplateId)), captor.capture());
|
||||
Assertions.assertEquals(captor.getValue(), 54);
|
||||
|
||||
verify(dictionaryPersistenceService, times(1)).updateType(eq(toTypeId("type5", dossierTemplateId)), captor.capture());
|
||||
caughtType = captor.getValue();
|
||||
Assertions.assertEquals(caughtType.getRank(), 54);
|
||||
verify(dictionaryPersistenceService, times(1)).updateRankForType(eq(toTypeId("type6", dossierTemplateId)), captor.capture());
|
||||
Assertions.assertEquals(captor.getValue(), 55);
|
||||
|
||||
verify(dictionaryPersistenceService, times(1)).updateType(eq(toTypeId("type6", dossierTemplateId)), captor.capture());
|
||||
caughtType = captor.getValue();
|
||||
Assertions.assertEquals(caughtType.getRank(), 55);
|
||||
verify(dictionaryPersistenceService, times(1)).updateRankForType(eq(toTypeId("type7", dossierTemplateId)), captor.capture());
|
||||
Assertions.assertEquals(captor.getValue(), 56);
|
||||
|
||||
verify(dictionaryPersistenceService, times(1)).updateType(eq(toTypeId("type7", dossierTemplateId)), captor.capture());
|
||||
caughtType = captor.getValue();
|
||||
Assertions.assertEquals(caughtType.getRank(), 56);
|
||||
verify(dictionaryPersistenceService, times(1)).updateRankForType(eq(toTypeId("type8", dossierTemplateId)), captor.capture());
|
||||
Assertions.assertEquals(captor.getValue(), 57);
|
||||
|
||||
verify(dictionaryPersistenceService, times(1)).updateType(eq(toTypeId("type8", dossierTemplateId)), captor.capture());
|
||||
caughtType = captor.getValue();
|
||||
Assertions.assertEquals(caughtType.getRank(), 57);
|
||||
verify(dictionaryPersistenceService, times(1)).updateRankForType(eq(toTypeId("type9", dossierTemplateId)), captor.capture());
|
||||
Assertions.assertEquals(captor.getValue(), 58);
|
||||
|
||||
verify(dictionaryPersistenceService, times(1)).updateType(eq(toTypeId("type9", dossierTemplateId)), captor.capture());
|
||||
caughtType = captor.getValue();
|
||||
Assertions.assertEquals(caughtType.getRank(), 58);
|
||||
verify(dictionaryPersistenceService, times(1)).updateRankForType(eq(toTypeId("type10", dossierTemplateId)), captor.capture());
|
||||
Assertions.assertEquals(captor.getValue(), 59);
|
||||
|
||||
verify(dictionaryPersistenceService, times(1)).updateType(eq(toTypeId("type10", dossierTemplateId)), captor.capture());
|
||||
caughtType = captor.getValue();
|
||||
Assertions.assertEquals(caughtType.getRank(), 59);
|
||||
|
||||
verify(dictionaryPersistenceService, times(1)).updateType(eq(toTypeId("type11", dossierTemplateId)), captor.capture());
|
||||
caughtType = captor.getValue();
|
||||
Assertions.assertEquals(caughtType.getRank(), 60);
|
||||
verify(dictionaryPersistenceService, times(1)).updateRankForType(eq(toTypeId("type11", dossierTemplateId)), captor.capture());
|
||||
Assertions.assertEquals(captor.getValue(), 60);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user