1 | <?xml version="1.0" encoding="UTF-8"?> |
---|
2 | <!-- |
---|
3 | POST body format: |
---|
4 | <json> |
---|
5 | <[field]> |
---|
6 | [fieldValue] |
---|
7 | </[field]> |
---|
8 | </json> |
---|
9 | --> |
---|
10 | <sequence debug="false"> |
---|
11 | <log> |
---|
12 | <level>INFO</level> |
---|
13 | <message> |
---|
14 | <literal type="string">[interface.REST] [%1] posted new [%2] for schema with id: [%3]</literal> |
---|
15 | </message> |
---|
16 | <param> |
---|
17 | <request> |
---|
18 | <identifier>active:xpath2</identifier> |
---|
19 | <argument name="operand">scratch:user</argument> |
---|
20 | <argument name="operator"> |
---|
21 | <literal type="string">string(/sc:user/@xml:id)</literal> |
---|
22 | </argument> |
---|
23 | </request> |
---|
24 | </param> |
---|
25 | <param>arg:metadataFieldName</param> |
---|
26 | <param>arg:schemaID</param> |
---|
27 | </log> |
---|
28 | <!-- Fetch authorized IDs from the database --> |
---|
29 | <request assignment="authorized-IDs"> |
---|
30 | <identifier>active:org.isocat.schemacat.access.data.schema.authorizedIDs</identifier> |
---|
31 | <argument name="schemaID">arg:schemaID</argument> |
---|
32 | </request> |
---|
33 | <!-- Obtain IDs authorized to update the schema --> |
---|
34 | <request assignment="authorized-update-IDs"> |
---|
35 | <identifier>active:sloot.xquery</identifier> |
---|
36 | <argument name="operator"> |
---|
37 | <literal type="xml"> |
---|
38 | <query> |
---|
39 | <ids> |
---|
40 | { |
---|
41 | for $id in $authorizedIDs/ids/id |
---|
42 | return if (contains($id/@actions, 'u')) |
---|
43 | then $id |
---|
44 | else () |
---|
45 | } |
---|
46 | </ids> |
---|
47 | </query> |
---|
48 | </literal> |
---|
49 | </argument> |
---|
50 | <argument name="authorizedIDs">this:authorized-IDs</argument> |
---|
51 | </request> |
---|
52 | <sloot-debug> |
---|
53 | <log> |
---|
54 | <level>INFO</level> |
---|
55 | <message> |
---|
56 | <literal type="string">[interface.REST] Users authorized to update schema metadata:
[
%1
]</literal> |
---|
57 | </message> |
---|
58 | <param>this:authorized-update-IDs</param> |
---|
59 | </log> |
---|
60 | </sloot-debug> |
---|
61 | <if assignment="response"> |
---|
62 | <cond> |
---|
63 | <request> |
---|
64 | <identifier>active:isAuthorized</identifier> |
---|
65 | <argument name="authorizedIDs" method="identity">this:authorized-update-IDs</argument> |
---|
66 | <argument name="authorizedRoles" method="identity"> |
---|
67 | <request> |
---|
68 | <identifier>active:org.isocat.schemacat.access.data.schemas.authorizedRoles</identifier> |
---|
69 | </request> |
---|
70 | </argument> |
---|
71 | <argument name="user" method="identity">scratch:user</argument> |
---|
72 | </request> |
---|
73 | </cond> |
---|
74 | <then> |
---|
75 | <if> |
---|
76 | <cond> |
---|
77 | <request> |
---|
78 | <identifier>httpRequest:/body</identifier> |
---|
79 | <verb>EXISTS</verb> |
---|
80 | </request> |
---|
81 | </cond> |
---|
82 | <then> |
---|
83 | <sequence> |
---|
84 | <request assignment="body-XML"> |
---|
85 | <identifier>active:JSONToXML</identifier> |
---|
86 | <argument name="operand">httpRequest:/body</argument> |
---|
87 | <argument name="operator"> |
---|
88 | <literal type="xml"> |
---|
89 | <config> |
---|
90 | <addRootElement>true</addRootElement> |
---|
91 | </config> |
---|
92 | </literal> |
---|
93 | </argument> |
---|
94 | </request> |
---|
95 | <sloot-debug> |
---|
96 | <log> |
---|
97 | <level>INFO</level> |
---|
98 | <message> |
---|
99 | <literal type="string">[interface.REST] POST body for schema [%1] update request:
[
%2
]</literal> |
---|
100 | </message> |
---|
101 | <param>arg:metadataFieldName</param> |
---|
102 | <param>this:body-XML</param> |
---|
103 | </log> |
---|
104 | </sloot-debug> |
---|
105 | <request assignment="schemaMetadataUpdateFragment"> |
---|
106 | <identifier>active:xslt2</identifier> |
---|
107 | <argument name="operand">this:body-XML</argument> |
---|
108 | <argument name="operator"> |
---|
109 | <literal type="xml"> |
---|
110 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sc="http://www.isocat.org/ns/schemacat" version="2.0"> |
---|
111 | <!-- transform the XQuery XML into a valid BaseX REST Query document --> |
---|
112 | <xsl:import href="active:sloot.xquery-wrapers.escape"/> |
---|
113 | <xsl:template match="/json"> |
---|
114 | <sc:schema> |
---|
115 | <xsl:choose> |
---|
116 | <xsl:when test="./*[1]/name() eq 'license'"> |
---|
117 | <sc:license> |
---|
118 | <xsl:attribute name="ref"><xsl:value-of select="./*[1]/text()"/></xsl:attribute> |
---|
119 | </sc:license> |
---|
120 | </xsl:when> |
---|
121 | <xsl:otherwise> |
---|
122 | <xsl:apply-templates/> |
---|
123 | </xsl:otherwise> |
---|
124 | </xsl:choose> |
---|
125 | </sc:schema> |
---|
126 | </xsl:template> |
---|
127 | <xsl:template match="element()"> |
---|
128 | <xsl:element name="{concat('sc:', local-name())}"> |
---|
129 | <xsl:apply-templates/> |
---|
130 | </xsl:element> |
---|
131 | </xsl:template> |
---|
132 | </xsl:stylesheet> |
---|
133 | </literal> |
---|
134 | </argument> |
---|
135 | </request> |
---|
136 | <sloot-debug> |
---|
137 | <log> |
---|
138 | <level>INFO</level> |
---|
139 | <message> |
---|
140 | <literal type="string">[interface.REST] New [%1] update fragment extracted from POST body:
[
%2
]</literal> |
---|
141 | </message> |
---|
142 | <param>arg:metadataFieldName</param> |
---|
143 | <param>this:schemaMetadataUpdateFragment</param> |
---|
144 | </log> |
---|
145 | </sloot-debug> |
---|
146 | <request assignment="response"> |
---|
147 | <identifier>active:org.isocat.schemacat.access.data.schema.metadata</identifier> |
---|
148 | <verb>SINK</verb> |
---|
149 | <argument name="id">arg:schemaID</argument> |
---|
150 | <argument name="schemaMetadataFragment">this:schemaMetadataUpdateFragment</argument> |
---|
151 | </request> |
---|
152 | </sequence> |
---|
153 | </then> |
---|
154 | <else> |
---|
155 | <throw> |
---|
156 | <id> |
---|
157 | <literal type="string">NK_INPUT_ARGS_NOT_COMPLETE</literal> |
---|
158 | </id> |
---|
159 | <message> |
---|
160 | <literal type="string">org.isocat.schemacat.interface.rest.post.schema.access: POST body not supplied!</literal> |
---|
161 | </message> |
---|
162 | </throw> |
---|
163 | </else> |
---|
164 | </if> |
---|
165 | </then> |
---|
166 | <else> |
---|
167 | <request> |
---|
168 | <identifier>active:interface.rest.HTTPresponse.forbidden</identifier> |
---|
169 | </request> |
---|
170 | </else> |
---|
171 | </if> |
---|
172 | <sloot-debug> |
---|
173 | <request> |
---|
174 | <verb>SINK</verb> |
---|
175 | <identifier>res:/debug/org.isocat.schemacat.interface.rest.post.schema.access.response.xml</identifier> |
---|
176 | <argument name="primary">this:response</argument> |
---|
177 | </request> |
---|
178 | </sloot-debug> |
---|
179 | </sequence> |
---|