Skip to content

Commit

Permalink
Non-functional whitespace clean-up
Browse files Browse the repository at this point in the history
Clean-up static imports where appropriate
Improve code syntax for constructors to make more clear the use of JcrTools
Clean-up whitespace formatting
  • Loading branch information
ajs6f authored and Andrew Woods committed Oct 21, 2013
1 parent f80dfc1 commit 5a8c48d
Show file tree
Hide file tree
Showing 33 changed files with 466 additions and 456 deletions.
25 changes: 12 additions & 13 deletions fcrepo-kernel/src/main/java/org/fcrepo/kernel/Datastream.java
Expand Up @@ -97,11 +97,11 @@ private void mixinTypeSpecificCrap() {
node.addMixin(FEDORA_DATASTREAM);

if (node.hasNode(JCR_CONTENT)) {
Node contentNode = node.getNode(JCR_CONTENT);
final Node contentNode = node.getNode(JCR_CONTENT);
decorateContentNode(contentNode);
}
}
} catch (RepositoryException ex) {
} catch (final RepositoryException ex) {
LOGGER.warn("Could not decorate {} with {} properties: {}" ,
JCR_CONTENT, FEDORA_DATASTREAM, ex);
}
Expand All @@ -124,8 +124,7 @@ public InputStream getContent() throws RepositoryException {
* @throws RepositoryException
*/
public void setContent(final InputStream content, final String contentType,
final URI checksum,
StoragePolicyDecisionPoint storagePolicyDecisionPoint)
final URI checksum, final StoragePolicyDecisionPoint storagePolicyDecisionPoint)
throws RepositoryException, InvalidChecksumException {

final Node contentNode =
Expand All @@ -149,7 +148,7 @@ public void setContent(final InputStream content, final String contentType,
hint = storagePolicyDecisionPoint.evaluatePolicies(node);
}

Binary binary = (Binary) getBinary(node, content, hint);
final Binary binary = (Binary) getBinary(node, content, hint);

/*
* This next line of code deserves explanation. If we chose for the
Expand Down Expand Up @@ -189,7 +188,7 @@ public void setContent(final InputStream content, final String contentType,
* @throws InvalidChecksumException
* @throws RepositoryException
*/
public void setContent(InputStream content) throws InvalidChecksumException,
public void setContent(final InputStream content) throws InvalidChecksumException,
RepositoryException {
setContent(content, null, null, null);
}
Expand All @@ -202,7 +201,7 @@ public long getContentSize() {
try {
return node.getNode(JCR_CONTENT).getProperty(CONTENT_SIZE)
.getLong();
} catch (RepositoryException e) {
} catch (final RepositoryException e) {
LOGGER.error("Could not get contentSize() - " + e.getMessage());
}
// TODO Size is not stored, recalculate size?
Expand All @@ -218,16 +217,16 @@ public URI getContentDigest() throws RepositoryException {
final Node contentNode = node.getNode(JCR_CONTENT);
try {
return new URI(contentNode.getProperty(CONTENT_DIGEST).getString());
} catch (RepositoryException e) {
} catch (final RepositoryException e) {
LOGGER.error("Could not get content digest: ", e);
} catch (URISyntaxException e) {
} catch (final URISyntaxException e) {
LOGGER.error("Could not get content digest: {}", e);
}
//TODO checksum not stored. recalculating checksum,
//however, this would defeat the purpose validating against the checksum
Binary binary = (Binary) contentNode.getProperty(JCR_DATA)
final Binary binary = (Binary) contentNode.getProperty(JCR_DATA)
.getBinary();
String dsChecksum = binary.getHexHash();
final String dsChecksum = binary.getHexHash();

return ContentDigest.asURI("SHA-1",dsChecksum);
}
Expand Down Expand Up @@ -271,7 +270,7 @@ public long getSize() throws RepositoryException {

}

private void decorateContentNode(Node contentNode)
private void decorateContentNode(final Node contentNode)
throws RepositoryException {
if (contentNode == null) {
LOGGER.warn("{}/{} appears to be null!", JCR_CONTENT);
Expand All @@ -282,7 +281,7 @@ private void decorateContentNode(Node contentNode)
}

final Property dataProperty = contentNode.getProperty(JCR_DATA);
Binary binary = (Binary) dataProperty.getBinary();
final Binary binary = (Binary) dataProperty.getBinary();
final String dsChecksum = binary.getHexHash();

contentSizeHistogram.update(dataProperty.getLength());
Expand Down
60 changes: 31 additions & 29 deletions fcrepo-kernel/src/main/java/org/fcrepo/kernel/FedoraResource.java
Expand Up @@ -15,12 +15,18 @@
*/
package org.fcrepo.kernel;

import static com.hp.hpl.jena.update.UpdateAction.execute;
import static com.hp.hpl.jena.update.UpdateFactory.create;
import static org.apache.commons.codec.digest.DigestUtils.shaHex;
import static org.fcrepo.kernel.rdf.GraphProperties.URI_SYMBOL;
import static org.fcrepo.kernel.services.ServiceHelpers.getObjectSize;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.getBaseVersion;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.getVersionHistory;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.isFedoraResource;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.map;
import static org.fcrepo.kernel.utils.FedoraTypesUtils.nodetype2name;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;
import static org.modeshape.jcr.api.JcrConstants.NT_FOLDER;
import static org.slf4j.LoggerFactory.getLogger;

import java.util.Calendar;
Expand All @@ -32,22 +38,17 @@
import javax.jcr.Session;
import javax.jcr.version.VersionHistory;

import org.apache.commons.codec.digest.DigestUtils;
import org.fcrepo.jcr.FedoraJcrTypes;
import org.fcrepo.kernel.rdf.GraphProperties;
import org.fcrepo.kernel.rdf.GraphSubjects;
import org.fcrepo.kernel.rdf.impl.JcrGraphProperties;
import org.fcrepo.kernel.utils.FedoraTypesUtils;
import org.fcrepo.kernel.utils.JcrRdfTools;
import org.modeshape.jcr.api.JcrConstants;
import org.modeshape.jcr.api.JcrTools;
import org.slf4j.Logger;

import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.query.DatasetFactory;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.update.UpdateAction;
import com.hp.hpl.jena.update.UpdateFactory;
import com.hp.hpl.jena.update.UpdateRequest;

/**
Expand All @@ -69,6 +70,7 @@ public class FedoraResource extends JcrTools implements FedoraJcrTypes {
* Construct a FedoraObject without a backing JCR Node
*/
public FedoraResource() {
super(false);
node = null;
this.properties = DEFAULT_PROPERTY_FACTORY;
}
Expand All @@ -78,9 +80,8 @@ public FedoraResource() {
* @param node an existing JCR node to treat as an fcrepo object
*/
public FedoraResource(final Node node) {
super(false);
this();
this.node = node;
this.properties = DEFAULT_PROPERTY_FACTORY;
}

/**
Expand All @@ -90,11 +91,10 @@ public FedoraResource(final Node node) {
* @throws RepositoryException
*/
public FedoraResource(final Session session, final String path,
final String nodeType)
throws RepositoryException {
super(false);
final String nodeType) throws RepositoryException {
this();
this.node = findOrCreateNode(
session, path, JcrConstants.NT_FOLDER, nodeType);
session, path, NT_FOLDER, nodeType);

if (!hasMixin(node)) {
node.addMixin(FEDORA_RESOURCE);
Expand All @@ -103,7 +103,6 @@ public FedoraResource(final Session session, final String path,
if (node.isNew()) {
node.setProperty(JCR_LASTMODIFIED, Calendar.getInstance());
}
this.properties = DEFAULT_PROPERTY_FACTORY;
}

/**
Expand All @@ -124,7 +123,7 @@ public static boolean hasMixin(final Node node) throws RepositoryException {
* @throws RepositoryException
*/
public boolean hasContent() throws RepositoryException {
return node.hasNode(JcrConstants.JCR_CONTENT);
return node.hasNode(JCR_CONTENT);
}

/**
Expand Down Expand Up @@ -216,12 +215,13 @@ public Collection<String> getModels() throws RepositoryException {
* @throws RepositoryException
*/
public Dataset updatePropertiesDataset(final GraphSubjects subjects,
final String sparqlUpdateStatement)
throws RepositoryException {
final String sparqlUpdateStatement) throws RepositoryException {
final Dataset dataset = getPropertiesDataset(subjects, 0, 0);
final UpdateRequest request = UpdateFactory.create(sparqlUpdateStatement, dataset.getContext().getAsString(GraphProperties.URI_SYMBOL));
final UpdateRequest request =
create(sparqlUpdateStatement, dataset.getContext().getAsString(
URI_SYMBOL));
dataset.getDefaultModel().setNsPrefixes(request.getPrefixMapping());
UpdateAction.execute(request, dataset);
execute(request, dataset);
return dataset;
}

Expand Down Expand Up @@ -265,13 +265,16 @@ public Dataset getPropertiesDataset(final GraphSubjects subjects)
*/
public Dataset getVersionDataset(final GraphSubjects subjects)
throws RepositoryException {
final Model model = JcrRdfTools.withContext(subjects, node.getSession()).getJcrPropertiesModel(FedoraTypesUtils.getVersionHistory(node), subjects.getGraphSubject(node));
final Model model =
JcrRdfTools.withContext(subjects, node.getSession())
.getJcrPropertiesModel(getVersionHistory(node),
subjects.getGraphSubject(node));

final Dataset dataset = DatasetFactory.create(model);

String uri = subjects.getGraphSubject(node).getURI();
com.hp.hpl.jena.sparql.util.Context context = dataset.getContext();
context.set(GraphProperties.URI_SYMBOL,uri);
final String uri = subjects.getGraphSubject(node).getURI();
final com.hp.hpl.jena.sparql.util.Context context = dataset.getContext();
context.set(URI_SYMBOL,uri);

return dataset;
}
Expand Down Expand Up @@ -306,7 +309,8 @@ public boolean isNew() {
* @return
* @throws RepositoryException
*/
public Dataset replacePropertiesDataset(final GraphSubjects subjects, final Model inputModel) throws RepositoryException {
public Dataset replacePropertiesDataset(final GraphSubjects subjects,
final Model inputModel) throws RepositoryException {
final Dataset propertiesDataset = getPropertiesDataset(subjects, 0, -2);
final Model model = propertiesDataset.getDefaultModel();

Expand All @@ -320,12 +324,10 @@ public Dataset replacePropertiesDataset(final GraphSubjects subjects, final Mode
}

/**
* Construct an ETag value from the last modified date and path.
*
* JCR has a mix:etag type, but it only takes into account binary
* properties. We actually want whole-object etag data.
*
* TODO : construct and store an ETag value on object modify
* Construct an ETag value from the last modified date and path. JCR has a
* mix:etag type, but it only takes into account binary properties. We
* actually want whole-object etag data. TODO : construct and store an ETag
* value on object modify
*
* @return
* @throws RepositoryException
Expand All @@ -334,7 +336,7 @@ public String getEtagValue() throws RepositoryException {
final Date lastModifiedDate = getLastModifiedDate();

if (lastModifiedDate != null) {
return DigestUtils.shaHex(node.getPath() + lastModifiedDate.toString());
return shaHex(node.getPath() + lastModifiedDate.toString());
} else {
return "";
}
Expand Down
20 changes: 12 additions & 8 deletions fcrepo-kernel/src/main/java/org/fcrepo/kernel/Transaction.java
Expand Up @@ -16,10 +16,14 @@

package org.fcrepo.kernel;

import static java.lang.System.currentTimeMillis;
import static java.util.UUID.randomUUID;
import static org.fcrepo.kernel.Transaction.State.COMMITED;
import static org.fcrepo.kernel.Transaction.State.DIRTY;
import static org.fcrepo.kernel.Transaction.State.ROLLED_BACK;

import java.util.Calendar;
import java.util.Date;
import java.util.UUID;

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

Expand Down Expand Up @@ -59,7 +63,7 @@ public Transaction(final Session session) {
super();
this.session = session;
this.created = new Date();
this.id = UUID.randomUUID().toString();
this.id = randomUUID().toString();
this.expires = Calendar.getInstance();
this.updateExpiryDate();
}
Expand Down Expand Up @@ -96,7 +100,7 @@ public String getId() {
*/
public State getState() throws RepositoryException {
if (this.session != null && this.session.hasPendingChanges()) {
return State.DIRTY;
return DIRTY;
}
return state;
}
Expand All @@ -116,7 +120,7 @@ public Date getExpires() {
*/
public void commit() throws RepositoryException {
this.session.save();
this.state = State.COMMITED;
this.state = COMMITED;
this.expire();
}

Expand All @@ -126,15 +130,15 @@ public void commit() throws RepositoryException {
*/
public void expire() throws RepositoryException {
this.session.logout();
this.expires.setTimeInMillis(System.currentTimeMillis());
this.expires.setTimeInMillis(currentTimeMillis());
}

/**
* Discard all unpersisted changes and expire
* @throws RepositoryException
*/
public void rollback() throws RepositoryException {
this.state = State.ROLLED_BACK;
this.state = ROLLED_BACK;
this.session.refresh(false);
this.expire();
}
Expand All @@ -150,6 +154,6 @@ public void updateExpiryDate() {
} else {
duration = DEFAULT_TIMEOUT;
}
this.expires.setTimeInMillis(System.currentTimeMillis() + duration);
this.expires.setTimeInMillis(currentTimeMillis() + duration);
}
}
Expand Up @@ -25,6 +25,10 @@
import com.hp.hpl.jena.sparql.util.Symbol;


/**
* @author barmintor
* @date 2013
*/
public interface GraphProperties {

Symbol URI_SYMBOL = create("uri");
Expand Down
Expand Up @@ -17,6 +17,7 @@
package org.fcrepo.kernel.rdf;

import static com.hp.hpl.jena.graph.NodeFactory.createURI;
import static com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel;
import static org.slf4j.LoggerFactory.getLogger;

import java.util.Iterator;
Expand All @@ -26,7 +27,6 @@
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.sparql.util.Context;
import com.hp.hpl.jena.sparql.util.Symbol;

Expand Down Expand Up @@ -84,7 +84,7 @@ public static Node getDatasetSubject(final Dataset rdf) {
*/
public static Model unifyDatasetModel(final Dataset dataset) {
final Iterator<String> iterator = dataset.listNames();
Model model = ModelFactory.createDefaultModel();
Model model = createDefaultModel();

model = model.union(dataset.getDefaultModel());

Expand Down

0 comments on commit 5a8c48d

Please sign in to comment.