diff options
Diffstat (limited to 'common/resourcefacade.cpp')
-rw-r--r-- | common/resourcefacade.cpp | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index 414e390..9294926 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp | |||
@@ -24,15 +24,12 @@ | |||
24 | #include "storage.h" | 24 | #include "storage.h" |
25 | #include <QDir> | 25 | #include <QDir> |
26 | 26 | ||
27 | ResourceFacade::ResourceFacade(const QByteArray &) | 27 | ResourceFacade::ResourceFacade(const QByteArray &) : Sink::StoreFacade<Sink::ApplicationDomain::SinkResource>() |
28 | : Sink::StoreFacade<Sink::ApplicationDomain::SinkResource>() | ||
29 | { | 28 | { |
30 | |||
31 | } | 29 | } |
32 | 30 | ||
33 | ResourceFacade::~ResourceFacade() | 31 | ResourceFacade::~ResourceFacade() |
34 | { | 32 | { |
35 | |||
36 | } | 33 | } |
37 | 34 | ||
38 | KAsync::Job<void> ResourceFacade::create(const Sink::ApplicationDomain::SinkResource &resource) | 35 | KAsync::Job<void> ResourceFacade::create(const Sink::ApplicationDomain::SinkResource &resource) |
@@ -40,14 +37,14 @@ KAsync::Job<void> ResourceFacade::create(const Sink::ApplicationDomain::SinkReso | |||
40 | return KAsync::start<void>([resource, this]() { | 37 | return KAsync::start<void>([resource, this]() { |
41 | const QByteArray type = resource.getProperty("type").toByteArray(); | 38 | const QByteArray type = resource.getProperty("type").toByteArray(); |
42 | const QByteArray providedIdentifier = resource.getProperty("identifier").toByteArray(); | 39 | const QByteArray providedIdentifier = resource.getProperty("identifier").toByteArray(); |
43 | //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 |
44 | const QByteArray identifier = providedIdentifier.isEmpty() ? ResourceConfig::newIdentifier(type) : providedIdentifier; | 41 | const QByteArray identifier = providedIdentifier.isEmpty() ? ResourceConfig::newIdentifier(type) : providedIdentifier; |
45 | ResourceConfig::addResource(identifier, type); | 42 | ResourceConfig::addResource(identifier, type); |
46 | auto changedProperties = resource.changedProperties(); | 43 | auto changedProperties = resource.changedProperties(); |
47 | changedProperties.removeOne("identifier"); | 44 | changedProperties.removeOne("identifier"); |
48 | changedProperties.removeOne("type"); | 45 | changedProperties.removeOne("type"); |
49 | if (!changedProperties.isEmpty()) { | 46 | if (!changedProperties.isEmpty()) { |
50 | //We have some configuration values | 47 | // We have some configuration values |
51 | QMap<QByteArray, QVariant> configurationValues; | 48 | QMap<QByteArray, QVariant> configurationValues; |
52 | for (const auto &property : changedProperties) { | 49 | for (const auto &property : changedProperties) { |
53 | configurationValues.insert(property, resource.getProperty(property)); | 50 | configurationValues.insert(property, resource.getProperty(property)); |
@@ -69,7 +66,7 @@ KAsync::Job<void> ResourceFacade::modify(const Sink::ApplicationDomain::SinkReso | |||
69 | changedProperties.removeOne("identifier"); | 66 | changedProperties.removeOne("identifier"); |
70 | changedProperties.removeOne("type"); | 67 | changedProperties.removeOne("type"); |
71 | if (!changedProperties.isEmpty()) { | 68 | if (!changedProperties.isEmpty()) { |
72 | //We have some configuration values | 69 | // We have some configuration values |
73 | QMap<QByteArray, QVariant> configurationValues; | 70 | QMap<QByteArray, QVariant> configurationValues; |
74 | for (const auto &property : changedProperties) { | 71 | for (const auto &property : changedProperties) { |
75 | configurationValues.insert(property, resource.getProperty(property)); | 72 | configurationValues.insert(property, resource.getProperty(property)); |
@@ -88,7 +85,7 @@ KAsync::Job<void> ResourceFacade::remove(const Sink::ApplicationDomain::SinkReso | |||
88 | return; | 85 | return; |
89 | } | 86 | } |
90 | ResourceConfig::removeResource(identifier); | 87 | ResourceConfig::removeResource(identifier); |
91 | //TODO shutdown resource, or use the resource process with a --remove option to cleanup (so we can take advantage of the file locking) | 88 | // TODO shutdown resource, or use the resource process with a --remove option to cleanup (so we can take advantage of the file locking) |
92 | QDir dir(Sink::storageLocation()); | 89 | QDir dir(Sink::storageLocation()); |
93 | for (const auto &folder : dir.entryList(QStringList() << identifier + "*")) { | 90 | for (const auto &folder : dir.entryList(QStringList() << identifier + "*")) { |
94 | Sink::Storage(Sink::storageLocation(), folder, Sink::Storage::ReadWrite).removeFromDisk(); | 91 | Sink::Storage(Sink::storageLocation(), folder, Sink::Storage::ReadWrite).removeFromDisk(); |
@@ -96,14 +93,12 @@ KAsync::Job<void> ResourceFacade::remove(const Sink::ApplicationDomain::SinkReso | |||
96 | }); | 93 | }); |
97 | } | 94 | } |
98 | 95 | ||
99 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<Sink::ApplicationDomain::SinkResource::Ptr>::Ptr > ResourceFacade::load(const Sink::Query &query) | 96 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<Sink::ApplicationDomain::SinkResource::Ptr>::Ptr> ResourceFacade::load(const Sink::Query &query) |
100 | { | 97 | { |
101 | auto resultProvider = new Sink::ResultProvider<typename Sink::ApplicationDomain::SinkResource::Ptr>(); | 98 | auto resultProvider = new Sink::ResultProvider<typename Sink::ApplicationDomain::SinkResource::Ptr>(); |
102 | auto emitter = resultProvider->emitter(); | 99 | auto emitter = resultProvider->emitter(); |
103 | resultProvider->setFetcher([](const QSharedPointer<Sink::ApplicationDomain::SinkResource> &) {}); | 100 | resultProvider->setFetcher([](const QSharedPointer<Sink::ApplicationDomain::SinkResource> &) {}); |
104 | resultProvider->onDone([resultProvider]() { | 101 | resultProvider->onDone([resultProvider]() { delete resultProvider; }); |
105 | delete resultProvider; | ||
106 | }); | ||
107 | auto job = KAsync::start<void>([query, resultProvider]() { | 102 | auto job = KAsync::start<void>([query, resultProvider]() { |
108 | const auto configuredResources = ResourceConfig::getResources(); | 103 | const auto configuredResources = ResourceConfig::getResources(); |
109 | for (const auto &res : configuredResources.keys()) { | 104 | for (const auto &res : configuredResources.keys()) { |
@@ -114,10 +109,9 @@ QPair<KAsync::Job<void>, typename Sink::ResultEmitter<Sink::ApplicationDomain::S | |||
114 | resultProvider->add(resource); | 109 | resultProvider->add(resource); |
115 | } | 110 | } |
116 | } | 111 | } |
117 | //TODO initialResultSetComplete should be implicit | 112 | // TODO initialResultSetComplete should be implicit |
118 | resultProvider->initialResultSetComplete(Sink::ApplicationDomain::SinkResource::Ptr()); | 113 | resultProvider->initialResultSetComplete(Sink::ApplicationDomain::SinkResource::Ptr()); |
119 | resultProvider->complete(); | 114 | resultProvider->complete(); |
120 | }); | 115 | }); |
121 | return qMakePair(job, emitter); | 116 | return qMakePair(job, emitter); |
122 | } | 117 | } |
123 | |||