Tech Blog

Loading secondary item file

The secondary item file is a way to provide descriptive information at migration (see Migration Guides and Tutorials under appropriate ILS). If the file isn’t ready at the time of migration it can be loaded post-migration using Retrieve Item and Update Item APIs.

For this script the secondary item file was converted from CSV to a pipe-delimited file in CSVed. Since there were no pipes in the data (data did contain commas), using pipes as the delimiter made a simpler file without quotes.

Script was run on Windows using Cygwin Linux emulator. It should work on any Unix environment.

#!/bin/bash
infile="items_file.txt"
# input file line example
# ISSitm1000-6038.141-lhalldb|v. 54, no. 3 (2018 Sept.)|54|3|||||||2018|Sep|||

results=”results.txt”
backup=”backup.txt”
original=”orig_item.tmp”
modified=”mod_item.tmp”

# production
authkey=”Authorization: apikey xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”
# sandbox
#authkey=”Authorization: apikey yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy”
#api URL (if all item lines don’t have a barcode, use MMS ID, Holding ID, and Item ID)
urlpre=”https://api-na.hosted.exlibrisgroup.com/almaws/v1/items?item_barcode=”

while IFS=| read -r id desc enumA enumB enumC enumD enumE enumF enumG enumH chronI chronJ chronK chronL chronM
do

# get item record using barcode from infile
curl -L “$urlpre$id” -H “$authkey” > “$original”
cat “$original” >> “$backup”
echo >> “$backup”

if grep -q “errorsExist>true” $original; then
echo “ERROR on $id” >> $results
else
echo “processing $id” >> $results
# replace fields and write to $original
sed ”
s|<enumeration_a>.*</enumeration_a>|<enumeration_a>$enumA</enumeration_a>|
s|<enumeration_b>.*</enumeration_b>|<enumeration_b>$enumB</enumeration_b>|
s|<enumeration_c>.*</enumeration_c>|<enumeration_c>$enumC</enumeration_c>|
s|<enumeration_d>.*</enumeration_d>|<enumeration_d>$enumD</enumeration_d>|
s|<enumeration_e>.*</enumeration_e>|<enumeration_e>$enumE</enumeration_e>|
s|<enumeration_f>.*</enumeration_f>|<enumeration_f>$enumF</enumeration_f>|
s|<enumeration_g>.*</enumeration_g>|<enumeration_g>$enumG</enumeration_g>|
s|<enumeration_h>.*</enumeration_h>|<enumeration_h>$enumH</enumeration_h>|
s|<chronology_i>.*</chronology_i>|<chronology_i>$chronI</chronology_i>|
s|<chronology_j>.*</chronology_j>|<chronology_j>$chronJ</chronology_j>|
s|<chronology_k>.*</chronology_k>|<chronology_k>$chronK</chronology_k>|
s|<chronology_l>.*</chronology_l>|<chronology_l>$chronL</chronology_l>|
s|<chronology_m>.*</chronology_m>|<chronology_m>$chronM</chronology_m>|
s|<description>.*</description>|<description>$desc</description>|” <$original >$modified

# put updated item
# put requires MMS ID, holdings ID and item ID. Retrieve from XML
urlpost=$(grep -Eo “https://api-na.hosted.exlibrisgroup.com/almaws/v1/bibs/[^/]+/holdings/[^/]+/items/[^”]+” $original)

# update item record in Alma
echo $urlpost
# uncomment below to update items in Alma
# curl -X PUT “$urlpost” -H “$authkey” -H “Content-Type: application/xml” –data-binary “$(cat $modified)”
fi
done <“$infile”

Leave a Reply