diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-11-04 10:45:20 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-11-04 10:45:20 +0100 |
commit | f4a22e49f23c930b244a1c7f33c7efb9e285750c (patch) | |
tree | 6e3a76c30fd1b24607196724b6f92ec844d28e68 /common/store.cpp | |
parent | 63ca9c4e0be265a4db6b89d444e6fcd8bdd135c1 (diff) | |
download | sink-f4a22e49f23c930b244a1c7f33c7efb9e285750c.tar.gz sink-f4a22e49f23c930b244a1c7f33c7efb9e285750c.zip |
Error propagation works in kasync now.
Diffstat (limited to 'common/store.cpp')
-rw-r--r-- | common/store.cpp | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/common/store.cpp b/common/store.cpp index 52fec2e..d569133 100644 --- a/common/store.cpp +++ b/common/store.cpp | |||
@@ -57,15 +57,15 @@ QString Store::getTemporaryFilePath() | |||
57 | /* | 57 | /* |
58 | * Returns a map of resource instance identifiers and resource type | 58 | * Returns a map of resource instance identifiers and resource type |
59 | */ | 59 | */ |
60 | static QMap<QByteArray, QByteArray> getResources(const Sink::Query &query, const QByteArray &type = QByteArray()) | 60 | static QMap<QByteArray, QByteArray> getResources(const Sink::Query::Filter &query, const QByteArray &type = QByteArray()) |
61 | { | 61 | { |
62 | const QList<QByteArray> resourceFilter = query.getResourceFilter().ids; | 62 | const QList<QByteArray> resourceFilter = query.ids; |
63 | 63 | ||
64 | 64 | ||
65 | const auto filterResource = [&](const QByteArray &res) { | 65 | const auto filterResource = [&](const QByteArray &res) { |
66 | const auto configuration = ResourceConfig::getConfiguration(res); | 66 | const auto configuration = ResourceConfig::getConfiguration(res); |
67 | for (const auto &filterProperty : query.getResourceFilter().propertyFilter.keys()) { | 67 | for (const auto &filterProperty : query.propertyFilter.keys()) { |
68 | const auto filter = query.getResourceFilter().propertyFilter.value(filterProperty); | 68 | const auto filter = query.propertyFilter.value(filterProperty); |
69 | if (!filter.matches(configuration.value(filterProperty))) { | 69 | if (!filter.matches(configuration.value(filterProperty))) { |
70 | return true; | 70 | return true; |
71 | } | 71 | } |
@@ -145,7 +145,7 @@ QSharedPointer<QAbstractItemModel> Store::loadModel(Query query) | |||
145 | //* The result provider needs to live for as long as results are provided (until the last thread exits). | 145 | //* The result provider needs to live for as long as results are provided (until the last thread exits). |
146 | 146 | ||
147 | // Query all resources and aggregate results | 147 | // Query all resources and aggregate results |
148 | auto resources = getResources(query, ApplicationDomain::getTypeName<DomainType>()); | 148 | auto resources = getResources(query.getResourceFilter(), ApplicationDomain::getTypeName<DomainType>()); |
149 | auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); | 149 | auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); |
150 | model->setEmitter(aggregatingEmitter); | 150 | model->setEmitter(aggregatingEmitter); |
151 | 151 | ||
@@ -257,33 +257,22 @@ KAsync::Job<void> Store::removeDataFromDisk(const QByteArray &identifier) | |||
257 | 257 | ||
258 | KAsync::Job<void> Store::synchronize(const Sink::Query &query) | 258 | KAsync::Job<void> Store::synchronize(const Sink::Query &query) |
259 | { | 259 | { |
260 | auto resources = getResources(query).keys(); | 260 | auto resources = getResources(query.getResourceFilter()).keys(); |
261 | SinkTrace() << "synchronize" << resources; | 261 | SinkTrace() << "synchronize" << resources; |
262 | //FIXME only necessary because each doesn't propagate errors | ||
263 | auto errorFlag = new bool; | ||
264 | return KAsync::value(resources) | 262 | return KAsync::value(resources) |
265 | .template each([query, errorFlag](const QByteArray &resource) { | 263 | .template each([query](const QByteArray &resource) { |
266 | SinkTrace() << "Synchronizing " << resource; | 264 | SinkTrace() << "Synchronizing " << resource; |
267 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource)); | 265 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource)); |
268 | resourceAccess->open(); | ||
269 | return resourceAccess->synchronizeResource(true, false) | 266 | return resourceAccess->synchronizeResource(true, false) |
270 | .addToContext(resourceAccess) | 267 | .addToContext(resourceAccess) |
271 | .then<void>([errorFlag](const KAsync::Error &error) { | 268 | .then<void>([](const KAsync::Error &error) { |
272 | if (error) { | 269 | if (error) { |
273 | *errorFlag = true; | ||
274 | SinkWarning() << "Error during sync."; | 270 | SinkWarning() << "Error during sync."; |
275 | return KAsync::error<void>(error); | 271 | return KAsync::error<void>(error); |
276 | } | 272 | } |
277 | SinkTrace() << "synced."; | 273 | SinkTrace() << "synced."; |
278 | return KAsync::null<void>(); | 274 | return KAsync::null<void>(); |
279 | }); | 275 | }); |
280 | }) | ||
281 | .then<void>([errorFlag]() { | ||
282 | if (*errorFlag) { | ||
283 | return KAsync::error<void>("Error during sync."); | ||
284 | } | ||
285 | delete errorFlag; | ||
286 | return KAsync::null<void>(); | ||
287 | }); | 276 | }); |
288 | } | 277 | } |
289 | 278 | ||
@@ -358,7 +347,7 @@ QList<DomainType> Store::read(const Sink::Query &q) | |||
358 | query.synchronousQuery = true; | 347 | query.synchronousQuery = true; |
359 | query.liveQuery = false; | 348 | query.liveQuery = false; |
360 | QList<DomainType> list; | 349 | QList<DomainType> list; |
361 | auto resources = getResources(query, ApplicationDomain::getTypeName<DomainType>()); | 350 | auto resources = getResources(query.getResourceFilter(), ApplicationDomain::getTypeName<DomainType>()); |
362 | auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); | 351 | auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); |
363 | aggregatingEmitter->onAdded([&list](const typename DomainType::Ptr &value){ | 352 | aggregatingEmitter->onAdded([&list](const typename DomainType::Ptr &value){ |
364 | SinkTrace() << "Found value: " << value->identifier(); | 353 | SinkTrace() << "Found value: " << value->identifier(); |