diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..9c55ab9 --- /dev/null +++ b/.clang-format @@ -0,0 +1,51 @@ +--- +BasedOnStyle: LLVM +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: 'true' +AlignConsecutiveDeclarations: 'false' +AlignEscapedNewlines: Right +AlignOperands: 'true' +AlignTrailingComments: 'true' +AllowAllParametersOfDeclarationOnNextLine: 'true' +AllowShortBlocksOnASingleLine: 'true' +AllowShortCaseLabelsOnASingleLine: 'true' +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: 'true' +AllowShortLoopsOnASingleLine: 'false' +AlwaysBreakAfterReturnType: None +BreakBeforeBraces: Custom +BraceWrapping: + AfterClass: true + AfterControlStatement: true + AfterEnum: true + AfterFunction: true + AfterStruct: true + AfterNamespace: true + AfterUnion: true + AfterExternBlock: true + BeforeCatch: false + BeforeElse: true + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +Cpp11BracedListStyle: 'true' +FixNamespaceComments: 'true' +IncludeBlocks: Regroup +IndentCaseLabels: 'true' +IndentWidth: 2 +KeepEmptyLinesAtTheStartOfBlocks: 'false' +Language: Cpp +NamespaceIndentation: All +PointerAlignment: Left +SortUsingDeclarations: 'false' +SpaceAfterTemplateKeyword: 'false' +SpaceBeforeAssignmentOperators: 'true' +SpaceBeforeParens: Never +SpaceInEmptyParentheses: 'false' +SpacesInAngles: 'false' +SpacesInContainerLiterals: 'false' +SpacesInParentheses: 'false' +SpacesInSquareBrackets: 'false' +UseTab: Never + +... diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..202644c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.txt.user diff --git a/.gitmodules b/.gitmodules index 586db29..6adabcf 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "external/libcatalogs"] path = external/libcatalogs url = https://hephaistos.lpp.polytechnique.fr/rhodecode/HG_REPOSITORIES/LPP/SciQLOP_Repos/libcatalogs +[submodule "external/catalogicpp"] + path = external/catalogicpp + url = https://github.com/jeandet/catalogicpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9457a06..565ae0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,16 @@ if (NOT catalogs_FOUND) add_subdirectory(external/libcatalogs) endif() +find_package(catalogicpp CONFIG QUIET) +if (NOT catalogicpp_FOUND) + if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/external/catalogicpp/CMakeLists.txt) + message("Init submodule catalogicpp") + execute_process(COMMAND git submodule init external/catalogicpp WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + execute_process(COMMAND git submodule update external/catalogicpp WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + endif() + add_subdirectory(external/catalogicpp) +endif() + macro(declare_test testname testexe sources libraries) add_executable(${testexe} ${sources}) target_link_libraries(${testexe} ${libraries}) @@ -168,6 +178,7 @@ target_link_libraries(sciqlopcore PUBLIC if(Catalog) target_link_libraries(sciqlopcore PUBLIC catalogs + CatalogiCpp ) endif() diff --git a/external/catalogicpp b/external/catalogicpp new file mode 160000 index 0000000..6547208 --- /dev/null +++ b/external/catalogicpp @@ -0,0 +1 @@ +Subproject commit 6547208a6ef0692c8fa0431e651c919ada111f4e diff --git a/include/Catalogue/CatalogueController.h b/include/Catalogue/CatalogueController.h index 7e300aa..0f4a27f 100644 --- a/include/Catalogue/CatalogueController.h +++ b/include/Catalogue/CatalogueController.h @@ -3,14 +3,13 @@ #include "CoreGlobal.h" +#include #include - #include #include #include - -#include - +#include +#include #include class DBCatalogue; @@ -23,71 +22,102 @@ class DataSourceItem; class Variable; /** - * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI - * library. + * @brief The CatalogueController class aims to handle catalogues and event + * using the CatalogueAPI library. */ -class SCIQLOP_CORE_EXPORT CatalogueController : public QObject { - Q_OBJECT +class SCIQLOP_CORE_EXPORT CatalogueController : public QObject +{ + using time_t = double; + using Repository_t = CatalogiCpp::Repository; + using Event_t = Repository_t::Event_t; + using Event_ptr = Repository_t::Event_ptr; + using Catalogue_t = Repository_t::Catalogue_t; + using Catalogue_ptr = typename Repository_t::Catalogue_ptr; + using uuid_t = Repository_t::uuid_t; + + std::map> _lastSavedRepos; + std::map> _currentRepos; + + Q_OBJECT public: - explicit CatalogueController(QObject *parent = 0); - virtual ~CatalogueController(); - - // DB - QStringList getRepositories() const; - void addDB(const QString &dbPath); - void saveDB(const QString &destinationPath, const QString &repository); - - // Event - /// retrieveEvents with empty repository retrieve them from the default repository - std::list > retrieveEvents(const QString &repository) const; - std::list > retrieveAllEvents() const; - - void addEvent(std::shared_ptr event); - void updateEvent(std::shared_ptr event); - void updateEventProduct(std::shared_ptr eventProduct); - void removeEvent(std::shared_ptr event); - // void trashEvent(std::shared_ptr event); - // void restore(std::shared_ptr event); - void saveEvent(std::shared_ptr event); - void discardEvent(std::shared_ptr event, bool &removed); - bool eventHasChanges(std::shared_ptr event) const; - - // Catalogue - std::list > - retrieveEventsFromCatalogue(std::shared_ptr catalogue) const; - - /// retrieveEvents with empty repository retrieve them from the default repository - std::list > retrieveCatalogues(const QString &repository - = QString()) const; - void addCatalogue(std::shared_ptr catalogue); - void updateCatalogue(std::shared_ptr catalogue); - void removeCatalogue(std::shared_ptr catalogue); - void saveCatalogue(std::shared_ptr catalogue); - void discardCatalogue(std::shared_ptr catalogue, bool &removed); - - void saveAll(); - bool hasChanges() const; - - /// Returns the MIME data associated to a list of variables - QByteArray mimeDataForEvents(const QVector > &events) const; - - /// Returns the list of variables contained in a MIME data - QVector > eventsForMimeData(const QByteArray &mimeData) const; - - /// Returns the MIME data associated to a list of variables - QByteArray - mimeDataForCatalogues(const QVector > &catalogues) const; - - /// Returns the list of variables contained in a MIME data - QVector > cataloguesForMimeData(const QByteArray &mimeData) const; - -public slots: - /// Manage init/end of the controller - void initialize(); + explicit CatalogueController(QObject* parent = nullptr); + virtual ~CatalogueController(); + + QStringList getRepositories() const; + void loadRepository(const QString& path, const QString& name); + void saveRepository(const QString& path, const QString& name); + + std::vector events(); + std::vector events(const QString& repository); + + std::vector catalogues(); + std::vector catalogues(const QString& repository); + + bool hasUnsavedChanges(Event_ptr event); + + std::optional repository(Event_ptr event); + std::optional repository(Catalogue_ptr catalogue); + + void save(Event_ptr event); + void save(Catalogue_ptr catalogue); + void save(const QString& repository); + + // // Event + // /// retrieveEvents with empty repository retrieve them from the default + // repository std::list> retrieveEvents(const + // QString& repository) const; std::list> + // retrieveAllEvents() const; + + // void addEvent(std::shared_ptr event); + // void updateEvent(std::shared_ptr event); + // void updateEventProduct(std::shared_ptr eventProduct); + // void removeEvent(std::shared_ptr event); + // // void trashEvent(std::shared_ptr event); + // // void restore(std::shared_ptr event); + // void saveEvent(std::shared_ptr event); + // void discardEvent(std::shared_ptr event, bool& removed); + // bool eventHasChanges(std::shared_ptr event) const; + + // // Catalogue + // std::list> retrieveEventsFromCatalogue( + // std::shared_ptr catalogue) const; + + // /// retrieveEvents with empty repository retrieve them from the default + // repository std::list> retrieveCatalogues( + // const QString& repository = QString()) const; + // void addCatalogue(std::shared_ptr catalogue); + // void updateCatalogue(std::shared_ptr catalogue); + // void removeCatalogue(std::shared_ptr catalogue); + // void saveCatalogue(std::shared_ptr catalogue); + // void discardCatalogue(std::shared_ptr catalogue, bool& + // removed); + + // void saveAll(); + // bool hasChanges() const; + + // /// Returns the MIME data associated to a list of variables + // QByteArray mimeDataForEvents(const QVector>& + // events) const; + + // /// Returns the list of variables contained in a MIME data + // QVector> eventsForMimeData(const QByteArray& + // mimeData) const; + + // /// Returns the MIME data associated to a list of variables + // QByteArray mimeDataForCatalogues(const + // QVector>& catalogues) const; + + // /// Returns the list of variables contained in a MIME data + // QVector> cataloguesForMimeData(const + // QByteArray& mimeData) const; + + // public slots: + // /// Manage init/end of the controller + // void initialize(); private: - class CatalogueControllerPrivate; - spimpl::unique_impl_ptr impl; + // class CatalogueControllerPrivate; + // spimpl::unique_impl_ptr impl; }; #endif // SCIQLOP_CATALOGUECONTROLLER_H diff --git a/include/Common/containers.h b/include/Common/containers.h index 5568cc4..f148c22 100644 --- a/include/Common/containers.h +++ b/include/Common/containers.h @@ -1,16 +1,28 @@ #ifndef CONTAINERS_H #define CONTAINERS_H -#include +#include "cpp_utils.h" -namespace SciQLop::containers { +#include +#include +#include -template -bool contains(const T1 &container, const T2 &value) +namespace SciQLop::containers { - return std::find(container.begin(), container.end(), value) != container.end(); -} + template + auto contains(const T1& container, const T2& value) + -> decltype(container.front(), std::end(container), true) + { + return std::find(std::cbegin(container), std::cend(container), value) != + std::cend(container); + } -} + template + auto contains(const T1& container, const T2& value) + -> decltype(container.find(value), std::cend(container), true) + { + return container.find(value) != std::cend(container); + } +} // namespace SciQLop::containers #endif // CONTAINERS_H diff --git a/src/Catalogue/CatalogueController.cpp b/src/Catalogue/CatalogueController.cpp index b9e5743..ef189c9 100644 --- a/src/Catalogue/CatalogueController.cpp +++ b/src/Catalogue/CatalogueController.cpp @@ -1,574 +1,760 @@ #include - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - +#include +#include +#include #include -#include -#include - #include +#include #include +#include -Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController") - -namespace { +using namespace SciQLop::containers; -static QString REPOSITORY_WORK_SUFFIX = QString{"_work"}; -static QString REPOSITORY_TRASH_SUFFIX = QString{"_trash"}; -} +// class CatalogueController::CatalogueControllerPrivate +//{ -/** - * Possible types of an repository - */ -enum class DBType { SYNC, WORK, TRASH }; -class CatalogueController::CatalogueControllerPrivate { +// public: +// explicit CatalogueControllerPrivate(CatalogueController* parent) : m_Q { +// parent } {} -public: - explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {} +// CatalogueDao m_CatalogueDao; - CatalogueDao m_CatalogueDao; +// QStringList m_RepositoryList; +// CatalogueController* m_Q; - QStringList m_RepositoryList; - CatalogueController *m_Q; +// QSet m_KeysWithChanges; - QSet m_KeysWithChanges; +// QString eventUniqueKey(const std::shared_ptr& event) const; +// QString catalogueUniqueKey(const std::shared_ptr& catalogue) +// const; - QString eventUniqueKey(const std::shared_ptr &event) const; - QString catalogueUniqueKey(const std::shared_ptr &catalogue) const; +// void copyDBtoDB(const QString& dbFrom, const QString& dbTo); +// QString toWorkRepository(QString repository); +// QString toSyncRepository(QString repository); +// void savAllDB(); - void copyDBtoDB(const QString &dbFrom, const QString &dbTo); - QString toWorkRepository(QString repository); - QString toSyncRepository(QString repository); - void savAllDB(); +// void saveEvent(std::shared_ptr event, bool persist = true); +// void saveCatalogue(std::shared_ptr catalogue, bool persist = +// true); - void saveEvent(std::shared_ptr event, bool persist = true); - void saveCatalogue(std::shared_ptr catalogue, bool persist = true); +// std::shared_ptr createFinder( +// const QUuid& uniqId, const QString& repository, DBType type); +//}; - std::shared_ptr createFinder(const QUuid &uniqId, const QString &repository, - DBType type); -}; +CatalogueController::CatalogueController(QObject* parent) +//: impl { spimpl::make_unique_impl(this) } +{} -CatalogueController::CatalogueController(QObject *parent) - : impl{spimpl::make_unique_impl(this)} -{ - qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction") - << QThread::currentThread(); -} - -CatalogueController::~CatalogueController() -{ - qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction") - << QThread::currentThread(); -} +CatalogueController::~CatalogueController() {} QStringList CatalogueController::getRepositories() const { - return impl->m_RepositoryList; -} - -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; - impl->copyDBtoDB(dirName, impl->toWorkRepository(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 -{ - QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; - - auto eventsShared = std::list >{}; - auto events = impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName)); - 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; -} - -std::list > -CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr catalogue) const -{ - auto eventsShared = std::list >{}; - auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue); - for (auto event : events) { - eventsShared.push_back(std::make_shared(event)); - } - return eventsShared; -} - -void CatalogueController::updateEvent(std::shared_ptr event) -{ - event->setRepository(impl->toWorkRepository(event->getRepository())); - - auto uniqueId = impl->eventUniqueKey(event); - impl->m_KeysWithChanges.insert(uniqueId); - - impl->m_CatalogueDao.updateEvent(*event); -} - -void CatalogueController::updateEventProduct(std::shared_ptr eventProduct) -{ - impl->m_CatalogueDao.updateEventProduct(*eventProduct); -} - -void CatalogueController::removeEvent(std::shared_ptr event) -{ - // Remove it from both repository and repository_work - event->setRepository(impl->toWorkRepository(event->getRepository())); - impl->m_CatalogueDao.removeEvent(*event); - event->setRepository(impl->toSyncRepository(event->getRepository())); - impl->m_CatalogueDao.removeEvent(*event); - impl->savAllDB(); -} - -void CatalogueController::addEvent(std::shared_ptr event) -{ - event->setRepository(impl->toWorkRepository(event->getRepository())); - - auto eventTemp = *event; - impl->m_CatalogueDao.addEvent(eventTemp); - - // Call update is necessary at the creation of add Event if it has some tags or some event - // products - if (!event->getEventProducts().empty() || !event->getTags().empty()) { - - auto eventProductsTemp = eventTemp.getEventProducts(); - auto eventProductTempUpdated = std::list{}; - for (auto eventProductTemp : eventProductsTemp) { - eventProductTemp.setEvent(eventTemp); - eventProductTempUpdated.push_back(eventProductTemp); - } - eventTemp.setEventProducts(eventProductTempUpdated); - - impl->m_CatalogueDao.updateEvent(eventTemp); - } - - auto workPred = impl->createFinder(event->getUniqId(), event->getRepository(), DBType::WORK); - - auto workEvent = impl->m_CatalogueDao.getEvent(workPred); - *event = workEvent; - - - auto uniqueId = impl->eventUniqueKey(event); - impl->m_KeysWithChanges.insert(uniqueId); -} - -void CatalogueController::saveEvent(std::shared_ptr event) -{ - impl->saveEvent(event, true); - impl->m_KeysWithChanges.remove(impl->eventUniqueKey(event)); -} - -void CatalogueController::discardEvent(std::shared_ptr event, bool &removed) -{ - auto syncPred = impl->createFinder(event->getUniqId(), event->getRepository(), DBType::SYNC); - auto workPred = impl->createFinder(event->getUniqId(), event->getRepository(), DBType::WORK); - - auto syncEvent = impl->m_CatalogueDao.getEvent(syncPred); - if (!syncEvent.getUniqId().isNull()) { - removed = false; - impl->m_CatalogueDao.copyEvent(syncEvent, impl->toWorkRepository(event->getRepository()), - true); - - auto workEvent = impl->m_CatalogueDao.getEvent(workPred); - *event = workEvent; - impl->m_KeysWithChanges.remove(impl->eventUniqueKey(event)); - } - else { - removed = true; - // Since the element wasn't in sync repository. Discard it means remove it - event->setRepository(impl->toWorkRepository(event->getRepository())); - impl->m_CatalogueDao.removeEvent(*event); - } -} - -bool CatalogueController::eventHasChanges(std::shared_ptr event) const -{ - return impl->m_KeysWithChanges.contains(impl->eventUniqueKey(event)); -} - -std::list > -CatalogueController::retrieveCatalogues(const QString &repository) const -{ - QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository; - - auto cataloguesShared = std::list >{}; - auto catalogues = impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName)); - for (auto catalogue : catalogues) { - cataloguesShared.push_back(std::make_shared(catalogue)); - } - return cataloguesShared; -} - -void CatalogueController::addCatalogue(std::shared_ptr catalogue) -{ - catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); - - auto catalogueTemp = *catalogue; - impl->m_CatalogueDao.addCatalogue(catalogueTemp); - - auto workPred - = impl->createFinder(catalogue->getUniqId(), catalogue->getRepository(), DBType::WORK); - - auto workCatalogue = impl->m_CatalogueDao.getCatalogue(workPred); - *catalogue = workCatalogue; - - auto uniqueId = impl->catalogueUniqueKey(catalogue); - impl->m_KeysWithChanges.insert(uniqueId); -} - -void CatalogueController::updateCatalogue(std::shared_ptr catalogue) -{ - catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); - - auto uniqueId = impl->catalogueUniqueKey(catalogue); - impl->m_KeysWithChanges.insert(uniqueId); - - impl->m_CatalogueDao.updateCatalogue(*catalogue); -} - -void CatalogueController::removeCatalogue(std::shared_ptr catalogue) -{ - // Remove it from both repository and repository_work - catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); - impl->m_CatalogueDao.removeCatalogue(*catalogue); - catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository())); - impl->m_CatalogueDao.removeCatalogue(*catalogue); - impl->savAllDB(); -} - -void CatalogueController::saveCatalogue(std::shared_ptr catalogue) -{ - impl->saveCatalogue(catalogue, true); - impl->m_KeysWithChanges.remove(impl->catalogueUniqueKey(catalogue)); - - // remove key of events of the catalogue - if (catalogue->getType() == CatalogueType::STATIC) { - auto events = this->retrieveEventsFromCatalogue(catalogue); - for (auto event : events) { - impl->m_KeysWithChanges.remove(impl->eventUniqueKey(event)); - } - } -} - -void CatalogueController::discardCatalogue(std::shared_ptr catalogue, bool &removed) -{ - auto syncPred - = impl->createFinder(catalogue->getUniqId(), catalogue->getRepository(), DBType::SYNC); - auto workPred - = impl->createFinder(catalogue->getUniqId(), catalogue->getRepository(), DBType::WORK); - - auto syncCatalogue = impl->m_CatalogueDao.getCatalogue(syncPred); - if (!syncCatalogue.getUniqId().isNull()) { - removed = false; - impl->m_CatalogueDao.copyCatalogue( - syncCatalogue, impl->toWorkRepository(catalogue->getRepository()), true); - - auto workCatalogue = impl->m_CatalogueDao.getCatalogue(workPred); - *catalogue = workCatalogue; - impl->m_KeysWithChanges.remove(impl->catalogueUniqueKey(catalogue)); - } - else { - removed = true; - // Since the element wasn't in sync repository. Discard it means remove it - catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); - impl->m_CatalogueDao.removeCatalogue(*catalogue); - } -} - -void CatalogueController::saveAll() -{ - for (auto repository : impl->m_RepositoryList) { - // Save Event - auto events = this->retrieveEvents(repository); - for (auto event : events) { - impl->saveEvent(event, false); - } - - // Save Catalogue - auto catalogues = this->retrieveCatalogues(repository); - for (auto catalogue : catalogues) { - impl->saveCatalogue(catalogue, false); - } - } - - impl->savAllDB(); - impl->m_KeysWithChanges.clear(); -} - -bool CatalogueController::hasChanges() const -{ - return !impl->m_KeysWithChanges.isEmpty(); -} - -QByteArray -CatalogueController::mimeDataForEvents(const QVector > &events) const -{ - auto encodedData = QByteArray{}; - - QMap idsPerRepository; - for (auto event : events) { - idsPerRepository[event->getRepository()] << event->getUniqId(); - } - - QDataStream stream{&encodedData, QIODevice::WriteOnly}; - stream << idsPerRepository; - - return encodedData; + QStringList repos; + std::transform(std::begin(_currentRepos), std::end(_currentRepos), + std::back_inserter(repos), + [](auto& pair) { return pair.first; }); + return repos; } -QVector > -CatalogueController::eventsForMimeData(const QByteArray &mimeData) const +void CatalogueController::loadRepository(const QString& path, + const QString& name) { - auto events = QVector >{}; - QDataStream stream{mimeData}; - - QMap idsPerRepository; - stream >> idsPerRepository; - - for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend(); ++it) { - auto repository = it.key(); - auto allRepositoryEvent = retrieveEvents(repository); - for (auto uuid : it.value()) { - for (auto repositoryEvent : allRepositoryEvent) { - if (uuid.toUuid() == repositoryEvent->getUniqId()) { - events << repositoryEvent; - } - } - } - } - - return events; + if(QFile::exists(path)) + { + auto repo = CatalogiCpp::load_repository(path.toStdString()); + _lastSavedRepos[name] = repo; + _currentRepos[name] = repo; + } } -QByteArray CatalogueController::mimeDataForCatalogues( - const QVector > &catalogues) const +void CatalogueController::saveRepository(const QString& path, + const QString& name) { - auto encodedData = QByteArray{}; - - QMap idsPerRepository; - for (auto catalogue : catalogues) { - idsPerRepository[catalogue->getRepository()] << catalogue->getUniqId(); - } - - QDataStream stream{&encodedData, QIODevice::WriteOnly}; - stream << idsPerRepository; - - return encodedData; + if(contains(_currentRepos, name)) + { + CatalogiCpp::save_repository(_currentRepos[name], path.toStdString()); + _lastSavedRepos[name] = _currentRepos[name]; + } } -QVector > -CatalogueController::cataloguesForMimeData(const QByteArray &mimeData) const +std::vector CatalogueController::events() { - auto catalogues = QVector >{}; - QDataStream stream{mimeData}; - - QMap idsPerRepository; - stream >> idsPerRepository; - - for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend(); ++it) { - auto repository = it.key(); - auto allRepositoryCatalogues = retrieveCatalogues(repository); - for (auto uuid : it.value()) { - for (auto repositoryCatalogues : allRepositoryCatalogues) { - if (uuid.toUuid() == repositoryCatalogues->getUniqId()) { - catalogues << repositoryCatalogues; - } - } - } - } - - return catalogues; + std::vector e_list; + for(auto& [_, repo] : _currentRepos) + { + for(auto& [_, event] : repo.events()) + e_list.push_back(event); + } + return e_list; } -void CatalogueController::initialize() +std::vector> +CatalogueController::events(const QString& repository) { - qCDebug(LOG_CatalogueController()) << tr("CatalogueController init") - << QThread::currentThread(); - - impl->m_CatalogueDao.initialize(); - auto defaultRepositoryLocation - = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); - - QDir defaultRepositoryLocationDir; - if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) { - defaultRepositoryLocationDir.cd(defaultRepositoryLocation); - auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT); - - qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ") - << defaultRepository; - - QDir dbDir(defaultRepository); - impl->m_RepositoryList << REPOSITORY_DEFAULT; - if (dbDir.exists()) { - auto dirName = dbDir.dirName(); - - if (impl->m_CatalogueDao.addDB(defaultRepository, dirName)) { - impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName)); - } - } - else { - qCInfo(LOG_CatalogueController()) << tr("Initialisation of Default repository detected") - << defaultRepository; - } - } - else { - qCWarning(LOG_CatalogueController()) - << tr("Cannot load the persistent default repository from ") - << defaultRepositoryLocation; - } - - qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END"); + std::vector> e_list; + if(contains(_currentRepos, repository)) + { + auto repo = _currentRepos[repository]; + for(auto& [_, event] : repo.events()) + e_list.push_back(event); + } + return e_list; } -QString CatalogueController::CatalogueControllerPrivate::eventUniqueKey( - const std::shared_ptr &event) const +std::vector +CatalogueController::catalogues() { - return event->getUniqId().toString().append(event->getRepository()); + std::vector c_list; + for(auto& [_, repo] : _currentRepos) + { + for(auto& [_, catalogue] : repo.catalogues()) + c_list.push_back(catalogue); + } + return c_list; } -QString CatalogueController::CatalogueControllerPrivate::catalogueUniqueKey( - const std::shared_ptr &catalogue) const +std::vector +CatalogueController::catalogues(const QString& repository) { - return catalogue->getUniqId().toString().append(catalogue->getRepository()); + std::vector c_list; + if(contains(_currentRepos, repository)) + { + auto repo = _currentRepos[repository]; + for(auto& [_, catalogue] : repo.catalogues()) + c_list.push_back(catalogue); + } + return c_list; } -void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom, - const QString &dbTo) +bool CatalogueController::hasUnsavedChanges( + CatalogueController::Event_ptr event) { - // auto cataloguesShared = std::list >{}; - auto catalogues = m_CatalogueDao.getCatalogues(dbFrom); - auto events = m_CatalogueDao.getEvents(dbFrom); - for (auto catalogue : catalogues) { - m_CatalogueDao.copyCatalogue(catalogue, dbTo, true); - } - - for (auto event : events) { - m_CatalogueDao.copyEvent(event, dbTo, true); - } + if(auto repo = repository(event)) + { + if(contains(_lastSavedRepos, *repo)) + { return *event != *(_lastSavedRepos[*repo].event(event->uuid)); } + } + return true; } -QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString repository) +std::optional +CatalogueController::repository(CatalogueController::Event_ptr event) { - auto syncRepository = toSyncRepository(repository); - - return QString("%1%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX); + for(auto& [repoName, repo] : _currentRepos) + { + if(repo.event(event->uuid)) return repoName; + } + return std::nullopt; } -QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository) +std::optional +CatalogueController::repository(CatalogueController::Catalogue_ptr catalogue) { - auto syncRepository = repository; - if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) { - syncRepository.remove(REPOSITORY_WORK_SUFFIX); - } - else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) { - syncRepository.remove(REPOSITORY_TRASH_SUFFIX); - } - return syncRepository; + for(auto& [repoName, repo] : _currentRepos) + { + if(repo.catalogue(catalogue->uuid)) return repoName; + } + return std::nullopt; } -void CatalogueController::CatalogueControllerPrivate::savAllDB() +void CatalogueController::save(CatalogueController::Event_ptr event) { - for (auto repository : m_RepositoryList) { - auto defaultRepositoryLocation - = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); - m_CatalogueDao.saveDB(defaultRepositoryLocation, repository); + auto repo_name = repository(event); + if(repo_name && contains(_lastSavedRepos, *repo_name)) + { + auto repo = _lastSavedRepos[*repo_name]; + if(contains(repo.events(), event->uuid)) + { + auto saved_evemt = _lastSavedRepos[*repo_name].event(event->uuid); + *saved_evemt = *event; } -} - -void CatalogueController::CatalogueControllerPrivate::saveEvent(std::shared_ptr event, - bool persist) -{ - m_CatalogueDao.copyEvent(*event, toSyncRepository(event->getRepository()), true); - if (persist) { - savAllDB(); + else + { + // TODO/Question should we also take care of which catalogue has it? + // if an event is created and added to a catalogue, what should we do if + // the user clicks the event save button? + // - Only save event value in all events list? + // - Also save the fact that this event is added to a catalogue and save + // the catalogue? + repo.add(event); } + } } -void CatalogueController::CatalogueControllerPrivate::saveCatalogue( - std::shared_ptr catalogue, bool persist) +void CatalogueController::save(CatalogueController::Catalogue_ptr catalogue) { - m_CatalogueDao.copyCatalogue(*catalogue, toSyncRepository(catalogue->getRepository()), true); - if (persist) { - savAllDB(); + auto repo_name = repository(catalogue); + if(repo_name && contains(_lastSavedRepos, *repo_name)) + { + auto repo = _lastSavedRepos[*repo_name]; + if(contains(repo.catalogues(), catalogue->uuid)) + { + auto saved_catalogue = repo.catalogue(catalogue->uuid); + *saved_catalogue = *catalogue; } -} - -std::shared_ptr CatalogueController::CatalogueControllerPrivate::createFinder( - const QUuid &uniqId, const QString &repository, DBType type) -{ - // update catalogue parameter - auto uniqIdPredicate = std::make_shared(QString{"uniqId"}, uniqId, - ComparaisonOperation::EQUALEQUAL); - - auto repositoryType = repository; - switch (type) { - case DBType::SYNC: - repositoryType = toSyncRepository(repositoryType); - break; - case DBType::WORK: - repositoryType = toWorkRepository(repositoryType); - break; - case DBType::TRASH: - default: - break; + else + { + repo.add(catalogue); } - - auto repositoryPredicate = std::make_shared( - QString{"repository"}, repositoryType, ComparaisonOperation::EQUALEQUAL); - - auto finderPred = std::make_shared(CompoundOperation::AND); - finderPred->AddRequestPredicate(uniqIdPredicate); - finderPred->AddRequestPredicate(repositoryPredicate); - - return finderPred; -} + } +} + +void CatalogueController::save(const QString& repository) +{ + if(contains(_currentRepos, repository)) + { _lastSavedRepos[repository] = _currentRepos[repository]; } + else + { + SCIQLOP_ERROR(CatalogueController, "Trying to save an unknown repository"); + } +} + +// void CatalogueController::saveDB(const QString& destinationPath, const +// QString& repositoryName) +//{ +// if (!impl->m_CatalogueDao.saveDB(destinationPath, repositoryName)) +// { +// qCCritical(LOG_CatalogueController()) +// << tr("Impossible to saveDB %1 from %2 ").arg(repositoryName, +// destinationPath); +// } +//} + +// std::list> CatalogueController::retrieveEvents( +// const QString& repository) const +//{ +// QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : +// repository; + +// auto eventsShared = std::list> {}; +// auto events = +// impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName)); 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; +//} + +// std::list> +// CatalogueController::retrieveEventsFromCatalogue( +// std::shared_ptr catalogue) const +//{ +// auto eventsShared = std::list> {}; +// auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue); +// for (auto event : events) +// { +// eventsShared.push_back(std::make_shared(event)); +// } +// return eventsShared; +//} + +// void CatalogueController::updateEvent(std::shared_ptr event) +//{ +// event->setRepository(impl->toWorkRepository(event->getRepository())); + +// auto uniqueId = impl->eventUniqueKey(event); +// impl->m_KeysWithChanges.insert(uniqueId); + +// impl->m_CatalogueDao.updateEvent(*event); +//} + +// void CatalogueController::updateEventProduct(std::shared_ptr +// eventProduct) +//{ +// impl->m_CatalogueDao.updateEventProduct(*eventProduct); +//} + +// void CatalogueController::removeEvent(std::shared_ptr event) +//{ +// // Remove it from both repository and repository_work +// event->setRepository(impl->toWorkRepository(event->getRepository())); +// impl->m_CatalogueDao.removeEvent(*event); +// event->setRepository(impl->toSyncRepository(event->getRepository())); +// impl->m_CatalogueDao.removeEvent(*event); +// impl->savAllDB(); +//} + +// void CatalogueController::addEvent(std::shared_ptr event) +//{ +// event->setRepository(impl->toWorkRepository(event->getRepository())); + +// auto eventTemp = *event; +// impl->m_CatalogueDao.addEvent(eventTemp); + +// // Call update is necessary at the creation of add Event if it has some +// tags or some event +// // products +// if (!event->getEventProducts().empty() || !event->getTags().empty()) +// { + +// auto eventProductsTemp = eventTemp.getEventProducts(); +// auto eventProductTempUpdated = std::list {}; +// for (auto eventProductTemp : eventProductsTemp) +// { +// eventProductTemp.setEvent(eventTemp); +// eventProductTempUpdated.push_back(eventProductTemp); +// } +// eventTemp.setEventProducts(eventProductTempUpdated); + +// impl->m_CatalogueDao.updateEvent(eventTemp); +// } + +// auto workPred = impl->createFinder(event->getUniqId(), +// event->getRepository(), DBType::WORK); + +// auto workEvent = impl->m_CatalogueDao.getEvent(workPred); +// *event = workEvent; + +// auto uniqueId = impl->eventUniqueKey(event); +// impl->m_KeysWithChanges.insert(uniqueId); +//} + +// void CatalogueController::saveEvent(std::shared_ptr event) +//{ +// impl->saveEvent(event, true); +// impl->m_KeysWithChanges.remove(impl->eventUniqueKey(event)); +//} + +// void CatalogueController::discardEvent(std::shared_ptr event, bool& +// removed) +//{ +// auto syncPred = impl->createFinder(event->getUniqId(), +// event->getRepository(), DBType::SYNC); auto workPred = +// impl->createFinder(event->getUniqId(), event->getRepository(), +// DBType::WORK); + +// auto syncEvent = impl->m_CatalogueDao.getEvent(syncPred); +// if (!syncEvent.getUniqId().isNull()) +// { +// removed = false; +// impl->m_CatalogueDao.copyEvent( +// syncEvent, impl->toWorkRepository(event->getRepository()), true); + +// auto workEvent = impl->m_CatalogueDao.getEvent(workPred); +// *event = workEvent; +// impl->m_KeysWithChanges.remove(impl->eventUniqueKey(event)); +// } +// else +// { +// removed = true; +// // Since the element wasn't in sync repository. Discard it means +// remove it +// event->setRepository(impl->toWorkRepository(event->getRepository())); +// impl->m_CatalogueDao.removeEvent(*event); +// } +//} + +// bool CatalogueController::eventHasChanges(std::shared_ptr event) +// const +//{ +// return impl->m_KeysWithChanges.contains(impl->eventUniqueKey(event)); +//} + +// std::list> +// CatalogueController::retrieveCatalogues( +// const QString& repository) const +//{ +// QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : +// repository; + +// auto cataloguesShared = std::list> {}; +// auto catalogues = +// impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName)); +// for (auto catalogue : catalogues) +// { +// cataloguesShared.push_back(std::make_shared(catalogue)); +// } +// return cataloguesShared; +//} + +// void CatalogueController::addCatalogue(std::shared_ptr +// catalogue) +//{ +// catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); + +// auto catalogueTemp = *catalogue; +// impl->m_CatalogueDao.addCatalogue(catalogueTemp); + +// auto workPred +// = impl->createFinder(catalogue->getUniqId(), +// catalogue->getRepository(), DBType::WORK); + +// auto workCatalogue = impl->m_CatalogueDao.getCatalogue(workPred); +// *catalogue = workCatalogue; + +// auto uniqueId = impl->catalogueUniqueKey(catalogue); +// impl->m_KeysWithChanges.insert(uniqueId); +//} + +// void CatalogueController::updateCatalogue(std::shared_ptr +// catalogue) +//{ +// catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); + +// auto uniqueId = impl->catalogueUniqueKey(catalogue); +// impl->m_KeysWithChanges.insert(uniqueId); + +// impl->m_CatalogueDao.updateCatalogue(*catalogue); +//} + +// void CatalogueController::removeCatalogue(std::shared_ptr +// catalogue) +//{ +// // Remove it from both repository and repository_work +// catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); +// impl->m_CatalogueDao.removeCatalogue(*catalogue); +// catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository())); +// impl->m_CatalogueDao.removeCatalogue(*catalogue); +// impl->savAllDB(); +//} + +// void CatalogueController::saveCatalogue(std::shared_ptr +// catalogue) +//{ +// impl->saveCatalogue(catalogue, true); +// impl->m_KeysWithChanges.remove(impl->catalogueUniqueKey(catalogue)); + +// // remove key of events of the catalogue +// if (catalogue->getType() == CatalogueType::STATIC) +// { +// auto events = this->retrieveEventsFromCatalogue(catalogue); +// for (auto event : events) +// { +// impl->m_KeysWithChanges.remove(impl->eventUniqueKey(event)); +// } +// } +//} + +// void CatalogueController::discardCatalogue(std::shared_ptr +// catalogue, bool& removed) +//{ +// auto syncPred +// = impl->createFinder(catalogue->getUniqId(), +// catalogue->getRepository(), DBType::SYNC); +// auto workPred +// = impl->createFinder(catalogue->getUniqId(), +// catalogue->getRepository(), DBType::WORK); + +// auto syncCatalogue = impl->m_CatalogueDao.getCatalogue(syncPred); +// if (!syncCatalogue.getUniqId().isNull()) +// { +// removed = false; +// impl->m_CatalogueDao.copyCatalogue( +// syncCatalogue, impl->toWorkRepository(catalogue->getRepository()), +// true); + +// auto workCatalogue = impl->m_CatalogueDao.getCatalogue(workPred); +// *catalogue = workCatalogue; +// impl->m_KeysWithChanges.remove(impl->catalogueUniqueKey(catalogue)); +// } +// else +// { +// removed = true; +// // Since the element wasn't in sync repository. Discard it means +// remove it +// catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository())); +// impl->m_CatalogueDao.removeCatalogue(*catalogue); +// } +//} + +// void CatalogueController::saveAll() +//{ +// for (auto repository : impl->m_RepositoryList) +// { +// // Save Event +// auto events = this->retrieveEvents(repository); +// for (auto event : events) +// { +// impl->saveEvent(event, false); +// } + +// // Save Catalogue +// auto catalogues = this->retrieveCatalogues(repository); +// for (auto catalogue : catalogues) +// { +// impl->saveCatalogue(catalogue, false); +// } +// } + +// impl->savAllDB(); +// impl->m_KeysWithChanges.clear(); +//} + +// bool CatalogueController::hasChanges() const +//{ +// return !impl->m_KeysWithChanges.isEmpty(); +//} + +// QByteArray CatalogueController::mimeDataForEvents( +// const QVector>& events) const +//{ +// auto encodedData = QByteArray {}; + +// QMap idsPerRepository; +// for (auto event : events) +// { +// idsPerRepository[event->getRepository()] << event->getUniqId(); +// } + +// QDataStream stream { &encodedData, QIODevice::WriteOnly }; +// stream << idsPerRepository; + +// return encodedData; +//} + +// QVector> CatalogueController::eventsForMimeData( +// const QByteArray& mimeData) const +//{ +// auto events = QVector> {}; +// QDataStream stream { mimeData }; + +// QMap idsPerRepository; +// stream >> idsPerRepository; + +// for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend(); +// ++it) +// { +// auto repository = it.key(); +// auto allRepositoryEvent = retrieveEvents(repository); +// for (auto uuid : it.value()) +// { +// for (auto repositoryEvent : allRepositoryEvent) +// { +// if (uuid.toUuid() == repositoryEvent->getUniqId()) +// { +// events << repositoryEvent; +// } +// } +// } +// } + +// return events; +//} + +// QByteArray CatalogueController::mimeDataForCatalogues( +// const QVector>& catalogues) const +//{ +// auto encodedData = QByteArray {}; + +// QMap idsPerRepository; +// for (auto catalogue : catalogues) +// { +// idsPerRepository[catalogue->getRepository()] << +// catalogue->getUniqId(); +// } + +// QDataStream stream { &encodedData, QIODevice::WriteOnly }; +// stream << idsPerRepository; + +// return encodedData; +//} + +// QVector> +// CatalogueController::cataloguesForMimeData( +// const QByteArray& mimeData) const +//{ +// auto catalogues = QVector> {}; +// QDataStream stream { mimeData }; + +// QMap idsPerRepository; +// stream >> idsPerRepository; + +// for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend(); +// ++it) +// { +// auto repository = it.key(); +// auto allRepositoryCatalogues = retrieveCatalogues(repository); +// for (auto uuid : it.value()) +// { +// for (auto repositoryCatalogues : allRepositoryCatalogues) +// { +// if (uuid.toUuid() == repositoryCatalogues->getUniqId()) +// { +// catalogues << repositoryCatalogues; +// } +// } +// } +// } + +// return catalogues; +//} + +// void CatalogueController::initialize() +//{ +// qCDebug(LOG_CatalogueController()) +// << tr("CatalogueController init") << QThread::currentThread(); + +// impl->m_CatalogueDao.initialize(); +// auto defaultRepositoryLocation +// = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); + +// QDir defaultRepositoryLocationDir; +// if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) +// { +// defaultRepositoryLocationDir.cd(defaultRepositoryLocation); +// auto defaultRepository = +// defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT); + +// qCInfo(LOG_CatalogueController()) +// << tr("Persistant data loading from: ") << defaultRepository; + +// QDir dbDir(defaultRepository); +// impl->m_RepositoryList << REPOSITORY_DEFAULT; +// if (dbDir.exists()) +// { +// auto dirName = dbDir.dirName(); + +// if (impl->m_CatalogueDao.addDB(defaultRepository, dirName)) +// { +// impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName)); +// } +// } +// else +// { +// qCInfo(LOG_CatalogueController()) +// << tr("Initialisation of Default repository detected") << +// defaultRepository; +// } +// } +// else +// { +// qCWarning(LOG_CatalogueController()) +// << tr("Cannot load the persistent default repository from ") +// << defaultRepositoryLocation; +// } + +// qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END"); +//} + +// QString CatalogueController::CatalogueControllerPrivate::eventUniqueKey( +// const std::shared_ptr& event) const +//{ +// return event->getUniqId().toString().append(event->getRepository()); +//} + +// QString CatalogueController::CatalogueControllerPrivate::catalogueUniqueKey( +// const std::shared_ptr& catalogue) const +//{ +// return +// catalogue->getUniqId().toString().append(catalogue->getRepository()); +//} + +// void CatalogueController::CatalogueControllerPrivate::copyDBtoDB( +// const QString& dbFrom, const QString& dbTo) +//{ +// // auto cataloguesShared = std::list >{}; +// auto catalogues = m_CatalogueDao.getCatalogues(dbFrom); +// auto events = m_CatalogueDao.getEvents(dbFrom); +// for (auto catalogue : catalogues) +// { +// m_CatalogueDao.copyCatalogue(catalogue, dbTo, true); +// } + +// for (auto event : events) +// { +// m_CatalogueDao.copyEvent(event, dbTo, true); +// } +//} + +// QString +// CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString +// repository) +//{ +// auto syncRepository = toSyncRepository(repository); + +// return QString("%1%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX); +//} + +// QString +// CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString +// repository) +//{ +// auto syncRepository = repository; +// if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) +// { +// syncRepository.remove(REPOSITORY_WORK_SUFFIX); +// } +// else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) +// { +// syncRepository.remove(REPOSITORY_TRASH_SUFFIX); +// } +// return syncRepository; +//} + +// void CatalogueController::CatalogueControllerPrivate::savAllDB() +//{ +// for (auto repository : m_RepositoryList) +// { +// auto defaultRepositoryLocation +// = +// QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); +// m_CatalogueDao.saveDB(defaultRepositoryLocation, repository); +// } +//} + +// void CatalogueController::CatalogueControllerPrivate::saveEvent( +// std::shared_ptr event, bool persist) +//{ +// m_CatalogueDao.copyEvent(*event, toSyncRepository(event->getRepository()), +// true); if (persist) +// { +// savAllDB(); +// } +//} + +// void CatalogueController::CatalogueControllerPrivate::saveCatalogue( +// std::shared_ptr catalogue, bool persist) +//{ +// m_CatalogueDao.copyCatalogue(*catalogue, +// toSyncRepository(catalogue->getRepository()), true); if (persist) +// { +// savAllDB(); +// } +//} + +// std::shared_ptr +// CatalogueController::CatalogueControllerPrivate::createFinder( +// const QUuid& uniqId, const QString& repository, DBType type) +//{ +// // update catalogue parameter +// auto uniqIdPredicate = std::make_shared( +// QString { "uniqId" }, uniqId, ComparaisonOperation::EQUALEQUAL); + +// auto repositoryType = repository; +// switch (type) +// { +// case DBType::SYNC: +// repositoryType = toSyncRepository(repositoryType); +// break; +// case DBType::WORK: +// repositoryType = toWorkRepository(repositoryType); +// break; +// case DBType::TRASH: +// default: +// break; +// } + +// auto repositoryPredicate = std::make_shared( +// QString { "repository" }, repositoryType, +// ComparaisonOperation::EQUALEQUAL); + +// auto finderPred = +// std::make_shared(CompoundOperation::AND); +// finderPred->AddRequestPredicate(uniqIdPredicate); +// finderPred->AddRequestPredicate(repositoryPredicate); + +// return finderPred; +//} diff --git a/src/pybind11_wrappers/CatalogWrappers.cpp b/src/pybind11_wrappers/CatalogWrappers.cpp index 1a96506..5d46bb2 100644 --- a/src/pybind11_wrappers/CatalogWrappers.cpp +++ b/src/pybind11_wrappers/CatalogWrappers.cpp @@ -1,80 +1,81 @@ -#include -#include +#include "pywrappers_common.h" #include +#include #include +#include #include -#include -#include -#include "pywrappers_common.h" -#include #include +#include +#include +#include #include +#include #include #include -#include namespace py = pybind11; -std::ostream &operator <<(std::ostream& os, const DBEvent& e) +std::ostream& operator<<(std::ostream& os, const DBEvent& e) { os << std::endl; return os; } -#define JAVA_LIKE_PROPERTY(name, className) .def_property("##name", &className::get##name, &className::set##name) +#define JAVA_LIKE_PROPERTY(name, className) \ + .def_property("##name", &className::get##name, &className::set##name) -PYBIND11_MODULE(pysciqlopcatalogs,m){ +PYBIND11_MODULE(pysciqlopcatalogs, m) +{ - py::class_>(m,"DBEventProduct") - JAVA_LIKE_PROPERTY(TStart, DBEventProduct) - JAVA_LIKE_PROPERTY(TEnd, DBEventProduct) - JAVA_LIKE_PROPERTY(ProductId, DBEventProduct) - JAVA_LIKE_PROPERTY(CreationDateTime, DBEventProduct) - JAVA_LIKE_PROPERTY(ModificationDateTime, DBEventProduct) - JAVA_LIKE_PROPERTY(Event, DBEventProduct) - ; + // py::class_>(m,"DBEventProduct") + // JAVA_LIKE_PROPERTY(TStart, DBEventProduct) + // JAVA_LIKE_PROPERTY(TEnd, DBEventProduct) + // JAVA_LIKE_PROPERTY(ProductId, DBEventProduct) + // JAVA_LIKE_PROPERTY(CreationDateTime, DBEventProduct) + // JAVA_LIKE_PROPERTY(ModificationDateTime, DBEventProduct) + // JAVA_LIKE_PROPERTY(Event, DBEventProduct) + // ; - py::class_>(m, "DBEvent") - JAVA_LIKE_PROPERTY(Name,DBEvent) - JAVA_LIKE_PROPERTY(UniqId,DBEvent) - JAVA_LIKE_PROPERTY(Author,DBEvent) - JAVA_LIKE_PROPERTY(Repository,DBEvent) - JAVA_LIKE_PROPERTY(CreationDateTime,DBEvent) - JAVA_LIKE_PROPERTY(ModificationDateTime,DBEvent) - JAVA_LIKE_PROPERTY(EventProducts,DBEvent) - .def_property_readonly("TStart", &DBEvent::getTStart) - .def_property_readonly("TEnd", &DBEvent::getTEnd) - .def("__repr__",__repr__); + // py::class_>(m, "DBEvent") + // JAVA_LIKE_PROPERTY(Name,DBEvent) + // JAVA_LIKE_PROPERTY(UniqId,DBEvent) + // JAVA_LIKE_PROPERTY(Author,DBEvent) + // JAVA_LIKE_PROPERTY(Repository,DBEvent) + // JAVA_LIKE_PROPERTY(CreationDateTime,DBEvent) + // JAVA_LIKE_PROPERTY(ModificationDateTime,DBEvent) + // JAVA_LIKE_PROPERTY(EventProducts,DBEvent) + // .def_property_readonly("TStart", &DBEvent::getTStart) + // .def_property_readonly("TEnd", &DBEvent::getTEnd) + // .def("__repr__",__repr__); - py::class_>(m,"DBEventProduct") - JAVA_LIKE_PROPERTY(CatalogueId, DBCatalogue) - JAVA_LIKE_PROPERTY(UniqId, DBCatalogue) - JAVA_LIKE_PROPERTY(Name, DBCatalogue) - JAVA_LIKE_PROPERTY(Author, DBCatalogue) - JAVA_LIKE_PROPERTY(Repository, DBCatalogue) - JAVA_LIKE_PROPERTY(CreationDateTime, DBCatalogue) - JAVA_LIKE_PROPERTY(ModificationDateTime, DBCatalogue) - ; + // py::class_>(m,"DBEventProduct") + // JAVA_LIKE_PROPERTY(CatalogueId, DBCatalogue) + // JAVA_LIKE_PROPERTY(UniqId, DBCatalogue) + // JAVA_LIKE_PROPERTY(Name, DBCatalogue) + // JAVA_LIKE_PROPERTY(Author, DBCatalogue) + // JAVA_LIKE_PROPERTY(Repository, DBCatalogue) + // JAVA_LIKE_PROPERTY(CreationDateTime, DBCatalogue) + // JAVA_LIKE_PROPERTY(ModificationDateTime, DBCatalogue) + // ; - py::class_(m, "CatalogueController") - .def("addDB", &CatalogueController::addDB) - .def("saveDB", &CatalogueController::saveDB) - .def("addEvent", &CatalogueController::addEvent) - .def("updateEvent", &CatalogueController::updateEvent) - .def("updateEventProduct", &CatalogueController::updateEventProduct) - .def("removeEvent", &CatalogueController::removeEvent) - .def("saveEvent", &CatalogueController::saveEvent) - .def("discardEvent", &CatalogueController::discardEvent) - .def("eventHasChanges", &CatalogueController::eventHasChanges) - .def("addCatalogue", &CatalogueController::addCatalogue) - .def("updateCatalogue", &CatalogueController::updateCatalogue) - .def("removeCatalogue", &CatalogueController::removeCatalogue) - .def("saveCatalogue", &CatalogueController::saveCatalogue) - .def("discardCatalogue", &CatalogueController::discardCatalogue) - .def("saveAll", &CatalogueController::saveAll) - .def("hasChanges", &CatalogueController::hasChanges) - ; + // py::class_(m, "CatalogueController") + // .def("addDB", &CatalogueController::addDB) + // .def("saveDB", &CatalogueController::saveDB) + // .def("addEvent", &CatalogueController::addEvent) + // .def("updateEvent", &CatalogueController::updateEvent) + // .def("updateEventProduct", &CatalogueController::updateEventProduct) + // .def("removeEvent", &CatalogueController::removeEvent) + // .def("saveEvent", &CatalogueController::saveEvent) + // .def("discardEvent", &CatalogueController::discardEvent) + // .def("eventHasChanges", &CatalogueController::eventHasChanges) + // .def("addCatalogue", &CatalogueController::addCatalogue) + // .def("updateCatalogue", &CatalogueController::updateCatalogue) + // .def("removeCatalogue", &CatalogueController::removeCatalogue) + // .def("saveCatalogue", &CatalogueController::saveCatalogue) + // .def("discardCatalogue", &CatalogueController::discardCatalogue) + // .def("saveAll", &CatalogueController::saveAll) + // .def("hasChanges", &CatalogueController::hasChanges) + // ; } - diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 441c4b1..e5b11d7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -47,3 +47,5 @@ declare_test(TestDownloader TestDownloader Network/TestDownloader.cpp "sciqlopco declare_test(TestVariableController2 TestVariableController2 Variable/TestVariableController2.cpp "sciqlopcore;TestUtils;Qt5::Test") declare_test(TestVariableController2Async TestVariableController2Async Variable/TestVariableController2Async.cpp "sciqlopcore;TestUtils;Qt5::Test") declare_test(TestVariableController2WithSync TestVariableController2WithSync Variable/TestVariableController2WithSync.cpp "sciqlopcore;TestUtils;Qt5::Test") + +declare_test(TestCatalogueController TestCatalogueController CatalogueController/TestCatalogueController.cpp "sciqlopcore;TestUtils;Qt5::Test") diff --git a/tests/CatalogueController/TestCatalogueController.cpp b/tests/CatalogueController/TestCatalogueController.cpp new file mode 100644 index 0000000..5354720 --- /dev/null +++ b/tests/CatalogueController/TestCatalogueController.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include + + +class TestCatalogueController : public QObject +{ + Q_OBJECT +public: + explicit TestCatalogueController(QObject* parent = nullptr) : QObject(parent) {} +signals: + +private slots: + void initTestCase() {} + void cleanupTestCase() {} +}; + + +QTEST_MAIN(TestCatalogueController) + +#include "TestCatalogueController.moc"