olp-cpp-sdk 1.24.0
Loading...
Searching...
No Matches
DataRequest.h
1/*
2 * Copyright (C) 2019-2020 HERE Europe B.V.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * SPDX-License-Identifier: Apache-2.0
17 * License-Filename: LICENSE
18 */
19
20#pragma once
21
22#include <sstream>
23#include <string>
24#include <utility>
25
26#include <olp/core/porting/optional.h>
27#include <olp/core/thread/TaskScheduler.h>
28#include <olp/dataservice/read/DataServiceReadApi.h>
29#include <olp/dataservice/read/FetchOptions.h>
30
31namespace olp {
32namespace dataservice {
33namespace read {
34
43class DATASERVICE_READ_API DataRequest final {
44 public:
50 const porting::optional<std::string>& GetPartitionId() const {
51 return partition_id_;
52 }
53
64 template <class T = porting::optional<std::string>>
65 DataRequest& WithPartitionId(T&& partition_id) {
66 partition_id_ = std::forward<T>(partition_id);
67 return *this;
68 }
69
81 const porting::optional<std::string>& GetDataHandle() const {
82 return data_handle_;
83 }
84
97 template <class T = porting::optional<std::string>>
98 DataRequest& WithDataHandle(T&& data_handle) {
99 data_handle_ = std::forward<T>(data_handle);
100 return *this;
101 }
102
113 const porting::optional<std::string>& GetBillingTag() const {
114 return billing_tag_;
115 }
116
126 template <class T = porting::optional<std::string>>
128 billing_tag_ = std::forward<T>(tag);
129 return *this;
130 }
131
140 FetchOptions GetFetchOption() const { return fetch_option_; }
141
152 DataRequest& WithFetchOption(FetchOptions fetch_option) {
153 fetch_option_ = fetch_option;
154 return *this;
155 }
156
164 uint32_t GetPriority() const { return priority_; }
165
173 DataRequest& WithPriority(uint32_t priority) {
174 priority_ = priority;
175 return *this;
176 }
177
186 std::string CreateKey(const std::string& layer_id,
187 porting::optional<int64_t> version) const {
188 std::stringstream out;
189 out << layer_id << "[";
190 if (GetPartitionId()) {
191 out << *GetPartitionId();
192 } else if (GetDataHandle()) {
193 out << *GetDataHandle();
194 }
195 out << "]";
196 if (version) {
197 out << "@" << *version;
198 }
199 if (GetBillingTag()) {
200 out << "$" << *GetBillingTag();
201 }
202 out << "^" << GetFetchOption();
203 return out.str();
204 }
205
206 private:
207 porting::optional<std::string> partition_id_;
208 porting::optional<int64_t> catalog_version_;
209 porting::optional<std::string> data_handle_;
210 porting::optional<std::string> billing_tag_;
211 FetchOptions fetch_option_{OnlineIfNotFound};
212 uint32_t priority_{thread::NORMAL};
213};
214
215} // namespace read
216} // namespace dataservice
217} // namespace olp
Encapsulates the fields required to request data for the given catalog, layer, and partition.
Definition DataRequest.h:43
DataRequest & WithPartitionId(T &&partition_id)
Sets the partition ID.
Definition DataRequest.h:65
std::string CreateKey(const std::string &layer_id, porting::optional< int64_t > version) const
Creates a readable format for the request.
Definition DataRequest.h:186
FetchOptions GetFetchOption() const
Gets the fetch option that controls how requests are handled.
Definition DataRequest.h:140
const porting::optional< std::string > & GetBillingTag() const
Gets the billing tag to group billing records together.
Definition DataRequest.h:113
DataRequest & WithFetchOption(FetchOptions fetch_option)
Sets the fetch option that you can use to set the source from which data should be fetched.
Definition DataRequest.h:152
const porting::optional< std::string > & GetDataHandle() const
Get the partition data handle.
Definition DataRequest.h:81
DataRequest & WithDataHandle(T &&data_handle)
Sets the partition data handle.
Definition DataRequest.h:98
DataRequest & WithBillingTag(T &&tag)
Sets the billing tag for the request.
Definition DataRequest.h:127
uint32_t GetPriority() const
Gets the request priority.
Definition DataRequest.h:164
const porting::optional< std::string > & GetPartitionId() const
Gets the ID of the requested partition.
Definition DataRequest.h:50
DataRequest & WithPriority(uint32_t priority)
Sets the priority of the request.
Definition DataRequest.h:173
Rules all the other namespaces.
Definition AppleSignInProperties.h:24