cognite/dto/data_organization/
datasets.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4use serde_with::skip_serializing_none;
5
6use crate::{
7    Identity, IntoPatch, IntoPatchItem, Patch, Range, UpdateMap, UpdateSetNull, UpsertOptions,
8};
9
10#[derive(Serialize, Deserialize, Debug, Default)]
11#[serde(rename_all = "camelCase")]
12/// A data set grouping data in CDF.
13pub struct DataSet {
14    /// Data set internal ID.
15    pub id: i64,
16    /// Time this data set was created, in milliseconds since epoch.
17    pub created_time: i64,
18    /// Time this data set was last modified, in milliseconds since epoch.
19    pub last_updated_time: i64,
20    /// Data set external ID. Must be unique within the project.
21    pub external_id: Option<String>,
22    /// Human readable data set name.
23    pub name: Option<String>,
24    /// Data set description.
25    pub description: Option<String>,
26    /// Custom, application specific metadata. String key -> String value.
27    /// Limits: Maximum length of key is 128 bytes, value 10240 bytes,
28    /// up to 256 key-value pairs, of total size at most 10240.
29    pub metadata: Option<HashMap<String, String>>,
30    /// To write data to a write-protected data set, you need to be a member of
31    /// a group that has the "datasets:owner" action for the data set.
32    pub write_protected: bool,
33}
34
35#[skip_serializing_none]
36#[derive(Serialize, Deserialize, Debug, Default)]
37#[serde(rename_all = "camelCase")]
38/// Create a CDF data set.
39pub struct AddDataSet {
40    /// Data set external ID. Must be unique within the project.
41    pub external_id: Option<String>,
42    /// Human readable data set name.
43    pub name: Option<String>,
44    /// Data set description.
45    pub description: Option<String>,
46    /// Custom, application specific metadata. String key -> String value.
47    /// Limits: Maximum length of key is 128 bytes, value 10240 bytes,
48    /// up to 256 key-value pairs, of total size at most 10240.
49    pub metadata: Option<HashMap<String, String>>,
50    /// To write data to a write-protected data set, you need to be a member of
51    /// a group that has the "datasets:owner" action for the data set.
52    pub write_protected: bool,
53}
54
55impl From<DataSet> for AddDataSet {
56    fn from(dataset: DataSet) -> Self {
57        AddDataSet {
58            external_id: dataset.external_id,
59            name: dataset.name,
60            description: dataset.description,
61            metadata: dataset.metadata,
62            write_protected: dataset.write_protected,
63        }
64    }
65}
66
67#[skip_serializing_none]
68#[derive(Serialize, Deserialize, Debug, Default, Clone)]
69#[serde(rename_all = "camelCase")]
70/// Filter for listing data sets.
71pub struct DataSetFilter {
72    /// Filter based on metadata.
73    pub metadata: Option<HashMap<String, String>>,
74    /// Range of timestamps for `created_time`.
75    pub created_time: Option<Range<i64>>,
76    /// Range of timestamps for `last_updated_time`.
77    pub last_updated_time: Option<Range<i64>>,
78    /// Filter by this (case-sensitive) prefix for the external ID.
79    pub external_id_prefix: Option<String>,
80    /// Filter on data set `writeProtected`.
81    pub write_protected: Option<bool>,
82}
83
84#[derive(Serialize, Deserialize, Debug, Default)]
85#[serde(rename_all = "camelCase")]
86/// Result for aggregating data sets.
87pub struct DataSetsCount {
88    /// Data set count.
89    pub count: i64,
90}
91
92#[skip_serializing_none]
93#[derive(Serialize, Deserialize, Debug, Default, Clone)]
94#[serde(rename_all = "camelCase")]
95/// Update data sets.
96pub struct PatchDataSet {
97    /// Data set external ID. Must be unique within the project.
98    pub external_id: Option<UpdateSetNull<String>>,
99    /// Data set name.
100    pub name: Option<UpdateSetNull<String>>,
101    /// Data set description.
102    pub description: Option<UpdateSetNull<String>>,
103    /// Custom, application specific metadata. String key -> String value.
104    /// Limits: Maximum length of key is 128 bytes, value 10240 bytes,
105    /// up to 256 key-value pairs, of total size at most 10240.
106    pub metadata: Option<UpdateMap<String, String>>,
107}
108
109impl IntoPatch<Patch<PatchDataSet>> for DataSet {
110    fn patch(self, options: &UpsertOptions) -> Patch<PatchDataSet> {
111        Patch::<PatchDataSet> {
112            id: to_idt!(self),
113            update: PatchDataSet {
114                external_id: None,
115                name: self.name.patch(options),
116                description: self.description.patch(options),
117                metadata: self.metadata.patch(options),
118            },
119        }
120    }
121}
122
123impl IntoPatch<PatchDataSet> for AddDataSet {
124    fn patch(self, options: &UpsertOptions) -> PatchDataSet {
125        PatchDataSet {
126            external_id: None,
127            name: self.name.patch(options),
128            description: self.description.patch(options),
129            metadata: self.metadata.patch(options),
130        }
131    }
132}
133
134impl From<DataSet> for Patch<PatchDataSet> {
135    fn from(data_set: DataSet) -> Patch<PatchDataSet> {
136        IntoPatch::<Patch<PatchDataSet>>::patch(data_set, &Default::default())
137    }
138}