Verify your credentials and access a catalog
Objectives: Verify that you set up the platform credentials and the Maven settings correctly, and introduce the concepts of HRN, Catalogs, Layers, and Metadata.
Complexity: Beginner
Time to complete: 20 min
Prerequisites: Verify Maven Settings
Source code: Download
This section demonstrates how to write a program that queries catalog information from the HERE Map Content data catalog (hrn: hrn:here:data::olp-here:rib-2
).
After running this example successfully, you can be assured that your repository credentials and the platform credentials are set up correctly.
You can create this project in the verify-credentials
folder, using the same structure and pom from the previous tutorial.
The following dependencies are needed for this example:
<dependencies>
<dependency>
<groupId>com.here.platform.data.client</groupId>
<artifactId>data-client_${scala.compat.version}</artifactId>
</dependency>
</dependencies>
To gather some metadata about a catalog, create some code in Scala or Java in the source folder.
If you have not generated your repository settings or platform credentials yet, see Get Credentials. After you have followed these instructions, you should have both a settings.xml
with repository credentials, and a credentials.properties
with platform credentials.
The program queries the HERE Map Content catalog (the catalog with all the traditional HERE map data) to get the latest available version, and some metadata associated with the catalog such as issue date, available layers, and the list of direct dependencies with the input catalogs you used to create this catalog).
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();
}
}
You can now run your code either using your IDE, or from the command line using mvn
:
mvn compile exec:java -Dexec.mainClass=CatalogInfoScala
mvn compile exec:java -Dexec.mainClass=CatalogInfoJava
The expected output should look like this, with the confirmation that your code was successful in fetching the token:
[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
The output lists the input catalog HRNs, together with their respective versions.
The Data Client Library is a complete API for accessing the Data Service. You can use this API to query the catalog metadata (versions, layers, partitions inside the layers) and data (actual partition payload). For more details, see Data Client Library Developer Guide.
The Data Client Library documentation covers more detailed workflows such as how to introspect more metadata fields, fetching data from partitions, and examining content changes between versions.
The following sections explain how to create your own catalog and layers and explore the available layer types and configurations:
Once you have verified your platform credentials to access the HERE Map Content, you can implement a simple batch pipeline to process catalog data in Spark.