Skip to content
Permalink
Browse files

fix for update to modeshape removed Stratgey and NamedHint.

  • Loading branch information...
nigelgbanks committed Jun 6, 2013
1 parent 56cc303 commit f6bef32be2a78bc5f01fd9beb0c605e3540dd928
@@ -37,14 +37,13 @@
import org.fcrepo.utils.FedoraJcrTypes;
import org.modeshape.jcr.api.Binary;
import org.modeshape.jcr.api.JcrTools;
import org.modeshape.jcr.value.binary.StrategyHint;
import org.slf4j.Logger;

import com.codahale.metrics.Histogram;

/**
* Abstraction for a Fedora datastream backed by a JCR node.
*
*
* @author ajs6f
*
*/
@@ -135,7 +134,7 @@ public Datastream(final Session session, final String dsPath)
Node contentNode = node.getNode(JCR_CONTENT);
decorateContentNode(contentNode);
}

}

/**
@@ -157,7 +156,7 @@ public InputStream getContent() throws RepositoryException {

/**
* Sets the content of this Datastream.
*
*
* @param content
* @throws RepositoryException
*/
@@ -176,10 +175,10 @@ public void setContent(final InputStream content, final String contentType,

node.setProperty(FEDORA_CONTENTTYPE, contentType);

StrategyHint hint = null;
String hint = null;


if(storagePolicyDecisionPoint != null) {
if (storagePolicyDecisionPoint != null) {
hint = storagePolicyDecisionPoint.evaluatePolicies(node);
}

@@ -255,7 +254,7 @@ public URI getContentDigest() throws RepositoryException {
} catch (RepositoryException e) {
logger.error("Could not get content digest - " + e.getMessage());
}
//TODO checksum not stored. recalculating checksum,
//TODO checksum not stored. recalculating checksum,
//however, this would defeat the purpose validating against the checksum
Binary binary = (Binary) contentNode.getProperty(JCR_DATA)
.getBinary();
@@ -407,7 +406,7 @@ public long getSize() throws RepositoryException {
return getNodePropertySize(node) + getContentSize();

}

private void decorateContentNode(Node contentNode) throws RepositoryException {
if (contentNode == null) {
logger.warn("{}/jcr:content appears to be null!");
@@ -429,7 +428,7 @@ private void decorateContentNode(Node contentNode) throws RepositoryException {

logger.debug("Decorated data property at path: " + dataProperty.getPath());
}

public static boolean hasMixin(Node node) throws RepositoryException {
NodeType[] nodeTypes = node.getMixinNodeTypes();
if (nodeTypes == null) return false;
@@ -22,11 +22,10 @@
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import org.modeshape.jcr.JcrValueFactory;
import org.modeshape.jcr.value.binary.StrategyHint;

/**
* Convenience class with static methods for manipulating Fedora types in the JCR.
*
*
* @author ajs6f
*
*/
@@ -84,7 +83,7 @@ public boolean apply(final Node node) {
};

/**
* Translates a {@link NodeType} to its {@link String} name.
* Translates a {@link NodeType} to its {@link String} name.
*/
public static Function<NodeType, String> nodetype2name =
new Function<NodeType, String>() {
@@ -97,7 +96,7 @@ public String apply(final NodeType t) {
};

/**
* Translates a JCR {@link Value} to its {@link String} expression.
* Translates a JCR {@link Value} to its {@link String} expression.
*/
public static Function<Value, String> value2string =
new Function<Value, String>() {
@@ -149,7 +148,7 @@ public ValueFactory apply(final Node n) {

/**
* Creates a JCR {@link Binary}
*
*
* @param n a {@link Node}
* @param i an {@link InputStream}
* @return a JCR {@link Binary}
@@ -173,7 +172,7 @@ public static Binary getBinary(final Node n, final InputStream i) {
* @param i an {@link InputStream}
* @return a JCR {@link Binary}
*/
public static Binary getBinary(final Node n, final InputStream i, final StrategyHint hint) {
public static Binary getBinary(final Node n, final InputStream i, final String hint) {
try {
checkArgument(n != null,
"null cannot have a Binary created for it!");
@@ -187,9 +186,9 @@ public static Binary getBinary(final Node n, final InputStream i, final Strategy
}

/**
* Convenience method for transforming arrays into
* Convenience method for transforming arrays into
* {@link Collection}s through a mapping {@link Function}.
*
*
* @param input A Collection<F>.
* @param f A Function<F,T>.
* @return An ImmutableSet copy of input after transformation by f
@@ -42,7 +42,6 @@
import org.junit.runner.RunWith;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.modeshape.jcr.value.binary.StrategyHint;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@@ -114,7 +113,7 @@ public void testSetContent() throws RepositoryException,
PowerMockito.mockStatic(FedoraTypesUtils.class);
when(
FedoraTypesUtils.getBinary(any(Node.class),
any(InputStream.class), any(StrategyHint.class))).thenReturn(mockBin);
any(InputStream.class), any(String.class))).thenReturn(mockBin);
final Binary content = mock(Binary.class);
final Node mockContent = TestHelpers.getContentNodeMock(8);
when(mockDsNode.getNode(JCR_CONTENT)).thenReturn(mockContent);
@@ -8,7 +8,6 @@
import org.fcrepo.services.ObjectService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.modeshape.jcr.value.binary.NamedHint;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@@ -38,7 +37,7 @@ public void shouldDemonstratePolicyDecisionPoints() throws Exception {
Session session = repo.login();

PolicyDecisionPoint pt = new PolicyDecisionPoint();
pt.addPolicy(new MimeTypePolicy("image/tiff", new NamedHint("tiff-store")));
pt.addPolicy(new MimeTypePolicy("image/tiff", "tiff-store"));

final Node dsNode =
datastreamService.createDatastreamNode(session,
@@ -14,7 +14,6 @@
import org.junit.Test;
import org.modeshape.jcr.JcrRepositoryFactory;
import org.modeshape.jcr.value.BinaryKey;
import org.modeshape.jcr.value.binary.NamedHint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@@ -62,7 +61,7 @@ public void setRepository() throws RepositoryException {
null);

pdp = new PolicyDecisionPoint();
pdp.addPolicy(new MimeTypePolicy("image/tiff", new NamedHint("tiff-store")));
pdp.addPolicy(new MimeTypePolicy("image/tiff", "tiff-store"));

datastreamService = new DatastreamService();
datastreamService.setRepository(repo);
@@ -26,7 +26,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.modeshape.jcr.api.Binary;
import org.modeshape.jcr.value.binary.StrategyHint;

import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@@ -37,15 +37,15 @@
public class DatastreamServiceTest implements FedoraJcrTypes {

private static final String MOCK_CONTENT_TYPE = "application/test-data";

private static final String JCR_CONTENT = "jcr:content";

private static final String JCR_DATA = "jcr:data";

private Session mockSession;

private Node mockRoot;

private DatastreamService testObj;

@Before
@@ -78,13 +78,13 @@ public void testCreateDatastreamNode() throws Exception {
when(pdp.evaluatePolicies(mockNode)).thenReturn(null);
testObj.setStoragePolicyDecisionPoint(pdp);
PowerMockito.mockStatic(FedoraTypesUtils.class);
when(FedoraTypesUtils.getBinary(eq(mockNode), eq(mockIS), any(StrategyHint.class))).thenReturn(mockBinary);
when(FedoraTypesUtils.getBinary(eq(mockNode), eq(mockIS), any(String.class))).thenReturn(mockBinary);

final Node actual =
testObj.createDatastreamNode(mockSession, testPath,
MOCK_CONTENT_TYPE, mockIS);
assertEquals(mockNode, actual);

verify(mockContent).setProperty(JCR_DATA, mockBinary);
}

@@ -1,8 +1,6 @@
package org.fcrepo.binary;

import org.fcrepo.utils.FedoraJcrTypes;
import org.modeshape.jcr.value.binary.NamedHint;
import org.modeshape.jcr.value.binary.StrategyHint;
import org.slf4j.Logger;

import javax.jcr.Node;
@@ -13,29 +11,29 @@

public class MimeTypePolicy implements Policy {

private static final Logger logger = getLogger(MimeTypePolicy.class);

private final String mimeType;
private final StrategyHint hint;

public MimeTypePolicy(String mimeType, StrategyHint hint) {
this.mimeType = mimeType;
this.hint = hint;
}

public StrategyHint evaluatePolicy(Node n) {
logger.debug("Evaluating MimeTypePolicy for {} -> {}", mimeType, hint.toString());
try {
final String nodeMimeType = n.getProperty(FEDORA_CONTENTTYPE).getString();
logger.debug("Found mime type {}", nodeMimeType);
if(nodeMimeType.equals(mimeType)) {
return hint;
}
} catch (RepositoryException e) {
logger.warn("Got Exception evaluating policy: {}", e);
return null;
}

return null;
}
private static final Logger logger = getLogger(MimeTypePolicy.class);

private final String mimeType;
private final String hint;

public MimeTypePolicy(String mimeType, String hint) {
this.mimeType = mimeType;
this.hint = hint;
}

public String evaluatePolicy(Node n) {
logger.debug("Evaluating MimeTypePolicy for {} -> {}", mimeType, hint.toString());
try {
final String nodeMimeType = n.getProperty(FEDORA_CONTENTTYPE).getString();
logger.debug("Found mime type {}", nodeMimeType);
if (nodeMimeType.equals(mimeType)) {
return hint;
}
} catch (RepositoryException e) {
logger.warn("Got Exception evaluating policy: {}", e);
return null;
}

return null;
}
}
@@ -1,9 +1,8 @@
package org.fcrepo.binary;

import org.modeshape.jcr.value.binary.StrategyHint;

import javax.jcr.Node;

public interface Policy {
StrategyHint evaluatePolicy(Node n);
String evaluatePolicy(Node n);
}
@@ -3,40 +3,39 @@
import javax.jcr.Node;
import java.util.ArrayList;
import java.util.List;
import org.modeshape.jcr.value.binary.StrategyHint;
import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;

public class PolicyDecisionPoint {

private static final Logger logger = getLogger(MimeTypePolicy.class);
private static final Logger logger = getLogger(MimeTypePolicy.class);

private List<Policy> policies;
private List<Policy> policies;

public PolicyDecisionPoint() {
logger.debug("Initializing binary PolicyDecisionPoint");
policies = new ArrayList<Policy>();
}
public PolicyDecisionPoint() {
logger.debug("Initializing binary PolicyDecisionPoint");
policies = new ArrayList<Policy>();
}

public void addPolicy(Policy p) {
policies.add(p);
}
public void addPolicy(Policy p) {
policies.add(p);
}

public StrategyHint evaluatePolicies(Node n) {
for(Policy p : policies) {
StrategyHint h = p.evaluatePolicy(n);
if(h != null) {
return h;
}
}
public String evaluatePolicies(Node n) {
for (Policy p : policies) {
String h = p.evaluatePolicy(n);
if (h != null) {
return h;
}
}

return null;
}
return null;
}


public void setPolicies(List<Policy> policies) {
logger.debug("Adding policies to binary PolicyDecisionPoint: {}", policies.toString());
this.policies = policies;
}
public void setPolicies(List<Policy> policies) {
logger.debug("Adding policies to binary PolicyDecisionPoint: {}", policies.toString());
this.policies = policies;
}
}
Oops, something went wrong.

0 comments on commit f6bef32

Please sign in to comment.
You can’t perform that action at this time.