diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-01 16:22:55 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-01 16:22:55 +0200 |
commit | 096d14f20f4dc39d20d35d605ca755b66bd48cf9 (patch) | |
tree | 4b28dd3b310ebcfa9cefa1b41992eeefa5456764 /common/store.cpp | |
parent | c1475df297975b403d991f69ef9436cd576c1e46 (diff) | |
download | sink-096d14f20f4dc39d20d35d605ca755b66bd48cf9.tar.gz sink-096d14f20f4dc39d20d35d605ca755b66bd48cf9.zip |
Account filter for resources and contains comparator in query
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 b89e08c..0ac99be 100644 --- a/common/store.cpp +++ b/common/store.cpp | |||
@@ -54,8 +54,16 @@ QString Store::getTemporaryFilePath() | |||
54 | /* | 54 | /* |
55 | * Returns a map of resource instance identifiers and resource type | 55 | * Returns a map of resource instance identifiers and resource type |
56 | */ | 56 | */ |
57 | static QMap<QByteArray, QByteArray> getResources(const QList<QByteArray> &resourceFilter, const QByteArray &type = QByteArray()) | 57 | static QMap<QByteArray, QByteArray> getResources(const QList<QByteArray> &resourceFilter, const QList<QByteArray> &accountFilter,const QByteArray &type = QByteArray()) |
58 | { | 58 | { |
59 | const auto filterResource = [&](const QByteArray &res) { | ||
60 | const auto configuration = ResourceConfig::getConfiguration(res); | ||
61 | if (!accountFilter.isEmpty() && !accountFilter.contains(configuration.value("account").toByteArray())) { | ||
62 | return true; | ||
63 | } | ||
64 | return false; | ||
65 | }; | ||
66 | |||
59 | QMap<QByteArray, QByteArray> resources; | 67 | QMap<QByteArray, QByteArray> resources; |
60 | // Return the global resource (signified by an empty name) for types that don't belong to a specific resource | 68 | // Return the global resource (signified by an empty name) for types that don't belong to a specific resource |
61 | if (type == "sinkresource" || type == "sinkaccount" || type == "identity") { | 69 | if (type == "sinkresource" || type == "sinkaccount" || type == "identity") { |
@@ -65,15 +73,22 @@ static QMap<QByteArray, QByteArray> getResources(const QList<QByteArray> &resour | |||
65 | const auto configuredResources = ResourceConfig::getResources(); | 73 | const auto configuredResources = ResourceConfig::getResources(); |
66 | if (resourceFilter.isEmpty()) { | 74 | if (resourceFilter.isEmpty()) { |
67 | for (const auto &res : configuredResources.keys()) { | 75 | for (const auto &res : configuredResources.keys()) { |
76 | const auto type = configuredResources.value(res); | ||
77 | if (filterResource(res)) { | ||
78 | continue; | ||
79 | } | ||
68 | // TODO filter by entity type | 80 | // TODO filter by entity type |
69 | resources.insert(res, configuredResources.value(res)); | 81 | resources.insert(res, type); |
70 | } | 82 | } |
71 | } else { | 83 | } else { |
72 | for (const auto &res : resourceFilter) { | 84 | for (const auto &res : resourceFilter) { |
73 | if (configuredResources.contains(res)) { | 85 | if (configuredResources.contains(res)) { |
86 | if (filterResource(res)) { | ||
87 | continue; | ||
88 | } | ||
74 | resources.insert(res, configuredResources.value(res)); | 89 | resources.insert(res, configuredResources.value(res)); |
75 | } else { | 90 | } else { |
76 | qWarning() << "Resource is not existing: " << res; | 91 | Warning() << "Resource is not existing: " << res; |
77 | } | 92 | } |
78 | } | 93 | } |
79 | } | 94 | } |
@@ -100,7 +115,7 @@ QSharedPointer<QAbstractItemModel> Store::loadModel(Query query) | |||
100 | //* The result provider needs to live for as long as results are provided (until the last thread exits). | 115 | //* The result provider needs to live for as long as results are provided (until the last thread exits). |
101 | 116 | ||
102 | // Query all resources and aggregate results | 117 | // Query all resources and aggregate results |
103 | auto resources = getResources(query.resources, ApplicationDomain::getTypeName<DomainType>()); | 118 | auto resources = getResources(query.resources, query.accounts, ApplicationDomain::getTypeName<DomainType>()); |
104 | auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); | 119 | auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); |
105 | model->setEmitter(aggregatingEmitter); | 120 | model->setEmitter(aggregatingEmitter); |
106 | KAsync::iterate(resources.keys()) | 121 | KAsync::iterate(resources.keys()) |
@@ -181,7 +196,7 @@ KAsync::Job<void> Store::removeDataFromDisk(const QByteArray &identifier) | |||
181 | KAsync::Job<void> Store::synchronize(const Sink::Query &query) | 196 | KAsync::Job<void> Store::synchronize(const Sink::Query &query) |
182 | { | 197 | { |
183 | Trace() << "synchronize" << query.resources; | 198 | Trace() << "synchronize" << query.resources; |
184 | auto resources = getResources(query.resources).keys(); | 199 | auto resources = getResources(query.resources, query.accounts).keys(); |
185 | return KAsync::iterate(resources) | 200 | return KAsync::iterate(resources) |
186 | .template each<void, QByteArray>([query](const QByteArray &resource, KAsync::Future<void> &future) { | 201 | .template each<void, QByteArray>([query](const QByteArray &resource, KAsync::Future<void> &future) { |
187 | Trace() << "Synchronizing " << resource; | 202 | Trace() << "Synchronizing " << resource; |