Old Release

This documentation covers an old version of Fedora. Looking for another version? See all documentation.

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 27 Next »

This feature is available in the Fedora 4 Alpha 2 release.

This page provides detailed steps for creating repository content via the REST API, and SPARQL queries to demonstrate that content in the triplestore.  Much more information about the REST API is available at: RESTful HTTP API and Another Take on the REST API .

1. Finding Objects by Datastream Name or MIME Type

Create a few sample objects with either a PDF or a text file, or both attached as datastreams (these commands assume you have two files named test.pdf and test.txt in your current working directory, please substitute working filenames as needed):

File: object-indexing.rdf
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX indexing: <http://fedora.info/definitions/v4/indexing#>
DELETE { }
INSERT { 
  <> indexing:hasIndexingTransformation "default";
  rdf:type indexing:indexable }
WHERE { }
1a. Creating Sample Objects
curl -X POST -H "Content-type: application/sparql-update" --data-binary "@object-indexing.rdf" "http://localhost:8080/rest/objects/101"
curl -X POST -H "Content-type: application/pdf" --data-binary "@test.pdf" "http://localhost:8080/rest/objects/101/master/fcr:content"
curl -X POST -H "Content-type: application/sparql-update" --data-binary "@object-indexing.rdf" "http://localhost:8080/rest/objects/102
curl -X POST -H "Content-type: text/plain" --data-binary "@test.txt" "http://localhost:8080/rest/objects/102/master/fcr:content"
curl -X POST -H "Content-type: application/sparql-update" --data-binary "@object-indexing.rdf" "http://localhost:8080/rest/objects/103"
curl -X POST -H "Content-type: application/pdf" --data-binary "@test.pdf" "http://localhost:8080/rest/objects/103/master/fcr:content"
curl -X POST -H "Content-type: text/plain" --data-binary "@test.txt" "http://localhost:8080/rest/objects/103/text/fcr:content"

Find objects with a datastream named "text":

1b. Selecting Objects With Datastreams Named "text"
prefix fcrepo: <http://fedora.info/definitions/v4/repository#>
select ?object where { ?ds fcrepo:mixinTypes "fedora:datastream" .
    ?ds fcrepo:hasParent ?object . filter(str(?ds)=concat(str(?object),'/text')) }
Expected Results
object
<http://localhost:8080/rest/objects/103>

Find objects with a PDF datastream:

1c. Selecting Objects With PDF Datastreams
prefix fcrepo: <http://fedora.info/definitions/v4/repository#>
select ?object where { ?ds fcrepo:mixinTypes "fedora:datastream" .
    ?ds fcrepo:hasParent ?object . ?ds fcrepo:hasContent ?content .
    ?content fcrepo:mimeType "application/pdf" }
Expected Results
object
<http://localhost:8080/rest/objects/101>
<http://localhost:8080/rest/objects/103>

2. Attach metadata properties directly to objects

Create an object and attach the dc:title property:

2a. Creating Sample Objects
curl -X POST http://localhost:8080/rest/objects/201
echo "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix index: <http://fedora.info/definitions/v4/indexing#>  insert data { <> rdf:type index:indexable . }" \
| curl -X PATCH --upload-file - http://localhost:8080/rest/objects/201
echo "prefix dc: <http://purl.org/dc/elements/1.1/> insert data { <http://localhost:8080/rest/objects/201> dc:title 'Foo' . }" \
| curl -X PATCH --upload-file - http://localhost:8080/rest/objects/201

Find objects with titles:

2b. Selecting Objects With Titles
prefix dc: <http://purl.org/dc/elements/1.1/>
select ?object ?title where { ?object dc:title ?title }
Expected Results
object     title
<http://localhost:8080/rest/objects/201>"Foo"

3. Find Objects By Collection Membership

Create three objects and three collections:

3a. Creating Sample Objects And Collections
curl -X POST http://localhost:8080/rest/objects/col1
curl -X POST http://localhost:8080/rest/objects/col2
curl -X POST http://localhost:8080/rest/objects/col3
curl -X POST http://localhost:8080/rest/objects/obj1
curl -X POST http://localhost:8080/rest/objects/obj2
curl -X POST http://localhost:8080/rest/objects/obj3

Mark the objects indexable:

3b. Marking objects indexable
echo "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix index: <http://fedora.info/definitions/v4/indexing#>  insert data { <> rdf:type index:indexable . }" \
| curl -X PATCH --upload-file - http://localhost:8080/rest/objects/obj1
echo "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix index: <http://fedora.info/definitions/v4/indexing#>  insert data { <> rdf:type index:indexable . }" \
| curl -X PATCH --upload-file - http://localhost:8080/rest/objects/obj2
echo "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix index: <http://fedora.info/definitions/v4/indexing#>  insert data { <> rdf:type index:indexable . }" \
| curl -X PATCH --upload-file - http://localhost:8080/rest/objects/obj3

Link each object to a collection:

3c. Linking Objects To Collections
echo 'insert data { <http://localhost:8080/rest/objects/obj1> <http://fedora.info/definitions/v4/rels-ext#isMemberOfCollection> <http://localhost:8080/rest/objects/col1> . }' | curl -X PATCH --upload-file - http://localhost:8080/rest/objects/obj1
echo 'insert data { <http://localhost:8080/rest/objects/obj2> <http://fedora.info/definitions/v4/rels-ext#isMemberOfCollection> <http://localhost:8080/rest/objects/col2> . }' | curl -X PATCH --upload-file - http://localhost:8080/rest/objects/obj2
echo 'insert data { <http://localhost:8080/rest/objects/obj3> <http://fedora.info/definitions/v4/rels-ext#isMemberOfCollection> <http://localhost:8080/rest/objects/col3> . }' | curl -X PATCH --upload-file - http://localhost:8080/rest/objects/obj3

Link the collections in a hierarchy:

3d. Linking Collections In A Hierarchy
echo 'insert data { <http://localhost:8080/rest/objects/col1> <http://fedora.info/definitions/v4/rels-ext#hasPart> <http://localhost:8080/rest/objects/col2> . }' | curl -X PATCH --upload-file - http://localhost:8080/rest/objects/col1
echo 'insert data { <http://localhost:8080/rest/objects/col2> <http://fedora.info/definitions/v4/rels-ext#hasPart> <http://localhost:8080/rest/objects/col3> . }' | curl -X PATCH --upload-file - http://localhost:8080/rest/objects/col2

Find objects directly attached to a collection:

3e. Selecting Objects Directly Linked To A Collection
select ?obj ?col where { ?obj <http://fedora.info/definitions/v4/rels-ext#isMemberOfCollection> ?col }
Expected Results
objcol
<http://localhost:8080/rest/objects/obj1><http://localhost:8080/rest/objects/col1>
<http://localhost:8080/rest/objects/obj2><http://localhost:8080/rest/objects/col2>
<http://localhost:8080/rest/objects/obj3><http://localhost:8080/rest/objects/col3>

Find objects directly or indirectly attached (recursive retrieval along the rels:hasPart chain).  Applications developed using Fedora 3 may use Mulgara's walk() function for queries that navigate a hierarchy.  That functionality is now part of standard SPARQL 1.1 (Jena's property paths documentation provides some good examples).

3f. Select Objects Directly Or Indirectly Linked To A Collection
prefix rels: <http://fedora.info/definitions/v4/rels-ext#>
select ?obj where {
  { ?obj rels:isMemberOfCollection <http://localhost:8080/rest/objects/col1> }
  UNION
  { <http://localhost:8080/rest/objects/col1> rels:hasPart+ ?col . ?obj rels:isMemberOfCollection ?col }
}
Expected Results
obj
<http://localhost:8080/rest/objects/obj1>
<http://localhost:8080/rest/objects/obj2>
<http://localhost:8080/rest/objects/obj3>

Also link an object to a project:

3g. Select Objects Directly Or Indirectly Linked To A Collection
curl -X POST http://localhost:8080/rest/objects/proj1
echo "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix index: <http://fedora.info/definitions/v4/indexing#>  insert data { <> rdf:type index:indexable . }" \
| curl -X PATCH --upload-file - http://localhost:8080/rest/objects/proj1
echo 'prefix ex: <http://example.org/> insert data { <http://localhost:8080/rest/obj1> ex:project <http://localhost:8080/rest/proj1> . }" \
| curl -X PATCH --upload-file - http://localhost:8080/rest/obj1

Find objects in a collection or linked to a project:

3h. Select Objects Linked To A Collection or A Project
prefix rels: <http://fedora.info/definitions/v4/rels-ext#>
prefix ex: <http://example.org/>
select ?obj where {
  { ?obj ex:project <http://localhost:8080/rest/objects/proj1> }
  UNION
  { ?obj rels:isMemberOfCollection <http://localhost:8080/rest/objects/col2> }
 }
Expected Results
obj
<http://localhost:8080/rest/objects/obj1>
<http://localhost:8080/rest/objects/obj2>

Count objects instead of listing them:

3i. Count the Objects Linked to a Collection or a Project
prefix rels: <http://fedora.info/definitions/v4/rels-ext#>
prefix ex: <http://example.org/>
select (count(distinct ?obj) as ?count) where {
  { ?obj ex:project <http://localhost:8080/rest/objects/proj1> }
  UNION
  { ?obj rels:isMemberOfCollection <http://localhost:8080/rest/objects/col2> }
}
Expected Results
count
"2"^^<http://www.w3.org/2001/XMLSchema#integer>
  • No labels