-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathagreements-attachpackages
More file actions
executable file
·60 lines (44 loc) · 1.64 KB
/
agreements-attachpackages
File metadata and controls
executable file
·60 lines (44 loc) · 1.64 KB
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
#!/usr/bin/bash
auth 2>/dev/null || authn 2>/dev/null
tenant=$(cat tenant)
okapi_url=$(cat okapi.url)
okapi_token=$(cat okapi.token)
declare -A packages_dict
### Be sure tenant eHoldings is fully configured and connected to library HLM
infile="agreementnames" # expects agreement names to be exactly the same as package names
outfile="packages.log"
rm -f ${outfile}
#get agreement list from FOLIO
echo "Retrieving agreements"
records-get agreements
#get package list from eHoldings/HLM
echo "Retrieving packages"
records-get packages
all_packages="$(<packages.json)"
all_agreements="$(<agreements.json)"
create_agreementline() {
IFS='' read -r -d '' agreementline << EndOfAgreementLine
{
"type":"external",
"authority":"ekb-package",
"reference":"${package_id}",
"owner":"${agreement_uuid}"
}
EndOfAgreementLine
echo "${agreementline}"
}
#read infile agreement list, compare against eHoldings package list
while IFS=$'\n' read -r agreement_name;do
echo "Processing ${agreement_name}"
package_id=$(jq -r --arg NAME "${agreement_name}" 'select(.attributes.name == $NAME) |.id' <<< "${all_packages}")
agreement_uuid=$(jq -r --arg NAME "${agreement_name}" 'select(.name == $NAME) |.id' <<< "${all_agreements}")
agreement_line=$(create_agreementline)
if [[ ${#package_id} -gt 1 ]];then
apicall=$(curl --http1.1 -s -w '\n' -X POST -H "Content-type: application/json" -H "X-Okapi-Tenant: ${tenant}" -H "x-okapi-token: ${okapi_token}" -d "${agreement_line}" "${okapi_url}/erm/entitlements")
echo "${apicall}" >> ${outfile}
else
echo "No package matching ${agreement_name} can be found"
fi
echo "${apicall}"
counter=$((counter + 1))
done < ${infile}