##// END OF EJS Templates
Add Catalogue methods
mperrinel -
r1268:acc828493557
parent child
Show More
@@ -55,10 +55,10 public:
55 // Catalogue
55 // Catalogue
56 std::list<std::shared_ptr<DBEvent> >
56 std::list<std::shared_ptr<DBEvent> >
57 retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const;
57 retrieveEventsFromCatalogue(std::shared_ptr<DBCatalogue> catalogue) const;
58 // bool createCatalogue(const QString &name, QVector<QUuid> eventList);
59 /// retrieveEvents with empty repository retrieve them from the default repository
58 /// retrieveEvents with empty repository retrieve them from the default repository
60 std::list<std::shared_ptr<DBCatalogue> > retrieveCatalogues(const QString &repository
59 std::list<std::shared_ptr<DBCatalogue> > retrieveCatalogues(const QString &repository
61 = QString()) const;
60 = QString()) const;
61 void addCatalogue(std::shared_ptr<DBCatalogue> catalogue);
62 void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue);
62 void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue);
63 void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue);
63 void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue);
64 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue);
64 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue);
@@ -27,6 +27,10 static QString REPOSITORY_WORK_SUFFIX = QString{"_work"};
27 static QString REPOSITORY_TRASH_SUFFIX = QString{"_trash"};
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 class CatalogueController::CatalogueControllerPrivate {
34 class CatalogueController::CatalogueControllerPrivate {
31
35
32 public:
36 public:
@@ -48,6 +52,8 public:
48
52
49 void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true);
53 void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true);
50 void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist = true);
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 CatalogueController::CatalogueController(QObject *parent)
59 CatalogueController::CatalogueController(QObject *parent)
@@ -215,26 +221,8 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
215
221
216 void CatalogueController::discardEvent(std::shared_ptr<DBEvent> event, bool &removed)
222 void CatalogueController::discardEvent(std::shared_ptr<DBEvent> event, bool &removed)
217 {
223 {
218 auto uniqIdPredicate = std::make_shared<ComparaisonPredicate>(
224 auto syncPred = impl->createFinder(event->getUniqId(), event->getRepository(), DBType::SYNC);
219 QString{"uniqId"}, event->getUniqId(), ComparaisonOperation::EQUALEQUAL);
225 auto workPred = impl->createFinder(event->getUniqId(), event->getRepository(), DBType::WORK);
220
221 auto syncRepositoryPredicate = std::make_shared<ComparaisonPredicate>(
222 QString{"repository"}, impl->toSyncRepository(event->getRepository()),
223 ComparaisonOperation::EQUALEQUAL);
224
225 auto syncPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND);
226 syncPred->AddRequestPredicate(uniqIdPredicate);
227 syncPred->AddRequestPredicate(syncRepositoryPredicate);
228
229
230 auto workRepositoryPredicate = std::make_shared<ComparaisonPredicate>(
231 QString{"repository"}, impl->toWorkRepository(event->getRepository()),
232 ComparaisonOperation::EQUALEQUAL);
233
234 auto workPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND);
235 workPred->AddRequestPredicate(uniqIdPredicate);
236 workPred->AddRequestPredicate(workRepositoryPredicate);
237
238
226
239 auto syncEvent = impl->m_CatalogueDao.getEvent(syncPred);
227 auto syncEvent = impl->m_CatalogueDao.getEvent(syncPred);
240 if (!syncEvent.getUniqId().isNull()) {
228 if (!syncEvent.getUniqId().isNull()) {
@@ -272,10 +260,29 CatalogueController::retrieveCatalogues(const QString &repository) const
272 return cataloguesShared;
260 return cataloguesShared;
273 }
261 }
274
262
263 void CatalogueController::addCatalogue(std::shared_ptr<DBCatalogue> catalogue)
264 {
265 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
266
267 auto catalogueTemp = *catalogue;
268 impl->m_CatalogueDao.addCatalogue(catalogueTemp);
269
270 auto workPred = impl->createFinder(catalogue->getUniqId(), catalogue->getRepository(), DBType::WORK);
271
272 auto workCatalogue = impl->m_CatalogueDao.getCatalogue(workPred);
273 *catalogue = workCatalogue;
274
275 // auto uniqueId = impl->eventUniqueKey(catalogue);
276 // impl->m_EventKeysWithChanges.insert(uniqueId);
277 }
278
275 void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue)
279 void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue> catalogue)
276 {
280 {
277 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
281 catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
278
282
283 // auto uniqueId = impl->eventUniqueKey(event);
284 // impl->m_EventKeysWithChanges.insert(uniqueId);
285
279 impl->m_CatalogueDao.updateCatalogue(*catalogue);
286 impl->m_CatalogueDao.updateCatalogue(*catalogue);
280 }
287 }
281
288
@@ -286,11 +293,13 void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue
286 impl->m_CatalogueDao.removeCatalogue(*catalogue);
293 impl->m_CatalogueDao.removeCatalogue(*catalogue);
287 catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository()));
294 catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository()));
288 impl->m_CatalogueDao.removeCatalogue(*catalogue);
295 impl->m_CatalogueDao.removeCatalogue(*catalogue);
296 impl->savAllDB();
289 }
297 }
290
298
291 void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue)
299 void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue> catalogue)
292 {
300 {
293 impl->saveCatalogue(catalogue, true);
301 impl->saveCatalogue(catalogue, true);
302 // impl->m_EventKeysWithChanges.remove(impl->eventUniqueKey(event));
294 }
303 }
295
304
296 void CatalogueController::saveAll()
305 void CatalogueController::saveAll()
@@ -464,3 +473,33 void CatalogueController::CatalogueControllerPrivate::saveCatalogue(
464 savAllDB();
473 savAllDB();
465 }
474 }
466 }
475 }
476
477 std::shared_ptr<IRequestPredicate> CatalogueController::CatalogueControllerPrivate::createFinder(const QUuid &uniqId, const QString &repository, DBType type)
478 {
479 // update catalogue parameter
480 auto uniqIdPredicate = std::make_shared<ComparaisonPredicate>(
481 QString{"uniqId"}, uniqId, ComparaisonOperation::EQUALEQUAL);
482
483 auto repositoryType = repository;
484 switch (type) {
485 case DBType::SYNC:
486 repositoryType = toSyncRepository(repositoryType);
487 break;
488 case DBType::WORK:
489 repositoryType =toWorkRepository(repositoryType);
490 break;
491 case DBType::TRASH:
492 default:
493 break;
494 }
495
496 auto repositoryPredicate = std::make_shared<ComparaisonPredicate>(
497 QString{"repository"}, repositoryType,
498 ComparaisonOperation::EQUALEQUAL);
499
500 auto finderPred = std::make_shared<CompoundPredicate>(CompoundOperation::AND);
501 finderPred->AddRequestPredicate(uniqIdPredicate);
502 finderPred->AddRequestPredicate(repositoryPredicate);
503
504 return finderPred;
505 }
General Comments 0
You need to be logged in to leave comments. Login now