diff --git a/login.sh b/login.sh new file mode 100755 index 0000000000000000000000000000000000000000..be0642cd373e1cd321614f3522f4cdd94ee002de --- /dev/null +++ b/login.sh @@ -0,0 +1,25 @@ +EMAIL=${1} +PASSWORD=${2} + +DSPACEURL="https://localhost:8443/rest" +TYPE="json" +VERB="POST" +ACTION="login" + +if [ $# != 2 ]; then + echo -e "ERROR! Wrong number parameter!" + echo -e "USE:" + echo -e "${0} <USER> <PASSWORD>" + exit 1 +fi + +RQST="{ + \"email\":\"${EMAIL}\", + \"password\":\"${PASSWORD}\" +}" + +curl -k -4 \ + -H "accept: application/${TYPE}" \ + -H "Content-Type: application/${TYPE}" \ + -X ${VERB} "${DSPACEURL}/${ACTION}" \ + -d "${RQST}" diff --git a/logout.sh b/logout.sh new file mode 100755 index 0000000000000000000000000000000000000000..77171b15808925befcdd455d12955d480ddcbba5 --- /dev/null +++ b/logout.sh @@ -0,0 +1,24 @@ +TOKEN=${1} + +DSPACEURL="https://localhost:8443/rest" +TYPE="json" +VERB="POST" +ACTION="logout" + +if [ $# != 1 ]; then + echo -e "ERROR! Wrong number parameter!" + echo -e "USE:" + echo -e "${0} <TOKEN>" + exit 1 +fi + +RQST="{ + \"email\":\"${EMAIL}\", + \"password\":\"${PASSWORD}\" +}" + +curl -k -4 \ + -H "rest-dspace-token: ${TOKEN}" \ + -H "accept: application/${TYPE}" \ + -H "Content-Type: application/${TYPE}" \ + -X ${VERB} "${DSPACEURL}/${ACTION}" diff --git a/requests/GET_status.sh b/requests/GET_status.sh new file mode 100644 index 0000000000000000000000000000000000000000..c0abf96ec0413360ff3f87febd9c731e9a273439 --- /dev/null +++ b/requests/GET_status.sh @@ -0,0 +1,10 @@ +# {} + +USER="admin@dspace.com" +PASS="admin" + +VERB="GET" +ACTION="status" + +RQST_JSON='[]' +RQST_XML='' diff --git a/requests/POST_add-items-metadata.sh b/requests/POST_add-items-metadata.sh new file mode 100644 index 0000000000000000000000000000000000000000..d70fea24714a020292cfd5a0783016ce13e1598e --- /dev/null +++ b/requests/POST_add-items-metadata.sh @@ -0,0 +1,23 @@ +# {} + +VERB="POST" +ACTION="items/11/metadata" + +RQST_JSON=' +[ + { + "key": "dc.title", + "value": "ADDED BY JSON (POST)", + "language": "en_US" + }, + { + "key": "dc.description", + "value": "ADDED BY JSON", + "language": "en_US" + } +] +' + +RQST_XML='<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +??? +' diff --git a/requests/POST_new-collections.sh b/requests/POST_new-collections.sh new file mode 100644 index 0000000000000000000000000000000000000000..7217d2d8e232e730f289dfa2c70ff324aca04b0f --- /dev/null +++ b/requests/POST_new-collections.sh @@ -0,0 +1,25 @@ +# {"id":3,"name":"CREATED BY JSON (POST)","handle":"123456789/17","type":"collection","link":"/RESTapi/collections/3","expand":["parentCommunityList","parentCommunity","items","license","logo","all"],"logo":null,"parentCommunity":null,"parentCommunityList":[],"items":[],"license":null,"copyrightText":"CREATED BY JSON (POST)","introductoryText":"CREATED BY JSON (POST)","shortDescription":"CREATED BY JSON (POST)","sidebarText":"CREATED BY JSON (POST)","numberItems":0} + +VERB="POST" +ACTION="communities/1/collections" + +RQST_JSON=' +{ + "name":"CREATED BY JSON (POST)", + "copyrightText":"CREATED BY JSON (POST)", + "introductoryText":"CREATED BY JSON (POST)", + "shortDescription":"CREATED BY JSON (POST)", + "sidebarText":"CREATED BY JSON (POST)" +} +' + +RQST_XML='<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<collection> + <name>CREATED BY XML (POST)</name> + <type>CREATED BY XML (POST)</type> + <copyrightText>CREATED BY XML (POST)</copyrightText> + <introductoryText>CREATED BY XML (POST)</introductoryText> + <shortDescription>CREATED BY XML (POST)</shortDescription> + <sidebarText>CREATED BY XML (POST)</sidebarText> +</collection> +' diff --git a/requests/POST_new-communities.sh b/requests/POST_new-communities.sh new file mode 100644 index 0000000000000000000000000000000000000000..61db61221e0aff33573f164471805b420c2d7548 --- /dev/null +++ b/requests/POST_new-communities.sh @@ -0,0 +1,25 @@ +# {"id":2,"name":"CREATED BY JSON (POST)","handle":"123456789/19","type":"community","link":"/RESTapi/communities/2","expand":["parentCommunity","collections","subCommunities","logo","all"],"logo":null,"parentCommunity":null,"copyrightText":"CREATED BY JSON (POST)","introductoryText":"CREATED BY JSON (POST)","shortDescription":"CREATED BY JSON (POST)","sidebarText":"CREATED BY JSON (POST)","countItems":0,"subcommunities":[],"collections":[]} + +VERB="POST" +ACTION="communities" + +RQST_JSON=' +{ + "name":"CREATED BY JSON (POST)", + "copyrightText":"CREATED BY JSON (POST)", + "introductoryText":"CREATED BY JSON (POST)", + "shortDescription":"CREATED BY JSON (POST)", + "shortDescription":"CREATED BY JSON (POST)", + "sidebarText":"CREATED BY JSON (POST)" +} +' + +RQST_XML='<?xml version="1.0" encoding="UTF-8" standalone="yes"?> + <community> + <name>CREATED BY XML (POST)</name> + <copyrightText>CREATED BY XML (POST)</copyrightText> + <introductoryText>CREATED BY XML (POST)</introductoryText> + <shortDescription>CREATED BY XML (POST)</shortDescription> + <sidebarText>CREATED BY XML (POST)</sidebarText> + </community> +' diff --git a/requests/POST_new-items.sh b/requests/POST_new-items.sh new file mode 100644 index 0000000000000000000000000000000000000000..7470739ca406d1ec8b61d7cce651415ab92fa010 --- /dev/null +++ b/requests/POST_new-items.sh @@ -0,0 +1,52 @@ +# {"id":12,"name":"TESTE 1","handle":"123456789/14","type":"item","link":"/RESTapi/items/12","expand":["metadata","parentCollection","parentCollectionList","parentCommunityList","bitstreams","all"],"lastModified":"2015-01-29 15:51:04.049","parentCollection":null,"parentCollectionList":null,"parentCommunityList":null,"bitstreams":null,"archived":"true","withdrawn":"false"} + +VERB="POST" +ACTION="collections/1/items" + +RQST_JSON=' +{"metadata":[ + { + "key": "dc.contributor.author", + "value": "LAST, FIRST" + }, + { + "key": "dc.description", + "language": "pt_BR", + "value": "DESCRICAO" + }, + { + "key": "dc.description.abstract", + "language": "pt_BR", + "value": "ABSTRACT" + }, + { + "key": "dc.title", + "language": "pt_BR", + "value": "TESTE 1" + } +]} +' + +RQST_XML='<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<item> + <metadata> + <key>dc.contributor.author</key> + <value>LAST, FIRST</value> + <language>en_US</language> + </metadata> + <metadata> + <key>dc.description</key> + <value>DESCRIPTION</value> + <language>en_US</language> + </metadata> + <metadata> + <key>dc.description.abstract</key> + <value>ABSTRACT</value> + <language>en_US</language> + </metadata> + <metadata> + <key>dc.title</key> + <value>TITLE</value> + <language>en_US</language> + </metadata> +</item>' diff --git a/requests/POST_new-subcommunities.sh b/requests/POST_new-subcommunities.sh new file mode 100644 index 0000000000000000000000000000000000000000..27027d76e87f353e5356bd3b8aefea560d30ee97 --- /dev/null +++ b/requests/POST_new-subcommunities.sh @@ -0,0 +1,25 @@ +# {"id":4,"name":"CREATED BY JSON (POST)","handle":"123456789/21","type":"community","link":"/RESTapi/communities/4","expand":["parentCommunity","collections","subCommunities","logo","all"],"logo":null,"parentCommunity":null,"copyrightText":"CREATED BY JSON (POST)","introductoryText":"CREATED BY JSON (POST)","shortDescription":"CREATED BY JSON (POST)","sidebarText":"CREATED BY JSON (POST)","countItems":0,"subcommunities":[],"collections":[]} + +VERB="POST" +ACTION="communities/1/communities" + +RQST_JSON=' +{ + "name":"CREATED BY JSON (POST)", + "copyrightText":"CREATED BY JSON (POST)", + "introductoryText":"CREATED BY JSON (POST)", + "shortDescription":"CREATED BY JSON (POST)", + "shortDescription":"CREATED BY JSON (POST)", + "sidebarText":"CREATED BY JSON (POST)" +} +' + +RQST_XML='<?xml version="1.0" encoding="UTF-8" standalone="yes"?> + <community> + <name>CREATED BY XML (POST)</name> + <copyrightText>CREATED BY XML (POST)</copyrightText> + <introductoryText>CREATED BY XML (POST)</introductoryText> + <shortDescription>CREATED BY XML (POST)</shortDescription> + <sidebarText>CREATED BY XML (POST)</sidebarText> + </community> +' diff --git a/requests/PUT_edit-bitstreams.sh b/requests/PUT_edit-bitstreams.sh new file mode 100644 index 0000000000000000000000000000000000000000..c7c8e5f912b3e04a2f373895740f9e23b76fca03 --- /dev/null +++ b/requests/PUT_edit-bitstreams.sh @@ -0,0 +1,18 @@ +# {} + +VERB="PUT" +ACTION="bitstreams/32" + +RQST_JSON=' +{ +"name":"FILE_NAME.pdf", +"description":"DESCRIPTION OF THE FILE" +} +' + +RQST_XML='<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<bitstream> +<name>FILE_NAME.pdf</name> +<description>DESCRIPTION OF THE FILE</description> +</bitstream> +' diff --git a/requests/PUT_edit-collections.sh b/requests/PUT_edit-collections.sh new file mode 100644 index 0000000000000000000000000000000000000000..44c5fb2a41c7ff677b5d1d0529ee1cf8f073691c --- /dev/null +++ b/requests/PUT_edit-collections.sh @@ -0,0 +1,24 @@ +# {} + +VERB="PUT" +ACTION="collections/2" + +RQST_JSON=' +{ + "name":"CHANGED BY JSON (PUT)", + "type":"CHANGED BY JSON (PUT)", + "copyrightText":"CHANGED BY JSON (PUT)", + "introductoryText":"CHANGED BY JSON (PUT)", + "shortDescription":"CHANGED BY JSON (PUT)", + "sidebarText":"CHANGED BY JSON (PUT)" +}' + +RQST_XML='<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<collection> + <name>CHANGED BY XML (PUT)</name> + <type>CHANGED BY XML (PUT)</type> + <copyrightText>CHANGED BY XML (PUT)</copyrightText> + <introductoryText>CHANGED BY XML (PUT)</introductoryText> + <shortDescription>CHANGED BY XML (PUT)</shortDescription> + <sidebarText>CHANGED BY XML (PUT)</sidebarText> +</collection>' diff --git a/requests/PUT_edit-communities.sh b/requests/PUT_edit-communities.sh new file mode 100644 index 0000000000000000000000000000000000000000..fc4fd9a9f1b493a1a134caadd10e32ad74d0c2f1 --- /dev/null +++ b/requests/PUT_edit-communities.sh @@ -0,0 +1,26 @@ +# {} + +VERB="PUT" +ACTION="communities/2" +TYPE="json" + +RQST_JSON=' +{ + "name":"CHANGED BY JSON (POST)", + "copyrightText":"CHANGED BY JSON (POST)", + "introductoryText":"CHANGED BY JSON (POST)", + "shortDescription":"CHANGED BY JSON (POST)", + "shortDescription":"CHANGED BY JSON (POST)", + "sidebarText":"CHANGED BY JSON (POST)" +} +' + +RQST_XML='<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<community> + <name>CHANGED BY XML (POST)</name> + <copyrightText>CHANGED BY XML (POST)</copyrightText> + <introductoryText>CHANGED BY XML (POST)</introductoryText> + <shortDescription>CHANGED BY XML (POST)</shortDescription> + <sidebarText>CHANGED BY XML (POST)</sidebarText> +</community> +' diff --git a/requests/PUT_edit-items.sh b/requests/PUT_edit-items.sh new file mode 100644 index 0000000000000000000000000000000000000000..a76646d5bae4292f0ed7004703f351e34a39170d --- /dev/null +++ b/requests/PUT_edit-items.sh @@ -0,0 +1,24 @@ +# {} + +VERB="PUT" +ACTION="items/11/metadata" +TYPE="json" + +RQST_JSON=' +[ + { + "key": "dc.title", + "value": "TESTE - CHANGED BY JSON (PUT)", + "language": "pt_BR" + }, + { + "key": "dc.description", + "value": "DESCRIPTION - CHANGED BY JSON", + "language": "pt_BR" + } +] +' + +RQST_XML='<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +??? +' diff --git a/requests/UPLOAD_edit-bitstreams.sh b/requests/UPLOAD_edit-bitstreams.sh new file mode 100644 index 0000000000000000000000000000000000000000..25d6bf3c628fc8257400cab5a9e924cead9c84f0 --- /dev/null +++ b/requests/UPLOAD_edit-bitstreams.sh @@ -0,0 +1,5 @@ +# {} + +VERB="PUT" +ACTION="bitstreams/32/data" +FILE="/home/bruno/C3SL/projeto-mec/testes-rest/v_ShellScript/requests/files/DSpaceREST_index.html" diff --git a/requests/UPLOAD_new-bitstreams.sh b/requests/UPLOAD_new-bitstreams.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2b8b67f5742bb0c272fa3a1c30b6b285f92ccd6 --- /dev/null +++ b/requests/UPLOAD_new-bitstreams.sh @@ -0,0 +1,7 @@ +# <?xml version="1.0" encoding="UTF-8" standalone="yes"?><bitstream><expand>parent</expand><expand>policies</expand><expand>all</expand><id>35</id><type>bitstream</type><bundleName>ORIGINAL</bundleName><checkSum checkSumAlgorithm="MD5">357ca1187f7eb6a580fec95fb3cec6f7</checkSum><format>Unknown</format><mimeType>application/octet-stream</mimeType><retrieveLink>/bitstreams/35/retrieve</retrieveLink><sequenceId>-1</sequenceId><sizeBytes>99021</sizeBytes></bitstream> + +# {"id":37,"name":null,"handle":null,"type":"bitstream","link":"/RESTapi/bitstreams/37","expand":["parent","policies","all"],"bundleName":"ORIGINAL","description":null,"format":"Unknown","mimeType":"application/octet-stream","sizeBytes":99021,"parentObject":null,"retrieveLink":"/bitstreams/37/retrieve","checkSum":{"value":"791274902ccd308c8a411e0d3395ec03","checkSumAlgorithm":"MD5"},"sequenceId":-1,"policies":null} + +VERB="POST" +ACTION="items/11/bitstreams" +FILE="/home/bruno/C3SL/projeto-mec/testes-rest/v_ShellScript/requests/files/pdf1.pdf" diff --git a/requests/files/DSpaceREST_index.html b/requests/files/DSpaceREST_index.html new file mode 100644 index 0000000000000000000000000000000000000000..b0c36e1de2a25bec883cdcd208af5da240c4ebf6 --- /dev/null +++ b/requests/files/DSpaceREST_index.html @@ -0,0 +1,3 @@ + +<!-- saved from url=(0029)https://demo.dspace.org/rest/ --> +<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>DSpace REST - index</title><style type="text/css"></style></head><body><h1>DSpace REST API</h1>Server path: /rest<h2>Index</h2><ul><li>GET / - Return this page.</li><li>GET /test - Return the string "REST api is running" for testing purposes.</li><li>POST /login - Method for logging into the DSpace RESTful API. You must post User class. Example: {"email":"test@dspace","password":"pass"}. Returns a token which must be included in future requests in the "rest-dspace-token" header.</li><li>POST /logout - Method for logging out of the DSpace RESTful API. The request must include the "rest-dspace-token" token</li> header.</ul><h2>Communities</h2><ul><li>GET /communities - Return an array of all communities in DSpace.</li><li>GET /communities/top-communities - Returns an array of all top-leve communities in DSpace.</li><li>GET /communities/{communityId} - Returns a community with the specified ID.</li><li>GET /communities/{communityId}/collections - Returns an array of collections of the specified community.</li><li>GET /communities/{communityId}/communities - Returns an array of subcommunities of the specified community.</li><li>POST /communities - Create a new top-level community. You must post a community.</li><li>POST /communities/{communityId}/collections - Create a new collection in the specified community. You must post a collection.</li><li>POST /communities/{communityId}/communities - Create a new subcommunity in the specified community. You must post a community.</li><li>PUT /communities/{communityId} - Update the specified community.</li><li>DELETE /communities/{communityId} - Delete the specified community.</li><li>DELETE /communities/{communityId}/collections/{collectionId} - Delete the specified collection in the specified community.</li><li>DELETE /communities/{communityId}/communities/{communityId2} - Delete the specified subcommunity (communityId2) in the specified community (communityId).</li></ul><h2>Collections</h2><ul><li>GET /collections - Return all DSpace collections in array.</li><li>GET /collections/{collectionId} - Return a collection with the specified ID.</li><li>GET /collections/{collectionId}/items - Return all items of the specified collection.</li><li>POST /collections/{collectionId}/items - Create an item in the specified collection. You must post an item.</li><li>POST /collections/find-collection - Find a collection by name.</li><li>PUT /collections/{collectionId} </li> - Update the specified collection. You must post a collection.<li>DELETE /collections/{collectionId} - Delete the specified collection from DSpace.</li><li>DELETE /collections/{collectionId}/items/{itemId} - Delete the specified item (itemId) in the specified collection (collectionId). </li></ul><h2>Items</h2><ul><li>GET /items - Return a list of items.</li><li>GET /items/{item id} - Return the specified item.</li><li>GET /items/{item id}/metadata - Return metadata of the specified item.</li><li>GET /items/{item id}/bitstreams - Return bitstreams of the specified item.</li><li>POST /items/find-by-metadata-field - Find items by the specified metadata value.</li><li>POST /items/{item id}/metadata - Add metadata to the specified item.</li><li>POST /items/{item id}/bitstreams - Add a bitstream to the specified item.</li><li>PUT /items/{item id}/metadata - Update metadata in the specified item.</li><li>DELETE /items/{item id} - Delete the specified item.</li><li>DELETE /items/{item id}/metadata - Clear metadata of the specified item.</li><li>DELETE /items/{item id}/bitstreams/{bitstream id} - Delete the specified bitstream of the specified item.</li></ul><h2>Bitstreams</h2><ul><li>GET /bitstreams - Return all bitstreams in DSpace.</li><li>GET /bitstreams/{bitstream id} - Return the specified bitstream.</li><li>GET /bitstreams/{bitstream id}/policy - Return policies of the specified bitstream.</li><li>GET /bitstreams/{bitstream id}/retrieve - Return the contents of the specified bitstream.</li><li>POST /bitstreams/{bitstream id}/policy - Add a policy to the specified bitstream.</li><li>PUT /bitstreams/{bitstream id}/data - Update the contents of the specified bitstream.</li><li>PUT /bitstreams/{bitstream id} - Update metadata of the specified bitstream.</li><li>DELETE /bitstreams/{bitstream id} - Delete the specified bitstream from DSpace.</li><li>DELETE /bitstreams/{bitstream id}/policy/{policy_id} - Delete the specified bitstream policy.</li></ul> </body></html> \ No newline at end of file diff --git a/requests/files/pdf1.pdf b/requests/files/pdf1.pdf new file mode 100644 index 0000000000000000000000000000000000000000..0f55751f9e99a5326777e55d8c03a473237c572d Binary files /dev/null and b/requests/files/pdf1.pdf differ diff --git a/send_file.sh b/send_file.sh new file mode 100755 index 0000000000000000000000000000000000000000..667e11f5184bce5dd1a8ae4ce514bc86ab6c55bd --- /dev/null +++ b/send_file.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +if [ $# != 4 ]; then + echo -e "ERRO! Wrong number parameter!" + echo -e "USE:" + echo -e "${0} <DSPACEURL> <TOKEN> <REQUEST_DECRIPTOR_FILE> <REQUEST_TYPE [\"json\"/\"xml\"]>" + exit 1 +fi + +DSPACEURL=${1} +TOKEN=${2} +REQUEST=${3} +REQUEST_TYPE=${4} + +if [ -e ${REQUEST} ]; then + source $REQUEST +else + echo "ERROR! Request descriptor file not found!" + exit 1 +fi + +curl -k -4 \ + -H "rest-dspace-token: ${TOKEN}" \ + -H "accept: application/${REQUEST_TYPE}" \ + -X ${VERB} "${DSPACEURL}/${ACTION}" \ + -F upload=@"${FILE}" diff --git a/send_request.sh b/send_request.sh new file mode 100755 index 0000000000000000000000000000000000000000..209995af4e89ae5515dfeb60372a79185cddd6a8 --- /dev/null +++ b/send_request.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +if [ $# != 4 ]; then + echo -e "ERRO! Wrong number parameter!" + echo -e "USE:" + echo -e "${0} <DSPACEURL> <TOKEN> <REQUEST_DECRIPTOR_FILE> <REQUEST_TYPE [\"json\"/\"xml\"]>" + exit 1 +fi + +DSPACEURL=${1} +TOKEN=${2} +REQUEST=${3} +REQUEST_TYPE=${4} + +if [ -e ${REQUEST} ]; then + source $REQUEST +else + echo "ERROR! Request descriptor file not found!" + exit 1 +fi + +case ${REQUEST_TYPE} in + "json") RQST=${RQST_JSON} ;; + "xml") RQST=${RQST_XML} ;; + *) echo -e "ERROR! TYPE MUST BE: \"json\" OR \"xml\"."; exit 1 ;; +esac + +curl -k -4 --silent\ + -H "rest-dspace-token: ${TOKEN}" \ + -H "accept: application/${REQUEST_TYPE}" \ + -H "Content-Type: application/${REQUEST_TYPE}" \ + -X ${VERB} "${DSPACEURL}/${ACTION}" \ + -d "${RQST}" diff --git a/test_all_requests.sh b/test_all_requests.sh new file mode 100755 index 0000000000000000000000000000000000000000..5ad33f5f20c33990162e47a866c7d73055898393 --- /dev/null +++ b/test_all_requests.sh @@ -0,0 +1,40 @@ +DSPACEURL="https://localhost:8443/rest" +EMAIL="admin@dspace.com" +PASSWORD="admin" + +TOKEN=$(./login.sh ${EMAIL} ${PASSWORD}) + +for R in $(ls requests/POST_*); do + for T in json xml; do + echo "EXECUTING REQUEST: $R ($T):" + echo "--------------------------------------------" + ./send_request.sh $DSPACEURL $TOKEN $R $T + echo "" + echo "--------------------------------------------" + echo "" + done +done + +for R in $(ls requests/PUT_*); do + for T in json xml; do + echo "EXECUTING REQUEST: $R ($T):" + echo "--------------------------------------------" + ./send_request.sh $DSPACEURL $TOKEN $R $T + echo "" + echo "--------------------------------------------" + echo "" + done +done + +for R in $(ls requests/UPLOAD_*); do + for T in json xml; do + echo "EXECUTING REQUEST: $R ($T):" + echo "--------------------------------------------" + ./send_file.sh $DSPACEURL $TOKEN $R $T + echo "" + echo "--------------------------------------------" + echo "" + done +done + +./logout.sh ${TOKEN}