gushakov / spring-data-fedora

Spring Data module for Fedora Commons repository v. 3.x

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spring-data-fedora

Note: this project is for version 3.x of the Fedora Commons repository. For the current version 4.x see

spring-data-fcrepo4

The purpose of this project is to extend Spring Data API for persisting and querying data from Fedora Commons Repository.

Description.

The idea behind this integration is to use a small set of custom annotations to be added to domain objects which allow generation of valid FOXML1.1 document to be stored in a Fedora repository.

Each object of a type annotated with @FedoraObject will be mapped to a FOXML1.1 document with one datastream of type "X" containing the result of serializing this object with JAXB marshaller. For example,

// declare domain object
@FedoraObject
public class Foobar {
    @Pid private long id = 1L;
    private String foo = "bar";
}

// ingest object with FedoraTemplate
fedoraTemplate.ingest(new Foobar(), "logging ingest");

Will produce a Fedora object with pid test:foobar_1 containing a single extensible datastream.

<foxml:datastream ID="FOOBAR" STATE="A" CONTROL_GROUP="X" VERSIONABLE="false">
    <foxml:datastreamVersion ID="FOOBAR.0" LABEL="foobar" CREATED="2014-11-10T17:09:05.137Z" MIMETYPE="text/xml" SIZE="44">
        <foxml:xmlContent>
            <foobar id="1">
                <foo>bar</foo>
            </foobar>
        </foxml:xmlContent>
    </foxml:datastreamVersion>
</foxml:datastream>

Querying the repository is also very easy using provided ch.unil.spring.data.fedora.core.query.FindObjectsQueryBuilder query builder.

// build query "pid has test:foobar_*"
FindObjectsQuery query = fedoraTemplate.getQueryBuilder()
        .withField(FindObjectsField.Pid)
        .withOperator(FindObjectsConditionOperator.Has)
        .withPhrase("*", Foobar.class)
        .build();

// use the query to get a page of domain objects (two at a time)
Page<Foobar> page = fedoraTemplate.query(query, Foobar.class, DefaultFindObjectsPageRequest.firstPage(2));

for (Foobar foobar: page){
    // iterate through results
}

// get the next page
if (page.hasNext()){
    page = fedoraTemplate.query(query, Foobar.class, (FindObjectsPageRequest) page.nextPageable());
}

Examples.

Some examples:

About

Spring Data module for Fedora Commons repository v. 3.x


Languages

Language:Java 100.0%