From 0b233494a69b5e9cd86e91c60016a294e6c9ef50 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 1 Feb 2016 13:12:37 +0100 Subject: Fixed modifications --- common/domain/applicationdomaintype.cpp | 9 +++++++-- common/domain/applicationdomaintype.h | 21 +++++++++++++++++---- common/domain/event.cpp | 2 ++ common/pipeline.cpp | 16 +++++++++++++--- tests/pipelinetest.cpp | 12 +++++++++--- 5 files changed, 48 insertions(+), 12 deletions(-) diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index fccf082..1649cb4 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp @@ -76,13 +76,18 @@ QVariant ApplicationDomainType::getProperty(const QByteArray &key) const void ApplicationDomainType::setProperty(const QByteArray &key, const QVariant &value) { Q_ASSERT(mAdaptor); - mChangeSet.insert(key, value); + mChangeSet.insert(key); mAdaptor->setProperty(key, value); } +void ApplicationDomainType::setChangedProperties(const QSet &changeset) +{ + mChangeSet = changeset; +} + QByteArrayList ApplicationDomainType::changedProperties() const { - return mChangeSet.keys(); + return mChangeSet.toList(); } qint64 ApplicationDomainType::revision() const diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index ca1ec1b..ce35af0 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h @@ -23,6 +23,7 @@ #include #include #include +#include #include "bufferadaptor.h" namespace Sink { @@ -56,16 +57,18 @@ public: virtual ~ApplicationDomainType(); - virtual QVariant getProperty(const QByteArray &key) const; - virtual void setProperty(const QByteArray &key, const QVariant &value); - virtual QByteArrayList changedProperties() const; + QVariant getProperty(const QByteArray &key) const;; + void setProperty(const QByteArray &key, const QVariant &value); + void setChangedProperties(const QSet &changeset); + QByteArrayList changedProperties() const; qint64 revision() const; QByteArray resourceInstanceIdentifier() const; QByteArray identifier() const; private: + friend QDebug operator<<(QDebug, const ApplicationDomainType &); QSharedPointer mAdaptor; - QHash mChangeSet; + QSet mChangeSet; /* * Each domain object needs to store the resource, identifier, revision triple so we can link back to the storage location. */ @@ -83,6 +86,16 @@ inline bool operator==(const ApplicationDomainType& lhs, const ApplicationDomain && lhs.resourceInstanceIdentifier() == rhs.resourceInstanceIdentifier(); } +inline QDebug operator<< (QDebug d, const ApplicationDomainType &type) +{ + d << "ApplicationDomainType(\n"; + for (const auto &property : type.mAdaptor->availableProperties()) { + d << " " << property << "\t" << type.getProperty(property) << "\n"; + } + d << ")"; + return d; +} + struct SINKCOMMON_EXPORT Entity : public ApplicationDomainType { typedef QSharedPointer Ptr; using ApplicationDomainType::ApplicationDomainType; diff --git a/common/domain/event.cpp b/common/domain/event.cpp index 9f81eb8..4210125 100644 --- a/common/domain/event.cpp +++ b/common/domain/event.cpp @@ -69,6 +69,7 @@ QSharedPointer::Buffer> > TypeImple { auto propertyMapper = QSharedPointer >::create(); propertyMapper->addMapping("summary", &Buffer::summary); + propertyMapper->addMapping("description", &Buffer::description); propertyMapper->addMapping("uid", &Buffer::uid); propertyMapper->addMapping("attachment", &Buffer::attachment); return propertyMapper; @@ -78,6 +79,7 @@ QSharedPointer::BufferBuilder> > T { auto propertyMapper = QSharedPointer >::create(); propertyMapper->addMapping("summary", &BufferBuilder::add_summary); + propertyMapper->addMapping("description", &BufferBuilder::add_description); propertyMapper->addMapping("uid", &BufferBuilder::add_uid); propertyMapper->addMapping("attachment", &BufferBuilder::add_attachment); return propertyMapper; diff --git a/common/pipeline.cpp b/common/pipeline.cpp index 0598bad..03d4e42 100644 --- a/common/pipeline.cpp +++ b/common/pipeline.cpp @@ -279,9 +279,16 @@ KAsync::Job Pipeline::modifiedEntity(void const *command, size_t size) //Apply diff //FIXME only apply the properties that are available in the buffer Trace() << "Applying changed properties: " << diff->availableProperties(); + QSet changeset; for (const auto &property : diff->availableProperties()) { - newObject->setProperty(property, diff->getProperty(property)); + changeset << property; + const auto value = diff->getProperty(property); + if (value.isValid()) { + newObject->setProperty(property, value); + } } + //Altough we only set some properties, we want all to be serialized + newObject->setChangedProperties(changeset); //Remove deletions if (modifyEntity->deletions()) { @@ -304,8 +311,11 @@ KAsync::Job Pipeline::modifiedEntity(void const *command, size_t size) storeNewRevision(newRevision, fbb, bufferType, key); Log() << "Pipeline: modified entity: " << key << newRevision << bufferType; - d->transaction.openDatabase(bufferType + ".main").scan(Sink::Storage::assembleKey(key, newRevision), [this, bufferType, newRevision, adaptorFactory, current, key](const QByteArray &, const QByteArray &value) -> bool { - auto entity = Sink::GetEntity(value); + d->transaction.openDatabase(bufferType + ".main").scan(Sink::Storage::assembleKey(key, newRevision), [this, bufferType, newRevision, adaptorFactory, current, key](const QByteArray &k, const QByteArray &value) -> bool { + if (value.isEmpty()) { + ErrorMsg() << "Read buffer is empty."; + } + auto entity = Sink::GetEntity(value.data()); auto newEntity = adaptorFactory->createAdaptor(*entity); for (auto processor : d->processors[bufferType]) { processor->modifiedEntity(key, newRevision, *current, *newEntity, d->transaction); diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp index c74d319..baa67f6 100644 --- a/tests/pipelinetest.cpp +++ b/tests/pipelinetest.cpp @@ -52,7 +52,7 @@ static QByteArray getEntity(const QByteArray &dbEnv, const QByteArray &name, con return result; } -flatbuffers::FlatBufferBuilder &createEvent(flatbuffers::FlatBufferBuilder &entityFbb, const QString &s = QString("summary")) +flatbuffers::FlatBufferBuilder &createEvent(flatbuffers::FlatBufferBuilder &entityFbb, const QString &s = QString("summary"), const QString &d = QString()) { flatbuffers::FlatBufferBuilder eventFbb; eventFbb.Clear(); @@ -66,9 +66,13 @@ flatbuffers::FlatBufferBuilder &createEvent(flatbuffers::FlatBufferBuilder &enti { auto uid = localFbb.CreateString("testuid"); auto summary = localFbb.CreateString(s.toStdString()); + auto description = localFbb.CreateString(d.toStdString()); auto localBuilder = Sink::ApplicationDomain::Buffer::EventBuilder(localFbb); localBuilder.add_uid(uid); localBuilder.add_summary(summary); + if (!d.isEmpty()) { + localBuilder.add_description(description); + } auto location = localBuilder.Finish(); Sink::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location); } @@ -203,7 +207,7 @@ private Q_SLOTS: void testModify() { flatbuffers::FlatBufferBuilder entityFbb; - auto command = createEntityCommand(createEvent(entityFbb)); + auto command = createEntityCommand(createEvent(entityFbb, "summary", "description")); Sink::Pipeline pipeline("org.kde.pipelinetest.instance1"); @@ -233,7 +237,9 @@ private Q_SLOTS: QVERIFY(!buffer.isEmpty()); Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); - QCOMPARE(adaptor->getProperty("summary").toString(), QString("summary2")); + QVERIFY2(adaptor->getProperty("summary").toString() == QString("summary2"), "The modification isn't applied."); + //Ensure we didn't modify anything else + QVERIFY2(adaptor->getProperty("description").toString() == QString("description"), "The modification has sideeffects."); //Both revisions are in the store at this point QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 2); -- cgit v1.2.3