Skip to content

Commit 227b34c

Browse files
authored
Update VersionedLayerClient example and doxygen. (#693)
VersionedLayerClient API is changed, version is specified in constructor instead of DataRequest now. So the goal of this change is to adapt example and doxygen to the new API. Added new argument for catalog version. Resolves: OLPEDGE-1566 Signed-off-by: Kostiantyn Zvieriev <[email protected]>
1 parent 52b9543 commit 227b34c

File tree

5 files changed

+46
-14
lines changed

5 files changed

+46
-14
lines changed

examples/Options.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ const Option kKeySecretOption{"-s", "--key_secret",
3636
const Option kCatalogOption{"-c", "--catalog",
3737
"Catalog HRN (HERE Resource Name)."};
3838

39+
const Option kCatalogVersionOption{
40+
"-v", "--catalog_version",
41+
"The version of the catalog from which you wan to "
42+
"get data(used in read example, optional)."};
43+
3944
const Option kLayerIdOption{"-l", "--layer_id",
4045
"The layer ID inside the catalog where you want to "
4146
"publish data to(required for write example)."};

examples/ReadExample.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ bool HandleDataResponse(
118118
}
119119
} // namespace
120120

121-
int RunExampleRead(const AccessKey& access_key, const std::string& catalog) {
121+
int RunExampleRead(const AccessKey& access_key, const std::string& catalog,
122+
const boost::optional<int64_t>& catalog_version) {
122123
// Create a task scheduler instance
123124
std::shared_ptr<olp::thread::TaskScheduler> task_scheduler =
124125
olp::client::OlpClientSettingsFactory::CreateDefaultTaskScheduler(1u);
@@ -174,9 +175,10 @@ int RunExampleRead(const AccessKey& access_key, const std::string& catalog) {
174175
first_layer_id = HandleCatalogResponse(catalog_response);
175176
}
176177

177-
// Create appropriate layer client with HRN, layer name and settings.
178+
// Create appropriate layer client with HRN, layer name, version and settings.
178179
olp::dataservice::read::VersionedLayerClient layer_client(
179-
olp::client::HRN(catalog), first_layer_id, client_settings);
180+
olp::client::HRN(catalog), first_layer_id, catalog_version,
181+
client_settings);
180182

181183
std::string first_partition_id;
182184
if (!first_layer_id.empty()) {

examples/ReadExample.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@
2121

2222
#include "Examples.h"
2323

24+
#include <boost/optional.hpp>
25+
2426
/**
2527
* @brief Dataservice read example. Authenticate client using access key id and
2628
* secret. Get catalog and partition metadata, as well as partition data using
2729
* the HERE Open Location Platform.
2830
* @param access_key here.access.key.id and here.access.key.secret.
29-
* @param The HERE Resource Name (HRN) of the catalog from which you want to read data.
31+
* @param catalog The HERE Resource Name (HRN) of the catalog from which you
32+
* want to read data.
33+
* @param catalog_version The desired version of the catalog.
3034
* @return result of publish data(0 - if succeed)
3135
*/
32-
int RunExampleRead(const AccessKey& access_key, const std::string& catalog);
36+
int RunExampleRead(
37+
const AccessKey& access_key, const std::string& catalog,
38+
const boost::optional<int64_t>& catalog_version = boost::none);

examples/main.cpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
#include "ReadExample.h"
2323
#include "WriteExample.h"
2424

25-
#include <iostream>
2625
#include <stdio.h>
2726
#include <string.h>
27+
#include <iostream>
28+
#include <sstream>
2829

2930
bool IsMatch(const std::string& name, const tools::Option& option) {
3031
return name == option.short_name || name == option.long_name;
@@ -42,6 +43,8 @@ constexpr auto usage =
4243
"example [read, write, cache] \n -i [--key_id] here.access.key.id \n -s "
4344
"[--key_secret] here.access.key.secret \n"
4445
" -c [--catalog] catalog HRN (HERE Resource Name). \n"
46+
" -v [--catalog_version] The version of the catalog from which you wan to"
47+
"get data(used in read example, optional). \n"
4548
" -l [--layer_id] the layer ID inside the catalog where you want to "
4649
"publish data to(required for write example). \n"
4750
" -h [--help]: show usage \n For "
@@ -57,7 +60,9 @@ int RequiredArgumentError(const tools::Option& arg) {
5760
return 0;
5861
}
5962
int ParseArguments(const int argc, char** argv, AccessKey& access_key,
60-
std::string& catalog, std::string& layer_id) {
63+
std::string& catalog,
64+
boost::optional<int64_t>& catalog_version,
65+
std::string& layer_id) {
6166
int examples_to_run = 0;
6267

6368
const std::vector<std::string> arguments(argv + 1, argv + argc);
@@ -104,6 +109,16 @@ int ParseArguments(const int argc, char** argv, AccessKey& access_key,
104109
return RequiredArgumentError(tools::kCatalogOption);
105110
}
106111
catalog = *it;
112+
} else if (IsMatch(*it, tools::kCatalogVersionOption)) {
113+
++it;
114+
catalog_version = 0;
115+
std::stringstream ss(*it);
116+
ss >> *catalog_version;
117+
if (ss.fail() || !ss.eof()) {
118+
std::cout << "invalid catalog version value -- '" << *it
119+
<< "', but int64 is expected." << std::endl;
120+
catalog_version = boost::none;
121+
}
107122
} else if (IsMatch(*it, tools::kLayerIdOption)) {
108123
if (++it == arguments.end()) {
109124
return RequiredArgumentError(tools::kLayerIdOption);
@@ -126,10 +141,12 @@ int ParseArguments(const int argc, char** argv, AccessKey& access_key,
126141
}
127142

128143
int RunExamples(const AccessKey& access_key, int examples_to_run,
129-
const std::string& catalog, const std::string& layer_id) {
144+
const std::string& catalog,
145+
const boost::optional<int64_t>& catalog_version,
146+
const std::string& layer_id) {
130147
if (examples_to_run & Examples::read_example) {
131148
std::cout << "Read Example" << std::endl;
132-
if (RunExampleRead(access_key, catalog)) {
149+
if (RunExampleRead(access_key, catalog, catalog_version)) {
133150
std::cout << "Read Example failed" << std::endl;
134151
return -1;
135152
}
@@ -159,9 +176,10 @@ int main(int argc, char** argv) {
159176
std::string catalog; // the HRN of the catalog to which you to publish data
160177
std::string layer_id; // the of the layer inside the catalog to which you
161178
// want to publish data
179+
boost::optional<int64_t> catalog_version; // version of the catalog.
162180

163-
int examples_to_run =
164-
ParseArguments(argc, argv, access_key, catalog, layer_id);
181+
int examples_to_run = ParseArguments(argc, argv, access_key, catalog,
182+
catalog_version, layer_id);
165183
if (examples_to_run == 0) {
166184
return 0;
167185
}
@@ -183,5 +201,6 @@ int main(int argc, char** argv) {
183201
<< std::endl;
184202
}
185203

186-
return RunExamples(access_key, examples_to_run, catalog, layer_id);
204+
return RunExamples(access_key, examples_to_run, catalog, catalog_version,
205+
layer_id);
187206
}

olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/VersionedLayerClient.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ class VersionedLayerClientImpl;
7676
* client_settings.task_scheduler = std::move(task_scheduler);
7777
* client_settings.network_request_handler = std::move(http_client);
7878
*
79-
* VersionedLayerClient client{"hrn:here:data:::your-catalog-hrn", "your-layer-id", client_settings};
79+
* VersionedLayerClient client{"hrn:here:data:::your-catalog-hrn", "your-layer-id", "catalog-version", client_settings};
8080
* auto callback = [](olp::client::ApiResponse<olp::model::Data, olp::client::ApiError> response) {};
81-
* auto request = DataRequest().WithVersion(100).WithPartitionId("269");
81+
* auto request = DataRequest().WithPartitionId("269");
8282
* auto token = client.GetData(request, callback);
8383
* @endcode
8484
*

0 commit comments

Comments
 (0)