-
Notifications
You must be signed in to change notification settings - Fork 6
/
stats.clj
140 lines (108 loc) · 5.59 KB
/
stats.clj
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
(ns common-swagger-api.schema.stats
(:use [clojure-commons.error-codes]
[common-swagger-api.schema])
(:require [common-swagger-api.schema.data :as data-schema]
[schema.core :as s])
(:import [java.util UUID]))
(def StatSummary "File and Folder Status Information")
(def StatDocs
"This endpoint allows the caller to get information about many files and folders at once.")
(def DataTypeEnum (s/enum :file :dir))
(def DataItemIdParam (describe UUID "The UUID of this data item"))
(def DataItemPathParam (describe NonBlankString "The IRODS paths to this data item"))
(s/defschema StatQueryParams
{(s/optional-key :validation-behavior)
(describe data-schema/PermissionEnum "What level of permissions on the queried files should be validated?")})
(s/defschema FilteredStatQueryParams
(merge StatQueryParams
{(s/optional-key :filter-include)
(describe String (str "Comma-separated list of keys to generate and return in each stat object. "
"Defaults to all keys. If both this and filter-exclude are provided, "
"includes are processed first, then excludes."))
(s/optional-key :filter-exclude)
(describe String (str "Comma-separated list of keys to exclude from each stat object. "
"Defaults to no keys. If both this and filter-include are provided, "
"includes are processed first, then excludes."))}))
(s/defschema DataStatInfo
{:id
DataItemIdParam
:path
DataItemPathParam
:type
(describe DataTypeEnum "The data item's type")
:label
(describe String "The descriptive label for this item.")
:date-created
(describe Long "The date this data item was created")
:date-modified
(describe Long "The date this data item was last modified")
:permission
(describe data-schema/PermissionEnum "The requesting user's permissions on this data item")
(s/optional-key :share-count)
(describe Long (str "The number of other users this data item is shared with (only displayed to users with 'own' "
"permissions)"))})
(s/defschema DirStatInfo
(merge DataStatInfo
{:file-count (describe Long "The number of files under this directory")
:dir-count (describe Long "The number of subdirectories under this directory")}))
(s/defschema FileStatInfo
(merge DataStatInfo
{:file-size
(describe Long "The size in bytes of this file")
:content-type
(describe NonBlankString "The detected media type of the data contained in this file")
:infoType
(describe String "The type of contents in this file")
:md5
(describe String "The md5 hash of this file's contents, as calculated and saved by IRODS")}))
(s/defschema FilteredStatInfo
(let [combined-stat (merge DirStatInfo FileStatInfo)]
(reduce ->optional-param combined-stat (remove s/optional-key? (keys combined-stat)))))
(def AvailableStatFields (vec (map optional-key->keyword (keys FilteredStatInfo))))
(s/defschema FileStat
{:file (describe FileStatInfo "File info")})
(s/defschema PathsMap
{(describe s/Keyword "The iRODS data item's path")
(describe (s/conditional #(contains? % :file-size) FileStatInfo :else DirStatInfo) "The data item's info")})
(s/defschema FilteredPathsMap
{(describe s/Keyword "The iRODS data item's path")
(describe FilteredStatInfo "The data item's info")})
(s/defschema DataIdsMap
{(describe s/Keyword "The iRODS data item's ID")
(describe (s/conditional #(contains? % :file-size) FileStatInfo :else DirStatInfo) "The data item's info")})
(s/defschema FilteredDataIdsMap
{(describe s/Keyword "The iRODS data item's ID")
(describe FilteredStatInfo "The data item's info")})
(s/defschema StatusInfo
{(s/optional-key :paths) (describe PathsMap "Paths info")
(s/optional-key :ids) (describe DataIdsMap "IDs info")})
(s/defschema FilteredStatusInfo
{(s/optional-key :paths) (describe FilteredPathsMap "Paths info")
(s/optional-key :ids) (describe FilteredDataIdsMap "IDs info")})
;; Used only for display as documentation in Swagger UI
(s/defschema StatResponsePathsMap
{:/path/from/request/to/a/folder (describe DirStatInfo "A folder's info")
:/path/from/request/to/a/file (describe FileStatInfo "A file's info")})
;; Used only for display as documentation in Swagger UI
(s/defschema StatResponseIdsMap
{:some-folder-uuid (describe DirStatInfo "A folder's info")
:some-file-uuid (describe FileStatInfo "A file's info")})
;; Used only for display as documentation in Swagger UI
(s/defschema StatResponse
{(s/optional-key :paths) (describe StatResponsePathsMap "A map of paths from the request to their status info")
(s/optional-key :ids) (describe StatResponseIdsMap "A map of ids from the request to their status info")})
(s/defschema StatErrorResponses
(merge ErrorResponseUnchecked
{:error_code (apply s/enum (conj data-schema/CommonErrorCodeResponses
ERR_DOES_NOT_EXIST
ERR_NOT_READABLE
ERR_NOT_WRITEABLE
ERR_NOT_OWNER
ERR_NOT_A_USER
ERR_TOO_MANY_RESULTS))}))
(s/defschema StatResponses
(merge CommonResponses
{200 {:schema (doc-only StatusInfo StatResponse)
:description "File and Folder Status Response."}
500 {:schema StatErrorResponses
:description data-schema/CommonErrorCodeDocs}}))