Class SequenceParser
- java.lang.Object
-
- com.cognite.client.servicesV1.parser.SequenceParser
-
public class SequenceParser extends Object
This class contains a set of methods to help parsingSequenceobjects between Cognite api representations (json and proto) and typed objects.
-
-
Constructor Summary
Constructors Constructor Description SequenceParser()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static SequenceBodyparseSequenceBody(String json)Parses a sequence body json string toSequenceBodyproto object.static SequenceMetadataparseSequenceMetadata(String json)Parses a sequence header json string toSequenceMetadataproto object.static Optional<SequenceColumn.ValueType>parseValueType(String type)Tries to parse a string into aSequenceColumn.ValueType.static Map<String,Object>toRequestDeleteRowsItem(SequenceBody element)Builds a request delete rows object fromSequenceBody.static Map<String,Object>toRequestInsertItem(SequenceBody element)Builds a request insert item object fromSequenceBody.static Map<String,Object>toRequestInsertItem(SequenceMetadata element)Builds a request insert item object fromSequenceMetadata.static Map<String,Object>toRequestReplaceItem(SequenceMetadata element)Builds a request insert item object fromSequenceMetadata.static Map<String,Object>toRequestReplaceItem(SequenceMetadata newElement, SequenceMetadata existingElement)Builds a request replace item object fromSequenceMetadata.static com.google.common.collect.ImmutableMap<String,Object>toRequestUpdateItem(SequenceMetadata element)Builds a request update item object fromSequenceMetadata.static Map<String,Object>toRequestUpdateItem(SequenceMetadata newElement, SequenceMetadata existingElement)Builds a request update item object fromSequenceMetadata.static StringtoString(SequenceColumn.ValueType valueType)Returns the string representation of aSequenceColumn.ValueType.
-
-
-
Method Detail
-
parseSequenceMetadata
public static SequenceMetadata parseSequenceMetadata(String json) throws Exception
Parses a sequence header json string toSequenceMetadataproto object.- Parameters:
json- The json representation of a sequence header- Returns:
- The sequence header as a typed object
- Throws:
Exception
-
parseSequenceBody
public static SequenceBody parseSequenceBody(String json) throws Exception
Parses a sequence body json string toSequenceBodyproto object.- Parameters:
json- The json representation of a sequence body- Returns:
- The sequence body as a typed object
- Throws:
Exception
-
toRequestInsertItem
public static Map<String,Object> toRequestInsertItem(SequenceMetadata element)
Builds a request insert item object fromSequenceMetadata. An insert item object creates a new sequence header data object in the Cognite system.- Parameters:
element-- Returns:
-
toRequestInsertItem
public static Map<String,Object> toRequestInsertItem(SequenceBody element) throws Exception
Builds a request insert item object fromSequenceBody. An insert item object creates a set of new rows for asequencein the Cognite system.- Parameters:
element-- Returns:
- Throws:
Exception
-
toRequestUpdateItem
public static Map<String,Object> toRequestUpdateItem(SequenceMetadata newElement, SequenceMetadata existingElement) throws Exception
Builds a request update item object fromSequenceMetadata. An update item object updates an existing sequence header object with new values for all provided fields. Fields that are not in the update object retain their original value. This method will also perform an update of the column definitions. It does so by comparing thenewElementwith theexistingElementand perform the following actions: - New columns will be created. - Existing columns will keep their data type (string, numeric, etc.) and externalId, but other attributes will be updated. Attributes that are not specified in thenewElementobject will retain their original value. - Deleted columns will not be touched. I.e. no columns will be deleted from CDF.- Parameters:
newElement- The new/updated sequence header/metadata.existingElement- The existing sequence header/metadata.- Returns:
- The update object in "javafied Json" structure.
- Throws:
Exception
-
toRequestUpdateItem
public static com.google.common.collect.ImmutableMap<String,Object> toRequestUpdateItem(SequenceMetadata element)
Builds a request update item object fromSequenceMetadata. An update item object updates an existing sequence header object with new values for all provided fields. Fields that are not in the update object retain their original value. This method will not take the column definition into account. You need to use thetoRequestUpdateItem(SequenceMetadata, SequenceMetadata)method to include column definition upsert.- Parameters:
element- The sequence header/metadata to update- Returns:
- The update object in "javafied Json" structure
-
toRequestReplaceItem
public static Map<String,Object> toRequestReplaceItem(SequenceMetadata newElement, SequenceMetadata existingElement) throws Exception
Builds a request replace item object fromSequenceMetadata. A replace item object replaces an existing sequence header object with new values for all provided fields. Fields that are not in the update object are set to null. This method will also perform an update of the column definitions. It does so by comparing thenewElementwith theexistingElementand perform the following actions: - New columns will be created. - Existing columns will keep their data type (string, numeric, etc.) and externalId, but other attributes will be replaced. Attributes that are not specified in thenewElementobject will be set to null. - Deleted columns will be removed.- Parameters:
newElement- The new/updated sequence header/metadata.existingElement- The existing sequence header/metadata.- Returns:
- The replace object in "javafied Json" structure.
- Throws:
Exception
-
toRequestReplaceItem
public static Map<String,Object> toRequestReplaceItem(SequenceMetadata element)
Builds a request insert item object fromSequenceMetadata. A replace item object replaces an existing sequence header object with new values for all provided fields. Fields that are not in the update object are set to null. This method will not take the column definition into account. You need to use thetoRequestReplaceItem(SequenceMetadata, SequenceMetadata)method to include column definition upsert.- Parameters:
element-- Returns:
-
toRequestDeleteRowsItem
public static Map<String,Object> toRequestDeleteRowsItem(SequenceBody element)
Builds a request delete rows object fromSequenceBody. An delete rows object removes a set of rows from a sequence in the Cognite system.- Parameters:
element-- Returns:
-
toString
public static String toString(SequenceColumn.ValueType valueType)
Returns the string representation of aSequenceColumn.ValueType.- Parameters:
valueType- The value type- Returns:
- The string representation of the
SequenceColumn.ValueType
-
parseValueType
public static Optional<SequenceColumn.ValueType> parseValueType(String type)
Tries to parse a string into aSequenceColumn.ValueType. If the string cannot be parsed, the returnedOptionalwill be empty.- Parameters:
type- The string to be parsed into aSequenceColumn.ValueType- Returns:
- an
Optionalcarrying theSequenceColumn.ValueType
-
-