##// END OF EJS Templates
CatalogueController: add few basic methods + commit the one not yet implemented
trabillard -
r1161:043d6b3a4bf6
parent child
Show More
@@ -1,67 +1,70
1 1 #ifndef SCIQLOP_CATALOGUECONTROLLER_H
2 2 #define SCIQLOP_CATALOGUECONTROLLER_H
3 3
4 4 #include "CoreGlobal.h"
5 5
6 6 #include <Data/SqpRange.h>
7 7
8 8 #include <QLoggingCategory>
9 9 #include <QObject>
10 10 #include <QUuid>
11 11
12 12 #include <Common/spimpl.h>
13 13
14 14 #include <memory>
15 15
16 16 class DBCatalogue;
17 17 class DBEvent;
18 18
19 19 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController)
20 20
21 21 class DataSourceItem;
22 22 class Variable;
23 23
24 24 /**
25 25 * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI
26 26 * library.
27 27 */
28 28 class SCIQLOP_CORE_EXPORT CatalogueController : public QObject {
29 29 Q_OBJECT
30 30 public:
31 31 explicit CatalogueController(QObject *parent = 0);
32 32 virtual ~CatalogueController();
33 33
34 34 // DB
35 QStringList getRepositories() const;
35 // QStringList getRepositories() const;
36 36 void addDB(const QString &dbPath);
37 37 void saveDB(const QString &destinationPath, const QString &repository);
38 38
39 39 // Event
40 bool createEvent(const QString &name);
40 // bool createEvent(const QString &name);
41 41 std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const;
42 42 std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const;
43 void updateEvent(std::shared_ptr<DBEvent> event);
44 void trashEvent(std::shared_ptr<DBEvent> event);
45 void removeEvent(std::shared_ptr<DBEvent> event);
46 void restore(QUuid eventId);
47 void saveEvent(std::shared_ptr<DBEvent> event);
43 std::list<std::shared_ptr<DBEvent> >
44 retrieveEventsFromCatalogue(const QString &repository,
45 std::shared_ptr<DBCatalogue> catalogue) const;
46 // void updateEvent(std::shared_ptr<DBEvent> event);
47 // void trashEvent(std::shared_ptr<DBEvent> event);
48 // void removeEvent(std::shared_ptr<DBEvent> event);
49 // void restore(QUuid eventId);
50 // void saveEvent(std::shared_ptr<DBEvent> event);
48 51
49 52 // Catalogue
50 bool createCatalogue(const QString &name, QVector<QUuid> eventList);
51 void getCatalogues(const QString &repository) const;
52 void removeEvent(QUuid catalogueId, const QString &repository);
53 void saveCatalogue(std::shared_ptr<DBEvent> event);
53 // bool createCatalogue(const QString &name, QVector<QUuid> eventList);
54 std::list<std::shared_ptr<DBCatalogue> > getCatalogues(const QString &repository) const;
55 // void removeEvent(QUuid catalogueId, const QString &repository);
56 // void saveCatalogue(std::shared_ptr<DBEvent> event);
54 57
55 58 public slots:
56 59 /// Manage init/end of the controller
57 60 void initialize();
58 61 void finalize();
59 62
60 63 private:
61 64 void waitForFinish();
62 65
63 66 class CatalogueControllerPrivate;
64 67 spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl;
65 68 };
66 69
67 70 #endif // SCIQLOP_CATALOGUECONTROLLER_H
@@ -1,139 +1,162
1 1 #include <Catalogue/CatalogueController.h>
2 2
3 3 #include <Variable/Variable.h>
4 4
5 5 #include <CatalogueDao.h>
6 6
7 7 #include <ComparaisonPredicate.h>
8 8 #include <CompoundPredicate.h>
9 9 #include <DBCatalogue.h>
10 10 #include <DBEvent.h>
11 11 #include <DBTag.h>
12 12 #include <IRequestPredicate.h>
13 13
14 14 #include <QMutex>
15 15 #include <QThread>
16 16
17 17 #include <QDir>
18 18 #include <QStandardPaths>
19 19
20 20 Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController")
21 21
22 22 namespace {
23 23
24 24 static QString REPOSITORY_WORK_SUFFIX = QString{"Work"};
25 25
26 26 }
27 27
28 28 class CatalogueController::CatalogueControllerPrivate {
29 29 public:
30 30 QMutex m_WorkingMutex;
31 31 CatalogueDao m_CatalogueDao;
32 32
33 33 std::list<QString> m_RepositoryList;
34 34 };
35 35
36 36 CatalogueController::CatalogueController(QObject *parent)
37 37 : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>()}
38 38 {
39 39 qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction")
40 40 << QThread::currentThread();
41 41 }
42 42
43 43 CatalogueController::~CatalogueController()
44 44 {
45 45 qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction")
46 46 << QThread::currentThread();
47 47 this->waitForFinish();
48 48 }
49 49
50 50 void CatalogueController::addDB(const QString &dbPath)
51 51 {
52 52 QDir dbDir(dbPath);
53 53 if (dbDir.exists()) {
54 54 auto dirName = dbDir.dirName();
55 55
56 56 if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName)
57 57 != impl->m_RepositoryList.cend()) {
58 58 qCCritical(LOG_CatalogueController())
59 59 << tr("Impossible to addDB that is already loaded");
60 60 }
61 61
62 62 if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) {
63 63 qCCritical(LOG_CatalogueController())
64 64 << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath);
65 65 }
66 66 else {
67 67 impl->m_RepositoryList.push_back(dirName);
68 68 }
69 69 }
70 70 else {
71 71 qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ")
72 72 << dbPath;
73 73 }
74 74 }
75 75
76 76 void CatalogueController::saveDB(const QString &destinationPath, const QString &repository)
77 77 {
78 78 if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) {
79 79 qCCritical(LOG_CatalogueController())
80 80 << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath);
81 81 }
82 82 }
83 83
84 84 std::list<std::shared_ptr<DBEvent> >
85 85 CatalogueController::retrieveEvents(const QString &repository) const
86 86 {
87 87 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
88 88 auto events = impl->m_CatalogueDao.getEvents(repository);
89 89 for (auto event : events) {
90 90 eventsShared.push_back(std::make_shared<DBEvent>(event));
91 91 }
92 92 return eventsShared;
93 93 }
94 94
95 95 std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const
96 96 {
97 97 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
98 98 for (auto repository : impl->m_RepositoryList) {
99 99 eventsShared.splice(eventsShared.end(), retrieveEvents(repository));
100 100 }
101 101
102 102 return eventsShared;
103 103 }
104 104
105 std::list<std::shared_ptr<DBEvent> >
106 CatalogueController::retrieveEventsFromCatalogue(const QString &repository,
107 std::shared_ptr<DBCatalogue> catalogue) const
108 {
109 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
110 auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue);
111 for (auto event : events) {
112 eventsShared.push_back(std::make_shared<DBEvent>(event));
113 }
114 return eventsShared;
115 }
116
117 std::list<std::shared_ptr<DBCatalogue> >
118 CatalogueController::getCatalogues(const QString &repository) const
119 {
120 auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
121 auto catalogues = impl->m_CatalogueDao.getCatalogues(repository);
122 for (auto catalogue : catalogues) {
123 cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue));
124 }
125 return cataloguesShared;
126 }
127
105 128 void CatalogueController::initialize()
106 129 {
107 130 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
108 131 << QThread::currentThread();
109 132 impl->m_WorkingMutex.lock();
110 133 impl->m_CatalogueDao.initialize();
111 134 auto defaultRepositoryLocation
112 135 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
113 136
114 137 QDir defaultRepositoryLocationDir;
115 138 if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) {
116 139 defaultRepositoryLocationDir.cd(defaultRepositoryLocation);
117 140 auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT);
118 141 qCInfo(LOG_CatalogueController())
119 142 << tr("Persistant data loading from: ") << defaultRepository;
120 143 this->addDB(defaultRepository);
121 144 }
122 145 else {
123 146 qCWarning(LOG_CatalogueController())
124 147 << tr("Cannot load the persistent default repository from ")
125 148 << defaultRepositoryLocation;
126 149 }
127 150
128 151 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
129 152 }
130 153
131 154 void CatalogueController::finalize()
132 155 {
133 156 impl->m_WorkingMutex.unlock();
134 157 }
135 158
136 159 void CatalogueController::waitForFinish()
137 160 {
138 161 QMutexLocker locker{&impl->m_WorkingMutex};
139 162 }
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved

Status change > Approved

You need to be logged in to leave comments. Login now