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
use activitystreams_vocabulary::{Item, create_object, field_access};
use crate::DependsOn;
create_object! {
/// Represents a relationship between 2 [Ticket](crate::Ticket)s, in which the resolution of one ticket requires the other ticket to be resolved too.
///
/// It **MUST** specify the `subject`, `object` and `relationship` properties.
///
/// The `relationship` property **MUST** be [dependsOn](DependsOn).
///
/// # Example
///
/// ```rust
/// use activityforge::{DependsOn, TicketDependency, context};
/// use activitystreams_vocabulary::{DateTime, Iri};
///
/// # fn main() {
/// let id = Iri::try_from("https://example.dev/ticket-deps/2342593").unwrap();
/// let attributed_to = Iri::try_from("https://example.dev/alice").unwrap();
/// let summary = "Alice's ticket depends on Bob's ticket";
/// let published = "2019-07-11T12:34:56Z";
/// let subject = Iri::try_from("https://example.dev/alice/myproj/issues/42").unwrap();
/// let relationship = DependsOn::new();
/// let object = Iri::try_from("https://dev.community/bob/coolproj/issues/85").unwrap();
///
/// let json_str = format!(
/// r#"{{
/// "@context": [
/// "https://www.w3.org/ns/activitystreams",
/// "https://forgefed.org/ns"
/// ],
/// "type": "TicketDependency",
/// "id": "{id}",
/// "attributedTo": "{attributed_to}",
/// "summary": "{summary}",
/// "published": "{published}",
/// "subject": "{subject}",
/// "relationship": "{relationship}",
/// "object": "{object}"
/// }}"#
/// );
///
/// let context = context::forgefed_context();
///
/// let ticket_dep = TicketDependency::new()
/// .with_context_property(context)
/// .with_id(id)
/// .with_attributed_to(attributed_to)
/// .with_published(published.parse::<DateTime>().unwrap())
/// .with_summary(summary)
/// .with_subject(subject)
/// .with_relationship(relationship)
/// .with_object(object);
///
/// assert_eq!(
/// serde_json::to_string_pretty(&ticket_dep).unwrap(),
/// json_str
/// );
/// assert_eq!(
/// serde_json::from_str::<TicketDependency>(json_str.as_str()).unwrap(),
/// ticket_dep
/// );
/// # }
/// ```
TicketDependency: crate::ObjectType::TicketDependency {
#[serde(skip_serializing_if = "Option::is_none")]
subject: Option<Box<Item>>,
#[serde(skip_serializing_if = "Option::is_none")]
relationship: Option<Box<DependsOn>>,
#[serde(skip_serializing_if = "Option::is_none")]
object: Option<Box<Item>>,
}
}
field_access! {
TicketDependency<Vocab> {
/// On a [TicketDependency] object, the `subject` property identifies one of the connected individuals.
///
/// For instance, for a [TicketDependency] object describing "John is related to Sally", `subject` would refer to John.
subject: option_box_deref { Item },
/// On a [TicketDependency] object, the `relationship` property identifies the kind of relationship that exists between `subject` and `object`.
relationship: option_box_deref { DependsOn },
/// When used within a [TicketDependency], `object` describes the entity to which the `subject` is related.
object: option_box_deref { Item },
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::context;
use activitystreams_vocabulary::{DateTime, Iri};
#[test]
fn test_ticket_dependency() {
let id = Iri::try_from("https://example.dev/ticket-deps/2342593").unwrap();
let attributed_to = Iri::try_from("https://example.dev/alice").unwrap();
let summary = "Alice's ticket depends on Bob's ticket";
let published = "2019-07-11T12:34:56Z";
let subject = Iri::try_from("https://example.dev/alice/myproj/issues/42").unwrap();
let relationship = DependsOn::new();
let object = Iri::try_from("https://dev.community/bob/coolproj/issues/85").unwrap();
let json_str = format!(
r#"{{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://forgefed.org/ns"
],
"type": "TicketDependency",
"id": "{id}",
"attributedTo": "{attributed_to}",
"summary": "{summary}",
"published": "{published}",
"subject": "{subject}",
"relationship": "{relationship}",
"object": "{object}"
}}"#
);
let context = context::forgefed_context();
let ticket_dep = TicketDependency::new()
.with_context_property(context)
.with_id(id)
.with_attributed_to(attributed_to)
.with_published(published.parse::<DateTime>().unwrap())
.with_summary(summary)
.with_subject(subject)
.with_relationship(relationship)
.with_object(object);
assert_eq!(serde_json::to_string_pretty(&ticket_dep).unwrap(), json_str);
assert_eq!(
serde_json::from_str::<TicketDependency>(json_str.as_str()).unwrap(),
ticket_dep
);
}
}