Get data from a versioned layer

You can request any data version from a versioned layer. When you request a particular version of data from the versioned layer, the partition you receive in the response may have a lower version number than you requested. The version of a layer or partition represents the catalog version in which the layer or partition was last updated.

To get data from the versioned layer:

  1. Create the OlpClientSettings object.

    For instructions, see Create platform client settings.

  2. Create the VersionedLayerClient object with the HERE Resource Name (HRN) of the catalog that contains the layer, the layer ID, catalog version, and the platform client settings from step 1.

    If you do not specify a catalog version, the latest version is used. Depending on the fetch option that you specified in your first API call to the client, the GetLatestVersion method automatically gets the latest version in one of the following ways:

    • For the OnlineIfNotFound fetch option, queries the network, and if an error occurs, checks the cache. If the online version is higher than the cache version, the cache version is updated.
    • For the OnlineOnly fetch option, only queries the network.
    • For the CacheOnly fetch option, only checks the cache.
    olp::dataservice::read::VersionedLayerClient layer_client (
                        client::HRN catalog,
                        std::string layer_id,
                        boost::optional<int64_t> catalog_version,
                        client::OlpClientSettings settings);
    
  3. Create the DataRequest object with the partition ID and one of the following fetch options:

    • (Default) To query the network if the requested resource is not found in the cache, use OnlineIfNotFound.
    • To skip cache lookups and query the network right away, use OnlineOnly.
    • To return immediately if a cache lookup fails, use CacheOnly.
    auto request = olp::dataservice::read::DataRequest()
                       .WithPartitionId(partition_id)
                       .WithBillingTag("MyBillingTag")
                       .WithFetchOption(FetchOptions::OnlineIfNotFound);
    
  4. Call the GetRequest method with the DataRequest parameter.

    auto future = layer_client.GetData(request);
    
  5. Wait for the DataResponse future.

    olp::dataservice::read::DataResponse data_response =
    future.GetFuture().get();
    

The DataResponse object holds details of the completed operation and is used to determine operation success and access resultant data:

  • IsSuccessful() – if the operation is successful, returns true. Otherwise, returns false.
  • GetResult()– if the operation is successful, returns the following resultant data: olp::dataservice::read::DataResult
  • GetError() – contains error information as a result of an error in the olp::client::ApiError object.
if (data_response.IsSuccessful()) {
    auto response_result = data_response.GetResult();
    // Handle success
} else {
    auto api_error = data_response.GetError();
    // Handle fail
}

results matching ""

    No results matching ""