資格情報 を確認し、カタログにアクセスします
目的: プラットフォーム資格情報と 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 が含まれているカタログ ) に問い合わせて、利用可能な最新バージョンを取得します。また、発行日、利用可能なレイヤーなど、カタログに関連付けられている一部のメタデータも取得します。 このカタログの作成に使用した入力カタログとの直接の依存関係のリストを参照してください)。
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 {
implicit lazy val actorSystem = ActorSystem()
private val hereMapContentHrn = HRN("hrn:here:data::olp-here:rib-2")
val queryApi = DataClient().queryApi(hereMapContentHrn)
val latestVersion = Await.result(queryApi.getLatestVersion(), 30 seconds)
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")
}
val shutdown = CoordinatedShutdown(actorSystem).run(UnknownReason)
Await.result(shutdown, Duration.Inf)
}
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) {
ActorSystem actorSystem = ActorSystem.create();
HRN hereMapContentHrn = HRN.fromString("hrn:here:data::olp-here:rib-2");
QueryApi queryApi = DataClient.get(actorSystem).queryApi(hereMapContentHrn);
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();
CoordinatedShutdown.get(actorSystem)
.runAll(CoordinatedShutdown.unknownReason())
.toCompletableFuture()
.join();
}
}
IDE を使用するか、または次のコマンドを使用してコマンド ラインからコードを実行できるようになりまし mvn
た。
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 でカタログデータを処理できます。