From af0f69d6c267d231d01b69525b91add8309e43e0 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 21 Oct 2015 12:05:09 +0200 Subject: ClientAPI: Don't require an explicit instance identifier --- common/clientapi.h | 59 +++++++++++++++++------------------ common/domain/applicationdomaintype.h | 7 +++++ common/facadeinterface.h | 25 +++++++++++++++ 3 files changed, 61 insertions(+), 30 deletions(-) (limited to 'common') diff --git a/common/clientapi.h b/common/clientapi.h index e467b8f..6237cfb 100644 --- a/common/clientapi.h +++ b/common/clientapi.h @@ -134,20 +134,25 @@ public: // { // } + template + static std::shared_ptr > getFacade(const QByteArray &resourceInstanceIdentifier) + { + if (auto facade = FacadeFactory::instance().getFacade(resourceName(resourceInstanceIdentifier), resourceInstanceIdentifier)) { + return facade; + } + return std::make_shared >(); + } /** * Create a new entity. */ template - static KAsync::Job create(const DomainType &domainObject, const QByteArray &resourceIdentifier) { + static KAsync::Job create(const DomainType &domainObject) { //Potentially move to separate thread as well - auto facade = FacadeFactory::instance().getFacade(resourceName(resourceIdentifier), resourceIdentifier); - if (facade) { - return facade->create(domainObject).template then([facade](){}, [](int errorCode, const QString &error) { - Warning() << "Failed to create"; - }); - } - return KAsync::error(-1, "Failed to create a facade"); + auto facade = getFacade(domainObject.resourceInstanceIdentifier()); + return facade->create(domainObject).template then([facade](){}, [](int errorCode, const QString &error) { + Warning() << "Failed to create"; + }); } /** @@ -156,30 +161,24 @@ public: * This includes moving etc. since these are also simple settings on a property. */ template - static KAsync::Job modify(const DomainType &domainObject, const QByteArray &resourceIdentifier) { + static KAsync::Job modify(const DomainType &domainObject) { //Potentially move to separate thread as well - auto facade = FacadeFactory::instance().getFacade(resourceName(resourceIdentifier), resourceIdentifier); - if (facade) { - return facade->modify(domainObject).template then([facade](){}, [](int errorCode, const QString &error) { - Warning() << "Failed to modify"; - }); - } - return KAsync::error(-1, "Failed to create a facade"); + auto facade = getFacade(domainObject.resourceInstanceIdentifier()); + return facade->modify(domainObject).template then([facade](){}, [](int errorCode, const QString &error) { + Warning() << "Failed to modify"; + }); } /** * Remove an entity. */ template - static KAsync::Job remove(const DomainType &domainObject, const QByteArray &resourceIdentifier) { + static KAsync::Job remove(const DomainType &domainObject) { //Potentially move to separate thread as well - auto facade = FacadeFactory::instance().getFacade(resourceName(resourceIdentifier), resourceIdentifier); - if (facade) { - return facade->remove(domainObject).template then([facade](){}, [](int errorCode, const QString &error) { - Warning() << "Failed to remove"; - }); - } - return KAsync::error(-1, "Failed to create a facade"); + auto facade = getFacade(domainObject.resourceInstanceIdentifier()); + return facade->remove(domainObject).template then([facade](){}, [](int errorCode, const QString &error) { + Warning() << "Failed to remove"; + }); } static void shutdown(const QByteArray &resourceIdentifier); @@ -213,20 +212,20 @@ public: return ApplicationDomain::AkonadiResource::Ptr::create(); } - static void setConfiguration(const ApplicationDomain::AkonadiResource &resource, const QByteArray &resourceIdentifier) + static void setConfiguration(const ApplicationDomain::AkonadiResource &resource) { - Store::modify(resource, resourceIdentifier); + Store::modify(resource); } - static void createResource(const ApplicationDomain::AkonadiResource &resource, const QByteArray &resourceIdentifier) + static void createResource(const ApplicationDomain::AkonadiResource &resource) { - Store::create(resource, resourceIdentifier); + Store::create(resource); } static void removeResource(const QByteArray &resourceIdentifier) { - ApplicationDomain::AkonadiResource resource; - Store::remove(resource, resourceIdentifier); + ApplicationDomain::AkonadiResource resource(resourceIdentifier); + Store::remove(resource); } }; diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index 3cc34ec..bd7ff65 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h @@ -45,6 +45,13 @@ public: } + ApplicationDomainType(const QByteArray &resourceInstanceIdentifier) + :mAdaptor(new MemoryBufferAdaptor()), + mResourceInstanceIdentifier(resourceInstanceIdentifier) + { + + } + ApplicationDomainType(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier, qint64 revision, const QSharedPointer &adaptor) : mAdaptor(adaptor), mResourceInstanceIdentifier(resourceInstanceIdentifier), diff --git a/common/facadeinterface.h b/common/facadeinterface.h index ac60ae4..cd43fa1 100644 --- a/common/facadeinterface.h +++ b/common/facadeinterface.h @@ -48,4 +48,29 @@ public: virtual KAsync::Job load(const Query &query, const QSharedPointer > &resultProvider) = 0; }; +template +class NullFacade : public StoreFacade { +public: + virtual ~NullFacade(){}; + KAsync::Job create(const DomainType &domainObject) + { + return KAsync::error(-1, "Failed to create a facade"); + } + + KAsync::Job modify(const DomainType &domainObject) + { + return KAsync::error(-1, "Failed to create a facade"); + } + + KAsync::Job remove(const DomainType &domainObject) + { + return KAsync::error(-1, "Failed to create a facade"); + } + + KAsync::Job load(const Query &query, const QSharedPointer > &resultProvider) + { + return KAsync::error(-1, "Failed to create a facade"); + } +}; + } -- cgit v1.2.3