oxinat_core/uri/admin/
system.rs

1use std::{fmt::Debug, sync::Arc};
2
3use oxinat_derive::uri_builder_alias;
4
5use crate::{UriBuilder, Version};
6
7uri_builder_alias!(SysUriBuilder);
8ImplSysUriBuilder! {
9    (String),
10    (AllowUriBuilder<'_>),
11    (CatalogsUriBuilder<'_>),
12    (DownloadUriBuilder<'_>),
13    (MessagesUriBuilder<'_>),
14    (RefreshUriBuilder<'_>),
15    (NotifyUriBuilder<'_>),
16    (SubscribersUriBuilder<'_>),
17}
18ImplSysUriBuilder! {
19    (ArchiveUriBuilder<Parent>, Parent),
20    (AsyncOpsUriBuilder<Parent>, Parent),
21    (NotificationsUriBuilder<Parent>, Parent),
22    (XnatTaskUriBuilder<Parent>, Parent),
23}
24
25/// Represents the URI paths available for
26/// endpoints meant for interacting with XNAT
27/// archive catalogs.
28#[derive(Clone, Debug, Default, UriBuilder)]
29#[match_path(path = "{parent}/archive")]
30pub struct ArchiveUriBuilder<Parent>
31where
32    Parent: SysUriBuilder,
33{
34    #[parent]
35    parent: Option<Arc<Parent>>,
36}
37
38/// Represents the URI paths available for
39/// endpoints meant for doing manipulations
40/// against an XNAT archive catalog.
41#[derive(Clone, Debug, Default, UriBuilder)]
42#[match_path(path = "{parent}/catalogs")]
43pub struct CatalogsUriBuilder<'a>
44{
45    #[parent]
46    parent: Option<&'a ArchiveUriBuilder<String>>
47}
48
49/// Represents the URI paths available for
50/// endpoints to request a refresh against an
51/// XNAT archive catalog.
52#[derive(Clone, Debug, Default, UriBuilder)]
53#[match_path(path = "{parent}/refresh")]
54#[match_path(path = "{parent}/refresh/{operations}")]
55pub struct RefreshUriBuilder<'a>
56{
57    #[param(map_from=r#"|o: &Vec<_>| o.join(",")"#)]
58    operations: Option<Vec<String>>,
59    #[parent]
60    parent: Option<&'a CatalogsUriBuilder<'a>>,
61}
62
63impl CatalogsUriBuilder<'_>
64{
65    /// Continue the builder into a
66    /// `RefreshUriBuilder`.
67    pub fn refresh(&self) -> RefreshUriBuilder {
68        RefreshUriBuilder::from_parent(&Arc::new(self))
69    }
70}
71
72/// Represents the URI paths available for
73/// endpoints to download the specified catalog.
74#[derive(Clone, Debug, Default, UriBuilder)]
75#[match_path(path = "{parent}/download")]
76#[match_path(path = "{parent}/download/{catalog_id}")]
77pub struct DownloadUriBuilder<'a>
78{
79    #[param]
80    catalog_id: Option<String>,
81    #[parent]
82    parent: Option<&'a ArchiveUriBuilder<String>>
83}
84
85impl DownloadUriBuilder<'_>
86{
87    /// Produce the
88    /// archive/download/{catalog_id}/test URI
89    /// endpoint.
90    pub fn build_test(&self) -> crate::BuildResult {
91        self.build_join("test")
92    }
93
94    /// Produce the archive/downloadwithsize URI
95    /// endpoint.
96    pub fn build_with_size(&self) -> crate::BuildResult {
97        self.parent.as_ref().unwrap().build_join("downloadwithsize")
98    }
99
100    /// Produce the
101    /// archive/download/{catalog_id}/xml URI
102    /// endpoint.
103    pub fn build_xml(&self) -> crate::BuildResult {
104        self.build_join("xml")
105    }
106
107    /// Produce the
108    /// archive/download/{catalog_id}/zip URI
109    /// endpoint.
110    pub fn build_zip(&self) -> crate::BuildResult {
111        self.build_join("zip")
112    }
113}
114
115impl ArchiveUriBuilder<String>
116{
117    /// Continue the builder into a
118    /// `CatalogsUriBuilder`.
119    pub fn catalogs(&self) -> CatalogsUriBuilder {
120        CatalogsUriBuilder::from_parent(&Arc::new(self))
121    }
122
123    /// Continue the builder into a
124    /// `DownloadUriBuilder`.
125    pub fn download(&self) -> DownloadUriBuilder {
126        DownloadUriBuilder::from_parent(&Arc::new(self))
127    }
128
129    /// Produce the archive/upload/xml URI
130    /// endpoint.
131    pub fn build_upload_xml(&self) -> crate::BuildResult {
132        self.build_join("upload/xml")
133    }
134}
135
136/// Represents the URI endpoint paths available to
137/// a user to allow/disallow notifications
138/// provided by the user.
139#[derive(Clone, Debug, Default, UriBuilder)]
140#[match_path(path = "{parent}/notifications")]
141pub struct NotificationsUriBuilder<Parent>
142where
143    Parent: SysUriBuilder,
144{
145    #[parent]
146    parent: Option<Arc<Parent>>
147}
148
149/// Represents URI endpoint paths available for
150/// managing some allowables for XNAT
151/// notifications.
152#[derive(Clone, Debug, Default, UriBuilder)]
153#[match_path(path = "{parent}/allow/{name}")]
154#[match_path(path = "{parent}/allow/{name}/{setting}")]
155pub struct AllowUriBuilder<'a>
156{
157    #[param]
158    name: Option<String>,
159    #[param]
160    setting: Option<String>,
161    #[parent]
162    parent: Option<&'a NotificationsUriBuilder<String>>,
163}
164
165/// Some supported message type by an XNAT
166/// notification system.
167#[derive(Clone, Debug, UriBuilder)]
168pub enum MessageType {
169    ForgotUserName,
170    Help,
171    PasswordReset,
172    Registration,
173}
174
175/// Represents URI endpoint paths available for
176/// user messaging configuration.
177#[derive(Clone, Debug, Default, UriBuilder)]
178#[match_path(path = "{parent}/messages/{message_type}")]
179pub struct MessagesUriBuilder<'a>
180{
181    #[param]
182    message_type: Option<MessageType>,
183    #[parent]
184    parent: Option<&'a NotificationsUriBuilder<String>>,
185}
186
187/// Some supported notification type by an XNAT
188/// notification system.
189#[derive(Clone, Debug, UriBuilder)]
190pub enum NotifyType {
191    Par,
192    Pipeline,
193    Registration,
194    Transfer,
195    Smtp,
196    #[match_path(path = "smtp/host/{p0}")]
197    SmtpHost(String),
198    #[match_path(path = "smtp/password/{p0}")]
199    SmtpPassword(String),
200    #[match_path(path = "smtp/port/{p0}")]
201    SmtpPort(String),
202    #[match_path(path = "smtp/property/{p0}")]
203    #[match_path(path = "smtp/property/{p0}/{p1}")]
204    SmtpProperty(String, Option<String>),
205    #[match_path(path = "smtp/protocol/{p0}")]
206    SmtpProtocol(String),
207    #[match_path(path = "smtp/username/{p0}")]
208    SmtpUsername(String),
209}
210
211/// Represents URI endpoint paths available for
212/// admin notifications to be enabled/disabled.
213#[derive(Clone, Debug, Default, UriBuilder)]
214#[match_path(path = "{parent}/notify/{notify_type}")]
215pub struct NotifyUriBuilder<'a>
216{
217    #[param]
218    notify_type: Option<NotifyType>,
219    #[parent]
220    parent: Option<&'a NotificationsUriBuilder<String>>,
221}
222
223/// Some supported options available for managing
224/// subscriber config options.
225#[derive(Clone, Debug, UriBuilder)]
226pub enum SubscriberOpt {
227    Error,
228    Issue,
229    NewUser,
230    Update,
231}
232
233/// Represents URI endpoint paths available for
234/// managing subscriber notification
235/// configuration.
236#[derive(Clone, Debug, Default, UriBuilder)]
237#[match_path(path = "{parent}/subscribers/{subscriber_option}")]
238pub struct SubscribersUriBuilder<'a>
239{
240    #[param]
241    subscriber_option: Option<SubscriberOpt>,
242    #[parent]
243    parent: Option<&'a NotificationsUriBuilder<String>>,
244}
245
246impl NotificationsUriBuilder<String>
247{
248    /// Continue the builder into a
249    /// `AllowUriBuilder`.
250    pub fn allow(&self) -> AllowUriBuilder {
251        AllowUriBuilder::from_parent(&Arc::new(self))
252    }
253
254    /// Continue the builder into a
255    /// `MessagesUriBuilder`.
256    pub fn messages(&self) -> MessagesUriBuilder {
257        MessagesUriBuilder::from_parent(&Arc::new(self))
258    }
259
260    /// Continue the builder into a
261    /// `NotifyUriBuilder`.
262    pub fn notify(&self) -> NotifyUriBuilder {
263        NotifyUriBuilder::from_parent(&Arc::new(self))
264    }
265
266    /// Continue the builder into a
267    /// `SubscribersUriBuilder`.
268    pub fn subscribers(&self) -> SubscribersUriBuilder {
269        SubscribersUriBuilder::from_parent(&Arc::new(self))
270    }
271}
272
273/// Represents the URI paths available for
274/// managing XNAT tasks.
275#[derive(Clone, Debug, Default, UriBuilder)]
276#[match_path(path = "{parent}/xnatTask")]
277pub struct XnatTaskUriBuilder<Parent>
278where
279    Parent: SysUriBuilder,
280{
281    #[parent]
282    parent: Option<Arc<Parent>>,
283}
284
285impl XnatTaskUriBuilder<String>
286{
287    /// Produce the
288    /// archive/xnatTask/checkNodeConfigurationStatus
289    /// URI endpoint.
290    pub fn build_check_node_config_status(&self) -> crate::BuildResult {
291        self.build_join("checkNodeConfigurationStatus")
292    }
293
294    /// Produce the archive/xnatTask/taskList URI
295    /// endpoint.
296    pub fn build_task_list(&self) -> crate::BuildResult {
297        self.build_join("taskList")
298    }
299}
300
301/// Represents the URI paths available for
302/// managing XNAT asyncronous operations.
303#[derive(Clone, Debug, Default, UriBuilder)]
304#[match_path(path = "{parent}/asyncOps")]
305#[match_path(path = "{parent}/asyncOps/{preference}")]
306pub struct AsyncOpsUriBuilder<Parent>
307where
308    Parent: SysUriBuilder,
309{
310    #[param]
311    preference: Option<String>,
312    #[parent]
313    parent: Option<Arc<Parent>>,
314}
315
316#[derive(Clone, Debug, UriBuilder)]
317pub enum LogConfigOpt {
318    #[match_path(path = "configs")]
319    #[match_path(path = "configs/{p0}")]
320    Configs(Option<String>),
321    #[match_path(path = "download")]
322    #[match_path(path = "download/{p0}")]
323    Download(Option<String>),
324    Elements,
325    Reset,
326}
327
328/// Represents the URI paths available for
329/// managing XNAT asyncronous operations.
330#[derive(Clone, Debug, Default, UriBuilder)]
331#[match_path(path = "{parent}/logs/{config_opt}")]
332pub struct LogsUriBuilder<Parent>
333where
334    Parent: SysUriBuilder,
335{
336    #[param]
337    config_opt: Option<LogConfigOpt>,
338    #[parent]
339    parent: Option<Arc<Parent>>,
340}
341
342/// Represent the URI paths available for
343/// endpoints meant for interacting with an XNAT
344/// archive catalog.
345pub trait SystemUri: Version {
346    /// URI endpoint to access the archive catalog
347    /// API.
348    #[inline]
349    fn archive(&self) -> ArchiveUriBuilder<String> {
350        ArchiveUriBuilder::from_parent(self.root_uri().into())
351    }
352
353    /// URI endpoint to interact with XNAT async
354    /// ops API.
355    #[inline]
356    fn async_ops(&self) -> AsyncOpsUriBuilder<String> {
357        AsyncOpsUriBuilder::from_parent(self.root_uri().into())
358    }
359
360    /// URI endpoint to interact with XNAT log
361    /// configurations.
362    #[inline]
363    fn logs(&self) -> LogsUriBuilder<String> {
364        LogsUriBuilder::from_parent(self.root_uri().into())
365    }
366
367    /// URI endpoint to interact with XNAT
368    /// notifications API.
369    #[inline]
370    fn notifications(&self) -> NotificationsUriBuilder<String> {
371        NotificationsUriBuilder::from_parent(self.root_uri().into())
372    }
373
374    /// URI enpoint to interact with XNAT task
375    /// API.
376    #[inline]
377    fn xnat_task(&self) -> XnatTaskUriBuilder<String> {
378        XnatTaskUriBuilder::from_parent(self.root_uri().into())
379    }
380}