#!/bin/bash

# Demo Script for location REST api
####################################

function log {
    echo
    echo $1
    echo "-------------------------------------------------------------------------------------------------------"
}

log "GET all Locations:"
./get-all-locations > all-locations.xml
cat all-locations.xml

log "DELETE all locations:"
./delete-all-locations

log "GET shows no more locations:"
./get-all-locations

log "POST the locations back:"
./post-locations all-locations.xml

log "GET shows they are back:"
./get-all-locations

log "POST some new locations - adding South Australia and Richmond,SA"
./post-locations demo-data-create-sa-richmond.xml

log "GET them individually and note the an HTTP 404 error indicates they are no longer there:"
./get-location d5f5ba1406dc4b6186212a7bd230e8d8
./get-location 3bf56b9493a64a618e71790c75e01315

log "Also the top-level 'Australia' location has refs to them:"
./get-location 5b14e33880bf47a2b23f8349e7bd2b6e

log "DELETE them one by one:"
./delete-location d5f5ba1406dc4b6186212a7bd230e8d8
./delete-location 3bf56b9493a64a618e71790c75e01315

log "attempt to GET them - will fail with 404 again because they are gone"
./get-location d5f5ba1406dc4b6186212a7bd230e8d8
./get-location 3bf56b9493a64a618e71790c75e01315

log "aditionally, their references are also gone from the top level 'Australia' location:"
./get-location 5b14e33880bf47a2b23f8349e7bd2b6e

log "GET the broker's ontology:"
./get-ontology > ontology.xml
cat ontology.xml

log "try to PUT to the ontology - will fail because there are active locations in the graph:"
./put-ontology ontology.xml

log "try to DELETE ontology - will fail for the same reason"
./delete-ontology

log "now DELETE all locations:"
./delete-all-locations

log "DELETEing the ontology should now work:"
./delete-ontology

log "but now POSTing the locations will fail without an ontology"
./post-locations all-locations.xml

log "so let's PUT it back:"
./put-ontology ontology.xml

log "and GET it back:"
./get-ontology

log "and re-POST the locations"
./post-locations all-locations.xml
