diff options
-rw-r--r-- | common/configstore.cpp | 7 | ||||
-rw-r--r-- | common/configstore.h | 3 | ||||
-rw-r--r-- | common/domain/applicationdomaintype.cpp | 24 | ||||
-rw-r--r-- | common/domain/applicationdomaintype.h | 2 | ||||
-rw-r--r-- | common/resourceaccess.cpp | 4 | ||||
-rw-r--r-- | common/resourceconfig.cpp | 5 | ||||
-rw-r--r-- | common/resourcefacade.cpp | 45 | ||||
-rw-r--r-- | common/resourcefacade.h | 5 | ||||
-rw-r--r-- | common/store.cpp | 2 | ||||
-rw-r--r-- | sinksh/syntax_modules/sink_create.cpp | 2 | ||||
-rw-r--r-- | tests/accountstest.cpp | 22 | ||||
-rw-r--r-- | tests/resourceconfigtest.cpp | 39 |
12 files changed, 87 insertions, 73 deletions
diff --git a/common/configstore.cpp b/common/configstore.cpp index 9a68662..ff5ba3d 100644 --- a/common/configstore.cpp +++ b/common/configstore.cpp | |||
@@ -31,8 +31,9 @@ static QSharedPointer<QSettings> getConfig(const QByteArray &identifier) | |||
31 | return QSharedPointer<QSettings>::create(Sink::configLocation() + "/" + identifier + ".ini", QSettings::IniFormat); | 31 | return QSharedPointer<QSettings>::create(Sink::configLocation() + "/" + identifier + ".ini", QSettings::IniFormat); |
32 | } | 32 | } |
33 | 33 | ||
34 | ConfigStore::ConfigStore(const QByteArray &identifier) | 34 | ConfigStore::ConfigStore(const QByteArray &identifier, const QByteArray &typeName) |
35 | : mIdentifier(identifier), | 35 | : mIdentifier(identifier), |
36 | mTypeName(typeName), | ||
36 | mConfig(getConfig(identifier)) | 37 | mConfig(getConfig(identifier)) |
37 | { | 38 | { |
38 | 39 | ||
@@ -43,7 +44,7 @@ QMap<QByteArray, QByteArray> ConfigStore::getEntries() | |||
43 | QMap<QByteArray, QByteArray> resources; | 44 | QMap<QByteArray, QByteArray> resources; |
44 | for (const auto &identifier : mConfig->childGroups()) { | 45 | for (const auto &identifier : mConfig->childGroups()) { |
45 | mConfig->beginGroup(identifier); | 46 | mConfig->beginGroup(identifier); |
46 | const auto type = mConfig->value("type").toByteArray(); | 47 | const auto type = mConfig->value(mTypeName).toByteArray(); |
47 | resources.insert(identifier.toLatin1(), type); | 48 | resources.insert(identifier.toLatin1(), type); |
48 | mConfig->endGroup(); | 49 | mConfig->endGroup(); |
49 | } | 50 | } |
@@ -54,7 +55,7 @@ void ConfigStore::add(const QByteArray &identifier, const QByteArray &type) | |||
54 | { | 55 | { |
55 | SinkTrace() << "Adding " << identifier; | 56 | SinkTrace() << "Adding " << identifier; |
56 | mConfig->beginGroup(QString::fromLatin1(identifier)); | 57 | mConfig->beginGroup(QString::fromLatin1(identifier)); |
57 | mConfig->setValue("type", type); | 58 | mConfig->setValue(mTypeName, type); |
58 | mConfig->endGroup(); | 59 | mConfig->endGroup(); |
59 | mConfig->sync(); | 60 | mConfig->sync(); |
60 | } | 61 | } |
diff --git a/common/configstore.h b/common/configstore.h index 2f51f63..514bc01 100644 --- a/common/configstore.h +++ b/common/configstore.h | |||
@@ -30,7 +30,7 @@ | |||
30 | class SINK_EXPORT ConfigStore | 30 | class SINK_EXPORT ConfigStore |
31 | { | 31 | { |
32 | public: | 32 | public: |
33 | ConfigStore(const QByteArray &identifier); | 33 | ConfigStore(const QByteArray &identifier, const QByteArray &typeName); |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * Returns all entries with their type. | 36 | * Returns all entries with their type. |
@@ -64,5 +64,6 @@ public: | |||
64 | 64 | ||
65 | private: | 65 | private: |
66 | QByteArray mIdentifier; | 66 | QByteArray mIdentifier; |
67 | QByteArray mTypeName; | ||
67 | QSharedPointer<QSettings> mConfig; | 68 | QSharedPointer<QSettings> mConfig; |
68 | }; | 69 | }; |
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index 2f7c32b..5474708 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp | |||
@@ -254,9 +254,9 @@ Identity::~Identity() | |||
254 | SinkResource DummyResource::create(const QByteArray &account) | 254 | SinkResource DummyResource::create(const QByteArray &account) |
255 | { | 255 | { |
256 | auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); | 256 | auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); |
257 | resource.setProperty("type", "sink.dummy"); | 257 | resource.setResourceType("sink.dummy"); |
258 | resource.setProperty("account", account); | 258 | resource.setAccount(account); |
259 | resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::storage << "-folder.rename")); | 259 | resource.setCapabilities(QByteArrayList() << ResourceCapabilities::Mail::storage << "-folder.rename"); |
260 | // resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::storage << ResourceCapabilities::Mail::drafts << "-folder.rename" << ResourceCapabilities::Mail::trash)); | 260 | // resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::storage << ResourceCapabilities::Mail::drafts << "-folder.rename" << ResourceCapabilities::Mail::trash)); |
261 | return resource; | 261 | return resource; |
262 | } | 262 | } |
@@ -264,27 +264,27 @@ SinkResource DummyResource::create(const QByteArray &account) | |||
264 | SinkResource MaildirResource::create(const QByteArray &account) | 264 | SinkResource MaildirResource::create(const QByteArray &account) |
265 | { | 265 | { |
266 | auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); | 266 | auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); |
267 | resource.setProperty("type", "sink.maildir"); | 267 | resource.setResourceType("sink.maildir"); |
268 | resource.setProperty("account", account); | 268 | resource.setAccount(account); |
269 | resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::storage << ResourceCapabilities::Mail::drafts << "-folder.rename" << ResourceCapabilities::Mail::trash)); | 269 | resource.setCapabilities(QByteArrayList() << ResourceCapabilities::Mail::storage << ResourceCapabilities::Mail::drafts << "-folder.rename" << ResourceCapabilities::Mail::trash); |
270 | return resource; | 270 | return resource; |
271 | } | 271 | } |
272 | 272 | ||
273 | SinkResource MailtransportResource::create(const QByteArray &account) | 273 | SinkResource MailtransportResource::create(const QByteArray &account) |
274 | { | 274 | { |
275 | auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); | 275 | auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); |
276 | resource.setProperty("type", "sink.mailtransport"); | 276 | resource.setResourceType("sink.mailtransport"); |
277 | resource.setProperty("account", account); | 277 | resource.setAccount(account); |
278 | resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::transport)); | 278 | resource.setCapabilities(QByteArrayList() << ResourceCapabilities::Mail::transport); |
279 | return resource; | 279 | return resource; |
280 | } | 280 | } |
281 | 281 | ||
282 | SinkResource ImapResource::create(const QByteArray &account) | 282 | SinkResource ImapResource::create(const QByteArray &account) |
283 | { | 283 | { |
284 | auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); | 284 | auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); |
285 | resource.setProperty("type", "sink.imap"); | 285 | resource.setResourceType("sink.imap"); |
286 | resource.setProperty("account", account); | 286 | resource.setAccount(account); |
287 | resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::storage << ResourceCapabilities::Mail::drafts << ResourceCapabilities::Mail::folderhierarchy << ResourceCapabilities::Mail::trash)); | 287 | resource.setCapabilities(QByteArrayList() << ResourceCapabilities::Mail::storage << ResourceCapabilities::Mail::drafts << ResourceCapabilities::Mail::folderhierarchy << ResourceCapabilities::Mail::trash); |
288 | return resource; | 288 | return resource; |
289 | } | 289 | } |
290 | 290 | ||
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index c824251..8b96758 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h | |||
@@ -295,7 +295,7 @@ struct SINK_EXPORT SinkResource : public ApplicationDomainType { | |||
295 | virtual ~SinkResource(); | 295 | virtual ~SinkResource(); |
296 | 296 | ||
297 | SINK_REFERENCE_PROPERTY(SinkAccount, Account, account); | 297 | SINK_REFERENCE_PROPERTY(SinkAccount, Account, account); |
298 | SINK_PROPERTY(QString, ResourceType, resourceType); | 298 | SINK_PROPERTY(QByteArray, ResourceType, resourceType); |
299 | SINK_PROPERTY(QByteArrayList, Capabilities, capabilities); | 299 | SINK_PROPERTY(QByteArrayList, Capabilities, capabilities); |
300 | SINK_STATUS_PROPERTY(int, Status, status); | 300 | SINK_STATUS_PROPERTY(int, Status, status); |
301 | SINK_STATUS_PROPERTY(ApplicationDomain::Error, Error, error); | 301 | SINK_STATUS_PROPERTY(ApplicationDomain::Error, Error, error); |
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index 364616c..e509292 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp | |||
@@ -199,6 +199,10 @@ KAsync::Job<void> ResourceAccess::Private::initializeSocket() | |||
199 | if (Sink::Test::testModeEnabled()) { | 199 | if (Sink::Test::testModeEnabled()) { |
200 | args << "--test"; | 200 | args << "--test"; |
201 | } | 201 | } |
202 | if (resourceName.isEmpty()) { | ||
203 | SinkWarning() << "No resource type given"; | ||
204 | return KAsync::error(); | ||
205 | } | ||
202 | args << resourceInstanceIdentifier << resourceName; | 206 | args << resourceInstanceIdentifier << resourceName; |
203 | qint64 pid = 0; | 207 | qint64 pid = 0; |
204 | if (QProcess::startDetached("sink_synchronizer", args, QDir::homePath(), &pid)) { | 208 | if (QProcess::startDetached("sink_synchronizer", args, QDir::homePath(), &pid)) { |
diff --git a/common/resourceconfig.cpp b/common/resourceconfig.cpp index 39f9ddb..68ac0bc 100644 --- a/common/resourceconfig.cpp +++ b/common/resourceconfig.cpp | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <QFile> | 23 | #include <QFile> |
24 | #include <log.h> | 24 | #include <log.h> |
25 | #include <definitions.h> | 25 | #include <definitions.h> |
26 | #include <applicationdomaintype.h> | ||
26 | 27 | ||
27 | static QSharedPointer<QSettings> getConfig(const QByteArray &identifier) | 28 | static QSharedPointer<QSettings> getConfig(const QByteArray &identifier) |
28 | { | 29 | { |
@@ -43,7 +44,7 @@ void ResourceConfig::addResource(const QByteArray &identifier, const QByteArray | |||
43 | { | 44 | { |
44 | auto settings = getConfig("resources"); | 45 | auto settings = getConfig("resources"); |
45 | settings->beginGroup(QString::fromLatin1(identifier)); | 46 | settings->beginGroup(QString::fromLatin1(identifier)); |
46 | settings->setValue("type", type); | 47 | settings->setValue(Sink::ApplicationDomain::SinkResource::ResourceType::name, type); |
47 | settings->endGroup(); | 48 | settings->endGroup(); |
48 | settings->sync(); | 49 | settings->sync(); |
49 | } | 50 | } |
@@ -64,7 +65,7 @@ QMap<QByteArray, QByteArray> ResourceConfig::getResources() | |||
64 | auto settings = getConfig("resources"); | 65 | auto settings = getConfig("resources"); |
65 | for (const auto &identifier : settings->childGroups()) { | 66 | for (const auto &identifier : settings->childGroups()) { |
66 | settings->beginGroup(identifier); | 67 | settings->beginGroup(identifier); |
67 | const auto type = settings->value("type").toByteArray(); | 68 | const auto type = settings->value(Sink::ApplicationDomain::SinkResource::ResourceType::name).toByteArray(); |
68 | resources.insert(identifier.toLatin1(), type); | 69 | resources.insert(identifier.toLatin1(), type); |
69 | settings->endGroup(); | 70 | settings->endGroup(); |
70 | } | 71 | } |
diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index 391b1d1..aee5706 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp | |||
@@ -37,7 +37,7 @@ template <typename DomainType> | |||
37 | static typename DomainType::Ptr readFromConfig(ConfigStore &configStore, const QByteArray &id, const QByteArray &type) | 37 | static typename DomainType::Ptr readFromConfig(ConfigStore &configStore, const QByteArray &id, const QByteArray &type) |
38 | { | 38 | { |
39 | auto object = DomainType::Ptr::create(id); | 39 | auto object = DomainType::Ptr::create(id); |
40 | object->setProperty("type", type); | 40 | object->setProperty(ApplicationDomain::SinkResource::ResourceType::name, type); |
41 | const auto configurationValues = configStore.get(id); | 41 | const auto configurationValues = configStore.get(id); |
42 | for (auto it = configurationValues.constBegin(); it != configurationValues.constEnd(); it++) { | 42 | for (auto it = configurationValues.constBegin(); it != configurationValues.constEnd(); it++) { |
43 | object->setProperty(it.key(), it.value()); | 43 | object->setProperty(it.key(), it.value()); |
@@ -48,7 +48,7 @@ static typename DomainType::Ptr readFromConfig(ConfigStore &configStore, const Q | |||
48 | static bool matchesFilter(const QHash<QByteArray, Query::Comparator> &filter, const QMap<QByteArray, QVariant> &properties) | 48 | static bool matchesFilter(const QHash<QByteArray, Query::Comparator> &filter, const QMap<QByteArray, QVariant> &properties) |
49 | { | 49 | { |
50 | for (const auto &filterProperty : filter.keys()) { | 50 | for (const auto &filterProperty : filter.keys()) { |
51 | if (filterProperty == "type") { | 51 | if (filterProperty == ApplicationDomain::SinkResource::ResourceType::name) { |
52 | continue; | 52 | continue; |
53 | } | 53 | } |
54 | if (!filter.value(filterProperty).matches(properties.value(filterProperty))) { | 54 | if (!filter.value(filterProperty).matches(properties.value(filterProperty))) { |
@@ -59,8 +59,8 @@ static bool matchesFilter(const QHash<QByteArray, Query::Comparator> &filter, co | |||
59 | } | 59 | } |
60 | 60 | ||
61 | template<typename DomainType> | 61 | template<typename DomainType> |
62 | LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query, const QByteArray &identifier, ConfigNotifier &configNotifier) | 62 | LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query, const QByteArray &identifier, const QByteArray &typeName, ConfigNotifier &configNotifier) |
63 | : mResultProvider(new ResultProvider<typename DomainType::Ptr>), mConfigStore(identifier), mGuard(new QObject) | 63 | : mResultProvider(new ResultProvider<typename DomainType::Ptr>), mConfigStore(identifier, typeName), mGuard(new QObject) |
64 | { | 64 | { |
65 | QObject *guard = new QObject; | 65 | QObject *guard = new QObject; |
66 | mResultProvider->setFetcher([this, query, guard, &configNotifier](const QSharedPointer<DomainType> &) { | 66 | mResultProvider->setFetcher([this, query, guard, &configNotifier](const QSharedPointer<DomainType> &) { |
@@ -68,7 +68,7 @@ LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query, | |||
68 | for (const auto &res : entries.keys()) { | 68 | for (const auto &res : entries.keys()) { |
69 | const auto type = entries.value(res); | 69 | const auto type = entries.value(res); |
70 | 70 | ||
71 | if (query.hasFilter("type") && query.getFilter("type").value.toByteArray() != type) { | 71 | if (query.hasFilter(ApplicationDomain::SinkResource::ResourceType::name) && query.getFilter(ApplicationDomain::SinkResource::ResourceType::name).value.toByteArray() != type) { |
72 | SinkTrace() << "Skipping due to type."; | 72 | SinkTrace() << "Skipping due to type."; |
73 | continue; | 73 | continue; |
74 | } | 74 | } |
@@ -154,7 +154,7 @@ typename Sink::ResultEmitter<typename DomainType::Ptr>::Ptr LocalStorageQueryRun | |||
154 | 154 | ||
155 | 155 | ||
156 | template <typename DomainType> | 156 | template <typename DomainType> |
157 | LocalStorageFacade<DomainType>::LocalStorageFacade(const QByteArray &identifier) : StoreFacade<DomainType>(), mIdentifier(identifier) | 157 | LocalStorageFacade<DomainType>::LocalStorageFacade(const QByteArray &identifier, const QByteArray &typeName) : StoreFacade<DomainType>(), mIdentifier(identifier), mTypeName(typeName) |
158 | { | 158 | { |
159 | } | 159 | } |
160 | 160 | ||
@@ -167,15 +167,16 @@ template <typename DomainType> | |||
167 | KAsync::Job<void> LocalStorageFacade<DomainType>::create(const DomainType &domainObject) | 167 | KAsync::Job<void> LocalStorageFacade<DomainType>::create(const DomainType &domainObject) |
168 | { | 168 | { |
169 | auto configStoreIdentifier = mIdentifier; | 169 | auto configStoreIdentifier = mIdentifier; |
170 | return KAsync::syncStart<void>([domainObject, configStoreIdentifier]() { | 170 | auto typeName = mTypeName; |
171 | const QByteArray type = domainObject.getProperty("type").toByteArray(); | 171 | return KAsync::syncStart<void>([domainObject, configStoreIdentifier, typeName]() { |
172 | const QByteArray type = domainObject.getProperty(typeName).toByteArray(); | ||
172 | const QByteArray providedIdentifier = domainObject.identifier().isEmpty() ? domainObject.getProperty("identifier").toByteArray() : domainObject.identifier(); | 173 | const QByteArray providedIdentifier = domainObject.identifier().isEmpty() ? domainObject.getProperty("identifier").toByteArray() : domainObject.identifier(); |
173 | const QByteArray identifier = providedIdentifier.isEmpty() ? ResourceConfig::newIdentifier(type) : providedIdentifier; | 174 | const QByteArray identifier = providedIdentifier.isEmpty() ? ResourceConfig::newIdentifier(type) : providedIdentifier; |
174 | auto configStore = ConfigStore(configStoreIdentifier); | 175 | auto configStore = ConfigStore(configStoreIdentifier, typeName); |
175 | configStore.add(identifier, type); | 176 | configStore.add(identifier, type); |
176 | auto changedProperties = domainObject.changedProperties(); | 177 | auto changedProperties = domainObject.changedProperties(); |
177 | changedProperties.removeOne("identifier"); | 178 | changedProperties.removeOne("identifier"); |
178 | changedProperties.removeOne("type"); | 179 | changedProperties.removeOne(typeName); |
179 | if (!changedProperties.isEmpty()) { | 180 | if (!changedProperties.isEmpty()) { |
180 | // We have some configuration values | 181 | // We have some configuration values |
181 | QMap<QByteArray, QVariant> configurationValues; | 182 | QMap<QByteArray, QVariant> configurationValues; |
@@ -192,7 +193,8 @@ template <typename DomainType> | |||
192 | KAsync::Job<void> LocalStorageFacade<DomainType>::modify(const DomainType &domainObject) | 193 | KAsync::Job<void> LocalStorageFacade<DomainType>::modify(const DomainType &domainObject) |
193 | { | 194 | { |
194 | auto configStoreIdentifier = mIdentifier; | 195 | auto configStoreIdentifier = mIdentifier; |
195 | return KAsync::syncStart<void>([domainObject, configStoreIdentifier]() { | 196 | auto typeName = mTypeName; |
197 | return KAsync::syncStart<void>([domainObject, configStoreIdentifier, typeName]() { | ||
196 | const QByteArray identifier = domainObject.identifier(); | 198 | const QByteArray identifier = domainObject.identifier(); |
197 | if (identifier.isEmpty()) { | 199 | if (identifier.isEmpty()) { |
198 | SinkWarning() << "We need an \"identifier\" property to identify the entity to configure."; | 200 | SinkWarning() << "We need an \"identifier\" property to identify the entity to configure."; |
@@ -200,8 +202,8 @@ KAsync::Job<void> LocalStorageFacade<DomainType>::modify(const DomainType &domai | |||
200 | } | 202 | } |
201 | auto changedProperties = domainObject.changedProperties(); | 203 | auto changedProperties = domainObject.changedProperties(); |
202 | changedProperties.removeOne("identifier"); | 204 | changedProperties.removeOne("identifier"); |
203 | changedProperties.removeOne("type"); | 205 | changedProperties.removeOne(typeName); |
204 | auto configStore = ConfigStore(configStoreIdentifier); | 206 | auto configStore = ConfigStore(configStoreIdentifier, typeName); |
205 | if (!changedProperties.isEmpty()) { | 207 | if (!changedProperties.isEmpty()) { |
206 | // We have some configuration values | 208 | // We have some configuration values |
207 | QMap<QByteArray, QVariant> configurationValues; | 209 | QMap<QByteArray, QVariant> configurationValues; |
@@ -220,14 +222,15 @@ template <typename DomainType> | |||
220 | KAsync::Job<void> LocalStorageFacade<DomainType>::remove(const DomainType &domainObject) | 222 | KAsync::Job<void> LocalStorageFacade<DomainType>::remove(const DomainType &domainObject) |
221 | { | 223 | { |
222 | auto configStoreIdentifier = mIdentifier; | 224 | auto configStoreIdentifier = mIdentifier; |
223 | return KAsync::syncStart<void>([domainObject, configStoreIdentifier]() { | 225 | auto typeName = mTypeName; |
226 | return KAsync::syncStart<void>([domainObject, configStoreIdentifier, typeName]() { | ||
224 | const QByteArray identifier = domainObject.identifier(); | 227 | const QByteArray identifier = domainObject.identifier(); |
225 | if (identifier.isEmpty()) { | 228 | if (identifier.isEmpty()) { |
226 | SinkWarning() << "We need an \"identifier\" property to identify the entity to configure"; | 229 | SinkWarning() << "We need an \"identifier\" property to identify the entity to configure"; |
227 | return; | 230 | return; |
228 | } | 231 | } |
229 | SinkTrace() << "Removing: " << identifier; | 232 | SinkTrace() << "Removing: " << identifier; |
230 | auto configStore = ConfigStore(configStoreIdentifier); | 233 | auto configStore = ConfigStore(configStoreIdentifier, typeName); |
231 | configStore.remove(identifier); | 234 | configStore.remove(identifier); |
232 | sConfigNotifier.remove(QSharedPointer<DomainType>::create(domainObject)); | 235 | sConfigNotifier.remove(QSharedPointer<DomainType>::create(domainObject)); |
233 | }); | 236 | }); |
@@ -236,11 +239,11 @@ KAsync::Job<void> LocalStorageFacade<DomainType>::remove(const DomainType &domai | |||
236 | template <typename DomainType> | 239 | template <typename DomainType> |
237 | QPair<KAsync::Job<void>, typename ResultEmitter<typename DomainType::Ptr>::Ptr> LocalStorageFacade<DomainType>::load(const Query &query) | 240 | QPair<KAsync::Job<void>, typename ResultEmitter<typename DomainType::Ptr>::Ptr> LocalStorageFacade<DomainType>::load(const Query &query) |
238 | { | 241 | { |
239 | auto runner = new LocalStorageQueryRunner<DomainType>(query, mIdentifier, sConfigNotifier); | 242 | auto runner = new LocalStorageQueryRunner<DomainType>(query, mIdentifier, mTypeName, sConfigNotifier); |
240 | return qMakePair(KAsync::null<void>(), runner->emitter()); | 243 | return qMakePair(KAsync::null<void>(), runner->emitter()); |
241 | } | 244 | } |
242 | 245 | ||
243 | ResourceFacade::ResourceFacade() : LocalStorageFacade<Sink::ApplicationDomain::SinkResource>("resources") | 246 | ResourceFacade::ResourceFacade() : LocalStorageFacade<Sink::ApplicationDomain::SinkResource>("resources", Sink::ApplicationDomain::SinkResource::ResourceType::name) |
244 | { | 247 | { |
245 | } | 248 | } |
246 | 249 | ||
@@ -256,7 +259,7 @@ KAsync::Job<void> ResourceFacade::remove(const Sink::ApplicationDomain::SinkReso | |||
256 | 259 | ||
257 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename ApplicationDomain::SinkResource::Ptr>::Ptr> ResourceFacade::load(const Sink::Query &query) | 260 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename ApplicationDomain::SinkResource::Ptr>::Ptr> ResourceFacade::load(const Sink::Query &query) |
258 | { | 261 | { |
259 | auto runner = new LocalStorageQueryRunner<ApplicationDomain::SinkResource>(query, mIdentifier, sConfigNotifier); | 262 | auto runner = new LocalStorageQueryRunner<ApplicationDomain::SinkResource>(query, mIdentifier, mTypeName, sConfigNotifier); |
260 | auto monitoredResources = QSharedPointer<QSet<QByteArray>>::create(); | 263 | auto monitoredResources = QSharedPointer<QSet<QByteArray>>::create(); |
261 | runner->setStatusUpdater([runner, monitoredResources](ApplicationDomain::SinkResource &resource) { | 264 | runner->setStatusUpdater([runner, monitoredResources](ApplicationDomain::SinkResource &resource) { |
262 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource.identifier(), ResourceConfig::getResourceType(resource.identifier())); | 265 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource.identifier(), ResourceConfig::getResourceType(resource.identifier())); |
@@ -276,7 +279,7 @@ QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename ApplicationDomain | |||
276 | } | 279 | } |
277 | 280 | ||
278 | 281 | ||
279 | AccountFacade::AccountFacade() : LocalStorageFacade<Sink::ApplicationDomain::SinkAccount>("accounts") | 282 | AccountFacade::AccountFacade() : LocalStorageFacade<Sink::ApplicationDomain::SinkAccount>("accounts", "type") |
280 | { | 283 | { |
281 | } | 284 | } |
282 | 285 | ||
@@ -286,7 +289,7 @@ AccountFacade::~AccountFacade() | |||
286 | 289 | ||
287 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename ApplicationDomain::SinkAccount::Ptr>::Ptr> AccountFacade::load(const Sink::Query &query) | 290 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename ApplicationDomain::SinkAccount::Ptr>::Ptr> AccountFacade::load(const Sink::Query &query) |
288 | { | 291 | { |
289 | auto runner = new LocalStorageQueryRunner<ApplicationDomain::SinkAccount>(query, mIdentifier, sConfigNotifier); | 292 | auto runner = new LocalStorageQueryRunner<ApplicationDomain::SinkAccount>(query, mIdentifier, mTypeName, sConfigNotifier); |
290 | auto monitoredResources = QSharedPointer<QSet<QByteArray>>::create(); | 293 | auto monitoredResources = QSharedPointer<QSet<QByteArray>>::create(); |
291 | runner->setStatusUpdater([runner, monitoredResources](ApplicationDomain::SinkAccount &account) { | 294 | runner->setStatusUpdater([runner, monitoredResources](ApplicationDomain::SinkAccount &account) { |
292 | Query query; | 295 | Query query; |
@@ -333,7 +336,7 @@ QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename ApplicationDomain | |||
333 | return qMakePair(KAsync::null<void>(), runner->emitter()); | 336 | return qMakePair(KAsync::null<void>(), runner->emitter()); |
334 | } | 337 | } |
335 | 338 | ||
336 | IdentityFacade::IdentityFacade() : LocalStorageFacade<Sink::ApplicationDomain::Identity>("identities") | 339 | IdentityFacade::IdentityFacade() : LocalStorageFacade<Sink::ApplicationDomain::Identity>("identities", "type") |
337 | { | 340 | { |
338 | } | 341 | } |
339 | 342 | ||
diff --git a/common/resourcefacade.h b/common/resourcefacade.h index b87a396..d259d4f 100644 --- a/common/resourcefacade.h +++ b/common/resourcefacade.h | |||
@@ -59,7 +59,7 @@ template <typename DomainType> | |||
59 | class LocalStorageQueryRunner | 59 | class LocalStorageQueryRunner |
60 | { | 60 | { |
61 | public: | 61 | public: |
62 | LocalStorageQueryRunner(const Sink::Query &query, const QByteArray &identifier, ConfigNotifier &configNotifier); | 62 | LocalStorageQueryRunner(const Sink::Query &query, const QByteArray &identifier, const QByteArray &typeName, ConfigNotifier &configNotifier); |
63 | typename Sink::ResultEmitter<typename DomainType::Ptr>::Ptr emitter(); | 63 | typename Sink::ResultEmitter<typename DomainType::Ptr>::Ptr emitter(); |
64 | void setStatusUpdater(const std::function<void(DomainType &)> &); | 64 | void setStatusUpdater(const std::function<void(DomainType &)> &); |
65 | void statusChanged(const QByteArray &identifier); | 65 | void statusChanged(const QByteArray &identifier); |
@@ -77,7 +77,7 @@ template <typename DomainType> | |||
77 | class LocalStorageFacade : public Sink::StoreFacade<DomainType> | 77 | class LocalStorageFacade : public Sink::StoreFacade<DomainType> |
78 | { | 78 | { |
79 | public: | 79 | public: |
80 | LocalStorageFacade(const QByteArray &instanceIdentifier); | 80 | LocalStorageFacade(const QByteArray &instanceIdentifier, const QByteArray &typeName); |
81 | virtual ~LocalStorageFacade(); | 81 | virtual ~LocalStorageFacade(); |
82 | virtual KAsync::Job<void> create(const DomainType &resource) Q_DECL_OVERRIDE; | 82 | virtual KAsync::Job<void> create(const DomainType &resource) Q_DECL_OVERRIDE; |
83 | virtual KAsync::Job<void> modify(const DomainType &resource) Q_DECL_OVERRIDE; | 83 | virtual KAsync::Job<void> modify(const DomainType &resource) Q_DECL_OVERRIDE; |
@@ -86,6 +86,7 @@ public: | |||
86 | 86 | ||
87 | protected: | 87 | protected: |
88 | QByteArray mIdentifier; | 88 | QByteArray mIdentifier; |
89 | QByteArray mTypeName; | ||
89 | static ConfigNotifier sConfigNotifier; | 90 | static ConfigNotifier sConfigNotifier; |
90 | }; | 91 | }; |
91 | 92 | ||
diff --git a/common/store.cpp b/common/store.cpp index c01d220..f5a7774 100644 --- a/common/store.cpp +++ b/common/store.cpp | |||
@@ -360,7 +360,7 @@ QList<DomainType> Store::read(const Sink::Query &q) | |||
360 | }); | 360 | }); |
361 | for (const auto &resourceInstanceIdentifier : resources.keys()) { | 361 | for (const auto &resourceInstanceIdentifier : resources.keys()) { |
362 | const auto resourceType = resources.value(resourceInstanceIdentifier); | 362 | const auto resourceType = resources.value(resourceInstanceIdentifier); |
363 | SinkTrace() << "Looking for " << resourceType << resourceInstanceIdentifier; | 363 | SinkTrace() << "Querying resource: " << resourceType << resourceInstanceIdentifier; |
364 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceType, resourceInstanceIdentifier); | 364 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceType, resourceInstanceIdentifier); |
365 | if (facade) { | 365 | if (facade) { |
366 | SinkTrace() << "Trying to fetch from resource " << resourceInstanceIdentifier; | 366 | SinkTrace() << "Trying to fetch from resource " << resourceInstanceIdentifier; |
diff --git a/sinksh/syntax_modules/sink_create.cpp b/sinksh/syntax_modules/sink_create.cpp index 1411b2e..4fedff4 100644 --- a/sinksh/syntax_modules/sink_create.cpp +++ b/sinksh/syntax_modules/sink_create.cpp | |||
@@ -91,7 +91,7 @@ bool resource(const QStringList &args, State &state) | |||
91 | auto identifier = map.take("identifier").toLatin1(); | 91 | auto identifier = map.take("identifier").toLatin1(); |
92 | 92 | ||
93 | auto object = ApplicationDomain::ApplicationDomainType::createEntity<ApplicationDomain::SinkResource>("", identifier); | 93 | auto object = ApplicationDomain::ApplicationDomainType::createEntity<ApplicationDomain::SinkResource>("", identifier); |
94 | object.setResourceType(resourceType); | 94 | object.setResourceType(resourceType.toLatin1()); |
95 | 95 | ||
96 | for (auto i = map.begin(); i != map.end(); ++i) { | 96 | for (auto i = map.begin(); i != map.end(); ++i) { |
97 | object.setProperty(i.key().toLatin1(), i.value()); | 97 | object.setProperty(i.key().toLatin1(), i.value()); |
diff --git a/tests/accountstest.cpp b/tests/accountstest.cpp index e0a99c2..260602c 100644 --- a/tests/accountstest.cpp +++ b/tests/accountstest.cpp | |||
@@ -22,8 +22,8 @@ private slots: | |||
22 | 22 | ||
23 | void init() | 23 | void init() |
24 | { | 24 | { |
25 | ConfigStore("accounts").clear(); | 25 | ConfigStore("accounts", "type").clear(); |
26 | ConfigStore("resources").clear(); | 26 | ConfigStore("resources", Sink::ApplicationDomain::SinkResource::ResourceType::name).clear(); |
27 | } | 27 | } |
28 | 28 | ||
29 | void testLoad() | 29 | void testLoad() |
@@ -34,17 +34,17 @@ private slots: | |||
34 | QString accountName("name"); | 34 | QString accountName("name"); |
35 | QString accountIcon("icon"); | 35 | QString accountIcon("icon"); |
36 | auto account = ApplicationDomainType::createEntity<SinkAccount>(); | 36 | auto account = ApplicationDomainType::createEntity<SinkAccount>(); |
37 | account.setProperty("type", "maildir"); | 37 | account.setAccountType("maildir"); |
38 | account.setProperty("name", accountName); | 38 | account.setName(accountName); |
39 | account.setProperty("icon", accountIcon); | 39 | account.setIcon(accountIcon); |
40 | Store::create(account).exec().waitForFinished(); | 40 | Store::create(account).exec().waitForFinished(); |
41 | 41 | ||
42 | Store::fetchAll<SinkAccount>(Query()).syncThen<void, QList<SinkAccount::Ptr>>([&](const QList<SinkAccount::Ptr> &accounts) { | 42 | Store::fetchAll<SinkAccount>(Query()).syncThen<void, QList<SinkAccount::Ptr>>([&](const QList<SinkAccount::Ptr> &accounts) { |
43 | QCOMPARE(accounts.size(), 1); | 43 | QCOMPARE(accounts.size(), 1); |
44 | auto account = accounts.first(); | 44 | auto account = accounts.first(); |
45 | QCOMPARE(account->getProperty("type").toString(), QString("maildir")); | 45 | QCOMPARE(account->getAccountType(), QString("maildir")); |
46 | QCOMPARE(account->getProperty("name").toString(), accountName); | 46 | QCOMPARE(account->getName(), accountName); |
47 | QCOMPARE(account->getProperty("icon").toString(), accountIcon); | 47 | QCOMPARE(account->getIcon(), accountIcon); |
48 | }) | 48 | }) |
49 | .exec().waitForFinished(); | 49 | .exec().waitForFinished(); |
50 | 50 | ||
@@ -52,8 +52,8 @@ private slots: | |||
52 | QString smtpUsername("smtpUsername"); | 52 | QString smtpUsername("smtpUsername"); |
53 | QString smtpPassword("smtpPassword"); | 53 | QString smtpPassword("smtpPassword"); |
54 | auto resource = ApplicationDomainType::createEntity<SinkResource>(); | 54 | auto resource = ApplicationDomainType::createEntity<SinkResource>(); |
55 | resource.setProperty("type", "sink.mailtransport"); | 55 | resource.setResourceType("sink.mailtransport"); |
56 | resource.setProperty("account", account.identifier()); | 56 | resource.setAccount(account); |
57 | resource.setProperty("server", smtpServer); | 57 | resource.setProperty("server", smtpServer); |
58 | resource.setProperty("username", smtpUsername); | 58 | resource.setProperty("username", smtpUsername); |
59 | resource.setProperty("password", smtpPassword); | 59 | resource.setProperty("password", smtpPassword); |
@@ -63,7 +63,7 @@ private slots: | |||
63 | Store::fetchAll<SinkResource>(Query()).syncThen<void, QList<SinkResource::Ptr>>([&](const QList<SinkResource::Ptr> &resources) { | 63 | Store::fetchAll<SinkResource>(Query()).syncThen<void, QList<SinkResource::Ptr>>([&](const QList<SinkResource::Ptr> &resources) { |
64 | QCOMPARE(resources.size(), 1); | 64 | QCOMPARE(resources.size(), 1); |
65 | auto resource = resources.first(); | 65 | auto resource = resources.first(); |
66 | QCOMPARE(resource->getProperty("type").toString(), QString("sink.mailtransport")); | 66 | QCOMPARE(resource->getResourceType(), QByteArray("sink.mailtransport")); |
67 | QCOMPARE(resource->getProperty("server").toString(), smtpServer); | 67 | QCOMPARE(resource->getProperty("server").toString(), smtpServer); |
68 | }) | 68 | }) |
69 | .exec().waitForFinished(); | 69 | .exec().waitForFinished(); |
diff --git a/tests/resourceconfigtest.cpp b/tests/resourceconfigtest.cpp index 70a37f0..c06b0fb 100644 --- a/tests/resourceconfigtest.cpp +++ b/tests/resourceconfigtest.cpp | |||
@@ -11,6 +11,9 @@ | |||
11 | #include "test.h" | 11 | #include "test.h" |
12 | #include "testutils.h" | 12 | #include "testutils.h" |
13 | 13 | ||
14 | using namespace Sink; | ||
15 | using namespace Sink::ApplicationDomain; | ||
16 | |||
14 | /** | 17 | /** |
15 | * Test of the resource configuration. | 18 | * Test of the resource configuration. |
16 | */ | 19 | */ |
@@ -31,43 +34,43 @@ private slots: | |||
31 | ResourceConfig::clear(); | 34 | ResourceConfig::clear(); |
32 | Sink::FacadeFactory::instance().registerStaticFacades(); | 35 | Sink::FacadeFactory::instance().registerStaticFacades(); |
33 | 36 | ||
34 | Sink::ApplicationDomain::SinkResource res("", "dummyresource.identifier1", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | 37 | SinkResource res("", "dummyresource.identifier1", 0, QSharedPointer<MemoryBufferAdaptor>::create()); |
35 | res.setProperty("identifier", "dummyresource.identifier1"); | 38 | res.setProperty("identifier", "dummyresource.identifier1"); |
36 | res.setProperty("type", "dummyresource"); | 39 | res.setProperty(SinkResource::ResourceType::name, "dummyresource"); |
37 | 40 | ||
38 | Sink::Store::create(res).exec().waitForFinished(); | 41 | Sink::Store::create(res).exec().waitForFinished(); |
39 | { | 42 | { |
40 | Sink::Query query; | 43 | Sink::Query query; |
41 | query.filter("type", Sink::Query::Comparator("dummyresource")); | 44 | query.filter<SinkResource::ResourceType>("dummyresource"); |
42 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::SinkResource>(query); | 45 | auto model = Sink::Store::loadModel<SinkResource>(query); |
43 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); | 46 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); |
44 | } | 47 | } |
45 | 48 | ||
46 | Sink::Store::remove(res).exec().waitForFinished(); | 49 | Sink::Store::remove(res).exec().waitForFinished(); |
47 | { | 50 | { |
48 | Sink::Query query; | 51 | Sink::Query query; |
49 | query.filter("type", Sink::Query::Comparator("dummyresource")); | 52 | query.filter<SinkResource::ResourceType>("dummyresource"); |
50 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::SinkResource>(query); | 53 | auto model = Sink::Store::loadModel<SinkResource>(query); |
51 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); | 54 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); |
52 | QCOMPARE(model->rowCount(QModelIndex()), 0); | 55 | QCOMPARE(model->rowCount(QModelIndex()), 0); |
53 | } | 56 | } |
54 | } | 57 | } |
55 | 58 | ||
56 | void testLoadResourceByCapabiity() | 59 | void testLoadResourceByCapability() |
57 | { | 60 | { |
58 | ResourceConfig::clear(); | 61 | ResourceConfig::clear(); |
59 | Sink::FacadeFactory::instance().registerStaticFacades(); | 62 | Sink::FacadeFactory::instance().registerStaticFacades(); |
60 | 63 | ||
61 | Sink::ApplicationDomain::SinkResource res("", "dummyresource.identifier1", 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | 64 | SinkResource res("", "dummyresource.identifier1", 0, QSharedPointer<MemoryBufferAdaptor>::create()); |
62 | res.setProperty("identifier", "dummyresource.identifier1"); | 65 | res.setProperty("identifier", "dummyresource.identifier1"); |
63 | res.setProperty("type", "dummyresource"); | 66 | res.setResourceType("dummyresource"); |
64 | res.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << "foo")); | 67 | res.setCapabilities(QByteArrayList() << "foo"); |
65 | 68 | ||
66 | Sink::Store::create(res).exec().waitForFinished(); | 69 | Sink::Store::create(res).exec().waitForFinished(); |
67 | { | 70 | { |
68 | Sink::Query query; | 71 | Sink::Query query; |
69 | query.filter("type", Sink::Query::Comparator("dummyresource")); | 72 | query.filter<SinkResource::ResourceType>("dummyresource"); |
70 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::SinkResource>(Sink::Query::CapabilityFilter("foo")); | 73 | auto model = Sink::Store::loadModel<SinkResource>(Query().containsFilter<SinkResource::Capabilities>("foo")); |
71 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); | 74 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); |
72 | } | 75 | } |
73 | 76 | ||
@@ -79,20 +82,20 @@ private slots: | |||
79 | ResourceConfig::clear(); | 82 | ResourceConfig::clear(); |
80 | Sink::FacadeFactory::instance().registerStaticFacades(); | 83 | Sink::FacadeFactory::instance().registerStaticFacades(); |
81 | 84 | ||
82 | auto res = Sink::ApplicationDomain::DummyResource::create(""); | 85 | auto res = DummyResource::create(""); |
83 | VERIFYEXEC(Sink::Store::create(res)); | 86 | VERIFYEXEC(Sink::Store::create(res)); |
84 | { | 87 | { |
85 | Sink::Query query; | 88 | Sink::Query query; |
86 | query.liveQuery = true; | 89 | query.liveQuery = true; |
87 | query.request<Sink::ApplicationDomain::SinkResource::Status>(); | 90 | query.request<SinkResource::Status>(); |
88 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::SinkResource>(query); | 91 | auto model = Sink::Store::loadModel<SinkResource>(query); |
89 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); | 92 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); |
90 | auto resource = model->data(model->index(0, 0, QModelIndex()), Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::SinkResource::Ptr>(); | 93 | auto resource = model->data(model->index(0, 0, QModelIndex()), Sink::Store::DomainObjectRole).value<SinkResource::Ptr>(); |
91 | QCOMPARE(resource->getStatus(), static_cast<int>(Sink::ApplicationDomain::OfflineStatus)); | 94 | QCOMPARE(resource->getStatus(), static_cast<int>(OfflineStatus)); |
92 | 95 | ||
93 | //Synchronize to connect | 96 | //Synchronize to connect |
94 | VERIFYEXEC(Sink::Store::synchronize(query)); | 97 | VERIFYEXEC(Sink::Store::synchronize(query)); |
95 | QTRY_COMPARE(model->data(model->index(0, 0, QModelIndex()), Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::SinkResource::Ptr>()->getStatus(), static_cast<int>(Sink::ApplicationDomain::ConnectedStatus)); | 98 | QTRY_COMPARE(model->data(model->index(0, 0, QModelIndex()), Sink::Store::DomainObjectRole).value<SinkResource::Ptr>()->getStatus(), static_cast<int>(ConnectedStatus)); |
96 | } | 99 | } |
97 | 100 | ||
98 | VERIFYEXEC(Sink::Store::remove(res)); | 101 | VERIFYEXEC(Sink::Store::remove(res)); |