From a3c4a70b635889ffba6477034d998984f889a719 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 21 Feb 2018 21:24:01 +0100 Subject: Apply modifications to aggregate values --- common/domain/applicationdomaintype.h | 8 +++++++ common/store.cpp | 45 ++++++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 9 deletions(-) (limited to 'common') 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: return object; } + template + static DomainType createCopy(const QByteArray &identifier, const DomainType &original) + { + DomainType object(original); + object.mIdentifier = identifier; + return object; + } + virtual ~ApplicationDomainType(); 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 KAsync::Job Store::create(const DomainType &domainObject) { SinkLog() << "Create: " << domainObject; - // Potentially move to separate thread as well auto facade = getFacade(domainObject.resourceInstanceIdentifier()); - return facade->create(domainObject).addToContext(std::shared_ptr(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to create"; }); + return facade->create(domainObject).addToContext(std::shared_ptr(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to create " << error; }); } template @@ -208,8 +207,15 @@ KAsync::Job Store::modify(const DomainType &domainObject) return KAsync::null(); } SinkLog() << "Modify: " << domainObject; - // Potentially move to separate thread as well auto facade = getFacade(domainObject.resourceInstanceIdentifier()); + if (domainObject.isAggregate()) { + return KAsync::value(domainObject.aggregatedIds()) + .addToContext(std::shared_ptr(facade)) + .each([=] (const QByteArray &id) { + auto object = Sink::ApplicationDomain::ApplicationDomainType::createCopy(id, domainObject); + return facade->modify(object).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to modify " << error; }); + }); + } return facade->modify(domainObject).addToContext(std::shared_ptr(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to modify"; }); } @@ -235,27 +241,48 @@ template KAsync::Job Store::move(const DomainType &domainObject, const QByteArray &newResource) { SinkLog() << "Move: " << domainObject << newResource; - // Potentially move to separate thread as well auto facade = getFacade(domainObject.resourceInstanceIdentifier()); - return facade->move(domainObject, newResource).addToContext(std::shared_ptr(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to move"; }); + if (domainObject.isAggregate()) { + return KAsync::value(domainObject.aggregatedIds()) + .addToContext(std::shared_ptr(facade)) + .each([=] (const QByteArray &id) { + auto object = Sink::ApplicationDomain::ApplicationDomainType::createCopy(id, domainObject); + return facade->move(object, newResource).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to move " << error; }); + }); + } + return facade->move(domainObject, newResource).addToContext(std::shared_ptr(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to move " << error; }); } template KAsync::Job Store::copy(const DomainType &domainObject, const QByteArray &newResource) { SinkLog() << "Copy: " << domainObject << newResource; - // Potentially copy to separate thread as well auto facade = getFacade(domainObject.resourceInstanceIdentifier()); - return facade->copy(domainObject, newResource).addToContext(std::shared_ptr(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to copy"; }); + if (domainObject.isAggregate()) { + return KAsync::value(domainObject.aggregatedIds()) + .addToContext(std::shared_ptr(facade)) + .each([=] (const QByteArray &id) { + auto object = Sink::ApplicationDomain::ApplicationDomainType::createCopy(id, domainObject); + return facade->copy(object, newResource).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to copy " << error; }); + }); + } + return facade->copy(domainObject, newResource).addToContext(std::shared_ptr(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to copy " << error; }); } template KAsync::Job Store::remove(const DomainType &domainObject) { SinkLog() << "Remove: " << domainObject; - // Potentially move to separate thread as well auto facade = getFacade(domainObject.resourceInstanceIdentifier()); - return facade->remove(domainObject).addToContext(std::shared_ptr(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to remove"; }); + if (domainObject.isAggregate()) { + return KAsync::value(domainObject.aggregatedIds()) + .addToContext(std::shared_ptr(facade)) + .each([=] (const QByteArray &id) { + auto object = Sink::ApplicationDomain::ApplicationDomainType::createCopy(id, domainObject); + return facade->remove(object).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to remove " << error; }); + }); + } + return facade->remove(domainObject).addToContext(std::shared_ptr(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to remove " << error; }); } template -- cgit v1.2.3