1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::default::Default;
use tardis::chrono::{DateTime, Utc};
use tardis::db::sea_orm;
use tardis::web::poem_openapi;
use crate::rbum::rbum_enumeration::{RbumRelEnvKind, RbumRelFromKind};
/// Add request for resource relationship
///
/// 资源关联添加请求
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
pub struct RbumRelAddReq {
/// Relationship tag
///
/// 关联标签
///
/// Used to distinguish different relationships.
///
/// 用于区分不同的关联关系。
#[oai(validator(min_length = "2", max_length = "255"))]
pub tag: String,
/// Relationship note
///
/// 关联备注
#[oai(validator(min_length = "2", max_length = "1000"))]
pub note: Option<String>,
/// Relationship source type
///
/// 关联来源方的类型
pub from_rbum_kind: RbumRelFromKind,
/// Relationship source id
///
/// 关联来源方的id
#[oai(validator(min_length = "2", max_length = "255"))]
pub from_rbum_id: String,
/// Relationship target id
///
/// 关联目标方的id
#[oai(validator(min_length = "2", max_length = "255"))]
pub to_rbum_item_id: String,
/// Relationship target ownership path
///
/// 关联目标方的所有权路径
#[oai(validator(min_length = "2", max_length = "255"))]
pub to_own_paths: String,
/// Relationship extension information
///
/// 关联扩展信息
///
/// E.g. the record from or to is in another service, to avoid remote calls,
/// you can redundantly add the required information to this field.
///
/// 例如:记录来源或目标在另一个服务中,为避免远程调用,可以将所需信息冗余添加到此字段。
#[oai(validator(min_length = "2", max_length = "1000"))]
pub ext: Option<String>,
/// Whether the target is an external object
///
/// 关联目标方是否是外部对象
///
/// If ``true``, the validity of the associated target will not be verified.
///
/// 当为 ``true`` 不会校验关联目标方的合法性。
pub to_is_outside: bool,
}
/// Modify request for resource relationship
///
/// 资源关联修改请求
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
pub struct RbumRelModifyReq {
/// Relationship tag
///
/// 关联标签
///
/// Used to distinguish different relationships.
///
/// 用于区分不同的关联关系。
#[oai(validator(min_length = "2", max_length = "255"))]
pub tag: Option<String>,
/// Relationship note
///
/// 关联备注
#[oai(validator(min_length = "2", max_length = "1000"))]
pub note: Option<String>,
/// Relationship extension information
///
/// 关联扩展信息
///
/// E.g. the record from or to is in another service, to avoid remote calls,
/// you can redundantly add the required information to this field.
///
/// 例如:记录来源或目标在另一个服务中,为避免远程调用,可以将所需信息冗余添加到此字段。
#[oai(validator(min_length = "2", max_length = "1000"))]
pub ext: Option<String>,
}
/// Simple find request for resource relationship
///
/// 资源关联简单查找请求
#[derive(Serialize, Deserialize, Debug, Clone, Default, poem_openapi::Object)]
#[serde(default)]
pub struct RbumRelSimpleFindReq {
/// Relationship tag
///
/// 关联标签
///
/// Used to distinguish different relationships.
///
/// 用于区分不同的关联关系。
#[oai(validator(min_length = "2", max_length = "255"))]
pub tag: Option<String>,
/// Relationship source type
///
/// 关联来源方的类型
pub from_rbum_kind: Option<RbumRelFromKind>,
/// Relationship source id
///
/// 关联来源方的id
#[oai(validator(min_length = "2", max_length = "255"))]
pub from_rbum_id: Option<String>,
/// Relationship target id
///
/// 关联目标方的id
#[oai(validator(min_length = "2", max_length = "255"))]
pub to_rbum_item_id: Option<String>,
/// Relationship source ownership path
///
/// 关联来源方的所有权路径
#[oai(validator(min_length = "2", max_length = "255"))]
pub from_own_paths: Option<String>,
/// Relationship target ownership path
///
/// 关联目标方的所有权路径
#[oai(validator(min_length = "2", max_length = "255"))]
pub to_rbum_own_paths: Option<String>,
}
/// Check request for resource relationship
///
/// 资源关联检查请求
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
pub struct RbumRelCheckReq {
/// Relationship tag
///
/// 关联标签
///
/// Used to distinguish different relationships.
///
/// 用于区分不同的关联关系。
#[oai(validator(min_length = "2", max_length = "255"))]
pub tag: String,
/// Relationship source type
///
/// 关联来源方的类型
pub from_rbum_kind: RbumRelFromKind,
/// Relationship source id
///
/// 关联来源方的id
#[oai(validator(min_length = "2", max_length = "255"))]
pub from_rbum_id: String,
/// Relationship target id
///
/// 关联目标方的id
#[oai(validator(min_length = "2", max_length = "255"))]
pub to_rbum_item_id: String,
/// Limit the attributes of the relationship source
///
/// 关联来源方的限定属性集合
///
/// Format: ``{"Attribute name": "Input value"}``
///
/// 格式: ``{"属性名称": "传入的值"}``
pub from_attrs: HashMap<String, String>,
/// Limit the attributes of the relationship target
///
/// 关联目标方的限定属性集合
///
/// Format: ``{"Attribute name": "Input value"}``
///
/// 格式: ``{"属性名称": "传入的值"}``
pub to_attrs: HashMap<String, String>,
/// Limit the environment of the relationship
///
/// 关联目标方的限定环境集合
pub envs: Vec<RbumRelEnvCheckReq>,
}
/// Check request for resource relationship environment
///
/// 资源关联环境检查请求
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
pub struct RbumRelEnvCheckReq {
/// Relationship environment type
///
/// 关联的环境类型
pub kind: RbumRelEnvKind,
/// Input value
///
/// 传入的关联环境值
pub value: String,
}
/// Resource relationship bone information
///
/// 资源关联骨干信息
#[derive(Serialize, Deserialize, Debug, Clone, poem_openapi::Object, sea_orm::FromQueryResult)]
pub struct RbumRelBoneResp {
/// Relationship tag
///
/// 关联标签
pub tag: String,
/// Relationship note
///
/// 关联备注
pub note: String,
/// Relationship source type
///
/// 关联来源方的类型
pub from_rbum_kind: RbumRelFromKind,
/// Relationship source or target id
///
/// 关联来源方或目标方的id
pub rel_id: String,
/// Relationship source or target name
///
/// 关联来源方或目标方的名称
///
/// When `from_rbum_kind` is [`crate::rbum::rbum_enumeration::RbumRelFromKind::Item`] is the name of the resource item,
/// When `from_rbum_kind` is [`crate::rbum::rbum_enumeration::RbumRelFromKind::Set`] is the name of the resource set,
/// When `from_rbum_kind` is [`crate::rbum::rbum_enumeration::RbumRelFromKind::SetCate`] is the name of the resource set category(node).
///
/// 当 `from_rbum_kind` 为 [`crate::rbum::rbum_enumeration::RbumRelFromKind::Item`] 时是资源项的名称,
/// 当 `from_rbum_kind` 为 [`crate::rbum::rbum_enumeration::RbumRelFromKind::Set`] 时是资源集的名称,
/// 当 `from_rbum_kind` 为 [`crate::rbum::rbum_enumeration::RbumRelFromKind::SetCate`] 时是资源集分类(节点)的名称。
pub rel_name: String,
/// Relationship source or target ownership path
///
/// 关联来源方或目标方的所有权路径
pub rel_own_paths: String,
/// Relationship extension information
///
/// 关联扩展信息
///
/// E.g. the record from or to is in another service, to avoid remote calls,
/// you can redundantly add the required information to this field.
///
/// 例如:记录来源或目标在另一个服务中,为避免远程调用,可以将所需信息冗余添加到此字段。
pub ext: String,
}
impl RbumRelBoneResp {
/// According to the relationship detail information, generate the relationship summary information
///
/// 根据关联详细信息生成关联概要信息
///
/// # Arguments
///
/// * `detail` - Relationship detail information
/// * `package_to_info` - If ``true``, generate the summary information of the relationship source side, if ``false``, generate the summary information of the relationship target side
pub fn new(detail: RbumRelDetailResp, package_to_info: bool) -> RbumRelBoneResp {
if package_to_info {
RbumRelBoneResp {
tag: detail.tag,
note: detail.note,
from_rbum_kind: detail.from_rbum_kind,
rel_id: detail.to_rbum_item_id,
rel_name: detail.to_rbum_item_name,
rel_own_paths: detail.to_own_paths,
ext: detail.ext,
}
} else {
RbumRelBoneResp {
rel_name: match &detail.from_rbum_kind {
RbumRelFromKind::Item => detail.from_rbum_item_name,
RbumRelFromKind::Set => detail.from_rbum_set_name,
RbumRelFromKind::SetCate => detail.from_rbum_set_cate_name,
RbumRelFromKind::Cert => "".to_string(),
},
tag: detail.tag,
note: detail.note,
from_rbum_kind: detail.from_rbum_kind,
rel_id: detail.from_rbum_id,
rel_own_paths: detail.own_paths,
ext: detail.ext,
}
}
}
}
/// Resource relationship detail information
///
/// 资源关联详细信息
#[derive(Serialize, Deserialize, Clone, Debug, poem_openapi::Object, sea_orm::FromQueryResult)]
pub struct RbumRelDetailResp {
/// Relationship id
///
/// 关联id
pub id: String,
/// Relationship tag
///
/// 关联标签
pub tag: String,
/// Relationship note
///
/// 关联备注
pub note: String,
/// Relationship source type
///
/// 关联来源方的类型
pub from_rbum_kind: RbumRelFromKind,
/// Relationship source id
///
/// 关联来源方的id
pub from_rbum_id: String,
/// Relationship source resource item name
///
/// 关联来源方的资源项名称
///
/// Only valid when `from_rbum_kind` is [`crate::rbum::rbum_enumeration::RbumRelFromKind::Item`].
///
/// 仅当 `from_rbum_kind` 为 [`crate::rbum::rbum_enumeration::RbumRelFromKind::Item`] 时有值。
pub from_rbum_item_name: String,
/// Relationship source resource set name
///
/// 关联来源方的资源集名称
///
/// Only valid when `from_rbum_kind` is [`crate::rbum::rbum_enumeration::RbumRelFromKind::Set`].
///
/// 仅当 `from_rbum_kind` 为 [`crate::rbum::rbum_enumeration::RbumRelFromKind::Set`] 时有值。
pub from_rbum_set_name: String,
/// Relationship source resource set category(node) name
///
/// 关联来源方的资源集分类(节点)名称
///
/// Only valid when `from_rbum_kind` is [`crate::rbum::rbum_enumeration::RbumRelFromKind::SetCate`].
///
/// 仅当 `from_rbum_kind` 为 [`crate::rbum::rbum_enumeration::RbumRelFromKind::SetCate`] 时有值。
pub from_rbum_set_cate_name: String,
/// Relationship target id
///
/// 关联目标方的id
pub to_rbum_item_id: String,
/// Relationship target name
///
/// 关联目标方的name
pub to_rbum_item_name: String,
/// Relationship target ownership path
///
/// 关联目标方的所有权路径
pub to_own_paths: String,
/// Relationship extension information
///
/// 关联扩展信息
pub ext: String,
pub own_paths: String,
pub owner: String,
pub owner_name: Option<String>,
pub create_time: DateTime<Utc>,
pub update_time: DateTime<Utc>,
}