Create an application using the Data Client Base Library
Create an application using the Data Client Base Library
The Data Client Base Library allows you to create HERE platform data applications. The instructions below describe the process for a basic application using the Scala Build Tool (SBT) and Maven.
Access credentials
You need two types of credentials:
- HERE platform credentials -- To obtain your HERE platform credentials,
create a new application via the
https://platform.here.com/profile/apps-and-keys page. When you have created
your application, click Create A Key to download these credentials. Place
the credentials in
$HOME/.here/credentials.properties. - Repository Credentials -- To obtain your credentials to access the
repository containing the Data Client Base Library, go to
https://platform.here.com/profile/repository
and click Create credentials to download the
settings.xmlfile.
NoteFor detailed instructions on how to obtain your platform and repository credentials, see the Identity and Access Management Developer Guide.
Configure the build system
The following steps describe how to configure SBT and Maven projects.
For SBT, create a new file in ~/.ivy2/.credentials with the following content:
realm=Artifactory Realm
host=repo.platform.here.com
user=[REPOSITORY_USERNAME]
password=[REPOSITORY_PASSWORD]where [REPOSITORY_USERNAME] and [REPOSITORY_PASSWORD] are the username and
password from the downloaded settings.xml. You can find this information in
the servers/server[1] XML node.
For Maven, copy the downloaded settings.xml to ~/.m2.
Create a project
Create a new empty project directory with one of the following files:
build.sbt for SBT or pom.xml for Maven.
scalaVersion := "2.13.16"
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
resolvers += "HERE Repo" at "https://repo.platform.here.com/artifactory/open-location-platform/"
libraryDependencies ++= Seq(
"com.here.platform.data.client.base" %% "data-client-base" % "1.4.36"
)<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>my-data-sample</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.here.platform.data.client.base</groupId>
<artifactId>data-client-base_${scala.compat.version}</artifactId>
<version>1.4.36</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
</project>You have now completed your project configuration and can start using the Data Client Base Library.
The code example below shows a simple class that prints the HERE Resource Names (HRNs) for catalogs that you have access to in the HERE platform.
Add the file containing the class to the appropriate directory in src/main/scala or src/main/java, in
your project:
import com.here.platform.data.client.base.generated.codecs.JsonSupport._
import com.here.platform.data.client.base.generated.scaladsl.api.config.ConfigApi
import com.here.platform.data.client.base.generated.scaladsl.model.config.CatalogsResultBase
import com.here.platform.data.client.base.scaladsl.BaseClient
import scala.concurrent.Await
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.Duration
import scala.util.{Failure, Success}
object ScalaSimpleMain {
def main(args: Array[String]): Unit = {
val client = BaseClient()
val configApi = client.of[ConfigApi]
val result =
for {
catalogsListResult: CatalogsResultBase <- configApi
.getCatalogs(
verbose = Some(false),
organisationType = Nil,
layerType = Nil,
region = Nil,
resourceType = None,
coverage = Nil,
access = Nil,
marketplaceReady = None,
sortBy = None,
sortOrder = None
)
.executeToEntity()
} yield {
catalogsListResult
}
result
.andThen {
case Success(response) => println(s"response: $response")
case Failure(ex) => ex.printStackTrace()
}
Await.result(result, Duration.Inf)
}
}import com.here.platform.data.client.base.generated.javadsl.api.config.ConfigApi;
import com.here.platform.data.client.base.generated.scaladsl.model.config.CatalogsSummaryListResult;
import com.here.platform.data.client.base.javadsl.BaseClient;
import com.here.platform.data.client.base.javadsl.BaseClientJava;
import java.util.Collections;
import java.util.Optional;
public class JavaSimpleMain {
public static void main(String[] args) {
BaseClient baseClient = BaseClientJava.instance();
ConfigApi configApi = new ConfigApi(baseClient);
CatalogsSummaryListResult listResult =
(CatalogsSummaryListResult)
configApi
.getCatalogs(
Optional.of(false),
Optional.empty(),
Optional.empty(),
Collections.emptyList(),
Collections.emptyList(),
Collections.emptyList(),
Optional.empty(),
Optional.empty(),
Collections.emptyList(),
Collections.emptyList(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty())
.executeToEntity()
.toCompletableFuture()
.join();
System.out.println(listResult);
}
}Scala vs Java
The Data Client Base Library supports both Java and Scala bindings, many classes
have both javadsl and scaladsl implementations. If the class package does
not include a specific Domain Specific Language (DSL), this means that the class
package has getters and setters available for both Scala and Java.
Artifacts
libraryDependencies += "com.here.platform.data.client.base" % "{data-module}" % "1.4.36"<dependency>
<groupId>com.here.platform.data.client.base</groupId>
<artifactId>{data-module}</artifactId>
<version>1.4.36</version>
</dependency>dependencies {
compile group: 'com.here.platform.data.client.base', name: '{data-module}', version: '1.4.36'
}Updated 19 days ago