-
Notifications
You must be signed in to change notification settings - Fork 2
/
resource_type.clj
44 lines (39 loc) · 1.39 KB
/
resource_type.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
(ns org.cyverse.metadata-files.datacite-4-1.resource-type
(:use [org.cyverse.metadata-files.datacite-4-1.namespaces :only [alias-uris]])
(:require [org.cyverse.metadata-files.simple-nested-element :as sne]
[org.cyverse.metadata-files.util :as util]))
(alias-uris)
(def valid-resource-types
#{"Audiovisual"
"Collection"
"DataPaper"
"Dataset"
"Event"
"Image"
"InteractiveResource"
"Model"
"PhysicalObject"
"Service"
"Software"
"Sound"
"Text"
"Workflow"
"Other"})
(defn- get-resource-type-general [location {:keys [avus]}]
(let [attribute-name "resourceTypeGeneral"
value (util/get-required-attribute-value location avus attribute-name)]
(when-not (valid-resource-types value)
(throw (ex-info (str "Invalid " attribute-name " value.")
{:location location
:attribute attribute-name
:value value
:valid-values valid-resource-types})))
value))
(defn- get-resource-type-attrs [location attribute]
{:resourceTypeGeneral (get-resource-type-general location attribute)})
(defn new-resource-type-generator [location]
(sne/new-simple-nested-element-generator
{:attr-name "resourceType"
:attrs-fn get-resource-type-attrs
:tag ::datacite/resourceType
:parent-location location}))