Skip to content

Commit

Permalink
Building new iterator-driven persistence machinery
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Oct 24, 2013
1 parent aaca4e0 commit 75410ce
Show file tree
Hide file tree
Showing 10 changed files with 429 additions and 32 deletions.
23 changes: 12 additions & 11 deletions fcrepo-kernel/src/main/java/org/fcrepo/kernel/RdfLexicon.java
Expand Up @@ -109,28 +109,29 @@ public final class RdfLexicon {
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,
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);
}

}
Expand Up @@ -379,7 +379,7 @@ public boolean isInternalProperty(final Node subjectNode,
* @return a JCR Value
* @throws javax.jcr.RepositoryException
*/
Value createValue(final Node node, final RDFNode data, final int type)
public Value createValue(final Node node, final RDFNode data, final int type)
throws RepositoryException {
final ValueFactory valueFactory = getValueFactory.apply(node);
assert (valueFactory != null);
Expand Down Expand Up @@ -442,7 +442,7 @@ Value createValue(final Node node, final RDFNode data, final int type)
* @return
* @throws RepositoryException
*/
String getPropertyNameFromPredicate(final Node node,
public String getPropertyNameFromPredicate(final Node node,
final com.hp.hpl.jena.rdf.model.Property predicate)
throws RepositoryException {
final Map<String, String> s = emptyMap();
Expand All @@ -460,7 +460,7 @@ String getPropertyNameFromPredicate(final Node node,
* @return the JCR property name
* @throws RepositoryException
*/
String getPropertyNameFromPredicate(final Node node, final com.hp.hpl.jena.rdf.model.Property predicate,
public String getPropertyNameFromPredicate(final Node node, final com.hp.hpl.jena.rdf.model.Property predicate,
final Map<String, String> namespaceMapping) throws RepositoryException {

final String prefix;
Expand Down
@@ -1,3 +1,18 @@
/**
* 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.utils.iterators;

Expand Down
@@ -1,12 +1,28 @@
/**
* 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.utils.iterators;

import java.util.Iterator;

import com.google.common.util.concurrent.ListenableFuture;

/**
* Implemented by anything that can consume an {@link Iterator}.
* Implemented by something that can consume an {@link Iterator}.
*
* The assumption is that a reference to the appropriate iterator
* is managed as part of the state of any implementation.
*
* @author ajs6f
* @date Oct 24, 2013
Expand All @@ -20,14 +36,14 @@ public interface IteratorConsumer<E, T> {
*
* @param i
*/
void consume(final Iterator<E> i);
void consume() throws Exception;

/**
* Asynchronous consumption.
*
* @param i
* @return
*/
ListenableFuture<T> consumeAsync(final Iterator<E> i);
ListenableFuture<T> consumeAsync();

}
@@ -0,0 +1,94 @@
/**
* 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.utils.iterators;

import static org.fcrepo.kernel.utils.NodePropertiesTools.appendOrReplaceNodeProperty;
import static org.slf4j.LoggerFactory.getLogger;

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

import org.fcrepo.kernel.exception.MalformedRdfException;
import org.fcrepo.kernel.rdf.GraphSubjects;
import org.slf4j.Logger;

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

/**
* Consumes an {@link RdfStream} by adding its contents to the
* JCR.
*
* @see {@link RdfRemover} for contrast
* @author ajs6f
* @date Oct 24, 2013
*/
public class RdfAdder extends RdfPersister {

private static final Logger LOGGER = getLogger(RdfAdder.class);

/**
* Ordinary constructor.
*
* @param graphSubjects
* @param session
* @param stream
*/
public RdfAdder(final GraphSubjects graphSubjects, final Session session,
final RdfStream stream) {
super(graphSubjects, session, stream);
}

@Override
protected void operateOnMixin(final Resource mixinResource,
final Node subjectNode) throws RepositoryException {
final String namespacePrefix;
try {
namespacePrefix =
session.getNamespacePrefix(mixinResource.getNameSpace());
} catch (final NamespaceException e) {
throw new MalformedRdfException(
"Unable to resolve registered namespace for resource "
+ mixinResource.toString());
}
final String mixinName =
namespacePrefix + ":" + mixinResource.getLocalName();
if (session.getWorkspace().getNodeTypeManager().hasNodeType(mixinName)) {
if (subjectNode.canAddMixin(mixinName)) {
LOGGER.debug("Adding mixin: {} to node: {}.", mixinName,
subjectNode.getPath());
subjectNode.addMixin(mixinName);
} else {
throw new MalformedRdfException(
"Could not persist triple containing type assertion:"
+ mixinResource.toString()
+ " because no such mixin/type exists in repository!");
}
}
}


@Override
protected void operateOnOneValueOfProperty(final Node n, final String p,
final Value v) throws RepositoryException {
LOGGER.debug("Adding property: {} with value: {} to node: {}.", p, v, n
.getPath());
appendOrReplaceNodeProperty(n, p, v);
}
}

0 comments on commit 75410ce

Please sign in to comment.