diff options
author | Minijackson <minijackson@riseup.net> | 2018-04-30 13:48:50 +0200 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2018-04-30 14:31:46 +0200 |
commit | de9e304c724b5de421a231bcc449a6f3dd0eb48b (patch) | |
tree | 295843d23a8533aa99b1634b3a4c14b26a21f9b4 /examples/webdavcommon | |
parent | 7a166895a54c4037749229b9ec9d0c90d60987b5 (diff) | |
download | sink-de9e304c724b5de421a231bcc449a6f3dd0eb48b.tar.gz sink-de9e304c724b5de421a231bcc449a6f3dd0eb48b.zip |
Add replay of events
Diffstat (limited to 'examples/webdavcommon')
-rw-r--r-- | examples/webdavcommon/webdav.cpp | 83 | ||||
-rw-r--r-- | examples/webdavcommon/webdav.h | 39 |
2 files changed, 119 insertions, 3 deletions
diff --git a/examples/webdavcommon/webdav.cpp b/examples/webdavcommon/webdav.cpp index ad1af35..f97a866 100644 --- a/examples/webdavcommon/webdav.cpp +++ b/examples/webdavcommon/webdav.cpp | |||
@@ -22,8 +22,13 @@ | |||
22 | #include "applicationdomaintype.h" | 22 | #include "applicationdomaintype.h" |
23 | #include "resourceconfig.h" | 23 | #include "resourceconfig.h" |
24 | 24 | ||
25 | #include <KDAV2/DavCollectionDeleteJob> | ||
26 | #include <KDAV2/DavCollectionModifyJob> | ||
25 | #include <KDAV2/DavCollectionsFetchJob> | 27 | #include <KDAV2/DavCollectionsFetchJob> |
28 | #include <KDAV2/DavItemCreateJob> | ||
29 | #include <KDAV2/DavItemDeleteJob> | ||
26 | #include <KDAV2/DavItemFetchJob> | 30 | #include <KDAV2/DavItemFetchJob> |
31 | #include <KDAV2/DavItemModifyJob> | ||
27 | #include <KDAV2/DavItemsListJob> | 32 | #include <KDAV2/DavItemsListJob> |
28 | #include <KDAV2/EtagCache> | 33 | #include <KDAV2/EtagCache> |
29 | 34 | ||
@@ -180,7 +185,6 @@ KAsync::Job<void> WebDavSynchronizer::synchronizeCollection(const KDAV2::DavColl | |||
180 | 185 | ||
181 | auto localRid = collectionLocalResourceID(collection); | 186 | auto localRid = collectionLocalResourceID(collection); |
182 | 187 | ||
183 | // The ETag cache is useless here, since `sinkStore()` IS the cache. | ||
184 | auto cache = std::make_shared<KDAV2::EtagCache>(); | 188 | auto cache = std::make_shared<KDAV2::EtagCache>(); |
185 | auto davItemsListJob = new KDAV2::DavItemsListJob(collection.url(), std::move(cache)); | 189 | auto davItemsListJob = new KDAV2::DavItemsListJob(collection.url(), std::move(cache)); |
186 | 190 | ||
@@ -234,14 +238,87 @@ KAsync::Job<void> WebDavSynchronizer::synchronizeItem(const KDAV2::DavItem &item | |||
234 | }); | 238 | }); |
235 | } | 239 | } |
236 | 240 | ||
241 | KAsync::Job<void> WebDavSynchronizer::createItem(const KDAV2::DavItem &item) | ||
242 | { | ||
243 | auto job = new KDAV2::DavItemCreateJob(item); | ||
244 | return runJob(job).then([] { | ||
245 | SinkLog() << "Done creating item"; | ||
246 | }); | ||
247 | } | ||
248 | |||
249 | KAsync::Job<void> WebDavSynchronizer::removeItem(const KDAV2::DavItem &item) | ||
250 | { | ||
251 | auto job = new KDAV2::DavItemDeleteJob(item); | ||
252 | return runJob(job).then([] { | ||
253 | SinkLog() << "Done removing item"; | ||
254 | }); | ||
255 | } | ||
256 | |||
257 | KAsync::Job<void> WebDavSynchronizer::modifyItem(const KDAV2::DavItem &item) | ||
258 | { | ||
259 | auto job = new KDAV2::DavItemModifyJob(item); | ||
260 | return runJob(job).then([] { | ||
261 | SinkLog() << "Done modifying item"; | ||
262 | }); | ||
263 | } | ||
264 | |||
265 | /* | ||
266 | KAsync::Job<void> WebDavSynchronizer::createCollection(const KDAV2::DavCollection &collection) | ||
267 | { | ||
268 | auto job = new KDAV2::DavCollectionCreateJob(collection); | ||
269 | return runJob(job); | ||
270 | } | ||
271 | */ | ||
272 | |||
273 | KAsync::Job<void> WebDavSynchronizer::removeCollection(const KDAV2::DavUrl &url) | ||
274 | { | ||
275 | auto job = new KDAV2::DavCollectionDeleteJob(url); | ||
276 | return runJob(job); | ||
277 | } | ||
278 | |||
279 | KAsync::Job<void> WebDavSynchronizer::modifyCollection(const KDAV2::DavUrl &url) | ||
280 | { | ||
281 | auto job = new KDAV2::DavCollectionModifyJob(url); | ||
282 | return runJob(job); | ||
283 | } | ||
284 | |||
285 | /* | ||
286 | KAsync::Job<QByteArray> WebDavSynchronizer::replay(const Contact &, Sink::Operation operation, | ||
287 | const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) | ||
288 | { | ||
289 | return replayItem(Sink::ApplicationDomain::getTypeName<Contact>(), operation, oldRemoteId, | ||
290 | changedProperties); | ||
291 | } | ||
292 | |||
293 | KAsync::Job<QByteArray> WebDavSynchronizer::replay(const Addressbook &, Sink::Operation operation, | ||
294 | const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) | ||
295 | { | ||
296 | return replayCollection(Sink::ApplicationDomain::getTypeName<Addressbook>(), operation, | ||
297 | oldRemoteId, changedProperties); | ||
298 | } | ||
299 | */ | ||
300 | |||
237 | QByteArray WebDavSynchronizer::resourceID(const KDAV2::DavCollection &collection) | 301 | QByteArray WebDavSynchronizer::resourceID(const KDAV2::DavCollection &collection) |
238 | { | 302 | { |
239 | return collection.url().toDisplayString().toUtf8(); | 303 | return collection.url().url().toEncoded(); |
240 | } | 304 | } |
241 | 305 | ||
242 | QByteArray WebDavSynchronizer::resourceID(const KDAV2::DavItem &item) | 306 | QByteArray WebDavSynchronizer::resourceID(const KDAV2::DavItem &item) |
243 | { | 307 | { |
244 | return item.url().toDisplayString().toUtf8(); | 308 | return item.url().url().toEncoded(); |
309 | } | ||
310 | |||
311 | KDAV2::DavUrl WebDavSynchronizer::urlOf(const QByteArray &remoteId) | ||
312 | { | ||
313 | auto url = QUrl::fromEncoded(remoteId); | ||
314 | auto davurl = serverUrl(); | ||
315 | davurl.setUrl(url); | ||
316 | return davurl; | ||
317 | } | ||
318 | |||
319 | KDAV2::DavUrl WebDavSynchronizer::urlOf(const QByteArray &collectionRemoteId, const QString &itemPath) | ||
320 | { | ||
321 | return urlOf(collectionRemoteId + "/" + itemPath.toUtf8()); | ||
245 | } | 322 | } |
246 | 323 | ||
247 | bool WebDavSynchronizer::unchanged(const KDAV2::DavCollection &collection) | 324 | bool WebDavSynchronizer::unchanged(const KDAV2::DavCollection &collection) |
diff --git a/examples/webdavcommon/webdav.h b/examples/webdavcommon/webdav.h index 3a4977c..ecb6a81 100644 --- a/examples/webdavcommon/webdav.h +++ b/examples/webdavcommon/webdav.h | |||
@@ -35,6 +35,32 @@ public: | |||
35 | KAsync::Job<void> synchronizeWithSource(const Sink::QueryBase &query) Q_DECL_OVERRIDE; | 35 | KAsync::Job<void> synchronizeWithSource(const Sink::QueryBase &query) Q_DECL_OVERRIDE; |
36 | 36 | ||
37 | protected: | 37 | protected: |
38 | |||
39 | /** | ||
40 | * Called in a child synchronizer, when replaying a creation of an item. | ||
41 | */ | ||
42 | KAsync::Job<void> createItem(const KDAV2::DavItem &); | ||
43 | |||
44 | /** | ||
45 | * Called in a child synchronizer, when replaying a removal of an item. | ||
46 | */ | ||
47 | KAsync::Job<void> removeItem(const KDAV2::DavItem &); | ||
48 | |||
49 | /** | ||
50 | * Called in a child synchronizer, when replaying a modification of an item. | ||
51 | * | ||
52 | * The item to modify is chosen according to the given item's URL. | ||
53 | * The job will fail if the ETag does not match. | ||
54 | */ | ||
55 | KAsync::Job<void> modifyItem(const KDAV2::DavItem &); | ||
56 | |||
57 | /** | ||
58 | * See comments of the *Item version above | ||
59 | */ | ||
60 | KAsync::Job<void> createCollection(const KDAV2::DavUrl &); | ||
61 | KAsync::Job<void> removeCollection(const KDAV2::DavUrl &); | ||
62 | KAsync::Job<void> modifyCollection(const KDAV2::DavUrl &); | ||
63 | |||
38 | /** | 64 | /** |
39 | * Called with the list of discovered collections. It's purpose should be | 65 | * Called with the list of discovered collections. It's purpose should be |
40 | * adding the said collections to the store. | 66 | * adding the said collections to the store. |
@@ -63,6 +89,19 @@ protected: | |||
63 | static QByteArray resourceID(const KDAV2::DavCollection &); | 89 | static QByteArray resourceID(const KDAV2::DavCollection &); |
64 | static QByteArray resourceID(const KDAV2::DavItem &); | 90 | static QByteArray resourceID(const KDAV2::DavItem &); |
65 | 91 | ||
92 | /** | ||
93 | * Used to get the url of an item / collection with the given remote ID | ||
94 | */ | ||
95 | KDAV2::DavUrl urlOf(const QByteArray &remoteId); | ||
96 | |||
97 | /** | ||
98 | * Used to get the url of an item / collection with the given remote ID, | ||
99 | * and append `itemPath` to the path of the URI. | ||
100 | * | ||
101 | * Useful when adding a new item to a collection | ||
102 | */ | ||
103 | KDAV2::DavUrl urlOf(const QByteArray &collectionRemoteId, const QString &itemPath); | ||
104 | |||
66 | bool unchanged(const KDAV2::DavCollection &); | 105 | bool unchanged(const KDAV2::DavCollection &); |
67 | bool unchanged(const KDAV2::DavItem &); | 106 | bool unchanged(const KDAV2::DavItem &); |
68 | 107 | ||