diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-10-04 17:12:02 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-10-04 17:12:02 +0200 |
commit | 3ae3ef9676bd7fdcb45064f9a1b397c90478b4b7 (patch) | |
tree | 5ac341b501dae0a5e7d5addb8114535de53979cf /common/store.cpp | |
parent | 7757d32b5a820623c469b7851354374427142598 (diff) | |
download | sink-3ae3ef9676bd7fdcb45064f9a1b397c90478b4b7.tar.gz sink-3ae3ef9676bd7fdcb45064f9a1b397c90478b4b7.zip |
Resource subqueries
Diffstat (limited to 'common/store.cpp')
-rw-r--r-- | common/store.cpp | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/common/store.cpp b/common/store.cpp index a1b3c17..efe1179 100644 --- a/common/store.cpp +++ b/common/store.cpp | |||
@@ -57,13 +57,28 @@ 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 QList<QByteArray> &resourceFilter, const QList<QByteArray> &accountFilter,const QByteArray &type = QByteArray()) | 60 | static QMap<QByteArray, QByteArray> getResources(const Sink::Query &query, const QByteArray &type = QByteArray()) |
61 | { | 61 | { |
62 | const QList<QByteArray> resourceFilter = query.resources; | ||
63 | const QList<QByteArray> accountFilter = query.accounts; | ||
64 | |||
65 | auto resourceComparator = query.getFilter(Sink::ApplicationDomain::Entity::Resource::name); | ||
66 | |||
62 | const auto filterResource = [&](const QByteArray &res) { | 67 | const auto filterResource = [&](const QByteArray &res) { |
63 | const auto configuration = ResourceConfig::getConfiguration(res); | 68 | const auto configuration = ResourceConfig::getConfiguration(res); |
64 | if (!accountFilter.isEmpty() && !accountFilter.contains(configuration.value("account").toByteArray())) { | 69 | if (!accountFilter.isEmpty() && !accountFilter.contains(configuration.value(ApplicationDomain::SinkResource::Account::name).toByteArray())) { |
65 | return true; | 70 | return true; |
66 | } | 71 | } |
72 | //Subquery for the resource | ||
73 | if (resourceComparator.value.canConvert<Query>()) { | ||
74 | auto subquery = resourceComparator.value.value<Query>(); | ||
75 | for (const auto &filterProperty : subquery.propertyFilter.keys()) { | ||
76 | const auto filter = subquery.propertyFilter.value(filterProperty); | ||
77 | if (!filter.matches(configuration.value(filterProperty))) { | ||
78 | return true; | ||
79 | } | ||
80 | } | ||
81 | } | ||
67 | return false; | 82 | return false; |
68 | }; | 83 | }; |
69 | 84 | ||
@@ -139,7 +154,7 @@ QSharedPointer<QAbstractItemModel> Store::loadModel(Query query) | |||
139 | //* The result provider needs to live for as long as results are provided (until the last thread exits). | 154 | //* The result provider needs to live for as long as results are provided (until the last thread exits). |
140 | 155 | ||
141 | // Query all resources and aggregate results | 156 | // Query all resources and aggregate results |
142 | auto resources = getResources(query.resources, query.accounts, ApplicationDomain::getTypeName<DomainType>()); | 157 | auto resources = getResources(query, ApplicationDomain::getTypeName<DomainType>()); |
143 | auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); | 158 | auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); |
144 | model->setEmitter(aggregatingEmitter); | 159 | model->setEmitter(aggregatingEmitter); |
145 | 160 | ||
@@ -252,7 +267,7 @@ KAsync::Job<void> Store::removeDataFromDisk(const QByteArray &identifier) | |||
252 | KAsync::Job<void> Store::synchronize(const Sink::Query &query) | 267 | KAsync::Job<void> Store::synchronize(const Sink::Query &query) |
253 | { | 268 | { |
254 | SinkTrace() << "synchronize" << query.resources; | 269 | SinkTrace() << "synchronize" << query.resources; |
255 | auto resources = getResources(query.resources, query.accounts).keys(); | 270 | auto resources = getResources(query).keys(); |
256 | //FIXME only necessary because each doesn't propagate errors | 271 | //FIXME only necessary because each doesn't propagate errors |
257 | auto errorFlag = new bool; | 272 | auto errorFlag = new bool; |
258 | return KAsync::value(resources) | 273 | return KAsync::value(resources) |
@@ -352,7 +367,7 @@ QList<DomainType> Store::read(const Sink::Query &q) | |||
352 | query.synchronousQuery = true; | 367 | query.synchronousQuery = true; |
353 | query.liveQuery = false; | 368 | query.liveQuery = false; |
354 | QList<DomainType> list; | 369 | QList<DomainType> list; |
355 | auto resources = getResources(query.resources, query.accounts, ApplicationDomain::getTypeName<DomainType>()); | 370 | auto resources = getResources(query, ApplicationDomain::getTypeName<DomainType>()); |
356 | auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); | 371 | auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); |
357 | aggregatingEmitter->onAdded([&list](const typename DomainType::Ptr &value){ | 372 | aggregatingEmitter->onAdded([&list](const typename DomainType::Ptr &value){ |
358 | SinkTrace() << "Found value: " << value->identifier(); | 373 | SinkTrace() << "Found value: " << value->identifier(); |