From 4db921b86a05529754a1634bad170de76a076e99 2017-12-13 09:35:24 From: mperrinel Date: 2017-12-13 09:35:24 Subject: [PATCH] Add retrieve events impl --- diff --git a/core/include/Catalogue/CatalogueController.h b/core/include/Catalogue/CatalogueController.h index 8878f81..3bea8b6 100644 --- a/core/include/Catalogue/CatalogueController.h +++ b/core/include/Catalogue/CatalogueController.h @@ -11,17 +11,19 @@ #include +#include + +class DBCatalogue; +class DBEvent; + Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController) class DataSourceItem; class Variable; /** - * @brief The CatalogueController class aims to make the link between SciQlop and its plugins. - * This is the intermediate class that SciQlop has to use in the way to connect a data source. - * Please first use register method to initialize a plugin specified by its metadata name (JSON - * plugin source) then others specifics method will be able to access it. You can load a data source - * driver plugin then create a data source. + * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI + * library. */ class SCIQLOP_CORE_EXPORT CatalogueController : public QObject { Q_OBJECT @@ -29,12 +31,26 @@ public: explicit CatalogueController(QObject *parent = 0); virtual ~CatalogueController(); -signals: - /// Signal emitted when a variable is about to be deleted from SciQlop - void variableAboutToBeDeleted(std::shared_ptr variable); + // DB + QStringList getRepositories() const; + void addDB(const QString &dbPath); + void saveDB(const QString &destinationPath, const QString &repository); + + // Event + bool createEvent(const QString &name); + std::list > retrieveEvents(const QString &repository) const; + std::list > retrieveAllEvents() const; + void updateEvent(std::shared_ptr event); + void trashEvent(std::shared_ptr event); + void removeEvent(std::shared_ptr event); + void restore(QUuid eventId); + void saveEvent(std::shared_ptr event); - /// Signal emitted when a data acquisition is requested on a range for a variable - void rangeChanged(std::shared_ptr variable, const SqpRange &range); + // Catalogue + bool createCatalogue(const QString &name, QVector eventList); + void getCatalogues(const QString &repository) const; + void removeEvent(QUuid catalogueId, const QString &repository); + void saveCatalogue(std::shared_ptr event); public slots: /// Manage init/end of the controller diff --git a/core/src/Catalogue/CatalogueController.cpp b/core/src/Catalogue/CatalogueController.cpp index 4932adf..d3a07eb 100644 --- a/core/src/Catalogue/CatalogueController.cpp +++ b/core/src/Catalogue/CatalogueController.cpp @@ -4,6 +4,13 @@ #include +#include +#include +#include +#include +#include +#include + #include #include @@ -12,10 +19,18 @@ Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController") +namespace { + +static QString REPOSITORY_WORK_SUFFIX = QString{"Work"}; + +} + class CatalogueController::CatalogueControllerPrivate { public: QMutex m_WorkingMutex; CatalogueDao m_CatalogueDao; + + std::list m_RepositoryList; }; CatalogueController::CatalogueController(QObject *parent) @@ -32,13 +47,77 @@ CatalogueController::~CatalogueController() this->waitForFinish(); } +void CatalogueController::addDB(const QString &dbPath) +{ + QDir dbDir(dbPath); + if (dbDir.exists()) { + auto dirName = dbDir.dirName(); + + if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName) + != impl->m_RepositoryList.cend()) { + qCCritical(LOG_CatalogueController()) + << tr("Impossible to addDB that is already loaded"); + } + + if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) { + qCCritical(LOG_CatalogueController()) + << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath); + } + else + { + impl->m_RepositoryList << dirName; + } + } + else { + qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ") + << dbPath; + } +} + +void CatalogueController::saveDB(const QString &destinationPath, const QString &repository) +{ + if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) { + qCCritical(LOG_CatalogueController()) + << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath); + } +} + +std::list > +CatalogueController::retrieveEvents(const QString &repository) const +{ + auto eventsShared = std::list >{}; + auto events = impl->m_CatalogueDao.getEvents(repository); + for (auto event : events) { + eventsShared.push_back(std::make_shared(event)); + } + return eventsShared; +} + +std::list > CatalogueController::retrieveAllEvents() const +{ + auto eventsShared = std::list >{}; + for (auto repository : impl->m_RepositoryList) { + eventsShared.splice(eventsShared.end(), retrieveEvents(repository)); + } + + return eventsShared; +} + void CatalogueController::initialize() { qCDebug(LOG_CatalogueController()) << tr("CatalogueController init") << QThread::currentThread(); impl->m_WorkingMutex.lock(); impl->m_CatalogueDao.initialize(); - qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END"); + auto defaultRepository = QString("%1/%2").arg( + QStandardPaths::displayName(QStandardPaths::AppDataLocation), REPOSITORY_DEFAULT); + QDir defaultRepositoryDir(defaultRepository); + if (defaultRepositoryDir.exists()) { + qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ") + << defaultRepository; + this->addDB(defaultRepository); + qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END"); + } } void CatalogueController::finalize()