Skip to content

Commit

Permalink
Merge pull request #317 from futures/filter-reference-props
Browse files Browse the repository at this point in the history
Filtering out reference properties from RDF output
  • Loading branch information
barmintor committed Apr 24, 2014
2 parents 46fce99 + 807ba08 commit ebb08c8
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 5 deletions.
Expand Up @@ -646,7 +646,6 @@ public Response deleteObject(@PathParam("path")
final FedoraResource resource =
nodeService.getObject(session, path);


evaluateRequestPreconditions(request, resource);

nodeService.deleteObject(session, path);
Expand All @@ -664,6 +663,8 @@ public Response deleteObject(@PathParam("path")
}
}
return status(SC_PRECONDITION_FAILED).entity(msg.toString()).build();
} catch (WebApplicationException ex) {
return status(SC_PRECONDITION_FAILED).entity(ex.getMessage()).build();
} finally {
session.logout();
}
Expand Down
Expand Up @@ -242,7 +242,7 @@ protected static void evaluateRequestPreconditions(final Request request,
request.evaluatePreconditions(roundedDate, etag);

if (builder != null) {
throw new WebApplicationException(builder.build());
throw new WebApplicationException(builder.entity("ETag mismatch").build());
}
}

Expand Down
Expand Up @@ -23,7 +23,7 @@
import static org.fcrepo.kernel.RdfLexicon.HAS_CONTENT;
import static org.fcrepo.kernel.RdfLexicon.HAS_CONTENT_LOCATION;
import static org.fcrepo.kernel.RdfLexicon.IS_CONTENT_OF;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.isBinaryContentProperty;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.isInternalProperty;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.property2values;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;
import static org.slf4j.LoggerFactory.getLogger;
Expand Down Expand Up @@ -135,11 +135,11 @@ private Iterator<Triple> triplesFromProperties(final javax.jcr.Node n)
LOGGER.trace("Creating triples for node: {}", n);
final UnmodifiableIterator<Property> nonBinaryProperties =
Iterators.filter(new PropertyIterator(n.getProperties()),
not(isBinaryContentProperty));
not(isInternalProperty));

final UnmodifiableIterator<Property> nonBinaryPropertiesCopy =
Iterators.filter(new PropertyIterator(n.getProperties()),
not(isBinaryContentProperty));
not(isInternalProperty));

return Iterators.concat(new ZippingIterator<>(
Iterators.transform(
Expand Down
Expand Up @@ -25,6 +25,8 @@
import static com.google.common.collect.Iterators.transform;
import static javax.jcr.PropertyType.BINARY;
import static org.modeshape.jcr.api.JcrConstants.JCR_DATA;
import static javax.jcr.PropertyType.REFERENCE;
import static org.fcrepo.kernel.utils.NodePropertiesTools.REFERENCE_PROPERTY_SUFFIX;
import static org.slf4j.LoggerFactory.getLogger;

import java.util.Collection;
Expand Down Expand Up @@ -195,6 +197,8 @@ public Iterator<Value> apply(final Property p) {
return Iterators.forArray(p.getValue());
} catch (final RepositoryException e) {
throw propagate(e);
} catch (final Exception e) {
throw propagate(e);
}
}
};
Expand Down Expand Up @@ -233,6 +237,35 @@ public boolean apply(final Property p) {
}
};

/**
* Check if a property is a reference property.
*/
public static Predicate<Property> isReferenceProperty =
new Predicate<Property>() {

@Override
public boolean apply(final Property p) {
try {
return p.getType() == REFERENCE && p.getName().endsWith(REFERENCE_PROPERTY_SUFFIX);
} catch (final RepositoryException e) {
throw propagate(e);
}
}
};

/**
* Check whether a property is an internal property that should be suppressed
* from external output.
*/
public static Predicate<Property> isInternalProperty =
new Predicate<Property>() {

@Override
public boolean apply(final Property p) {
return isReferenceProperty.apply(p) || isBinaryContentProperty.apply(p);
}
};

/**
* Check if a node is "internal" and should not be exposed e.g. via the REST
* API
Expand Down
Expand Up @@ -22,13 +22,17 @@
import static org.fcrepo.kernel.utils.FedoraTypesUtils.getDefinitionForPropertyName;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.getVersionHistory;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.isBinaryContentProperty;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.isReferenceProperty;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.isInternalProperty;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.isFedoraDatastream;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.isFedoraObject;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.isFedoraResource;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.isInternalNode;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.isMultipleValuedProperty;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.propertyContains;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.value2string;
import static org.fcrepo.kernel.utils.NodePropertiesTools.REFERENCE_PROPERTY_SUFFIX;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
Expand Down Expand Up @@ -176,6 +180,24 @@ public void testIsBinaryContentProperty() throws RepositoryException {
assertTrue(isBinaryContentProperty.apply(mockProperty));
}

@Test
public void testIsReferenceProperty() throws RepositoryException {
when(mockProperty.getType()).thenReturn(PropertyType.REFERENCE);
when(mockProperty.getName()).thenReturn("foo" + REFERENCE_PROPERTY_SUFFIX);
assertTrue(isReferenceProperty.apply(mockProperty));
}

@Test
public void testIsInternalProperty() throws RepositoryException {
when(mockProperty.getType()).thenReturn(PropertyType.REFERENCE);
when(mockProperty.getName()).thenReturn("foo" + REFERENCE_PROPERTY_SUFFIX);
assertTrue(isInternalProperty.apply(mockProperty));

when(mockProperty.getType()).thenReturn(PropertyType.BINARY);
when(mockProperty.getName()).thenReturn(JcrConstants.JCR_DATA);
assertTrue(isInternalProperty.apply(mockProperty));
}

@Test
public void testIsNotBinaryContentProperty() throws RepositoryException {
when(mockProperty.getType()).thenReturn(PropertyType.STRING);
Expand Down

0 comments on commit ebb08c8

Please sign in to comment.