summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/domain/applicationdomaintype.h8
-rw-r--r--common/store.cpp45
2 files changed, 44 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>