diff options
Diffstat (limited to 'common/resourcefacade.cpp')
-rw-r--r-- | common/resourcefacade.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index 7d42f47..35f7f46 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp | |||
@@ -39,6 +39,7 @@ KAsync::Job<void> ResourceFacade::create(const Sink::ApplicationDomain::SinkReso | |||
39 | const QByteArray providedIdentifier = resource.getProperty("identifier").toByteArray(); | 39 | const QByteArray providedIdentifier = resource.getProperty("identifier").toByteArray(); |
40 | // It is currently a requirement that the resource starts with the type | 40 | // It is currently a requirement that the resource starts with the type |
41 | const QByteArray identifier = providedIdentifier.isEmpty() ? ResourceConfig::newIdentifier(type) : providedIdentifier; | 41 | const QByteArray identifier = providedIdentifier.isEmpty() ? ResourceConfig::newIdentifier(type) : providedIdentifier; |
42 | Trace() << "Creating resource " << type << identifier; | ||
42 | ResourceConfig::addResource(identifier, type); | 43 | ResourceConfig::addResource(identifier, type); |
43 | auto changedProperties = resource.changedProperties(); | 44 | auto changedProperties = resource.changedProperties(); |
44 | changedProperties.removeOne("identifier"); | 45 | changedProperties.removeOne("identifier"); |
@@ -66,12 +67,11 @@ KAsync::Job<void> ResourceFacade::modify(const Sink::ApplicationDomain::SinkReso | |||
66 | changedProperties.removeOne("identifier"); | 67 | changedProperties.removeOne("identifier"); |
67 | changedProperties.removeOne("type"); | 68 | changedProperties.removeOne("type"); |
68 | if (!changedProperties.isEmpty()) { | 69 | if (!changedProperties.isEmpty()) { |
69 | // We have some configuration values | 70 | auto config = ResourceConfig::getConfiguration(identifier); |
70 | QMap<QByteArray, QVariant> configurationValues; | ||
71 | for (const auto &property : changedProperties) { | 71 | for (const auto &property : changedProperties) { |
72 | configurationValues.insert(property, resource.getProperty(property)); | 72 | config.insert(property, resource.getProperty(property)); |
73 | } | 73 | } |
74 | ResourceConfig::configureResource(identifier, configurationValues); | 74 | ResourceConfig::configureResource(identifier, config); |
75 | } | 75 | } |
76 | }); | 76 | }); |
77 | } | 77 | } |
@@ -84,6 +84,7 @@ KAsync::Job<void> ResourceFacade::remove(const Sink::ApplicationDomain::SinkReso | |||
84 | Warning() << "We need an \"identifier\" property to identify the resource to configure"; | 84 | Warning() << "We need an \"identifier\" property to identify the resource to configure"; |
85 | return; | 85 | return; |
86 | } | 86 | } |
87 | Trace() << "Removing resource " << identifier; | ||
87 | ResourceConfig::removeResource(identifier); | 88 | ResourceConfig::removeResource(identifier); |
88 | // TODO shutdown resource, or use the resource process with a --remove option to cleanup (so we can take advantage of the file locking) | 89 | // TODO shutdown resource, or use the resource process with a --remove option to cleanup (so we can take advantage of the file locking) |
89 | QDir dir(Sink::storageLocation()); | 90 | QDir dir(Sink::storageLocation()); |
@@ -93,6 +94,16 @@ KAsync::Job<void> ResourceFacade::remove(const Sink::ApplicationDomain::SinkReso | |||
93 | }); | 94 | }); |
94 | } | 95 | } |
95 | 96 | ||
97 | static bool matchesFilter(const QHash<QByteArray, QVariant> &filter, const QMap<QByteArray, QVariant> &properties) | ||
98 | { | ||
99 | for (const auto &filterProperty : filter.keys()) { | ||
100 | if (filter.value(filterProperty).toByteArray() != properties.value(filterProperty).toByteArray()) { | ||
101 | return false; | ||
102 | } | ||
103 | } | ||
104 | return true; | ||
105 | } | ||
106 | |||
96 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<Sink::ApplicationDomain::SinkResource::Ptr>::Ptr> ResourceFacade::load(const Sink::Query &query) | 107 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<Sink::ApplicationDomain::SinkResource::Ptr>::Ptr> ResourceFacade::load(const Sink::Query &query) |
97 | { | 108 | { |
98 | auto resultProvider = new Sink::ResultProvider<typename Sink::ApplicationDomain::SinkResource::Ptr>(); | 109 | auto resultProvider = new Sink::ResultProvider<typename Sink::ApplicationDomain::SinkResource::Ptr>(); |
@@ -109,11 +120,13 @@ QPair<KAsync::Job<void>, typename Sink::ResultEmitter<Sink::ApplicationDomain::S | |||
109 | if (!query.ids.isEmpty() && !query.ids.contains(res)) { | 120 | if (!query.ids.isEmpty() && !query.ids.contains(res)) { |
110 | continue; | 121 | continue; |
111 | } | 122 | } |
123 | const auto configurationValues = ResourceConfig::getConfiguration(res); | ||
124 | if (!matchesFilter(query.propertyFilter, configurationValues)){ | ||
125 | continue; | ||
126 | } | ||
112 | 127 | ||
113 | auto resource = Sink::ApplicationDomain::SinkResource::Ptr::create(res); | 128 | auto resource = Sink::ApplicationDomain::SinkResource::Ptr::create(res); |
114 | resource->setProperty("type", type); | 129 | resource->setProperty("type", type); |
115 | |||
116 | const auto configurationValues = ResourceConfig::getConfiguration(res); | ||
117 | for (auto it = configurationValues.constBegin(); it != configurationValues.constEnd(); it++) { | 130 | for (auto it = configurationValues.constBegin(); it != configurationValues.constEnd(); it++) { |
118 | resource->setProperty(it.key(), it.value()); | 131 | resource->setProperty(it.key(), it.value()); |
119 | } | 132 | } |