diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-15 17:26:59 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-15 17:26:59 +0100 |
commit | 7bd037fae43c963d5f67e9447b3ee6875591a2c7 (patch) | |
tree | e2537369bb21d12e77668f0b2e878cffc1b9b423 /common/resourcefacade.cpp | |
parent | 20b4d255509d5a490619afef50e49477ea09c71d (diff) | |
download | sink-7bd037fae43c963d5f67e9447b3ee6875591a2c7.tar.gz sink-7bd037fae43c963d5f67e9447b3ee6875591a2c7.zip |
Don't set capabilities as property on creation.
Instead we make it part of the plugin.
This ensure we also have access to the proper capabilities when creating
a resource via sinksh.
Diffstat (limited to 'common/resourcefacade.cpp')
-rw-r--r-- | common/resourcefacade.cpp | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index c4e16b1..ea4218d 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp | |||
@@ -24,6 +24,7 @@ | |||
24 | #include "storage.h" | 24 | #include "storage.h" |
25 | #include "store.h" | 25 | #include "store.h" |
26 | #include "resourceaccess.h" | 26 | #include "resourceaccess.h" |
27 | #include "resource.h" | ||
27 | #include <QDir> | 28 | #include <QDir> |
28 | 29 | ||
29 | using namespace Sink; | 30 | using namespace Sink; |
@@ -33,25 +34,50 @@ SINK_DEBUG_AREA("ResourceFacade") | |||
33 | template<typename DomainType> | 34 | template<typename DomainType> |
34 | ConfigNotifier LocalStorageFacade<DomainType>::sConfigNotifier; | 35 | ConfigNotifier LocalStorageFacade<DomainType>::sConfigNotifier; |
35 | 36 | ||
37 | static void applyConfig(ConfigStore &configStore, const QByteArray &id, ApplicationDomain::ApplicationDomainType &object) | ||
38 | { | ||
39 | const auto configurationValues = configStore.get(id); | ||
40 | for (auto it = configurationValues.constBegin(); it != configurationValues.constEnd(); it++) { | ||
41 | object.setProperty(it.key(), it.value()); | ||
42 | } | ||
43 | } | ||
44 | |||
36 | template <typename DomainType> | 45 | template <typename DomainType> |
37 | static typename DomainType::Ptr readFromConfig(ConfigStore &configStore, const QByteArray &id, const QByteArray &type) | 46 | static typename DomainType::Ptr readFromConfig(ConfigStore &configStore, const QByteArray &id, const QByteArray &type) |
38 | { | 47 | { |
39 | auto object = DomainType::Ptr::create(id); | 48 | auto object = DomainType::Ptr::create(id); |
49 | applyConfig(configStore, id, *object); | ||
50 | return object; | ||
51 | } | ||
52 | |||
53 | template <> | ||
54 | typename ApplicationDomain::SinkAccount::Ptr readFromConfig<ApplicationDomain::SinkAccount>(ConfigStore &configStore, const QByteArray &id, const QByteArray &type) | ||
55 | { | ||
56 | auto object = ApplicationDomain::SinkAccount::Ptr::create(id); | ||
57 | object->setProperty(ApplicationDomain::SinkAccount::AccountType::name, type); | ||
58 | applyConfig(configStore, id, *object); | ||
59 | return object; | ||
60 | } | ||
61 | |||
62 | template <> | ||
63 | typename ApplicationDomain::SinkResource::Ptr readFromConfig<ApplicationDomain::SinkResource>(ConfigStore &configStore, const QByteArray &id, const QByteArray &type) | ||
64 | { | ||
65 | auto object = ApplicationDomain::SinkResource::Ptr::create(id); | ||
40 | object->setProperty(ApplicationDomain::SinkResource::ResourceType::name, type); | 66 | object->setProperty(ApplicationDomain::SinkResource::ResourceType::name, type); |
41 | const auto configurationValues = configStore.get(id); | 67 | if (auto res = ResourceFactory::load(type)) { |
42 | for (auto it = configurationValues.constBegin(); it != configurationValues.constEnd(); it++) { | 68 | object->setCapabilities(res->capabilities()); |
43 | object->setProperty(it.key(), it.value()); | ||
44 | } | 69 | } |
70 | applyConfig(configStore, id, *object); | ||
45 | return object; | 71 | return object; |
46 | } | 72 | } |
47 | 73 | ||
48 | static bool matchesFilter(const QHash<QByteArray, Query::Comparator> &filter, const QMap<QByteArray, QVariant> &properties) | 74 | static bool matchesFilter(const QHash<QByteArray, Query::Comparator> &filter, const ApplicationDomain::ApplicationDomainType &entity) |
49 | { | 75 | { |
50 | for (const auto &filterProperty : filter.keys()) { | 76 | for (const auto &filterProperty : filter.keys()) { |
51 | if (filterProperty == ApplicationDomain::SinkResource::ResourceType::name) { | 77 | if (filterProperty == ApplicationDomain::SinkResource::ResourceType::name) { |
52 | continue; | 78 | continue; |
53 | } | 79 | } |
54 | if (!filter.value(filterProperty).matches(properties.value(filterProperty))) { | 80 | if (!filter.value(filterProperty).matches(entity.getProperty(filterProperty))) { |
55 | return false; | 81 | return false; |
56 | } | 82 | } |
57 | } | 83 | } |
@@ -75,13 +101,12 @@ LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query, | |||
75 | if (!query.ids().isEmpty() && !query.ids().contains(res)) { | 101 | if (!query.ids().isEmpty() && !query.ids().contains(res)) { |
76 | continue; | 102 | continue; |
77 | } | 103 | } |
78 | const auto configurationValues = mConfigStore.get(res); | 104 | auto entity = readFromConfig<DomainType>(mConfigStore, res, type); |
79 | if (!matchesFilter(query.getBaseFilters(), configurationValues)){ | 105 | if (!matchesFilter(query.getBaseFilters(), *entity)){ |
80 | SinkTrace() << "Skipping due to filter."; | 106 | SinkTrace() << "Skipping due to filter." << res; |
81 | continue; | 107 | continue; |
82 | } | 108 | } |
83 | SinkTrace() << "Found match " << res; | 109 | SinkTrace() << "Found match " << res; |
84 | auto entity = readFromConfig<DomainType>(mConfigStore, res, type); | ||
85 | updateStatus(*entity); | 110 | updateStatus(*entity); |
86 | mResultProvider->add(entity); | 111 | mResultProvider->add(entity); |
87 | } | 112 | } |