##// END OF EJS Templates
Add Catalogue methods
mperrinel -
r1352:51c5ed888bf9
parent child
Show More
@@ -55,10 +55,10 public:
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);
@@ -27,6 +27,10 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:
@@ -48,6 +52,8 public:
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)
@@ -211,26 +217,8 void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
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()) {
@@ -268,10 +256,29 CatalogueController::retrieveCatalogues(const QString &repository) const
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
@@ -282,11 +289,13 void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue> catalogue
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()
@@ -460,3 +469,33 void CatalogueController::CatalogueControllerPrivate::saveCatalogue(
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