Skip to content

Commit 78cbe20

Browse files
authored
idempotent dataverse previewer create/update (#356)
1 parent 2f605ef commit 78cbe20

1 file changed

Lines changed: 33 additions & 20 deletions

File tree

files/dataverse-previewers.sh

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
#!/bin/sh
22

3-
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
3+
curl http://localhost:8080/api/admin/externalTools > /tmp/externalTools.json
4+
5+
upload_if_necessary() {
6+
JSON=$1
7+
TOOL_URL_LINE=`echo "$JSON" | grep toolUrl | sed -e 's/^[[:space:]]*//'`
8+
CONTENT_TYPE_LINE=`echo "$JSON" | grep contentType | sed -e 's/^[[:space:]]*//'`
9+
grep -q "$TOOL_URL_LINE" /tmp/externalTools.json && \
10+
grep -q "$CONTENT_TYPE_LINE" /tmp/externalTools.json && \
11+
echo "skipping $TOOL_URL_LINE $CONTENT_TYPE_LINE"
12+
return
13+
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d "$JSON"
14+
}
15+
16+
upload_if_necessary \
417
'{
518
"displayName":"Read Text",
619
"description":"Read the text file.",
@@ -21,7 +34,7 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
2134
"contentType":"text/plain"
2235
}'
2336

24-
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
37+
upload_if_necessary \
2538
'{
2639
"displayName":"View Html",
2740
"description":"View the html file.",
@@ -42,7 +55,7 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
4255
"contentType":"text/html"
4356
}'
4457

45-
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
58+
upload_if_necessary \
4659
'{
4760
"displayName":"Play Audio",
4861
"description":"Listen to an audio file.",
@@ -63,7 +76,7 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
6376
"contentType":"audio/mp3"
6477
}'
6578

66-
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
79+
upload_if_necessary \
6780
'{
6881
"displayName":"Play Audio",
6982
"description":"Listen to an audio file.",
@@ -84,7 +97,7 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
8497
"contentType":"audio/mpeg"
8598
}'
8699

87-
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
100+
upload_if_necessary \
88101
'{
89102
"displayName":"Play Audio",
90103
"description":"Listen to an audio file.",
@@ -105,7 +118,7 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
105118
"contentType":"audio/wav"
106119
}'
107120

108-
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
121+
upload_if_necessary \
109122
'{
110123
"displayName":"Play Audio",
111124
"description":"Listen to an audio file.",
@@ -126,7 +139,7 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
126139
"contentType":"audio/ogg"
127140
}'
128141

129-
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
142+
upload_if_necessary \
130143
'{
131144
"displayName":"View Image",
132145
"description":"Preview an image file.",
@@ -147,7 +160,7 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
147160
"contentType":"image/gif"
148161
}'
149162

150-
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
163+
upload_if_necessary \
151164
'{
152165
"displayName":"View Image",
153166
"description":"Preview an image file.",
@@ -168,7 +181,7 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
168181
"contentType":"image/jpeg"
169182
}'
170183

171-
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
184+
upload_if_necessary \
172185
'{
173186
"displayName":"View Image",
174187
"description":"Preview an image file.",
@@ -189,7 +202,7 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
189202
"contentType":"image/png"
190203
}'
191204

192-
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
205+
upload_if_necessary \
193206
'{
194207
"displayName":"Read Document",
195208
"description":"Read a pdf document.",
@@ -210,7 +223,7 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
210223
"contentType":"application/pdf"
211224
}'
212225

213-
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
226+
upload_if_necessary \
214227
'{
215228
"displayName":"Play Video",
216229
"description":"Watch a video file.",
@@ -231,7 +244,7 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
231244
"contentType":"video/mp4"
232245
}'
233246

234-
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
247+
upload_if_necessary \
235248
'{
236249
"displayName":"Play Video",
237250
"description":"Watch a video file.",
@@ -252,7 +265,7 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
252265
"contentType":"video/ogg"
253266
}'
254267

255-
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
268+
upload_if_necessary \
256269
'{
257270
"displayName":"Play Video",
258271
"description":"Watch a video file.",
@@ -273,7 +286,7 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
273286
"contentType":"video/quicktime"
274287
}'
275288

276-
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
289+
upload_if_necessary \
277290
'{
278291
"displayName":"View Data",
279292
"description":"View the spreadsheet data.",
@@ -294,7 +307,7 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
294307
"contentType":"text/comma-separated-values"
295308
}'
296309

297-
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
310+
upload_if_necessary \
298311
'{
299312
"displayName":"View Data",
300313
"description":"View the spreadsheet data.",
@@ -315,7 +328,7 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
315328
"contentType":"text/tab-separated-values"
316329
}'
317330

318-
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
331+
upload_if_necessary \
319332
'{
320333
"displayName":"View Data",
321334
"description":"View the spreadsheet data.",
@@ -336,7 +349,7 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
336349
"contentType":"text/csv"
337350
}'
338351

339-
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
352+
upload_if_necessary \
340353
'{
341354
"displayName":"View Data",
342355
"description":"View the spreadsheet data.",
@@ -357,7 +370,7 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
357370
"contentType":"text/tsv"
358371
}'
359372

360-
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
373+
upload_if_necessary \
361374
'{
362375
"displayName":"View Stata File",
363376
"description":"View the Stata file as text.",
@@ -378,7 +391,7 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
378391
"contentType":"application/x-stata-syntax"
379392
}'
380393

381-
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
394+
upload_if_necessary \
382395
'{
383396
"displayName":"View R file",
384397
"description":"View the R file as text.",
@@ -399,7 +412,7 @@ curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin
399412
"contentType":"type/x-r-syntax"
400413
}'
401414

402-
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
415+
upload_if_necessary \
403416
'{
404417
"displayName":"View Annotations",
405418
"description":"View the annotation entries in a file.",

0 commit comments

Comments
 (0)