Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added fedora 4 client abstraction layer.
- Loading branch information
1 parent
26f49af
commit b98cfab
Showing
6 changed files
with
263 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.fcrepo.migration; | ||
|
||
import java.io.InputStream; | ||
|
||
/** | ||
* An interface representing all of the high-level fedora 4 operations | ||
* needed by the migration utility. | ||
* | ||
* @author Mike Durbin | ||
*/ | ||
public interface Fedora4Client { | ||
|
||
/** | ||
* Determines if a resource exists. | ||
* @param path the path to the resource | ||
* @return true if it exists, false otherwise | ||
*/ | ||
public boolean exists(String path); | ||
|
||
/** | ||
* Creates a new resource at the given path. | ||
* @param path the path to the new resource | ||
*/ | ||
public void createResource(String path); | ||
|
||
/** | ||
* Creates a new non-RDF resource at the given path. | ||
* @param path the path to the new resource | ||
*/ | ||
public void createNonRDFResource(String path); | ||
|
||
/** | ||
* Gets the repository URL (to which paths can be appended to reference resources). | ||
* @return the repository URL | ||
*/ | ||
public String getRepositoryUrl(); | ||
|
||
/** | ||
* Creates or updates a non-RDF resource that points to external content at the given URL. | ||
* @param path the path of the resource to be created | ||
* @param url the URL at which the external content is hosted | ||
*/ | ||
public void createOrUpdateRedirectNonRDFResource(String path, String url); | ||
|
||
/** | ||
* Creates or updates a non-RDF resource. | ||
* @param path the path of the resource to be modified/created | ||
* @param content the non-RDF content | ||
* @param contentType the mime type of the content | ||
*/ | ||
public void createOrUpdateNonRDFResource(String path, InputStream content, String contentType); | ||
|
||
/** | ||
* Creates a version snapshot for the resource (or graph) at the given path. | ||
* @param path the path of the resource to be versioned | ||
* @param versionId a label for the version | ||
*/ | ||
public void createVersionSnapshot(String path, String versionId); | ||
|
||
/** | ||
* Updates properties on a resource. | ||
* @param path the resource whose properties are to be updated. | ||
* @param sparqlUpdate the sparql update statements to be applied | ||
*/ | ||
public void updateResourceProperties(String path, String sparqlUpdate); | ||
|
||
/** | ||
* Updates properties on a non-RDF resource. | ||
* @param path the resource whose properties are to be updated. | ||
* @param sparqlUpdate the sparql update statements to be applied | ||
*/ | ||
public void updateNonRDFResourceProperties(String path, String sparqlUpdate); | ||
} |
115 changes: 115 additions & 0 deletions
115
src/main/java/org/fcrepo/migration/f4clients/DefaultFedora4Client.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package org.fcrepo.migration.f4clients; | ||
|
||
import org.fcrepo.client.FedoraContent; | ||
import org.fcrepo.client.FedoraException; | ||
import org.fcrepo.client.FedoraRepository; | ||
import org.fcrepo.migration.Fedora4Client; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.InputStream; | ||
import java.io.UnsupportedEncodingException; | ||
|
||
/** | ||
* A Fedora4Client implementation built on top of the fcrepo4-client | ||
* project's FedoraRepositoryImpl class. | ||
* | ||
* @author Mike Durbin | ||
*/ | ||
public class DefaultFedora4Client implements Fedora4Client { | ||
|
||
private FedoraRepository repo; | ||
|
||
/** | ||
* Only constructor; requires an instance of a FedoraRepository implementation. | ||
* @param repo a FedoraRepository implementation that will do the heavy lifting. | ||
*/ | ||
public DefaultFedora4Client(final FedoraRepository repo) { | ||
this.repo = repo; | ||
} | ||
|
||
@Override | ||
public boolean exists(final String path) { | ||
try { | ||
return repo.exists(path); | ||
} catch (FedoraException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void createResource(final String path) { | ||
try { | ||
repo.createObject(path); | ||
} catch (FedoraException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void createNonRDFResource(final String path) { | ||
try { | ||
repo.createDatastream(path, new FedoraContent().setContent( | ||
new ByteArrayInputStream("placeholder".getBytes("UTF-8"))).setContentType("text/plain")); | ||
} catch (FedoraException e) { | ||
throw new RuntimeException(e); | ||
} catch (UnsupportedEncodingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public String getRepositoryUrl() { | ||
return repo.getRepositoryUrl(); | ||
} | ||
|
||
@Override | ||
public void createOrUpdateRedirectNonRDFResource(final String path, final String url) { | ||
try { | ||
repo.createOrUpdateRedirectDatastream(path, url); | ||
} catch (FedoraException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void createOrUpdateNonRDFResource(final String path, final InputStream content, final String contentType) { | ||
try { | ||
if (repo.exists(path)) { | ||
repo.getDatastream(path).updateContent( | ||
new FedoraContent().setContent(content).setContentType(contentType)); | ||
} else { | ||
repo.createDatastream(path, new FedoraContent().setContent(content).setContentType(contentType)); | ||
} | ||
} catch (FedoraException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void createVersionSnapshot(final String path, final String versionId) { | ||
try { | ||
repo.getObject(path).createVersionSnapshot(versionId); | ||
} catch (FedoraException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void updateResourceProperties(final String path, final String sparqlUpdate) { | ||
try { | ||
repo.getObject(path).updateProperties(sparqlUpdate); | ||
} catch (FedoraException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void updateNonRDFResourceProperties(final String path, final String sparqlUpdate) { | ||
try { | ||
repo.getDatastream(path).updateProperties(sparqlUpdate); | ||
} catch (FedoraException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.