Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Interim commit for updating kernel contracts to suppport iterators
Partial resolution of: https://www.pivotaltracker.com/story/show/59243236

Distinguishing between managed and unmanaged RDF
Developing machinery to compare new and old material for updating
Building new iterator-driven persistence machinery
Continuing to build iterating persistance machinery
Completed positive persistence
Moved iterating RDF generation to the outer layer of JcrRdfTools
Moving iterated generation of versioning-related triples through to the domain models
  • Loading branch information
ajs6f authored and Andrew Woods committed Oct 26, 2013
1 parent d6c271c commit eb4baf3
Show file tree
Hide file tree
Showing 35 changed files with 1,916 additions and 184 deletions.
Expand Up @@ -85,7 +85,7 @@ public class FedoraRepositoryWorkspaces extends AbstractResource {
public Dataset getWorkspaces() throws RepositoryException {

final Model workspaceModel =
JcrRdfTools.withContext(null, session).getJcrPropertiesModel();
JcrRdfTools.withContext(null, session).getJcrPropertiesModel().asModel();

final String[] workspaces =
session.getWorkspace().getAccessibleWorkspaceNames();
Expand Down
Expand Up @@ -44,6 +44,7 @@
import org.fcrepo.http.commons.test.util.TestHelpers;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.services.NodeService;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
Expand Down Expand Up @@ -89,7 +90,7 @@ public void testGetVersionList() throws RepositoryException {
when(mockNodes.getObject(any(Session.class), anyString())).thenReturn(
mockResource);
when(mockResource.getVersionDataset(any(HttpGraphSubjects.class)))
.thenReturn(mockDataset);
.thenReturn(new RdfStream());
when(mockVariant.getMediaType()).thenReturn(
new MediaType("text", "turtle"));

Expand Down
Expand Up @@ -27,9 +27,11 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.StreamingOutput;

import org.fcrepo.kernel.utils.iterators.RdfStream;
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.GraphStore;

Expand Down Expand Up @@ -66,7 +68,20 @@ public GraphStoreStreamingOutput(final GraphStore graphStore,
public GraphStoreStreamingOutput(final Dataset dataset,
final MediaType mediaType) {
this.dataset = dataset;
format =
this.format =
contentTypeToLang(mediaType.toString()).getName().toUpperCase();
}

/**
* Construct the StreamingOutput machinery to serialize
* an RdfStream to the mime type given
* @param dataset
* @param mediaType
*/
public GraphStoreStreamingOutput(final RdfStream stream,
final MediaType mediaType) {
this.dataset = DatasetFactory.create(stream.asModel());
this.format =
contentTypeToLang(mediaType.toString()).getName().toUpperCase();
}

Expand Down
17 changes: 4 additions & 13 deletions fcrepo-kernel/src/main/java/org/fcrepo/kernel/FedoraResource.java
Expand Up @@ -43,11 +43,11 @@
import org.fcrepo.kernel.rdf.GraphSubjects;
import org.fcrepo.kernel.rdf.impl.JcrGraphProperties;
import org.fcrepo.kernel.utils.JcrRdfTools;
import org.fcrepo.kernel.utils.iterators.RdfStream;
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.UpdateRequest;

Expand Down Expand Up @@ -263,19 +263,10 @@ public Dataset getPropertiesDataset(final GraphSubjects subjects)
* @return
* @throws RepositoryException
*/
public Dataset getVersionDataset(final GraphSubjects subjects)
public RdfStream getVersionDataset(final GraphSubjects subjects)
throws RepositoryException {
final Model model =
JcrRdfTools.withContext(subjects, node.getSession())
.getJcrVersionPropertiesModel(node);

final Dataset dataset = DatasetFactory.create(model);

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;
return JcrRdfTools.withContext(subjects, node.getSession())
.getJcrVersionPropertiesModel(node);
}

/**
Expand Down
88 changes: 72 additions & 16 deletions fcrepo-kernel/src/main/java/org/fcrepo/kernel/RdfLexicon.java
Expand Up @@ -15,8 +15,14 @@
*/
package org.fcrepo.kernel;

import static com.google.common.base.Predicates.in;
import static com.google.common.collect.ImmutableSet.of;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createProperty;

import java.util.Set;

import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
import com.hp.hpl.jena.rdf.model.Property;

/**
Expand Down Expand Up @@ -58,6 +64,9 @@ public final class RdfLexicon {
public static final Property HAS_CHILD_COUNT =
createProperty(REPOSITORY_NAMESPACE + "numberOfChildren");

public static final Set<Property> membershipProperties = of(
HAS_MEMBER_OF_RESULT, HAS_PARENT, HAS_CHILD, HAS_CHILD_COUNT);

// FIXITY
public static final Property IS_FIXITY_RESULT_OF =
createProperty(REPOSITORY_NAMESPACE + "isFixityResultOf");
Expand All @@ -77,6 +86,10 @@ public final class RdfLexicon {
public static final Property HAS_FIXITY_REPAIRED_COUNT =
createProperty(REPOSITORY_NAMESPACE + "numFixityRepaired");

public static final Set<Property> fixityProperties = of(
IS_FIXITY_RESULT_OF, HAS_FIXITY_RESULT, HAS_FIXITY_STATE,
HAS_COMPUTED_CHECKSUM, HAS_COMPUTED_SIZE, HAS_FIXITY_CHECK_COUNT,
HAS_FIXITY_ERROR_COUNT, HAS_FIXITY_REPAIRED_COUNT);

// SEARCH
public static final Property SEARCH_PAGE = createProperty("http://sindice.com/vocab/search#Page");
Expand All @@ -91,31 +104,39 @@ public final class RdfLexicon {
public static final Property SEARCH_HAS_MORE =
createProperty(RESTAPI_NAMESPACE + "hasMoreResults");

public static final Set<Property> searchProperties = of(SEARCH_PAGE,
SEARCH_HAS_TOTAL_RESULTS, SEARCH_ITEMS_PER_PAGE, SEARCH_OFFSET,
SEARCH_OFFSET, SEARCH_TERMS, SEARCH_HAS_MORE);

// Linked Data Platform
public static final String LDP_NAMESPACE = "http://www.w3.org/ns/ldp#";
public static final Property PAGE =
createProperty("http://www.w3.org/ns/ldp#Page");
createProperty(LDP_NAMESPACE + "Page");
public static final Property PAGE_OF =
createProperty("http://www.w3.org/ns/ldp#pageOf");

createProperty(LDP_NAMESPACE + "pageOf");
public static final Property FIRST_PAGE =
createProperty("http://www.w3.org/ns/ldp#firstPage");
createProperty(LDP_NAMESPACE + "firstPage");
public static final Property NEXT_PAGE =
createProperty("http://www.w3.org/ns/ldp#nextPage");

createProperty(LDP_NAMESPACE + "nextPage");
public static final Property MEMBERS_INLINED =
createProperty("http://www.w3.org/ns/ldp#membersInlined");
createProperty(LDP_NAMESPACE + "membersInlined");
public static final Property CONTAINER =
createProperty("http://www.w3.org/ns/ldp#Container");
createProperty(LDP_NAMESPACE + "Container");
public static final Property MEMBERSHIP_SUBJECT =
createProperty("http://www.w3.org/ns/ldp#membershipSubject");
createProperty(LDP_NAMESPACE + "membershipSubject");
public static final Property MEMBERSHIP_PREDICATE =
createProperty("http://www.w3.org/ns/ldp#membershipPredicate");
createProperty(LDP_NAMESPACE + "membershipPredicate");
public static final Property MEMBERSHIP_OBJECT =
createProperty("http://www.w3.org/ns/ldp#membershipObject");
createProperty(LDP_NAMESPACE + "membershipObject");
public static final Property MEMBER_SUBJECT =
createProperty("http://www.w3.org/ns/ldp#MemberSubject");
createProperty(LDP_NAMESPACE + "MemberSubject");
public static final Property INLINED_RESOURCE =
createProperty("http://www.w3.org/ns/ldp#inlinedResource");
createProperty(LDP_NAMESPACE + "inlinedResource");

public static final Set<Property> ldpProperties = of(PAGE, PAGE_OF,
FIRST_PAGE, NEXT_PAGE, MEMBERS_INLINED, CONTAINER,
MEMBERSHIP_SUBJECT, MEMBERSHIP_PREDICATE, MEMBERSHIP_OBJECT,
MEMBER_SUBJECT, INLINED_RESOURCE);

// REPOSITORY INFORMATION
public static final Property HAS_OBJECT_COUNT =
Expand All @@ -134,13 +155,20 @@ public final class RdfLexicon {
public static final Property HAS_SITEMAP =
createProperty("http://microformats.org/wiki/rel-sitemap");

public static final Set<Property> repositoryProperties = of(
HAS_OBJECT_COUNT, HAS_OBJECT_SIZE, HAS_TRANSACTION_SERVICE,
HAS_NAMESPACE_SERVICE, HAS_WORKSPACE_SERVICE, HAS_SEARCH_SERVICE,
HAS_SITEMAP);

// NAMESPACES
public static final Property HAS_NAMESPACE_PREFIX =
createProperty("http://purl.org/vocab/vann/preferredNamespacePrefix");
public static final Property HAS_NAMESPACE_URI =
createProperty("http://purl.org/vocab/vann/preferredNamespaceUri");
public static final Property VOAF_VOCABULARY = createProperty("http://purl.org/vocommons/voaf#Vocabulary");

public static final Set<Property> namespaceProperties = of(
HAS_NAMESPACE_PREFIX, HAS_NAMESPACE_URI, VOAF_VOCABULARY);

// OTHER SERVICES
public static final Property HAS_SERIALIZATION =
Expand All @@ -158,6 +186,11 @@ public final class RdfLexicon {
public static final Property NOT_IMPLEMENTED =
createProperty(REPOSITORY_NAMESPACE + "notImplemented");

public static final Set<Property> otherServiceProperties = of(
HAS_SERIALIZATION, HAS_VERSION_HISTORY, HAS_FIXITY_SERVICE,
HAS_FEED, HAS_SUBSCRIPTION_SERVICE, NOT_IMPLEMENTED);


// CONTENT
public static final Property HAS_CONTENT =
createProperty(REPOSITORY_NAMESPACE + "hasContent");
Expand All @@ -170,12 +203,19 @@ public final class RdfLexicon {
public static final Property HAS_SIZE =
createProperty(REPOSITORY_NAMESPACE + "hasSize");

public static final Set<Property> contentProperties = of(HAS_CONTENT,
IS_CONTENT_OF, HAS_LOCATION, HAS_MIME_TYPE, HAS_SIZE);


// VERSIONING
public static final Property HAS_VERSION =
createProperty(REPOSITORY_NAMESPACE + "hasVersion");
public static final Property HAS_VERSION_LABEL =
createProperty(REPOSITORY_NAMESPACE + "hasVersionLabel");

public static final Set<Property> versioningProperties = of(HAS_VERSION,
HAS_VERSION_LABEL);

// RDF EXTRACTION
public static final Property COULD_NOT_STORE_PROPERTY =
createProperty(REPOSITORY_NAMESPACE + "couldNotStoreProperty");
Expand All @@ -189,24 +229,40 @@ public final class RdfLexicon {
createProperty(REPOSITORY_NAMESPACE + "hasNodeType");
public static final Property HAS_MIXIN_TYPE =
createProperty(REPOSITORY_NAMESPACE + "mixinTypes");

public static final Property CREATED_DATE =
createProperty(REPOSITORY_NAMESPACE + "created");
public static final Property CREATED_BY =
createProperty(REPOSITORY_NAMESPACE + "createdBy");


public static final Property LAST_MODIFIED_DATE =
createProperty(REPOSITORY_NAMESPACE + "lastModified");
public static final Property LAST_MODIFIED_BY =
createProperty(REPOSITORY_NAMESPACE + "lastModifiedBy");

public static final Set<Property> jcrProperties = of(
HAS_PRIMARY_IDENTIFIER, HAS_PRIMARY_TYPE, HAS_NODE_TYPE,
HAS_MIXIN_TYPE, CREATED_DATE, CREATED_BY, LAST_MODIFIED_DATE,
LAST_MODIFIED_BY);

public static final Property RDFS_LABEL =
createProperty("http://www.w3.org/2000/01/rdf-schema#label");
public static final Property DC_TITLE =
createProperty("http://purl.org/dc/terms/title");

public static final Set<Property> managedProperties;

static {
final ImmutableSet.Builder<Property> b = ImmutableSet.builder();
b.addAll(membershipProperties).addAll(fixityProperties).addAll(
searchProperties).addAll(ldpProperties).addAll(
repositoryProperties).addAll(namespaceProperties).addAll(
otherServiceProperties).addAll(contentProperties).addAll(
versioningProperties).addAll(jcrProperties);
managedProperties = b.build();
}

public static final Predicate<Property> isManagedPredicate =
in(managedProperties);

private RdfLexicon() {

}
Expand Down
@@ -0,0 +1,41 @@
/**
* Copyright 2013 DuraSpace, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.fcrepo.kernel.exception;

import javax.jcr.RepositoryException;


/**
* Indicates that RDF was presented for persistence to the repository,
* but could not be persisted for some reportable reason.
*
* @author ajs6f
* @date Oct 24, 2013
*/
public class MalformedRdfException extends RepositoryException {

private static final long serialVersionUID = 1L;

/**
* Ordinary constructor.
*
* @param msg
*/
public MalformedRdfException(final String msg) {
super(msg);
}

}
@@ -0,0 +1,33 @@
/**
* Copyright 2013 DuraSpace, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.fcrepo.kernel.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
* that does not restrict its property types.
*
* @author ajs6f
* @date Oct 25, 2013
*/
public class NoSuchPropertyDefinitionException extends RepositoryException {

private static final long serialVersionUID = 1L;

}
Expand Up @@ -49,8 +49,8 @@ public Dataset getProperties(final Node node, final GraphSubjects subjects,
final long offset, final int limit)
throws RepositoryException {
final JcrRdfTools jcrRdfTools = JcrRdfTools.withContext(subjects, node.getSession());
final Model model = jcrRdfTools.getJcrPropertiesModel(node);
final Model treeModel = jcrRdfTools.getJcrTreeModel(node, offset, limit);
final Model model = jcrRdfTools.getJcrPropertiesModel(node).asModel();
final Model treeModel = jcrRdfTools.getJcrTreeModel(node, offset, limit).asModel();
final Model problemModel = JcrRdfTools.getProblemsModel();

final JcrPropertyStatementListener listener =
Expand Down
Expand Up @@ -193,8 +193,9 @@ public Dataset getFixityResultsModel(final GraphSubjects subjects,
runFixityAndFixProblems(datastream);

final Model model =
JcrRdfTools.withContext(subjects, datastream.getNode().getSession()).getJcrPropertiesModel(datastream
.getNode(), blobs);
JcrRdfTools
.withContext(subjects, datastream.getNode().getSession())
.getJcrPropertiesModel(datastream.getNode(), blobs).asModel();

final Dataset dataset = GraphStoreFactory.create(model).toDataset();

Expand Down

0 comments on commit eb4baf3

Please sign in to comment.