Class Request

  • All Implemented Interfaces:
    Serializable

    public abstract class Request
    extends Object
    implements Serializable
    This class represents the Cognite Data Fusion API request parameters. The available parameters depend on which API endpoint you are working towards. The parameters mirrors what is available in the api. For example, which filters you can use. Please refer to the Cognite API documentation https://docs.cognite.com/api/v1/ for reference.
    See Also:
    Cognite API v1 specification, Serialized Form
    • Constructor Detail

      • Request

        public Request()
    • Method Detail

      • create

        public static Request create()
      • getRequestParameters

        public abstract com.google.common.collect.ImmutableMap<String,​Object> getRequestParameters()
        Returns the object representation of the composite request body. It is similar to the Cognite API Json request body, with Map<String, Object> as the Json container, List as the Json array.
        Returns:
      • getProtoRequestBody

        @Nullable
        public abstract com.google.protobuf.Message getProtoRequestBody()
        For internal use only. Returns the protobuf request body.
        Returns:
      • getAuthConfig

        @Nullable
        public abstract AuthConfig getAuthConfig()
        Returns the project configuration for a request. The configuration includes host (optional), project/tenant and key.
        Returns:
      • withRequestParameters

        public Request withRequestParameters​(Map<String,​Object> requestParameters)
        Adds the complete request parameter structure based on Java objects. Calling this method will overwrite any previously added parameters. - All keys must be String. - Values can be primitives or containers - Valid primitives are String, Integer, Double, Float, Long, Boolean. - Valid containers are Map (Json Object) and List (Json array).

        Example:

         
             Request.create().withRequestParameters(ImmutableMap.of("limit", 2))
         
         
        Parameters:
        requestParameters -
        Returns:
        The request object with the parameter applied.
        See Also:
        Request, create()
      • withProtoRequestBody

        public Request withProtoRequestBody​(com.google.protobuf.Message requestBody)
        Adds the complete request body as a protobuf object.

        Example:

         
             Message requestBody;
             Request.create().withProtoRequestBody(requestBody);
         
         
        Parameters:
        requestBody -
        Returns:
        The request object with the parameter applied.
        See Also:
        Message, Request, create()
      • withRequestJson

        public Request withRequestJson​(String value)
                                throws Exception
        Adds the complete request parameter structure based on Json. Calling this method will overwrite any previously added parameters.

        Example:

         
             String value = //Object json string;
             Request parameters = Request.create()
                         .withRequestJson(value);
         
         
        Parameters:
        value -
        Returns:
        The request object with the parameter applied.
        Throws:
        Exception
        See Also:
        Request, create()
      • withRootParameter

        public Request withRootParameter​(String key,
                                         Object value)
        Adds a new parameter to the root level.

        Example:

         
             Object object;
             Request parameters = Request.create()
                         .withRootParameter("key",object);
         
         
        Parameters:
        key -
        value -
        Returns:
        The request object with the parameter applied.
        See Also:
        Request, create()
      • withFilterParameter

        public Request withFilterParameter​(String key,
                                           Object value)
        Adds a new parameter to the filter node.

        Example:

         
             Object object;
             Request parameters = Request.create()
                         .withFilterParameter("key",object);
         
         
        Parameters:
        key -
        value -
        Returns:
        The request object with the parameter applied.
        See Also:
        Request, create()
      • withFilterMetadataParameter

        public Request withFilterMetadataParameter​(String key,
                                                   String value)
        Adds a new parameter to the filter.metadata node.

        Example:

         
             Request parameters = Request.create()
                         .withFilterMetadataParameter("key","value");
         
         
        Parameters:
        key -
        value -
        Returns:
        The request object with the parameter applied.
        See Also:
        Request, create()
      • withItems

        public Request withItems​(List<? extends Map<String,​Object>> items)
        Sets the items array to the specified input list. The list represents an array of objects via Java Map. That is, an instance of Map equals a Json object. For most write operations the maximum number of items per request is 1k. For time series datapoints the maximum number of items is 10k, with a maximum of 100k data points.

        Example:

         
              List<Map<String, Object>> requestItems = new ArrayList<>();
              Map<String, Object> requestItem = new HashMap<>();
              requestItem.put("externalId", 1);
              requestItems.add(requestItem);
              Request parameters = Request.create()
                          .withItems(requestItems);
         
         
        Parameters:
        items -
        Returns:
        The request object with the parameter applied.
        See Also:
        Request, create()
      • withDatasetExternalIds

        public Request withDatasetExternalIds​(String... externalId)
        Convenience method for setting dataset external ids of a request. You can use this methods to limit a request to only include the resources within one or several specified data sets.
        Parameters:
        externalId -
        Returns:
        The request object with the parameter applied.
      • withDatasetIds

        public Request withDatasetIds​(long... internalId)
        Convenience method for setting dataset ids of a request. You can use this methods to limit a request to only include the resources within one or several specified data sets.
        Parameters:
        internalId -
        Returns:
        The request object with the parameter applied.
      • withItemExternalId

        @Deprecated
        public Request withItemExternalId​(String externalId)
        Deprecated.
        Convenience method for setting the external id for requesting an item. You can use this method when requesting a data item by id, for example when requesting the data points from a time series.
        Parameters:
        externalId -
        Returns:
        The request object with the parameter applied.
      • withItemExternalIds

        public Request withItemExternalIds​(String... externalId)
        Convenience method for setting the external id for requesting multiple items. You can use this method when requesting a data item by id, for example when requesting a set of events.

        Example:

         
              Request parameters = Request.create().withItemExternalIds("externalId");
         
         
        Parameters:
        externalId -
        Returns:
        The request object with the parameter applied.
        See Also:
        Request, create()
      • withItemInternalId

        @Deprecated
        public Request withItemInternalId​(long internalId)
        Deprecated.
        Convenience method for setting the external id for requesting an item. You can use this method when requesting a data item by id, for example when requesting the data points from a time series.

        Example:

         
              Long internalId = 1L;
              Request parameters = Request.create().withItemInternalId(internalId);
         
         
        Parameters:
        internalId -
        Returns:
        The request object with the parameter applied.
        See Also:
        Request, create()
      • withItemInternalIds

        public Request withItemInternalIds​(long... internalId)
        Convenience method for setting the external id for requesting multiple items. You can use this method when requesting a data item by id, for example when requesting a set of events.

        Example:

         
              Request parameters = Request.create().withItemInternalId(1,2);
         
         
        Parameters:
        internalId -
        Returns:
        The request object with the parameter applied.
        See Also:
        Request, create()
      • withDbName

        public Request withDbName​(String dbName)
        Convenience method for adding the database name when reading from Cognite.Raw.
        Parameters:
        dbName - The name of the database to read from.
        Returns:
        The request object with the parameter applied.
      • withTableName

        public Request withTableName​(String tableName)
        Convenience method for adding the table name when reading from Cognite.Raw.
        Parameters:
        tableName - The name of the database to read from.
        Returns:
        The request object with the parameter applied.
      • withAuthConfig

        public Request withAuthConfig​(AuthConfig config)
        Sets the project configuration for a request. The configuration includes host (optional), project/tenant and key. You can use this method if you need detailed, per-request control over auth config. In most cases, however, you will configure this once on the CogniteClient.

        Example:

         
              AuthConfig authConfig = //AuthConfig object;
              Request parameters = Request.create().withAuthConfig(authConfig);
         
         
        Parameters:
        config - The auth config
        Returns:
        The request object with the configuration applied.
        See Also:
        AuthConfig, Request, create()
      • getRequestParametersAsJson

        public String getRequestParametersAsJson()
                                          throws com.fasterxml.jackson.core.JsonProcessingException

        Example:

         
              String requestParametersAsJson = Request.create().getRequestParametersAsJson();
         
         
        Returns:
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException
        See Also:
        Request, create()
      • getFilterParameters

        public com.google.common.collect.ImmutableMap<String,​Object> getFilterParameters()
        Returns the collection of filter parameters as a Map. The filter parameter must have a key of type String in order to be included in the return collection. Please note that all entries (with a key of type String) under the filter node are returned, potentially including nested collections (such as metadata).

        Example:

         
              Request parameters = Request.create();
              parameters.getFilterParameters().get("key");
         
         
        Returns:
        See Also:
        Request, create()
      • getMetadataFilterParameters

        public com.google.common.collect.ImmutableMap<String,​String> getMetadataFilterParameters()
        Returns the collection of metadata specific filter parameters as a Map. The parameters must have both a key and value of type String in order to be included in the return collection.

        Example:

         
              Request parameters = Request.create();
              parameters.getMetadataFilterParameters().get("key");
         
         
        Returns:
        See Also:
        Request, create()
      • getItems

        public com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableMap<String,​Object>> getItems()
        Returns the list of items. This is typically the main payload of a write request (create, update or delete).

        Example:

         
              Request parameters = Request.create();
              parameters.getItems();
         
         
        Returns:
        See Also:
        Request, create()