summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-10-19 15:28:42 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-10-21 09:18:49 +0200
commitba7c8b890c45d735216888204ec88882ef58c918 (patch)
treecb00c9b51e5353ba3726216679c81c0e2fe9ac35 /examples
parentda1c86b80f230c3a2023f97c0048020a12e38de4 (diff)
downloadsink-ba7c8b890c45d735216888204ec88882ef58c918.tar.gz
sink-ba7c8b890c45d735216888204ec88882ef58c918.zip
Ported the pipeline to the entitystore
Diffstat (limited to 'examples')
-rw-r--r--examples/dummyresource/resourcefactory.cpp7
-rw-r--r--examples/imapresource/imapresource.cpp5
-rw-r--r--examples/maildirresource/maildirresource.cpp33
-rw-r--r--examples/mailtransportresource/mailtransportresource.cpp3
4 files changed, 21 insertions, 27 deletions
diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp
index e288be2..5513986 100644
--- a/examples/dummyresource/resourcefactory.cpp
+++ b/examples/dummyresource/resourcefactory.cpp
@@ -35,7 +35,6 @@
35#include "dummystore.h" 35#include "dummystore.h"
36#include "definitions.h" 36#include "definitions.h"
37#include "facadefactory.h" 37#include "facadefactory.h"
38#include "indexupdater.h"
39#include "adaptorfactoryregistry.h" 38#include "adaptorfactoryregistry.h"
40#include "synchronizer.h" 39#include "synchronizer.h"
41#include "mailpreprocessor.h" 40#include "mailpreprocessor.h"
@@ -135,11 +134,11 @@ DummyResource::DummyResource(const Sink::ResourceContext &resourceContext, const
135 setupSynchronizer(QSharedPointer<DummySynchronizer>::create(resourceContext)); 134 setupSynchronizer(QSharedPointer<DummySynchronizer>::create(resourceContext));
136 setupChangereplay(QSharedPointer<Sink::NullChangeReplay>::create(resourceContext)); 135 setupChangereplay(QSharedPointer<Sink::NullChangeReplay>::create(resourceContext));
137 setupPreprocessors(ENTITY_TYPE_MAIL, 136 setupPreprocessors(ENTITY_TYPE_MAIL,
138 QVector<Sink::Preprocessor*>() << new MailPropertyExtractor << new DefaultIndexUpdater<Sink::ApplicationDomain::Mail>); 137 QVector<Sink::Preprocessor*>() << new MailPropertyExtractor);
139 setupPreprocessors(ENTITY_TYPE_FOLDER, 138 setupPreprocessors(ENTITY_TYPE_FOLDER,
140 QVector<Sink::Preprocessor*>() << new DefaultIndexUpdater<Sink::ApplicationDomain::Folder>); 139 QVector<Sink::Preprocessor*>());
141 setupPreprocessors(ENTITY_TYPE_EVENT, 140 setupPreprocessors(ENTITY_TYPE_EVENT,
142 QVector<Sink::Preprocessor*>() << new DefaultIndexUpdater<Sink::ApplicationDomain::Event>); 141 QVector<Sink::Preprocessor*>());
143} 142}
144 143
145DummyResource::~DummyResource() 144DummyResource::~DummyResource()
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp
index 90dae7a..9656a04 100644
--- a/examples/imapresource/imapresource.cpp
+++ b/examples/imapresource/imapresource.cpp
@@ -33,7 +33,6 @@
33#include "domain/mail.h" 33#include "domain/mail.h"
34#include "definitions.h" 34#include "definitions.h"
35#include "facadefactory.h" 35#include "facadefactory.h"
36#include "indexupdater.h"
37#include "inspection.h" 36#include "inspection.h"
38#include "synchronizer.h" 37#include "synchronizer.h"
39#include "sourcewriteback.h" 38#include "sourcewriteback.h"
@@ -527,8 +526,8 @@ ImapResource::ImapResource(const ResourceContext &resourceContext, const QShared
527 changereplay->mPassword = mPassword; 526 changereplay->mPassword = mPassword;
528 setupChangereplay(changereplay); 527 setupChangereplay(changereplay);
529 528
530 setupPreprocessors(ENTITY_TYPE_MAIL, QVector<Sink::Preprocessor*>() << new SpecialPurposeProcessor(resourceContext.resourceType, resourceContext.instanceId()) << new MimeMessageMover << new MailPropertyExtractor << new DefaultIndexUpdater<Sink::ApplicationDomain::Mail>); 529 setupPreprocessors(ENTITY_TYPE_MAIL, QVector<Sink::Preprocessor*>() << new SpecialPurposeProcessor(resourceContext.resourceType, resourceContext.instanceId()) << new MimeMessageMover << new MailPropertyExtractor);
531 setupPreprocessors(ENTITY_TYPE_FOLDER, QVector<Sink::Preprocessor*>() << new DefaultIndexUpdater<Sink::ApplicationDomain::Folder>); 530 setupPreprocessors(ENTITY_TYPE_FOLDER, QVector<Sink::Preprocessor*>());
532} 531}
533 532
534void ImapResource::removeFromDisk(const QByteArray &instanceIdentifier) 533void ImapResource::removeFromDisk(const QByteArray &instanceIdentifier)
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp
index b89d78c..920bd28 100644
--- a/examples/maildirresource/maildirresource.cpp
+++ b/examples/maildirresource/maildirresource.cpp
@@ -33,7 +33,6 @@
33#include "domain/mail.h" 33#include "domain/mail.h"
34#include "definitions.h" 34#include "definitions.h"
35#include "facadefactory.h" 35#include "facadefactory.h"
36#include "indexupdater.h"
37#include "libmaildir/maildir.h" 36#include "libmaildir/maildir.h"
38#include "inspection.h" 37#include "inspection.h"
39#include "synchronizer.h" 38#include "synchronizer.h"
@@ -85,7 +84,7 @@ class MaildirMimeMessageMover : public Sink::Preprocessor
85public: 84public:
86 MaildirMimeMessageMover(const QByteArray &resourceInstanceIdentifier, const QString &maildirPath) : mResourceInstanceIdentifier(resourceInstanceIdentifier), mMaildirPath(maildirPath) {} 85 MaildirMimeMessageMover(const QByteArray &resourceInstanceIdentifier, const QString &maildirPath) : mResourceInstanceIdentifier(resourceInstanceIdentifier), mMaildirPath(maildirPath) {}
87 86
88 QString getPath(const QByteArray &folderIdentifier, Sink::Storage::DataStore::Transaction &transaction) 87 QString getPath(const QByteArray &folderIdentifier)
89 { 88 {
90 if (folderIdentifier.isEmpty()) { 89 if (folderIdentifier.isEmpty()) {
91 return mMaildirPath; 90 return mMaildirPath;
@@ -108,10 +107,10 @@ public:
108 return folderPath; 107 return folderPath;
109 } 108 }
110 109
111 QString moveMessage(const QString &oldPath, const QByteArray &folder, Sink::Storage::DataStore::Transaction &transaction) 110 QString moveMessage(const QString &oldPath, const QByteArray &folder)
112 { 111 {
113 if (oldPath.startsWith(Sink::temporaryFileLocation())) { 112 if (oldPath.startsWith(Sink::temporaryFileLocation())) {
114 const auto path = getPath(folder, transaction); 113 const auto path = getPath(folder);
115 KPIM::Maildir maildir(path, false); 114 KPIM::Maildir maildir(path, false);
116 if (!maildir.isValid(true)) { 115 if (!maildir.isValid(true)) {
117 SinkWarning() << "Maildir is not existing: " << path; 116 SinkWarning() << "Maildir is not existing: " << path;
@@ -120,7 +119,7 @@ public:
120 return path + "/" + identifier; 119 return path + "/" + identifier;
121 } else { 120 } else {
122 //Handle moves 121 //Handle moves
123 const auto path = getPath(folder, transaction); 122 const auto path = getPath(folder);
124 KPIM::Maildir maildir(path, false); 123 KPIM::Maildir maildir(path, false);
125 if (!maildir.isValid(true)) { 124 if (!maildir.isValid(true)) {
126 SinkWarning() << "Maildir is not existing: " << path; 125 SinkWarning() << "Maildir is not existing: " << path;
@@ -141,16 +140,15 @@ public:
141 } 140 }
142 } 141 }
143 142
144 void newEntity(const QByteArray &uid, qint64 revision, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::DataStore::Transaction &transaction) Q_DECL_OVERRIDE 143 void newEntity(Sink::ApplicationDomain::ApplicationDomainType &newEntity) Q_DECL_OVERRIDE
145 { 144 {
146 const auto mimeMessage = newEntity.getProperty("mimeMessage"); 145 const auto mimeMessage = newEntity.getProperty("mimeMessage");
147 if (mimeMessage.isValid()) { 146 if (mimeMessage.isValid()) {
148 newEntity.setProperty("mimeMessage", moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray(), transaction)); 147 newEntity.setProperty("mimeMessage", moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray()));
149 } 148 }
150 } 149 }
151 150
152 void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::ApplicationDomain::BufferAdaptor &newEntity, 151 void modifiedEntity(const Sink::ApplicationDomain::ApplicationDomainType &oldEntity, Sink::ApplicationDomain::ApplicationDomainType &newEntity) Q_DECL_OVERRIDE
153 Sink::Storage::DataStore::Transaction &transaction) Q_DECL_OVERRIDE
154 { 152 {
155 const auto mimeMessage = newEntity.getProperty("mimeMessage"); 153 const auto mimeMessage = newEntity.getProperty("mimeMessage");
156 const auto newFolder = newEntity.getProperty("folder"); 154 const auto newFolder = newEntity.getProperty("folder");
@@ -158,7 +156,7 @@ public:
158 const bool folderChanged = newFolder.isValid() && newFolder.toString() != oldEntity.getProperty("mimeMessage").toString(); 156 const bool folderChanged = newFolder.isValid() && newFolder.toString() != oldEntity.getProperty("mimeMessage").toString();
159 if (mimeMessageChanged || folderChanged) { 157 if (mimeMessageChanged || folderChanged) {
160 SinkTrace() << "Moving mime message: " << mimeMessageChanged << folderChanged; 158 SinkTrace() << "Moving mime message: " << mimeMessageChanged << folderChanged;
161 auto newPath = moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray(), transaction); 159 auto newPath = moveMessage(mimeMessage.toString(), newEntity.getProperty("folder").toByteArray());
162 if (newPath != oldEntity.getProperty("mimeMessage").toString()) { 160 if (newPath != oldEntity.getProperty("mimeMessage").toString()) {
163 const auto oldPath = getFilePathFromMimeMessagePath(oldEntity.getProperty("mimeMessage").toString()); 161 const auto oldPath = getFilePathFromMimeMessagePath(oldEntity.getProperty("mimeMessage").toString());
164 newEntity.setProperty("mimeMessage", newPath); 162 newEntity.setProperty("mimeMessage", newPath);
@@ -168,7 +166,7 @@ public:
168 } 166 }
169 167
170 auto mimeMessagePath = newEntity.getProperty("mimeMessage").toString(); 168 auto mimeMessagePath = newEntity.getProperty("mimeMessage").toString();
171 const auto maildirPath = getPath(newEntity.getProperty("folder").toByteArray(), transaction); 169 const auto maildirPath = getPath(newEntity.getProperty("folder").toByteArray());
172 KPIM::Maildir maildir(maildirPath, false); 170 KPIM::Maildir maildir(maildirPath, false);
173 const auto file = getFilePathFromMimeMessagePath(mimeMessagePath); 171 const auto file = getFilePathFromMimeMessagePath(mimeMessagePath);
174 QString identifier = KPIM::Maildir::getKeyFromFile(file); 172 QString identifier = KPIM::Maildir::getKeyFromFile(file);
@@ -185,7 +183,7 @@ public:
185 maildir.changeEntryFlags(identifier, flags); 183 maildir.changeEntryFlags(identifier, flags);
186 } 184 }
187 185
188 void deletedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::DataStore::Transaction &transaction) Q_DECL_OVERRIDE 186 void deletedEntity(const Sink::ApplicationDomain::ApplicationDomainType &oldEntity) Q_DECL_OVERRIDE
189 { 187 {
190 const auto filePath = getFilePathFromMimeMessagePath(oldEntity.getProperty("mimeMessage").toString()); 188 const auto filePath = getFilePathFromMimeMessagePath(oldEntity.getProperty("mimeMessage").toString());
191 QFile::remove(filePath); 189 QFile::remove(filePath);
@@ -199,7 +197,7 @@ class FolderPreprocessor : public Sink::Preprocessor
199public: 197public:
200 FolderPreprocessor(const QString maildirPath) : mMaildirPath(maildirPath) {} 198 FolderPreprocessor(const QString maildirPath) : mMaildirPath(maildirPath) {}
201 199
202 void newEntity(const QByteArray &uid, qint64 revision, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::DataStore::Transaction &transaction) Q_DECL_OVERRIDE 200 void newEntity(Sink::ApplicationDomain::ApplicationDomainType &newEntity) Q_DECL_OVERRIDE
203 { 201 {
204 auto folderName = newEntity.getProperty("name").toString(); 202 auto folderName = newEntity.getProperty("name").toString();
205 const auto path = mMaildirPath + "/" + folderName; 203 const auto path = mMaildirPath + "/" + folderName;
@@ -207,12 +205,11 @@ public:
207 maildir.create(); 205 maildir.create();
208 } 206 }
209 207
210 void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::ApplicationDomain::BufferAdaptor &newEntity, 208 void modifiedEntity(const Sink::ApplicationDomain::ApplicationDomainType &oldEntity, Sink::ApplicationDomain::ApplicationDomainType &newEntity) Q_DECL_OVERRIDE
211 Sink::Storage::DataStore::Transaction &transaction) Q_DECL_OVERRIDE
212 { 209 {
213 } 210 }
214 211
215 void deletedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::DataStore::Transaction &transaction) Q_DECL_OVERRIDE 212 void deletedEntity(const Sink::ApplicationDomain::ApplicationDomainType &oldEntity) Q_DECL_OVERRIDE
216 { 213 {
217 } 214 }
218 QString mMaildirPath; 215 QString mMaildirPath;
@@ -440,8 +437,8 @@ MaildirResource::MaildirResource(const Sink::ResourceContext &resourceContext, c
440 changereplay->mMaildirPath = mMaildirPath; 437 changereplay->mMaildirPath = mMaildirPath;
441 setupChangereplay(changereplay); 438 setupChangereplay(changereplay);
442 439
443 setupPreprocessors(ENTITY_TYPE_MAIL, QVector<Sink::Preprocessor*>() << new SpecialPurposeProcessor(resourceContext.resourceType, resourceContext.instanceId()) << new MaildirMimeMessageMover(resourceContext.instanceId(), mMaildirPath) << new MaildirMailPropertyExtractor << new DefaultIndexUpdater<Sink::ApplicationDomain::Mail>); 440 setupPreprocessors(ENTITY_TYPE_MAIL, QVector<Sink::Preprocessor*>() << new SpecialPurposeProcessor(resourceContext.resourceType, resourceContext.instanceId()) << new MaildirMimeMessageMover(resourceContext.instanceId(), mMaildirPath) << new MaildirMailPropertyExtractor);
444 setupPreprocessors(ENTITY_TYPE_FOLDER, QVector<Sink::Preprocessor*>() << new FolderPreprocessor(mMaildirPath) << new DefaultIndexUpdater<Sink::ApplicationDomain::Folder>); 441 setupPreprocessors(ENTITY_TYPE_FOLDER, QVector<Sink::Preprocessor*>() << new FolderPreprocessor(mMaildirPath));
445 442
446 KPIM::Maildir dir(mMaildirPath, true); 443 KPIM::Maildir dir(mMaildirPath, true);
447 SinkTrace() << "Started maildir resource for maildir: " << mMaildirPath; 444 SinkTrace() << "Started maildir resource for maildir: " << mMaildirPath;
diff --git a/examples/mailtransportresource/mailtransportresource.cpp b/examples/mailtransportresource/mailtransportresource.cpp
index 9a22c41..25231c8 100644
--- a/examples/mailtransportresource/mailtransportresource.cpp
+++ b/examples/mailtransportresource/mailtransportresource.cpp
@@ -40,7 +40,6 @@
40#include <resourceconfig.h> 40#include <resourceconfig.h>
41#include <pipeline.h> 41#include <pipeline.h>
42#include <mailpreprocessor.h> 42#include <mailpreprocessor.h>
43#include <indexupdater.h>
44#include <adaptorfactoryregistry.h> 43#include <adaptorfactoryregistry.h>
45 44
46#define ENTITY_TYPE_MAIL "mail" 45#define ENTITY_TYPE_MAIL "mail"
@@ -162,7 +161,7 @@ MailtransportResource::MailtransportResource(const Sink::ResourceContext &resour
162 changereplay->mSettings = mSettings; 161 changereplay->mSettings = mSettings;
163 setupChangereplay(changereplay); 162 setupChangereplay(changereplay);
164 163
165 setupPreprocessors(ENTITY_TYPE_MAIL, QVector<Sink::Preprocessor*>() << new MimeMessageMover << new MailPropertyExtractor << new DefaultIndexUpdater<Sink::ApplicationDomain::Mail>); 164 setupPreprocessors(ENTITY_TYPE_MAIL, QVector<Sink::Preprocessor*>() << new MimeMessageMover << new MailPropertyExtractor);
166} 165}
167 166
168void MailtransportResource::removeFromDisk(const QByteArray &instanceIdentifier) 167void MailtransportResource::removeFromDisk(const QByteArray &instanceIdentifier)