Skip to content

Commit

Permalink
Static imports where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Oct 21, 2013
1 parent f80dfc1 commit 1f7e8ce
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 65 deletions.
52 changes: 27 additions & 25 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 Down Expand Up @@ -80,7 +81,6 @@ public FedoraResource() {
public FedoraResource(final Node node) {
super(false);
this.node = node;
this.properties = DEFAULT_PROPERTY_FACTORY;
}

/**
Expand All @@ -94,7 +94,7 @@ public FedoraResource(final Session session, final String path,
throws RepositoryException {
super(false);
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
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 @@ -16,19 +16,17 @@
package org.fcrepo.kernel.rdf.impl;

import static com.google.common.base.Preconditions.checkArgument;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
import static org.fcrepo.jcr.FedoraJcrTypes.FCR_CONTENT;
import static org.fcrepo.kernel.RdfLexicon.RESTAPI_NAMESPACE;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;

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

import org.fcrepo.jcr.FedoraJcrTypes;
import org.fcrepo.kernel.RdfLexicon;
import org.fcrepo.kernel.rdf.GraphSubjects;
import org.modeshape.jcr.api.JcrConstants;

import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;

/**
* Translates JCR names into "fedora" subjects (by replacing jcr-specific names
Expand All @@ -46,19 +44,16 @@ public class DefaultGraphSubjects implements GraphSubjects {
*/
public DefaultGraphSubjects(final Session session) {
this.session = session;
this.context = ResourceFactory.createResource();
this.context = createResource();
}

@Override
public Resource getGraphSubject(final String absPath) throws RepositoryException {
if (absPath.endsWith(JcrConstants.JCR_CONTENT)) {
return ResourceFactory
.createResource(RdfLexicon.RESTAPI_NAMESPACE +
absPath.replace(JcrConstants.JCR_CONTENT,
FedoraJcrTypes.FCR_CONTENT));
if (absPath.endsWith(JCR_CONTENT)) {
return createResource(RESTAPI_NAMESPACE
+ absPath.replace(JCR_CONTENT, FCR_CONTENT));
} else {
return ResourceFactory
.createResource(RdfLexicon.RESTAPI_NAMESPACE + absPath);
return createResource(RESTAPI_NAMESPACE + absPath);
}
}

Expand All @@ -80,11 +75,10 @@ public Node getNodeFromGraphSubject(final Resource subject)
}

final String absPath = subject.getURI()
.substring(RdfLexicon.RESTAPI_NAMESPACE.length());
.substring(RESTAPI_NAMESPACE.length());

if (absPath.endsWith(FCR_CONTENT)) {
return session.getNode(absPath.replace(FedoraJcrTypes.FCR_CONTENT,
JcrConstants.JCR_CONTENT));
return session.getNode(absPath.replace(FCR_CONTENT, JCR_CONTENT));
} else if (session.nodeExists(absPath)) {
return session.getNode(absPath);
} else {
Expand All @@ -98,7 +92,7 @@ public boolean isFedoraGraphSubject(final Resource subject) {
assert(subject != null);

return subject.isURIResource() &&
subject.getURI().startsWith(RdfLexicon.RESTAPI_NAMESPACE);
subject.getURI().startsWith(RESTAPI_NAMESPACE);
}

}
Expand Up @@ -30,6 +30,10 @@
import com.hp.hpl.jena.rdf.model.Resource;


/**
* @author cbeer
* @date 2013
*/
public class JcrGraphProperties implements GraphProperties {

private static final String MODEL_NAME = "tree";
Expand All @@ -48,7 +52,7 @@ public Dataset getProperties(final Node node, final GraphSubjects subjects,
final Model treeModel = jcrRdfTools.getJcrTreeModel(node, offset, limit);
final Model problemModel = JcrRdfTools.getProblemsModel();

JcrPropertyStatementListener listener =
final JcrPropertyStatementListener listener =
JcrPropertyStatementListener.getListener(
subjects, node.getSession(), problemModel);

Expand All @@ -58,9 +62,9 @@ public Dataset getProperties(final Node node, final GraphSubjects subjects,
final Dataset dataset = DatasetFactory.create(model);
dataset.addNamedModel(MODEL_NAME, treeModel);

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

Expand Down

0 comments on commit 1f7e8ce

Please sign in to comment.