Permalink
Browse files

update getLowLevelCacheEntries to take the jcr:content node or jcr:da…

…ta property, instead of the parent node.
  • Loading branch information...
1 parent d40943b commit 7b4e883228468e3daf1506eaf46eee469acf8d8f @cbeer cbeer committed May 20, 2013

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -27,6 +27,7 @@
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.jcr.Node;
+import javax.jcr.Property;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
@@ -42,6 +43,7 @@
import org.infinispan.loaders.CacheStore;
import org.infinispan.loaders.decorators.ChainingCacheStore;
import org.modeshape.jcr.GetBinaryStore;
+import org.modeshape.jcr.api.JcrConstants;
import org.modeshape.jcr.value.BinaryKey;
import org.modeshape.jcr.value.binary.BinaryStore;
import org.modeshape.jcr.value.binary.CompositeBinaryStore;
@@ -112,7 +114,20 @@
public Set<LowLevelCacheEntry> getLowLevelCacheEntries(final Node resource)
throws RepositoryException {
- return getLowLevelCacheEntries(getBinaryKey.apply(resource));
+ return getLowLevelCacheEntries(resource.getProperty(JcrConstants.JCR_DATA));
+
+ }
+
+ /**
+ *
+ * @param resource a JCR node that has a jcr:content/jcr:data child.
+ * @return a map of binary stores and input streams
+ * @throws RepositoryException
+ */
+ public Set<LowLevelCacheEntry> getLowLevelCacheEntries(final Property jcrBinaryProperty)
+ throws RepositoryException {
+
+ return getLowLevelCacheEntries(getBinaryKey.apply(jcrBinaryProperty));
}
@@ -273,7 +288,7 @@ public void setRepository(final Repository repository) {
try {
fixityResults =
- copyOf(getFixity(datastream.getNode(), digest, digestUri,
+ copyOf(getFixity(datastream.getNode().getNode(JcrConstants.JCR_CONTENT), digest, digestUri,
size));
goodEntries = getGoodFixityResults.apply(fixityResults);
@@ -7,21 +7,21 @@
import static org.modeshape.jcr.api.JcrConstants.JCR_DATA;
import javax.jcr.Node;
+import javax.jcr.Property;
import javax.jcr.RepositoryException;
import org.modeshape.jcr.value.BinaryKey;
import org.modeshape.jcr.value.BinaryValue;
import com.google.common.base.Function;
-public class GetBinaryKey implements Function<Node, BinaryKey> {
+public class GetBinaryKey implements Function<Property, BinaryKey> {
@Override
- public BinaryKey apply(final Node input) {
+ public BinaryKey apply(final Property input) {
checkArgument(input != null, "null cannot have a Binarykey!");
try {
- return ((BinaryValue) input.getNode(JCR_CONTENT).getProperty(
- JCR_DATA).getBinary()).getKey();
+ return ((BinaryValue) input.getBinary()).getKey();
} catch (final RepositoryException e) {
throw propagate(e);
}
@@ -302,7 +302,7 @@ private static void addJcrContentLocationInformationToModel(
llstore.setRepository(node.getSession().getRepository());
final Set<LowLevelCacheEntry> cacheEntries =
- llstore.getLowLevelCacheEntries(node);
+ llstore.getLowLevelCacheEntries(contentNode);
for (final LowLevelCacheEntry e : cacheEntries) {
model.add(
@@ -23,6 +23,7 @@
import org.fcrepo.utils.LowLevelCacheEntry;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.modeshape.jcr.api.JcrConstants;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -57,7 +58,7 @@ public void testChecksumBlobs() throws Exception {
final Datastream ds = datastreamService.getDatastream(session, "/testLLObject/testRepositoryContent");
final Collection<FixityResult> fixityResults =
- lowLevelService.getFixity(ds.getNode(), MessageDigest
+ lowLevelService.getFixity(ds.getNode().getNode(JcrConstants.JCR_CONTENT), MessageDigest
.getInstance("SHA-1"), ds.getContentDigest(), ds
.getContentSize());
@@ -84,7 +85,7 @@ public void testGetBinaryBlobs() throws Exception {
datastreamService.getDatastream(session, "/testLLObject/testRepositoryContent");
final Iterator<LowLevelCacheEntry> inputStreamList =
- lowLevelService.getLowLevelCacheEntries(ds.getNode()).iterator();
+ lowLevelService.getLowLevelCacheEntries(ds.getNode().getNode(JcrConstants.JCR_CONTENT)).iterator();
int i = 0;
while (inputStreamList.hasNext()) {
@@ -29,6 +29,7 @@
import org.junit.Before;
import org.junit.Test;
import org.modeshape.jcr.JcrRepositoryFactory;
+import org.modeshape.jcr.api.JcrConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -72,7 +73,7 @@ private void tamperWithNode(final Node node) throws Exception {
logger.info("Tampering with node " + node.toString());
final Set<LowLevelCacheEntry> binaryBlobs =
- lowLevelService.getLowLevelCacheEntries(node);
+ lowLevelService.getLowLevelCacheEntries(node.getNode(JcrConstants.JCR_CONTENT));
final Iterator<LowLevelCacheEntry> it = binaryBlobs.iterator();
@@ -85,7 +86,7 @@ private void tamperWithNode(final Node node) throws Exception {
private Collection<FixityResult> getNodeFixity(final Datastream ds)
throws NoSuchAlgorithmException, RepositoryException {
- return lowLevelService.getFixity(ds.getNode(), MessageDigest
+ return lowLevelService.getFixity(ds.getNode().getNode(JcrConstants.JCR_CONTENT), MessageDigest
.getInstance("SHA-1"), ds.getContentDigest(), ds
.getContentSize());
@@ -26,6 +26,7 @@
import org.junit.Ignore;
import org.junit.Test;
import org.modeshape.jcr.JcrRepositoryFactory;
+import org.modeshape.jcr.api.JcrConstants;
import org.modeshape.jcr.value.BinaryKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -93,14 +94,14 @@ public void testPolicyDrivenStorage() throws Exception {
final Node node = session.getNode("/testCompositeObject/content");
- BinaryKey key = getBinaryKey.apply(node);
+ BinaryKey key = getBinaryKey.apply(node.getNode(JcrConstants.JCR_CONTENT).getProperty(JcrConstants.JCR_DATA));
logger.info("content key: {}", key);
final Node tiffNode = session.getNode("/testCompositeObject/tiffContent");
- BinaryKey tiffKey = getBinaryKey.apply(tiffNode);
+ BinaryKey tiffKey = getBinaryKey.apply(tiffNode.getNode(JcrConstants.JCR_CONTENT).getProperty(JcrConstants.JCR_DATA));
logger.info("tiff key: {}", tiffKey);
@@ -25,6 +25,7 @@
import javax.jcr.LoginException;
import javax.jcr.Node;
+import javax.jcr.Property;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
@@ -43,6 +44,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.modeshape.jcr.GetBinaryStore;
+import org.modeshape.jcr.api.JcrConstants;
import org.modeshape.jcr.value.BinaryKey;
import org.modeshape.jcr.value.binary.BinaryStore;
import org.modeshape.jcr.value.binary.CompositeBinaryStore;
@@ -64,11 +66,15 @@ public void testGetFixity() throws RepositoryException {
final GetBinaryStore mockStoreFunc = mock(GetBinaryStore.class);
final GetBinaryKey mockKeyFunc = mock(GetBinaryKey.class);
final Node mockNode = mock(Node.class);
+
+ final Property mockProperty = mock(Property.class);
+ when(mockNode.getProperty(JcrConstants.JCR_DATA)).thenReturn(mockProperty);
+
final Repository mockRepo = mock(Repository.class);
final BinaryKey mockKey = mock(BinaryKey.class);
final BinaryStore mockStore = mock(BinaryStore.class);
when(mockStore.toString()).thenReturn("foo");
- when(mockKeyFunc.apply(mockNode)).thenReturn(mockKey);
+ when(mockKeyFunc.apply(mockProperty)).thenReturn(mockKey);
when(mockStoreFunc.apply(mockRepo)).thenReturn(mockStore);
final LowLevelStorageService testObj = new LowLevelStorageService();
testObj.setGetBinaryStore(mockStoreFunc);
@@ -102,8 +108,11 @@ public void testTransformBinaryBlobs() throws RepositoryException {
final Repository mockRepo = mock(Repository.class);
final BinaryKey mockKey = mock(BinaryKey.class);
final BinaryStore mockStore = mock(BinaryStore.class);
+
+ final Property mockProperty = mock(Property.class);
+ when(mockNode.getProperty(JcrConstants.JCR_DATA)).thenReturn(mockProperty);
when(mockStore.toString()).thenReturn("foo");
- when(mockKeyFunc.apply(mockNode)).thenReturn(mockKey);
+ when(mockKeyFunc.apply(mockProperty)).thenReturn(mockKey);
when(mockStoreFunc.apply(mockRepo)).thenReturn(mockStore);
final LowLevelStorageService testObj = new LowLevelStorageService();
testObj.setGetBinaryStore(mockStoreFunc);
@@ -124,11 +133,13 @@ public void testGetBinaryBlobs() throws RepositoryException {
final GetBinaryStore mockStoreFunc = mock(GetBinaryStore.class);
final GetBinaryKey mockKeyFunc = mock(GetBinaryKey.class);
final Node mockNode = mock(Node.class);
+ final Property mockProperty = mock(Property.class);
+ when(mockNode.getProperty(JcrConstants.JCR_DATA)).thenReturn(mockProperty);
final Repository mockRepo = mock(Repository.class);
final BinaryKey mockKey = mock(BinaryKey.class);
final BinaryStore mockStore = mock(BinaryStore.class);
when(mockStore.toString()).thenReturn("foo");
- when(mockKeyFunc.apply(mockNode)).thenReturn(mockKey);
+ when(mockKeyFunc.apply(mockProperty)).thenReturn(mockKey);
when(mockStoreFunc.apply(mockRepo)).thenReturn(mockStore);
final LowLevelStorageService testObj = new LowLevelStorageService();
testObj.setGetBinaryStore(mockStoreFunc);
@@ -295,7 +306,11 @@ public void testRunFixityAndFixProblems() throws RepositoryException,
final GetBinaryStore mockStoreFunc = mock(GetBinaryStore.class);
final GetBinaryKey mockKeyFunc = mock(GetBinaryKey.class);
final Node mockNode = mock(Node.class);
+
+ final Property mockProperty = mock(Property.class);
final Repository mockRepo = mock(Repository.class);
+ final Node mockContentNode = mock(Node.class);
+ when(mockContentNode.getProperty(JcrConstants.JCR_DATA)).thenReturn(mockProperty);
final BinaryKey mockKey = new BinaryKey("key-123");
final InfinispanBinaryStore mockStore =
mock(InfinispanBinaryStore.class);
@@ -314,7 +329,7 @@ public void testRunFixityAndFixProblems() throws RepositoryException,
when(mockCacheStoreFunc.apply(mockBadCache)).thenReturn(
mockBadCacheStore);
when(mockStore.getCaches()).thenReturn(Arrays.asList(mockCaches));
- when(mockKeyFunc.apply(mockNode)).thenReturn(mockKey);
+ when(mockKeyFunc.apply(mockProperty)).thenReturn(mockKey);
when(mockStoreFunc.apply(mockRepo)).thenReturn(mockStore);
final LowLevelStorageService testObj = new LowLevelStorageService();
testObj.setGetBinaryStore(mockStoreFunc);
@@ -339,6 +354,7 @@ public void testRunFixityAndFixProblems() throws RepositoryException,
when(mockDs.getObject()).thenReturn(mockObj);
when(mockDs.getDsId()).thenReturn("mockDs");
when(mockDs.getNode()).thenReturn(mockNode);
+ when(mockNode.getNode(JcrConstants.JCR_CONTENT)).thenReturn(mockContentNode);
when(mockDs.getContentSize()).thenReturn(testSize);
when(mockDs.getContentDigestType()).thenReturn("MD5"); // whatever, just be quiet
when(mockDs.getContentDigest()).thenReturn(mockUri);
@@ -1,6 +1,7 @@
package org.fcrepo.services.functions;
+import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;
@@ -12,6 +13,7 @@
import javax.jcr.RepositoryException;
import org.junit.Test;
+import org.modeshape.jcr.value.BinaryKey;
import org.modeshape.jcr.value.BinaryValue;
public class GetBinaryKeyTest {
@@ -22,11 +24,13 @@ public void testApply() throws LoginException, RepositoryException {
final Node mockContent = mock(Node.class);
final Property mockProp = mock(Property.class);
final BinaryValue mockBin = mock(BinaryValue.class);
+ final BinaryKey binaryKey = new BinaryKey("abc");
+ when(mockBin.getKey()).thenReturn(binaryKey);
when(mockProp.getBinary()).thenReturn(mockBin);
when(mockContent.getProperty(JCR_DATA)).thenReturn(mockProp);
when(mockNode.getNode(JCR_CONTENT)).thenReturn(mockContent);
final GetBinaryKey testObj = new GetBinaryKey();
- testObj.apply(mockNode);
+ assertEquals(binaryKey, testObj.apply(mockProp));
}
}

0 comments on commit 7b4e883

Please sign in to comment.