1
0

Nachbearbeitung: DocumentProcessingCoordinator strukturell entflechtet

This commit is contained in:
2026-04-04 12:05:05 +02:00
parent 3a14bcb0d0
commit 3e65eff6e6

View File

@@ -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<SourceDocumentCandidate, DocumentProcessingOutcome> m3Executor) {
Function<SourceDocumentCandidate, DocumentProcessingOutcome> m3Executor) {
Objects.requireNonNull(candidate, "candidate must not be null");
Objects.requireNonNull(fingerprint, "fingerprint must not be null");