Skip to content

Commit f981e91

Browse files
authored
サーバーのURLとBearer認証トークンを設定できるようにしました。サーバー仕様変更に対応。 (Synesthesias#144)
* APIのエンドポイントを変更 * 同上 * サーバーから受け取るmaxLodの値を文字列型から数値型にした。 * sdk/datasetsのmaxLod削除 * GmlFile::FetchでClientを指定できるように対応(C++サイド) * GmlFile::Fetchでclientを指定できるように対応(C#サイド) * デフォルトトークン取得 * トークン指定 * コード整理 * サーバートークン * サーバーに関するコメント変更 * 同上 * デフォルトURLはC#からアクセスしないようにした。 * デフォルトURL・トークンの取得を無名関数に
1 parent 0a53645 commit f981e91

25 files changed

+222
-114
lines changed

examples/https_mock_test/https_mock_test.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#include <plateau/network/client.h>
22

33
int main(void) {
4-
plateau::network::Client client;
5-
6-
client.setApiServerUrl(plateau::network::Client::getDefaultServerUrl());
4+
const auto client = plateau::network::Client::createClientForMockServer();
75

86
// check Client::getMetadata
97
auto meta_data_ptr = client.getMetadata();
@@ -17,14 +15,13 @@ int main(void) {
1715
std::cout << " id : " << meta_data[i].datasets[j].id << std::endl;
1816
std::cout << " title : " << meta_data[i].datasets[j].title << std::endl;
1917
std::cout << " description : " << meta_data[i].datasets[j].description << std::endl;
20-
std::cout << " max_lod : " << meta_data[i].datasets[j].max_lod << std::endl;
2118
std::cout << " feature_types : ";
2219
for(int k = 0; k < meta_data[i].datasets[j].feature_types.size(); k++) std::cout << meta_data[i].datasets[j].feature_types[k] << " ,";
2320
std::cout << std::endl;
2421
}
2522
}
2623

2724
// check Client::download
28-
auto fpath = client.download(".", plateau::network::Client::getDefaultServerUrl() + "/13100_tokyo23-ku_2020_citygml_3_2_op/udx/bldg/53392642_bldg_6697_2_op.gml");
25+
auto fpath = client.download(".", plateau::network::Client::getMockServerUrl() + "/13100_tokyo23-ku_2020_citygml_3_2_op/udx/bldg/53392642_bldg_6697_2_op.gml");
2926
std::cout << "gml @ " << fpath << std::endl;
3027
}

include/plateau/dataset/dataset_source.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ namespace plateau::network {
1010
namespace plateau::dataset {
1111
/**
1212
* PLATEAUデータ一式を表現したクラスです。
13-
* 保持している IDatasetAccessor によってGMLファイルの検索ができます
13+
* 保持している IDatasetAccessor によってGMLファイルの検索・取得ができます
1414
* データの場所が ローカルPCか APIサーバーかは DatasetSource の作成時にはっきりさせたいので、
1515
* デフォルトコンストラクタの代わりに createLocal または createServer を利用してください。
1616
* 表記例: new DatasetSource(DatasetSource::createServer("23ku"));
17+
*
18+
* 他クラスとの関係:
19+
* DatasetSource -> (保持) -> IDatasetAccessor (すなわち ServerDatasetAccessor または LocalDatasetAccessor)
1720
*/
1821
class LIBPLATEAU_EXPORT DatasetSource {
1922
public:

include/plateau/dataset/gml_file.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <libplateau_api.h>
44
#include <plateau/dataset/mesh_code.h>
55
#include <set>
6+
#include <optional>
67
#include "plateau/network/client.h"
78

89
namespace plateau::dataset {
@@ -13,7 +14,7 @@ namespace plateau::dataset {
1314
class LIBPLATEAU_EXPORT GmlFile {
1415
public:
1516
explicit GmlFile(const std::string& path);
16-
explicit GmlFile(const std::string& path, const int max_lod);
17+
GmlFile(const std::string& path, const network::Client& client, int max_lod = -1);
1718

1819

1920
const std::string& getPath() const;
@@ -64,6 +65,9 @@ namespace plateau::dataset {
6465
bool is_local_;
6566
int max_lod_;
6667

68+
/// サーバーモード(is_local_ が falseのとき)のみ利用します。ダウンロードに使用するクライアントです。
69+
std::optional<network::Client> client_;
70+
6771
void applyPath();
6872
};
6973
}

include/plateau/network/client.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ namespace plateau::network {
1212
std::string id;
1313
std::string title;
1414
std::string description;
15-
int max_lod = 0;
1615
std::vector<std::string> feature_types;
1716
};
1817

@@ -46,18 +45,35 @@ namespace plateau::network {
4645
*/
4746
class LIBPLATEAU_EXPORT Client {
4847
public:
49-
explicit Client(const std::string& server_url = "");
48+
/**
49+
* @param server_url 接続先のURLです。空文字の場合、デフォルトのものを利用します。
50+
* @param api_token 接続時のBearer認証トークンです。空文字の場合、デフォルトのものを利用します。
51+
*/
52+
Client(const std::string& server_url, const std::string& api_token);
53+
54+
static Client createClientForMockServer();
5055

5156
std::string getApiServerUrl() const;
5257
void setApiServerUrl(const std::string& url);
58+
void setApiToken(const std::string& api_token);
5359
std::shared_ptr<std::vector<DatasetMetadataGroup>> getMetadata() const;
5460
void getMetadata(std::vector<DatasetMetadataGroup>& out_metadata_groups) const;
61+
62+
/**
63+
* @brief サーバーから json を受け取り、それをパースしてデータファイルに関する情報を得ます。
64+
* 受け取る json の例 : https://plateau-api-mock-v2.deta.dev/sdk/datasets/23ku/files
65+
*/
5566
DatasetFiles getFiles(const std::string& id) const;
5667
std::string download(const std::string& destination_directory_path, const std::string& url) const;
5768

58-
static const std::string& getDefaultServerUrl();
69+
/// 開発用に用意したモックサーバーのURLです。
70+
static const std::string& getMockServerUrl();
5971

6072
private:
6173
std::string server_url_;
74+
std::string api_token_;
75+
76+
static std::string endPointUrlForMetadataGroups() { return "/sdk/datasets"; }
77+
static std::string endPointUrlForFiles(const std::string& id) { return "/sdk/datasets/" + id + "/files"; }
6278
};
6379
}

src/c_wrapper/client_c.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@ extern "C" {
55
using namespace plateau::network;
66
using namespace libplateau;
77

8-
DLL_CREATE_FUNC(plateau_create_client,
9-
Client)
8+
DLL_3_ARG_FUNC(plateau_create_client,
9+
const Client** const out_client_ptr,
10+
const char* const server_url,
11+
const char* const api_token,
12+
*out_client_ptr = new Client(server_url, api_token))
13+
14+
DLL_1_ARG_FUNC(plateau_create_client_for_mock_server,
15+
const Client** const out_client_ptr,
16+
*out_client_ptr = new Client(Client::createClientForMockServer()))
1017

1118
DLL_DELETE_FUNC(plateau_delete_client,
1219
Client)
@@ -32,7 +39,8 @@ DLL_4_ARG_FUNC(plateau_client_download,
3239
std::string* const out_downloaded_path,
3340
*out_downloaded_path = client->download(destination_directory, url) )
3441

35-
DLL_1_ARG_FUNC(plateau_client_get_default_url,
36-
std::string* out_default_url,
37-
*out_default_url = Client::getDefaultServerUrl())
42+
43+
DLL_1_ARG_FUNC(plateau_client_get_mock_server_url,
44+
std::string* out_mock_server_url,
45+
*out_mock_server_url = Client::getMockServerUrl())
3846
}

src/c_wrapper/dataset_metadata_c.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ DLL_STRING_PTR_FUNC(plateau_dataset_metadata_get_description,
2323
DatasetMetadata,
2424
handle->description)
2525

26-
DLL_VALUE_FUNC(plateau_dataset_metadata_get_max_lod,
27-
DatasetMetadata,
28-
int,
29-
handle->max_lod)
30-
3126
DLL_2_ARG_FUNC(plateau_dataset_metadata_get_feature_types,
3227
const DatasetMetadata* const meta_data,
3328
std::vector<std::string>* const feature_types,

src/dataset/gml_file.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ namespace plateau::dataset {
2727

2828
GmlFile::GmlFile(const std::string& path) // NOLINT
2929
: path_(path), is_valid_(false), is_local_(true), max_lod_(-1) {
30+
// 上の行の is_valid_ と is_local_ の設定は一時的なもので、すぐ applyPath() によって書き換えられます。
3031
applyPath();
3132
}
3233

33-
GmlFile::GmlFile(const std::string& path, const int max_lod) // NOLINT
34-
: path_(path), is_valid_(false), is_local_(true), max_lod_(max_lod) {
35-
applyPath();
34+
/// サーバーモードで使うコンストラクタです。GMLファイルのダウンロードに使う Client を指定します。
35+
GmlFile::GmlFile(const std::string& path, const network::Client& client, int max_lod)
36+
: GmlFile(path){
37+
client_ = client;
38+
max_lod_ = max_lod;
3639
}
3740

3841
const std::string& GmlFile::getPath() const {
@@ -281,10 +284,9 @@ namespace plateau::dataset {
281284
}
282285

283286
void fetchServer(const fs::path& gml_file_path, const fs::path& gml_relative_path_from_udx, const fs::path& destination_udx_path,
284-
const fs::path& gml_destination_path, GmlFile& copied_gml_file) {
287+
const fs::path& gml_destination_path, GmlFile& copied_gml_file, const network::Client& client) {
285288
auto destination_dir = gml_destination_path.parent_path();
286289
// gmlファイルをダウンロードします。
287-
auto client = Client();
288290
client.download(destination_dir.u8string(), gml_file_path.u8string());
289291
auto downloaded_path = destination_dir;
290292
downloaded_path /= gml_file_path.filename();
@@ -330,11 +332,16 @@ namespace plateau::dataset {
330332
prepareFetch(fs::u8path(getPath()), fs::u8path(destination_root_path), gml_relative_path_from_udx, destination_udx_path,
331333
gml_destination_path);
332334
if (is_local_) {
335+
// ローカルモード
333336
fetchLocal(fs::u8path(path_), gml_relative_path_from_udx, destination_udx_path, gml_destination_path,
334337
copied_gml_file);
335338
} else {
339+
// サーバーモード
340+
if (!client_.has_value()) {
341+
throw std::runtime_error("Client is nullopt.");
342+
}
336343
fetchServer(fs::u8path(path_), gml_relative_path_from_udx, destination_udx_path, gml_destination_path,
337-
copied_gml_file);
344+
copied_gml_file, client_.value());
338345
}
339346
}
340347

src/dataset/local_dataset_accessor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace plateau::dataset {
77
/**
88
* \brief ローカルPCに存在するPLATEAUの3D都市モデルデータ製品へのアクセスを提供します。
9+
* 他クラスとの関係については、 DatasetSource のコメントを参照してください。
910
*/
1011
class LIBPLATEAU_EXPORT LocalDatasetAccessor : public IDatasetAccessor {
1112
public:

src/dataset/server_dataset_accessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace plateau::dataset {
4444
for (const auto& [sub_folder, gml_files] : dataset_files_) {
4545
if (UdxSubFolder::getPackage(sub_folder) == package) {
4646
for (const auto& dataset_file : gml_files) {
47-
out_gml_files.emplace_back(dataset_file.url, dataset_file.max_lod);
47+
out_gml_files.emplace_back(dataset_file.url, client_, dataset_file.max_lod);
4848
}
4949
}
5050
}

src/dataset/server_dataset_accessor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace plateau::dataset {
77
/**
88
* \brief サーバー上のPLATEAUデータセットに対して、データの検索等を行います。
9+
* 他クラスとの関係 については DatasetSource のコメントを参照してください。
910
*/
1011
class LIBPLATEAU_EXPORT ServerDatasetAccessor : public IDatasetAccessor {
1112
public:

0 commit comments

Comments
 (0)