Package com.cognite.client
Class Request
java.lang.Object
com.cognite.client.Request
- All Implemented Interfaces:
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:
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Requestcreate()abstract AuthConfigReturns the project configuration for a request.Returns the collection of filter parameters as a Map.getItems()Returns the list of items.Returns the collection of metadata specific filter parameters as a Map.abstract com.google.protobuf.MessageFor internal use only.Returns the object representation of the composite request body.Example:withAuthConfig(AuthConfig config) Sets the project configuration for a request.withDatasetExternalIds(String... externalId) Convenience method for setting dataset external ids of a request.withDatasetIds(long... internalId) Convenience method for setting dataset ids of a request.withDbName(String dbName) Convenience method for adding the database name when reading from Cognite.Raw.withFilterMetadataParameter(String key, String value) Adds a new parameter to the filter.metadata node.withFilterParameter(String key, Object value) Adds a new parameter to the filter node.withItemExternalIds(String... externalId) Convenience method for setting the external id for requesting multiple items.withItemInternalIds(long... internalId) Convenience method for setting the external id for requesting multiple items.Sets the items array to the specified input list.withProtoRequestBody(com.google.protobuf.Message requestBody) Adds the complete request body as a protobuf object.withRequestJson(String value) Adds the complete request parameter structure based on Json.withRequestParameters(Map<String, Object> requestParameters) Adds the complete request parameter structure based on Java objects.withRootParameter(String key, Object value) Adds a new parameter to the root level.withTableName(String tableName) Convenience method for adding the table name when reading from Cognite.Raw.
-
Constructor Details
-
Request
public Request()
-
-
Method Details
-
create
-
getRequestParameters
Returns the object representation of the composite request body. It is similar to the Cognite API Json request body, withMap<String, Object>as the Json container,Listas the Json array.- Returns:
-
getProtoRequestBody
@Nullable public abstract com.google.protobuf.Message getProtoRequestBody()For internal use only. Returns the protobuf request body.- Returns:
-
getAuthConfig
Returns the project configuration for a request. The configuration includes host (optional), project/tenant and key.- Returns:
-
withRequestParameters
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)) -
withProtoRequestBody
Adds the complete request body as a protobuf object.Example:
Message requestBody; Request.create().withProtoRequestBody(requestBody); -
withRequestJson
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); -
withRootParameter
Adds a new parameter to the root level.Example:
Object object; Request parameters = Request.create() .withRootParameter("key",object); -
withFilterParameter
Adds a new parameter to the filter node.Example:
Object object; Request parameters = Request.create() .withFilterParameter("key",object); -
withFilterMetadataParameter
Adds a new parameter to the filter.metadata node.Example:
Request parameters = Request.create() .withFilterMetadataParameter("key","value"); -
withItems
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); -
withDatasetExternalIds
Convenience method for setting dataset external ids of a request. You can use this method 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
Convenience method for setting dataset ids of a request. You can use this method 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.
-
withItemExternalIds
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"); -
withItemInternalIds
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); -
withDbName
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
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
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 theCogniteClient.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:
-
getRequestParametersAsJson
public String getRequestParametersAsJson() throws com.fasterxml.jackson.core.JsonProcessingExceptionExample:
String requestParametersAsJson = Request.create().getRequestParametersAsJson(); -
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 typeString) under the filter node are returned, potentially including nested collections (such as metadata).Example:
Request parameters = Request.create(); parameters.getFilterParameters().get("key"); -
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"); -
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();
-