diff options
-rw-r--r-- | common/pipeline.cpp | 54 | ||||
-rw-r--r-- | common/pipeline.h | 24 | ||||
-rw-r--r-- | examples/mailtransportresource/mailtransportresource.cpp | 23 | ||||
-rw-r--r-- | examples/mailtransportresource/tests/mailtransporttest.cpp | 7 |
4 files changed, 91 insertions, 17 deletions
diff --git a/common/pipeline.cpp b/common/pipeline.cpp index 91437d4..019784e 100644 --- a/common/pipeline.cpp +++ b/common/pipeline.cpp | |||
@@ -269,7 +269,26 @@ KAsync::Job<qint64> Pipeline::modifiedEntity(void const *command, size_t size) | |||
269 | } | 269 | } |
270 | 270 | ||
271 | foreach (const auto &processor, d->processors[bufferType]) { | 271 | foreach (const auto &processor, d->processors[bufferType]) { |
272 | processor->modifiedEntity(current, newEntity); | 272 | bool exitLoop = false; |
273 | const auto result = processor->processModification(Preprocessor::Modification, current, newEntity); | ||
274 | switch (result.action) { | ||
275 | case Preprocessor::MoveToResource: | ||
276 | isMove = true; | ||
277 | exitLoop = true; | ||
278 | break; | ||
279 | case Preprocessor::CopyToResource: | ||
280 | isMove = true; | ||
281 | exitLoop = true; | ||
282 | break; | ||
283 | case Preprocessor::DropModification: | ||
284 | SinkTraceCtx(d->logCtx) << "Dropping modification"; | ||
285 | return KAsync::error<qint64>(0); | ||
286 | default: | ||
287 | break; | ||
288 | } | ||
289 | if (exitLoop) { | ||
290 | break; | ||
291 | } | ||
273 | } | 292 | } |
274 | 293 | ||
275 | //The entity is either being copied or moved | 294 | //The entity is either being copied or moved |
@@ -378,6 +397,39 @@ void Preprocessor::finalizeBatch() | |||
378 | { | 397 | { |
379 | } | 398 | } |
380 | 399 | ||
400 | void Preprocessor::newEntity(ApplicationDomain::ApplicationDomainType &newEntity) | ||
401 | { | ||
402 | |||
403 | } | ||
404 | |||
405 | void Preprocessor::modifiedEntity(const ApplicationDomain::ApplicationDomainType &oldEntity, ApplicationDomain::ApplicationDomainType &newEntity) | ||
406 | { | ||
407 | |||
408 | } | ||
409 | |||
410 | void Preprocessor::deletedEntity(const ApplicationDomain::ApplicationDomainType &oldEntity) | ||
411 | { | ||
412 | |||
413 | } | ||
414 | |||
415 | Preprocessor::Result Preprocessor::processModification(Type type, const ApplicationDomain::ApplicationDomainType ¤t, ApplicationDomain::ApplicationDomainType &diff) | ||
416 | { | ||
417 | switch(type) { | ||
418 | case Creation: | ||
419 | newEntity(diff); | ||
420 | return {NoAction}; | ||
421 | case Modification: | ||
422 | modifiedEntity(current, diff); | ||
423 | return {NoAction}; | ||
424 | case Deletion: | ||
425 | deletedEntity(current); | ||
426 | return {NoAction}; | ||
427 | default: | ||
428 | break; | ||
429 | } | ||
430 | return {NoAction}; | ||
431 | } | ||
432 | |||
381 | QByteArray Preprocessor::resourceInstanceIdentifier() const | 433 | QByteArray Preprocessor::resourceInstanceIdentifier() const |
382 | { | 434 | { |
383 | return d->resourceInstanceIdentifier; | 435 | return d->resourceInstanceIdentifier; |
diff --git a/common/pipeline.h b/common/pipeline.h index c6dc5fe..11d52fd 100644 --- a/common/pipeline.h +++ b/common/pipeline.h | |||
@@ -77,10 +77,28 @@ public: | |||
77 | Preprocessor(); | 77 | Preprocessor(); |
78 | virtual ~Preprocessor(); | 78 | virtual ~Preprocessor(); |
79 | 79 | ||
80 | enum Action { | ||
81 | NoAction, | ||
82 | MoveToResource, | ||
83 | CopyToResource, | ||
84 | DropModification, | ||
85 | DeleteEntity | ||
86 | }; | ||
87 | |||
88 | enum Type { | ||
89 | Creation, | ||
90 | Modification, | ||
91 | Deletion | ||
92 | }; | ||
93 | struct Result { | ||
94 | Action action; | ||
95 | }; | ||
96 | |||
80 | virtual void startBatch(); | 97 | virtual void startBatch(); |
81 | virtual void newEntity(ApplicationDomain::ApplicationDomainType &newEntity) {}; | 98 | virtual void newEntity(ApplicationDomain::ApplicationDomainType &newEntity); |
82 | virtual void modifiedEntity(const ApplicationDomain::ApplicationDomainType &oldEntity, ApplicationDomain::ApplicationDomainType &newEntity) {}; | 99 | virtual void modifiedEntity(const ApplicationDomain::ApplicationDomainType &oldEntity, ApplicationDomain::ApplicationDomainType &newEntity); |
83 | virtual void deletedEntity(const ApplicationDomain::ApplicationDomainType &oldEntity) {}; | 100 | virtual void deletedEntity(const ApplicationDomain::ApplicationDomainType &oldEntity); |
101 | virtual Result processModification(Type type, const ApplicationDomain::ApplicationDomainType ¤t, ApplicationDomain::ApplicationDomainType &diff); | ||
84 | virtual void finalizeBatch(); | 102 | virtual void finalizeBatch(); |
85 | 103 | ||
86 | void setup(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier, Pipeline *, Storage::EntityStore *entityStore); | 104 | void setup(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier, Pipeline *, Storage::EntityStore *entityStore); |
diff --git a/examples/mailtransportresource/mailtransportresource.cpp b/examples/mailtransportresource/mailtransportresource.cpp index 8e5b22e..8a4ef92 100644 --- a/examples/mailtransportresource/mailtransportresource.cpp +++ b/examples/mailtransportresource/mailtransportresource.cpp | |||
@@ -66,18 +66,21 @@ public: | |||
66 | return targetResource.identifier(); | 66 | return targetResource.identifier(); |
67 | } | 67 | } |
68 | 68 | ||
69 | void modifiedEntity(const Sink::ApplicationDomain::ApplicationDomainType &oldEntity, Sink::ApplicationDomain::ApplicationDomainType &newEntity) Q_DECL_OVERRIDE | 69 | virtual Result processModification(Type type, const ApplicationDomain::ApplicationDomainType ¤t, ApplicationDomain::ApplicationDomainType &diff) Q_DECL_OVERRIDE |
70 | { | 70 | { |
71 | using namespace Sink::ApplicationDomain; | 71 | if (type == Preprocessor::Modification) { |
72 | auto mail = newEntity.cast<Mail>(); | 72 | using namespace Sink::ApplicationDomain; |
73 | if (mail.changedProperties().contains(Mail::Trash::name)) { | 73 | if (diff.changedProperties().contains(Mail::Trash::name)) { |
74 | //Move back to regular resource | 74 | //Move back to regular resource |
75 | newEntity.setResource(getTargetResource()); | 75 | diff.setResource(getTargetResource()); |
76 | } else if (mail.changedProperties().contains(Mail::Draft::name)) { | 76 | return {MoveToResource}; |
77 | //Move back to regular resource | 77 | } else if (diff.changedProperties().contains(Mail::Draft::name)) { |
78 | newEntity.setResource(getTargetResource()); | 78 | //Move back to regular resource |
79 | diff.setResource(getTargetResource()); | ||
80 | return {MoveToResource}; | ||
81 | } | ||
79 | } | 82 | } |
80 | //TODO this will only copy it back, but not yet move | 83 | return {NoAction}; |
81 | } | 84 | } |
82 | }; | 85 | }; |
83 | 86 | ||
diff --git a/examples/mailtransportresource/tests/mailtransporttest.cpp b/examples/mailtransportresource/tests/mailtransporttest.cpp index a30fc20..e4cc447 100644 --- a/examples/mailtransportresource/tests/mailtransporttest.cpp +++ b/examples/mailtransportresource/tests/mailtransporttest.cpp | |||
@@ -47,7 +47,8 @@ private slots: | |||
47 | 47 | ||
48 | void cleanup() | 48 | void cleanup() |
49 | { | 49 | { |
50 | VERIFYEXEC(ResourceControl::shutdown(mResourceInstanceIdentifier)); | 50 | VERIFYEXEC(Store::removeDataFromDisk(mResourceInstanceIdentifier)); |
51 | VERIFYEXEC(Store::removeDataFromDisk(mStorageResource)); | ||
51 | } | 52 | } |
52 | 53 | ||
53 | void init() | 54 | void init() |
@@ -107,8 +108,8 @@ private slots: | |||
107 | VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); | 108 | VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); |
108 | 109 | ||
109 | QTest::qWait(100); | 110 | QTest::qWait(100); |
110 | // auto mailsInOutbox = Store::read<ApplicationDomain::Mail>(Query().resourceFilter(mResourceInstanceIdentifier)); | 111 | auto mailsInOutbox = Store::read<ApplicationDomain::Mail>(Query().resourceFilter(mResourceInstanceIdentifier)); |
111 | // QCOMPARE(mailsInOutbox.size(), 0); | 112 | QCOMPARE(mailsInOutbox.size(), 0); |
112 | 113 | ||
113 | auto mailsInDrafts = Store::read<ApplicationDomain::Mail>(Query().resourceFilter(mStorageResource)); | 114 | auto mailsInDrafts = Store::read<ApplicationDomain::Mail>(Query().resourceFilter(mStorageResource)); |
114 | QCOMPARE(mailsInDrafts.size(), 1); | 115 | QCOMPARE(mailsInDrafts.size(), 1); |