Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2020 Cognite AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.cognite.client;
import com.cognite.client.config.AuthConfig;
import com.cognite.client.dto.Item;
import com.cognite.client.servicesV1.util.JsonUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.protobuf.Message;
import javax.annotation.Nullable;
import java.io.Serializable;
import java.util.*;
import static com.google.common.base.Preconditions.*;
/**
* 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
* {@code https://docs.cognite.com/api/v1/} for reference.
*
* @see Cognite API v1 specification
*/
@AutoValue
public abstract class Request implements Serializable {
private final ObjectReader objectReader = JsonUtil.getObjectMapperInstance().reader();
private final ObjectWriter objectWriter = JsonUtil.getObjectMapperInstance().writer();
private static Builder builder() {
return new AutoValue_Request.Builder();
}
public static Request create() {
return Request.builder().build();
}
/**
* Returns the object representation of the composite request body. It is similar to the Cognite API Json
* request body, with {@code Map} as the Json container, {@code List} as the
* Json array.
*
* @return
*/
public abstract ImmutableMap getRequestParameters();
/**
* For internal use only.
*
* Returns the protobuf request body.
* @return
*/
@Nullable
public abstract Message getProtoRequestBody();
/**
* Returns the project configuration for a request. The configuration includes host (optional),
* project/tenant and key.
*
* @return
*/
@Nullable
public abstract AuthConfig getAuthConfig();
abstract Builder toBuilder();
/**
* 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).
*
* @param requestParameters
* @return The request object with the parameter applied.
*/
public Request withRequestParameters(Map requestParameters) {
checkArgument(requestParameters != null, "Input cannot be null or empty.");
return toBuilder().setRequestParameters(requestParameters).build();
}
/**
* Adds the complete request body as a protobuf object.
*
* @param requestBody
* @return The request object with the parameter applied.
*/
public Request withProtoRequestBody(Message requestBody) {
return toBuilder().setProtoRequestBody(requestBody).build();
}
/**
* Adds the complete request parameter structure based on Json. Calling this method will overwrite
* any previously added parameters.
*
* @param value
* @return The request object with the parameter applied.
*/
public Request withRequestJson(String value) throws Exception {
checkArgument(value != null && !value.isEmpty(), "Request Json cannot be null or empty.");
ImmutableMap fromJson = ImmutableMap.copyOf(
objectReader.forType(new TypeReference