Skip to content

Commit

Permalink
update PropertyRdfContext serialization to include all BINARY propert…
Browse files Browse the repository at this point in the history
…ies, except BINARY properties that are jcr:data (which should be retrieved as streams, not serialized in the graph)
  • Loading branch information
cbeer committed Nov 12, 2013
1 parent 29a15af commit 4e10a7d
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 11 deletions.
Expand Up @@ -23,7 +23,7 @@
import static org.fcrepo.kernel.RdfLexicon.HAS_CONTENT;
import static org.fcrepo.kernel.RdfLexicon.HAS_LOCATION;
import static org.fcrepo.kernel.RdfLexicon.IS_CONTENT_OF;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.isBinaryProperty;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.isBinaryContentProperty;
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.debug("Creating triples for node: {}", n);
final UnmodifiableIterator<Property> nonBinaryProperties =
Iterators.filter(new PropertyIterator(n.getProperties()),
not(isBinaryProperty));
not(isBinaryContentProperty));

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

return Iterators.concat(new ZippingIterator<>(
Iterators.transform(
Expand Down
Expand Up @@ -29,6 +29,8 @@
import static org.fcrepo.jcr.FedoraJcrTypes.FEDORA_OBJECT;
import static org.fcrepo.jcr.FedoraJcrTypes.FEDORA_RESOURCE;
import static org.fcrepo.kernel.utils.JcrRdfTools.getRDFNamespaceForJcrNamespace;
import static org.modeshape.jcr.api.JcrConstants.JCR_DATA;
import static org.modeshape.jcr.api.JcrConstants.JCR_PATH;
import static org.slf4j.LoggerFactory.getLogger;

import java.util.Collection;
Expand All @@ -49,12 +51,10 @@
import javax.jcr.version.Version;
import javax.jcr.version.VersionHistory;

import org.fcrepo.jcr.FedoraJcrTypes;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
import org.modeshape.jcr.api.JcrConstants;
import org.modeshape.jcr.api.Namespaced;
import org.slf4j.Logger;

Expand Down Expand Up @@ -198,17 +198,17 @@ public boolean apply(final Property p) {
};

/**
* Check if a JCR property is a binary property or not
* Check if a JCR property is a binary jcr:data property
*/
public static Predicate<Property> isBinaryProperty =
public static Predicate<Property> isBinaryContentProperty =
new Predicate<Property>() {

@Override
public boolean apply(final Property p) {
checkArgument(p != null,
"null is neither binary nor not binary!");
"null is neither binary nor not binary!");
try {
return p.getType() == BINARY;
return p.getType() == BINARY && p.getName().equals(JCR_DATA);
} catch (final RepositoryException e) {
throw propagate(e);
}
Expand Down Expand Up @@ -384,8 +384,8 @@ public static long getRepositoryCount(final Repository repository)
session.getWorkspace().getQueryManager();

final String querystring =
"SELECT [" + JcrConstants.JCR_PATH + "] FROM ["
+ FedoraJcrTypes.FEDORA_OBJECT + "]";
"SELECT [" + JCR_PATH + "] FROM ["
+ FEDORA_OBJECT + "]";

final QueryResult queryResults =
queryManager.createQuery(querystring, JCR_SQL2).execute();
Expand Down
Expand Up @@ -24,7 +24,9 @@
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createTypedLiteral;
import static java.util.Arrays.asList;
import static javax.jcr.PropertyType.BINARY;
import static javax.jcr.PropertyType.LONG;
import static org.fcrepo.kernel.RdfLexicon.DC_TITLE;
import static org.fcrepo.kernel.RdfLexicon.HAS_CHILD;
import static org.fcrepo.kernel.RdfLexicon.HAS_PRIMARY_IDENTIFIER;
import static org.fcrepo.kernel.RdfLexicon.RELATIONS_NAMESPACE;
Expand Down Expand Up @@ -53,6 +55,7 @@
import org.fcrepo.kernel.services.DatastreamService;
import org.fcrepo.kernel.services.NodeService;
import org.fcrepo.kernel.services.ObjectService;
import org.fcrepo.kernel.utils.JcrRdfTools;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
Expand Down Expand Up @@ -178,6 +181,48 @@ public void testObjectGraph() throws IOException, RepositoryException {

}


@Test
public void testObjectGraphWithCustomProperty() throws IOException, RepositoryException {

FedoraResource object =
objectService.createObject(session, "/testObjectGraph");

final javax.jcr.Node node = object.getNode();
node.setProperty("dc:title", "this-is-some-title");
node.setProperty("dc:subject", "this-is-some-subject-stored-as-a-binary", BINARY);
node.setProperty("jcr:data", "jcr-data-should-be-ignored", BINARY);

session.save();
session.logout();

session = repo.login();

object = objectService.getObject(session, "/testObjectGraph");


logger.warn(object.getPropertiesDataset(subjects).toString());

// jcr property
final Node s = createURI(RESTAPI_NAMESPACE + "/testObjectGraph");
Node p = DC_TITLE.asNode();
Node o = createLiteral("this-is-some-title");
assertTrue(object.getPropertiesDataset(subjects).asDatasetGraph()
.contains(ANY, s, p, o));

p = createURI("http://purl.org/dc/terms/subject");
o = createLiteral("this-is-some-subject-stored-as-a-binary");
assertTrue(object.getPropertiesDataset(subjects).asDatasetGraph()
.contains(ANY, s, p, o));

p = Node.ANY;
o = createLiteral("jcr-data-should-be-ignored");
assertFalse(object.getPropertiesDataset(subjects).asDatasetGraph()
.contains(ANY, s, p, o));


}

@Test
public void testDatastreamGraph() throws IOException, RepositoryException,
InvalidChecksumException {
Expand Down
Expand Up @@ -28,6 +28,7 @@
import static org.fcrepo.kernel.utils.FedoraTypesUtils.getRepositoryCount;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.getRepositorySize;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.getVersionHistory;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.isBinaryContentProperty;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.isFedoraDatastream;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.isFedoraObject;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.isFedoraResource;
Expand All @@ -53,6 +54,7 @@

import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.PropertyType;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
Expand All @@ -75,6 +77,7 @@
import org.junit.Test;
import org.mockito.Mock;
import org.modeshape.jcr.JcrValueFactory;
import org.modeshape.jcr.api.JcrConstants;
import org.modeshape.jcr.api.Namespaced;

import com.google.common.base.Predicate;
Expand Down Expand Up @@ -174,6 +177,26 @@ public void testIsMultipleValuedProperty() throws RepositoryException {
} catch (final RuntimeException e) {} // expected
}

@Test
public void testIsBinaryContentProperty() throws RepositoryException {
when(mockProperty.getType()).thenReturn(PropertyType.BINARY);
when(mockProperty.getName()).thenReturn(JcrConstants.JCR_DATA);
assertTrue(isBinaryContentProperty.apply(mockProperty));
}

@Test
public void testIsNotBinaryContentProperty() throws RepositoryException {
when(mockProperty.getType()).thenReturn(PropertyType.STRING);
assertFalse(isBinaryContentProperty.apply(mockProperty));
}

@Test
public void testContentButNotBinaryContentProperty() throws RepositoryException {
when(mockProperty.getType()).thenReturn(PropertyType.STRING);
when(mockProperty.getName()).thenReturn(JcrConstants.JCR_DATA);
assertFalse(isBinaryContentProperty.apply(mockProperty));
}

@Test
public void testGetPredicateForProperty() throws RepositoryException {
final PropertyMock mockProp = mock(PropertyMock.class);
Expand Down

0 comments on commit 4e10a7d

Please sign in to comment.