FOSSredder 0.5.0
Loading...
Searching...
No Matches
ImportWorkflow.h
Go to the documentation of this file.
1
6
7#pragma once
8
9#include <QHash>
10#include <QObject>
11#include <QString>
12#include <QStringList>
13#include <functional>
14#include <memory>
15
19
20namespace ui {
21
47
50
51namespace adapters {
52class ImportAdapter;
53}
54
55namespace importing {
57
58} // namespace importing
59
64class ImportWorkflow : public QObject {
65 Q_OBJECT
66
67public:
70
80 explicit ImportWorkflow(
81 std::shared_ptr<ui::adapters::ImportAdapter> importAdapter,
82 std::shared_ptr<core::ports::diagnostics::IErrorReporter> errorReporter,
83 StateSnapshotProvider stateSnapshotProvider = {},
84 WorkspaceCommands* commands = nullptr,
85 WorkspaceSelectors* selectors = nullptr, QObject* parent = nullptr);
89 ~ImportWorkflow() override;
90
97 WorkspaceSelectors* selectors);
98
101 bool isRunning() const noexcept;
104 bool isPaused() const noexcept;
106 double progress() const noexcept;
108 QString phase() const;
111 QString error() const;
113 QString selectedFile() const;
118 void setSelectedFile(const QString& path);
120 int queuedCount() const noexcept;
122 QStringList queuedFiles() const;
125 bool hasDraft() const noexcept;
127 QString currentDraftId() const;
130 int currentTransactionIndex() const noexcept;
135 void setCurrentTransactionIndex(int index);
138 int transactionCount() const noexcept;
139
144 QString currentStatementName() const;
145
155 bool renameCurrentStatementDraft(const QString& name);
171 bool commitCurrentTransactionName(const QString& name);
177 bool commitCurrentTransactionBookingDate(const QString& bookingDate);
183 bool commitCurrentTransactionValuta(const QString& valuta);
189 bool setCurrentTransactionStatus(int status);
195 bool setCurrentTransactionAllocatable(bool allocatable);
201 bool applyCurrentTransactionAmountText(const QString& amountText);
207 bool selectCurrentTransactionActor(const QString& actorId);
219 bool setCurrentTransactionPropertySelected(const QString& propertyId,
220 bool selected);
226 bool selectCurrentTransactionContract(const QString& contractId);
237 bool createActorForCurrentTransaction(const QString& actorName);
243 bool createPropertyForCurrentTransaction(const QString& propertyName);
251 bool
252 createOrSelectContractForCurrentTransaction(const QString& contractName,
253 const QString& contractType,
254 const QString& allocatableMode);
263 void pauseActiveDraft();
267 void discardActiveDraft();
271 void finalizeActiveDraft();
278 void removeAttachedImportLog(const QString& logId, bool draftAttached,
279 const QString& draftId);
280
289 void addFiles(const QStringList& paths);
293 void resetStatus();
297 void clearDraft();
304 bool openStoredDraft(const QString& draftId = {});
308 void cancelImport();
312 void cancelQueuedImports();
316 void pauseImport();
320 void resumeImport();
321
322signals:
339 void importFailed(const QString& error);
340
341private slots:
347 void updateProgress(double progress, const QString& phase);
353 void onJobTerminal(core::ports::importing::StatementImportState state,
354 const QString& message);
355
356private:
361 bool hasActiveImportHandle() const noexcept;
365 void clearActiveImportSubscription();
371 void rejectImportStart(const QString& errorMessage, const char* traceMessage);
378 void requestImportCancellation(bool clearQueue, const char* origin,
379 const char* traceMessage);
384 void setImportPaused(bool paused);
389 void
390 handleImportEvent(const core::ports::importing::StatementImportEvent& event);
394 void handleImportCanceled();
400 void handleImportFailed(const QString& errorMessage,
401 const char* traceMessage);
406 bool populateDraftFromResult();
410 void startNextQueuedImport();
415 void startImportForFile(const QString& path);
421 void reportException(const char* origin, std::exception_ptr exception) const;
432 void saveImportLog(const QString& logId, const QString& status,
433 const QString& message, bool draftAttached = false,
434 const QString& draftId = {},
435 const QString& statementId = {},
436 const QString& importFile = {});
441 void clearStoredDraft(const QString& draftId);
445 void rememberCurrentDraftTransactionIndex();
451 bool applyCurrentTransactionPatch(
452 const core::ports::importing::draft::TransactionDraftPatch& patch);
457 core::ports::importing::draft::TransactionDraft* currentTransactionDraft();
462 const core::ports::importing::draft::TransactionDraft*
463 currentTransactionDraft() const;
468 core::ports::workspace::WorkspaceSnapshot stateSnapshot() const;
473 core::ports::workspace::WorkspaceSnapshot catalogSnapshotForDraft() const;
477 void notifyDraftChanged();
482 core::ports::workspace::StatementDraftSnapshot
483 currentStatementDraftSnapshot() const;
488 QString finalizeCurrentStatementDraft();
493 core::ports::importing::draft::StatementDraft* statementDraft() noexcept;
498 const core::ports::importing::draft::StatementDraft*
499 statementDraft() const noexcept;
505 bool restoreDraftFromState(
506 const core::ports::workspace::WorkspaceSnapshot& snapshot);
511 QString resolveDraftContextId() const;
517 int rememberedDraftTransactionIndex(const QString& draftId) const;
518
519 std::unique_ptr<importing::ImportWorkflowState> state_;
520 std::shared_ptr<ui::adapters::ImportAdapter> importAdapter_;
521 StateSnapshotProvider stateSnapshotProvider_;
522 WorkspaceCommands* commands_ = nullptr;
523 WorkspaceSelectors* selectors_ = nullptr;
524 std::shared_ptr<core::ports::diagnostics::IErrorReporter> errorReporter_;
525
526 QString activeDraftId_;
527 QHash<QString, int> draftTransactionIndexByDraftId_;
528 QString activeImportLogId_;
529 bool activeImportTerminalHandled_ = false;
530 bool hasPendingTerminalEvent_ = false;
531 bool hasActiveImportHandle_ = false;
532 core::ports::importing::StatementImportHandle activeImportHandle_;
533 core::ports::importing::StatementImportState pendingTerminalState_ =
534 core::ports::importing::StatementImportState::Pending;
535 QString pendingTerminalMessage_;
536};
537
538} // namespace ui
Declares the structured diagnostics reporting port.
Import runner port consumed by UI workflows.
Immutable workspace read-model snapshot exposed through workspace ports.
bool clearCurrentTransactionContract()
Clears the contract selection for the current transaction draft.
void startStatementImport()
Starts importing the selected or next queued statement file.
void discardActiveDraft()
Discards the active draft and removes its workspace draft state.
bool createActorForCurrentTransaction(const QString &actorName)
Creates or reuses an actor and selects it for the current draft.
bool setCurrentTransactionPropertySelected(const QString &propertyId, bool selected)
Selects or deselects a property for the current transaction draft.
ImportWorkflow(std::shared_ptr< ui::adapters::ImportAdapter > importAdapter, std::shared_ptr< core::ports::diagnostics::IErrorReporter > errorReporter, StateSnapshotProvider stateSnapshotProvider={}, WorkspaceCommands *commands=nullptr, WorkspaceSelectors *selectors=nullptr, QObject *parent=nullptr)
Creates an import workflow.
void cancelImport()
Cancels the current running import.
void setSelectedFile(const QString &path)
Sets the selected import file.
QString currentDraftId() const
Returns the active draft id.
void setWorkspaceRoles(WorkspaceCommands *commands, WorkspaceSelectors *selectors)
Rebinds workspace roles used by the workflow.
bool commitCurrentTransactionName(const QString &name)
Updates the current transaction draft name.
void addFiles(const QStringList &paths)
Adds files to the import selection or queue.
bool clearCurrentTransactionActor()
Clears the actor selection for the current transaction draft.
bool openStoredDraft(const QString &draftId={})
Opens a statement draft stored in workspace state.
void finalizeActiveDraft()
Finalizes the active draft into workspace statement data.
void resumeImport()
Resumes the current paused import.
bool commitCurrentTransactionValuta(const QString &valuta)
Updates the current transaction draft valuta date.
bool createOrSelectContractForCurrentTransaction(const QString &contractName, const QString &contractType, const QString &allocatableMode)
Creates or reuses a contract and selects it for the current draft.
bool selectCurrentTransactionContract(const QString &contractId)
Selects a contract for the current transaction draft.
bool setCurrentTransactionStatus(int status)
Updates the current transaction draft status.
void setCurrentTransactionIndex(int index)
Selects the current transaction draft by index.
void importFailed(const QString &error)
Emitted when an import failed.
void pauseImport()
Pauses the current running import.
bool isRunning() const noexcept
Reports whether an import is running.
QString selectedFile() const
Returns the selected import file.
TransactionDraftView currentTransactionView() const
Builds the QML-facing view of the current transaction draft.
void clearDraft()
Clears the active draft and may continue queued imports.
double progress() const noexcept
Returns import progress.
bool selectCurrentTransactionActor(const QString &actorId)
Selects an actor for the current transaction draft.
bool hasDraft() const noexcept
Reports whether an active statement draft exists.
int queuedCount() const noexcept
Returns queued import file count.
bool applyCurrentTransactionAmountText(const QString &amountText)
Applies user-entered amount text to the current transaction draft.
void stateChanged()
Emitted when import workflow state changed.
void removeAttachedImportLog(const QString &logId, bool draftAttached, const QString &draftId)
Removes an import log and optionally its attached draft.
void cancelQueuedImports()
Cancels the running import and clears queued imports.
void flushActiveDraftToWorkspace()
Saves the active in-memory draft into workspace draft state.
bool createPropertyForCurrentTransaction(const QString &propertyName)
Creates or reuses a property and selects it for the current draft.
bool isPaused() const noexcept
Reports whether the running import is paused.
void importFinished()
Emitted when an import reached a finished state.
bool commitCurrentTransactionBookingDate(const QString &bookingDate)
Updates the current transaction draft booking date.
~ImportWorkflow() override
Destroys the workflow and its internal state.
QString currentStatementName() const
Returns the editable name of the active statement draft.
int insertTransactionAfterCurrent()
Inserts a transaction draft after the current one.
void resetStatus()
Resets import status fields when no import is running.
void pauseActiveDraft()
Saves the active draft and returns to the import overview.
int removeCurrentTransaction()
Removes the current transaction draft.
int currentTransactionIndex() const noexcept
Returns the selected transaction draft index.
QString phase() const
Returns the current import phase text.
QStringList queuedFiles() const
Returns queued import files.
void importCanceled()
Emitted when an import was canceled.
QString error() const
Returns the current import error text.
std::function< core::ports::workspace::WorkspaceSnapshot()> StateSnapshotProvider
bool renameCurrentStatementDraft(const QString &name)
Renames the active statement draft.
int transactionCount() const noexcept
Returns transaction count in the active draft.
bool setCurrentTransactionAllocatable(bool allocatable)
Updates the current transaction draft allocatable flag.
Maps UI intent to core workspace writer commands.
Projects workspace store data into QML-facing read models.
Qt-friendly projection of the currently edited import transaction.