Skip to content

Commit

Permalink
Trapping errors when broken links to non-existent repository content …
Browse files Browse the repository at this point in the history
…(e.g. versions associated with federated filesystem)
  • Loading branch information
escowles committed Mar 18, 2014
1 parent 39c5e16 commit b044ffe
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 18 deletions.
Expand Up @@ -791,7 +791,7 @@ public void testUploadToProjection() throws IOException {
// upload file to federated filesystem using rest api
final String uploadLocation = serverAddress + "files/upload/ds1/fcr:content";
final String uploadContent = "abc123";
logger.debug("XXX: uploading to federated filesystem via rest api: " + uploadLocation);
logger.debug("Uploading to federated filesystem via rest api: " + uploadLocation);
final HttpPost post = postDSMethod("files/upload", "ds1", uploadContent);
final HttpResponse response = client.execute(post);
assertEquals(CREATED.getStatusCode(), response.getStatusLine().getStatusCode());
Expand Down
Expand Up @@ -41,6 +41,8 @@

import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.AbstractFuture;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.Triple;
Expand Down Expand Up @@ -107,24 +109,28 @@ public void write(final OutputStream output) throws IOException {
}

private Iterable<Statement> asStatements() {
return new Iterable<Statement>() {
return Iterables.filter(new Iterable<Statement>() {

@Override
public Iterator<Statement> iterator() {
return rdfStream.transform(toStatement);
}
};
}, Predicates.notNull() );
}

protected static final Function<? super Triple, Statement> toStatement =
new Function<Triple, Statement>() {

@Override
public Statement apply(final Triple t) {
final Value object = getValueForObject(t.getObject());
return vfactory.createStatement(vfactory.createURI(t
.getSubject().getURI()), vfactory.createURI(t
.getPredicate().getURI()), object);
if ( t != null ) {
final Value object = getValueForObject(t.getObject());
return vfactory.createStatement(vfactory.createURI(t
.getSubject().getURI()), vfactory.createURI(t
.getPredicate().getURI()), object);
} else {
return null;
}
}

};
Expand Down
Expand Up @@ -291,7 +291,9 @@ public Model asModel() {
final Model model = createDefaultModel();
model.setNsPrefixes(namespaces());
for (final Triple t : this) {
model.add(model.asStatement(t));
if ( t != null ) {
model.add(model.asStatement(t));
}
}
return model;
}
Expand Down
Expand Up @@ -117,11 +117,16 @@ public Triple apply(final Value v) {
private Triple propertyvalue2triple(final Property p, final Value v) {
LOGGER.trace("Rendering triple for Property: {} with Value: {}", p, v);
try {
final Triple triple =
create(getGraphSubject(p.getParent()), getPredicateForProperty
.apply(p).asNode(), propertyvalue2node(p, v));
LOGGER.trace("Created triple: {} ", triple);
return triple;
final Node val = propertyvalue2node(p, v);
if ( val != null ) {
final Triple triple =
create(getGraphSubject(p.getParent()),
getPredicateForProperty.apply(p).asNode(), val);
LOGGER.trace("Created triple: {} ", triple);
return triple;
} else {
return null;
}
} catch (final RepositoryException e) {
throw propagate(e);
}
Expand Down Expand Up @@ -163,12 +168,17 @@ private static Node literal2node(final Object literal) {
private Node traverseLink(final Property p, final Value v)
throws RepositoryException {
final javax.jcr.Node refNode;
if (v.getType() == PATH) {
refNode = p.getParent().getNode(v.getString());
} else {
refNode = p.getSession().getNodeByIdentifier(v.getString());
try {
if (v.getType() == PATH) {
refNode = p.getParent().getNode(v.getString());
} else {
refNode = p.getSession().getNodeByIdentifier(v.getString());
}
return getGraphSubject(refNode);
} catch ( Exception ex ) {
LOGGER.warn("Exception: " + ex.toString());
return null;
}
return getGraphSubject(refNode);
}

private Node getGraphSubject(final javax.jcr.Node n)
Expand Down

0 comments on commit b044ffe

Please sign in to comment.