diff options
Diffstat (limited to 'common/resourcefacade.cpp')
-rw-r--r-- | common/resourcefacade.cpp | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index e6f98a9..dab6aed 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp | |||
@@ -96,17 +96,24 @@ template<typename DomainType> | |||
96 | LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query, const QByteArray &identifier, const QByteArray &typeName, ConfigNotifier &configNotifier, const Sink::Log::Context &ctx) | 96 | LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query, const QByteArray &identifier, const QByteArray &typeName, ConfigNotifier &configNotifier, const Sink::Log::Context &ctx) |
97 | : mResultProvider(new ResultProvider<typename DomainType::Ptr>), mConfigStore(identifier, typeName), mGuard(new QObject), mLogCtx(ctx.subContext("config")) | 97 | : mResultProvider(new ResultProvider<typename DomainType::Ptr>), mConfigStore(identifier, typeName), mGuard(new QObject), mLogCtx(ctx.subContext("config")) |
98 | { | 98 | { |
99 | |||
100 | auto matchesTypeAndIds = [query, this] (const QByteArray &type, const QByteArray &id) { | ||
101 | if (query.hasFilter(ApplicationDomain::SinkResource::ResourceType::name) && query.getFilter(ApplicationDomain::SinkResource::ResourceType::name).value.toByteArray() != type) { | ||
102 | SinkTraceCtx(mLogCtx) << "Skipping due to type."; | ||
103 | return false; | ||
104 | } | ||
105 | if (!query.ids().isEmpty() && !query.ids().contains(id)) { | ||
106 | return false; | ||
107 | } | ||
108 | return true; | ||
109 | }; | ||
110 | |||
99 | QObject *guard = new QObject; | 111 | QObject *guard = new QObject; |
100 | mResultProvider->setFetcher([this, query, guard, &configNotifier](const QSharedPointer<DomainType> &) { | 112 | mResultProvider->setFetcher([this, query, guard, &configNotifier, matchesTypeAndIds](const QSharedPointer<DomainType> &) { |
101 | const auto entries = mConfigStore.getEntries(); | 113 | const auto entries = mConfigStore.getEntries(); |
102 | for (const auto &res : entries.keys()) { | 114 | for (const auto &res : entries.keys()) { |
103 | const auto type = entries.value(res); | 115 | const auto type = entries.value(res); |
104 | 116 | if (!matchesTypeAndIds(type, res)){ | |
105 | if (query.hasFilter(ApplicationDomain::SinkResource::ResourceType::name) && query.getFilter(ApplicationDomain::SinkResource::ResourceType::name).value.toByteArray() != type) { | ||
106 | SinkTraceCtx(mLogCtx) << "Skipping due to type."; | ||
107 | continue; | ||
108 | } | ||
109 | if (!query.ids().isEmpty() && !query.ids().contains(res)) { | ||
110 | continue; | 117 | continue; |
111 | } | 118 | } |
112 | auto entity = readFromConfig<DomainType>(mConfigStore, res, type, query.requestedProperties); | 119 | auto entity = readFromConfig<DomainType>(mConfigStore, res, type, query.requestedProperties); |
@@ -124,8 +131,14 @@ LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query, | |||
124 | }); | 131 | }); |
125 | if (query.liveQuery()) { | 132 | if (query.liveQuery()) { |
126 | { | 133 | { |
127 | auto ret = QObject::connect(&configNotifier, &ConfigNotifier::added, guard, [this](const ApplicationDomain::ApplicationDomainType::Ptr &entry) { | 134 | auto ret = QObject::connect(&configNotifier, &ConfigNotifier::added, guard, [this, query, matchesTypeAndIds](const ApplicationDomain::ApplicationDomainType::Ptr &entry, const QByteArray &type) { |
128 | auto entity = entry.staticCast<DomainType>(); | 135 | auto entity = entry.staticCast<DomainType>(); |
136 | if (!matchesTypeAndIds(type, entity->identifier())){ | ||
137 | return; | ||
138 | } | ||
139 | if (!matchesFilter(query.getBaseFilters(), *entity)){ | ||
140 | return; | ||
141 | } | ||
129 | SinkTraceCtx(mLogCtx) << "A new resource has been added: " << entity->identifier(); | 142 | SinkTraceCtx(mLogCtx) << "A new resource has been added: " << entity->identifier(); |
130 | updateStatus(*entity); | 143 | updateStatus(*entity); |
131 | mResultProvider->add(entity); | 144 | mResultProvider->add(entity); |
@@ -133,8 +146,14 @@ LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query, | |||
133 | Q_ASSERT(ret); | 146 | Q_ASSERT(ret); |
134 | } | 147 | } |
135 | { | 148 | { |
136 | auto ret = QObject::connect(&configNotifier, &ConfigNotifier::modified, guard, [this](const ApplicationDomain::ApplicationDomainType::Ptr &entry) { | 149 | auto ret = QObject::connect(&configNotifier, &ConfigNotifier::modified, guard, [this, query, matchesTypeAndIds](const ApplicationDomain::ApplicationDomainType::Ptr &entry, const QByteArray &type) { |
137 | auto entity = entry.staticCast<DomainType>(); | 150 | auto entity = entry.staticCast<DomainType>(); |
151 | if (!matchesTypeAndIds(type, entity->identifier())){ | ||
152 | return; | ||
153 | } | ||
154 | if (!matchesFilter(query.getBaseFilters(), *entity)){ | ||
155 | return; | ||
156 | } | ||
138 | updateStatus(*entity); | 157 | updateStatus(*entity); |
139 | mResultProvider->modify(entity); | 158 | mResultProvider->modify(entity); |
140 | }); | 159 | }); |
@@ -218,7 +237,7 @@ KAsync::Job<void> LocalStorageFacade<DomainType>::create(const DomainType &domai | |||
218 | } | 237 | } |
219 | configStore.modify(identifier, configurationValues); | 238 | configStore.modify(identifier, configurationValues); |
220 | } | 239 | } |
221 | sConfigNotifier.add(::readFromConfig<DomainType>(configStore, identifier, type, QByteArrayList{})); | 240 | sConfigNotifier.add(::readFromConfig<DomainType>(configStore, identifier, type, QByteArrayList{}), type); |
222 | }); | 241 | }); |
223 | } | 242 | } |
224 | 243 | ||
@@ -247,7 +266,7 @@ KAsync::Job<void> LocalStorageFacade<DomainType>::modify(const DomainType &domai | |||
247 | } | 266 | } |
248 | 267 | ||
249 | const auto type = configStore.getEntries().value(identifier); | 268 | const auto type = configStore.getEntries().value(identifier); |
250 | sConfigNotifier.modify(::readFromConfig<DomainType>(configStore, identifier, type, QByteArrayList{})); | 269 | sConfigNotifier.modify(::readFromConfig<DomainType>(configStore, identifier, type, QByteArrayList{}), type); |
251 | }); | 270 | }); |
252 | } | 271 | } |
253 | 272 | ||
@@ -277,7 +296,7 @@ KAsync::Job<void> LocalStorageFacade<DomainType>::remove(const DomainType &domai | |||
277 | SinkTrace() << "Removing: " << identifier; | 296 | SinkTrace() << "Removing: " << identifier; |
278 | auto configStore = ConfigStore(configStoreIdentifier, typeName); | 297 | auto configStore = ConfigStore(configStoreIdentifier, typeName); |
279 | configStore.remove(identifier); | 298 | configStore.remove(identifier); |
280 | sConfigNotifier.remove(QSharedPointer<DomainType>::create(domainObject)); | 299 | sConfigNotifier.remove(QSharedPointer<DomainType>::create(domainObject), typeName); |
281 | }); | 300 | }); |
282 | } | 301 | } |
283 | 302 | ||