From 3e65eff6e6392dd7e157455df7ecbefe0e892902 Mon Sep 17 00:00:00 2001 From: Marcus van Elst Date: Sat, 4 Apr 2026 12:05:05 +0200 Subject: [PATCH] Nachbearbeitung: DocumentProcessingCoordinator strukturell entflechtet --- .../DocumentProcessingCoordinator.java | 54 ++----------------- 1 file changed, 3 insertions(+), 51 deletions(-) diff --git a/pdf-umbenenner-application/src/main/java/de/gecheckt/pdf/umbenenner/application/service/DocumentProcessingCoordinator.java b/pdf-umbenenner-application/src/main/java/de/gecheckt/pdf/umbenenner/application/service/DocumentProcessingCoordinator.java index d30c129..d6df65d 100644 --- a/pdf-umbenenner-application/src/main/java/de/gecheckt/pdf/umbenenner/application/service/DocumentProcessingCoordinator.java +++ b/pdf-umbenenner-application/src/main/java/de/gecheckt/pdf/umbenenner/application/service/DocumentProcessingCoordinator.java @@ -27,6 +27,7 @@ import org.apache.logging.log4j.Logger; import java.time.Instant; import java.util.Objects; +import java.util.function.Function; /** * Application-level service that implements the per-document processing logic. @@ -141,56 +142,7 @@ public class DocumentProcessingCoordinator { Objects.requireNonNull(context, "context must not be null"); Objects.requireNonNull(attemptStart, "attemptStart must not be null"); - // Step 1: Load the document master record - DocumentRecordLookupResult lookupResult = - documentRecordRepository.findByFingerprint(fingerprint); - - // Step 2: Handle persistence lookup failure – cannot safely proceed - if (lookupResult instanceof PersistenceLookupTechnicalFailure failure) { - LOG.error("Cannot process '{}': master record lookup failed: {}", - candidate.uniqueIdentifier(), failure.errorMessage()); - return; - } - - // Step 3: Determine the action based on the lookup result - switch (lookupResult) { - case DocumentTerminalSuccess terminalSuccess -> { - // Document already successfully processed → skip - LOG.info("Skipping '{}': already successfully processed (fingerprint: {}).", - candidate.uniqueIdentifier(), fingerprint.sha256Hex()); - persistSkipAttempt( - candidate, fingerprint, terminalSuccess.record(), - ProcessingStatus.SKIPPED_ALREADY_PROCESSED, - context, attemptStart); - } - - case DocumentTerminalFinalFailure terminalFailure -> { - // Document finally failed → skip - LOG.info("Skipping '{}': already finally failed (fingerprint: {}).", - candidate.uniqueIdentifier(), fingerprint.sha256Hex()); - persistSkipAttempt( - candidate, fingerprint, terminalFailure.record(), - ProcessingStatus.SKIPPED_FINAL_FAILURE, - context, attemptStart); - } - - case DocumentUnknown ignored -> { - // New document – process and create a new master record - processAndPersistNewDocument(candidate, fingerprint, m3Outcome, context, attemptStart); - } - - case DocumentKnownProcessable knownProcessable -> { - // Known but not terminal – process and update the existing master record - processAndPersistKnownDocument( - candidate, fingerprint, m3Outcome, knownProcessable.record(), - context, attemptStart); - } - - default -> - // Exhaustive sealed hierarchy; this branch is unreachable - LOG.error("Unexpected lookup result type for '{}': {}", - candidate.uniqueIdentifier(), lookupResult.getClass().getSimpleName()); - } + processWithM3Execution(candidate, fingerprint, context, attemptStart, ignored -> m3Outcome); } /** @@ -225,7 +177,7 @@ public class DocumentProcessingCoordinator { DocumentFingerprint fingerprint, BatchRunContext context, Instant attemptStart, - java.util.function.Function m3Executor) { + Function m3Executor) { Objects.requireNonNull(candidate, "candidate must not be null"); Objects.requireNonNull(fingerprint, "fingerprint must not be null");