diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-07-08 14:30:37 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-07-08 14:30:37 +0200 |
commit | db8f328bde01d24bf9271638f8295fc70c68cdd4 (patch) | |
tree | 368dbc4895ae3f653d4ba42163780791888b5125 | |
parent | d099ece17c6707af477b91dee9ced13b0f7e962a (diff) | |
download | sink-db8f328bde01d24bf9271638f8295fc70c68cdd4.tar.gz sink-db8f328bde01d24bf9271638f8295fc70c68cdd4.zip |
Account status
-rw-r--r-- | common/resourcefacade.cpp | 49 | ||||
-rw-r--r-- | common/resourcefacade.h | 1 | ||||
-rw-r--r-- | tests/accountstest.cpp | 30 |
3 files changed, 80 insertions, 0 deletions
diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index bdb5841..583d6ec 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp | |||
@@ -283,6 +283,55 @@ AccountFacade::~AccountFacade() | |||
283 | { | 283 | { |
284 | } | 284 | } |
285 | 285 | ||
286 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename ApplicationDomain::SinkAccount::Ptr>::Ptr> AccountFacade::load(const Sink::Query &query) | ||
287 | { | ||
288 | auto runner = new LocalStorageQueryRunner<ApplicationDomain::SinkAccount>(query, mIdentifier, sConfigNotifier); | ||
289 | auto monitoredResources = QSharedPointer<QSet<QByteArray>>::create(); | ||
290 | runner->setStatusUpdater([runner, monitoredResources](ApplicationDomain::SinkAccount &account) { | ||
291 | Query query; | ||
292 | query.filter<ApplicationDomain::SinkResource::Account>(account.identifier()); | ||
293 | const auto resources = Store::read<ApplicationDomain::SinkResource>(query); | ||
294 | SinkTrace() << "Found resource belonging to the account " << account.identifier() << " : " << resources; | ||
295 | auto accountIdentifier = account.identifier(); | ||
296 | ApplicationDomain::Status status = ApplicationDomain::ConnectedStatus; | ||
297 | for (const auto &resource : resources) { | ||
298 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource.identifier(), ResourceConfig::getResourceType(resource.identifier())); | ||
299 | if (!monitoredResources->contains(resource.identifier())) { | ||
300 | auto ret = QObject::connect(resourceAccess.data(), &ResourceAccess::notification, runner->guard(), [resource, runner, resourceAccess, accountIdentifier](const Notification ¬ification) { | ||
301 | SinkTrace() << "Received notification in facade: " << notification.type; | ||
302 | if (notification.type == Notification::Status) { | ||
303 | runner->statusChanged(accountIdentifier); | ||
304 | } | ||
305 | }); | ||
306 | Q_ASSERT(ret); | ||
307 | monitoredResources->insert(resource.identifier()); | ||
308 | } | ||
309 | |||
310 | //Figure out overall status | ||
311 | auto s = resourceAccess->getResourceStatus(); | ||
312 | switch (s) { | ||
313 | case ApplicationDomain::ErrorStatus: | ||
314 | status = ApplicationDomain::ErrorStatus; | ||
315 | break; | ||
316 | case ApplicationDomain::OfflineStatus: | ||
317 | if (status == ApplicationDomain::ConnectedStatus) { | ||
318 | status = ApplicationDomain::OfflineStatus; | ||
319 | } | ||
320 | break; | ||
321 | case ApplicationDomain::ConnectedStatus: | ||
322 | break; | ||
323 | case ApplicationDomain::BusyStatus: | ||
324 | if (status != ApplicationDomain::ErrorStatus) { | ||
325 | status = ApplicationDomain::BusyStatus; | ||
326 | } | ||
327 | break; | ||
328 | } | ||
329 | } | ||
330 | account.setStatusStatus(status); | ||
331 | }); | ||
332 | return qMakePair(KAsync::null<void>(), runner->emitter()); | ||
333 | } | ||
334 | |||
286 | IdentityFacade::IdentityFacade() : LocalStorageFacade<Sink::ApplicationDomain::Identity>("identities") | 335 | IdentityFacade::IdentityFacade() : LocalStorageFacade<Sink::ApplicationDomain::Identity>("identities") |
287 | { | 336 | { |
288 | } | 337 | } |
diff --git a/common/resourcefacade.h b/common/resourcefacade.h index 64e082f..23c453a 100644 --- a/common/resourcefacade.h +++ b/common/resourcefacade.h | |||
@@ -107,6 +107,7 @@ class AccountFacade : public LocalStorageFacade<Sink::ApplicationDomain::SinkAcc | |||
107 | public: | 107 | public: |
108 | AccountFacade(); | 108 | AccountFacade(); |
109 | virtual ~AccountFacade(); | 109 | virtual ~AccountFacade(); |
110 | virtual QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename Sink::ApplicationDomain::SinkAccount::Ptr>::Ptr> load(const Sink::Query &query) Q_DECL_OVERRIDE; | ||
110 | }; | 111 | }; |
111 | 112 | ||
112 | class IdentityFacade : public LocalStorageFacade<Sink::ApplicationDomain::Identity> | 113 | class IdentityFacade : public LocalStorageFacade<Sink::ApplicationDomain::Identity> |
diff --git a/tests/accountstest.cpp b/tests/accountstest.cpp index 8d0f2e6..4be8bd6 100644 --- a/tests/accountstest.cpp +++ b/tests/accountstest.cpp | |||
@@ -8,6 +8,7 @@ | |||
8 | #include <store.h> | 8 | #include <store.h> |
9 | #include <log.h> | 9 | #include <log.h> |
10 | #include <configstore.h> | 10 | #include <configstore.h> |
11 | #include "testutils.h" | ||
11 | 12 | ||
12 | class AccountsTest : public QObject | 13 | class AccountsTest : public QObject |
13 | { | 14 | { |
@@ -115,6 +116,35 @@ private slots: | |||
115 | QTRY_COMPARE(model->rowCount(QModelIndex()), 2); | 116 | QTRY_COMPARE(model->rowCount(QModelIndex()), 2); |
116 | } | 117 | } |
117 | 118 | ||
119 | void testLoadAccountStatus() | ||
120 | { | ||
121 | using namespace Sink; | ||
122 | using namespace Sink::ApplicationDomain; | ||
123 | |||
124 | auto account = ApplicationDomainType::createEntity<SinkAccount>(); | ||
125 | account.setAccountType("dummy"); | ||
126 | account.setName("name"); | ||
127 | VERIFYEXEC(Store::create(account)); | ||
128 | |||
129 | auto res = Sink::ApplicationDomain::DummyResource::create(account.identifier()); | ||
130 | VERIFYEXEC(Sink::Store::create(res)); | ||
131 | { | ||
132 | Sink::Query query; | ||
133 | query.liveQuery = true; | ||
134 | query.request<Sink::ApplicationDomain::SinkAccount::Status>(); | ||
135 | |||
136 | auto model = Sink::Store::loadModel<Sink::ApplicationDomain::SinkAccount>(query); | ||
137 | QTRY_COMPARE(model->rowCount(QModelIndex()), 1); | ||
138 | auto account = model->data(model->index(0, 0, QModelIndex()), Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::SinkAccount::Ptr>(); | ||
139 | QCOMPARE(account->getStatus(), static_cast<int>(Sink::ApplicationDomain::OfflineStatus)); | ||
140 | |||
141 | //Synchronize to connect | ||
142 | VERIFYEXEC(Sink::Store::synchronize(Query::ResourceFilter(res))); | ||
143 | |||
144 | QTRY_COMPARE_WITH_TIMEOUT(model->data(model->index(0, 0, QModelIndex()), Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::SinkAccount::Ptr>()->getStatus(), static_cast<int>(Sink::ApplicationDomain::ConnectedStatus), 1000); | ||
145 | } | ||
146 | } | ||
147 | |||
118 | }; | 148 | }; |
119 | 149 | ||
120 | QTEST_GUILESS_MAIN(AccountsTest) | 150 | QTEST_GUILESS_MAIN(AccountsTest) |