資格情報 を確認し、カタログにアクセスします

目的: プラットフォーム資格情報と Maven の設定が正しく設定されていることを確認し、 HERE リソースネーム 、カタログ、レイヤー、およびメタデータの概念を紹介します。

複雑さ: 初心者向け

所要時間: 20 分

前提条件: Maven 設定を確認します

ソースコード: ダウンロード

このセクションでは 、 HERE Map Content データカタログ( HERE リソースネーム : hrn:here:data::olp-here:rib-2)からカタログ情報を照会するプログラムを作成する方法について説明します。

この例を正常に実行すると 、リポジトリの資格情報プラットフォーム資格情報 が正しく設定されていることを確認できます。

このプロジェクトは、前のチュートリアルと同じ構造と pom を使用して、verify-credentialsフォルダーに作成できます。

この例では、次の依存関係が必要です。

<dependencies>
    <dependency>
        <groupId>com.here.platform.data.client</groupId>
        <artifactId>data-client_${scala.compat.version}</artifactId>
    </dependency>
</dependencies>

カタログについてのメタデータを収集するには、ソースフォルダーの Scala または Java でコードを作成します。

リポジトリ設定またはプラットフォーム資格情報をまだ生成していない場合 は、「資格情報の取得」を参照してください。 これらの手順を実行した後は、リポジトリが資格情報の settings.xml とプラットフォーム資格情報の credentials.properties のの両方を使用する必要があります。

プログラムは、 HERE Map Content カタログ ( 従来のすべての HERE Map Data が含まれているカタログ ) に問い合わせて、利用可能な最新バージョンを取得します。また、発行日、利用可能なレイヤーなど、カタログに関連付けられている一部のメタデータも取得します。 このカタログの作成に使用した入力カタログとの直接の依存関係のリストを参照してください)。

Scala
Java
/*
 * Copyright (c) 2018-2023 HERE Europe B.V.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import akka.actor.CoordinatedShutdown.UnknownReason
import akka.actor.{ActorSystem, CoordinatedShutdown}
import com.here.hrn.HRN
import com.here.platform.data.client.scaladsl.DataClient

import scala.concurrent._
import scala.concurrent.duration._

object CatalogInfoScala extends App {

  // Initialize the Akka Actor System used by the Data Client Library
  implicit lazy val actorSystem = ActorSystem()

  // The Here Map Content identifier is an HRN (Here Resource Name)
  // Please, use hrn:here-cn:data::olp-cn-here:here-map-content-china-2 for China environment
  private val hereMapContentHrn = HRN("hrn:here:data::olp-here:rib-2")

  // Initialize the query API for the catalog
  val queryApi = DataClient().queryApi(hereMapContentHrn)

  // Get the latest available catalog version
  val latestVersion = Await.result(queryApi.getLatestVersion(), 30 seconds)

  // Retrieve more metadata for the version, if any
  latestVersion match {
    case Some(version) =>
      println(s"The latest Here Map Content version is $version")
      val latestVersionInfo = Await.result(queryApi.getVersion(version), 30 seconds)
      println(s"The catalog was last updated on ${new java.util.Date(latestVersionInfo.timestamp)}")

      println("And was reportedly compiled out of these input catalogs:")
      latestVersionInfo.dependencies.filter(_.direct).foreach { dependency =>
        println(s"  ${dependency.hrn} ${dependency.version}")
      }

    case None =>
      println("No version for this catalog")
  }

  // In production code this would be in a finally block
  val shutdown = CoordinatedShutdown(actorSystem).run(UnknownReason)
  Await.result(shutdown, Duration.Inf)
}

/*
 * Copyright (c) 2018-2023 HERE Europe B.V.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import static java.lang.System.out;

import akka.actor.ActorSystem;
import akka.actor.CoordinatedShutdown;
import com.here.hrn.HRN;
import com.here.platform.data.client.javadsl.DataClient;
import com.here.platform.data.client.javadsl.QueryApi;
import com.here.platform.data.client.model.VersionDependency;
import java.util.OptionalLong;

public class CatalogInfoJava {

  public static void main(String[] args) {

    // Initialize the Akka Actor System used by the Data Client Library
    ActorSystem actorSystem = ActorSystem.create();

    // The Here Map Content identifier is an HRN (Here Resource Name)
    // Please, use hrn:here-cn:data::olp-cn-here:here-map-content-china-2 for China environment
    HRN hereMapContentHrn = HRN.fromString("hrn:here:data::olp-here:rib-2");

    // Initialize the query API for the catalog
    QueryApi queryApi = DataClient.get(actorSystem).queryApi(hereMapContentHrn);

    // Get the latest available catalog version
    queryApi
        .getLatestVersion(OptionalLong.empty())
        .thenAccept(
            version -> {
              if (version.isPresent()) {
                out.println("The latest Here Map Content version is " + version.getAsLong());
                queryApi
                    .getVersion(version.getAsLong())
                    .thenAccept(
                        versionInfo -> {
                          out.println(
                              "The catalog was last updated on "
                                  + new java.util.Date(versionInfo.getTimestamp()));
                          out.println("And was reportedly compiled out of these input catalogs:");
                          versionInfo
                              .getDependencies()
                              .stream()
                              .filter(VersionDependency::isDirect)
                              .forEach(
                                  dependency ->
                                      out.println(
                                          "  "
                                              + dependency.getHrn()
                                              + " "
                                              + dependency.getVersion()));
                        })
                    .toCompletableFuture()
                    .join();
              } else {
                out.println("No version for this catalog");
              }
            })
        .toCompletableFuture()
        .join();

    // In production code this would be in a finally block
    CoordinatedShutdown.get(actorSystem)
        .runAll(CoordinatedShutdown.unknownReason())
        .toCompletableFuture()
        .join();
  }
}

IDE を使用するか、または次のコマンドを使用してコマンド ラインからコードを実行できるようになりまし mvnた。

Scala を実行します
Java を実行します
mvn compile exec:java -Dexec.mainClass=CatalogInfoScala
mvn compile exec:java -Dexec.mainClass=CatalogInfoJava

予期される出力は次のようになります。コードがトークンの取得に成功したことを示す確認メッセージが表示されます。

[INFO] [...] [CatalogInfoJava.main()] [DataClientSettingsExt] Reading credentials from default credentials file XXXX
[INFO] [...] [default-akka.actor.default-dispatcher-5] [HereAccountProvider] OAuth token fetched successfully with expiration of 86399s, next refresh scheduled in 57599s.
The latest Here Map Content version is 32
The catalog was last updated on Sat May 26 10:14:24 CEST 2018
And was reportedly compiled out of these input catalogs:
  hrn:here:data::olp-here:tailgate-2 28
  hrn:here:datastore::olp-here:os-rib-address-global-1 221
  hrn:here:datastore::olp-here:os-rib-carto-global-1 222
  hrn:here:datastore::olp-here:os-rib-street-global-1 217

出力には、入力カタログ HRNS とそれぞれのバージョンが一覧表示されます。

詳細情報

データ クライアント ライブラリは、データサービスにアクセスするための完全な API です。 この API を使用して、カタログメタデータ ( バージョン、レイヤー、レイヤー内のパーティション ) およびデータ ( 実際のパーティションペイロード ) をクエリできます。 詳細については 、データ クライアント ライブラリ開発者ガイドを参照してください。

データ クライアント ライブラリのドキュメントでは、より詳細なワークフローについて説明しています。たとえば、より多くのメタデータフィールドをイントロスペクトする方法、パーティションからデータを取得する方法、バージョン間のコンテンツの変更を確認する方法などがあります。

次のセクションでは、独自のカタログおよびレイヤーを作成し、使用可能なレイヤータイプおよび構成を探索する方法について説明します。

プラットフォーム資格情報が HERE Map Content にアクセスできることを確認したら 、簡単なバッチ パイプラインを実装して Spark でカタログデータを処理できます。

」に一致する結果は 件です

    」に一致する結果はありません