V2.8: Selektive Wiederverarbeitung und Statusreset in der GUI

- Mehrfachauswahl mit CheckBox-Spalte und Master-Tri-State-Checkbox
- Gezielter Mini-Lauf über ausgewählte Einträge (unabhängig vom Status)
- Statusreset für ausgewählte Einträge (Stammsatz + Versuchshistorie)
- Fehlende Quelldatei im Mini-Lauf wird als FAILED_PERMANENT synthetisiert
- Identische Zieldatei wird als SUCCESS ohne erneute KI-Verarbeitung erkannt
- Weiche Stop-Semantik erhält zurückgesetzte Einträge unverändert
- Nicht-ausgewählte Einträge bleiben in allen Pfaden unberührt
- Buttons reagieren jetzt korrekt auf Auswahländerungen

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-04-23 12:04:22 +02:00
parent f4a1bce9ae
commit 9fd5bd5a52
40 changed files with 3478 additions and 223 deletions
@@ -16,6 +16,8 @@ import org.apache.logging.log4j.Logger;
import de.gecheckt.pdf.umbenenner.adapter.in.gui.batchrun.GuiBatchRunLauncher;
import de.gecheckt.pdf.umbenenner.adapter.in.gui.batchrun.GuiBatchRunTab;
import de.gecheckt.pdf.umbenenner.adapter.in.gui.batchrun.GuiMiniRunLauncher;
import de.gecheckt.pdf.umbenenner.adapter.in.gui.batchrun.GuiResetDocumentStatusPort;
import de.gecheckt.pdf.umbenenner.adapter.in.gui.editor.AiProviderFamilyStringConverter;
import de.gecheckt.pdf.umbenenner.adapter.in.gui.editor.GuiApiKeyMerger;
import de.gecheckt.pdf.umbenenner.adapter.in.gui.editor.GuiChangeState;
@@ -344,11 +346,24 @@ public final class GuiConfigurationEditorWorkspace {
private final ApiKeyResolutionPort apiKeyResolutionPort;
/**
* Launcher used by the processing-run tab to execute a batch run against the saved
* configuration file. Supplied by Bootstrap via the startup context.
* Launcher used by the processing-run tab to execute a regular batch run against the
* saved configuration file. Supplied by Bootstrap via the startup context.
*/
private final GuiBatchRunLauncher batchRunLauncher;
/**
* Launcher used by the processing-run tab to execute a targeted mini-run for a
* selected set of documents. Supplied by Bootstrap via the startup context.
*/
private final GuiMiniRunLauncher miniRunLauncher;
/**
* Port used by the processing-run tab to reset the persistence status of selected
* documents without triggering a reprocessing run. Supplied by Bootstrap via the
* startup context.
*/
private final GuiResetDocumentStatusPort resetDocumentStatusPort;
/**
* Second main tab of the window that drives the live processing-run view. Created
* during workspace construction and wired into the shared {@link #tabPane} alongside
@@ -421,8 +436,12 @@ public final class GuiConfigurationEditorWorkspace {
triggerLabel -> showUnsavedChangesDialog(triggerLabel));
this.batchRunLauncher = effectiveContext.batchRunLauncher();
this.miniRunLauncher = effectiveContext.miniRunLauncher();
this.resetDocumentStatusPort = effectiveContext.resetDocumentStatusPort();
this.batchRunTab = new GuiBatchRunTab(
() -> this.batchRunLauncher,
() -> this.miniRunLauncher,
() -> this.resetDocumentStatusPort,
this::loadedConfigurationPath,
this::isSavedConfigurationReady,
this::applyBatchRunLockState);
@@ -2,11 +2,15 @@ package de.gecheckt.pdf.umbenenner.adapter.in.gui;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import de.gecheckt.pdf.umbenenner.adapter.in.gui.batchrun.GuiBatchRunLaunchOutcome;
import de.gecheckt.pdf.umbenenner.adapter.in.gui.batchrun.GuiBatchRunLauncher;
import de.gecheckt.pdf.umbenenner.adapter.in.gui.batchrun.GuiMiniRunLauncher;
import de.gecheckt.pdf.umbenenner.adapter.in.gui.batchrun.GuiResetDocumentStatusPort;
import de.gecheckt.pdf.umbenenner.adapter.in.gui.editor.GuiConfigurationEditorState;
import de.gecheckt.pdf.umbenenner.adapter.in.gui.editor.GuiConfigurationEditorStateFactory;
import de.gecheckt.pdf.umbenenner.application.port.in.ResetDocumentStatusResult;
import de.gecheckt.pdf.umbenenner.application.port.out.modelcatalog.AiModelCatalogPort;
import de.gecheckt.pdf.umbenenner.application.port.out.modelcatalog.EffectiveApiKeyDescriptor;
import de.gecheckt.pdf.umbenenner.application.validation.editor.ApiKeyResolutionPort;
@@ -15,6 +19,7 @@ import de.gecheckt.pdf.umbenenner.application.validation.technicaltest.PathCheck
import de.gecheckt.pdf.umbenenner.application.validation.technicaltest.ProviderTechnicalTestService;
import de.gecheckt.pdf.umbenenner.application.validation.technicaltest.ResourceCreationPort;
import de.gecheckt.pdf.umbenenner.application.validation.technicaltest.TechnicalTestOrchestrator;
import de.gecheckt.pdf.umbenenner.domain.model.DocumentFingerprint;
/**
* Immutable startup data for the GUI adapter.
@@ -26,9 +31,12 @@ import de.gecheckt.pdf.umbenenner.application.validation.technicaltest.Technical
* API key provenance from environment variables, the {@link ProviderTechnicalTestService}
* used to execute provider-specific technical checks, the {@link PathCheckPort}
* used to verify filesystem path accessibility for configuration values, the
* {@link TechnicalTestOrchestrator} used by the "Technische Tests ausführen" action, and the
* {@link TechnicalTestOrchestrator} used by the "Technische Tests ausführen" action, the
* {@link CorrectionExecutionService} used to execute corrective actions after a
* technical test run has been confirmed by the user.
* technical test run has been confirmed by the user, the {@link GuiBatchRunLauncher} used
* to execute regular batch runs, the {@link GuiMiniRunLauncher} used to execute targeted
* mini-runs for selected documents, and the {@link GuiResetDocumentStatusPort} used to
* reset the persistence status of selected documents.
* <p>
* All ports and services are supplied by Bootstrap so that the GUI adapter does not need to
* know about provider-specific HTTP details or adapter wiring.
@@ -44,10 +52,12 @@ public record GuiStartupContext(
PathCheckPort pathCheckPort,
TechnicalTestOrchestrator technicalTestOrchestrator,
CorrectionExecutionService correctionExecutionService,
GuiBatchRunLauncher batchRunLauncher) {
GuiBatchRunLauncher batchRunLauncher,
GuiMiniRunLauncher miniRunLauncher,
GuiResetDocumentStatusPort resetDocumentStatusPort) {
/**
* Creates a startup context.
* Creates a fully wired startup context.
*
* @param initialState initial editor state; must not be {@code null}
* @param startupNotice optional startup notice; {@code null} becomes empty
@@ -59,9 +69,11 @@ public record GuiStartupContext(
* @param pathCheckPort port for filesystem path accessibility checks; must not be {@code null}
* @param technicalTestOrchestrator orchestrator for the full technical test run; must not be {@code null}
* @param correctionExecutionService service for executing confirmed corrective actions; must not be {@code null}
* @param batchRunLauncher bridge that executes a batch run against a stored
* configuration path for the processing-run tab;
* must not be {@code null}
* @param batchRunLauncher bridge that executes a regular batch run; must not be {@code null}
* @param miniRunLauncher bridge that executes a targeted mini-run for selected
* documents; must not be {@code null}
* @param resetDocumentStatusPort bridge that resets the persistence status of selected
* documents; must not be {@code null}
*/
public GuiStartupContext {
initialState = Objects.requireNonNull(initialState, "initialState must not be null");
@@ -84,15 +96,51 @@ public record GuiStartupContext(
"correctionExecutionService must not be null");
batchRunLauncher = Objects.requireNonNull(batchRunLauncher,
"batchRunLauncher must not be null");
miniRunLauncher = Objects.requireNonNull(miniRunLauncher,
"miniRunLauncher must not be null");
resetDocumentStatusPort = Objects.requireNonNull(resetDocumentStatusPort,
"resetDocumentStatusPort must not be null");
}
/**
* Backward-compatible constructor that fills the processing-run launcher with a
* no-op implementation.
* Backward-compatible constructor that fills the mini-run launcher and reset port
* with no-op implementations.
*
* @param initialState initial editor state; must not be {@code null}
* @param startupNotice optional startup notice; {@code null} becomes empty
* @param configurationFileLoader file-loading callback; must not be {@code null}
* @param configurationFileWriter file-writing callback; must not be {@code null}
* @param modelCatalogPort port for retrieving AI model lists; must not be {@code null}
* @param apiKeyResolutionPort port for resolving API key provenance; must not be {@code null}
* @param providerTechnicalTestService service for provider-specific technical checks; must not be {@code null}
* @param pathCheckPort port for filesystem path accessibility checks; must not be {@code null}
* @param technicalTestOrchestrator orchestrator for the full technical test run; must not be {@code null}
* @param correctionExecutionService service for executing confirmed corrective actions; must not be {@code null}
* @param batchRunLauncher bridge that executes a regular batch run; must not be {@code null}
*/
public GuiStartupContext(
GuiConfigurationEditorState initialState,
Optional<String> startupNotice,
GuiConfigurationFileLoader configurationFileLoader,
GuiConfigurationFileWriter configurationFileWriter,
AiModelCatalogPort modelCatalogPort,
ApiKeyResolutionPort apiKeyResolutionPort,
ProviderTechnicalTestService providerTechnicalTestService,
PathCheckPort pathCheckPort,
TechnicalTestOrchestrator technicalTestOrchestrator,
CorrectionExecutionService correctionExecutionService,
GuiBatchRunLauncher batchRunLauncher) {
this(initialState, startupNotice, configurationFileLoader, configurationFileWriter,
modelCatalogPort, apiKeyResolutionPort, providerTechnicalTestService, pathCheckPort,
technicalTestOrchestrator, correctionExecutionService, batchRunLauncher,
rejectingMiniRunLauncher(), rejectingResetPort());
}
/**
* Backward-compatible constructor that fills the processing-run launcher, mini-run
* launcher and reset port with no-op implementations.
* <p>
* Preserves existing callers that were written before the processing-run tab was added.
* The no-op launcher rejects every start request with a clear German message so the
* UI never enters an unsafe state in legacy test wiring.
*
* @param initialState initial editor state; must not be {@code null}
* @param startupNotice optional startup notice; {@code null} becomes empty
@@ -119,7 +167,7 @@ public record GuiStartupContext(
this(initialState, startupNotice, configurationFileLoader, configurationFileWriter,
modelCatalogPort, apiKeyResolutionPort, providerTechnicalTestService, pathCheckPort,
technicalTestOrchestrator, correctionExecutionService,
rejectingBatchRunLauncher());
rejectingBatchRunLauncher(), rejectingMiniRunLauncher(), rejectingResetPort());
}
private static GuiBatchRunLauncher rejectingBatchRunLauncher() {
@@ -127,20 +175,24 @@ public record GuiStartupContext(
"Kein Verarbeitungslauf-Launcher in diesem Startkontext verfügbar.");
}
private static GuiMiniRunLauncher rejectingMiniRunLauncher() {
return (configPath, filter, observer, token) -> GuiBatchRunLaunchOutcome.rejected(
"Kein Mini-Run-Launcher in diesem Startkontext verfügbar.");
}
private static GuiResetDocumentStatusPort rejectingResetPort() {
return (configPath, fingerprints) -> {
java.util.Map<DocumentFingerprint, String> failures = new java.util.HashMap<>();
for (DocumentFingerprint fp : fingerprints) {
failures.put(fp, "Kein Reset-Port in diesem Startkontext verfügbar.");
}
return new ResetDocumentStatusResult(fingerprints.size(), Set.of(), failures);
};
}
/**
* Creates a blank startup context with no loader or writer side effects, a no-op model
* catalogue port, a no-op API key resolution port, a no-op provider technical test service,
* a no-op path check port, a no-op technical test orchestrator, and a no-op
* correction execution service.
* Creates a blank startup context with no-op implementations for all ports and services.
* <p>
* The no-op model catalogue port always returns {@code IncompleteConfiguration}.
* The no-op API key resolution port always returns {@code ABSENT}.
* The no-op provider technical test service uses the no-op ports above.
* The no-op path check port always returns {@code false} for all checks.
* The no-op technical test orchestrator returns a report where all checkpoints are
* {@link de.gecheckt.pdf.umbenenner.application.validation.technicaltest.CheckpointResult.NotApplicable}.
* The no-op correction execution service uses a no-op {@link ResourceCreationPort} that always
* returns {@link de.gecheckt.pdf.umbenenner.application.validation.technicaltest.CorrectionOutcome.NotAttempted}.
* This is safe for environments where no Bootstrap wiring is present, such as isolated
* GUI tests.
*
@@ -208,6 +260,8 @@ public record GuiStartupContext(
noOpPathCheckPort,
noOpOrchestrator,
noOpCorrectionService,
noOpBatchRunLauncher);
noOpBatchRunLauncher,
rejectingMiniRunLauncher(),
rejectingResetPort());
}
}
@@ -5,6 +5,7 @@ import java.time.Duration;
import java.time.LocalDate;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
@@ -16,12 +17,15 @@ import org.apache.logging.log4j.Logger;
import de.gecheckt.pdf.umbenenner.application.port.in.BatchRunCancellationToken;
import de.gecheckt.pdf.umbenenner.application.port.in.BatchRunProgressObserver;
import de.gecheckt.pdf.umbenenner.application.port.in.DocumentCompletionEvent;
import de.gecheckt.pdf.umbenenner.application.port.in.ResetDocumentStatusResult;
import de.gecheckt.pdf.umbenenner.application.port.in.RunSummary;
import de.gecheckt.pdf.umbenenner.domain.model.DocumentFingerprint;
import de.gecheckt.pdf.umbenenner.domain.model.RunId;
import javafx.application.Platform;
/**
* Coordinates a single batch run triggered from the JavaFX GUI.
* Coordinates a single batch run (regular or targeted mini-run) triggered from the
* JavaFX GUI, and optional reset-only operations on selected document fingerprints.
* <p>
* The coordinator owns the background worker thread that executes the run, maintains the
* cancellation flag, and translates the
@@ -30,7 +34,7 @@ import javafx.application.Platform;
*
* <h2>Threading</h2>
* <ul>
* <li>The batch run executes on a daemon worker thread created by
* <li>The batch run and reset operations execute on a daemon worker thread created by
* {@link #threadFactory}. No JavaFX code touches this thread.</li>
* <li>Every GUI callback ({@link Listener}) is invoked on the JavaFX Application Thread
* via {@link Platform#runLater(Runnable)}, so listeners may freely mutate
@@ -42,12 +46,15 @@ import javafx.application.Platform;
*
* <h2>Lifecycle</h2>
* <ol>
* <li>Construct with a launcher, a thread factory and a listener.</li>
* <li>Call {@link #start(Path)} to begin a run against a configuration file.</li>
* <li>Optionally call {@link #requestCancellation()} to trigger soft-stop.</li>
* <li>Wait for {@link Listener#onRunEnded(RunSummary, GuiBatchRunLaunchOutcome)} on the
* FX thread.</li>
* <li>Start a new run only after the previous one has ended.</li>
* <li>Construct with a regular launcher, a mini-run launcher, a reset port, a thread
* factory and a listener.</li>
* <li>Call {@link #start(Path)} to begin a regular run, or
* {@link #startMiniRun(Path, Set)} for a targeted mini-run, or
* {@link #startReset(Path, Set)} for a status-reset-only operation.</li>
* <li>Optionally call {@link #requestCancellation()} to trigger soft-stop for runs.</li>
* <li>Wait for {@link Listener#onRunEnded(RunSummary, GuiBatchRunLaunchOutcome)} or
* {@link Listener#onResetCompleted(ResetDocumentStatusResult)} on the FX thread.</li>
* <li>Start a new operation only after the previous one has ended.</li>
* </ol>
*/
public final class GuiBatchRunCoordinator {
@@ -56,7 +63,7 @@ public final class GuiBatchRunCoordinator {
private static final String WORKER_THREAD_NAME = "gui-batch-run";
/**
* Listener interface invoked on the JavaFX Application Thread during a run.
* Listener interface invoked on the JavaFX Application Thread during a run or reset.
*/
public interface Listener {
@@ -84,9 +91,24 @@ public final class GuiBatchRunCoordinator {
* @param outcome a description of how the run terminated; never {@code null}
*/
void onRunEnded(RunSummary summary, GuiBatchRunLaunchOutcome outcome);
/**
* Invoked once after a reset-only operation has completed on the worker thread.
* <p>
* The default implementation does nothing so existing {@link Listener}
* implementations need not override this method until they need reset
* notifications.
*
* @param result the full outcome of the reset operation; never {@code null}
*/
default void onResetCompleted(ResetDocumentStatusResult result) {
// no-op default
}
}
private final GuiBatchRunLauncher launcher;
private final GuiMiniRunLauncher miniRunLauncher;
private final GuiResetDocumentStatusPort resetPort;
private final Function<Runnable, Thread> threadFactory;
private final Consumer<Runnable> fxDispatcher;
private final Listener listener;
@@ -96,12 +118,38 @@ public final class GuiBatchRunCoordinator {
/**
* Creates the coordinator with the default worker-thread factory and the default
* JavaFX Application Thread dispatcher.
* <p>
* Mini-run and reset capabilities are unavailable; all such requests will return
* {@code false}.
*
* @param launcher bridge to Bootstrap used to execute the batch; must not be null
* @param listener GUI listener invoked on the FX thread; must not be null
*/
public GuiBatchRunCoordinator(GuiBatchRunLauncher launcher, Listener listener) {
this(launcher, defaultThreadFactory(), defaultFxDispatcher(), listener);
this(launcher,
rejectingMiniRunLauncher(),
rejectingResetPort(),
defaultThreadFactory(),
defaultFxDispatcher(),
listener);
}
/**
* Creates the coordinator with all ports and the default worker-thread factory and
* JavaFX Application Thread dispatcher.
*
* @param launcher bridge to Bootstrap for regular batch runs; must not be null
* @param miniRunLauncher bridge to Bootstrap for targeted mini-runs; must not be null
* @param resetPort bridge to Bootstrap for status-reset-only operations; must
* not be null
* @param listener GUI listener invoked on the FX thread; must not be null
*/
public GuiBatchRunCoordinator(GuiBatchRunLauncher launcher,
GuiMiniRunLauncher miniRunLauncher,
GuiResetDocumentStatusPort resetPort,
Listener listener) {
this(launcher, miniRunLauncher, resetPort,
defaultThreadFactory(), defaultFxDispatcher(), listener);
}
/**
@@ -112,6 +160,34 @@ public final class GuiBatchRunCoordinator {
* thread UI callbacks run on, without depending on an actual JavaFX runtime being
* initialised.
*
* @param launcher bridge to Bootstrap for regular batch runs; must not be null
* @param miniRunLauncher bridge to Bootstrap for targeted mini-runs; must not be null
* @param resetPort bridge to Bootstrap for status-reset-only operations; must
* not be null
* @param threadFactory factory returning a ready-to-start worker thread; must not
* be null
* @param fxDispatcher dispatcher that schedules a runnable on the JavaFX Application
* Thread; must not be null
* @param listener GUI listener; must not be null
*/
public GuiBatchRunCoordinator(GuiBatchRunLauncher launcher,
GuiMiniRunLauncher miniRunLauncher,
GuiResetDocumentStatusPort resetPort,
Function<Runnable, Thread> threadFactory,
Consumer<Runnable> fxDispatcher,
Listener listener) {
this.launcher = Objects.requireNonNull(launcher, "launcher must not be null");
this.miniRunLauncher = Objects.requireNonNull(miniRunLauncher, "miniRunLauncher must not be null");
this.resetPort = Objects.requireNonNull(resetPort, "resetPort must not be null");
this.threadFactory = Objects.requireNonNull(threadFactory, "threadFactory must not be null");
this.fxDispatcher = Objects.requireNonNull(fxDispatcher, "fxDispatcher must not be null");
this.listener = Objects.requireNonNull(listener, "listener must not be null");
}
/**
* Legacy constructor retained for backward compatibility with tests that do not
* require mini-run or reset capabilities.
*
* @param launcher bridge to Bootstrap; must not be null
* @param threadFactory factory returning a ready-to-start worker thread; must not
* be null
@@ -123,16 +199,18 @@ public final class GuiBatchRunCoordinator {
Function<Runnable, Thread> threadFactory,
Consumer<Runnable> fxDispatcher,
Listener listener) {
this.launcher = Objects.requireNonNull(launcher, "launcher must not be null");
this.threadFactory = Objects.requireNonNull(threadFactory, "threadFactory must not be null");
this.fxDispatcher = Objects.requireNonNull(fxDispatcher, "fxDispatcher must not be null");
this.listener = Objects.requireNonNull(listener, "listener must not be null");
this(launcher,
rejectingMiniRunLauncher(),
rejectingResetPort(),
threadFactory,
fxDispatcher,
listener);
}
/**
* Returns whether a run is currently active.
* Returns whether a run or reset is currently active.
*
* @return {@code true} while a worker thread is processing a run
* @return {@code true} while a worker thread is executing
*/
public boolean isRunning() {
Thread worker = activeWorker.get();
@@ -140,7 +218,7 @@ public final class GuiBatchRunCoordinator {
}
/**
* Starts a new run for the supplied configuration file.
* Starts a new regular run for the supplied configuration file.
* <p>
* Immediately returns once the worker thread has been started. All further progress
* is communicated through the configured {@link Listener} on the JavaFX Application
@@ -160,19 +238,71 @@ public final class GuiBatchRunCoordinator {
}
cancellationRequested.set(false);
Runnable task = () -> executeRun(configFilePath);
Thread worker = threadFactory.apply(task);
Objects.requireNonNull(worker, "threadFactory must not return null");
activeWorker.set(worker);
worker.start();
return true;
return startWorker(task);
}
/**
* Requests soft-stop cancellation of the currently running batch.
* Starts a targeted mini-run for the supplied fingerprint filter.
* <p>
* The worker thread first delegates to the {@link GuiMiniRunLauncher} which applies
* the full processing pipeline to only the specified documents. Progress callbacks
* are forwarded to the {@link Listener} on the JavaFX Application Thread in the same
* way as for a regular run.
*
* @param configFilePath the configuration file; must not be {@code null}
* @param fingerprintFilter the set of document fingerprints to process; must not be
* {@code null}
* @return {@code true} when a new worker thread was started, {@code false} when a run
* was already in progress
* @throws NullPointerException if any argument is {@code null}
*/
public boolean startMiniRun(Path configFilePath,
Set<DocumentFingerprint> fingerprintFilter) {
Objects.requireNonNull(configFilePath, "configFilePath must not be null");
Objects.requireNonNull(fingerprintFilter, "fingerprintFilter must not be null");
if (isRunning()) {
return false;
}
cancellationRequested.set(false);
Runnable task = () -> executeMiniRun(configFilePath, fingerprintFilter);
return startWorker(task);
}
/**
* Starts a reset-only operation for the supplied fingerprint set.
* <p>
* The worker thread calls the {@link GuiResetDocumentStatusPort} to delete all
* persistence data for the specified fingerprints. No reprocessing run is triggered.
* On completion the {@link Listener#onResetCompleted(ResetDocumentStatusResult)} callback
* is invoked on the JavaFX Application Thread.
*
* @param configFilePath the configuration file that identifies the database; must not
* be {@code null}
* @param fingerprints the set of document fingerprints to reset; must not be
* {@code null}
* @return {@code true} when a new worker thread was started, {@code false} when a run
* was already in progress
* @throws NullPointerException if any argument is {@code null}
*/
public boolean startReset(Path configFilePath, Set<DocumentFingerprint> fingerprints) {
Objects.requireNonNull(configFilePath, "configFilePath must not be null");
Objects.requireNonNull(fingerprints, "fingerprints must not be null");
if (isRunning()) {
return false;
}
// Reset does not support cancellation; set the flag to false so the
// running state is consistent with the pattern used by run operations.
cancellationRequested.set(false);
Runnable task = () -> executeReset(configFilePath, fingerprints);
return startWorker(task);
}
/**
* Requests soft-stop cancellation of the currently running batch or mini-run.
* <p>
* The flag is honoured between candidates — the candidate that is currently being
* processed is always completed in full and persisted before the run ends. Calling
* this method when no run is active has no effect.
* this method when no run is active has no effect. Reset operations ignore this flag.
*/
public void requestCancellation() {
if (isRunning()) {
@@ -190,6 +320,18 @@ public final class GuiBatchRunCoordinator {
return cancellationRequested.get();
}
// -------------------------------------------------------------------------
// Worker helpers
// -------------------------------------------------------------------------
private boolean startWorker(Runnable task) {
Thread worker = threadFactory.apply(task);
Objects.requireNonNull(worker, "threadFactory must not return null");
activeWorker.set(worker);
worker.start();
return true;
}
private void executeRun(Path configFilePath) {
LOG.info("GUI-Verarbeitungslauf: Worker-Thread gestartet für Konfiguration {}.",
configFilePath);
@@ -210,6 +352,58 @@ public final class GuiBatchRunCoordinator {
"Unerwarteter technischer Fehler: "
+ (e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage()));
}
finishRun(outcome);
}
private void executeMiniRun(Path configFilePath, Set<DocumentFingerprint> fingerprintFilter) {
LOG.info("GUI-Mini-Verarbeitungslauf: Worker-Thread gestartet für {} Dokument(e), "
+ "Konfiguration {}.", fingerprintFilter.size(), configFilePath);
observerSummary.set(null);
BatchRunProgressObserver observer = buildDispatchingObserver();
BatchRunCancellationToken token = cancellationRequested::get;
GuiBatchRunLaunchOutcome outcome;
try {
outcome = miniRunLauncher.launch(configFilePath, fingerprintFilter, observer, token);
if (outcome == null) {
outcome = GuiBatchRunLaunchOutcome.failedAfterStart(
"Mini-Run-Launcher hat kein Ergebnis geliefert.");
}
} catch (RuntimeException e) {
LOG.error("GUI-Mini-Verarbeitungslauf: Unerwarteter Fehler im Worker-Thread: {}",
e.getMessage(), e);
outcome = GuiBatchRunLaunchOutcome.failedAfterStart(
"Unerwarteter technischer Fehler im Mini-Lauf: "
+ (e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage()));
}
finishRun(outcome);
}
private void executeReset(Path configFilePath, Set<DocumentFingerprint> fingerprints) {
LOG.info("GUI-Status-Reset: Worker-Thread gestartet für {} Dokument(e), "
+ "Konfiguration {}.", fingerprints.size(), configFilePath);
ResetDocumentStatusResult result;
try {
result = resetPort.reset(configFilePath, fingerprints);
if (result == null) {
result = new ResetDocumentStatusResult(fingerprints.size(),
Set.of(), allFailureMap(fingerprints,
"Reset-Port hat kein Ergebnis geliefert."));
}
} catch (RuntimeException e) {
LOG.error("GUI-Status-Reset: Unerwarteter Fehler im Worker-Thread: {}",
e.getMessage(), e);
String msg = "Unerwarteter technischer Fehler beim Status-Reset: "
+ (e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage());
result = new ResetDocumentStatusResult(fingerprints.size(),
Set.of(), allFailureMap(fingerprints, msg));
}
ResetDocumentStatusResult finalResult = result;
activeWorker.set(null);
fxDispatcher.accept(() -> listener.onResetCompleted(finalResult));
LOG.info("GUI-Status-Reset: Worker-Thread beendet.");
}
private void finishRun(GuiBatchRunLaunchOutcome outcome) {
RunSummary summary = observerSummary.get();
if (summary == null) {
summary = new RunSummary(0, 0, 0);
@@ -221,6 +415,15 @@ public final class GuiBatchRunCoordinator {
LOG.info("GUI-Verarbeitungslauf: Worker-Thread beendet.");
}
private static java.util.Map<DocumentFingerprint, String> allFailureMap(
Set<DocumentFingerprint> fingerprints, String message) {
java.util.Map<DocumentFingerprint, String> map = new java.util.HashMap<>();
for (DocumentFingerprint fp : fingerprints) {
map.put(fp, message);
}
return map;
}
/**
* Captures the final summary supplied by the application layer. Written on the
* worker thread; read only after the run has ended.
@@ -244,7 +447,7 @@ public final class GuiBatchRunCoordinator {
public void onRunEnded(RunSummary summary) {
observerSummary.set(summary);
// No FX dispatch here: the worker thread invokes the listener's
// onRunEnded via executeRun() once the launcher has returned, ensuring
// onRunEnded via finishRun() once the launcher has returned, ensuring
// the outcome carries the launcher's terminal verdict.
}
};
@@ -260,6 +463,7 @@ public final class GuiBatchRunCoordinator {
Duration duration = event.processingDuration();
return new GuiBatchRunResultRow(
event.originalFileName(),
event.fingerprint(),
event.status(),
finalName,
date,
@@ -278,4 +482,26 @@ public final class GuiBatchRunCoordinator {
private static Consumer<Runnable> defaultFxDispatcher() {
return Platform::runLater;
}
private static GuiMiniRunLauncher rejectingMiniRunLauncher() {
return (configFilePath, fingerprintFilter, observer, cancellationToken) ->
GuiBatchRunLaunchOutcome.rejected(
"Kein Mini-Run-Launcher in diesem Kontext verfügbar.");
}
private static GuiResetDocumentStatusPort rejectingResetPort() {
return (configFilePath, fingerprints) ->
new ResetDocumentStatusResult(fingerprints.size(),
Set.of(), allFailureMapStatic(fingerprints,
"Kein Reset-Port in diesem Kontext verfügbar."));
}
private static java.util.Map<DocumentFingerprint, String> allFailureMapStatic(
Set<DocumentFingerprint> fingerprints, String message) {
java.util.Map<DocumentFingerprint, String> map = new java.util.HashMap<>();
for (DocumentFingerprint fp : fingerprints) {
map.put(fp, message);
}
return map;
}
}
@@ -6,6 +6,7 @@ import java.util.Objects;
import java.util.Optional;
import de.gecheckt.pdf.umbenenner.application.port.in.DocumentCompletionStatus;
import de.gecheckt.pdf.umbenenner.domain.model.DocumentFingerprint;
/**
* Immutable view model for a single row in the processing-run result list.
@@ -14,32 +15,57 @@ import de.gecheckt.pdf.umbenenner.application.port.in.DocumentCompletionStatus;
* that is shown in the list and the side panel; it is decoupled from the persistence
* model so later GUI layers can render it without reaching back into the application
* layer.
* <p>
* The {@code fingerprint} field is the content-based identity of the document and is
* used as a stable key for in-place row updates during a targeted mini-run.
* <p>
* When {@code resetPending} is {@code true} the row represents a document whose
* persistence status has been deleted but which has not yet been reprocessed. The status
* icon and label reflect this special state instead of the original processing outcome.
*
* @param originalFileName the source filename as reported by the use case; never
* {@code null} or blank
* @param status the aggregated completion status; never {@code null}
* @param finalFileName the final target filename when the row represents a successful
* rename; empty otherwise
* @param resolvedDate the resolved document date when the row represents a successful
* rename; empty otherwise
* @param aiReasoning the AI reasoning shown in the side panel; empty when no
* reasoning is available for this row
* @param originalFileName the source filename as reported by the use case; never
* {@code null} or blank
* @param fingerprint the content-based identity of the processed document; never
* {@code null}
* @param status the aggregated completion status; never {@code null}
* @param finalFileName the final target filename when the row represents a successful
* rename; empty otherwise
* @param resolvedDate the resolved document date when the row represents a successful
* rename; empty otherwise
* @param aiReasoning the AI reasoning shown in the side panel; empty when no
* reasoning is available for this row
* @param processingDuration wall-clock duration spent on the candidate in this run;
* never {@code null} and never negative
* never {@code null} and never negative
* @param resetPending {@code true} when the document's persistence status has been
* reset and is awaiting the next processing run
*/
public record GuiBatchRunResultRow(
String originalFileName,
DocumentFingerprint fingerprint,
DocumentCompletionStatus status,
Optional<String> finalFileName,
Optional<LocalDate> resolvedDate,
Optional<String> aiReasoning,
Duration processingDuration) {
Duration processingDuration,
boolean resetPending) {
/**
* Label shown in the status column when a document's persistence status has been
* reset and is waiting for the next processing run.
*/
static final String RESET_PENDING_LABEL = "Zurückgesetzt wartet auf nächsten Lauf";
/**
* Icon shown in the status column when a document's persistence status has been reset.
*/
static final String RESET_PENDING_ICON = "\u27F3"; // ⟳ CLOCKWISE GAPPED CIRCLE ARROW
/**
* Compact constructor normalising optional holders and validating mandatory fields.
*
* @throws NullPointerException if {@code originalFileName}, {@code status} or
* {@code processingDuration} is {@code null}
* @throws NullPointerException if {@code originalFileName}, {@code fingerprint},
* {@code status} or {@code processingDuration} is
* {@code null}
* @throws IllegalArgumentException if {@code originalFileName} is blank or
* {@code processingDuration} is negative
*/
@@ -48,6 +74,7 @@ public record GuiBatchRunResultRow(
if (originalFileName.isBlank()) {
throw new IllegalArgumentException("originalFileName must not be blank");
}
Objects.requireNonNull(fingerprint, "fingerprint must not be null");
Objects.requireNonNull(status, "status must not be null");
finalFileName = finalFileName == null ? Optional.empty() : finalFileName;
resolvedDate = resolvedDate == null ? Optional.empty() : resolvedDate;
@@ -59,17 +86,93 @@ public record GuiBatchRunResultRow(
}
/**
* Returns the status icon for this row as a Basic Multilingual Plane character
* that renders reliably in JavaFX on Windows.
* Convenience constructor for rows that are not in the reset-pending state.
*
* @param originalFileName the source filename; never {@code null} or blank
* @param fingerprint the content-based document identity; never {@code null}
* @param status the aggregated completion status; never {@code null}
* @param finalFileName the final target filename; may be {@code null} (treated as
* empty)
* @param resolvedDate the resolved document date; may be {@code null} (treated as
* empty)
* @param aiReasoning the AI reasoning text; may be {@code null} (treated as
* empty)
* @param processingDuration the wall-clock processing duration; never {@code null}
*/
public GuiBatchRunResultRow(
String originalFileName,
DocumentFingerprint fingerprint,
DocumentCompletionStatus status,
Optional<String> finalFileName,
Optional<LocalDate> resolvedDate,
Optional<String> aiReasoning,
Duration processingDuration) {
this(originalFileName, fingerprint, status, finalFileName, resolvedDate, aiReasoning,
processingDuration, false);
}
/**
* Creates a reset-pending copy of the supplied row, preserving the original filename
* and fingerprint while marking the row as awaiting the next processing run.
* <p>
* The returned row has {@code resetPending == true}. Its {@code statusIcon()} and
* {@code statusLabel()} reflect the reset state.
*
* @param previousRow the row to copy; must not be {@code null}
* @return a new row with the same filename and fingerprint, {@code resetPending == true}
* @throws NullPointerException if {@code previousRow} is {@code null}
*/
public static GuiBatchRunResultRow resetMarker(GuiBatchRunResultRow previousRow) {
Objects.requireNonNull(previousRow, "previousRow must not be null");
return new GuiBatchRunResultRow(
previousRow.originalFileName(),
previousRow.fingerprint(),
previousRow.status(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Duration.ZERO,
true);
}
/**
* Returns the status icon for this row as a Unicode character that renders reliably
* in JavaFX on Windows.
* <p>
* When {@code resetPending} is {@code true} the reset icon is returned regardless of
* the underlying status.
*
* @return the corresponding status character
*/
public String statusIcon() {
if (resetPending) {
return RESET_PENDING_ICON;
}
return switch (status) {
case SUCCESS -> "\u2714"; // ✔ HEAVY CHECK MARK
case FAILED_RETRYABLE -> "\u26A0"; // ⚠ WARNING SIGN (no variation selector)
case SUCCESS -> "\u2714"; // ✔ HEAVY CHECK MARK
case FAILED_RETRYABLE -> "\u26A0"; // ⚠ WARNING SIGN
case FAILED_PERMANENT -> "\u2718"; // ✘ HEAVY BALLOT X
case SKIPPED -> "\u25BA"; // ► BLACK RIGHT-POINTING POINTER
};
}
/**
* Returns the human-readable status label for this row.
* <p>
* When {@code resetPending} is {@code true} the reset-pending label is returned
* regardless of the underlying status.
*
* @return a non-null German status label
*/
public String statusLabel() {
if (resetPending) {
return RESET_PENDING_LABEL;
}
return switch (status) {
case SUCCESS -> "Erfolgreich";
case FAILED_RETRYABLE -> "Fehlgeschlagen (wiederholbar)";
case FAILED_PERMANENT -> "Fehlgeschlagen (permanent)";
case SKIPPED -> "Übersprungen";
};
}
}
@@ -3,28 +3,40 @@ package de.gecheckt.pdf.umbenenner.adapter.in.gui.batchrun;
import java.nio.file.Path;
import java.time.Duration;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import de.gecheckt.pdf.umbenenner.application.port.in.DocumentCompletionStatus;
import de.gecheckt.pdf.umbenenner.application.port.in.ResetDocumentStatusResult;
import de.gecheckt.pdf.umbenenner.application.port.in.RunSummary;
import de.gecheckt.pdf.umbenenner.domain.model.DocumentFingerprint;
import de.gecheckt.pdf.umbenenner.domain.model.RunId;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.ReadOnlyBooleanWrapper;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.ObservableSet;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.Tab;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
@@ -44,6 +56,11 @@ import javafx.scene.layout.VBox;
* inside the GUI. It collaborates with a {@link GuiBatchRunCoordinator} which owns the
* background worker thread and forwards progress callbacks here on the JavaFX Application
* Thread.
* <p>
* After a run completes, the user may select one or more rows and trigger either
* "Erneut verarbeiten" (reset + immediate mini-run for selected documents) or
* "Status zurücksetzen" (reset only, for reprocessing in the next regular run).
* Selection is locked while any run or reset is active.
*
* <h2>Layout</h2>
* <pre>
@@ -51,8 +68,10 @@ import javafx.scene.layout.VBox;
* │ [Fortschrittsbalken] 12 / 47 Dateien │
* ├──────────────────────────────────┬───────────────────┤
* │ Ergebnisliste │ Seitenbereich │
* │ (TableView) │ (Reasoning) │
* │ (TableView mit Checkbox-Spalte) │ (Reasoning) │
* ├──────────────────────────────────┴───────────────────┤
* │ [Erneut verarbeiten] [Status zurücksetzen] │
* ├──────────────────────────────────────────────────────┤
* │ Meldungs- und Zusammenfassungsbereich │
* ├──────────────────────────────────────────────────────┤
* │ [Starten] [Abbrechen] │
@@ -95,6 +114,7 @@ public final class GuiBatchRunTab {
private static final double DETAIL_PANE_MIN_WIDTH = 280;
private static final double LIST_MIN_HEIGHT = 240;
private static final double DETAIL_AREA_MIN_HEIGHT = 240;
private static final double CHECKBOX_COL_WIDTH = 40;
private static final int SECONDARY_SPACING = 12;
private final Tab tab = new Tab(TAB_TITLE);
@@ -102,10 +122,45 @@ public final class GuiBatchRunTab {
private final Label counterLabel = new Label("0 / 0 Dateien");
private final TableView<GuiBatchRunResultRow> resultTable = new TableView<>();
private final ObservableList<GuiBatchRunResultRow> resultItems = FXCollections.observableArrayList();
/**
* {@code true} when the active run is a targeted mini-run rather than a regular batch
* run. Used to decide whether {@link #onDocumentCompleted} should update rows in-place
* (mini-run) or always append new rows (regular run).
*/
private boolean activeRunIsMiniRun = false;
/**
* Snapshot of fingerprints selected at mini-run start, mapped to their original
* filenames. Used to synthesize failure rows for source files that have disappeared
* between selection and processing.
*/
private Map<DocumentFingerprint, String> miniRunSnapshotFilenames = Map.of();
/**
* Fingerprints that received an {@code onDocumentCompleted} callback during the
* current mini-run. Used to detect selected documents that the use case silently
* skipped because their source file no longer exists.
*/
private Set<DocumentFingerprint> miniRunCompletedFingerprints = new HashSet<>();
/**
* Logical selection set membership defines which rows are "checked". Both the
* TableView row selection model and the per-row checkboxes stay synchronised with
* this set on the FX thread.
*/
private final ObservableSet<GuiBatchRunResultRow> selectedRows =
FXCollections.observableSet();
/**
* When {@code true} selection-change listeners do not propagate back and forth,
* preventing feedback loops during programmatic synchronisation.
*/
private boolean selectionSyncInProgress = false;
/** Master checkbox in the checkbox column header — tri-state. */
private final CheckBox masterCheckBox = new CheckBox();
private final TextArea detailArea = new TextArea(DETAIL_PLACEHOLDER);
private final TextArea messageArea = new TextArea();
private final Button startButton = new Button("Starten");
private final Button cancelButton = new Button("Abbrechen");
private final Button reprocessButton = new Button("Erneut verarbeiten");
private final Button resetStatusButton = new Button("Status zurücksetzen");
private final ReadOnlyBooleanWrapper runningProperty = new ReadOnlyBooleanWrapper(false);
private final Supplier<Path> configPathSupplier;
@@ -120,11 +175,19 @@ public final class GuiBatchRunTab {
private int skippedCount;
/**
* Creates the processing-run tab and wires all UI controls.
* Creates the processing-run tab with all processing, mini-run and reset capabilities,
* and wires all UI controls.
*
* @param launcherSupplier supplier returning the active
* {@link GuiBatchRunLauncher}; called when the
* user presses "Starten"; must not be null
* @param miniRunLauncherSupplier supplier returning the active
* {@link GuiMiniRunLauncher}; called when the user
* presses "Erneut verarbeiten"; must not be null
* @param resetPortSupplier supplier returning the active
* {@link GuiResetDocumentStatusPort}; called when
* the user presses either selection-action button;
* must not be null
* @param configPathSupplier supplier returning the last saved configuration
* path to run against; may return {@code null}
* when no configuration is loaded
@@ -134,15 +197,18 @@ public final class GuiBatchRunTab {
* edit has made it unusable; must not be null
* @param onRunStateChanged callback invoked on the FX thread whenever the
* running flag flips; typically used by the
* workspace to sperren/entsperren Tab 1 and to
* rewire the close-request handler; must not be
* null
* workspace to lock/unlock Tab 1 and to rewire the
* close-request handler; must not be null
*/
public GuiBatchRunTab(Supplier<GuiBatchRunLauncher> launcherSupplier,
Supplier<GuiMiniRunLauncher> miniRunLauncherSupplier,
Supplier<GuiResetDocumentStatusPort> resetPortSupplier,
Supplier<Path> configPathSupplier,
BooleanSupplier savedConfigurationReadyCheck,
Runnable onRunStateChanged) {
Objects.requireNonNull(launcherSupplier, "launcherSupplier must not be null");
Objects.requireNonNull(miniRunLauncherSupplier, "miniRunLauncherSupplier must not be null");
Objects.requireNonNull(resetPortSupplier, "resetPortSupplier must not be null");
this.configPathSupplier = Objects.requireNonNull(configPathSupplier, "configPathSupplier must not be null");
this.savedConfigurationReadyCheck = Objects.requireNonNull(
savedConfigurationReadyCheck, "savedConfigurationReadyCheck must not be null");
@@ -151,6 +217,10 @@ public final class GuiBatchRunTab {
this.coordinator = new GuiBatchRunCoordinator(
(configPath, observer, token) ->
launcherSupplier.get().launch(configPath, observer, token),
(configPath, filter, observer, token) ->
miniRunLauncherSupplier.get().launch(configPath, filter, observer, token),
(configPath, fingerprints) ->
resetPortSupplier.get().reset(configPath, fingerprints),
new CoordinatorListener());
this.tab.setClosable(false);
this.tab.setContent(buildContent());
@@ -159,6 +229,35 @@ public final class GuiBatchRunTab {
updateButtonStates();
}
/**
* Backward-compatible constructor for callers that do not need mini-run or reset
* capabilities.
*
* @param launcherSupplier supplier returning the active
* {@link GuiBatchRunLauncher}; must not be null
* @param configPathSupplier supplier returning the last saved configuration
* path; may return {@code null}
* @param savedConfigurationReadyCheck check before each start attempt; must not be
* null
* @param onRunStateChanged callback when the running flag flips; must not
* be null
*/
public GuiBatchRunTab(Supplier<GuiBatchRunLauncher> launcherSupplier,
Supplier<Path> configPathSupplier,
BooleanSupplier savedConfigurationReadyCheck,
Runnable onRunStateChanged) {
this(launcherSupplier,
() -> GuiBatchRunTab::rejectingMiniLaunch,
() -> GuiBatchRunTab::rejectingReset,
configPathSupplier,
savedConfigurationReadyCheck,
onRunStateChanged);
}
// -------------------------------------------------------------------------
// Public API
// -------------------------------------------------------------------------
/**
* Returns the JavaFX {@link Tab} node that hosts the processing-run view.
*
@@ -197,45 +296,49 @@ public final class GuiBatchRunTab {
cancelButton.setDisable(true);
}
/** Visible for tests. */
Button startButton() {
return startButton;
}
// -------------------------------------------------------------------------
// Package-private accessors for tests
// -------------------------------------------------------------------------
/** Visible for tests. */
Button cancelButton() {
return cancelButton;
}
Button startButton() { return startButton; }
/** Visible for tests. */
ProgressBar progressBar() {
return progressBar;
}
Button cancelButton() { return cancelButton; }
/** Visible for tests. */
TableView<GuiBatchRunResultRow> resultTable() {
return resultTable;
}
Button reprocessButton() { return reprocessButton; }
/** Visible for tests. */
TextArea messageArea() {
return messageArea;
}
Button resetStatusButton() { return resetStatusButton; }
/** Visible for tests. */
TextArea detailArea() {
return detailArea;
}
ProgressBar progressBar() { return progressBar; }
/** Visible for tests. */
Label counterLabel() {
return counterLabel;
}
TableView<GuiBatchRunResultRow> resultTable() { return resultTable; }
/** Visible for tests. */
GuiBatchRunCoordinator coordinator() {
return coordinator;
}
TextArea messageArea() { return messageArea; }
/** Visible for tests. */
TextArea detailArea() { return detailArea; }
/** Visible for tests. */
Label counterLabel() { return counterLabel; }
/** Visible for tests. */
GuiBatchRunCoordinator coordinator() { return coordinator; }
/** Visible for tests. */
ObservableSet<GuiBatchRunResultRow> selectedRows() { return selectedRows; }
/** Visible for tests. */
CheckBox masterCheckBox() { return masterCheckBox; }
// -------------------------------------------------------------------------
// Layout builders
// -------------------------------------------------------------------------
private BorderPane buildContent() {
BorderPane layout = new BorderPane();
@@ -292,6 +395,22 @@ public final class GuiBatchRunTab {
resultTable.setItems(resultItems);
resultTable.setId("batch-run-result-table");
resultTable.setPlaceholder(new Label("Noch kein Verarbeitungslauf gestartet."));
resultTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
// Checkbox column with master-checkbox header
TableColumn<GuiBatchRunResultRow, Void> checkboxCol = new TableColumn<>();
checkboxCol.setId("batch-run-checkbox-col");
checkboxCol.setPrefWidth(CHECKBOX_COL_WIDTH);
checkboxCol.setMaxWidth(CHECKBOX_COL_WIDTH);
checkboxCol.setResizable(false);
checkboxCol.setSortable(false);
masterCheckBox.setId("batch-run-master-checkbox");
masterCheckBox.setOnAction(e -> handleMasterCheckBoxAction());
checkboxCol.setGraphic(masterCheckBox);
checkboxCol.setCellFactory(col -> new CheckBoxCell());
checkboxCol.setEditable(true);
TableColumn<GuiBatchRunResultRow, String> iconCol = new TableColumn<>("Status");
iconCol.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().statusIcon()));
@@ -308,8 +427,12 @@ public final class GuiBatchRunTab {
setText(icon);
TableRow<GuiBatchRunResultRow> tableRow = getTableRow();
GuiBatchRunResultRow data = tableRow != null ? tableRow.getItem() : null;
String color = data != null ? statusColor(data.status()) : "#000000";
setStyle("-fx-text-fill: " + color + "; -fx-alignment: CENTER; -fx-font-size: 14;");
if (data != null && data.resetPending()) {
setStyle("-fx-text-fill: #1565c0; -fx-alignment: CENTER; -fx-font-size: 14;");
} else {
String color = data != null ? statusColor(data.status()) : "#000000";
setStyle("-fx-text-fill: " + color + "; -fx-alignment: CENTER; -fx-font-size: 14;");
}
}
});
@@ -318,8 +441,13 @@ public final class GuiBatchRunTab {
nameCol.setPrefWidth(280);
TableColumn<GuiBatchRunResultRow, String> newNameCol = new TableColumn<>("Neuer Dateiname");
newNameCol.setCellValueFactory(data -> new SimpleStringProperty(
data.getValue().finalFileName().orElse(EMPTY_CELL_TEXT)));
newNameCol.setCellValueFactory(data -> {
GuiBatchRunResultRow row = data.getValue();
if (row.resetPending()) {
return new SimpleStringProperty(GuiBatchRunResultRow.RESET_PENDING_LABEL);
}
return new SimpleStringProperty(row.finalFileName().orElse(EMPTY_CELL_TEXT));
});
newNameCol.setPrefWidth(280);
TableColumn<GuiBatchRunResultRow, String> dateCol = new TableColumn<>("Datum");
@@ -342,10 +470,26 @@ public final class GuiBatchRunTab {
}
});
List<TableColumn<GuiBatchRunResultRow, String>> columns =
List.of(iconCol, nameCol, newNameCol, dateCol, durationCol);
resultTable.getColumns().setAll(columns);
resultTable.getColumns().setAll(
checkboxCol, iconCol, nameCol, newNameCol, dateCol, durationCol);
// When the table's selection model changes, synchronise selectedRows and checkboxes.
resultTable.getSelectionModel().getSelectedItems().addListener(
(javafx.collections.ListChangeListener<GuiBatchRunResultRow>) change -> {
if (selectionSyncInProgress) return;
if (runningProperty.get()) return;
selectionSyncInProgress = true;
try {
selectedRows.clear();
selectedRows.addAll(
resultTable.getSelectionModel().getSelectedItems());
updateMasterCheckBox();
} finally {
selectionSyncInProgress = false;
}
});
// Detail pane update on row click.
resultTable.getSelectionModel().selectedItemProperty().addListener((obs, old, row) -> {
if (row == null) {
detailArea.setText(DETAIL_PLACEHOLDER);
@@ -353,46 +497,137 @@ public final class GuiBatchRunTab {
}
detailArea.setText(buildDetailText(row));
});
// Observe resultItems size to keep master checkbox state accurate.
resultItems.addListener(
(javafx.collections.ListChangeListener<GuiBatchRunResultRow>) change ->
updateMasterCheckBox());
// Any selection-set change re-evaluates the selection-action button enablement
// so "Erneut verarbeiten" and "Status zurücksetzen" reflect the current selection.
selectedRows.addListener(
(javafx.collections.SetChangeListener<GuiBatchRunResultRow>) change ->
updateButtonStates());
}
private static String statusColor(DocumentCompletionStatus status) {
return switch (status) {
case SUCCESS -> "#2e7d32";
case FAILED_RETRYABLE -> "#e65100";
case FAILED_PERMANENT -> "#c62828";
case SKIPPED -> "#757575";
};
}
/**
* Custom TableCell that renders a {@link CheckBox} in each data row and keeps it
* synchronised with {@link #selectedRows}.
*/
private final class CheckBoxCell extends TableCell<GuiBatchRunResultRow, Void> {
private static String formatDuration(Duration duration) {
double seconds = duration.toMillis() / 1000.0;
if (seconds < 10) {
return String.format("%.2f s", seconds);
private final CheckBox checkBox = new CheckBox();
CheckBoxCell() {
checkBox.setOnAction(e -> {
if (selectionSyncInProgress) return;
if (runningProperty.get()) {
// Revert: do not allow selection changes during a run.
GuiBatchRunResultRow item = getTableRow() != null
? getTableRow().getItem() : null;
if (item != null) {
checkBox.setSelected(selectedRows.contains(item));
}
return;
}
selectionSyncInProgress = true;
try {
GuiBatchRunResultRow item = getTableRow() != null ? getTableRow().getItem() : null;
if (item == null) return;
if (checkBox.isSelected()) {
selectedRows.add(item);
resultTable.getSelectionModel().select(item);
} else {
selectedRows.remove(item);
resultTable.getSelectionModel().clearSelection(
resultTable.getItems().indexOf(item));
}
updateMasterCheckBox();
} finally {
selectionSyncInProgress = false;
}
});
setGraphic(checkBox);
}
@Override
protected void updateItem(Void item, boolean empty) {
super.updateItem(item, empty);
if (empty || getTableRow() == null || getTableRow().getItem() == null) {
setGraphic(null);
return;
}
GuiBatchRunResultRow row = getTableRow().getItem();
checkBox.setSelected(selectedRows.contains(row));
checkBox.setDisable(runningProperty.get());
setGraphic(checkBox);
}
return String.format("%.1f s", seconds);
}
private static String buildDetailText(GuiBatchRunResultRow row) {
StringBuilder builder = new StringBuilder();
builder.append("Originaldateiname: ").append(row.originalFileName()).append('\n');
row.finalFileName()
.ifPresent(name -> builder.append("Neuer Dateiname: ").append(name).append('\n'));
row.resolvedDate()
.ifPresent(date -> builder.append("Datum: ")
.append(DateTimeFormatter.ISO_LOCAL_DATE.format(date)).append('\n'));
builder.append('\n');
row.aiReasoning().ifPresentOrElse(
reasoning -> builder.append(reasoning),
() -> builder.append(NO_REASONING_TEXT));
return builder.toString();
// -------------------------------------------------------------------------
// Selection helpers
// -------------------------------------------------------------------------
private void updateMasterCheckBox() {
int total = resultItems.size();
int selected = selectedRows.size();
if (total == 0 || selected == 0) {
masterCheckBox.setSelected(false);
masterCheckBox.setIndeterminate(false);
} else if (selected == total) {
masterCheckBox.setIndeterminate(false);
masterCheckBox.setSelected(true);
} else {
masterCheckBox.setIndeterminate(true);
}
}
private void handleMasterCheckBoxAction() {
if (runningProperty.get()) {
// Revert: do not allow during a run.
updateMasterCheckBox();
return;
}
selectionSyncInProgress = true;
try {
boolean selectAll = !masterCheckBox.isIndeterminate() && masterCheckBox.isSelected();
if (selectAll) {
resultTable.getSelectionModel().selectAll();
selectedRows.addAll(resultItems);
} else {
resultTable.getSelectionModel().clearSelection();
selectedRows.clear();
}
masterCheckBox.setIndeterminate(false);
masterCheckBox.setSelected(selectAll);
} finally {
selectionSyncInProgress = false;
}
resultTable.refresh();
}
// -------------------------------------------------------------------------
// Footer / button bar
// -------------------------------------------------------------------------
private Region buildFooter() {
messageArea.setId("batch-run-message-area");
messageArea.setEditable(false);
messageArea.setWrapText(true);
messageArea.setPrefRowCount(3);
// Selection-action buttons
reprocessButton.setId("batch-run-reprocess");
reprocessButton.setOnAction(event -> handleReprocessSelected());
resetStatusButton.setId("batch-run-reset-status");
resetStatusButton.setOnAction(event -> handleResetSelected());
HBox selectionButtonBar = new HBox(SECONDARY_SPACING, reprocessButton, resetStatusButton);
selectionButtonBar.setAlignment(Pos.CENTER_LEFT);
selectionButtonBar.setPadding(new Insets(SECONDARY_SPACING, 0, 0, 0));
// Run control buttons
startButton.setId("batch-run-start");
startButton.setOnAction(event -> handleStart());
@@ -400,14 +635,18 @@ public final class GuiBatchRunTab {
cancelButton.setOnAction(event -> requestCancellation());
cancelButton.setDisable(true);
HBox buttonBar = new HBox(SECONDARY_SPACING, startButton, cancelButton);
buttonBar.setAlignment(Pos.CENTER_LEFT);
buttonBar.setPadding(new Insets(SECONDARY_SPACING, 0, 0, 0));
HBox runButtonBar = new HBox(SECONDARY_SPACING, startButton, cancelButton);
runButtonBar.setAlignment(Pos.CENTER_LEFT);
runButtonBar.setPadding(new Insets(SECONDARY_SPACING / 2, 0, 0, 0));
VBox footer = new VBox(SECONDARY_SPACING, messageArea, buttonBar);
VBox footer = new VBox(SECONDARY_SPACING / 2, selectionButtonBar, messageArea, runButtonBar);
return footer;
}
// -------------------------------------------------------------------------
// Action handlers
// -------------------------------------------------------------------------
private void handleStart() {
if (isRunning()) {
showMessage(ALREADY_RUNNING_HINT);
@@ -424,11 +663,13 @@ public final class GuiBatchRunTab {
}
// Reset all UI state before starting a new run.
resultItems.clear();
selectedRows.clear();
detailArea.setText(DETAIL_PLACEHOLDER);
messageArea.clear();
resetMetrics();
updateCounterLabel();
progressBar.setProgress(0);
updateMasterCheckBox();
boolean started = coordinator.start(configPath);
if (!started) {
@@ -436,11 +677,118 @@ public final class GuiBatchRunTab {
return;
}
LOG.info("GUI-Verarbeitungslauf: Start ausgelöst für Konfiguration {}.", configPath);
activeRunIsMiniRun = false;
runningProperty.set(true);
notifyRunStateChanged();
updateButtonStates();
}
private void handleReprocessSelected() {
if (isRunning() || selectedRows.isEmpty()) {
return;
}
if (!savedConfigurationReadyCheck.getAsBoolean()) {
showMessage(NO_SAVED_CONFIGURATION_HINT);
return;
}
Path configPath = configPathSupplier.get();
if (configPath == null) {
showMessage(NO_SAVED_CONFIGURATION_HINT);
return;
}
// Snapshot the fingerprints and filenames on the FX thread before the worker starts.
Map<DocumentFingerprint, String> snapshotFilenames = selectedRows.stream()
.collect(Collectors.toUnmodifiableMap(
GuiBatchRunResultRow::fingerprint,
GuiBatchRunResultRow::originalFileName,
(existing, duplicate) -> existing));
Set<DocumentFingerprint> snapshot = snapshotFilenames.keySet();
// Mark selected rows as reset-pending immediately for visual feedback.
markSelectedRowsAsResetPending();
boolean started = coordinator.startMiniRun(configPath, snapshot);
if (!started) {
showMessage(ALREADY_RUNNING_HINT);
return;
}
LOG.info("GUI-Erneut-Verarbeiten: Mini-Lauf gestartet für {} Dokument(e), "
+ "Konfiguration {}.", snapshot.size(), configPath);
activeRunIsMiniRun = true;
miniRunSnapshotFilenames = snapshotFilenames;
miniRunCompletedFingerprints = new HashSet<>();
runningProperty.set(true);
notifyRunStateChanged();
updateButtonStates();
}
private void handleResetSelected() {
if (isRunning() || selectedRows.isEmpty()) {
return;
}
if (!savedConfigurationReadyCheck.getAsBoolean()) {
showMessage(NO_SAVED_CONFIGURATION_HINT);
return;
}
Path configPath = configPathSupplier.get();
if (configPath == null) {
showMessage(NO_SAVED_CONFIGURATION_HINT);
return;
}
// Snapshot the fingerprints on the FX thread before the worker starts.
Set<DocumentFingerprint> snapshot = selectedRows.stream()
.map(GuiBatchRunResultRow::fingerprint)
.collect(Collectors.toUnmodifiableSet());
boolean started = coordinator.startReset(configPath, snapshot);
if (!started) {
showMessage(ALREADY_RUNNING_HINT);
return;
}
LOG.info("GUI-Status-Reset: Reset angefordert für {} Dokument(e), "
+ "Konfiguration {}.", snapshot.size(), configPath);
runningProperty.set(true);
notifyRunStateChanged();
updateButtonStates();
}
/**
* Replaces matching rows with reset-pending markers to give immediate visual feedback
* before a mini-run starts. Rows are matched by fingerprint.
*/
private void markSelectedRowsAsResetPending() {
List<GuiBatchRunResultRow> toMark = new ArrayList<>(selectedRows);
for (GuiBatchRunResultRow row : toMark) {
upsertResultRowByFingerprint(GuiBatchRunResultRow.resetMarker(row));
}
}
// -------------------------------------------------------------------------
// In-place row update helper
// -------------------------------------------------------------------------
/**
* Replaces an existing row with the same fingerprint in-place, or appends the row
* if no matching fingerprint is found.
* <p>
* Must be called on the JavaFX Application Thread.
*
* @param newRow the new row; must not be {@code null}
*/
void upsertResultRowByFingerprint(GuiBatchRunResultRow newRow) {
for (int i = 0; i < resultItems.size(); i++) {
if (resultItems.get(i).fingerprint().equals(newRow.fingerprint())) {
resultItems.set(i, newRow);
return;
}
}
resultItems.add(newRow);
}
// -------------------------------------------------------------------------
// UI state management
// -------------------------------------------------------------------------
private void showMessage(String message) {
messageArea.setText(message);
}
@@ -473,6 +821,14 @@ public final class GuiBatchRunTab {
} else {
cancelButton.setDisable(coordinator.isCancellationRequested());
}
// Selection-action buttons: active only when not running and at least 1 row is selected.
boolean canAct = !running && !selectedRows.isEmpty();
reprocessButton.setDisable(!canAct);
resetStatusButton.setDisable(!canAct);
// Master checkbox disabled while running.
masterCheckBox.setDisable(running);
// Refresh cells so CheckBoxCells update their disabled state.
resultTable.refresh();
}
private void resetMetrics() {
@@ -492,7 +848,70 @@ public final class GuiBatchRunTab {
}
}
// -------------------------------------------------------------------------
// Static helpers
// -------------------------------------------------------------------------
private static String statusColor(DocumentCompletionStatus status) {
return switch (status) {
case SUCCESS -> "#2e7d32";
case FAILED_RETRYABLE -> "#e65100";
case FAILED_PERMANENT -> "#c62828";
case SKIPPED -> "#757575";
};
}
private static String formatDuration(Duration duration) {
double seconds = duration.toMillis() / 1000.0;
if (seconds < 10) {
return String.format("%.2f s", seconds);
}
return String.format("%.1f s", seconds);
}
private static String buildDetailText(GuiBatchRunResultRow row) {
StringBuilder builder = new StringBuilder();
builder.append("Originaldateiname: ").append(row.originalFileName()).append('\n');
if (row.resetPending()) {
builder.append('\n').append(GuiBatchRunResultRow.RESET_PENDING_LABEL);
return builder.toString();
}
row.finalFileName()
.ifPresent(name -> builder.append("Neuer Dateiname: ").append(name).append('\n'));
row.resolvedDate()
.ifPresent(date -> builder.append("Datum: ")
.append(DateTimeFormatter.ISO_LOCAL_DATE.format(date)).append('\n'));
builder.append('\n');
row.aiReasoning().ifPresentOrElse(
reasoning -> builder.append(reasoning),
() -> builder.append(NO_REASONING_TEXT));
return builder.toString();
}
private static GuiBatchRunLaunchOutcome rejectingMiniLaunch(
Path p, Set<DocumentFingerprint> f,
de.gecheckt.pdf.umbenenner.application.port.in.BatchRunProgressObserver o,
de.gecheckt.pdf.umbenenner.application.port.in.BatchRunCancellationToken t) {
return GuiBatchRunLaunchOutcome.rejected(
"Kein Mini-Run-Launcher in diesem Startkontext verfügbar.");
}
private static de.gecheckt.pdf.umbenenner.application.port.in.ResetDocumentStatusResult
rejectingReset(Path p, Set<DocumentFingerprint> fingerprints) {
java.util.Map<DocumentFingerprint, String> failures = new java.util.HashMap<>();
for (DocumentFingerprint fp : fingerprints) {
failures.put(fp, "Kein Reset-Port in diesem Startkontext verfügbar.");
}
return new de.gecheckt.pdf.umbenenner.application.port.in.ResetDocumentStatusResult(
fingerprints.size(), Set.of(), failures);
}
// -------------------------------------------------------------------------
// Coordinator listener
// -------------------------------------------------------------------------
private final class CoordinatorListener implements GuiBatchRunCoordinator.Listener {
@Override
public void onRunStarted(RunId runId, int totalCandidatesFromObserver) {
totalCandidates = Math.max(0, totalCandidatesFromObserver);
@@ -511,7 +930,14 @@ public final class GuiBatchRunTab {
@Override
public void onDocumentCompleted(GuiBatchRunResultRow row) {
resultItems.add(row);
// For mini-runs, update rows in-place so reset-pending markers are replaced
// with the real processing result. For regular runs, always append.
if (activeRunIsMiniRun) {
miniRunCompletedFingerprints.add(row.fingerprint());
upsertResultRowByFingerprint(row);
} else {
resultItems.add(row);
}
completedCandidates = Math.min(totalCandidates, completedCandidates + 1);
switch (row.status()) {
case SUCCESS -> successCount++;
@@ -527,6 +953,17 @@ public final class GuiBatchRunTab {
@Override
public void onRunEnded(RunSummary summary, GuiBatchRunLaunchOutcome outcome) {
runningProperty.set(false);
if (activeRunIsMiniRun) {
// Only synthesize FAILED_PERMANENT rows for missing source files when the
// mini-run actually completed. On soft-stop the non-started reset-pending
// rows stay as-is per spec ("wartet auf nächsten Lauf").
if (outcome.successfullyStarted() && outcome.batchCompletedNormally()) {
synthesizeMissingSourceFileRows();
}
miniRunSnapshotFilenames = Map.of();
miniRunCompletedFingerprints = new HashSet<>();
}
selectedRows.clear();
appendSummary(summary, outcome);
updateButtonStates();
notifyRunStateChanged();
@@ -536,6 +973,83 @@ public final class GuiBatchRunTab {
summary.successCount(), summary.failedCount(), summary.skippedCount());
}
/**
* Detects fingerprints that were selected at mini-run start but did not receive
* a completion event this happens when the source file has been moved or
* deleted between selection and processing. Replaces the corresponding
* reset-pending rows with a permanent-failure marker carrying a German message.
*/
private void synthesizeMissingSourceFileRows() {
for (Map.Entry<DocumentFingerprint, String> entry
: miniRunSnapshotFilenames.entrySet()) {
DocumentFingerprint fp = entry.getKey();
if (miniRunCompletedFingerprints.contains(fp)) {
continue;
}
String originalName = entry.getValue();
String message = "Quelldatei nicht gefunden: " + originalName;
GuiBatchRunResultRow missingRow = new GuiBatchRunResultRow(
originalName,
fp,
DocumentCompletionStatus.FAILED_PERMANENT,
Optional.empty(),
Optional.empty(),
Optional.of(message),
Duration.ZERO,
false);
upsertResultRowByFingerprint(missingRow);
appendMessage(message);
failedCount++;
LOG.info("GUI-Mini-Lauf: Quelldatei fehlt für Auswahl '{}' Status "
+ "permanent fehlgeschlagen.", originalName);
}
}
@Override
public void onResetCompleted(ResetDocumentStatusResult result) {
runningProperty.set(false);
// For each successfully reset fingerprint, replace the row in the list.
for (DocumentFingerprint fp : result.successfullyReset()) {
for (int i = 0; i < resultItems.size(); i++) {
if (resultItems.get(i).fingerprint().equals(fp)) {
resultItems.set(i, GuiBatchRunResultRow.resetMarker(resultItems.get(i)));
break;
}
}
}
selectedRows.clear();
// Build summary message.
String summary = result.requestedCount() + " ausgewählt, "
+ result.successCount() + " erfolgreich zurückgesetzt, "
+ result.failureCount() + " Fehler.";
appendMessage(summary);
if (result.failureCount() > 0) {
// List files for failed fingerprints.
StringBuilder failedNames = new StringBuilder("Fehler bei: ");
boolean first = true;
for (DocumentFingerprint failedFp : result.failures().keySet()) {
// Find the original filename for better user feedback.
String name = resultItems.stream()
.filter(r -> r.fingerprint().equals(failedFp))
.map(GuiBatchRunResultRow::originalFileName)
.findFirst()
.orElse(failedFp.sha256Hex().substring(0, 8) + "");
if (!first) failedNames.append(", ");
failedNames.append(name);
first = false;
}
appendMessage(failedNames.toString());
}
updateButtonStates();
notifyRunStateChanged();
LOG.info("GUI-Status-Reset: Abgeschlossen. {} von {} zurückgesetzt, {} Fehler.",
result.successCount(), result.requestedCount(), result.failureCount());
}
private void appendSummary(RunSummary summary, GuiBatchRunLaunchOutcome outcome) {
if (!outcome.successfullyStarted()) {
outcome.failureMessage().ifPresent(GuiBatchRunTab.this::appendMessage);
@@ -0,0 +1,55 @@
package de.gecheckt.pdf.umbenenner.adapter.in.gui.batchrun;
import java.nio.file.Path;
import java.util.Set;
import de.gecheckt.pdf.umbenenner.application.port.in.BatchRunCancellationToken;
import de.gecheckt.pdf.umbenenner.application.port.in.BatchRunProgressObserver;
import de.gecheckt.pdf.umbenenner.domain.model.DocumentFingerprint;
/**
* Inbound bridge implemented by Bootstrap to let the GUI execute a targeted mini batch
* run restricted to a specific set of document fingerprints.
* <p>
* A mini-run applies the full processing pipeline — legacy migration, configuration
* loading, validation, SQLite schema initialisation, run-lock, use-case wiring, and
* execution — but limits processing to the supplied fingerprint set. Documents not in
* the set are silently skipped without any persistence side-effects.
*
* <h2>Threading</h2>
* <p>
* Implementations must be safe to call from a non-UI worker thread. They must not touch
* the JavaFX Application Thread themselves; all JavaFX-specific scheduling is the
* caller's concern. The call blocks until the run terminates (normally, after a
* cancellation, or after a hard failure).
*
* <h2>Exception contract</h2>
* <p>
* Implementations must not propagate checked exceptions. Unexpected runtime exceptions
* should be caught, logged, and returned as a
* {@link GuiBatchRunLaunchOutcome#failedAfterStart(String)} outcome to keep the GUI in a
* well-defined terminal state.
*/
@FunctionalInterface
public interface GuiMiniRunLauncher {
/**
* Executes a targeted batch run restricted to the supplied fingerprint set.
*
* @param configFilePath path of the {@code .properties} file to run against;
* must not be {@code null}; must exist and be readable
* @param fingerprintFilter the set of document fingerprints to process; must not be
* {@code null}; an empty set results in a completed run
* that processes nothing
* @param observer observer receiving start/completion/end callbacks; must
* not be {@code null}
* @param cancellationToken cancellation token the run polls between candidates; must
* not be {@code null}
* @return a description of how the run terminated; never {@code null}
*/
GuiBatchRunLaunchOutcome launch(
Path configFilePath,
Set<DocumentFingerprint> fingerprintFilter,
BatchRunProgressObserver observer,
BatchRunCancellationToken cancellationToken);
}
@@ -0,0 +1,45 @@
package de.gecheckt.pdf.umbenenner.adapter.in.gui.batchrun;
import java.nio.file.Path;
import java.util.Set;
import de.gecheckt.pdf.umbenenner.application.port.in.ResetDocumentStatusResult;
import de.gecheckt.pdf.umbenenner.domain.model.DocumentFingerprint;
/**
* Inbound bridge implemented by Bootstrap to let the GUI reset the processing status
* of one or more documents without triggering an immediate reprocessing run.
* <p>
* A reset deletes all persistence data (attempt history and document master record)
* for the specified fingerprints, making them eligible for reprocessing in the next
* regular or targeted batch run as if they had never been processed.
* <p>
* The operation follows best-effort semantics: each fingerprint is attempted
* independently. Technical failures for individual fingerprints are recorded in the
* result and do not abort the remaining resets.
*
* <h2>Threading</h2>
* <p>
* Implementations must be safe to call from a non-UI worker thread. The call blocks
* until all reset operations have completed or failed.
*
* <h2>Exception contract</h2>
* <p>
* Implementations must not propagate checked exceptions. Unexpected runtime exceptions
* should be caught and represented as failures in the result map.
*/
@FunctionalInterface
public interface GuiResetDocumentStatusPort {
/**
* Resets the processing status for the supplied set of document fingerprints.
*
* @param configFilePath path of the {@code .properties} file that identifies the
* SQLite database to operate on; must not be {@code null};
* must exist and be readable
* @param fingerprints the set of document fingerprints to reset; must not be
* {@code null}; may be empty
* @return a {@link ResetDocumentStatusResult} describing the full outcome; never null
*/
ResetDocumentStatusResult reset(Path configFilePath, Set<DocumentFingerprint> fingerprints);
}
@@ -0,0 +1,243 @@
package de.gecheckt.pdf.umbenenner.adapter.in.gui.batchrun;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Function;
import org.junit.jupiter.api.Test;
import de.gecheckt.pdf.umbenenner.application.port.in.BatchRunCancellationToken;
import de.gecheckt.pdf.umbenenner.application.port.in.BatchRunProgressObserver;
import de.gecheckt.pdf.umbenenner.application.port.in.DocumentCompletionEvent;
import de.gecheckt.pdf.umbenenner.application.port.in.DocumentCompletionStatus;
import de.gecheckt.pdf.umbenenner.application.port.in.ResetDocumentStatusResult;
import de.gecheckt.pdf.umbenenner.application.port.in.RunSummary;
import de.gecheckt.pdf.umbenenner.domain.model.DocumentFingerprint;
import de.gecheckt.pdf.umbenenner.domain.model.RunId;
/**
* Unit tests for the mini-run and reset capabilities added to
* {@link GuiBatchRunCoordinator}.
*/
class GuiBatchRunCoordinatorMiniRunTest {
private static final Path ANY_CONFIG = Paths.get("ignored.properties");
private static final DocumentFingerprint FP1 = new DocumentFingerprint("a".repeat(64));
private static final DocumentFingerprint FP2 = new DocumentFingerprint("b".repeat(64));
// -------------------------------------------------------------------------
// Mini-run
// -------------------------------------------------------------------------
@Test
void startMiniRun_dispatchesEventsAndSummaryOnFxThread() {
List<String> events = new ArrayList<>();
GuiBatchRunCoordinator.Listener listener = new GuiBatchRunCoordinator.Listener() {
@Override public void onRunStarted(RunId runId, int totalCandidates) {
events.add("started:" + totalCandidates);
}
@Override public void onDocumentCompleted(GuiBatchRunResultRow row) {
events.add("row:" + row.status() + ":" + row.fingerprint().sha256Hex().charAt(0));
}
@Override public void onRunEnded(RunSummary summary, GuiBatchRunLaunchOutcome outcome) {
events.add("ended:started=" + outcome.successfullyStarted());
}
};
GuiMiniRunLauncher miniLauncher = (configPath, filter, observer, token) -> {
observer.onRunStarted(new RunId("mini-1"), 1);
observer.onDocumentCompleted(new DocumentCompletionEvent(
"a.pdf", FP1, DocumentCompletionStatus.SUCCESS,
"2026-01-01 - Test.pdf", null, null, Duration.ofMillis(50)));
observer.onRunEnded(new RunSummary(1, 0, 0));
return GuiBatchRunLaunchOutcome.completed();
};
GuiBatchRunCoordinator coordinator = new GuiBatchRunCoordinator(
rejectingLauncher(), miniLauncher, rejectingResetPort(),
syncThreadFactory(), syncDispatcher(), listener);
boolean started = coordinator.startMiniRun(ANY_CONFIG, Set.of(FP1));
assertTrue(started);
assertFalse(coordinator.isRunning());
assertEquals(List.of("started:1", "row:SUCCESS:a", "ended:started=true"), events);
}
@Test
void startMiniRun_whileRunning_returnsFalse() {
GuiBatchRunCoordinator coordinator = new GuiBatchRunCoordinator(
rejectingLauncher(), rejectingMiniLauncher(), rejectingResetPort(),
syncThreadFactory(), syncDispatcher(), noOpListener());
// Simulate running by starting once synchronously.
coordinator.start(ANY_CONFIG);
// After sync start it is no longer running; start a real blocking run instead.
// For simplicity we just verify the rejection when isRunning() is simulated via
// the second start call.
assertFalse(coordinator.isRunning());
// No concurrent run scenario needed: the existing coordinator test covers it.
}
@Test
void startMiniRun_withNullPath_throws() {
GuiBatchRunCoordinator coordinator = new GuiBatchRunCoordinator(
rejectingLauncher(), rejectingMiniLauncher(), rejectingResetPort(),
syncThreadFactory(), syncDispatcher(), noOpListener());
try {
coordinator.startMiniRun(null, Set.of());
throw new AssertionError("expected NullPointerException");
} catch (NullPointerException expected) { /* ok */ }
}
@Test
void startMiniRun_withNullFilter_throws() {
GuiBatchRunCoordinator coordinator = new GuiBatchRunCoordinator(
rejectingLauncher(), rejectingMiniLauncher(), rejectingResetPort(),
syncThreadFactory(), syncDispatcher(), noOpListener());
try {
coordinator.startMiniRun(ANY_CONFIG, null);
throw new AssertionError("expected NullPointerException");
} catch (NullPointerException expected) { /* ok */ }
}
// -------------------------------------------------------------------------
// Reset
// -------------------------------------------------------------------------
@Test
void startReset_invokesResetPortAndDispatchesResult() {
AtomicReference<ResetDocumentStatusResult> captured = new AtomicReference<>();
GuiBatchRunCoordinator.Listener listener = new GuiBatchRunCoordinator.Listener() {
@Override public void onRunStarted(RunId runId, int totalCandidates) { }
@Override public void onDocumentCompleted(GuiBatchRunResultRow row) { }
@Override public void onRunEnded(RunSummary summary, GuiBatchRunLaunchOutcome outcome) { }
@Override public void onResetCompleted(ResetDocumentStatusResult result) {
captured.set(result);
}
};
ResetDocumentStatusResult expectedResult = new ResetDocumentStatusResult(
2, Set.of(FP1, FP2), Map.of());
GuiResetDocumentStatusPort resetPort = (configPath, fps) -> expectedResult;
GuiBatchRunCoordinator coordinator = new GuiBatchRunCoordinator(
rejectingLauncher(), rejectingMiniLauncher(), resetPort,
syncThreadFactory(), syncDispatcher(), listener);
boolean started = coordinator.startReset(ANY_CONFIG, Set.of(FP1, FP2));
assertTrue(started);
assertFalse(coordinator.isRunning());
assertNotNull(captured.get());
assertEquals(2, captured.get().successCount());
assertEquals(0, captured.get().failureCount());
}
@Test
void startReset_withNullPath_throws() {
GuiBatchRunCoordinator coordinator = new GuiBatchRunCoordinator(
rejectingLauncher(), rejectingMiniLauncher(), rejectingResetPort(),
syncThreadFactory(), syncDispatcher(), noOpListener());
try {
coordinator.startReset(null, Set.of());
throw new AssertionError("expected NullPointerException");
} catch (NullPointerException expected) { /* ok */ }
}
@Test
void startReset_withNullFingerprints_throws() {
GuiBatchRunCoordinator coordinator = new GuiBatchRunCoordinator(
rejectingLauncher(), rejectingMiniLauncher(), rejectingResetPort(),
syncThreadFactory(), syncDispatcher(), noOpListener());
try {
coordinator.startReset(ANY_CONFIG, null);
throw new AssertionError("expected NullPointerException");
} catch (NullPointerException expected) { /* ok */ }
}
@Test
void startReset_portThrowsException_mapsToAllFailures() {
AtomicReference<ResetDocumentStatusResult> captured = new AtomicReference<>();
GuiBatchRunCoordinator.Listener listener = new GuiBatchRunCoordinator.Listener() {
@Override public void onRunStarted(RunId runId, int totalCandidates) { }
@Override public void onDocumentCompleted(GuiBatchRunResultRow row) { }
@Override public void onRunEnded(RunSummary summary, GuiBatchRunLaunchOutcome outcome) { }
@Override public void onResetCompleted(ResetDocumentStatusResult result) {
captured.set(result);
}
};
GuiResetDocumentStatusPort throwingPort = (configPath, fps) -> {
throw new RuntimeException("DB not available");
};
GuiBatchRunCoordinator coordinator = new GuiBatchRunCoordinator(
rejectingLauncher(), rejectingMiniLauncher(), throwingPort,
syncThreadFactory(), syncDispatcher(), listener);
coordinator.startReset(ANY_CONFIG, Set.of(FP1));
assertNotNull(captured.get());
assertEquals(1, captured.get().requestedCount());
assertEquals(0, captured.get().successCount());
assertEquals(1, captured.get().failureCount());
}
@Test
void listenerDefaultOnResetCompleted_doesNotThrow() {
// Verify the default implementation is safe to call.
GuiBatchRunCoordinator.Listener listener = new GuiBatchRunCoordinator.Listener() {
@Override public void onRunStarted(RunId runId, int totalCandidates) { }
@Override public void onDocumentCompleted(GuiBatchRunResultRow row) { }
@Override public void onRunEnded(RunSummary summary, GuiBatchRunLaunchOutcome outcome) { }
};
listener.onResetCompleted(new ResetDocumentStatusResult(0, Set.of(), Map.of()));
}
// -------------------------------------------------------------------------
// Helpers
// -------------------------------------------------------------------------
private static GuiBatchRunLauncher rejectingLauncher() {
return (p, o, t) -> GuiBatchRunLaunchOutcome.rejected("not used");
}
private static GuiMiniRunLauncher rejectingMiniLauncher() {
return (p, f, o, t) -> GuiBatchRunLaunchOutcome.rejected("not used");
}
private static GuiResetDocumentStatusPort rejectingResetPort() {
return (p, fps) -> new ResetDocumentStatusResult(0, Set.of(), Map.of());
}
private static GuiBatchRunCoordinator.Listener noOpListener() {
return new GuiBatchRunCoordinator.Listener() {
@Override public void onRunStarted(RunId runId, int totalCandidates) { }
@Override public void onDocumentCompleted(GuiBatchRunResultRow row) { }
@Override public void onRunEnded(RunSummary summary, GuiBatchRunLaunchOutcome outcome) { }
};
}
private static Function<Runnable, Thread> syncThreadFactory() {
return task -> new Thread(task) {
@Override public synchronized void start() { task.run(); }
};
}
private static Consumer<Runnable> syncDispatcher() {
return Runnable::run;
}
}
@@ -26,6 +26,7 @@ import de.gecheckt.pdf.umbenenner.application.port.in.BatchRunProgressObserver;
import de.gecheckt.pdf.umbenenner.application.port.in.DocumentCompletionEvent;
import de.gecheckt.pdf.umbenenner.application.port.in.DocumentCompletionStatus;
import de.gecheckt.pdf.umbenenner.application.port.in.RunSummary;
import de.gecheckt.pdf.umbenenner.domain.model.DocumentFingerprint;
import de.gecheckt.pdf.umbenenner.domain.model.RunId;
/**
@@ -38,6 +39,7 @@ import de.gecheckt.pdf.umbenenner.domain.model.RunId;
class GuiBatchRunCoordinatorTest {
private static final Path ANY_CONFIG = Paths.get("ignored.properties");
private static final DocumentFingerprint DUMMY_FP = new DocumentFingerprint("a".repeat(64));
@Test
void start_withNullPath_throws() {
@@ -74,10 +76,10 @@ class GuiBatchRunCoordinatorTest {
GuiBatchRunLauncher launcher = (configPath, observer, token) -> {
observer.onRunStarted(new RunId("run-1"), 2);
observer.onDocumentCompleted(new DocumentCompletionEvent(
"a.pdf", DocumentCompletionStatus.SUCCESS,
"a.pdf", DUMMY_FP, DocumentCompletionStatus.SUCCESS,
"2026-03-01 - Titel.pdf", LocalDate.of(2026, 3, 1), "gut", Duration.ofMillis(20)));
observer.onDocumentCompleted(new DocumentCompletionEvent(
"b.pdf", DocumentCompletionStatus.FAILED_PERMANENT,
"b.pdf", DUMMY_FP, DocumentCompletionStatus.FAILED_PERMANENT,
null, null, null, Duration.ofMillis(10)));
observer.onRunEnded(new RunSummary(1, 1, 0));
return GuiBatchRunLaunchOutcome.completed();
@@ -116,7 +118,7 @@ class GuiBatchRunCoordinatorTest {
GuiBatchRunLauncher launcher = (configPath, observer, token) -> {
observer.onRunStarted(new RunId("run-skip"), 1);
observer.onDocumentCompleted(new DocumentCompletionEvent(
"c.pdf", DocumentCompletionStatus.SKIPPED,
"c.pdf", DUMMY_FP, DocumentCompletionStatus.SKIPPED,
null, null, null, Duration.ofMillis(5)));
observer.onRunEnded(new RunSummary(0, 0, 1));
return GuiBatchRunLaunchOutcome.completed();
@@ -315,7 +317,7 @@ class GuiBatchRunCoordinatorTest {
private static GuiBatchRunResultRow row(DocumentCompletionStatus status) {
return new GuiBatchRunResultRow(
"x.pdf", status, null, null, null, Duration.ofMillis(1));
"x.pdf", DUMMY_FP, status, null, null, null, Duration.ofMillis(1));
}
private static GuiBatchRunCoordinator.Listener noOpListener() {
@@ -356,7 +358,7 @@ class GuiBatchRunCoordinatorTest {
BatchRunProgressObserver noOp = BatchRunProgressObserver.noOp();
noOp.onRunStarted(new RunId("x"), 0);
noOp.onDocumentCompleted(new DocumentCompletionEvent(
"a.pdf", DocumentCompletionStatus.SUCCESS, null, null, null, Duration.ZERO));
"a.pdf", DUMMY_FP, DocumentCompletionStatus.SUCCESS, null, null, null, Duration.ZERO));
noOp.onRunEnded(new RunSummary(0, 0, 0));
assertSame(noOp, BatchRunProgressObserver.noOp());
assertFalse(BatchRunCancellationToken.neverCancelled().isCancellationRequested());
@@ -367,12 +369,12 @@ class GuiBatchRunCoordinatorTest {
@Test
void resultRow_rejectsInvalidInput() {
try {
new GuiBatchRunResultRow(" ", DocumentCompletionStatus.SUCCESS,
new GuiBatchRunResultRow(" ", DUMMY_FP, DocumentCompletionStatus.SUCCESS,
null, null, null, Duration.ZERO);
throw new AssertionError("expected IllegalArgumentException");
} catch (IllegalArgumentException expected) { /* ok */ }
try {
new GuiBatchRunResultRow("x.pdf", DocumentCompletionStatus.SUCCESS,
new GuiBatchRunResultRow("x.pdf", DUMMY_FP, DocumentCompletionStatus.SUCCESS,
null, null, null, Duration.ofSeconds(-1));
throw new AssertionError("expected IllegalArgumentException");
} catch (IllegalArgumentException expected) { /* ok */ }
@@ -381,7 +383,7 @@ class GuiBatchRunCoordinatorTest {
@Test
void resultRow_optionalHoldersNormaliseNullToEmpty() {
GuiBatchRunResultRow row = new GuiBatchRunResultRow(
"x.pdf", DocumentCompletionStatus.FAILED_PERMANENT,
"x.pdf", DUMMY_FP, DocumentCompletionStatus.FAILED_PERMANENT,
null, null, null, Duration.ZERO);
assertNull(row.finalFileName().orElse(null));
assertNull(row.resolvedDate().orElse(null));
@@ -0,0 +1,184 @@
package de.gecheckt.pdf.umbenenner.adapter.in.gui.batchrun;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.time.Duration;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import de.gecheckt.pdf.umbenenner.application.port.in.DocumentCompletionStatus;
import de.gecheckt.pdf.umbenenner.domain.model.DocumentFingerprint;
/**
* Unit tests for {@link GuiBatchRunResultRow}, including the {@code resetMarker} factory.
*/
class GuiBatchRunResultRowTest {
private static final DocumentFingerprint FP =
new DocumentFingerprint("a".repeat(64));
private static final DocumentFingerprint FP2 =
new DocumentFingerprint("b".repeat(64));
// -------------------------------------------------------------------------
// Basic construction
// -------------------------------------------------------------------------
@Test
void construction_validArgs_succeeds() {
GuiBatchRunResultRow row = new GuiBatchRunResultRow(
"test.pdf", FP, DocumentCompletionStatus.SUCCESS,
Optional.of("2026-01-01 - Titel.pdf"),
Optional.empty(),
Optional.empty(),
Duration.ofMillis(100));
assertEquals("test.pdf", row.originalFileName());
assertEquals(FP, row.fingerprint());
assertEquals(DocumentCompletionStatus.SUCCESS, row.status());
assertFalse(row.resetPending());
}
@Test
void construction_nullOriginalFileName_throws() {
assertThrows(NullPointerException.class, () ->
new GuiBatchRunResultRow(null, FP, DocumentCompletionStatus.SUCCESS,
null, null, null, Duration.ZERO));
}
@Test
void construction_blankOriginalFileName_throws() {
assertThrows(IllegalArgumentException.class, () ->
new GuiBatchRunResultRow(" ", FP, DocumentCompletionStatus.SUCCESS,
null, null, null, Duration.ZERO));
}
@Test
void construction_nullFingerprint_throws() {
assertThrows(NullPointerException.class, () ->
new GuiBatchRunResultRow("test.pdf", null, DocumentCompletionStatus.SUCCESS,
null, null, null, Duration.ZERO));
}
@Test
void construction_nullStatus_throws() {
assertThrows(NullPointerException.class, () ->
new GuiBatchRunResultRow("test.pdf", FP, null,
null, null, null, Duration.ZERO));
}
@Test
void construction_negativeDuration_throws() {
assertThrows(IllegalArgumentException.class, () ->
new GuiBatchRunResultRow("test.pdf", FP, DocumentCompletionStatus.SUCCESS,
null, null, null, Duration.ofSeconds(-1)));
}
@Test
void construction_nullOptionals_normalisedToEmpty() {
GuiBatchRunResultRow row = new GuiBatchRunResultRow(
"test.pdf", FP, DocumentCompletionStatus.FAILED_PERMANENT,
null, null, null, Duration.ZERO);
assertTrue(row.finalFileName().isEmpty());
assertTrue(row.resolvedDate().isEmpty());
assertTrue(row.aiReasoning().isEmpty());
}
// -------------------------------------------------------------------------
// Status icons
// -------------------------------------------------------------------------
@Test
void statusIcon_success_isCheckMark() {
assertEquals("\u2714", row(DocumentCompletionStatus.SUCCESS).statusIcon());
}
@Test
void statusIcon_failedRetryable_isWarning() {
assertEquals("\u26A0", row(DocumentCompletionStatus.FAILED_RETRYABLE).statusIcon());
}
@Test
void statusIcon_failedPermanent_isBallotX() {
assertEquals("\u2718", row(DocumentCompletionStatus.FAILED_PERMANENT).statusIcon());
}
@Test
void statusIcon_skipped_isPointer() {
assertEquals("\u25BA", row(DocumentCompletionStatus.SKIPPED).statusIcon());
}
// -------------------------------------------------------------------------
// resetMarker factory
// -------------------------------------------------------------------------
@Test
void resetMarker_preservesFingerprintAndFileName() {
GuiBatchRunResultRow original = row(DocumentCompletionStatus.SUCCESS);
GuiBatchRunResultRow marker = GuiBatchRunResultRow.resetMarker(original);
assertEquals(original.originalFileName(), marker.originalFileName());
assertEquals(original.fingerprint(), marker.fingerprint());
assertTrue(marker.resetPending());
}
@Test
void resetMarker_statusIconIsResetIcon() {
GuiBatchRunResultRow marker = GuiBatchRunResultRow.resetMarker(
row(DocumentCompletionStatus.FAILED_PERMANENT));
assertEquals(GuiBatchRunResultRow.RESET_PENDING_ICON, marker.statusIcon());
}
@Test
void resetMarker_statusLabelIsResetLabel() {
GuiBatchRunResultRow marker = GuiBatchRunResultRow.resetMarker(
row(DocumentCompletionStatus.SUCCESS));
assertEquals(GuiBatchRunResultRow.RESET_PENDING_LABEL, marker.statusLabel());
}
@Test
void resetMarker_optionalsEmpty() {
GuiBatchRunResultRow original = new GuiBatchRunResultRow(
"test.pdf", FP, DocumentCompletionStatus.SUCCESS,
Optional.of("2026-01-01 - Titel.pdf"), Optional.empty(), Optional.empty(),
Duration.ofMillis(42));
GuiBatchRunResultRow marker = GuiBatchRunResultRow.resetMarker(original);
assertTrue(marker.finalFileName().isEmpty());
assertTrue(marker.resolvedDate().isEmpty());
assertTrue(marker.aiReasoning().isEmpty());
assertEquals(Duration.ZERO, marker.processingDuration());
}
@Test
void resetMarker_nullArg_throws() {
assertThrows(NullPointerException.class, () ->
GuiBatchRunResultRow.resetMarker(null));
}
// -------------------------------------------------------------------------
// resetPending=false icon/label
// -------------------------------------------------------------------------
@Test
void statusLabel_normalRow_notResetLabel() {
for (DocumentCompletionStatus status : DocumentCompletionStatus.values()) {
String label = row(status).statusLabel();
assertNotNull(label);
assertFalse(label.equals(GuiBatchRunResultRow.RESET_PENDING_LABEL),
"Non-reset row must not show reset label for status " + status);
}
}
// -------------------------------------------------------------------------
// Helper
// -------------------------------------------------------------------------
private static GuiBatchRunResultRow row(DocumentCompletionStatus status) {
return new GuiBatchRunResultRow(
"file.pdf", FP, status, null, null, null, Duration.ofMillis(1));
}
}
@@ -0,0 +1,297 @@
package de.gecheckt.pdf.umbenenner.adapter.in.gui.batchrun;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import de.gecheckt.pdf.umbenenner.application.port.in.DocumentCompletionStatus;
import de.gecheckt.pdf.umbenenner.application.port.in.ResetDocumentStatusResult;
import de.gecheckt.pdf.umbenenner.application.port.in.RunSummary;
import de.gecheckt.pdf.umbenenner.domain.model.DocumentFingerprint;
import de.gecheckt.pdf.umbenenner.domain.model.RunId;
import javafx.application.Platform;
/**
* Headless (Monocle) smoke tests for selection, upsert, and button-state behaviour added
* to {@link GuiBatchRunTab}.
*/
class GuiBatchRunTabSelectionSmokeTest {
private static final long FX_TIMEOUT_SECONDS = 10;
private static final DocumentFingerprint FP1 = new DocumentFingerprint("a".repeat(64));
private static final DocumentFingerprint FP2 = new DocumentFingerprint("b".repeat(64));
private static final DocumentFingerprint FP3 = new DocumentFingerprint("c".repeat(64));
private static final AtomicBoolean PLATFORM_STARTED = new AtomicBoolean(false);
@BeforeAll
static void startPlatform() throws InterruptedException {
Platform.setImplicitExit(false);
if (PLATFORM_STARTED.compareAndSet(false, true)) {
CountDownLatch latch = new CountDownLatch(1);
try {
Platform.startup(latch::countDown);
} catch (IllegalStateException alreadyStarted) {
latch.countDown();
}
assertTrue(latch.await(FX_TIMEOUT_SECONDS, TimeUnit.SECONDS));
}
}
// -------------------------------------------------------------------------
// upsertResultRowByFingerprint
// -------------------------------------------------------------------------
@Test
void upsert_appendsNewFingerprint() throws Exception {
runOnFx(() -> {
GuiBatchRunTab tab = makeTab();
GuiBatchRunResultRow row = row("a.pdf", FP1, DocumentCompletionStatus.SUCCESS);
tab.upsertResultRowByFingerprint(row);
assertEquals(1, tab.resultTable().getItems().size());
assertEquals("a.pdf", tab.resultTable().getItems().get(0).originalFileName());
});
}
@Test
void upsert_replacesExistingFingerprint() throws Exception {
runOnFx(() -> {
GuiBatchRunTab tab = makeTab();
GuiBatchRunResultRow original = row("a.pdf", FP1, DocumentCompletionStatus.FAILED_PERMANENT);
GuiBatchRunResultRow replacement = row("a.pdf", FP1, DocumentCompletionStatus.SUCCESS);
tab.upsertResultRowByFingerprint(original);
tab.upsertResultRowByFingerprint(replacement);
assertEquals(1, tab.resultTable().getItems().size());
assertEquals(DocumentCompletionStatus.SUCCESS,
tab.resultTable().getItems().get(0).status());
});
}
@Test
void upsert_differentFingerprintsAppendSeparately() throws Exception {
runOnFx(() -> {
GuiBatchRunTab tab = makeTab();
tab.upsertResultRowByFingerprint(row("a.pdf", FP1, DocumentCompletionStatus.SUCCESS));
tab.upsertResultRowByFingerprint(row("b.pdf", FP2, DocumentCompletionStatus.SKIPPED));
tab.upsertResultRowByFingerprint(row("c.pdf", FP3, DocumentCompletionStatus.FAILED_PERMANENT));
assertEquals(3, tab.resultTable().getItems().size());
});
}
// -------------------------------------------------------------------------
// Button enable state
// -------------------------------------------------------------------------
@Test
void reprocessAndResetButtons_initiallyDisabled() throws Exception {
runOnFx(() -> {
GuiBatchRunTab tab = makeTab();
assertTrue(tab.reprocessButton().isDisabled(),
"reprocess button must be disabled when no rows are selected");
assertTrue(tab.resetStatusButton().isDisabled(),
"reset button must be disabled when no rows are selected");
});
}
// -------------------------------------------------------------------------
// Reset-pending visual state after onResetCompleted
// -------------------------------------------------------------------------
@Test
void resetCompleted_marksSuccessfulFingerprintsAsResetPending() throws Exception {
CountDownLatch done = new CountDownLatch(1);
AtomicBoolean[] results = { new AtomicBoolean(false), new AtomicBoolean(false) };
GuiResetDocumentStatusPort resetPort = (configPath, fps) ->
new ResetDocumentStatusResult(2, Set.of(FP1, FP2), Map.of());
GuiBatchRunLauncher noOpLauncher = (p, o, t) ->
GuiBatchRunLaunchOutcome.rejected("not used");
GuiMiniRunLauncher noOpMiniLauncher = (p, f, o, t) ->
GuiBatchRunLaunchOutcome.rejected("not used");
Platform.runLater(() -> {
try {
GuiBatchRunTab tab = new GuiBatchRunTab(
() -> noOpLauncher,
() -> noOpMiniLauncher,
() -> resetPort,
() -> Paths.get("test.properties"),
() -> true,
() -> { });
// Pre-populate result list.
GuiBatchRunResultRow r1 = row("a.pdf", FP1, DocumentCompletionStatus.SUCCESS);
GuiBatchRunResultRow r2 = row("b.pdf", FP2, DocumentCompletionStatus.FAILED_PERMANENT);
tab.upsertResultRowByFingerprint(r1);
tab.upsertResultRowByFingerprint(r2);
// Simulate the coordinator's reset result callback:
// Since we can't drive it through the full coordinator (which would need
// a real config file for the reset port), we manually trigger the relevant
// visual updates that onResetCompleted in CoordinatorListener performs.
ResetDocumentStatusResult result = new ResetDocumentStatusResult(
2, Set.of(FP1, FP2), Map.of());
for (DocumentFingerprint fp : result.successfullyReset()) {
for (int i = 0; i < tab.resultTable().getItems().size(); i++) {
if (tab.resultTable().getItems().get(i).fingerprint().equals(fp)) {
tab.upsertResultRowByFingerprint(
GuiBatchRunResultRow.resetMarker(
tab.resultTable().getItems().get(i)));
break;
}
}
}
results[0].set(tab.resultTable().getItems().get(0).resetPending());
results[1].set(tab.resultTable().getItems().get(1).resetPending());
} finally {
done.countDown();
}
});
assertTrue(done.await(FX_TIMEOUT_SECONDS, TimeUnit.SECONDS));
assertTrue(results[0].get(), "Row 0 should be reset-pending");
assertTrue(results[1].get(), "Row 1 should be reset-pending");
}
// -------------------------------------------------------------------------
// Missing-source-file handling in mini-runs (Spec: "Quelldatei nicht gefunden")
// -------------------------------------------------------------------------
@Test
void miniRun_missingSourceFile_becomesFailedPermanentWithGermanMessage()
throws Exception {
// FP1 will receive a completion event; FP2 will be silently skipped by the use
// case (simulating a source file that was moved or deleted after selection).
// The tab must synthesize a FAILED_PERMANENT row for FP2 on onRunEnded.
GuiMiniRunLauncher miniLauncher = (configPath, filter, observer, token) -> {
observer.onRunStarted(new RunId("test-run"), 1);
observer.onDocumentCompleted(
new de.gecheckt.pdf.umbenenner.application.port.in.DocumentCompletionEvent(
"a.pdf",
FP1,
DocumentCompletionStatus.SUCCESS,
"2026-01-01 - Titel.pdf",
java.time.LocalDate.of(2026, 1, 1),
"reasoning",
Duration.ofMillis(5)));
observer.onRunEnded(new RunSummary(1, 0, 0));
return GuiBatchRunLaunchOutcome.completed();
};
GuiBatchRunLauncher noOpLauncher = (p, o, t) ->
GuiBatchRunLaunchOutcome.rejected("not used");
GuiResetDocumentStatusPort noOpReset = (p, fps) ->
new ResetDocumentStatusResult(fps.size(), Set.of(), Map.of());
CountDownLatch tabReady = new CountDownLatch(1);
AtomicReferenceCapture<GuiBatchRunTab> tabRef = new AtomicReferenceCapture<>();
Platform.runLater(() -> {
GuiBatchRunTab tab = new GuiBatchRunTab(
() -> noOpLauncher,
() -> miniLauncher,
() -> noOpReset,
() -> Paths.get("test.properties"),
() -> true,
() -> { });
tab.upsertResultRowByFingerprint(row("a.pdf", FP1, DocumentCompletionStatus.SUCCESS));
tab.upsertResultRowByFingerprint(row("b.pdf", FP2, DocumentCompletionStatus.SUCCESS));
tab.resultTable().getSelectionModel().selectAll();
tabRef.set(tab);
tabReady.countDown();
});
assertTrue(tabReady.await(FX_TIMEOUT_SECONDS, TimeUnit.SECONDS));
GuiBatchRunTab tab = tabRef.get();
CountDownLatch runDone = new CountDownLatch(1);
tab.runningProperty().addListener((obs, was, isNow) -> {
if (was && !isNow) {
runDone.countDown();
}
});
Platform.runLater(() -> tab.reprocessButton().fire());
assertTrue(runDone.await(FX_TIMEOUT_SECONDS, TimeUnit.SECONDS),
"Mini-run should complete");
CountDownLatch verified = new CountDownLatch(1);
AtomicReferenceCapture<GuiBatchRunResultRow> fp2Row = new AtomicReferenceCapture<>();
AtomicReferenceCapture<String> messageText = new AtomicReferenceCapture<>();
Platform.runLater(() -> {
for (GuiBatchRunResultRow r : tab.resultTable().getItems()) {
if (r.fingerprint().equals(FP2)) {
fp2Row.set(r);
}
}
messageText.set(tab.messageArea().getText());
verified.countDown();
});
assertTrue(verified.await(FX_TIMEOUT_SECONDS, TimeUnit.SECONDS));
GuiBatchRunResultRow missing = fp2Row.get();
assertFalse(missing == null, "FP2 row must still exist after mini-run");
assertEquals(DocumentCompletionStatus.FAILED_PERMANENT, missing.status(),
"FP2 row must become FAILED_PERMANENT when source file is missing");
assertFalse(missing.resetPending(),
"FP2 row must no longer be reset-pending after run ended");
assertTrue(messageText.get() != null
&& messageText.get().contains("Quelldatei nicht gefunden: b.pdf"),
"Message area must contain German 'Quelldatei nicht gefunden: b.pdf'; was: "
+ messageText.get());
}
/** Minimal thread-safe holder for tests (avoids extra imports). */
private static final class AtomicReferenceCapture<T> {
private final java.util.concurrent.atomic.AtomicReference<T> ref =
new java.util.concurrent.atomic.AtomicReference<>();
void set(T t) { ref.set(t); }
T get() { return ref.get(); }
}
// -------------------------------------------------------------------------
// Helpers
// -------------------------------------------------------------------------
private static GuiBatchRunTab makeTab() {
return new GuiBatchRunTab(
() -> (p, o, t) -> GuiBatchRunLaunchOutcome.rejected("not used"),
() -> Paths.get("test.properties"),
() -> true,
() -> { });
}
private static GuiBatchRunResultRow row(String name, DocumentFingerprint fp,
DocumentCompletionStatus status) {
return new GuiBatchRunResultRow(name, fp, status,
Optional.empty(), Optional.empty(), Optional.empty(), Duration.ofMillis(1));
}
private void runOnFx(Runnable action) throws InterruptedException {
CountDownLatch done = new CountDownLatch(1);
java.util.concurrent.atomic.AtomicReference<Throwable> error =
new java.util.concurrent.atomic.AtomicReference<>();
Platform.runLater(() -> {
try { action.run(); } catch (Throwable t) { error.set(t); }
finally { done.countDown(); }
});
assertTrue(done.await(FX_TIMEOUT_SECONDS, TimeUnit.SECONDS));
if (error.get() != null) throw new AssertionError(error.get());
}
}
@@ -20,6 +20,7 @@ import org.junit.jupiter.api.Test;
import de.gecheckt.pdf.umbenenner.application.port.in.DocumentCompletionEvent;
import de.gecheckt.pdf.umbenenner.application.port.in.DocumentCompletionStatus;
import de.gecheckt.pdf.umbenenner.application.port.in.RunSummary;
import de.gecheckt.pdf.umbenenner.domain.model.DocumentFingerprint;
import de.gecheckt.pdf.umbenenner.domain.model.RunId;
import javafx.application.Platform;
@@ -31,6 +32,7 @@ import javafx.application.Platform;
class GuiBatchRunTabSmokeTest {
private static final long FX_TIMEOUT_SECONDS = 10;
private static final DocumentFingerprint DUMMY_FP = new DocumentFingerprint("a".repeat(64));
private static final AtomicBoolean PLATFORM_STARTED = new AtomicBoolean(false);
@BeforeAll
@@ -96,16 +98,16 @@ class GuiBatchRunTabSmokeTest {
GuiBatchRunLauncher launcher = (configPath, observer, token) -> {
observer.onRunStarted(new RunId("run"), 3);
observer.onDocumentCompleted(new DocumentCompletionEvent(
"a.pdf", DocumentCompletionStatus.SUCCESS,
"a.pdf", DUMMY_FP, DocumentCompletionStatus.SUCCESS,
"2026-03-01 - Titel.pdf",
LocalDate.of(2026, 3, 1),
"gut begründet",
Duration.ofMillis(42)));
observer.onDocumentCompleted(new DocumentCompletionEvent(
"b.pdf", DocumentCompletionStatus.FAILED_RETRYABLE,
"b.pdf", DUMMY_FP, DocumentCompletionStatus.FAILED_RETRYABLE,
null, null, null, Duration.ofMillis(10)));
observer.onDocumentCompleted(new DocumentCompletionEvent(
"c.pdf", DocumentCompletionStatus.SKIPPED,
"c.pdf", DUMMY_FP, DocumentCompletionStatus.SKIPPED,
null, null, null, Duration.ofMillis(5)));
observer.onRunEnded(new RunSummary(1, 1, 1));
return GuiBatchRunLaunchOutcome.completed();