Last active
October 18, 2017 06:24
-
-
Save jweisman/5b0c5e7fb92416cfa25086ffc9a2c79e to your computer and use it in GitHub Desktop.
Process Orchestration in Alma with the Job and Set APIs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "Creating new set" | |
SET_ID=`curl -s --fail -X POST -H "Authorization: apikey $API_KEY" -H "Content-type: application/xml" -H "Accept: application/xml" --data @set.xml "https://api-na.hosted.exlibrisgroup.com/almaws/v1/conf/sets" | xmllint --xpath '/set/id/text()' -` | |
res=$? | |
if test $res != 0; then | |
echo "HTTP request failed with return code $res" | |
exit $res | |
fi | |
echo "Setting the job payload to use set $SET_ID" | |
python - <<-EOF | |
from xml.etree import ElementTree as et | |
tree = et.parse("job.xml") | |
tree.find("parameters/parameter[name='set_id']/value").text = "$SET_ID" | |
tree.write("job.xml") | |
EOF | |
echo "Submitting the export job" | |
JOB_INSTANCE_URL=`curl -s --fail -X POST -H "Authorization: apikey $API_KEY" -H "Content-type: application/xml" -H "Accept: application/xml" --data @job.xml "https://api-na.hosted.exlibrisgroup.com/almaws/v1/conf/jobs/M44?op=run" | xmllint --xpath 'string(/job/additional_info/@link)' -` | |
res=$? | |
if test $res != 0; then | |
echo "HTTP request failed with return code $res" | |
exit $res | |
fi | |
echo "Checking the job status at $JOB_INSTANCE_URL" | |
until [[ "$JOB_STATUS" == "COMPLETED"* ]]; do | |
sleep 3 | |
curl -s --fail -H "Authorization: apikey $API_KEY" -H "Accept: application/xml" "$JOB_INSTANCE_URL" > job_instance.xml | |
JOB_PROGRESS=`xmllint --xpath '/job_instance/progress/text()' job_instance.xml` | |
JOB_STATUS=`xmllint --xpath '/job_instance/status/text()' job_instance.xml` | |
FILE_ID=`xmllint --xpath '/job_instance/counters/counter[type="c.jobs.bibExport.link"]/value/text()' job_instance.xml` | |
echo "Job progress: $JOB_PROGRESS; Job status: $JOB_STATUS" | |
done | |
if [ "$JOB_STATUS" = "COMPLETED_SUCCESS" ]; then | |
echo "Downloading the files for $FILE_ID" | |
lftp -c "connect sftp://$FTP_USER:$FTP_PASS@ftp.exlibrisgroup.com/public/TR_INTEGRATION_INST/export; mget *$FILE_ID*" | |
else | |
echo "Job not completed successfully. No files to download." | |
fi | |
echo "Deleting set $SET_ID" | |
curl -s --fail -X DELETE -H "Authorization: apikey $API_KEY" "https://api-na.hosted.exlibrisgroup.com/almaws/v1/conf/sets/$SET_ID" | |
echo "Done" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<job> | |
<parameters> | |
<parameter> | |
<name>task_ExportBibParams_outputFormat_string</name> | |
<value>MARC21_XML</value> | |
</parameter> | |
<parameter> | |
<name>task_ExportBibParams_outputRegistryFormat_string</name> | |
<value>3</value> | |
</parameter> | |
<parameter> | |
<name>task_ExportBibParams_maxSize_string</name> | |
<value>0</value> | |
</parameter> | |
<parameter> | |
<name>task_ExportBibParams_enrich_string</name> | |
<value>Null</value> | |
</parameter> | |
<parameter> | |
<name>task_ExportBibParams_exportFolder_string</name> | |
<value>PRIVATE</value> | |
</parameter> | |
<parameter> | |
<name>task_ExportParams_ftpConfig_string</name> | |
<value>85625670000561</value> | |
</parameter> | |
<parameter> | |
<name>task_ExportParams_ftpSubdirectory_string</name> | |
<value>export</value> | |
</parameter> | |
<parameter> | |
<name>set_id</name> | |
<value>2960292890000561</value> | |
</parameter> | |
<parameter> | |
<name>job_name</name> | |
<value>Export Bibliographic Records - via API - Export small test</value> | |
</parameter> | |
</parameters> | |
</job> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<set> | |
<name>Recent Binghamton Material</name> | |
<description></description> | |
<type desc="Logical">LOGICAL</type> | |
<content desc="All Titles">BIB_MMS</content> | |
<private desc="Yes">true</private> | |
<status desc="Active">ACTIVE</status> | |
<query>BIB_MMS where BIB_MMS (all CONTAIN "Binghamton" AND main_pub_date GREATER_EQUAL "2000") | |
</query> | |
</set> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For more information on this Gist, see this blog post.
To run this script, set the following environment variables:
API_KEY
: Key with read/write on the configuration APIsFTP_USER
andFTP_PASS
: Username and password for the specified FTP configuration.