-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradar2oai.sh
executable file
·64 lines (52 loc) · 1.29 KB
/
radar2oai.sh
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
#!/usr/bin/env bash
##
## Optionally specify the backend as argument, e.g.
## ./radar2oai.sh http://10.22.13.12:6081/oai-backend
##
BACKEND="${1:-http://localhost:8081/oai-backend}"
JSONLD=data/10.22000-702.json
if [ ! -f "$JSONLD" ] ; then
echo "File not found"
exit 1
fi
if ! jq type "$JSONLD" ; then
EXITCODE=$?
echo "jq found invalid JSON. Exit code $EXITCODE"
exit $EXITCODE
fi
## Clean logs
rm -f error.log
touch error.log
# For array of records:
# jq --compact-output '.[]' $JSONLD | \
jq --compact-output '.' $JSONLD | \
while read -r i; do
IDENTIFIER=`echo "$i" | jq '."@id"'`
if [ -z $IDENTIFIER ] ; then
echo "Empty IDENTIFIER:"
echo "$i"
exit 1
fi
TAGS='["RADAR4Chem", "Dataset", "RADAR4Chem:Dataset"]'
# Change to: <json xmlns="http://nfdi4chem.de/schemas/json-container/1.0/">
(
cat <<EOF
<json xmlns="http://denbi.de/schemas/json-container">
<![CDATA[
EOF
echo "$i"
cat <<EOF
]]>
</json>
EOF
) | curl -v -H 'Content-Type: multipart/form-data' \
-i \
--fail-with-body \
"$BACKEND/item" \
-F "item={\"identifier\":$IDENTIFIER,\"deleteFlag\":false,\"ingestFormat\":\"json_container\",\"tags\":$TAGS};type=application/json" \
-F content=@- ;\
retval=$?
if [ $retval -ne 0 ] ; then
echo -e "curl error $retval:\t$IDENTIFIER" >>error.log
fi
done # while read