summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-10-19 15:47:39 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-10-21 09:18:50 +0200
commit21da1b751d0f55648a7c9dbe71a3cd3440a134f0 (patch)
treef422bfd94c77c9c2c8783d0e399b061d29913af0
parentba7c8b890c45d735216888204ec88882ef58c918 (diff)
downloadsink-21da1b751d0f55648a7c9dbe71a3cd3440a134f0.tar.gz
sink-21da1b751d0f55648a7c9dbe71a3cd3440a134f0.zip
Fixed specialpurposeprocessor
-rw-r--r--common/pipeline.cpp11
-rw-r--r--common/pipeline.h7
-rw-r--r--common/specialpurposepreprocessor.cpp39
-rw-r--r--common/storage/entitystore.h1
4 files changed, 36 insertions, 22 deletions
diff --git a/common/pipeline.cpp b/common/pipeline.cpp
index ea59ae9..b1c2c58 100644
--- a/common/pipeline.cpp
+++ b/common/pipeline.cpp
@@ -73,7 +73,7 @@ void Pipeline::setPreprocessors(const QString &entityType, const QVector<Preproc
73 auto &list = d->processors[entityType]; 73 auto &list = d->processors[entityType];
74 list.clear(); 74 list.clear();
75 for (auto p : processors) { 75 for (auto p : processors) {
76 p->setup(d->resourceContext.resourceType, d->resourceContext.instanceId(), this); 76 p->setup(d->resourceContext.resourceType, d->resourceContext.instanceId(), this, &d->entityStore);
77 list.append(QSharedPointer<Preprocessor>(p)); 77 list.append(QSharedPointer<Preprocessor>(p));
78 } 78 }
79} 79}
@@ -307,6 +307,7 @@ public:
307 QByteArray resourceType; 307 QByteArray resourceType;
308 QByteArray resourceInstanceIdentifier; 308 QByteArray resourceInstanceIdentifier;
309 Pipeline *pipeline; 309 Pipeline *pipeline;
310 Storage::EntityStore *entityStore;
310}; 311};
311 312
312Preprocessor::Preprocessor() : d(new Preprocessor::Private) 313Preprocessor::Preprocessor() : d(new Preprocessor::Private)
@@ -317,11 +318,12 @@ Preprocessor::~Preprocessor()
317{ 318{
318} 319}
319 320
320void Preprocessor::setup(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier, Pipeline *pipeline) 321void Preprocessor::setup(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier, Pipeline *pipeline, Storage::EntityStore *entityStore)
321{ 322{
322 d->resourceType = resourceType; 323 d->resourceType = resourceType;
323 d->resourceInstanceIdentifier = resourceInstanceIdentifier; 324 d->resourceInstanceIdentifier = resourceInstanceIdentifier;
324 d->pipeline = pipeline; 325 d->pipeline = pipeline;
326 d->entityStore = entityStore;
325} 327}
326 328
327void Preprocessor::startBatch() 329void Preprocessor::startBatch()
@@ -337,6 +339,11 @@ QByteArray Preprocessor::resourceInstanceIdentifier() const
337 return d->resourceInstanceIdentifier; 339 return d->resourceInstanceIdentifier;
338} 340}
339 341
342Storage::EntityStore &Preprocessor::entityStore() const
343{
344 return *d->entityStore;
345}
346
340void Preprocessor::createEntity(const Sink::ApplicationDomain::ApplicationDomainType &entity, const QByteArray &typeName) 347void Preprocessor::createEntity(const Sink::ApplicationDomain::ApplicationDomainType &entity, const QByteArray &typeName)
341{ 348{
342 flatbuffers::FlatBufferBuilder entityFbb; 349 flatbuffers::FlatBufferBuilder entityFbb;
diff --git a/common/pipeline.h b/common/pipeline.h
index 0461507..c6efaa6 100644
--- a/common/pipeline.h
+++ b/common/pipeline.h
@@ -35,6 +35,9 @@
35#include <resourcecontext.h> 35#include <resourcecontext.h>
36 36
37namespace Sink { 37namespace Sink {
38namespace Storage {
39 class EntityStore;
40}
38 41
39class Preprocessor; 42class Preprocessor;
40 43
@@ -87,7 +90,7 @@ public:
87 virtual void deletedEntity(const ApplicationDomain::ApplicationDomainType &oldEntity) {}; 90 virtual void deletedEntity(const ApplicationDomain::ApplicationDomainType &oldEntity) {};
88 virtual void finalizeBatch(); 91 virtual void finalizeBatch();
89 92
90 void setup(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier, Pipeline *); 93 void setup(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier, Pipeline *, Storage::EntityStore *entityStore);
91 94
92protected: 95protected:
93 template <typename DomainType> 96 template <typename DomainType>
@@ -99,6 +102,8 @@ protected:
99 102
100 QByteArray resourceInstanceIdentifier() const; 103 QByteArray resourceInstanceIdentifier() const;
101 104
105 Storage::EntityStore &entityStore() const;
106
102private: 107private:
103 friend class Pipeline; 108 friend class Pipeline;
104 class Private; 109 class Private;
diff --git a/common/specialpurposepreprocessor.cpp b/common/specialpurposepreprocessor.cpp
index 920f78a..b3a6bab 100644
--- a/common/specialpurposepreprocessor.cpp
+++ b/common/specialpurposepreprocessor.cpp
@@ -1,6 +1,7 @@
1#include "specialpurposepreprocessor.h" 1#include "specialpurposepreprocessor.h"
2#include "query.h" 2#include "query.h"
3#include "applicationdomaintype.h" 3#include "applicationdomaintype.h"
4#include "datastorequery.h"
4 5
5using namespace Sink; 6using namespace Sink;
6 7
@@ -48,25 +49,25 @@ SpecialPurposeProcessor::SpecialPurposeProcessor(const QByteArray &resourceType,
48 49
49QByteArray SpecialPurposeProcessor::ensureFolder(const QByteArray &specialPurpose) 50QByteArray SpecialPurposeProcessor::ensureFolder(const QByteArray &specialPurpose)
50{ 51{
51 /* if (!mSpecialPurposeFolders.contains(specialPurpose)) { */ 52 if (!mSpecialPurposeFolders.contains(specialPurpose)) {
52 /* //Try to find an existing drafts folder */ 53 //Try to find an existing drafts folder
53 /* Sink::EntityReader<ApplicationDomain::Folder> reader(mResourceType, mResourceInstanceIdentifier); */ 54 DataStoreQuery dataStoreQuery{Sink::Query().filter<ApplicationDomain::Folder::SpecialPurpose>(Query::Comparator(specialPurpose, Query::Comparator::Contains)), ApplicationDomain::getTypeName<ApplicationDomain::Folder>(), entityStore()};
54 /* reader.query(Sink::Query().filter<ApplicationDomain::Folder::SpecialPurpose>(Query::Comparator(specialPurpose, Query::Comparator::Contains)), */ 55 auto resultSet = dataStoreQuery.execute();
55 /* [this, specialPurpose](const ApplicationDomain::Folder &f) -> bool{ */ 56 resultSet.replaySet(0, 1, [&, this](const ResultSet::Result &r) {
56 /* mSpecialPurposeFolders.insert(specialPurpose, f.identifier()); */ 57 mSpecialPurposeFolders.insert(specialPurpose, r.entity.identifier());
57 /* return false; */ 58 });
58 /* }); */ 59
59 /* if (!mSpecialPurposeFolders.contains(specialPurpose)) { */ 60 if (!mSpecialPurposeFolders.contains(specialPurpose)) {
60 /* SinkTrace() << "Failed to find a drafts folder, creating a new one"; */ 61 SinkTrace() << "Failed to find a drafts folder, creating a new one";
61 /* auto folder = ApplicationDomain::Folder::create(mResourceInstanceIdentifier); */ 62 auto folder = ApplicationDomain::Folder::create(mResourceInstanceIdentifier);
62 /* folder.setSpecialPurpose(QByteArrayList() << specialPurpose); */ 63 folder.setSpecialPurpose(QByteArrayList() << specialPurpose);
63 /* folder.setName(sSpecialPurposeFolders.value(specialPurpose)); */ 64 folder.setName(sSpecialPurposeFolders.value(specialPurpose));
64 /* folder.setIcon("folder"); */ 65 folder.setIcon("folder");
65 /* //This processes the pipeline synchronously */ 66 //This processes the pipeline synchronously
66 /* createEntity(folder); */ 67 createEntity(folder);
67 /* mSpecialPurposeFolders.insert(specialPurpose, folder.identifier()); */ 68 mSpecialPurposeFolders.insert(specialPurpose, folder.identifier());
68 /* } */ 69 }
69 /* } */ 70 }
70 return mSpecialPurposeFolders.value(specialPurpose); 71 return mSpecialPurposeFolders.value(specialPurpose);
71} 72}
72 73
diff --git a/common/storage/entitystore.h b/common/storage/entitystore.h
index 65bff50..39f5fc1 100644
--- a/common/storage/entitystore.h
+++ b/common/storage/entitystore.h
@@ -42,6 +42,7 @@ public:
42 typedef std::function<void(ApplicationDomain::ApplicationDomainType &)> PreprocessCreation; 42 typedef std::function<void(ApplicationDomain::ApplicationDomainType &)> PreprocessCreation;
43 typedef std::function<void(const ApplicationDomain::ApplicationDomainType &)> PreprocessRemoval; 43 typedef std::function<void(const ApplicationDomain::ApplicationDomainType &)> PreprocessRemoval;
44 44
45 //Only the pipeline may call the following functions outside of tests
45 bool add(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &, bool replayToSource, const PreprocessCreation &); 46 bool add(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &, bool replayToSource, const PreprocessCreation &);
46 bool modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &, const QByteArrayList &deletions, bool replayToSource, const PreprocessModification &); 47 bool modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &, const QByteArrayList &deletions, bool replayToSource, const PreprocessModification &);
47 bool remove(const QByteArray &type, const QByteArray &uid, bool replayToSource, const PreprocessRemoval &); 48 bool remove(const QByteArray &type, const QByteArray &uid, bool replayToSource, const PreprocessRemoval &);