Permalink
Browse files

Non-functional update: Refactor Storage Policy names

  • Loading branch information...
awoods committed Sep 11, 2013
1 parent 15d2277 commit f6fc189ffc03618df54d9da5fc278aae2ab77d49
Showing with 91 additions and 94 deletions.
  1. +1 −1 fcrepo-kernel/src/main/java/org/fcrepo/kernel/services/DatastreamService.java
  2. +2 −2 fcrepo-kernel/src/main/java/org/fcrepo/kernel/services/policy/{Policy.java → StoragePolicy.java}
  3. +5 −5 fcrepo-kernel/src/main/java/org/fcrepo/kernel/services/policy/StoragePolicyDecisionPoint.java
  4. +19 −19 ...ge-policy/src/main/java/org/fcrepo/storage/policy/{StoragePolicy.java → FedoraStoragePolicy.java}
  5. +7 −7 ...policy/src/main/java/org/fcrepo/storage/policy/{MimeTypePolicy.java → MimeTypeStoragePolicy.java}
  6. +15 −15 ...n/java/org/fcrepo/storage/policy/{PolicyDecisionPoint.java → StoragePolicyDecisionPointImpl.java}
  7. +2 −2 .../main/java/org/fcrepo/storage/policy/{PolicyTypeException.java → StoragePolicyTypeException.java}
  8. +4 −4 ...olicy/src/test/java/org/fcrepo/storage/policy/{StoragePolicyIT.java → FedoraStoragePolicyIT.java}
  9. +16 −17 ...y/src/test/java/org/fcrepo/storage/policy/{StoragePolicyTest.java → FedoraStoragePolicyTest.java}
  10. +8 −8 ...rc/test/java/org/fcrepo/storage/policy/{MimeTypePolicyTest.java → MimeTypeStoragePolicyTest.java}
  11. +6 −6 ...va/org/fcrepo/storage/policy/{PolicyDecisionPointTest.java → StoragePolicyDecisionPointTest.java}
  12. +4 −6 .../test/java/org/fcrepo/storage/policy/{TiffPolicyStorageIT.java → TiffStoragePolicyStorageIT.java}
  13. +1 −1 fcrepo-storage-policy/src/test/resources/spring-test/rest.xml
  14. +1 −1 fcrepo-webapp/src/main/resources/spring/rest.xml
@@ -316,7 +316,7 @@ public void setStoragePolicyDecisionPoint(final StoragePolicyDecisionPoint pdp)
}
/**
* Get the Policy Decision Point for this service. Initialize it if Spring
* Get the StoragePolicy Decision Point for this service. Initialize it if Spring
* didn't wire it in for us.
*
* @return a PolicyDecisionPoint
@@ -22,11 +22,11 @@
* @author cbeer
* @date Apr 25, 2013
*/
public interface Policy {
public interface StoragePolicy {
/**
* Evaluate the policy; if the policy matches, return the
* binary storage hint. If not, return null.
*/
String evaluatePolicy(Node n);
public String evaluatePolicy(Node n);
}
@@ -21,7 +21,7 @@
import java.util.List;
/**
* Service Interface implementation for managing and using org.fcrepo.kernel.services.policy.Policy
* Service Interface implementation for managing and using StoragePolicy
* @author osmandin
* @date Aug 14, 2013
*
@@ -33,7 +33,7 @@
*
* @param p org.fcrepo.kernel.services.policy object
*/
void addPolicy(final Policy p);
void addPolicy(final StoragePolicy p);
/**
* Given a JCR node (likely a jcr:content node), determine which storage
@@ -49,19 +49,19 @@
*
* @param p org.fcrepo.kernel.services.policy object
*/
void removePolicy(final Policy p);
void removePolicy(final StoragePolicy p);
/**
* Explicitly set the policies this PDP should use
*
* @param policies
*/
void setPolicies(final List<Policy> policies);
void setPolicies(final List<StoragePolicy> policies);
/**
* @param policy
*/
boolean contains(final Policy policy);
boolean contains(final StoragePolicy policy);
/**
* clear all policies
@@ -23,7 +23,7 @@
import com.codahale.metrics.annotation.Timed;
import org.apache.commons.lang.StringUtils;
import org.fcrepo.http.commons.AbstractResource;
import org.fcrepo.kernel.services.policy.Policy;
import org.fcrepo.kernel.services.policy.StoragePolicy;
import org.fcrepo.kernel.services.policy.StoragePolicyDecisionPoint;
import org.fcrepo.http.commons.session.InjectedSession;
import org.modeshape.jcr.api.JcrTools;
@@ -66,7 +66,7 @@
@Component
@Scope("prototype")
@Path("/{path: .*}/fcr:storagepolicy")
public class StoragePolicy extends AbstractResource {
public class FedoraStoragePolicy extends AbstractResource {
@InjectedSession
protected Session session;
@@ -81,7 +81,7 @@
public static final String POLICY_RESOURCE = "policies";
private static final Logger LOGGER = getLogger(StoragePolicy.class);
private static final Logger LOGGER = getLogger(FedoraStoragePolicy.class);
/**
* Initialize
@@ -145,10 +145,10 @@ public Response post(final @PathParam("path") String path,
node.setProperty(str[0], new String[] {str[1] + ":" + str[2]});
// TODO (for now) instantiate PolicyType based on mix:mimeType
Policy policy = newPolicyInstance(str[0], str[1], str[2]);
StoragePolicy policy = newPolicyInstance(str[0], str[1], str[2]);
// TODO (for now) based on object comparison using equals()
if (storagePolicyDecisionPoint.contains(policy)) {
throw new PolicyTypeException("Property already exists!");
throw new StoragePolicyTypeException("Property already exists!");
}
storagePolicyDecisionPoint.addPolicy(policy);
session.save();
@@ -159,7 +159,7 @@ public Response post(final @PathParam("path") String path,
.path("fcr:storagepolicy")
.build());
} else {
throw new PolicyTypeException(
throw new StoragePolicyTypeException(
"Invalid property type specified: " + str[0]);
}
} catch (final Exception e) {
@@ -172,25 +172,25 @@ public Response post(final @PathParam("path") String path,
}
/**
* For nodeType n or runtime property p get org.fcrepo.binary.Policy
* For nodeType n or runtime property p get org.fcrepo.binary.StoragePolicy
* implementation. Note: Signature might need to change, or a more
* sophisticated method used, as implementation evolves.
*
* @param propertyType
* @param itemType
* @param value
* @return
* @throws PolicyTypeException
* @throws StoragePolicyTypeException
*/
protected Policy newPolicyInstance(final String propertyType,
final String itemType, final String value) throws PolicyTypeException {
protected StoragePolicy newPolicyInstance(final String propertyType,
final String itemType, final String value) throws StoragePolicyTypeException {
switch (propertyType) {
case NodeType.MIX_MIMETYPE:
case "mix:mimeType":
return new MimeTypePolicy(itemType, value);
return new MimeTypeStoragePolicy(itemType, value);
default:
throw new PolicyTypeException("Mapping not found");
throw new StoragePolicyTypeException("Mapping not found");
}
}
@@ -214,8 +214,8 @@ public Response deleteNodeType(@PathParam("path") final String nodeType)
session.save();
// remove all MimeType intances (since thats only the stored
// Policy for now.
// TODO Once Policy is updated to display Policy type, this
// StoragePolicy for now.
// TODO Once StoragePolicy is updated to display StoragePolicy type, this
// would change
storagePolicyDecisionPoint.removeAll();
return Response.noContent().build();
@@ -229,7 +229,7 @@ public Response deleteNodeType(@PathParam("path") final String nodeType)
}
/**
* TODO (for now) prints org.fcrepo.binary.PolicyDecisionPoint
* TODO (for now) prints org.fcrepo.binary.StoragePolicyDecisionPointImpl
*
* @return
* @throws RepositoryException
@@ -264,14 +264,14 @@ private Response getStoragePolicy(final String nodeType) {
Property prop = node.getProperty(nodeType);
if (null == prop) {
throw new PathNotFoundException("Policy not found: " + nodeType);
throw new PathNotFoundException("StoragePolicy not found: " + nodeType);
}
Value[] values = prop.getValues();
if (values != null && values.length > 0) {
response = Response.ok(values[0].getString());
} else {
throw new PathNotFoundException("Policy not found: " + nodeType);
throw new PathNotFoundException("StoragePolicy not found: " + nodeType);
}
} catch (PathNotFoundException e) {
@@ -309,10 +309,10 @@ private boolean isValidNodeTypeProperty(final Session session,
* applicable runtime configurations)
*
* @return
* @throws PolicyTypeException
* @throws StoragePolicyTypeException
*/
private boolean isValidConfigurationProperty(String property)
throws PolicyTypeException {
throws StoragePolicyTypeException {
// TODO (for now) returns false. For future, need to represent & eval.
// non node type props
return false;
@@ -20,7 +20,7 @@
import static org.modeshape.jcr.api.JcrConstants.JCR_MIME_TYPE;
import static org.slf4j.LoggerFactory.getLogger;
import org.fcrepo.kernel.services.policy.Policy;
import org.fcrepo.kernel.services.policy.StoragePolicy;
import org.slf4j.Logger;
import javax.jcr.Node;
@@ -32,9 +32,9 @@
* @author cbeer
* @date Apr 25, 2013
*/
public class MimeTypePolicy implements Policy {
public class MimeTypeStoragePolicy implements StoragePolicy {
private static final Logger LOGGER = getLogger(MimeTypePolicy.class);
private static final Logger LOGGER = getLogger(MimeTypeStoragePolicy.class);
private final String mimeType;
@@ -43,14 +43,14 @@
/**
* Register a mime type => binary storage hint mapping
*/
public MimeTypePolicy(final String mimeType, final String hint) {
public MimeTypeStoragePolicy(final String mimeType, final String hint) {
this.mimeType = mimeType;
this.hint = hint;
}
@Override
public String toString() {
return "MimeTypePolicy [mimeType=" + mimeType + ", hint=" + hint + "]";
return "MimeTypeStoragePolicy [mimeType=" + mimeType + ", hint=" + hint + "]";
}
/**
@@ -59,7 +59,7 @@ public String toString() {
*/
@Override
public String evaluatePolicy(final Node n) {
LOGGER.debug("Evaluating MimeTypePolicy ({} -> {}) for {} ", mimeType,
LOGGER.debug("Evaluating MimeTypeStoragePolicy ({} -> {}) for {} ", mimeType,
hint, n);
try {
final String nodeMimeType =
@@ -108,7 +108,7 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass()) {
return false;
}
MimeTypePolicy other = (MimeTypePolicy) obj;
MimeTypeStoragePolicy other = (MimeTypeStoragePolicy) obj;
if (hint == null) {
if (other.hint != null) {
return false;
@@ -18,8 +18,8 @@
import static org.slf4j.LoggerFactory.getLogger;
import org.fcrepo.kernel.services.policy.Policy;
import org.fcrepo.kernel.services.policy.StoragePolicyDecisionPoint;
import org.fcrepo.kernel.services.policy.StoragePolicy;
import org.slf4j.Logger;
import javax.jcr.Node;
@@ -34,26 +34,26 @@
* @author cbeer
* @date Apr 25, 2013
*/
public class PolicyDecisionPoint implements StoragePolicyDecisionPoint {
public class StoragePolicyDecisionPointImpl implements StoragePolicyDecisionPoint {
private static final Logger LOGGER = getLogger(PolicyDecisionPoint.class);
private static final Logger LOGGER = getLogger(StoragePolicyDecisionPointImpl.class);
private List<Policy> policies;
private List<StoragePolicy> policies;
/**
* Initialize the policy storage machinery
*/
public PolicyDecisionPoint() {
LOGGER.debug("Initializing binary PolicyDecisionPoint");
policies = new ArrayList<Policy>();
public StoragePolicyDecisionPointImpl() {
LOGGER.debug("Initializing binary StoragePolicyDecisionPointImpl");
policies = new ArrayList<StoragePolicy>();
}
/*
* (non-Javadoc)
* @see org.fcrepo.kernel.services.policy.StoragePolicyDecisionPoint#addPolicy(org.fcrepo.kernel.services.policy.Policy)
* @see org.fcrepo.kernel.services.policy.StoragePolicyDecisionPoint#addPolicy(org.fcrepo.kernel.services.policy.StoragePolicy)
*/
@Override
public void addPolicy(final Policy p) {
public void addPolicy(final org.fcrepo.kernel.services.policy.StoragePolicy p) {
policies.add(p);
}
@@ -63,7 +63,7 @@ public void addPolicy(final Policy p) {
*/
@Override
public String evaluatePolicies(final Node n) {
for (final Policy p : policies) {
for (final StoragePolicy p : policies) {
final String h = p.evaluatePolicy(n);
if (h != null) {
return h;
@@ -74,16 +74,16 @@ public String evaluatePolicies(final Node n) {
/*
* (non-Javadoc)
* @see org.fcrepo.kernel.services.policy.StoragePolicyDecisionPoint#addPolicy(org.fcrepo.kernel.services.policy.Policy)
* @see org.fcrepo.kernel.services.policy.StoragePolicyDecisionPoint#addPolicy(org.fcrepo.kernel.services.policy.StoragePolicy)
*/
@Override
public void removePolicy(final Policy p) {
public void removePolicy(final StoragePolicy p) {
policies.remove(p);
}
/*
* (non-Javadoc)
* @see org.fcrepo.kernel.services.policy.StoragePolicyDecisionPoint#addPolicy(org.fcrepo.kernel.services.policy.Policy)
* @see org.fcrepo.kernel.services.policy.StoragePolicyDecisionPoint#addPolicy(org.fcrepo.kernel.services.policy.StoragePolicy)
*/
@Override
public void removeAll() {
@@ -96,7 +96,7 @@ public void removeAll() {
* @param p
*/
@Override
public boolean contains(Policy p) {
public boolean contains(StoragePolicy p) {
return policies.contains(p);
}
@@ -105,7 +105,7 @@ public boolean contains(Policy p) {
* @see org.fcrepo.kernel.services.policy.StoragePolicyDecisionPoint#setPolicies(java.util.List)
*/
@Override
public void setPolicies(final List<Policy> policies) {
public void setPolicies(final List<StoragePolicy> policies) {
this.policies = policies;
}
@@ -21,11 +21,11 @@
* (where other exceptions are not adequate).
*/
public class PolicyTypeException extends RuntimeException {
public class StoragePolicyTypeException extends RuntimeException {
/**
* @param arg0
*/
public PolicyTypeException(final String arg0) {
public StoragePolicyTypeException(final String arg0) {
super(arg0);
}
@@ -16,7 +16,7 @@
package org.fcrepo.storage.policy;
import static org.fcrepo.storage.policy.StoragePolicy.POLICY_RESOURCE;
import static org.fcrepo.storage.policy.FedoraStoragePolicy.POLICY_RESOURCE;
import static org.junit.Assert.assertEquals;
import org.apache.http.Header;
@@ -26,7 +26,7 @@
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.tika.io.IOUtils;
import org.fcrepo.kernel.services.policy.Policy;
import org.fcrepo.kernel.services.policy.StoragePolicy;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -40,7 +40,7 @@
import static org.junit.Assert.fail;
// Runs integration test for restful interface for storage policies
public class StoragePolicyIT extends AbstractResourceIT {
public class FedoraStoragePolicyIT extends AbstractResourceIT {
private static final String MIME_KEY = "mix:mimeType";
private static final String MIME = "image/tiff";
@@ -119,7 +119,7 @@ public void testGetStoragePolicies() throws Exception {
String body = IOUtils.toString(response1.getEntity().getContent());
assertEquals(body, 200, response1.getStatusLine().getStatusCode());
Policy policy = new MimeTypePolicy(MIME, STORE);
StoragePolicy policy = new MimeTypeStoragePolicy(MIME, STORE);
assertEquals("policies=[" + policy.toString() + "]", body);
}
Oops, something went wrong.

0 comments on commit f6fc189

Please sign in to comment.