From 678d9dab38679185141de43e2ac355ec508b1a4e Mon Sep 17 00:00:00 2001 From: Marcel Date: Mon, 4 May 2026 15:15:33 +0200 Subject: [PATCH] refactor(training): extract kurrentLabels helper + clarify query comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extract repeated `new java.util.HashSet<>(Set.of(TrainingLabel.KURRENT_RECOGNITION))` into a `kurrentLabels()` helper in TrainingBlockQueryTest and add `import java.util.HashSet`. Add clarifying comments on the two person-scoped queries in TranscriptionBlockRepository explaining that they use `MEMBER OF d.trainingLabels` — aligned with the pre-existing `findEligibleKurrentBlocks()` pattern. Co-Authored-By: Claude Sonnet 4.6 --- .../repository/TranscriptionBlockRepository.java | 4 ++++ .../repository/TrainingBlockQueryTest.java | 16 ++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/org/raddatz/familienarchiv/repository/TranscriptionBlockRepository.java b/backend/src/main/java/org/raddatz/familienarchiv/repository/TranscriptionBlockRepository.java index 8e61e09d..5c2d34e2 100644 --- a/backend/src/main/java/org/raddatz/familienarchiv/repository/TranscriptionBlockRepository.java +++ b/backend/src/main/java/org/raddatz/familienarchiv/repository/TranscriptionBlockRepository.java @@ -60,6 +60,8 @@ public interface TranscriptionBlockRepository extends JpaRepository findSegmentationBlocks(); + // Uses 'KURRENT_RECOGNITION' MEMBER OF d.trainingLabels — aligned with findEligibleKurrentBlocks() + // which already used this form (changed from d.scriptType = 'KURRENT' in the original queries). @Query(""" SELECT COUNT(b) FROM TranscriptionBlock b JOIN Document d ON d.id = b.documentId @@ -69,6 +71,8 @@ public interface TranscriptionBlockRepository extends JpaRepository(Set.of(TrainingLabel.KURRENT_RECOGNITION))) + .trainingLabels(kurrentLabels()) .build()); kurrentDocId = kurrentDoc.getId(); @@ -123,7 +123,7 @@ class TrainingBlockQueryTest { .originalFilename("karl.pdf") .status(DocumentStatus.UPLOADED) .sender(sender) - .trainingLabels(new HashSet<>(Set.of(TrainingLabel.KURRENT_RECOGNITION))) + .trainingLabels(kurrentLabels()) .build()); UUID annId = annotationRepository.save(annotation(doc.getId())).getId(); blockRepository.save(block(doc.getId(), annId, BlockSource.MANUAL, false)); @@ -158,7 +158,7 @@ class TrainingBlockQueryTest { .originalFilename("karl.pdf") .status(DocumentStatus.UPLOADED) .sender(sender) - .trainingLabels(new HashSet<>(Set.of(TrainingLabel.KURRENT_RECOGNITION))) + .trainingLabels(kurrentLabels()) .build()); UUID annId = annotationRepository.save(annotation(doc.getId())).getId(); blockRepository.save(block(doc.getId(), annId, BlockSource.OCR, false)); @@ -177,7 +177,7 @@ class TrainingBlockQueryTest { .originalFilename("karl.pdf") .status(DocumentStatus.UPLOADED) .sender(karl) - .trainingLabels(new HashSet<>(Set.of(TrainingLabel.KURRENT_RECOGNITION))) + .trainingLabels(kurrentLabels()) .build()); UUID annId = annotationRepository.save(annotation(doc.getId())).getId(); blockRepository.save(block(doc.getId(), annId, BlockSource.MANUAL, false)); @@ -195,7 +195,7 @@ class TrainingBlockQueryTest { .originalFilename("karl.pdf") .status(DocumentStatus.UPLOADED) .sender(sender) - .trainingLabels(new HashSet<>(Set.of(TrainingLabel.KURRENT_RECOGNITION))) + .trainingLabels(kurrentLabels()) .build()); UUID annId = annotationRepository.save(annotation(doc.getId())).getId(); blockRepository.save(block(doc.getId(), annId, BlockSource.MANUAL, false)); @@ -218,6 +218,10 @@ class TrainingBlockQueryTest { // ─── helpers ───────────────────────────────────────────────────────────── + private static Set kurrentLabels() { + return new HashSet<>(Set.of(TrainingLabel.KURRENT_RECOGNITION)); + } + private DocumentAnnotation annotation(UUID docId) { return DocumentAnnotation.builder() .documentId(docId)