##// END OF EJS Templates
Add Catalogue methods
mperrinel -
r1262:043629eaaed2
parent child
Show More
@@ -1,84 +1,84
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 class DBEventProduct;
19 19
20 20 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController)
21 21
22 22 class DataSourceItem;
23 23 class Variable;
24 24
25 25 /**
26 26 * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI
27 27 * library.
28 28 */
29 29 class SCIQLOP_CORE_EXPORT CatalogueController : public QObject {
30 30 Q_OBJECT
31 31 public:
32 32 explicit CatalogueController(QObject *parent = 0);
33 33 virtual ~CatalogueController();
34 34
35 35 // DB
36 36 QStringList getRepositories() const;
37 37 void addDB(const QString &dbPath);
38 38 void saveDB(const QString &destinationPath, const QString &repository);
39 39
40 40 // Event
41 41 /// retrieveEvents with empty repository retrieve them from the default repository
42 42 std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const;
43 43 std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const;
44 44
45 45 void addEvent(std::shared_ptr<DBEvent> event);
46 46 void updateEvent(std::shared_ptr<DBEvent> event);
47 47 void updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct);
48 48 void removeEvent(std::shared_ptr<DBEvent> event);
49 49 // void trashEvent(std::shared_ptr<DBEvent> event);
50 50 // void restore(std::shared_ptr<DBEvent> event);
51 51 void saveEvent(std::shared_ptr<DBEvent> event);
52 52 void discardEvent(std::shared_ptr<DBEvent> event, bool &removed);
53 53 bool eventHasChanges(std::shared_ptr<DBEvent> event) const;
54 54
55 55 // Catalogue
56 56 std::list<std::shared_ptr<DBEvent> >
57 57 retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const;
58 // bool createCatalogue(const QString &name, QVector<QUuid> eventList);
59 58 /// retrieveEvents with empty repository retrieve them from the default repository
60 59 std::list<std::shared_ptr<DBCatalogue> > retrieveCatalogues(const QString &repository
61 60 = QString()) const;
61 void addCatalogue(std::shared_ptr<DBCatalogue> catalogue);
62 62 void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue);
63 63 void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue);
64 64 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue);
65 65
66 66 void saveAll();
67 67 bool hasChanges() const;
68 68
69 69 /// Returns the MIME data associated to a list of variables
70 70 QByteArray mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const;
71 71
72 72 /// Returns the list of variables contained in a MIME data
73 73 QVector<std::shared_ptr<DBEvent> > eventsForMimeData(const QByteArray &mimeData) const;
74 74
75 75 public slots:
76 76 /// Manage init/end of the controller
77 77 void initialize();
78 78
79 79 private:
80 80 class CatalogueControllerPrivate;
81 81 spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl;
82 82 };
83 83
84 84 #endif // SCIQLOP_CATALOGUECONTROLLER_H
@@ -1,462 +1,501
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 <DBEventProduct.h>
12 12 #include <DBTag.h>
13 13 #include <IRequestPredicate.h>
14 14
15 15 #include <QDataStream>
16 16 #include <QMutex>
17 17 #include <QThread>
18 18
19 19 #include <QDir>
20 20 #include <QStandardPaths>
21 21
22 22 Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController")
23 23
24 24 namespace {
25 25
26 26 static QString REPOSITORY_WORK_SUFFIX = QString{"_work"};
27 27 static QString REPOSITORY_TRASH_SUFFIX = QString{"_trash"};
28 28 }
29 29
30 /**
31 * Possible types of an repository
32 */
33 enum class DBType { SYNC, WORK, TRASH};
30 34 class CatalogueController::CatalogueControllerPrivate {
31 35
32 36 public:
33 37 explicit CatalogueControllerPrivate(CatalogueController *parent) : m_Q{parent} {}
34 38
35 39 CatalogueDao m_CatalogueDao;
36 40
37 41 QStringList m_RepositoryList;
38 42 CatalogueController *m_Q;
39 43
40 44 QSet<QString> m_EventKeysWithChanges;
41 45
42 46 QString eventUniqueKey(const std::shared_ptr<DBEvent> &event) const;
43 47
44 48 void copyDBtoDB(const QString &dbFrom, const QString &dbTo);
45 49 QString toWorkRepository(QString repository);
46 50 QString toSyncRepository(QString repository);
47 51 void savAllDB();
48 52
49 53 void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true);
50 54 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist = true);
55
56 std::shared_ptr<IRequestPredicate> createFinder(const QUuid& uniqId, const QString & repository, DBType type);
51 57 };
52 58
53 59 CatalogueController::CatalogueController(QObject *parent)
54 60 : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>(this)}
55 61 {
56 62 qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction")
57 63 << QThread::currentThread();
58 64 }
59 65
60 66 CatalogueController::~CatalogueController()
61 67 {
62 68 qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction")
63 69 << QThread::currentThread();
64 70 }
65 71
66 72 QStringList CatalogueController::getRepositories() const
67 73 {
68 74 return impl->m_RepositoryList;
69 75 }
70 76
71 77 void CatalogueController::addDB(const QString &dbPath)
72 78 {
73 79 QDir dbDir(dbPath);
74 80 if (dbDir.exists()) {
75 81 auto dirName = dbDir.dirName();
76 82
77 83 if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName)
78 84 != impl->m_RepositoryList.cend()) {
79 85 qCCritical(LOG_CatalogueController())
80 86 << tr("Impossible to addDB that is already loaded");
81 87 }
82 88
83 89 if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) {
84 90 qCCritical(LOG_CatalogueController())
85 91 << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath);
86 92 }
87 93 else {
88 94 impl->m_RepositoryList << dirName;
89 95 impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName));
90 96 }
91 97 }
92 98 else {
93 99 qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ")
94 100 << dbPath;
95 101 }
96 102 }
97 103
98 104 void CatalogueController::saveDB(const QString &destinationPath, const QString &repository)
99 105 {
100 106 if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) {
101 107 qCCritical(LOG_CatalogueController())
102 108 << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath);
103 109 }
104 110 }
105 111
106 112 std::list<std::shared_ptr<DBEvent> >
107 113 CatalogueController::retrieveEvents(const QString &repository) const
108 114 {
109 115 QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository;
110 116
111 117 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
112 118 auto events = impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName));
113 119 for (auto event : events) {
114 120 eventsShared.push_back(std::make_shared<DBEvent>(event));
115 121 }
116 122 return eventsShared;
117 123 }
118 124
119 125 std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const
120 126 {
121 127 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
122 128 for (auto repository : impl->m_RepositoryList) {
123 129 eventsShared.splice(eventsShared.end(), retrieveEvents(repository));
124 130 }
125 131
126 132 return eventsShared;
127 133 }
128 134
129 135 std::list<std::shared_ptr<DBEvent> >
130 136 CatalogueController::retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const
131 137 {
132 138 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
133 139 auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue);
134 140 for (auto event : events) {
135 141 eventsShared.push_back(std::make_shared<DBEvent>(event));
136 142 }
137 143 return eventsShared;
138 144 }
139 145
140 146 void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event)
141 147 {
142 148 event->setRepository(impl->toWorkRepository(event->getRepository()));
143 149
144 150 auto uniqueId = impl->eventUniqueKey(event);
145 151 impl->m_EventKeysWithChanges.insert(uniqueId);
146 152
147 153 impl->m_CatalogueDao.updateEvent(*event);
148 154 }
149 155
150 156 void CatalogueController::updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct)
151 157 {
152 158 impl->m_CatalogueDao.updateEventProduct(*eventProduct);
153 159 }
154 160
155 161 void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event)
156 162 {
157 163 // Remove it from both repository and repository_work
158 164 event->setRepository(impl->toWorkRepository(event->getRepository()));
159 165 impl->m_CatalogueDao.removeEvent(*event);
160 166 event->setRepository(impl->toSyncRepository(event->getRepository()));
161 167 impl->m_CatalogueDao.removeEvent(*event);
162 168 impl->savAllDB();
163 169 }
164 170
165 171 void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
166 172 {
167 173 event->setRepository(impl->toWorkRepository(event->getRepository()));
168 174
169 175 auto eventTemp = *event;
170 176 impl->m_CatalogueDao.addEvent(eventTemp);
171 177
172 178 // Call update is necessary at the creation of add Event if it has some tags or some event
173 179 // products
174 180 if (!event->getEventProducts().empty() || !event->getTags().empty()) {
175 181
176 182 auto eventProductsTemp = eventTemp.getEventProducts();
177 183 auto eventProductTempUpdated = std::list<DBEventProduct>{};
178 184 for (auto eventProductTemp : eventProductsTemp) {
179 185 eventProductTemp.setEvent(eventTemp);
180 186 eventProductTempUpdated.push_back(eventProductTemp);
181 187 }
182 188 eventTemp.setEventProducts(eventProductTempUpdated);
183 189
184 190 impl->m_CatalogueDao.updateEvent(eventTemp);
185 191 }
186 192
187 193 // update event parameter
188 194 auto uniqIdPredicate = std::make_shared<ComparaisonPredicate>(
189 195 QString{"uniqId"}, event->getUniqId(), ComparaisonOperation::EQUALEQUAL);
190 196
191 197 auto workRepositoryPredicate = std::make_shared<ComparaisonPredicate>(
192 198 QString{"repository"}, impl->toWorkRepository(event->getRepository()),
193 199 ComparaisonOperation::EQUALEQUAL);
194 200
195 201 auto workPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND);
196 202 workPred->AddRequestPredicate(uniqIdPredicate);
197 203 workPred->AddRequestPredicate(workRepositoryPredicate);
198 204
199 205 auto workEvent = impl->m_CatalogueDao.getEvent(workPred);
200 206 *event = workEvent;
201 207
202 208 auto uniqueId = impl->eventUniqueKey(event);
203 209 impl->m_EventKeysWithChanges.insert(uniqueId);
204 210 }
205 211
206 212 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
207 213 {
208 214 impl->saveEvent(event, true);
209 215 impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event));
210 216 }
211 217
212 218 void CatalogueController::discardEvent(std::shared_ptr<DBEvent> event, bool &removed)
213 219 {
214 auto uniqIdPredicate = std::make_shared<ComparaisonPredicate>(
215 QString{"uniqId"}, event->getUniqId(), ComparaisonOperation::EQUALEQUAL);
216
217 auto syncRepositoryPredicate = std::make_shared<ComparaisonPredicate>(
218 QString{"repository"}, impl->toSyncRepository(event->getRepository()),
219 ComparaisonOperation::EQUALEQUAL);
220
221 auto syncPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND);
222 syncPred->AddRequestPredicate(uniqIdPredicate);
223 syncPred->AddRequestPredicate(syncRepositoryPredicate);
224
225
226 auto workRepositoryPredicate = std::make_shared<ComparaisonPredicate>(
227 QString{"repository"}, impl->toWorkRepository(event->getRepository()),
228 ComparaisonOperation::EQUALEQUAL);
229
230 auto workPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND);
231 workPred->AddRequestPredicate(uniqIdPredicate);
232 workPred->AddRequestPredicate(workRepositoryPredicate);
233
220 auto syncPred = impl->createFinder(event->getUniqId(), event->getRepository(), DBType::SYNC);
221 auto workPred = impl->createFinder(event->getUniqId(), event->getRepository(), DBType::WORK);
234 222
235 223 auto syncEvent = impl->m_CatalogueDao.getEvent(syncPred);
236 224 if (!syncEvent.getUniqId().isNull()) {
237 225 removed = false;
238 226 impl->m_CatalogueDao.copyEvent(syncEvent, impl->toWorkRepository(event->getRepository()),
239 227 true);
240 228
241 229 auto workEvent = impl->m_CatalogueDao.getEvent(workPred);
242 230 *event = workEvent;
243 231 impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event));
244 232 }
245 233 else {
246 234 removed = true;
247 235 // Since the element wasn't in sync repository. Discard it means remove it
248 236 event->setRepository(impl->toWorkRepository(event->getRepository()));
249 237 impl->m_CatalogueDao.removeEvent(*event);
250 238 }
251 239 }
252 240
253 241 bool CatalogueController::eventHasChanges(std::shared_ptr<DBEvent> event) const
254 242 {
255 243 return impl->m_EventKeysWithChanges.contains(impl->eventUniqueKey(event));
256 244 }
257 245
258 246 std::list<std::shared_ptr<DBCatalogue> >
259 247 CatalogueController::retrieveCatalogues(const QString &repository) const
260 248 {
261 249 QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT : repository;
262 250
263 251 auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
264 252 auto catalogues = impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName));
265 253 for (auto catalogue : catalogues) {
266 254 cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue));
267 255 }
268 256 return cataloguesShared;
269 257 }
270 258
259 void CatalogueController::addCatalogue(std::shared_ptr<DBCatalogue> catalogue)
260 {
261 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
262
263 auto catalogueTemp = *catalogue;
264 impl->m_CatalogueDao.addCatalogue(catalogueTemp);
265
266 auto workPred = impl->createFinder(catalogue->getUniqId(), catalogue->getRepository(), DBType::WORK);
267
268 auto workCatalogue = impl->m_CatalogueDao.getCatalogue(workPred);
269 *catalogue = workCatalogue;
270
271 // auto uniqueId = impl->eventUniqueKey(catalogue);
272 // impl->m_EventKeysWithChanges.insert(uniqueId);
273 }
274
271 275 void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue)
272 276 {
273 277 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
274 278
279 // auto uniqueId = impl->eventUniqueKey(event);
280 // impl->m_EventKeysWithChanges.insert(uniqueId);
281
275 282 impl->m_CatalogueDao.updateCatalogue(*catalogue);
276 283 }
277 284
278 285 void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue)
279 286 {
280 287 // Remove it from both repository and repository_work
281 288 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
282 289 impl->m_CatalogueDao.removeCatalogue(*catalogue);
283 290 catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository()));
284 291 impl->m_CatalogueDao.removeCatalogue(*catalogue);
292 impl->savAllDB();
285 293 }
286 294
287 295 void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue)
288 296 {
289 297 impl->saveCatalogue(catalogue, true);
298 // impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event));
290 299 }
291 300
292 301 void CatalogueController::saveAll()
293 302 {
294 303 for (auto repository : impl->m_RepositoryList) {
295 304 // Save Event
296 305 auto events = this->retrieveEvents(repository);
297 306 for (auto event : events) {
298 307 impl->saveEvent(event, false);
299 308 }
300 309
301 310 // Save Catalogue
302 311 auto catalogues = this->retrieveCatalogues(repository);
303 312 for (auto catalogue : catalogues) {
304 313 impl->saveCatalogue(catalogue, false);
305 314 }
306 315 }
307 316
308 317 impl->savAllDB();
309 318 impl->m_EventKeysWithChanges.clear();
310 319 }
311 320
312 321 bool CatalogueController::hasChanges() const
313 322 {
314 323 return !impl->m_EventKeysWithChanges.isEmpty(); // TODO: catalogues
315 324 }
316 325
317 326 QByteArray
318 327 CatalogueController::mimeDataForEvents(const QVector<std::shared_ptr<DBEvent> > &events) const
319 328 {
320 329 auto encodedData = QByteArray{};
321 330
322 331 QMap<QString, QVariantList> idsPerRepository;
323 332 for (auto event : events) {
324 333 idsPerRepository[event->getRepository()] << event->getUniqId();
325 334 }
326 335
327 336 QDataStream stream{&encodedData, QIODevice::WriteOnly};
328 337 stream << idsPerRepository;
329 338
330 339 return encodedData;
331 340 }
332 341
333 342 QVector<std::shared_ptr<DBEvent> >
334 343 CatalogueController::eventsForMimeData(const QByteArray &mimeData) const
335 344 {
336 345 auto events = QVector<std::shared_ptr<DBEvent> >{};
337 346 QDataStream stream{mimeData};
338 347
339 348 QMap<QString, QVariantList> idsPerRepository;
340 349 stream >> idsPerRepository;
341 350
342 351 for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend(); ++it) {
343 352 auto repository = it.key();
344 353 auto allRepositoryEvent = retrieveEvents(repository);
345 354 for (auto uuid : it.value()) {
346 355 for (auto repositoryEvent : allRepositoryEvent) {
347 356 if (uuid.toUuid() == repositoryEvent->getUniqId()) {
348 357 events << repositoryEvent;
349 358 }
350 359 }
351 360 }
352 361 }
353 362
354 363 return events;
355 364 }
356 365
357 366 void CatalogueController::initialize()
358 367 {
359 368 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
360 369 << QThread::currentThread();
361 370
362 371 impl->m_CatalogueDao.initialize();
363 372 auto defaultRepositoryLocation
364 373 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
365 374
366 375 QDir defaultRepositoryLocationDir;
367 376 if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) {
368 377 defaultRepositoryLocationDir.cd(defaultRepositoryLocation);
369 378 auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT);
370 379
371 380 qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ")
372 381 << defaultRepository;
373 382
374 383 QDir dbDir(defaultRepository);
375 384 impl->m_RepositoryList << REPOSITORY_DEFAULT;
376 385 if (dbDir.exists()) {
377 386 auto dirName = dbDir.dirName();
378 387
379 388 if (impl->m_CatalogueDao.addDB(defaultRepository, dirName)) {
380 389 impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName));
381 390 }
382 391 }
383 392 else {
384 393 qCInfo(LOG_CatalogueController()) << tr("Initialisation of Default repository detected")
385 394 << defaultRepository;
386 395 }
387 396 }
388 397 else {
389 398 qCWarning(LOG_CatalogueController())
390 399 << tr("Cannot load the persistent default repository from ")
391 400 << defaultRepositoryLocation;
392 401 }
393 402
394 403 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
395 404 }
396 405
397 406 QString CatalogueController::CatalogueControllerPrivate::eventUniqueKey(
398 407 const std::shared_ptr<DBEvent> &event) const
399 408 {
400 409 return event->getUniqId().toString().append(event->getRepository());
401 410 }
402 411
403 412 void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(const QString &dbFrom,
404 413 const QString &dbTo)
405 414 {
406 415 // auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
407 416 auto catalogues = m_CatalogueDao.getCatalogues(dbFrom);
408 417 auto events = m_CatalogueDao.getEvents(dbFrom);
409 418 for (auto catalogue : catalogues) {
410 419 m_CatalogueDao.copyCatalogue(catalogue, dbTo, true);
411 420 }
412 421
413 422 for (auto event : events) {
414 423 m_CatalogueDao.copyEvent(event, dbTo, true);
415 424 }
416 425 }
417 426
418 427 QString CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString repository)
419 428 {
420 429 auto syncRepository = toSyncRepository(repository);
421 430
422 431 return QString("%1%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX);
423 432 }
424 433
425 434 QString CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString repository)
426 435 {
427 436 auto syncRepository = repository;
428 437 if (repository.endsWith(REPOSITORY_WORK_SUFFIX)) {
429 438 syncRepository.remove(REPOSITORY_WORK_SUFFIX);
430 439 }
431 440 else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX)) {
432 441 syncRepository.remove(REPOSITORY_TRASH_SUFFIX);
433 442 }
434 443 return syncRepository;
435 444 }
436 445
437 446 void CatalogueController::CatalogueControllerPrivate::savAllDB()
438 447 {
439 448 for (auto repository : m_RepositoryList) {
440 449 auto defaultRepositoryLocation
441 450 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
442 451 m_CatalogueDao.saveDB(defaultRepositoryLocation, repository);
443 452 }
444 453 }
445 454
446 455 void CatalogueController::CatalogueControllerPrivate::saveEvent(std::shared_ptr<DBEvent> event,
447 456 bool persist)
448 457 {
449 458 m_CatalogueDao.copyEvent(*event, toSyncRepository(event->getRepository()), true);
450 459 if (persist) {
451 460 savAllDB();
452 461 }
453 462 }
454 463
455 464 void CatalogueController::CatalogueControllerPrivate::saveCatalogue(
456 465 std::shared_ptr<DBCatalogue> catalogue, bool persist)
457 466 {
458 467 m_CatalogueDao.copyCatalogue(*catalogue, toSyncRepository(catalogue->getRepository()), true);
459 468 if (persist) {
460 469 savAllDB();
461 470 }
462 471 }
472
473 std::shared_ptr<IRequestPredicate> CatalogueController::CatalogueControllerPrivate::createFinder(const QUuid &uniqId, const QString &repository, DBType type)
474 {
475 // update catalogue parameter
476 auto uniqIdPredicate = std::make_shared<ComparaisonPredicate>(
477 QString{"uniqId"}, uniqId, ComparaisonOperation::EQUALEQUAL);
478
479 auto repositoryType = repository;
480 switch (type) {
481 case DBType::SYNC:
482 repositoryType = toSyncRepository(repositoryType);
483 break;
484 case DBType::WORK:
485 repositoryType =toWorkRepository(repositoryType);
486 break;
487 case DBType::TRASH:
488 default:
489 break;
490 }
491
492 auto repositoryPredicate = std::make_shared<ComparaisonPredicate>(
493 QString{"repository"}, repositoryType,
494 ComparaisonOperation::EQUALEQUAL);
495
496 auto finderPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND);
497 finderPred->AddRequestPredicate(uniqIdPredicate);
498 finderPred->AddRequestPredicate(repositoryPredicate);
499
500 return finderPred;
501 }
General Comments 0
You need to be logged in to leave comments. Login now