##// END OF EJS Templates
Add missing methods
perrinel -
r1282:2f18e2b8f0cc
parent child
Show More
@@ -1,75 +1,77
1 #ifndef SCIQLOP_CATALOGUECONTROLLER_H
1 #ifndef SCIQLOP_CATALOGUECONTROLLER_H
2 #define SCIQLOP_CATALOGUECONTROLLER_H
2 #define SCIQLOP_CATALOGUECONTROLLER_H
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5
5
6 #include <Data/SqpRange.h>
6 #include <Data/SqpRange.h>
7
7
8 #include <QLoggingCategory>
8 #include <QLoggingCategory>
9 #include <QObject>
9 #include <QObject>
10 #include <QUuid>
10 #include <QUuid>
11
11
12 #include <Common/spimpl.h>
12 #include <Common/spimpl.h>
13
13
14 #include <memory>
14 #include <memory>
15
15
16 class DBCatalogue;
16 class DBCatalogue;
17 class DBEvent;
17 class DBEvent;
18 class DBEventProduct;
18
19
19 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController)
20 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController)
20
21
21 class DataSourceItem;
22 class DataSourceItem;
22 class Variable;
23 class Variable;
23
24
24 /**
25 /**
25 * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI
26 * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI
26 * library.
27 * library.
27 */
28 */
28 class SCIQLOP_CORE_EXPORT CatalogueController : public QObject {
29 class SCIQLOP_CORE_EXPORT CatalogueController : public QObject {
29 Q_OBJECT
30 Q_OBJECT
30 public:
31 public:
31 explicit CatalogueController(QObject *parent = 0);
32 explicit CatalogueController(QObject *parent = 0);
32 virtual ~CatalogueController();
33 virtual ~CatalogueController();
33
34
34 // DB
35 // DB
35 QStringList getRepositories() const;
36 QStringList getRepositories() const;
36 void addDB(const QString &dbPath);
37 void addDB(const QString &dbPath);
37 void saveDB(const QString &destinationPath, const QString &repository);
38 void saveDB(const QString &destinationPath, const QString &repository);
38
39
39 // Event
40 // Event
40 /// retrieveEvents with empty repository retrieve them from the default repository
41 /// retrieveEvents with empty repository retrieve them from the default repository
41 std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const;
42 std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const;
42 std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const;
43 std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const;
43 std::list<std::shared_ptr<DBEvent> >
44 std::list<std::shared_ptr<DBEvent> >
44 retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const;
45 retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const;
45 void addEvent(std::shared_ptr<DBEvent> event);
46 void addEvent(std::shared_ptr<DBEvent> event);
46 void updateEvent(std::shared_ptr<DBEvent> event);
47 void updateEvent(std::shared_ptr<DBEvent> event);
48 void updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct);
47 void removeEvent(std::shared_ptr<DBEvent> event);
49 void removeEvent(std::shared_ptr<DBEvent> event);
48 // void trashEvent(std::shared_ptr<DBEvent> event);
50 // void trashEvent(std::shared_ptr<DBEvent> event);
49 // void restore(QUuid eventId);
51 // void restore(QUuid eventId);
50 void saveEvent(std::shared_ptr<DBEvent> event);
52 void saveEvent(std::shared_ptr<DBEvent> event);
51
53
52 // Catalogue
54 // Catalogue
53 // bool createCatalogue(const QString &name, QVector<QUuid> eventList);
55 // bool createCatalogue(const QString &name, QVector<QUuid> eventList);
54 /// retrieveEvents with empty repository retrieve them from the default repository
56 /// retrieveEvents with empty repository retrieve them from the default repository
55 std::list<std::shared_ptr<DBCatalogue> > retrieveCatalogues(const QString &repository
57 std::list<std::shared_ptr<DBCatalogue> > retrieveCatalogues(const QString &repository
56 = QString()) const;
58 = QString()) const;
57 void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue);
59 void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue);
58 void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue);
60 void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue);
59 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue);
61 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue);
60
62
61 void saveAll();
63 void saveAll();
62
64
63 public slots:
65 public slots:
64 /// Manage init/end of the controller
66 /// Manage init/end of the controller
65 void initialize();
67 void initialize();
66 void finalize();
68 void finalize();
67
69
68 private:
70 private:
69 void waitForFinish();
71 void waitForFinish();
70
72
71 class CatalogueControllerPrivate;
73 class CatalogueControllerPrivate;
72 spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl;
74 spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl;
73 };
75 };
74
76
75 #endif // SCIQLOP_CATALOGUECONTROLLER_H
77 #endif // SCIQLOP_CATALOGUECONTROLLER_H
@@ -1,329 +1,334
1 #include <Catalogue/CatalogueController.h>
1 #include <Catalogue/CatalogueController.h>
2
2
3 #include <Variable/Variable.h>
3 #include <Variable/Variable.h>
4
4
5 #include <CatalogueDao.h>
5 #include <CatalogueDao.h>
6
6
7 #include <ComparaisonPredicate.h>
7 #include <ComparaisonPredicate.h>
8 #include <CompoundPredicate.h>
8 #include <CompoundPredicate.h>
9 #include <DBCatalogue.h>
9 #include <DBCatalogue.h>
10 #include <DBEvent.h>
10 #include <DBEvent.h>
11 #include <DBEventProduct.h>
11 #include <DBEventProduct.h>
12 #include <DBTag.h>
12 #include <DBTag.h>
13 #include <IRequestPredicate.h>
13 #include <IRequestPredicate.h>
14
14
15 #include <QMutex>
15 #include <QMutex>
16 #include <QThread>
16 #include <QThread>
17
17
18 #include <QDir>
18 #include <QDir>
19 #include <QStandardPaths>
19 #include <QStandardPaths>
20
20
21 Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController")
21 Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController")
22
22
23 namespace {
23 namespace {
24
24
25 static QString REPOSITORY_WORK_SUFFIX = QString{"_work"};
25 static QString REPOSITORY_WORK_SUFFIX = QString{"_work"};
26 static QString REPOSITORY_TRASH_SUFFIX = QString{"_trash"};
26 static QString REPOSITORY_TRASH_SUFFIX = QString{"_trash"};
27 }
27 }
28
28
29 class CatalogueController::CatalogueControllerPrivate {
29 class CatalogueController::CatalogueControllerPrivate {
30
30
31 public:
31 public:
32 explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {}
32 explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {}
33
33
34 QMutex m_WorkingMutex;
34 QMutex m_WorkingMutex;
35 CatalogueDao m_CatalogueDao;
35 CatalogueDao m_CatalogueDao;
36
36
37 QStringList m_RepositoryList;
37 QStringList m_RepositoryList;
38 CatalogueController *m_Q;
38 CatalogueController *m_Q;
39
39
40 void copyDBtoDB(const QString &dbFrom, const QString &dbTo);
40 void copyDBtoDB(const QString &dbFrom, const QString &dbTo);
41 QString toWorkRepository(QString repository);
41 QString toWorkRepository(QString repository);
42 QString toSyncRepository(QString repository);
42 QString toSyncRepository(QString repository);
43 void savAllDB();
43 void savAllDB();
44
44
45 void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true);
45 void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true);
46 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist = true);
46 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist = true);
47 };
47 };
48
48
49 CatalogueController::CatalogueController(QObject *parent)
49 CatalogueController::CatalogueController(QObject *parent)
50 : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>(this)}
50 : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>(this)}
51 {
51 {
52 qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction")
52 qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction")
53 << QThread::currentThread();
53 << QThread::currentThread();
54 }
54 }
55
55
56 CatalogueController::~CatalogueController()
56 CatalogueController::~CatalogueController()
57 {
57 {
58 qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction")
58 qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction")
59 << QThread::currentThread();
59 << QThread::currentThread();
60 this->waitForFinish();
60 this->waitForFinish();
61 }
61 }
62
62
63 QStringList CatalogueController::getRepositories() const
63 QStringList CatalogueController::getRepositories() const
64 {
64 {
65 return impl->m_RepositoryList;
65 return impl->m_RepositoryList;
66 }
66 }
67
67
68 void CatalogueController::addDB(const QString &dbPath)
68 void CatalogueController::addDB(const QString &dbPath)
69 {
69 {
70 QDir dbDir(dbPath);
70 QDir dbDir(dbPath);
71 if (dbDir.exists()) {
71 if (dbDir.exists()) {
72 auto dirName = dbDir.dirName();
72 auto dirName = dbDir.dirName();
73
73
74 if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName)
74 if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName)
75 != impl->m_RepositoryList.cend()) {
75 != impl->m_RepositoryList.cend()) {
76 qCCritical(LOG_CatalogueController())
76 qCCritical(LOG_CatalogueController())
77 << tr("Impossible to addDB that is already loaded");
77 << tr("Impossible to addDB that is already loaded");
78 }
78 }
79
79
80 if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) {
80 if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) {
81 qCCritical(LOG_CatalogueController())
81 qCCritical(LOG_CatalogueController())
82 << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath);
82 << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath);
83 }
83 }
84 else {
84 else {
85 impl->m_RepositoryList << dirName;
85 impl->m_RepositoryList << dirName;
86 impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName));
86 impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName));
87 }
87 }
88 }
88 }
89 else {
89 else {
90 qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ")
90 qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ")
91 << dbPath;
91 << dbPath;
92 }
92 }
93 }
93 }
94
94
95 void CatalogueController::saveDB(const QString &destinationPath, const QString &repository)
95 void CatalogueController::saveDB(const QString &destinationPath, const QString &repository)
96 {
96 {
97 if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) {
97 if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) {
98 qCCritical(LOG_CatalogueController())
98 qCCritical(LOG_CatalogueController())
99 << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath);
99 << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath);
100 }
100 }
101 }
101 }
102
102
103 std::list<std::shared_ptr<DBEvent> >
103 std::list<std::shared_ptr<DBEvent> >
104 CatalogueController::retrieveEvents(const QString &repository) const
104 CatalogueController::retrieveEvents(const QString &repository) const
105 {
105 {
106 QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository;
106 QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository;
107
107
108 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
108 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
109 auto events = impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName));
109 auto events = impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName));
110 for (auto event : events) {
110 for (auto event : events) {
111 eventsShared.push_back(std::make_shared<DBEvent>(event));
111 eventsShared.push_back(std::make_shared<DBEvent>(event));
112 }
112 }
113 return eventsShared;
113 return eventsShared;
114 }
114 }
115
115
116 std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const
116 std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const
117 {
117 {
118 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
118 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
119 for (auto repository : impl->m_RepositoryList) {
119 for (auto repository : impl->m_RepositoryList) {
120 eventsShared.splice(eventsShared.end(), retrieveEvents(repository));
120 eventsShared.splice(eventsShared.end(), retrieveEvents(repository));
121 }
121 }
122
122
123 return eventsShared;
123 return eventsShared;
124 }
124 }
125
125
126 std::list<std::shared_ptr<DBEvent> >
126 std::list<std::shared_ptr<DBEvent> >
127 CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const
127 CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const
128 {
128 {
129 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
129 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
130 auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue);
130 auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue);
131 for (auto event : events) {
131 for (auto event : events) {
132 eventsShared.push_back(std::make_shared<DBEvent>(event));
132 eventsShared.push_back(std::make_shared<DBEvent>(event));
133 }
133 }
134 return eventsShared;
134 return eventsShared;
135 }
135 }
136
136
137 void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event)
137 void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event)
138 {
138 {
139 event->setRepository(impl->toWorkRepository(event->getRepository()));
139 event->setRepository(impl->toWorkRepository(event->getRepository()));
140
140
141 impl->m_CatalogueDao.updateEvent(*event);
141 impl->m_CatalogueDao.updateEvent(*event);
142 }
142 }
143
143
144 void CatalogueController::updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct)
145 {
146 impl->m_CatalogueDao.updateEventProduct(*eventProduct);
147 }
148
144 void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event)
149 void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event)
145 {
150 {
146 // Remove it from both repository and repository_work
151 // Remove it from both repository and repository_work
147 event->setRepository(impl->toWorkRepository(event->getRepository()));
152 event->setRepository(impl->toWorkRepository(event->getRepository()));
148 impl->m_CatalogueDao.removeEvent(*event);
153 impl->m_CatalogueDao.removeEvent(*event);
149 event->setRepository(impl->toSyncRepository(event->getRepository()));
154 event->setRepository(impl->toSyncRepository(event->getRepository()));
150 impl->m_CatalogueDao.removeEvent(*event);
155 impl->m_CatalogueDao.removeEvent(*event);
151 }
156 }
152
157
153 void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
158 void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
154 {
159 {
155 event->setRepository(impl->toWorkRepository(event->getRepository()));
160 event->setRepository(impl->toWorkRepository(event->getRepository()));
156
161
157 auto eventTemp = *event;
162 auto eventTemp = *event;
158 impl->m_CatalogueDao.addEvent(eventTemp);
163 impl->m_CatalogueDao.addEvent(eventTemp);
159
164
160 // Call update is necessary at the creation of add Event if it has some tags or some event
165 // Call update is necessary at the creation of add Event if it has some tags or some event
161 // products
166 // products
162 if (!event->getEventProducts().empty() || !event->getTags().empty()) {
167 if (!event->getEventProducts().empty() || !event->getTags().empty()) {
163
168
164 auto eventProductsTemp = eventTemp.getEventProducts();
169 auto eventProductsTemp = eventTemp.getEventProducts();
165 auto eventProductTempUpdated = std::list<DBEventProduct>{};
170 auto eventProductTempUpdated = std::list<DBEventProduct>{};
166 for (auto eventProductTemp : eventProductsTemp) {
171 for (auto eventProductTemp : eventProductsTemp) {
167 eventProductTemp.setEvent(eventTemp);
172 eventProductTemp.setEvent(eventTemp);
168 eventProductTempUpdated.push_back(eventProductTemp);
173 eventProductTempUpdated.push_back(eventProductTemp);
169 }
174 }
170 eventTemp.setEventProducts(eventProductTempUpdated);
175 eventTemp.setEventProducts(eventProductTempUpdated);
171
176
172 impl->m_CatalogueDao.updateEvent(eventTemp);
177 impl->m_CatalogueDao.updateEvent(eventTemp);
173 }
178 }
174 }
179 }
175
180
176 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
181 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
177 {
182 {
178 impl->saveEvent(event, true);
183 impl->saveEvent(event, true);
179 }
184 }
180
185
181 std::list<std::shared_ptr<DBCatalogue> >
186 std::list<std::shared_ptr<DBCatalogue> >
182 CatalogueController::retrieveCatalogues(const QString &repository) const
187 CatalogueController::retrieveCatalogues(const QString &repository) const
183 {
188 {
184 QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository;
189 QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository;
185
190
186 auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
191 auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
187 auto catalogues = impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName));
192 auto catalogues = impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName));
188 for (auto catalogue : catalogues) {
193 for (auto catalogue : catalogues) {
189 cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue));
194 cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue));
190 }
195 }
191 return cataloguesShared;
196 return cataloguesShared;
192 }
197 }
193
198
194 void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue)
199 void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue)
195 {
200 {
196 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
201 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
197
202
198 impl->m_CatalogueDao.updateCatalogue(*catalogue);
203 impl->m_CatalogueDao.updateCatalogue(*catalogue);
199 }
204 }
200
205
201 void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue)
206 void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue)
202 {
207 {
203 // Remove it from both repository and repository_work
208 // Remove it from both repository and repository_work
204 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
209 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
205 impl->m_CatalogueDao.removeCatalogue(*catalogue);
210 impl->m_CatalogueDao.removeCatalogue(*catalogue);
206 catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository()));
211 catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository()));
207 impl->m_CatalogueDao.removeCatalogue(*catalogue);
212 impl->m_CatalogueDao.removeCatalogue(*catalogue);
208 }
213 }
209
214
210 void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue)
215 void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue)
211 {
216 {
212 impl->saveCatalogue(catalogue, true);
217 impl->saveCatalogue(catalogue, true);
213 }
218 }
214
219
215 void CatalogueController::saveAll()
220 void CatalogueController::saveAll()
216 {
221 {
217 for (auto repository : impl->m_RepositoryList) {
222 for (auto repository : impl->m_RepositoryList) {
218 // Save Event
223 // Save Event
219 auto events = this->retrieveEvents(repository);
224 auto events = this->retrieveEvents(repository);
220 for (auto event : events) {
225 for (auto event : events) {
221 impl->saveEvent(event, false);
226 impl->saveEvent(event, false);
222 }
227 }
223
228
224 // Save Catalogue
229 // Save Catalogue
225 auto catalogues = this->retrieveCatalogues(repository);
230 auto catalogues = this->retrieveCatalogues(repository);
226 for (auto catalogue : catalogues) {
231 for (auto catalogue : catalogues) {
227 impl->saveCatalogue(catalogue, false);
232 impl->saveCatalogue(catalogue, false);
228 }
233 }
229 }
234 }
230
235
231 impl->savAllDB();
236 impl->savAllDB();
232 }
237 }
233
238
234 void CatalogueController::initialize()
239 void CatalogueController::initialize()
235 {
240 {
236 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
241 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
237 << QThread::currentThread();
242 << QThread::currentThread();
238 impl->m_WorkingMutex.lock();
243 impl->m_WorkingMutex.lock();
239 impl->m_CatalogueDao.initialize();
244 impl->m_CatalogueDao.initialize();
240 auto defaultRepositoryLocation
245 auto defaultRepositoryLocation
241 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
246 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
242
247
243 QDir defaultRepositoryLocationDir;
248 QDir defaultRepositoryLocationDir;
244 if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) {
249 if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) {
245 defaultRepositoryLocationDir.cd(defaultRepositoryLocation);
250 defaultRepositoryLocationDir.cd(defaultRepositoryLocation);
246 auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT);
251 auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT);
247 qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ")
252 qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ")
248 << defaultRepository;
253 << defaultRepository;
249 this->addDB(defaultRepository);
254 this->addDB(defaultRepository);
250 }
255 }
251 else {
256 else {
252 qCWarning(LOG_CatalogueController())
257 qCWarning(LOG_CatalogueController())
253 << tr("Cannot load the persistent default repository from ")
258 << tr("Cannot load the persistent default repository from ")
254 << defaultRepositoryLocation;
259 << defaultRepositoryLocation;
255 }
260 }
256
261
257 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
262 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
258 }
263 }
259
264
260 void CatalogueController::finalize()
265 void CatalogueController::finalize()
261 {
266 {
262 impl->m_WorkingMutex.unlock();
267 impl->m_WorkingMutex.unlock();
263 }
268 }
264
269
265 void CatalogueController::waitForFinish()
270 void CatalogueController::waitForFinish()
266 {
271 {
267 QMutexLocker locker{&impl->m_WorkingMutex};
272 QMutexLocker locker{&impl->m_WorkingMutex};
268 }
273 }
269
274
270 void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom,
275 void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom,
271 const QString &dbTo)
276 const QString &dbTo)
272 {
277 {
273 // auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
278 // auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
274 auto catalogues = m_CatalogueDao.getCatalogues(dbFrom);
279 auto catalogues = m_CatalogueDao.getCatalogues(dbFrom);
275 auto events = m_CatalogueDao.getEvents(dbFrom);
280 auto events = m_CatalogueDao.getEvents(dbFrom);
276 for (auto catalogue : catalogues) {
281 for (auto catalogue : catalogues) {
277 m_CatalogueDao.copyCatalogue(catalogue, dbTo, true);
282 m_CatalogueDao.copyCatalogue(catalogue, dbTo, true);
278 }
283 }
279
284
280 for (auto event : events) {
285 for (auto event : events) {
281 m_CatalogueDao.copyEvent(event, dbTo, true);
286 m_CatalogueDao.copyEvent(event, dbTo, true);
282 }
287 }
283 }
288 }
284
289
285 QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString repository)
290 QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString repository)
286 {
291 {
287 auto syncRepository = toSyncRepository(repository);
292 auto syncRepository = toSyncRepository(repository);
288
293
289 return QString("%1%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX);
294 return QString("%1%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX);
290 }
295 }
291
296
292 QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository)
297 QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository)
293 {
298 {
294 auto syncRepository = repository;
299 auto syncRepository = repository;
295 if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) {
300 if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) {
296 syncRepository.remove(REPOSITORY_WORK_SUFFIX);
301 syncRepository.remove(REPOSITORY_WORK_SUFFIX);
297 }
302 }
298 else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) {
303 else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) {
299 syncRepository.remove(REPOSITORY_TRASH_SUFFIX);
304 syncRepository.remove(REPOSITORY_TRASH_SUFFIX);
300 }
305 }
301 return syncRepository;
306 return syncRepository;
302 }
307 }
303
308
304 void CatalogueController::CatalogueControllerPrivate::savAllDB()
309 void CatalogueController::CatalogueControllerPrivate::savAllDB()
305 {
310 {
306 for (auto repository : m_RepositoryList) {
311 for (auto repository : m_RepositoryList) {
307 auto defaultRepositoryLocation
312 auto defaultRepositoryLocation
308 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
313 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
309 m_CatalogueDao.saveDB(defaultRepositoryLocation, repository);
314 m_CatalogueDao.saveDB(defaultRepositoryLocation, repository);
310 }
315 }
311 }
316 }
312
317
313 void CatalogueController::CatalogueControllerPrivate::saveEvent(std::shared_ptr<DBEvent> event,
318 void CatalogueController::CatalogueControllerPrivate::saveEvent(std::shared_ptr<DBEvent> event,
314 bool persist)
319 bool persist)
315 {
320 {
316 m_CatalogueDao.copyEvent(*event, toSyncRepository(event->getRepository()), true);
321 m_CatalogueDao.copyEvent(*event, toSyncRepository(event->getRepository()), true);
317 if (persist) {
322 if (persist) {
318 savAllDB();
323 savAllDB();
319 }
324 }
320 }
325 }
321
326
322 void CatalogueController::CatalogueControllerPrivate::saveCatalogue(
327 void CatalogueController::CatalogueControllerPrivate::saveCatalogue(
323 std::shared_ptr<DBCatalogue> catalogue, bool persist)
328 std::shared_ptr<DBCatalogue> catalogue, bool persist)
324 {
329 {
325 m_CatalogueDao.copyCatalogue(*catalogue, toSyncRepository(catalogue->getRepository()), true);
330 m_CatalogueDao.copyCatalogue(*catalogue, toSyncRepository(catalogue->getRepository()), true);
326 if (persist) {
331 if (persist) {
327 savAllDB();
332 savAllDB();
328 }
333 }
329 }
334 }
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

Status change > Approved

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