summaryrefslogtreecommitdiffstats
path: root/examples/dummyresource/resourcefactory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/dummyresource/resourcefactory.cpp')
-rw-r--r--examples/dummyresource/resourcefactory.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp
index e524c3f..8dae749 100644
--- a/examples/dummyresource/resourcefactory.cpp
+++ b/examples/dummyresource/resourcefactory.cpp
@@ -36,6 +36,7 @@
36#include "definitions.h" 36#include "definitions.h"
37#include "facadefactory.h" 37#include "facadefactory.h"
38#include <QDate> 38#include <QDate>
39#include <QUuid>
39 40
40//This is the resources entity type, and not the domain type 41//This is the resources entity type, and not the domain type
41#define ENTITY_TYPE_EVENT "event" 42#define ENTITY_TYPE_EVENT "event"
@@ -182,6 +183,19 @@ void DummyResource::createMail(const QByteArray &ridBuffer, const QMap<QString,
182 Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, 0, 0, m_fbb.GetBufferPointer(), m_fbb.GetSize()); 183 Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, 0, 0, m_fbb.GetBufferPointer(), m_fbb.GetSize());
183} 184}
184 185
186QString DummyResource::resolveRemoteId(const QString &remoteId)
187{
188 //Lookup local id for remote id, or insert a new pair otherwise
189 Akonadi2::Storage store(Akonadi2::storageLocation(), mResourceInstanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite);
190 auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite);
191 QByteArray akonadiId = Index("rid.mapping", transaction).lookup(remoteId.toLatin1());
192 if (akonadiId.isEmpty()) {
193 akonadiId = QUuid::createUuid().toString().toUtf8();
194 Index("rid.mapping", transaction).add(remoteId.toLatin1(), akonadiId);
195 }
196 return akonadiId;
197}
198
185void DummyResource::createFolder(const QByteArray &ridBuffer, const QMap<QString, QVariant> &data, flatbuffers::FlatBufferBuilder &entityFbb) 199void DummyResource::createFolder(const QByteArray &ridBuffer, const QMap<QString, QVariant> &data, flatbuffers::FlatBufferBuilder &entityFbb)
186{ 200{
187 //Map the source format to the buffer format (which happens to be an exact copy here) 201 //Map the source format to the buffer format (which happens to be an exact copy here)
@@ -190,7 +204,8 @@ void DummyResource::createFolder(const QByteArray &ridBuffer, const QMap<QString
190 bool hasParent = false; 204 bool hasParent = false;
191 if (!data.value("parent").toString().isEmpty()) { 205 if (!data.value("parent").toString().isEmpty()) {
192 hasParent = true; 206 hasParent = true;
193 parent = m_fbb.CreateString(data.value("parent").toString().toStdString()); 207 auto akonadiId = resolveRemoteId(data.value("parent").toString());
208 parent = m_fbb.CreateString(akonadiId.toStdString());
194 } 209 }
195 210
196 auto builder = Akonadi2::ApplicationDomain::Buffer::FolderBuilder(m_fbb); 211 auto builder = Akonadi2::ApplicationDomain::Buffer::FolderBuilder(m_fbb);
@@ -222,11 +237,14 @@ void DummyResource::synchronize(const QString &bufferType, const QMap<QString, Q
222 flatbuffers::FlatBufferBuilder entityFbb; 237 flatbuffers::FlatBufferBuilder entityFbb;
223 createEntity(it.key().toUtf8(), it.value(), entityFbb); 238 createEntity(it.key().toUtf8(), it.value(), entityFbb);
224 239
240 auto akonadiId = resolveRemoteId(it.key());
241
225 flatbuffers::FlatBufferBuilder fbb; 242 flatbuffers::FlatBufferBuilder fbb;
226 //This is the resource type and not the domain type 243 //This is the resource type and not the domain type
244 auto entityId = fbb.CreateString(akonadiId.toStdString());
227 auto type = fbb.CreateString(bufferType.toStdString()); 245 auto type = fbb.CreateString(bufferType.toStdString());
228 auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); 246 auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize());
229 auto location = Akonadi2::Commands::CreateCreateEntity(fbb, type, delta); 247 auto location = Akonadi2::Commands::CreateCreateEntity(fbb, entityId, type, delta);
230 Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); 248 Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location);
231 249
232 enqueueCommand(mSynchronizerQueue, Akonadi2::Commands::CreateEntityCommand, QByteArray::fromRawData(reinterpret_cast<char const *>(fbb.GetBufferPointer()), fbb.GetSize())); 250 enqueueCommand(mSynchronizerQueue, Akonadi2::Commands::CreateEntityCommand, QByteArray::fromRawData(reinterpret_cast<char const *>(fbb.GetBufferPointer()), fbb.GetSize()));