Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update based on impact of fcrepo shift from checked to runtime except…
  • Loading branch information
Andrew Woods committed Sep 16, 2014
1 parent 2951f4e commit ca1a0fd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
Expand Up @@ -30,6 +30,7 @@

import org.fcrepo.http.commons.session.SessionFactory;
import org.fcrepo.kernel.Datastream;
import org.fcrepo.kernel.exception.RepositoryRuntimeException;
import org.fcrepo.kernel.services.DatastreamService;
import org.fcrepo.kernel.services.NodeService;
import org.jboss.security.xacml.sunxacml.AbstractPolicy;
Expand Down Expand Up @@ -231,7 +232,7 @@ public final PolicyFinderResult findPolicy(final URI idReference,

return new PolicyFinderResult(policy);

} catch (final RepositoryException e) {
} catch (final RepositoryRuntimeException e) {
LOGGER.warn("Failed to retrieve a policy for " + idReference.toString(), e);
return new PolicyFinderResult();
}
Expand Down
Expand Up @@ -33,6 +33,7 @@

import org.fcrepo.http.commons.session.SessionFactory;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.exception.RepositoryRuntimeException;
import org.fcrepo.kernel.rdf.IdentifierTranslator;
import org.fcrepo.kernel.impl.rdf.impl.DefaultIdentifierTranslator;
import org.fcrepo.kernel.services.NodeService;
Expand Down Expand Up @@ -134,7 +135,7 @@ public final EvaluationResult findAttribute(final URI attributeType,
final Session session;
try {
session = sessionFactory.getInternalSession();
} catch (final RepositoryException e) {
} catch (final RepositoryRuntimeException e) {
LOGGER.debug("Error getting session!");
final Status status = new Status(singletonList(STATUS_PROCESSING_ERROR), "Error getting session");
return new EvaluationResult(status);
Expand Down Expand Up @@ -174,7 +175,7 @@ public final EvaluationResult findAttribute(final URI attributeType,
path = resource.getPath();
idTranslator = new DefaultIdentifierTranslator();

} catch (final RepositoryException e) {
} catch (final RepositoryRuntimeException e) {
// If the object does not exist, it may be due to the action being "create"
return new EvaluationResult(empty_bag);
}
Expand All @@ -183,12 +184,22 @@ public final EvaluationResult findAttribute(final URI attributeType,

// Get the properties of the resource
Model properties;
Resource graphNode;
try {
properties = resource.getTriples(idTranslator).asModel();

} catch (final RepositoryRuntimeException e) {
LOGGER.debug("Cannot retrieve any properties for [{}]: {}", resourceId, e);
final Status status =
new Status(singletonList(STATUS_PROCESSING_ERROR),
"Error retrieving properties for [" + path + "]!");
return new EvaluationResult(status);
}

Resource graphNode;
try {
graphNode = idTranslator.getSubject(resource.getPath());
} catch (final RepositoryException e) {
LOGGER.debug("Cannot retrieve any properties for [{}]: {}", resourceId, e);
LOGGER.debug("Cannot get subject for[{}]: {}", resource.getPath(), e);
final Status status =
new Status(singletonList(STATUS_PROCESSING_ERROR),
"Error retrieving properties for [" + path + "]!");
Expand Down
Expand Up @@ -30,12 +30,12 @@
import java.net.URI;
import java.util.Set;

import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;

import org.fcrepo.http.commons.session.SessionFactory;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.exception.RepositoryRuntimeException;
import org.fcrepo.kernel.rdf.IdentifierTranslator;
import org.fcrepo.kernel.services.NodeService;
import org.fcrepo.kernel.utils.iterators.RdfStream;
Expand Down Expand Up @@ -197,7 +197,7 @@ public void testFindAttributeBySelector() {

@Test
public void testFindAttributeInvalidSession() throws RepositoryException {
when(mockSessionFactory.getInternalSession()).thenThrow(new RepositoryException());
when(mockSessionFactory.getInternalSession()).thenThrow(new RepositoryRuntimeException("expected"));
final EvaluationResult result = doFindAttribute("/{ns}path/{ns}to/{ns}resource");
final String status = (String) result.getStatus().getCode().get(0);
assertEquals("Evaluation status should be STATUS_PROCESSING_ERROR!", status,
Expand Down Expand Up @@ -235,7 +235,7 @@ public void testFindAttributeNewResourceId() throws RepositoryException {
final String[] actions = { "read" };

when(mockNodeService.getObject(mockSession, resourceId)).thenReturn(mockFedoraResource);
when(mockFedoraResource.getPath()).thenThrow(new PathNotFoundException());
when(mockFedoraResource.getPath()).thenThrow(new RepositoryRuntimeException("expected"));

final EvaluationResult result = doFindAttribute(resourceId, actions);
final BagAttribute bag = (BagAttribute) result.getAttributeValue();
Expand Down Expand Up @@ -298,7 +298,7 @@ public void testFindAttributeBadProperties() throws RepositoryException {

when(mockNodeService.getObject(mockSession, resourceId)).thenReturn(mockFedoraResource);
when(mockFedoraResource.getTriples(any(IdentifierTranslator.class))).thenThrow(
new RepositoryException());
new RepositoryRuntimeException("expected"));

final EvaluationResult result = doFindAttribute(resourceId, actions);
final String status = (String) result.getStatus().getCode().get(0);
Expand Down
Expand Up @@ -34,6 +34,7 @@

import org.fcrepo.http.commons.session.SessionFactory;
import org.fcrepo.kernel.Datastream;
import org.fcrepo.kernel.exception.RepositoryRuntimeException;
import org.fcrepo.kernel.services.DatastreamService;

import org.junit.Before;
Expand Down Expand Up @@ -130,9 +131,9 @@ public void testInit() throws Exception {
verify(mockNode).setProperty(eq("authz:policy"), any(Node.class));
}

@Test(expected = Error.class)
@Test(expected = RepositoryRuntimeException.class)
public void testInitInitialPoliciesException() throws Exception {
when(mockSessionFactory.getInternalSession()).thenThrow(new RepositoryException("expected"));
when(mockSessionFactory.getInternalSession()).thenThrow(new RepositoryRuntimeException("expected"));

xacmlWI.init();
}
Expand Down

0 comments on commit ca1a0fd

Please sign in to comment.