diff options
Diffstat (limited to 'common/store.cpp')
-rw-r--r-- | common/store.cpp | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/common/store.cpp b/common/store.cpp index 0321583..b89e08c 100644 --- a/common/store.cpp +++ b/common/store.cpp | |||
@@ -51,23 +51,27 @@ QString Store::getTemporaryFilePath() | |||
51 | return Sink::temporaryFileLocation() + "/" + QUuid::createUuid().toString(); | 51 | return Sink::temporaryFileLocation() + "/" + QUuid::createUuid().toString(); |
52 | } | 52 | } |
53 | 53 | ||
54 | static QList<QByteArray> getResources(const QList<QByteArray> &resourceFilter, const QByteArray &type = QByteArray()) | 54 | /* |
55 | * Returns a map of resource instance identifiers and resource type | ||
56 | */ | ||
57 | static QMap<QByteArray, QByteArray> getResources(const QList<QByteArray> &resourceFilter, const QByteArray &type = QByteArray()) | ||
55 | { | 58 | { |
59 | QMap<QByteArray, QByteArray> resources; | ||
56 | // Return the global resource (signified by an empty name) for types that don't belong to a specific resource | 60 | // Return the global resource (signified by an empty name) for types that don't belong to a specific resource |
57 | if (type == "sinkresource" || type == "sinkaccount" || type == "identity") { | 61 | if (type == "sinkresource" || type == "sinkaccount" || type == "identity") { |
58 | return QList<QByteArray>() << ""; | 62 | resources.insert("", ""); |
63 | return resources; | ||
59 | } | 64 | } |
60 | QList<QByteArray> resources; | ||
61 | const auto configuredResources = ResourceConfig::getResources(); | 65 | const auto configuredResources = ResourceConfig::getResources(); |
62 | if (resourceFilter.isEmpty()) { | 66 | if (resourceFilter.isEmpty()) { |
63 | for (const auto &res : configuredResources.keys()) { | 67 | for (const auto &res : configuredResources.keys()) { |
64 | // TODO filter by entity type | 68 | // TODO filter by entity type |
65 | resources << res; | 69 | resources.insert(res, configuredResources.value(res)); |
66 | } | 70 | } |
67 | } else { | 71 | } else { |
68 | for (const auto &res : resourceFilter) { | 72 | for (const auto &res : resourceFilter) { |
69 | if (configuredResources.contains(res)) { | 73 | if (configuredResources.contains(res)) { |
70 | resources << res; | 74 | resources.insert(res, configuredResources.value(res)); |
71 | } else { | 75 | } else { |
72 | qWarning() << "Resource is not existing: " << res; | 76 | qWarning() << "Resource is not existing: " << res; |
73 | } | 77 | } |
@@ -99,16 +103,17 @@ QSharedPointer<QAbstractItemModel> Store::loadModel(Query query) | |||
99 | auto resources = getResources(query.resources, ApplicationDomain::getTypeName<DomainType>()); | 103 | auto resources = getResources(query.resources, ApplicationDomain::getTypeName<DomainType>()); |
100 | auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); | 104 | auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); |
101 | model->setEmitter(aggregatingEmitter); | 105 | model->setEmitter(aggregatingEmitter); |
102 | KAsync::iterate(resources) | 106 | KAsync::iterate(resources.keys()) |
103 | .template each<void, QByteArray>([query, aggregatingEmitter](const QByteArray &resource, KAsync::Future<void> &future) { | 107 | .template each<void, QByteArray>([query, aggregatingEmitter, resources](const QByteArray &resourceInstanceIdentifier, KAsync::Future<void> &future) { |
104 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resource), resource); | 108 | const auto resourceType = resources.value(resourceInstanceIdentifier); |
109 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceType, resourceInstanceIdentifier); | ||
105 | if (facade) { | 110 | if (facade) { |
106 | Trace() << "Trying to fetch from resource " << resource; | 111 | Trace() << "Trying to fetch from resource " << resourceInstanceIdentifier; |
107 | auto result = facade->load(query); | 112 | auto result = facade->load(query); |
108 | aggregatingEmitter->addEmitter(result.second); | 113 | aggregatingEmitter->addEmitter(result.second); |
109 | result.first.template then<void>([&future]() { future.setFinished(); }).exec(); | 114 | result.first.template then<void>([&future]() { future.setFinished(); }).exec(); |
110 | } else { | 115 | } else { |
111 | Trace() << "Couldn' find a facade for " << resource; | 116 | Trace() << "Couldn' find a facade for " << resourceInstanceIdentifier; |
112 | // Ignore the error and carry on | 117 | // Ignore the error and carry on |
113 | future.setFinished(); | 118 | future.setFinished(); |
114 | } | 119 | } |
@@ -129,8 +134,7 @@ static std::shared_ptr<StoreFacade<DomainType>> getFacade(const QByteArray &reso | |||
129 | return facade; | 134 | return facade; |
130 | } | 135 | } |
131 | } | 136 | } |
132 | const auto resourceType = resourceName(resourceInstanceIdentifier); | 137 | if (auto facade = FacadeFactory::instance().getFacade<DomainType>(ResourceConfig::getResourceType(resourceInstanceIdentifier), resourceInstanceIdentifier)) { |
133 | if (auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceType, resourceInstanceIdentifier)) { | ||
134 | return facade; | 138 | return facade; |
135 | } | 139 | } |
136 | return std::make_shared<NullFacade<DomainType>>(); | 140 | return std::make_shared<NullFacade<DomainType>>(); |
@@ -168,7 +172,7 @@ KAsync::Job<void> Store::removeDataFromDisk(const QByteArray &identifier) | |||
168 | Trace() << "Remove data from disk " << identifier; | 172 | Trace() << "Remove data from disk " << identifier; |
169 | auto time = QSharedPointer<QTime>::create(); | 173 | auto time = QSharedPointer<QTime>::create(); |
170 | time->start(); | 174 | time->start(); |
171 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(identifier); | 175 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(identifier, ResourceConfig::getResourceType(identifier)); |
172 | resourceAccess->open(); | 176 | resourceAccess->open(); |
173 | return resourceAccess->sendCommand(Sink::Commands::RemoveFromDiskCommand) | 177 | return resourceAccess->sendCommand(Sink::Commands::RemoveFromDiskCommand) |
174 | .then<void>([resourceAccess, time]() { Trace() << "Remove from disk complete." << Log::TraceTime(time->elapsed()); }); | 178 | .then<void>([resourceAccess, time]() { Trace() << "Remove from disk complete." << Log::TraceTime(time->elapsed()); }); |
@@ -177,11 +181,11 @@ KAsync::Job<void> Store::removeDataFromDisk(const QByteArray &identifier) | |||
177 | KAsync::Job<void> Store::synchronize(const Sink::Query &query) | 181 | KAsync::Job<void> Store::synchronize(const Sink::Query &query) |
178 | { | 182 | { |
179 | Trace() << "synchronize" << query.resources; | 183 | Trace() << "synchronize" << query.resources; |
180 | auto resources = getResources(query.resources); | 184 | auto resources = getResources(query.resources).keys(); |
181 | return KAsync::iterate(resources) | 185 | return KAsync::iterate(resources) |
182 | .template each<void, QByteArray>([query](const QByteArray &resource, KAsync::Future<void> &future) { | 186 | .template each<void, QByteArray>([query](const QByteArray &resource, KAsync::Future<void> &future) { |
183 | Trace() << "Synchronizing " << resource; | 187 | Trace() << "Synchronizing " << resource; |
184 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource); | 188 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource)); |
185 | resourceAccess->open(); | 189 | resourceAccess->open(); |
186 | resourceAccess->synchronizeResource(true, false).then<void>([&future, resourceAccess]() { future.setFinished(); }).exec(); | 190 | resourceAccess->synchronizeResource(true, false).then<void>([&future, resourceAccess]() { future.setFinished(); }).exec(); |
187 | }); | 191 | }); |