From 76d2afa5130db628a884b6bcae9db9f3b077241d Mon Sep 17 00:00:00 2001 From: Iuliia Moroz Date: Thu, 17 Mar 2022 15:56:38 +0200 Subject: [PATCH] Add synchronous GetLatestVersion method. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The methoŠ² could be used in special cases when the method has to run synchronously in one thread. Relates-To: OAM-1422 Signed-off-by: Iuliia Moroz --- .../olp/dataservice/read/CatalogClient.h | 13 ++++++++++ .../olp/dataservice/read/VersionsRequest.h | 26 +++++++++++++++++++ .../src/CatalogClient.cpp | 5 ++++ .../src/CatalogClientImpl.cpp | 10 +++++++ .../src/CatalogClientImpl.h | 3 +++ 5 files changed, 57 insertions(+) diff --git a/olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/CatalogClient.h b/olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/CatalogClient.h index 576d2fa89..5305bbcb0 100644 --- a/olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/CatalogClient.h +++ b/olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/CatalogClient.h @@ -159,6 +159,19 @@ class DATASERVICE_READ_API CatalogClient final { client::CancellableFuture GetLatestVersion( CatalogVersionRequest request); + /** + * @brief Gets the catalog version synchronously. + * + * @param request The `CatalogVersionRequest` instance that contains + * a complete set of request parameters. + * @param context The `CancellationContext` instance. + * + * @return `CatalogVersionResponse` instance with the catalog configuration or + * an error + */ + CatalogVersionResponse GetLatestVersion(CatalogVersionRequest request, + client::CancellationContext context); + /** * @brief Gets the catalog versions list. * diff --git a/olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/VersionsRequest.h b/olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/VersionsRequest.h index 89b3b0685..364f6db81 100644 --- a/olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/VersionsRequest.h +++ b/olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/VersionsRequest.h @@ -136,6 +136,31 @@ class DATASERVICE_READ_API VersionsRequest final { return *this; } + /** + * @brief Gets the fetch option that controls how requests are handled. + * + * The default option is `OnlineIfNotFound` that queries the network if + * the requested resource is not in the cache. + * + * @return The fetch option. + */ + inline FetchOptions GetFetchOption() const { return fetch_option_; } + + /** + * @brief Sets the fetch option that you can use to set the source from + * which data should be fetched. + * + * @see `GetFetchOption()` for information on usage and format. + * + * @param fetch_option The `FetchOption` enum. + * + * @return A reference to the updated `VersionsRequest` instance. + */ + inline VersionsRequest& WithFetchOption(FetchOptions fetch_option) { + fetch_option_ = fetch_option; + return *this; + } + /** * @brief Creates a readable format for the request. * @@ -156,6 +181,7 @@ class DATASERVICE_READ_API VersionsRequest final { std::int64_t start_version_; std::int64_t end_version_; boost::optional billing_tag_; + FetchOptions fetch_option_{OnlineIfNotFound}; }; } // namespace read diff --git a/olp-cpp-sdk-dataservice-read/src/CatalogClient.cpp b/olp-cpp-sdk-dataservice-read/src/CatalogClient.cpp index 3f1be74c8..d4264e92e 100644 --- a/olp-cpp-sdk-dataservice-read/src/CatalogClient.cpp +++ b/olp-cpp-sdk-dataservice-read/src/CatalogClient.cpp @@ -62,6 +62,11 @@ CatalogClient::GetLatestVersion(CatalogVersionRequest request) { return impl_->GetLatestVersion(std::move(request)); } +CatalogVersionResponse CatalogClient::GetLatestVersion( + CatalogVersionRequest request, client::CancellationContext context) { + return impl_->GetLatestVersion(std::move(request), std::move(context)); +} + client::CancellationToken CatalogClient::ListVersions( VersionsRequest request, VersionsResponseCallback callback) { return impl_->ListVersions(std::move(request), std::move(callback)); diff --git a/olp-cpp-sdk-dataservice-read/src/CatalogClientImpl.cpp b/olp-cpp-sdk-dataservice-read/src/CatalogClientImpl.cpp index 129407fb4..7a8a94d53 100644 --- a/olp-cpp-sdk-dataservice-read/src/CatalogClientImpl.cpp +++ b/olp-cpp-sdk-dataservice-read/src/CatalogClientImpl.cpp @@ -121,6 +121,16 @@ CatalogClientImpl::GetLatestVersion(CatalogVersionRequest request) { std::move(cancel_token), std::move(promise)); } +CatalogVersionResponse CatalogClientImpl::GetLatestVersion( + CatalogVersionRequest request, client::CancellationContext context) { + auto catalog = catalog_; + auto settings = settings_; + auto lookup_client = lookup_client_; + + repository::CatalogRepository repository(catalog, settings, lookup_client); + return repository.GetLatestVersion(request, std::move(context)); +} + client::CancellationToken CatalogClientImpl::ListVersions( VersionsRequest request, VersionsResponseCallback callback) { auto catalog = catalog_; diff --git a/olp-cpp-sdk-dataservice-read/src/CatalogClientImpl.h b/olp-cpp-sdk-dataservice-read/src/CatalogClientImpl.h index e048ccca7..11160fcab 100644 --- a/olp-cpp-sdk-dataservice-read/src/CatalogClientImpl.h +++ b/olp-cpp-sdk-dataservice-read/src/CatalogClientImpl.h @@ -64,6 +64,9 @@ class CatalogClientImpl final { client::CancellableFuture GetLatestVersion( CatalogVersionRequest request); + CatalogVersionResponse GetLatestVersion(CatalogVersionRequest request, + client::CancellationContext context); + client::CancellationToken ListVersions(VersionsRequest request, VersionsResponseCallback callback);