Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

F4 alpha 2

Table of Contents
maxLevel3

Excerpt

This page provides detailed steps for creating repository content via the REST API, and SPARQL queries to demonstrate that content in the triplestorehas been synchronized to an external triplestore.  For more details on setting up triplestore sync, see External Triplestore.  Much more information about the REST API is available at: RESTful HTTP API and Another Take on the REST API .

1. Finding

...

Containers by

...

Binary Name or MIME Type

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

Code Block
titleFile: objectcontainer-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 { }
Code Block
languagebash
title1a. Creating Sample ObjectsContainers
curl -X POSTPUT -H "Content-type: application/sparql-"http://localhost:8080/rest/objects/101"
curl -X PATCH -H "Content-type: application/sparql-update" --data-binary "@object-indexing.rdf" "http://localhost:8080/rest/objects/101"
curl -X POSTPUT -H "Content-type: application/pdf" --data-binary "@test.pdf" "http://localhost:8080/rest/objects/101/master/fcr:content"
curl -X POSTPATCH -H "Content-type: application/sparql-update" --data-binary "@object-indexing.rdf" "http://localhost:8080/rest/objects/102101/master/fcr:metadata"
curl -X POSTPUT -H "Content-type: text/plain" --data-binary "@test.txt" "http://"http://localhost:8080/rest/objects/102/master/fcr:content"
curl -X POSTPATCH -H "Content-type: application/sparql-update" --data-binary "@object-indexing.rdf" "http://localhost:8080/rest/objects/103102"
curl -X POSTPUT -H "Content-type: applicationtext/pdfplain" --data-binary "@test.pdftxt" "http://localhost:8080/rest/objects/103102/master/fcr:content"
curl -X POSTPATCH -H "Content-type: textapplication/plainsparql-update" --data-binary "@test@object-indexing.txtrdf" "http://localhost:8080/rest/objects/103102/textmaster/fcr:content"

Find objects with a datastream named "text":

Code Block
languagesql
title1b. 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:

Code Block
languagesql
title1c. 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:

Code Block
languagebash
title2a. Creating Sample Objects
curl -X POST metadata"
curl -X PUT "http://localhost:8080/rest/objects/103"
curl -X PATCH -H "Content-type: application/sparql-update" --data-binary "@object-indexing.rdf" "http://localhost:8080/rest/objects/103"
curl -X PUT -H "Content-type: application/pdf" --data-binary "@test.pdf" "http://localhost:8080/rest/objects/103/master"
curl -X PUT -H "Content-type: text/plain" --data-binary "@test.txt" "http://localhost:8080/rest/objects/103/text"
curl -X PATCH -H "Content-type: application/sparql-update" --data-binary "@object-indexing.rdf" "http://localhost:8080/rest/objects/103/master/fcr:metadata"
curl -X PATCH -H "Content-type: application/sparql-update" --data-binary "@object-indexing.rdf" "http://localhost:8080/rest/objects/201
echo "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-/103/text/fcr:metadata"

Find containers with a binary named "text":

Code Block
languagesql
title1b. Selecting Containers With Binaries Named "text"
prefix fcrepons#> prefix index: <http://fedora.info/definitions/v4/indexing#>  insert data { <> rdf:type index:indexable . }" \
| curl -X PATCH --upload-file - http://repository#>
select ?object where { 
    ?ds fcrepo:mixinTypes "fedora:NonRdfSourceDescription" .
    ?ds fcrepo:hasParent ?object . 
    filter(str(?ds)=concat(str(?object),'/text/fcr:metadata')) 
}
Expected Results
container
<http://localhost:8080/rest/objects/

...

103>

Find containers with a PDF binary:

Code Block
languagesql
title1c. Selecting Containers With PDF Binaries
prefix fcrepo: <http://fedora.info/definitions/v4/repository#>
prefix relation: <http://www.iana.org/assignments/relation/>
select ?object where { 
    ?ds fcrepo:mixinTypes "fedora:NonRdfSourceDescription" .
    ?ds fcrepo:hasParent ?object . 
    ?ds relation:describes ?content .
    ?content fcrepo:mimeType "application/pdf" 
}
Expected Results
container
<http://localhost:8080/rest/objects/

...

101>
<http://localhost:8080/rest/objects/103>

2. Attach metadata properties directly to containers

Create an container and attach the dc:title property:

Find objects with titles:

Code Block
languagesqlbash
title2b. 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:

2a. Creating Sample Containers
curl -X PUT 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 containers with titles:

Code Block
languagesql
title2b. Selecting Containers With Titles
prefix dc: <http://purl.org/dc/elements/1.1/>
select ?object ?title where { ?object dc:title ?title }
Expected Results
container     title
<http://localhost:8080/rest/objects/201>"Foo"

3. Find Containers By Collection Membership

Create three containers and three collections:

Code Block
languagebash
title3a. Creating Sample Containers And Collections
curl -X PUT http://localhost:8080/rest/objects/col1
curl -X PUT http://localhost:8080/rest/objects/col2
curl -X PUT http://localhost:8080/rest/objects/col3
curl -X PUT http://localhost:8080/rest/objects/obj1
curl -X PUT http://localhost:8080/rest/objects/obj2
curl -X PUT http://localhost:8080/rest/objects/obj3

Mark the containers indexable:

Code Block
languagebash
title3b. Marking containers indexable
echo "insert data { <> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://fedora.info/definitions/v4/indexing#indexable> . }" \
| curl -X PATCH --upload-file -
Code Block
languagebash
title3a. 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 POSTobj1
echo "insert data { <> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://fedora.info/definitions/v4/indexing#indexable> . }" \
| curl -X PATCH --upload-file - 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 POSTobj2
echo "insert data { <> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://fedora.info/definitions/v4/indexing#indexable> . }" \
| curl -X PATCH --upload-file - http://localhost:8080/rest/objects/obj3

Mark the objects indexable:

Code Block
languagebash
title3b. Marking objects indexable
echo "prefix rdf:/objects/obj3
echo "insert data { <> <http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix index: ns#type> <http://fedora.info/definitions/v4/indexing#>  insert data { <> rdf:type index:indexable indexing#indexable> . }" \
| curl -X PATCH --upload-file - http://localhost:8080/rest/objects/obj1col1
echo "prefix rdf:insert data { <> <http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix index:-syntax-ns#type> <http://fedora.info/definitions/v4/indexing#>  insert data { <> rdf:type index:indexable indexing#indexable> . }" \
| curl -X PATCH --upload-file - http://localhost:8080/rest/objects/obj2col2
echo "prefix rdf:insert data { <> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>ns#type> prefix index: <http://fedora.info/definitions/v4/indexing#>  insert data { <> rdf:type index:indexableindexing#indexable> . }" \
| curl -X PATCH --upload-file - http://localhost:8080/rest/objects/obj3col3

Link each object container to a collection:

Code Block
languagebash
title3c. Linking Objects Containers To Collections
echo 'insert data { <http://localhost:8080/rest/objects/obj1> <http://fedora.info/definitions/v4some-vocabulary.org/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/some-vocabulary.org/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/some-vocabulary.org/rels-ext#isMemberOfCollection> <http://localhost:8080/rest/objects/col3> . }' | curl -X PATCH --upload-file - http://localhost:8080/rest/objects/obj3

...

Code Block
languagebash
title3d. Linking Collections In A Hierarchy
echo 'insert data { <http://localhost:8080/rest/objects/col1> <http://fedorasome-vocabulary.infoorg/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/v4some-vocabulary.org/rels-ext#hasPart> <http://localhost:8080/rest/objects/col3> . }' | curl -X PATCH --upload-file - http://localhost:8080/rest/objects/col2

Find objects containers directly attached to a collection:

Code Block
languagesql
title3e. Selecting Objects Containers Directly Linked To A Collection
select ?obj ?col where { ?obj <http://fedora.info/definitions/v4/some-vocabulary.org/rels-ext#isMemberOfCollection> ?col }

...

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>

Anchor
walk
walk
Find objects containers 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).

Code Block
languagesql
title3f. Select Objects Containers Directly Or Indirectly Linked To A Collection
prefixprefix rels: <http://fedora.info/definitions/v4/rels-ext#>
select ?obj where {
  { ?obj rels:isMemberOfCollection <http://localhost:8080/rest/objects/col1> }
  UNIONsome-vocabulary.org/rels-ext#>
select ?obj where {
  { <http://localhost:8080/rest/objects/col1> rels:hasPart+* ?col
  . ?obj rels:isMemberOfCollection ?col }
}
Expected Results
objcontainers
<http://localhost:8080/rest/objects/obj1>
<http://localhost:8080/rest/objects/obj2>
<http://localhost:8080/rest/objects/obj3>

Also link an object a container to a project:

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

Find objects containers in a collection or linked to a project:

Code Block
languagesql
title3h. Select Objects Containers Linked To A Collection or A Project
prefix rels: <http://fedorasome-vocabulary.infoorg/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> }
}

...

obj
<http://localhost:8080/rest/objects/obj1>
<http://localhost:8080/rest/objects/obj2>

Count objects containers instead of listing them:

Code Block
languagesql
title3i. Count the Objects Containers Linked to a Collection or a Project
prefix rels: <http://fedora.info/definitions/v4some-vocabulary.org/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> }
}

...