Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #967 from fcrepo4/FCREPO-1865
FCREPO-1865: remove javax.jcr.RepositoryException from kernel-api
  • Loading branch information
acoburn committed Dec 23, 2015
2 parents 7494305 + f00f6ba commit 1704dc6
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 88 deletions.
Expand Up @@ -17,7 +17,6 @@

import java.util.Date;

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

/**
Expand Down Expand Up @@ -51,9 +50,8 @@ public static enum State {
/**
* Get the state of this transaction
* @return transaction state
* @throws RepositoryException if repository exception occurred
*/
State getState() throws RepositoryException;
State getState();

/**
* Get the Date when this transaction is expired and can be
Expand Down
Expand Up @@ -15,8 +15,6 @@
*/
package org.fcrepo.kernel.api.exception;

import javax.jcr.RepositoryException;

/**
* Represents the case where a property definition has been requested but does
* not exist. Typically, this happens when a new property is added to a node
Expand All @@ -25,8 +23,16 @@
* @author ajs6f
* @since Oct 25, 2013
*/
public class NoSuchPropertyDefinitionException extends RepositoryException {
public class NoSuchPropertyDefinitionException extends RepositoryRuntimeException {

private static final long serialVersionUID = 1L;

/**
* Ordinary constructor.
*
* @param msg the message
*/
public NoSuchPropertyDefinitionException(final String msg) {
super(msg);
}
}
Expand Up @@ -15,7 +15,6 @@
*/
package org.fcrepo.kernel.api.services;

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

/**
Expand All @@ -30,10 +29,9 @@ public interface VersionService {
* @param session the session in which the node resides
* @param absPath absolute paths to the node
* @param label a label to be applied to the new version
* @throws RepositoryException if repository exception occurred
* @return the identifier
*/
String createVersion(Session session, String absPath, String label) throws RepositoryException;
String createVersion(Session session, String absPath, String label);

/**
* Reverts the node to the version identified by the label. This method
Expand All @@ -43,10 +41,8 @@ public interface VersionService {
* @param session the session in which the node resides
* @param absPath the path to the node whose version is to be reverted
* @param label identifies the historic version
* @throws RepositoryException if repository exception occurred
*/
void revertToVersion(Session session, String absPath, String label)
throws RepositoryException;
void revertToVersion(Session session, String absPath, String label);

/**
* Remove a version of a node. This method will throw a PathNotFoundException
Expand All @@ -55,9 +51,7 @@ void revertToVersion(Session session, String absPath, String label)
* @param session the session in which the node resides
* @param absPath the path to the node whose version is to be removed
* @param label identifies the historic version by label or id
* @throws RepositoryException if repository exception occurred
*/
void removeVersion(Session session, String absPath, String label)
throws RepositoryException;
void removeVersion(Session session, String absPath, String label);

}
Expand Up @@ -18,8 +18,6 @@
import java.io.InputStream;
import java.util.Collection;

import javax.jcr.RepositoryException;

/**
* A CacheEntry abstraction for the various possible types of entries
* @author fasseg
Expand All @@ -31,23 +29,19 @@ public interface CacheEntry {
* Check the fixity of a {@link CacheEntry}
* @param algorithm the given algorithm
* @return a {@link FixityResult} containing the relevant data
* @throws RepositoryException if repository exception occurred
*/
Collection<FixityResult> checkFixity(final String algorithm)
throws RepositoryException;
Collection<FixityResult> checkFixity(final String algorithm);

/**
* Get a raw input stream from the underlying store
* @return the content for this entry
* @throws RepositoryException if repository exception occurred
*/
abstract InputStream getInputStream() throws RepositoryException;
abstract InputStream getInputStream();

/**
* Generate a human-readable identifier for the location of this entry
*
* @return human-readable identifier for the location of this entry
* @throws RepositoryException if repository exception occurred
*/
abstract String getExternalIdentifier() throws RepositoryException;
abstract String getExternalIdentifier();
}
Expand Up @@ -15,7 +15,6 @@
*/
package org.fcrepo.kernel.api.utils;

import javax.jcr.RepositoryException;
import java.net.URI;
import java.util.Set;

Expand All @@ -35,9 +34,8 @@ public static enum FixityState {
/**
* Get the identifier for the entry's store
* @return String
* @throws RepositoryException if repository exception occurred
*/
String getStoreIdentifier() throws RepositoryException;
String getStoreIdentifier();

/**
* Check if the fixity result matches the given checksum URI
Expand Down
Expand Up @@ -49,8 +49,6 @@
import java.util.Collection;

import static com.codahale.metrics.MetricRegistry.name;
import static org.fcrepo.kernel.api.FedoraTypes.HAS_MIME_TYPE;
import static org.fcrepo.kernel.api.FedoraTypes.FILENAME;
import static org.fcrepo.kernel.modeshape.utils.FedoraTypesUtils.isFedoraBinary;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;
import static org.modeshape.jcr.api.JcrConstants.JCR_DATA;
Expand Down
Expand Up @@ -101,11 +101,15 @@ public String getId() {
* @see org.fcrepo.kernel.api.Transaction#getState()
*/
@Override
public State getState() throws RepositoryException {
if (this.session != null && this.session.hasPendingChanges()) {
return DIRTY;
public State getState() {
try {
if (this.session != null && this.session.hasPendingChanges()) {
return DIRTY;
}
return state;
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
return state;
}

/* (non-Javadoc)
Expand Down
Expand Up @@ -15,6 +15,7 @@
*/
package org.fcrepo.kernel.modeshape.services;

import org.fcrepo.kernel.api.exception.RepositoryRuntimeException;
import org.fcrepo.kernel.api.services.VersionService;
import org.fcrepo.kernel.modeshape.FedoraBinaryImpl;
import org.slf4j.Logger;
Expand Down Expand Up @@ -53,34 +54,40 @@ public class VersionServiceImpl extends AbstractService implements VersionServic
private static final Pattern invalidLabelPattern = Pattern.compile("[~#@*+%{}<>\\[\\]|\"^]");

@Override
public String createVersion(final Session session,
final String absPath, final String label) throws RepositoryException {
final Node node = session.getNode(absPath);
if (!isVersioningEnabled(node)) {
enableVersioning(node);
public String createVersion(final Session session, final String absPath, final String label) {
try {
final Node node = session.getNode(absPath);
if (!isVersioningEnabled(node)) {
enableVersioning(node);
}
return checkpoint(session, absPath, label);
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
return checkpoint(session, absPath, label);
}

@Override
public void revertToVersion(final Session session, final String absPath,
final String label) throws RepositoryException {
public void revertToVersion(final Session session, final String absPath, final String label) {
final Workspace workspace = session.getWorkspace();
final Version v = getVersionForLabel(workspace, absPath, label);
if (v == null) {
throw new PathNotFoundException("Unknown version \"" + label + "\"!");
}
final VersionManager versionManager = workspace.getVersionManager();
final Version preRevertVersion = versionManager.checkin(absPath);

try {
preRevertVersion.getContainingHistory().addVersionLabel(preRevertVersion.getName(),
getPreRevertVersionLabel(label, preRevertVersion.getContainingHistory()), false);
} catch (final LabelExistsVersionException e) {
// fall-back behavior is to leave an unlabeled version
final Version v = getVersionForLabel(workspace, absPath, label);
if (v == null) {
throw new PathNotFoundException("Unknown version \"" + label + "\"!");
}
final VersionManager versionManager = workspace.getVersionManager();
final Version preRevertVersion = versionManager.checkin(absPath);

try {
preRevertVersion.getContainingHistory().addVersionLabel(preRevertVersion.getName(),
getPreRevertVersionLabel(label, preRevertVersion.getContainingHistory()), false);
} catch (final LabelExistsVersionException e) {
// fall-back behavior is to leave an unlabeled version
}
versionManager.restore(v, true);
versionManager.checkout(absPath);
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
versionManager.restore(v, true);
versionManager.checkout(absPath);
}

/**
Expand All @@ -105,24 +112,26 @@ private static String getPreRevertVersionLabel(final String targetLabel, final V
}

@Override
public void removeVersion(final Session session, final String absPath,
final String label) throws RepositoryException {
public void removeVersion(final Session session, final String absPath, final String label) {
final Workspace workspace = session.getWorkspace();
final Version v = getVersionForLabel(workspace, absPath, label);

if (v == null) {
throw new PathNotFoundException("Unknown version \"" + label + "\"!");
} else if (workspace.getVersionManager().getBaseVersion(absPath).equals(v) ) {
throw new VersionException("Cannot remove most recent version snapshot.");
} else {
// remove labels
final VersionHistory history = v.getContainingHistory();
final String[] versionLabels = history.getVersionLabels(v);
for ( final String versionLabel : versionLabels ) {
LOGGER.debug("Removing label: {}", versionLabel);
history.removeVersionLabel( versionLabel );
try {
final Version v = getVersionForLabel(workspace, absPath, label);
if (v == null) {
throw new PathNotFoundException("Unknown version \"" + label + "\"!");
} else if (workspace.getVersionManager().getBaseVersion(absPath).equals(v) ) {
throw new VersionException("Cannot remove most recent version snapshot.");
} else {
// remove labels
final VersionHistory history = v.getContainingHistory();
final String[] versionLabels = history.getVersionLabels(v);
for ( final String versionLabel : versionLabels ) {
LOGGER.debug("Removing label: {}", versionLabel);
history.removeVersionLabel( versionLabel );
}
history.removeVersion( v.getName() );
}
history.removeVersion( v.getName() );
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
}

Expand Down
Expand Up @@ -53,11 +53,9 @@ public abstract class BasicCacheEntry implements CacheEntry {
*
* @param digest the digest
* @return the fixity of this cache entry
* @throws RepositoryException if repository exception occurred
*/
@Override
public Collection<FixityResult> checkFixity(final String digest)
throws RepositoryException {
public Collection<FixityResult> checkFixity(final String digest) {

try (FixityInputStream fixityInputStream = new FixityInputStream(this.getInputStream(),
MessageDigest.getInstance(digest))) {
Expand All @@ -77,9 +75,8 @@ public Collection<FixityResult> checkFixity(final String digest)
} catch (final IOException e) {
LOGGER.debug("Got error closing input stream: {}", e);
throw new RepositoryRuntimeException(e);
} catch (final NoSuchAlgorithmException e1) {
} catch (final NoSuchAlgorithmException | RepositoryException e1) {
throw new RepositoryRuntimeException(e1);
}

}
}
Expand Up @@ -19,6 +19,7 @@

import javax.jcr.Property;
import javax.jcr.RepositoryException;
import org.fcrepo.kernel.api.exception.RepositoryRuntimeException;

/**
* A {@link org.fcrepo.kernel.api.utils.CacheEntry} for simple Binary objects
Expand All @@ -43,17 +44,25 @@ public BinaryCacheEntry(final Property property) {
* @see org.fcrepo.kernel.api.utils.CacheEntry#getInputStream()
*/
@Override
public InputStream getInputStream() throws RepositoryException {
return property.getBinary().getStream();
public InputStream getInputStream() {
try {
return property.getBinary().getStream();
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
}

/*
* (non-Javadoc)
* @see org.fcrepo.kernel.api.utils.CacheEntry#getExternalIdentifier()
*/
@Override
public String getExternalIdentifier() throws RepositoryException {
return property.getPath();
public String getExternalIdentifier() {
try {
return property.getPath();
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
}

protected Property property() {
Expand Down
Expand Up @@ -15,6 +15,8 @@
*/
package org.fcrepo.kernel.modeshape.utils;

import org.fcrepo.kernel.api.exception.RepositoryRuntimeException;

import org.modeshape.connector.filesystem.FileSystemConnector;

import javax.jcr.Property;
Expand All @@ -36,8 +38,11 @@ public ProjectedCacheEntry(final Property property) {
}

@Override
public String getExternalIdentifier() throws RepositoryException {
return "/" + FileSystemConnector.class.getName() + ":projections:" + property().getPath();
public String getExternalIdentifier() {
try {
return "/" + FileSystemConnector.class.getName() + ":projections:" + property().getPath();
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
}

}

0 comments on commit 1704dc6

Please sign in to comment.