From 21da1b751d0f55648a7c9dbe71a3cd3440a134f0 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 19 Oct 2016 15:47:39 +0200 Subject: Fixed specialpurposeprocessor --- common/pipeline.cpp | 11 ++++++++-- common/pipeline.h | 7 ++++++- common/specialpurposepreprocessor.cpp | 39 ++++++++++++++++++----------------- common/storage/entitystore.h | 1 + 4 files changed, 36 insertions(+), 22 deletions(-) (limited to 'common') 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 QVectorprocessors[entityType]; list.clear(); for (auto p : processors) { - p->setup(d->resourceContext.resourceType, d->resourceContext.instanceId(), this); + p->setup(d->resourceContext.resourceType, d->resourceContext.instanceId(), this, &d->entityStore); list.append(QSharedPointer(p)); } } @@ -307,6 +307,7 @@ public: QByteArray resourceType; QByteArray resourceInstanceIdentifier; Pipeline *pipeline; + Storage::EntityStore *entityStore; }; Preprocessor::Preprocessor() : d(new Preprocessor::Private) @@ -317,11 +318,12 @@ Preprocessor::~Preprocessor() { } -void Preprocessor::setup(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier, Pipeline *pipeline) +void Preprocessor::setup(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier, Pipeline *pipeline, Storage::EntityStore *entityStore) { d->resourceType = resourceType; d->resourceInstanceIdentifier = resourceInstanceIdentifier; d->pipeline = pipeline; + d->entityStore = entityStore; } void Preprocessor::startBatch() @@ -337,6 +339,11 @@ QByteArray Preprocessor::resourceInstanceIdentifier() const return d->resourceInstanceIdentifier; } +Storage::EntityStore &Preprocessor::entityStore() const +{ + return *d->entityStore; +} + void Preprocessor::createEntity(const Sink::ApplicationDomain::ApplicationDomainType &entity, const QByteArray &typeName) { 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 @@ #include namespace Sink { +namespace Storage { + class EntityStore; +} class Preprocessor; @@ -87,7 +90,7 @@ public: virtual void deletedEntity(const ApplicationDomain::ApplicationDomainType &oldEntity) {}; virtual void finalizeBatch(); - void setup(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier, Pipeline *); + void setup(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier, Pipeline *, Storage::EntityStore *entityStore); protected: template @@ -99,6 +102,8 @@ protected: QByteArray resourceInstanceIdentifier() const; + Storage::EntityStore &entityStore() const; + private: friend class Pipeline; 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 @@ #include "specialpurposepreprocessor.h" #include "query.h" #include "applicationdomaintype.h" +#include "datastorequery.h" using namespace Sink; @@ -48,25 +49,25 @@ SpecialPurposeProcessor::SpecialPurposeProcessor(const QByteArray &resourceType, QByteArray SpecialPurposeProcessor::ensureFolder(const QByteArray &specialPurpose) { - /* if (!mSpecialPurposeFolders.contains(specialPurpose)) { */ - /* //Try to find an existing drafts folder */ - /* Sink::EntityReader reader(mResourceType, mResourceInstanceIdentifier); */ - /* reader.query(Sink::Query().filter(Query::Comparator(specialPurpose, Query::Comparator::Contains)), */ - /* [this, specialPurpose](const ApplicationDomain::Folder &f) -> bool{ */ - /* mSpecialPurposeFolders.insert(specialPurpose, f.identifier()); */ - /* return false; */ - /* }); */ - /* if (!mSpecialPurposeFolders.contains(specialPurpose)) { */ - /* SinkTrace() << "Failed to find a drafts folder, creating a new one"; */ - /* auto folder = ApplicationDomain::Folder::create(mResourceInstanceIdentifier); */ - /* folder.setSpecialPurpose(QByteArrayList() << specialPurpose); */ - /* folder.setName(sSpecialPurposeFolders.value(specialPurpose)); */ - /* folder.setIcon("folder"); */ - /* //This processes the pipeline synchronously */ - /* createEntity(folder); */ - /* mSpecialPurposeFolders.insert(specialPurpose, folder.identifier()); */ - /* } */ - /* } */ + if (!mSpecialPurposeFolders.contains(specialPurpose)) { + //Try to find an existing drafts folder + DataStoreQuery dataStoreQuery{Sink::Query().filter(Query::Comparator(specialPurpose, Query::Comparator::Contains)), ApplicationDomain::getTypeName(), entityStore()}; + auto resultSet = dataStoreQuery.execute(); + resultSet.replaySet(0, 1, [&, this](const ResultSet::Result &r) { + mSpecialPurposeFolders.insert(specialPurpose, r.entity.identifier()); + }); + + if (!mSpecialPurposeFolders.contains(specialPurpose)) { + SinkTrace() << "Failed to find a drafts folder, creating a new one"; + auto folder = ApplicationDomain::Folder::create(mResourceInstanceIdentifier); + folder.setSpecialPurpose(QByteArrayList() << specialPurpose); + folder.setName(sSpecialPurposeFolders.value(specialPurpose)); + folder.setIcon("folder"); + //This processes the pipeline synchronously + createEntity(folder); + mSpecialPurposeFolders.insert(specialPurpose, folder.identifier()); + } + } return mSpecialPurposeFolders.value(specialPurpose); } 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: typedef std::function PreprocessCreation; typedef std::function PreprocessRemoval; + //Only the pipeline may call the following functions outside of tests bool add(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &, bool replayToSource, const PreprocessCreation &); bool modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &, const QByteArrayList &deletions, bool replayToSource, const PreprocessModification &); bool remove(const QByteArray &type, const QByteArray &uid, bool replayToSource, const PreprocessRemoval &); -- cgit v1.2.3