##// END OF EJS Templates
Some more work into Catalogue Controller...
jeandet -
r54:548ec6a0c922
parent child
Show More
@@ -1,123 +1,142
1 1 #ifndef SCIQLOP_CATALOGUECONTROLLER_H
2 2 #define SCIQLOP_CATALOGUECONTROLLER_H
3 3
4 4 #include "CoreGlobal.h"
5 5
6 6 #include <Common/spimpl.h>
7 7 #include <Data/DateTimeRange.h>
8 8 #include <QLoggingCategory>
9 9 #include <QObject>
10 10 #include <QUuid>
11 11 #include <Repository.hpp>
12 12 #include <map>
13 13 #include <memory>
14 14
15 15 class DBCatalogue;
16 16 class DBEvent;
17 17 class DBEventProduct;
18 18
19 19 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController)
20 20
21 21 class DataSourceItem;
22 22 class Variable;
23 23
24 constexpr auto default_repo = "default";
25
24 26 /**
25 27 * @brief The CatalogueController class aims to handle catalogues and event
26 28 * using the CatalogueAPI library.
27 29 */
28 30 class SCIQLOP_CORE_EXPORT CatalogueController : public QObject
29 31 {
32 Q_OBJECT
33 public:
30 34 using time_t = double;
35 using Product_t = CatalogiCpp::Product<time_t>;
31 36 using Repository_t = CatalogiCpp::Repository<time_t>;
32 37 using Event_t = Repository_t::Event_t;
33 38 using Event_ptr = Repository_t::Event_ptr;
34 39 using Catalogue_t = Repository_t::Catalogue_t;
35 40 using Catalogue_ptr = typename Repository_t::Catalogue_ptr;
36 41 using uuid_t = Repository_t::uuid_t;
42 template<typename... _Args>
43 static inline Catalogue_ptr make_catalogue_ptr(_Args&&... __args)
44 {
45 return Repository_t::make_catalogue_ptr(std::forward<_Args>(__args)...);
46 }
47
48 template<typename... _Args>
49 static inline Event_ptr make_event_ptr(_Args&&... __args)
50 {
51 return Catalogue_t::make_event_ptr(std::forward<_Args>(__args)...);
52 }
37 53
38 std::map<QString, CatalogiCpp::Repository<time_t>> _lastSavedRepos;
39 std::map<QString, CatalogiCpp::Repository<time_t>> _currentRepos;
40
41 Q_OBJECT
42 public:
43 54 explicit CatalogueController(QObject* parent = nullptr);
44 55 virtual ~CatalogueController();
45 56
46 QStringList getRepositories() const;
57 QStringList repositories() const;
47 58 void loadRepository(const QString& path, const QString& name);
48 59 void saveRepository(const QString& path, const QString& name);
49 60
50 61 std::vector<Event_ptr> events();
51 62 std::vector<Event_ptr> events(const QString& repository);
52 63
53 64 std::vector<Catalogue_ptr> catalogues();
54 65 std::vector<Catalogue_ptr> catalogues(const QString& repository);
55 66
56 67 bool hasUnsavedChanges(Event_ptr event);
57 68
58 69 std::optional<QString> repository(Event_ptr event);
59 70 std::optional<QString> repository(Catalogue_ptr catalogue);
60 71
61 72 void save(Event_ptr event);
62 73 void save(Catalogue_ptr catalogue);
63 74 void save(const QString& repository);
64 75
76 void add(const QString& repository);
77 void add(const QString& catalogue, const QString& repository);
78 void add(Event_ptr event, Catalogue_ptr catalogue);
79 void add(Event_ptr event, const QString& repository = default_repo);
80
65 81 // // Event
66 82 // /// retrieveEvents with empty repository retrieve them from the default
67 83 // repository std::list<std::shared_ptr<DBEvent>> retrieveEvents(const
68 84 // QString& repository) const; std::list<std::shared_ptr<DBEvent>>
69 85 // retrieveAllEvents() const;
70 86
71 87 // void addEvent(std::shared_ptr<DBEvent> event);
72 88 // void updateEvent(std::shared_ptr<DBEvent> event);
73 89 // void updateEventProduct(std::shared_ptr<DBEventProduct> eventProduct);
74 90 // void removeEvent(std::shared_ptr<DBEvent> event);
75 91 // // void trashEvent(std::shared_ptr<DBEvent> event);
76 92 // // void restore(std::shared_ptr<DBEvent> event);
77 93 // void saveEvent(std::shared_ptr<DBEvent> event);
78 94 // void discardEvent(std::shared_ptr<DBEvent> event, bool& removed);
79 95 // bool eventHasChanges(std::shared_ptr<DBEvent> event) const;
80 96
81 97 // // Catalogue
82 98 // std::list<std::shared_ptr<DBEvent>> retrieveEventsFromCatalogue(
83 99 // std::shared_ptr<DBCatalogue> catalogue) const;
84 100
85 101 // /// retrieveEvents with empty repository retrieve them from the default
86 102 // repository std::list<std::shared_ptr<DBCatalogue>> retrieveCatalogues(
87 103 // const QString& repository = QString()) const;
88 104 // void addCatalogue(std::shared_ptr<DBCatalogue> catalogue);
89 105 // void updateCatalogue(std::shared_ptr<DBCatalogue> catalogue);
90 106 // void removeCatalogue(std::shared_ptr<DBCatalogue> catalogue);
91 107 // void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue);
92 108 // void discardCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool&
93 109 // removed);
94 110
95 111 // void saveAll();
96 112 // bool hasChanges() const;
97 113
98 114 // /// Returns the MIME data associated to a list of variables
99 115 // QByteArray mimeDataForEvents(const QVector<std::shared_ptr<DBEvent>>&
100 116 // events) const;
101 117
102 118 // /// Returns the list of variables contained in a MIME data
103 119 // QVector<std::shared_ptr<DBEvent>> eventsForMimeData(const QByteArray&
104 120 // mimeData) const;
105 121
106 122 // /// Returns the MIME data associated to a list of variables
107 123 // QByteArray mimeDataForCatalogues(const
108 124 // QVector<std::shared_ptr<DBCatalogue>>& catalogues) const;
109 125
110 126 // /// Returns the list of variables contained in a MIME data
111 127 // QVector<std::shared_ptr<DBCatalogue>> cataloguesForMimeData(const
112 128 // QByteArray& mimeData) const;
113 129
114 130 // public slots:
115 131 // /// Manage init/end of the controller
116 132 // void initialize();
117 133
118 134 private:
135 std::map<QString, CatalogiCpp::Repository<time_t>> _lastSavedRepos;
136 std::map<QString, CatalogiCpp::Repository<time_t>> _currentRepos;
137
119 138 // class CatalogueControllerPrivate;
120 139 // spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl;
121 140 };
122 141
123 142 #endif // SCIQLOP_CATALOGUECONTROLLER_H
@@ -1,28 +1,49
1 1 #ifndef CONTAINERS_H
2 2 #define CONTAINERS_H
3 3 #include "cpp_utils.h"
4 4
5 5 #include <algorithm>
6 6 #include <map>
7 7 #include <vector>
8 8
9 9 namespace SciQLop::containers
10 10 {
11 11 template<class T1, class T2>
12 12 auto contains(const T1& container, const T2& value)
13 13 -> decltype(container.front(), std::end(container), true)
14 14 {
15 15 return std::find(std::cbegin(container), std::cend(container), value) !=
16 16 std::cend(container);
17 17 }
18 18
19 19 template<class T1, class T2>
20 20 auto contains(const T1& container, const T2& value)
21 21 -> decltype(container.find(value), std::cend(container), true)
22 22 {
23 23 return container.find(value) != std::cend(container);
24 24 }
25 25
26 template<class T1, class T2>
27 auto index_of(const T1& container, const T2& value)
28 -> decltype(container.front() == value, 0)
29 {
30 return std::distance(
31 std::cbegin(container),
32 std::find(std::cbegin(container), std::cend(container), value));
33 }
34
35 template<class T1, class T2>
36 auto index_of(const T1& container, const T2& value)
37 -> decltype(container.front().get(), std::is_pointer<T2>::value, 0)
38 {
39 return std::distance(std::cbegin(container),
40 std::find_if(std::cbegin(container),
41 std::cend(container),
42 [value](const auto& item) {
43 return value == item.get();
44 }));
45 }
46
26 47 } // namespace SciQLop::containers
27 48
28 49 #endif // CONTAINERS_H
@@ -1,760 +1,780
1 1 #include <Catalogue/CatalogueController.h>
2 2 #include <CatalogueIO.hpp>
3 3 #include <Common/containers.h>
4 4 #include <Common/debug.h>
5 5 #include <QDataStream>
6 6 #include <QDir>
7 7 #include <QMutex>
8 8 #include <QStandardPaths>
9 9 #include <QThread>
10 10
11 11 using namespace SciQLop::containers;
12 12
13 13 // class CatalogueController::CatalogueControllerPrivate
14 14 //{
15 15
16 16 // public:
17 17 // explicit CatalogueControllerPrivate(CatalogueController* parent) : m_Q {
18 18 // parent } {}
19 19
20 20 // CatalogueDao m_CatalogueDao;
21 21
22 22 // QStringList m_RepositoryList;
23 23 // CatalogueController* m_Q;
24 24
25 25 // QSet<QString> m_KeysWithChanges;
26 26
27 27 // QString eventUniqueKey(const std::shared_ptr<DBEvent>& event) const;
28 28 // QString catalogueUniqueKey(const std::shared_ptr<DBCatalogue>& catalogue)
29 29 // const;
30 30
31 31 // void copyDBtoDB(const QString& dbFrom, const QString& dbTo);
32 32 // QString toWorkRepository(QString repository);
33 33 // QString toSyncRepository(QString repository);
34 34 // void savAllDB();
35 35
36 36 // void saveEvent(std::shared_ptr<DBEvent> event, bool persist = true);
37 37 // void saveCatalogue(std::shared_ptr<DBCatalogue> catalogue, bool persist =
38 38 // true);
39 39
40 40 // std::shared_ptr<IRequestPredicate> createFinder(
41 41 // const QUuid& uniqId, const QString& repository, DBType type);
42 42 //};
43 43
44 44 CatalogueController::CatalogueController(QObject* parent)
45 45 //: impl { spimpl::make_unique_impl<CatalogueControllerPrivate>(this) }
46 46 {}
47 47
48 48 CatalogueController::~CatalogueController() {}
49 49
50 QStringList CatalogueController::getRepositories() const
50 QStringList CatalogueController::repositories() const
51 51 {
52 52 QStringList repos;
53 53 std::transform(std::begin(_currentRepos), std::end(_currentRepos),
54 54 std::back_inserter(repos),
55 55 [](auto& pair) { return pair.first; });
56 56 return repos;
57 57 }
58 58
59 59 void CatalogueController::loadRepository(const QString& path,
60 60 const QString& name)
61 61 {
62 62 if(QFile::exists(path))
63 63 {
64 64 auto repo = CatalogiCpp::load_repository<time_t>(path.toStdString());
65 65 _lastSavedRepos[name] = repo;
66 66 _currentRepos[name] = repo;
67 67 }
68 68 }
69 69
70 70 void CatalogueController::saveRepository(const QString& path,
71 71 const QString& name)
72 72 {
73 73 if(contains(_currentRepos, name))
74 74 {
75 75 CatalogiCpp::save_repository(_currentRepos[name], path.toStdString());
76 76 _lastSavedRepos[name] = _currentRepos[name];
77 77 }
78 78 }
79 79
80 80 std::vector<CatalogueController::Event_ptr> CatalogueController::events()
81 81 {
82 82 std::vector<CatalogueController::Event_ptr> e_list;
83 83 for(auto& [_, repo] : _currentRepos)
84 84 {
85 85 for(auto& [_, event] : repo.events())
86 86 e_list.push_back(event);
87 87 }
88 88 return e_list;
89 89 }
90 90
91 91 std::vector<std::shared_ptr<CatalogueController::Event_t>>
92 92 CatalogueController::events(const QString& repository)
93 93 {
94 94 std::vector<std::shared_ptr<CatalogueController::Event_t>> e_list;
95 95 if(contains(_currentRepos, repository))
96 96 {
97 97 auto repo = _currentRepos[repository];
98 98 for(auto& [_, event] : repo.events())
99 99 e_list.push_back(event);
100 100 }
101 101 return e_list;
102 102 }
103 103
104 104 std::vector<CatalogueController::Catalogue_ptr>
105 105 CatalogueController::catalogues()
106 106 {
107 107 std::vector<CatalogueController::Catalogue_ptr> c_list;
108 108 for(auto& [_, repo] : _currentRepos)
109 109 {
110 110 for(auto& [_, catalogue] : repo.catalogues())
111 111 c_list.push_back(catalogue);
112 112 }
113 113 return c_list;
114 114 }
115 115
116 116 std::vector<CatalogueController::Catalogue_ptr>
117 117 CatalogueController::catalogues(const QString& repository)
118 118 {
119 119 std::vector<CatalogueController::Catalogue_ptr> c_list;
120 120 if(contains(_currentRepos, repository))
121 121 {
122 122 auto repo = _currentRepos[repository];
123 123 for(auto& [_, catalogue] : repo.catalogues())
124 124 c_list.push_back(catalogue);
125 125 }
126 126 return c_list;
127 127 }
128 128
129 129 bool CatalogueController::hasUnsavedChanges(
130 130 CatalogueController::Event_ptr event)
131 131 {
132 132 if(auto repo = repository(event))
133 133 {
134 134 if(contains(_lastSavedRepos, *repo))
135 135 { return *event != *(_lastSavedRepos[*repo].event(event->uuid)); }
136 136 }
137 137 return true;
138 138 }
139 139
140 140 std::optional<QString>
141 141 CatalogueController::repository(CatalogueController::Event_ptr event)
142 142 {
143 143 for(auto& [repoName, repo] : _currentRepos)
144 144 {
145 145 if(repo.event(event->uuid)) return repoName;
146 146 }
147 147 return std::nullopt;
148 148 }
149 149
150 150 std::optional<QString>
151 151 CatalogueController::repository(CatalogueController::Catalogue_ptr catalogue)
152 152 {
153 153 for(auto& [repoName, repo] : _currentRepos)
154 154 {
155 155 if(repo.catalogue(catalogue->uuid)) return repoName;
156 156 }
157 157 return std::nullopt;
158 158 }
159 159
160 160 void CatalogueController::save(CatalogueController::Event_ptr event)
161 161 {
162 162 auto repo_name = repository(event);
163 163 if(repo_name && contains(_lastSavedRepos, *repo_name))
164 164 {
165 165 auto repo = _lastSavedRepos[*repo_name];
166 166 if(contains(repo.events(), event->uuid))
167 167 {
168 168 auto saved_evemt = _lastSavedRepos[*repo_name].event(event->uuid);
169 169 *saved_evemt = *event;
170 170 }
171 171 else
172 172 {
173 173 // TODO/Question should we also take care of which catalogue has it?
174 174 // if an event is created and added to a catalogue, what should we do if
175 175 // the user clicks the event save button?
176 176 // - Only save event value in all events list?
177 177 // - Also save the fact that this event is added to a catalogue and save
178 178 // the catalogue?
179 179 repo.add(event);
180 180 }
181 181 }
182 182 }
183 183
184 184 void CatalogueController::save(CatalogueController::Catalogue_ptr catalogue)
185 185 {
186 186 auto repo_name = repository(catalogue);
187 187 if(repo_name && contains(_lastSavedRepos, *repo_name))
188 188 {
189 189 auto repo = _lastSavedRepos[*repo_name];
190 190 if(contains(repo.catalogues(), catalogue->uuid))
191 191 {
192 192 auto saved_catalogue = repo.catalogue(catalogue->uuid);
193 193 *saved_catalogue = *catalogue;
194 194 }
195 195 else
196 196 {
197 197 repo.add(catalogue);
198 198 }
199 199 }
200 200 }
201 201
202 202 void CatalogueController::save(const QString& repository)
203 203 {
204 204 if(contains(_currentRepos, repository))
205 205 { _lastSavedRepos[repository] = _currentRepos[repository]; }
206 206 else
207 207 {
208 208 SCIQLOP_ERROR(CatalogueController, "Trying to save an unknown repository");
209 209 }
210 210 }
211 211
212 void CatalogueController::add(const QString& repository)
213 {
214 if(!contains(_currentRepos, repository))
215 { _currentRepos[repository] = Repository_t{}; }
216 }
217
218 void CatalogueController::add(const QString& catalogue,
219 const QString& repository)
220 {
221 if(!contains(_currentRepos, repository))
222 { _currentRepos[repository] = Repository_t{}; }
223 auto new_catalogue = make_catalogue_ptr();
224 new_catalogue->name = catalogue.toStdString();
225 _currentRepos[repository].add(std::move(new_catalogue));
226 }
227
228 void CatalogueController::add(CatalogueController::Event_ptr event,
229 const QString& repository)
230 {}
231
212 232 // void CatalogueController::saveDB(const QString& destinationPath, const
213 233 // QString& repositoryName)
214 234 //{
215 235 // if (!impl->m_CatalogueDao.saveDB(destinationPath, repositoryName))
216 236 // {
217 237 // qCCritical(LOG_CatalogueController())
218 238 // << tr("Impossible to saveDB %1 from %2 ").arg(repositoryName,
219 239 // destinationPath);
220 240 // }
221 241 //}
222 242
223 243 // std::list<std::shared_ptr<DBEvent>> CatalogueController::retrieveEvents(
224 244 // const QString& repository) const
225 245 //{
226 246 // QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT :
227 247 // repository;
228 248
229 249 // auto eventsShared = std::list<std::shared_ptr<DBEvent>> {};
230 250 // auto events =
231 251 // impl->m_CatalogueDao.getEvents(impl->toWorkRepository(dbDireName)); for
232 252 // (auto event : events)
233 253 // {
234 254 // eventsShared.push_back(std::make_shared<DBEvent>(event));
235 255 // }
236 256 // return eventsShared;
237 257 //}
238 258
239 259 // std::list<std::shared_ptr<DBEvent>> CatalogueController::retrieveAllEvents()
240 260 // const
241 261 //{
242 262 // auto eventsShared = std::list<std::shared_ptr<DBEvent>> {};
243 263 // for (auto repository : impl->m_RepositoryList)
244 264 // {
245 265 // eventsShared.splice(eventsShared.end(), retrieveEvents(repository));
246 266 // }
247 267
248 268 // return eventsShared;
249 269 //}
250 270
251 271 // std::list<std::shared_ptr<DBEvent>>
252 272 // CatalogueController::retrieveEventsFromCatalogue(
253 273 // std::shared_ptr<DBCatalogue> catalogue) const
254 274 //{
255 275 // auto eventsShared = std::list<std::shared_ptr<DBEvent>> {};
256 276 // auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue);
257 277 // for (auto event : events)
258 278 // {
259 279 // eventsShared.push_back(std::make_shared<DBEvent>(event));
260 280 // }
261 281 // return eventsShared;
262 282 //}
263 283
264 284 // void CatalogueController::updateEvent(std::shared_ptr<DBEvent> event)
265 285 //{
266 286 // event->setRepository(impl->toWorkRepository(event->getRepository()));
267 287
268 288 // auto uniqueId = impl->eventUniqueKey(event);
269 289 // impl->m_KeysWithChanges.insert(uniqueId);
270 290
271 291 // impl->m_CatalogueDao.updateEvent(*event);
272 292 //}
273 293
274 294 // void CatalogueController::updateEventProduct(std::shared_ptr<DBEventProduct>
275 295 // eventProduct)
276 296 //{
277 297 // impl->m_CatalogueDao.updateEventProduct(*eventProduct);
278 298 //}
279 299
280 300 // void CatalogueController::removeEvent(std::shared_ptr<DBEvent> event)
281 301 //{
282 302 // // Remove it from both repository and repository_work
283 303 // event->setRepository(impl->toWorkRepository(event->getRepository()));
284 304 // impl->m_CatalogueDao.removeEvent(*event);
285 305 // event->setRepository(impl->toSyncRepository(event->getRepository()));
286 306 // impl->m_CatalogueDao.removeEvent(*event);
287 307 // impl->savAllDB();
288 308 //}
289 309
290 310 // void CatalogueController::addEvent(std::shared_ptr<DBEvent> event)
291 311 //{
292 312 // event->setRepository(impl->toWorkRepository(event->getRepository()));
293 313
294 314 // auto eventTemp = *event;
295 315 // impl->m_CatalogueDao.addEvent(eventTemp);
296 316
297 317 // // Call update is necessary at the creation of add Event if it has some
298 318 // tags or some event
299 319 // // products
300 320 // if (!event->getEventProducts().empty() || !event->getTags().empty())
301 321 // {
302 322
303 323 // auto eventProductsTemp = eventTemp.getEventProducts();
304 324 // auto eventProductTempUpdated = std::list<DBEventProduct> {};
305 325 // for (auto eventProductTemp : eventProductsTemp)
306 326 // {
307 327 // eventProductTemp.setEvent(eventTemp);
308 328 // eventProductTempUpdated.push_back(eventProductTemp);
309 329 // }
310 330 // eventTemp.setEventProducts(eventProductTempUpdated);
311 331
312 332 // impl->m_CatalogueDao.updateEvent(eventTemp);
313 333 // }
314 334
315 335 // auto workPred = impl->createFinder(event->getUniqId(),
316 336 // event->getRepository(), DBType::WORK);
317 337
318 338 // auto workEvent = impl->m_CatalogueDao.getEvent(workPred);
319 339 // *event = workEvent;
320 340
321 341 // auto uniqueId = impl->eventUniqueKey(event);
322 342 // impl->m_KeysWithChanges.insert(uniqueId);
323 343 //}
324 344
325 345 // void CatalogueController::saveEvent(std::shared_ptr<DBEvent> event)
326 346 //{
327 347 // impl->saveEvent(event, true);
328 348 // impl->m_KeysWithChanges.remove(impl->eventUniqueKey(event));
329 349 //}
330 350
331 351 // void CatalogueController::discardEvent(std::shared_ptr<DBEvent> event, bool&
332 352 // removed)
333 353 //{
334 354 // auto syncPred = impl->createFinder(event->getUniqId(),
335 355 // event->getRepository(), DBType::SYNC); auto workPred =
336 356 // impl->createFinder(event->getUniqId(), event->getRepository(),
337 357 // DBType::WORK);
338 358
339 359 // auto syncEvent = impl->m_CatalogueDao.getEvent(syncPred);
340 360 // if (!syncEvent.getUniqId().isNull())
341 361 // {
342 362 // removed = false;
343 363 // impl->m_CatalogueDao.copyEvent(
344 364 // syncEvent, impl->toWorkRepository(event->getRepository()), true);
345 365
346 366 // auto workEvent = impl->m_CatalogueDao.getEvent(workPred);
347 367 // *event = workEvent;
348 368 // impl->m_KeysWithChanges.remove(impl->eventUniqueKey(event));
349 369 // }
350 370 // else
351 371 // {
352 372 // removed = true;
353 373 // // Since the element wasn't in sync repository. Discard it means
354 374 // remove it
355 375 // event->setRepository(impl->toWorkRepository(event->getRepository()));
356 376 // impl->m_CatalogueDao.removeEvent(*event);
357 377 // }
358 378 //}
359 379
360 380 // bool CatalogueController::eventHasChanges(std::shared_ptr<DBEvent> event)
361 381 // const
362 382 //{
363 383 // return impl->m_KeysWithChanges.contains(impl->eventUniqueKey(event));
364 384 //}
365 385
366 386 // std::list<std::shared_ptr<DBCatalogue>>
367 387 // CatalogueController::retrieveCatalogues(
368 388 // const QString& repository) const
369 389 //{
370 390 // QString dbDireName = repository.isEmpty() ? REPOSITORY_DEFAULT :
371 391 // repository;
372 392
373 393 // auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue>> {};
374 394 // auto catalogues =
375 395 // impl->m_CatalogueDao.getCatalogues(impl->toWorkRepository(dbDireName));
376 396 // for (auto catalogue : catalogues)
377 397 // {
378 398 // cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue));
379 399 // }
380 400 // return cataloguesShared;
381 401 //}
382 402
383 403 // void CatalogueController::addCatalogue(std::shared_ptr<DBCatalogue>
384 404 // catalogue)
385 405 //{
386 406 // catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
387 407
388 408 // auto catalogueTemp = *catalogue;
389 409 // impl->m_CatalogueDao.addCatalogue(catalogueTemp);
390 410
391 411 // auto workPred
392 412 // = impl->createFinder(catalogue->getUniqId(),
393 413 // catalogue->getRepository(), DBType::WORK);
394 414
395 415 // auto workCatalogue = impl->m_CatalogueDao.getCatalogue(workPred);
396 416 // *catalogue = workCatalogue;
397 417
398 418 // auto uniqueId = impl->catalogueUniqueKey(catalogue);
399 419 // impl->m_KeysWithChanges.insert(uniqueId);
400 420 //}
401 421
402 422 // void CatalogueController::updateCatalogue(std::shared_ptr<DBCatalogue>
403 423 // catalogue)
404 424 //{
405 425 // catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
406 426
407 427 // auto uniqueId = impl->catalogueUniqueKey(catalogue);
408 428 // impl->m_KeysWithChanges.insert(uniqueId);
409 429
410 430 // impl->m_CatalogueDao.updateCatalogue(*catalogue);
411 431 //}
412 432
413 433 // void CatalogueController::removeCatalogue(std::shared_ptr<DBCatalogue>
414 434 // catalogue)
415 435 //{
416 436 // // Remove it from both repository and repository_work
417 437 // catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
418 438 // impl->m_CatalogueDao.removeCatalogue(*catalogue);
419 439 // catalogue->setRepository(impl->toSyncRepository(catalogue->getRepository()));
420 440 // impl->m_CatalogueDao.removeCatalogue(*catalogue);
421 441 // impl->savAllDB();
422 442 //}
423 443
424 444 // void CatalogueController::saveCatalogue(std::shared_ptr<DBCatalogue>
425 445 // catalogue)
426 446 //{
427 447 // impl->saveCatalogue(catalogue, true);
428 448 // impl->m_KeysWithChanges.remove(impl->catalogueUniqueKey(catalogue));
429 449
430 450 // // remove key of events of the catalogue
431 451 // if (catalogue->getType() == CatalogueType::STATIC)
432 452 // {
433 453 // auto events = this->retrieveEventsFromCatalogue(catalogue);
434 454 // for (auto event : events)
435 455 // {
436 456 // impl->m_KeysWithChanges.remove(impl->eventUniqueKey(event));
437 457 // }
438 458 // }
439 459 //}
440 460
441 461 // void CatalogueController::discardCatalogue(std::shared_ptr<DBCatalogue>
442 462 // catalogue, bool& removed)
443 463 //{
444 464 // auto syncPred
445 465 // = impl->createFinder(catalogue->getUniqId(),
446 466 // catalogue->getRepository(), DBType::SYNC);
447 467 // auto workPred
448 468 // = impl->createFinder(catalogue->getUniqId(),
449 469 // catalogue->getRepository(), DBType::WORK);
450 470
451 471 // auto syncCatalogue = impl->m_CatalogueDao.getCatalogue(syncPred);
452 472 // if (!syncCatalogue.getUniqId().isNull())
453 473 // {
454 474 // removed = false;
455 475 // impl->m_CatalogueDao.copyCatalogue(
456 476 // syncCatalogue, impl->toWorkRepository(catalogue->getRepository()),
457 477 // true);
458 478
459 479 // auto workCatalogue = impl->m_CatalogueDao.getCatalogue(workPred);
460 480 // *catalogue = workCatalogue;
461 481 // impl->m_KeysWithChanges.remove(impl->catalogueUniqueKey(catalogue));
462 482 // }
463 483 // else
464 484 // {
465 485 // removed = true;
466 486 // // Since the element wasn't in sync repository. Discard it means
467 487 // remove it
468 488 // catalogue->setRepository(impl->toWorkRepository(catalogue->getRepository()));
469 489 // impl->m_CatalogueDao.removeCatalogue(*catalogue);
470 490 // }
471 491 //}
472 492
473 493 // void CatalogueController::saveAll()
474 494 //{
475 495 // for (auto repository : impl->m_RepositoryList)
476 496 // {
477 497 // // Save Event
478 498 // auto events = this->retrieveEvents(repository);
479 499 // for (auto event : events)
480 500 // {
481 501 // impl->saveEvent(event, false);
482 502 // }
483 503
484 504 // // Save Catalogue
485 505 // auto catalogues = this->retrieveCatalogues(repository);
486 506 // for (auto catalogue : catalogues)
487 507 // {
488 508 // impl->saveCatalogue(catalogue, false);
489 509 // }
490 510 // }
491 511
492 512 // impl->savAllDB();
493 513 // impl->m_KeysWithChanges.clear();
494 514 //}
495 515
496 516 // bool CatalogueController::hasChanges() const
497 517 //{
498 518 // return !impl->m_KeysWithChanges.isEmpty();
499 519 //}
500 520
501 521 // QByteArray CatalogueController::mimeDataForEvents(
502 522 // const QVector<std::shared_ptr<DBEvent>>& events) const
503 523 //{
504 524 // auto encodedData = QByteArray {};
505 525
506 526 // QMap<QString, QVariantList> idsPerRepository;
507 527 // for (auto event : events)
508 528 // {
509 529 // idsPerRepository[event->getRepository()] << event->getUniqId();
510 530 // }
511 531
512 532 // QDataStream stream { &encodedData, QIODevice::WriteOnly };
513 533 // stream << idsPerRepository;
514 534
515 535 // return encodedData;
516 536 //}
517 537
518 538 // QVector<std::shared_ptr<DBEvent>> CatalogueController::eventsForMimeData(
519 539 // const QByteArray& mimeData) const
520 540 //{
521 541 // auto events = QVector<std::shared_ptr<DBEvent>> {};
522 542 // QDataStream stream { mimeData };
523 543
524 544 // QMap<QString, QVariantList> idsPerRepository;
525 545 // stream >> idsPerRepository;
526 546
527 547 // for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend();
528 548 // ++it)
529 549 // {
530 550 // auto repository = it.key();
531 551 // auto allRepositoryEvent = retrieveEvents(repository);
532 552 // for (auto uuid : it.value())
533 553 // {
534 554 // for (auto repositoryEvent : allRepositoryEvent)
535 555 // {
536 556 // if (uuid.toUuid() == repositoryEvent->getUniqId())
537 557 // {
538 558 // events << repositoryEvent;
539 559 // }
540 560 // }
541 561 // }
542 562 // }
543 563
544 564 // return events;
545 565 //}
546 566
547 567 // QByteArray CatalogueController::mimeDataForCatalogues(
548 568 // const QVector<std::shared_ptr<DBCatalogue>>& catalogues) const
549 569 //{
550 570 // auto encodedData = QByteArray {};
551 571
552 572 // QMap<QString, QVariantList> idsPerRepository;
553 573 // for (auto catalogue : catalogues)
554 574 // {
555 575 // idsPerRepository[catalogue->getRepository()] <<
556 576 // catalogue->getUniqId();
557 577 // }
558 578
559 579 // QDataStream stream { &encodedData, QIODevice::WriteOnly };
560 580 // stream << idsPerRepository;
561 581
562 582 // return encodedData;
563 583 //}
564 584
565 585 // QVector<std::shared_ptr<DBCatalogue>>
566 586 // CatalogueController::cataloguesForMimeData(
567 587 // const QByteArray& mimeData) const
568 588 //{
569 589 // auto catalogues = QVector<std::shared_ptr<DBCatalogue>> {};
570 590 // QDataStream stream { mimeData };
571 591
572 592 // QMap<QString, QVariantList> idsPerRepository;
573 593 // stream >> idsPerRepository;
574 594
575 595 // for (auto it = idsPerRepository.cbegin(); it != idsPerRepository.cend();
576 596 // ++it)
577 597 // {
578 598 // auto repository = it.key();
579 599 // auto allRepositoryCatalogues = retrieveCatalogues(repository);
580 600 // for (auto uuid : it.value())
581 601 // {
582 602 // for (auto repositoryCatalogues : allRepositoryCatalogues)
583 603 // {
584 604 // if (uuid.toUuid() == repositoryCatalogues->getUniqId())
585 605 // {
586 606 // catalogues << repositoryCatalogues;
587 607 // }
588 608 // }
589 609 // }
590 610 // }
591 611
592 612 // return catalogues;
593 613 //}
594 614
595 615 // void CatalogueController::initialize()
596 616 //{
597 617 // qCDebug(LOG_CatalogueController())
598 618 // << tr("CatalogueController init") << QThread::currentThread();
599 619
600 620 // impl->m_CatalogueDao.initialize();
601 621 // auto defaultRepositoryLocation
602 622 // = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
603 623
604 624 // QDir defaultRepositoryLocationDir;
605 625 // if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation))
606 626 // {
607 627 // defaultRepositoryLocationDir.cd(defaultRepositoryLocation);
608 628 // auto defaultRepository =
609 629 // defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT);
610 630
611 631 // qCInfo(LOG_CatalogueController())
612 632 // << tr("Persistant data loading from: ") << defaultRepository;
613 633
614 634 // QDir dbDir(defaultRepository);
615 635 // impl->m_RepositoryList << REPOSITORY_DEFAULT;
616 636 // if (dbDir.exists())
617 637 // {
618 638 // auto dirName = dbDir.dirName();
619 639
620 640 // if (impl->m_CatalogueDao.addDB(defaultRepository, dirName))
621 641 // {
622 642 // impl->copyDBtoDB(dirName, impl->toWorkRepository(dirName));
623 643 // }
624 644 // }
625 645 // else
626 646 // {
627 647 // qCInfo(LOG_CatalogueController())
628 648 // << tr("Initialisation of Default repository detected") <<
629 649 // defaultRepository;
630 650 // }
631 651 // }
632 652 // else
633 653 // {
634 654 // qCWarning(LOG_CatalogueController())
635 655 // << tr("Cannot load the persistent default repository from ")
636 656 // << defaultRepositoryLocation;
637 657 // }
638 658
639 659 // qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
640 660 //}
641 661
642 662 // QString CatalogueController::CatalogueControllerPrivate::eventUniqueKey(
643 663 // const std::shared_ptr<DBEvent>& event) const
644 664 //{
645 665 // return event->getUniqId().toString().append(event->getRepository());
646 666 //}
647 667
648 668 // QString CatalogueController::CatalogueControllerPrivate::catalogueUniqueKey(
649 669 // const std::shared_ptr<DBCatalogue>& catalogue) const
650 670 //{
651 671 // return
652 672 // catalogue->getUniqId().toString().append(catalogue->getRepository());
653 673 //}
654 674
655 675 // void CatalogueController::CatalogueControllerPrivate::copyDBtoDB(
656 676 // const QString& dbFrom, const QString& dbTo)
657 677 //{
658 678 // // auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
659 679 // auto catalogues = m_CatalogueDao.getCatalogues(dbFrom);
660 680 // auto events = m_CatalogueDao.getEvents(dbFrom);
661 681 // for (auto catalogue : catalogues)
662 682 // {
663 683 // m_CatalogueDao.copyCatalogue(catalogue, dbTo, true);
664 684 // }
665 685
666 686 // for (auto event : events)
667 687 // {
668 688 // m_CatalogueDao.copyEvent(event, dbTo, true);
669 689 // }
670 690 //}
671 691
672 692 // QString
673 693 // CatalogueController::CatalogueControllerPrivate::toWorkRepository(QString
674 694 // repository)
675 695 //{
676 696 // auto syncRepository = toSyncRepository(repository);
677 697
678 698 // return QString("%1%2").arg(syncRepository, REPOSITORY_WORK_SUFFIX);
679 699 //}
680 700
681 701 // QString
682 702 // CatalogueController::CatalogueControllerPrivate::toSyncRepository(QString
683 703 // repository)
684 704 //{
685 705 // auto syncRepository = repository;
686 706 // if (repository.endsWith(REPOSITORY_WORK_SUFFIX))
687 707 // {
688 708 // syncRepository.remove(REPOSITORY_WORK_SUFFIX);
689 709 // }
690 710 // else if (repository.endsWith(REPOSITORY_TRASH_SUFFIX))
691 711 // {
692 712 // syncRepository.remove(REPOSITORY_TRASH_SUFFIX);
693 713 // }
694 714 // return syncRepository;
695 715 //}
696 716
697 717 // void CatalogueController::CatalogueControllerPrivate::savAllDB()
698 718 //{
699 719 // for (auto repository : m_RepositoryList)
700 720 // {
701 721 // auto defaultRepositoryLocation
702 722 // =
703 723 // QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
704 724 // m_CatalogueDao.saveDB(defaultRepositoryLocation, repository);
705 725 // }
706 726 //}
707 727
708 728 // void CatalogueController::CatalogueControllerPrivate::saveEvent(
709 729 // std::shared_ptr<DBEvent> event, bool persist)
710 730 //{
711 731 // m_CatalogueDao.copyEvent(*event, toSyncRepository(event->getRepository()),
712 732 // true); if (persist)
713 733 // {
714 734 // savAllDB();
715 735 // }
716 736 //}
717 737
718 738 // void CatalogueController::CatalogueControllerPrivate::saveCatalogue(
719 739 // std::shared_ptr<DBCatalogue> catalogue, bool persist)
720 740 //{
721 741 // m_CatalogueDao.copyCatalogue(*catalogue,
722 742 // toSyncRepository(catalogue->getRepository()), true); if (persist)
723 743 // {
724 744 // savAllDB();
725 745 // }
726 746 //}
727 747
728 748 // std::shared_ptr<IRequestPredicate>
729 749 // CatalogueController::CatalogueControllerPrivate::createFinder(
730 750 // const QUuid& uniqId, const QString& repository, DBType type)
731 751 //{
732 752 // // update catalogue parameter
733 753 // auto uniqIdPredicate = std::make_shared<ComparaisonPredicate>(
734 754 // QString { "uniqId" }, uniqId, ComparaisonOperation::EQUALEQUAL);
735 755
736 756 // auto repositoryType = repository;
737 757 // switch (type)
738 758 // {
739 759 // case DBType::SYNC:
740 760 // repositoryType = toSyncRepository(repositoryType);
741 761 // break;
742 762 // case DBType::WORK:
743 763 // repositoryType = toWorkRepository(repositoryType);
744 764 // break;
745 765 // case DBType::TRASH:
746 766 // default:
747 767 // break;
748 768 // }
749 769
750 770 // auto repositoryPredicate = std::make_shared<ComparaisonPredicate>(
751 771 // QString { "repository" }, repositoryType,
752 772 // ComparaisonOperation::EQUALEQUAL);
753 773
754 774 // auto finderPred =
755 775 // std::make_shared<CompoundPredicate>(CompoundOperation::AND);
756 776 // finderPred->AddRequestPredicate(uniqIdPredicate);
757 777 // finderPred->AddRequestPredicate(repositoryPredicate);
758 778
759 779 // return finderPred;
760 780 //}
General Comments 0
You need to be logged in to leave comments. Login now