Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Non-functional update: Refactor Storage Policy names
  • Loading branch information
Andrew Woods committed Sep 11, 2013
1 parent 15d2277 commit f6fc189
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 94 deletions.
Expand Up @@ -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
Expand Down
Expand Up @@ -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);
}
Expand Up @@ -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
*
Expand All @@ -33,7 +33,7 @@ public interface StoragePolicyDecisionPoint {
*
* @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
Expand All @@ -49,19 +49,19 @@ public interface StoragePolicyDecisionPoint {
*
* @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
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -81,7 +81,7 @@ public class StoragePolicy extends AbstractResource {

public static final String POLICY_RESOURCE = "policies";

private static final Logger LOGGER = getLogger(StoragePolicy.class);
private static final Logger LOGGER = getLogger(FedoraStoragePolicy.class);

/**
* Initialize
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand All @@ -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");
}
}

Expand All @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -43,14 +43,14 @@ public class MimeTypePolicy implements Policy {
/**
* 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 + "]";
}

/**
Expand All @@ -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 =
Expand Down Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
Expand All @@ -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);
}

Expand All @@ -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;
Expand All @@ -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() {
Expand All @@ -96,7 +96,7 @@ public void removeAll() {
* @param p
*/
@Override
public boolean contains(Policy p) {
public boolean contains(StoragePolicy p) {
return policies.contains(p);
}

Expand All @@ -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;
}

Expand Down
Expand Up @@ -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);
}

Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit f6fc189

Please sign in to comment.