refactor(training-export): route export services through owning services
SegmentationTrainingExportService and TrainingDataExportService each injected TranscriptionBlockRepository, AnnotationRepository and DocumentRepository directly. They now go through: - TranscriptionBlockQueryService (extended) for the three eligible-block queries — used over TranscriptionService to keep SenderModelService → TrainingDataExportService → TranscriptionService cycle-free. - AnnotationService.findById (new) — read API on the annotation domain. - DocumentService.findById (already added in #417 commit 3). The TrainingDataExportServiceTest @DataJpaTest delegates the new service reads to the real JPA repositories via Mockito stubs in the new makeService helper, so the integration coverage stays unchanged. Refs #417 (C6.2 violations #6 and #7). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
@@ -32,6 +33,10 @@ public class AnnotationService {
|
||||
return annotationRepository.findByDocumentId(documentId);
|
||||
}
|
||||
|
||||
public Optional<DocumentAnnotation> findById(UUID id) {
|
||||
return annotationRepository.findById(id);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public DocumentAnnotation createAnnotation(UUID documentId, CreateAnnotationDTO dto, UUID userId, String fileHash) {
|
||||
DocumentAnnotation annotation = DocumentAnnotation.builder()
|
||||
|
||||
@@ -8,9 +8,6 @@ import org.apache.pdfbox.rendering.PDFRenderer;
|
||||
import org.raddatz.familienarchiv.model.Document;
|
||||
import org.raddatz.familienarchiv.model.DocumentAnnotation;
|
||||
import org.raddatz.familienarchiv.model.TranscriptionBlock;
|
||||
import org.raddatz.familienarchiv.repository.AnnotationRepository;
|
||||
import org.raddatz.familienarchiv.repository.DocumentRepository;
|
||||
import org.raddatz.familienarchiv.repository.TranscriptionBlockRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
|
||||
|
||||
@@ -27,13 +24,13 @@ import java.util.zip.ZipOutputStream;
|
||||
@Slf4j
|
||||
public class SegmentationTrainingExportService {
|
||||
|
||||
private final TranscriptionBlockRepository blockRepository;
|
||||
private final AnnotationRepository annotationRepository;
|
||||
private final DocumentRepository documentRepository;
|
||||
private final TranscriptionBlockQueryService transcriptionBlockQueryService;
|
||||
private final AnnotationService annotationService;
|
||||
private final DocumentService documentService;
|
||||
private final FileService fileService;
|
||||
|
||||
public List<TranscriptionBlock> querySegmentationBlocks() {
|
||||
return blockRepository.findSegmentationBlocks();
|
||||
return transcriptionBlockQueryService.findSegmentationBlocks();
|
||||
}
|
||||
|
||||
public StreamingResponseBody exportToZip() {
|
||||
@@ -51,14 +48,14 @@ public class SegmentationTrainingExportService {
|
||||
// Pre-fetch annotations keyed by id
|
||||
Map<UUID, DocumentAnnotation> annotations = new HashMap<>();
|
||||
for (TranscriptionBlock b : blocks) {
|
||||
annotationRepository.findById(b.getAnnotationId())
|
||||
annotationService.findById(b.getAnnotationId())
|
||||
.ifPresent(a -> annotations.put(a.getId(), a));
|
||||
}
|
||||
|
||||
// Pre-fetch documents keyed by id
|
||||
Map<UUID, Document> documents = new HashMap<>();
|
||||
for (UUID docId : byDoc.keySet()) {
|
||||
documentRepository.findById(docId).ifPresent(d -> documents.put(d.getId(), d));
|
||||
documentService.findById(docId).ifPresent(d -> documents.put(d.getId(), d));
|
||||
}
|
||||
|
||||
return out -> {
|
||||
|
||||
@@ -8,9 +8,6 @@ import org.apache.pdfbox.rendering.PDFRenderer;
|
||||
import org.raddatz.familienarchiv.model.Document;
|
||||
import org.raddatz.familienarchiv.model.DocumentAnnotation;
|
||||
import org.raddatz.familienarchiv.model.TranscriptionBlock;
|
||||
import org.raddatz.familienarchiv.repository.AnnotationRepository;
|
||||
import org.raddatz.familienarchiv.repository.DocumentRepository;
|
||||
import org.raddatz.familienarchiv.repository.TranscriptionBlockRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
|
||||
|
||||
@@ -28,13 +25,13 @@ import java.util.zip.ZipOutputStream;
|
||||
@Slf4j
|
||||
public class TrainingDataExportService {
|
||||
|
||||
private final TranscriptionBlockRepository blockRepository;
|
||||
private final AnnotationRepository annotationRepository;
|
||||
private final DocumentRepository documentRepository;
|
||||
private final TranscriptionBlockQueryService transcriptionBlockQueryService;
|
||||
private final AnnotationService annotationService;
|
||||
private final DocumentService documentService;
|
||||
private final FileService fileService;
|
||||
|
||||
public List<TranscriptionBlock> queryEligibleBlocks() {
|
||||
return blockRepository.findEligibleKurrentBlocks();
|
||||
return transcriptionBlockQueryService.findEligibleKurrentBlocks();
|
||||
}
|
||||
|
||||
public StreamingResponseBody exportToZip() {
|
||||
@@ -42,7 +39,7 @@ public class TrainingDataExportService {
|
||||
}
|
||||
|
||||
public List<TranscriptionBlock> queryBlocksForSender(UUID personId) {
|
||||
return blockRepository.findManualKurrentBlocksByPerson(personId);
|
||||
return transcriptionBlockQueryService.findManualKurrentBlocksByPerson(personId);
|
||||
}
|
||||
|
||||
public StreamingResponseBody exportForSender(UUID personId) {
|
||||
@@ -63,14 +60,14 @@ public class TrainingDataExportService {
|
||||
// Pre-fetch annotations keyed by id
|
||||
Map<UUID, DocumentAnnotation> annotations = new HashMap<>();
|
||||
for (TranscriptionBlock b : blocks) {
|
||||
annotationRepository.findById(b.getAnnotationId())
|
||||
annotationService.findById(b.getAnnotationId())
|
||||
.ifPresent(a -> annotations.put(a.getId(), a));
|
||||
}
|
||||
|
||||
// Pre-fetch documents keyed by id
|
||||
Map<UUID, Document> documents = new HashMap<>();
|
||||
for (UUID docId : byDoc.keySet()) {
|
||||
documentRepository.findById(docId).ifPresent(d -> documents.put(d.getId(), d));
|
||||
documentService.findById(docId).ifPresent(d -> documents.put(d.getId(), d));
|
||||
}
|
||||
|
||||
return out -> {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.raddatz.familienarchiv.service;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.raddatz.familienarchiv.model.TranscriptionBlock;
|
||||
import org.raddatz.familienarchiv.repository.CompletionStatsRow;
|
||||
import org.raddatz.familienarchiv.repository.TranscriptionBlockRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -24,4 +25,16 @@ public class TranscriptionBlockQueryService {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<TranscriptionBlock> findSegmentationBlocks() {
|
||||
return blockRepository.findSegmentationBlocks();
|
||||
}
|
||||
|
||||
public List<TranscriptionBlock> findEligibleKurrentBlocks() {
|
||||
return blockRepository.findEligibleKurrentBlocks();
|
||||
}
|
||||
|
||||
public List<TranscriptionBlock> findManualKurrentBlocksByPerson(UUID personId) {
|
||||
return blockRepository.findManualKurrentBlocksByPerson(personId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user