Usage is simple:
FedoraCredentials credentials = new FedoraCredentials("http://example.org/fedora", "username", "password"); FedoraClient fedora = new FedoraClient(credentials);
FedoraRequest.setDefaultClient(fedora);
IngestResponse response = new Ingest("test:pid").label("foo").execute(); String pid = response.getPid();
Using static imports, you can use an even more abbreviated syntax:
import static com.yourmediashelf.fedora.client.FedoraClient.*; ... ingest("test:pid").execute();
Use optimistic locking for modifyObject by passing the lastModifiedDate as a request parameter. If the request's lastModifiedDate is earlier than the object's, the request will fail with a HTTP 409 Conflict error.
Date lastModifiedDate = fedora.getLastModifiedDate("test:pid"); try { modifyObject("test:pid").label("bar").lastModifiedDate(lastModifiedDate).execute(); } catch(FedoraClientException e) { if (e.getStatus() == 409) { // do something } }
FedoraRequests return instances of a FedoraResponse. The response-specific implementations (e.g. AddDatastreamResponse, GetDatastreamResponse, etc.) provide convenience methods that parse the response body. However, at this writing, not every request has a corresponding response implemented (yet). In those cases, it is necessary to parse the "raw" response, as returned by FedoraReponse.getEntity(Class) or FedoraResponse.getEntityInputStream().
FedoraResponse r = getDatastream("test:pid", "DC").format("html").execute(); String htmlResponseBody = r.getEntity(String.class); GetDatastreamResponse gdr = getDatastream("test:pid", "DC").execute(); assert("A".equals(gdr.getDatastreamProfile().getDsState()));
The same FedoraRequest can be re-used across multiple Fedora instances:
FedoraClient f1 = new FedoraClient(new FedoraCredentials("http://localhost:8080/fedora", "fedoraAdmin", "pass1")); FedoraClient f2 = new FedoraClient(new FedoraCredentials("http://example.com/fedora", "fedoraAdmin", "pass2")); Ingest ingest = new Ingest("test:pid").label("foo"); ingest.execute(f1); ingest.execute(f2);
As of 0.1.8, fedora-client is now a Maven multi-module project, producing fedora-client-core and fedora-client-messaging artifacts. Unless you specifically require support for Fedora Messaging, fedora-client-core is all you need. Similarly, if you only need support for Fedora Messaging and not Fedora's REST API, fedora-client-messaging is all you need.
Add the following to your pom.xml (substituting the actual, current version of fedora-client):
<dependencies> <dependency> <groupId>com.yourmediashelf.fedora.client</groupId> <artifactId>fedora-client-core</artifactId> <version>0.7</version> </dependency> <dependency> <groupId>com.yourmediashelf.fedora.client</groupId> <artifactId>fedora-client-messaging</artifactId> <version>0.7</version> </dependency> </dependencies>
As of version 0.1.5, fedora-client also distributes -with-dependencies jars that bundle all dependencies (except for log4j) for use with non-Maven-based projects.
These artifacts are available via Maven Central and its mirrors.