Class CogniteClient

java.lang.Object
com.cognite.client.CogniteClient
All Implemented Interfaces:
Serializable

public abstract class CogniteClient extends Object implements Serializable
This class represents the main entry point for interacting with this SDK (and Cognite Data Fusion). All services are exposed via this object.
See Also:
  • Field Details

    • LOG

      protected static final org.slf4j.Logger LOG
  • Constructor Details

    • CogniteClient

      public CogniteClient()
  • Method Details

    • ofToken

      public static CogniteClient ofToken(String cdfProject, Supplier<String> tokenSupplier)
      Returns a CogniteClient using the provided supplier (function) to provide a bearer token for authorization. The token will be placed into the request header: Authorization: <theToken> If your application handles the authentication flow itself, you can pass a Supplier to this constructor. The supplier will be called for each api request and the provided token will be added as a bearer token to the request header.
      Parameters:
      cdfProject - The CDF project to connect to.
      tokenSupplier - A Supplier (functional interface) producing a valid access token when called.
      Returns:
      the client object with default configuration.
    • ofAuthHeader

      public static CogniteClient ofAuthHeader(String cdfProject, String authHeaderKey, Supplier<String> tokenSupplier)
      Returns a CogniteClient using the provided supplier (function) to provide an auth token for authorization. The token will be placed into the request header at the specified authHeaderKey If your application handles the authentication flow itself, you can pass a header key and a Supplier to this constructor. The supplier will be called for each api request and the provided token will be added to the request header at the specified header key.

      This is a CogniteClient builder for advanced use cases where you need fine-grained control over authorization. Most users should use the ofClientCredentials(String, String, String, URL) or ofToken(String, Supplier) builders instead.

      Parameters:
      cdfProject - The CDF project to connect to.
      authHeaderKey - The header (key) to add the access token to.
      tokenSupplier - A Supplier (functional interface) producing a valid access token when called.
      Returns:
      the client object with default configuration.
    • ofClientCredentials

      public static CogniteClient ofClientCredentials(String cdfProject, String clientId, String clientSecret, URL tokenUrl, Collection<String> scopes)
      Returns a CogniteClient using client credentials for authentication. Client credentials is the preferred authentication pattern for services / machine to machine communication for Openid Connect (and Oauth) compatible identity providers.
      Parameters:
      cdfProject - The CDF project to connect to.
      clientId - The client id to use for authentication.
      clientSecret - The client secret to use for authentication.
      tokenUrl - The URL to call for obtaining the access token.
      scopes - The list of scopes to be used for authentication
      Returns:
      the client object with default configuration.
    • ofClientCredentials

      public static CogniteClient ofClientCredentials(String cdfProject, String clientId, String clientSecret, URL tokenUrl)
      Returns a CogniteClient using client credentials for authentication. Client credentials is the preferred authentication pattern for services / machine to machine communication for Openid Connect (and Oauth) compatible identity providers.
      Parameters:
      cdfProject - The CDF project to connect to.
      clientId - The client id to use for authentication.
      clientSecret - The client secret to use for authentication.
      tokenUrl - The URL to call for obtaining the access token.
      Returns:
      the client object with default configuration.
    • toBuilder

      protected abstract com.cognite.client.CogniteClient.Builder toBuilder()
    • getProject

      protected abstract String getProject()
    • getClientId

      @Nullable protected abstract String getClientId()
    • getClientSecret

      @Nullable protected abstract String getClientSecret()
    • getTokenUrl

      @Nullable protected abstract URL getTokenUrl()
    • getAuthScopes

      @Nullable protected abstract Collection<String> getAuthScopes()
    • getAuthTokenSupplier

      @Nullable protected abstract Supplier<String> getAuthTokenSupplier()
    • getAuthHeaderKey

      @Nullable protected abstract String getAuthHeaderKey()
    • getAuthType

      protected abstract CogniteClient.AuthType getAuthType()
    • getBaseUrl

      protected abstract String getBaseUrl()
    • getClientConfig

      public abstract ClientConfig getClientConfig()
    • getHttpClient

      public abstract okhttp3.OkHttpClient getHttpClient()
    • getExecutorService

      public ExecutorService getExecutorService()
    • getTsExecutorService

      public ExecutorService getTsExecutorService()
    • withProject

      public CogniteClient withProject(String project)
      Returns a CogniteClient using the specified Cognite Data Fusion project / tenant.
      Parameters:
      project - The project / tenant to use for interacting with Cognite Data Fusion.
      Returns:
      the client object with the project / tenant key set.
    • withBaseUrl

      public CogniteClient withBaseUrl(String baseUrl)
      Returns a CogniteClient using the specified base URL for issuing API requests. The base URL must follow the format https://<my-host>.cognitedata.com, with an optional trailing slash. The default base URL is https://api.cognitedata.com
      Parameters:
      baseUrl - The CDF api base URL
      Returns:
      the client object with the base URL set.
    • withScopes

      public CogniteClient withScopes(Collection<String> scopes)
      Returns a CogniteClient using the specified list of scopes for issuing API requests.
      Parameters:
      scopes - The collection of scopes to be used for OAuth2.0 authentication
      Returns:
      the client object with the authentication handler configured
    • withClientConfig

      public CogniteClient withClientConfig(ClientConfig config)
      Returns a CogniteClient using the specified configuration settings.
      Parameters:
      config - The ClientConfig hosting the client configuration setting.
      Returns:
      the client object with the config applied.
    • enableHttp

      public CogniteClient enableHttp(boolean enable)
      Enable (or disable) support for http. Set to true to enable support for http calls. Set to false to disable support for http (then only https will be possible). The default setting is disabled. I.e. only https calls are allowed.
      Parameters:
      enable - Set to true to enable support for http calls. Set to false to disable support for http.
      Returns:
      the client object with the config applied.
    • assets

      public Assets assets()
      Returns Assets representing the Cognite assets api endpoint.
      Returns:
      The assets api object.
    • timeseries

      public Timeseries timeseries()
      Returns Timeseries representing the Cognite timeseries api endpoint.
      Returns:
      The timeseries api object.
    • events

      public Events events()
      Returns Events representing the Cognite events api endpoint.
      Returns:
      The events api object.
    • files

      public Files files()
      Returns Files representing the Cognite files api endpoints.
      Returns:
      The labels api endpoint.
    • relationships

      public Relationships relationships()
      Returns Relationships representing the Cognite relationships api endpoint.
      Returns:
      The relationships api object.
    • sequences

      public Sequences sequences()
      Returns Sequences representing the Cognite sequences api endpoint.
      Returns:
      The sequences api object.
    • raw

      public Raw raw()
      Returns Raw representing the Cognite Raw service.
      Returns:
      The raw api object.
    • labels

      public Labels labels()
      Returns Labels representing the Cognite labels api endpoints.
      Returns:
      The labels api endpoint.
    • datasets

      public Datasets datasets()
      Returns Datasets representing the Cognite dats sets api endpoint.
      Returns:
      The data sets api object.
    • extractionPipelines

      public ExtractionPipelines extractionPipelines()
      Returns ExtractionPipelines representing the Cognite extraction pipelines api endpoint.
      Returns:
      The extraction pipelines api object.
    • securityCategories

      public SecurityCategories securityCategories()
      Returns SecurityCategories representing the Cognite labels api endpoints.
      Returns:
      The security categories api endpoint.
    • contextualization

      public Contextualization contextualization()
      Returns Contextualization representing the Cognite contextualization api endpoints.
      Returns:
      The contextualization api endpoint.
    • experimental

      public Experimental experimental()
      Returns Experimental representing experimental (non-released) api endpoints.
      Returns:
      The Experimental api endpoints.
    • threeD

      public ThreeD threeD()
      Returns ThreeD representing 3D api endpoints.
      Returns:
      The ThreeD api endpoints.
    • transformations

      public Transformations transformations()
      Returns Transformations representing Transformation api endpoints.
      Returns:
      The Transformation api endpoints.
    • getConnectorService

      protected ConnectorServiceV1 getConnectorService()
      Returns the services layer mirroring the Cognite Data Fusion API.
      Returns:
    • buildAuthConfig

      protected AuthConfig buildAuthConfig() throws Exception
      Returns a auth info for api requests
      Returns:
      project config with auth info populated
      Throws:
      Exception