summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/domain/applicationdomaintype.h8
-rw-r--r--common/store.cpp45
-rw-r--r--tests/clientapitest.cpp20
-rw-r--r--tests/mailthreadtest.cpp1
4 files changed, 65 insertions, 9 deletions
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h
index dcd401c..f2216da 100644
--- a/common/domain/applicationdomaintype.h
+++ b/common/domain/applicationdomaintype.h
@@ -242,6 +242,14 @@ public:
242 return object; 242 return object;
243 } 243 }
244 244
245 template <class DomainType>
246 static DomainType createCopy(const QByteArray &identifier, const DomainType &original)
247 {
248 DomainType object(original);
249 object.mIdentifier = identifier;
250 return object;
251 }
252
245 virtual ~ApplicationDomainType(); 253 virtual ~ApplicationDomainType();
246 254
247 bool hasProperty(const QByteArray &key) const; 255 bool hasProperty(const QByteArray &key) const;
diff --git a/common/store.cpp b/common/store.cpp
index 022c40e..ad2bb1c 100644
--- a/common/store.cpp
+++ b/common/store.cpp
@@ -195,9 +195,8 @@ template <class DomainType>
195KAsync::Job<void> Store::create(const DomainType &domainObject) 195KAsync::Job<void> Store::create(const DomainType &domainObject)
196{ 196{
197 SinkLog() << "Create: " << domainObject; 197 SinkLog() << "Create: " << domainObject;
198 // Potentially move to separate thread as well
199 auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); 198 auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier());
200 return facade->create(domainObject).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to create"; }); 199 return facade->create(domainObject).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to create " << error; });
201} 200}
202 201
203template <class DomainType> 202template <class DomainType>
@@ -208,8 +207,15 @@ KAsync::Job<void> Store::modify(const DomainType &domainObject)
208 return KAsync::null(); 207 return KAsync::null();
209 } 208 }
210 SinkLog() << "Modify: " << domainObject; 209 SinkLog() << "Modify: " << domainObject;
211 // Potentially move to separate thread as well
212 auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); 210 auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier());
211 if (domainObject.isAggregate()) {
212 return KAsync::value(domainObject.aggregatedIds())
213 .addToContext(std::shared_ptr<void>(facade))
214 .each([=] (const QByteArray &id) {
215 auto object = Sink::ApplicationDomain::ApplicationDomainType::createCopy(id, domainObject);
216 return facade->modify(object).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to modify " << error; });
217 });
218 }
213 return facade->modify(domainObject).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to modify"; }); 219 return facade->modify(domainObject).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to modify"; });
214} 220}
215 221
@@ -235,27 +241,48 @@ template <class DomainType>
235KAsync::Job<void> Store::move(const DomainType &domainObject, const QByteArray &newResource) 241KAsync::Job<void> Store::move(const DomainType &domainObject, const QByteArray &newResource)
236{ 242{
237 SinkLog() << "Move: " << domainObject << newResource; 243 SinkLog() << "Move: " << domainObject << newResource;
238 // Potentially move to separate thread as well
239 auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); 244 auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier());
240 return facade->move(domainObject, newResource).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to move"; }); 245 if (domainObject.isAggregate()) {
246 return KAsync::value(domainObject.aggregatedIds())
247 .addToContext(std::shared_ptr<void>(facade))
248 .each([=] (const QByteArray &id) {
249 auto object = Sink::ApplicationDomain::ApplicationDomainType::createCopy(id, domainObject);
250 return facade->move(object, newResource).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to move " << error; });
251 });
252 }
253 return facade->move(domainObject, newResource).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to move " << error; });
241} 254}
242 255
243template <class DomainType> 256template <class DomainType>
244KAsync::Job<void> Store::copy(const DomainType &domainObject, const QByteArray &newResource) 257KAsync::Job<void> Store::copy(const DomainType &domainObject, const QByteArray &newResource)
245{ 258{
246 SinkLog() << "Copy: " << domainObject << newResource; 259 SinkLog() << "Copy: " << domainObject << newResource;
247 // Potentially copy to separate thread as well
248 auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); 260 auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier());
249 return facade->copy(domainObject, newResource).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to copy"; }); 261 if (domainObject.isAggregate()) {
262 return KAsync::value(domainObject.aggregatedIds())
263 .addToContext(std::shared_ptr<void>(facade))
264 .each([=] (const QByteArray &id) {
265 auto object = Sink::ApplicationDomain::ApplicationDomainType::createCopy(id, domainObject);
266 return facade->copy(object, newResource).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to copy " << error; });
267 });
268 }
269 return facade->copy(domainObject, newResource).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to copy " << error; });
250} 270}
251 271
252template <class DomainType> 272template <class DomainType>
253KAsync::Job<void> Store::remove(const DomainType &domainObject) 273KAsync::Job<void> Store::remove(const DomainType &domainObject)
254{ 274{
255 SinkLog() << "Remove: " << domainObject; 275 SinkLog() << "Remove: " << domainObject;
256 // Potentially move to separate thread as well
257 auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); 276 auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier());
258 return facade->remove(domainObject).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to remove"; }); 277 if (domainObject.isAggregate()) {
278 return KAsync::value(domainObject.aggregatedIds())
279 .addToContext(std::shared_ptr<void>(facade))
280 .each([=] (const QByteArray &id) {
281 auto object = Sink::ApplicationDomain::ApplicationDomainType::createCopy(id, domainObject);
282 return facade->remove(object).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to remove " << error; });
283 });
284 }
285 return facade->remove(domainObject).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to remove " << error; });
259} 286}
260 287
261template <class DomainType> 288template <class DomainType>
diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp
index 3582a3c..e2f3543 100644
--- a/tests/clientapitest.cpp
+++ b/tests/clientapitest.cpp
@@ -412,6 +412,26 @@ private slots:
412 } 412 }
413 } 413 }
414 414
415 void testAggregateModify()
416 {
417 auto facade = setupFacade<Sink::ApplicationDomain::Event>("dummyresource.instance1");
418 facade->results << QSharedPointer<Sink::ApplicationDomain::Event>::create("dummyresource.instance1", "id1", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
419 facade->results << QSharedPointer<Sink::ApplicationDomain::Event>::create("dummyresource.instance1", "id2", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
420
421 Sink::ApplicationDomain::Event modification("dummyresource.instance1", "id1", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
422 modification.aggregatedIds() << "id1" << "id2";
423 modification.setUid("modifiedUid2");
424
425 Sink::Store::modify(modification).exec().waitForFinished();
426 QCOMPARE(facade->modifications.size(), 2);
427 for (const auto &m : facade->modifications) {
428 QCOMPARE(m.getUid(), {"modifiedUid2"});
429 }
430
431 Sink::Store::remove(modification).exec().waitForFinished();
432 QCOMPARE(facade->removals.size(), 2);
433 }
434
415 void testModelStress() 435 void testModelStress()
416 { 436 {
417 auto facade = setupFacade<Sink::ApplicationDomain::Folder>("dummyresource.instance1"); 437 auto facade = setupFacade<Sink::ApplicationDomain::Folder>("dummyresource.instance1");
diff --git a/tests/mailthreadtest.cpp b/tests/mailthreadtest.cpp
index eabfc81..8c325d8 100644
--- a/tests/mailthreadtest.cpp
+++ b/tests/mailthreadtest.cpp
@@ -78,6 +78,7 @@ void MailThreadTest::testListThreadLeader()
78 QVERIFY(mails.first().getSubject().startsWith(QString("ThreadLeader"))); 78 QVERIFY(mails.first().getSubject().startsWith(QString("ThreadLeader")));
79 auto threadSize = mails.first().getProperty("count").toInt(); 79 auto threadSize = mails.first().getProperty("count").toInt();
80 QCOMPARE(threadSize, 2); 80 QCOMPARE(threadSize, 2);
81 QCOMPARE(mails.first().aggregatedIds().size(), 2);
81} 82}
82 83
83/* 84/*