Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
package org.fcrepo.kernel.impl; | ||
|
||
import static com.google.common.base.Throwables.propagate; | ||
import static com.google.common.collect.ImmutableSet.copyOf; | ||
import static com.google.common.collect.Iterators.singletonIterator; | ||
import static com.google.common.collect.Lists.newArrayList; | ||
import static com.hp.hpl.jena.update.UpdateAction.execute; | ||
|
@@ -35,7 +34,6 @@ | |
import java.util.Date; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
|
||
import javax.jcr.ItemNotFoundException; | ||
|
@@ -58,7 +56,7 @@ | |
import org.fcrepo.kernel.exception.RepositoryRuntimeException; | ||
import org.fcrepo.kernel.identifiers.IdentifierConverter; | ||
import org.fcrepo.kernel.impl.utils.JcrPropertyStatementListener; | ||
import org.fcrepo.kernel.utils.iterators.DifferencingIterator; | ||
import org.fcrepo.kernel.utils.iterators.GraphDifferencingIterator; | ||
import org.fcrepo.kernel.impl.utils.iterators.RdfAdder; | ||
import org.fcrepo.kernel.impl.utils.iterators.RdfRemover; | ||
import org.fcrepo.kernel.utils.iterators.NodeIterator; | ||
|
@@ -67,9 +65,7 @@ | |
import org.modeshape.jcr.api.JcrTools; | ||
import org.slf4j.Logger; | ||
|
||
import com.google.common.collect.Iterables; | ||
import com.google.common.collect.Iterators; | ||
import com.hp.hpl.jena.graph.Triple; | ||
import com.hp.hpl.jena.rdf.model.Model; | ||
import com.hp.hpl.jena.update.UpdateRequest; | ||
|
||
|
@@ -417,28 +413,23 @@ public Boolean isNew() { | |
* (org.fcrepo.kernel.identifiers.IdentifierConverter, com.hp.hpl.jena.rdf.model.Model) | ||
*/ | ||
@Override | ||
public RdfStream replaceProperties(final IdentifierConverter<Resource, FedoraResource> graphSubjects, | ||
public void replaceProperties(final IdentifierConverter<Resource, FedoraResource> graphSubjects, | ||
This comment has been minimized.
Sorry, something went wrong. |
||
final Model inputModel, final RdfStream originalTriples) { | ||
|
||
final RdfStream replacementStream = RdfStream.fromModel(inputModel); | ||
final RdfStream replacementStream = new RdfStream().namespaces(inputModel.getNsPrefixMap()); | ||
|
||
final Set<Triple> replacementTriples = copyOf(replacementStream); | ||
|
||
final DifferencingIterator<Triple> differencer = | ||
new DifferencingIterator<>(replacementTriples, originalTriples); | ||
final GraphDifferencingIterator differencer = | ||
new GraphDifferencingIterator(inputModel, originalTriples); | ||
|
||
try { | ||
new RdfRemover(graphSubjects, getSession(), replacementStream | ||
.withThisContext(differencer)).consume(); | ||
|
||
new RdfAdder(graphSubjects, getSession(), replacementStream | ||
.withThisContext(differencer.notCommon())).consume(); | ||
.withThisContext(differencer.notCommon().find(null, null, null))).consume(); | ||
This comment has been minimized.
Sorry, something went wrong.
ajs6f
Contributor
|
||
} catch (final RepositoryException e) { | ||
throw new RepositoryRuntimeException(e); | ||
} | ||
|
||
return replacementStream.withThisContext(Iterables.concat(differencer | ||
.common(), differencer.notCommon())); | ||
} | ||
|
||
/* (non-Javadoc) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -565,6 +565,25 @@ public boolean apply(final javax.jcr.Property property) { | |
|
||
} | ||
|
||
@Test | ||
public void testReplacePropertyWithSemanticEquivalent() throws RepositoryException { | ||
This comment has been minimized.
Sorry, something went wrong.
ajs6f
Contributor
|
||
final String pid = UUID.randomUUID().toString(); | ||
final FedoraObject object = objectService.findOrCreateObject(session, pid); | ||
object.getNode().setProperty("dc:title", "xyz"); | ||
session.save(); | ||
|
||
final RdfStream triples = object.getTriples(subjects, PropertiesRdfContext.class); | ||
final Model model = triples.asModel(); | ||
|
||
final Resource subject = subjects.reverse().convert(object); | ||
final Property predicate = model.createProperty("http://purl.org/dc/elements/1.1/title"); | ||
This comment has been minimized.
Sorry, something went wrong.
ajs6f
Contributor
|
||
|
||
model.removeAll(subject, predicate, null); | ||
|
||
model.add(subject, predicate, createPlainLiteral("xyz")); | ||
|
||
object.replaceProperties(subjects, model, object.getTriples(subjects, PropertiesRdfContext.class)); | ||
This comment has been minimized.
Sorry, something went wrong.
ajs6f
Contributor
|
||
} | ||
|
||
@Test | ||
public void testDeleteObject() throws RepositoryException { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,12 +15,14 @@ | |
*/ | ||
package org.fcrepo.kernel.utils.iterators; | ||
|
||
import static com.google.common.collect.Sets.newHashSet; | ||
|
||
import java.util.Iterator; | ||
import java.util.Set; | ||
|
||
import com.google.common.collect.AbstractIterator; | ||
import com.hp.hpl.jena.graph.Graph; | ||
import com.hp.hpl.jena.graph.Triple; | ||
import com.hp.hpl.jena.rdf.model.Model; | ||
import com.hp.hpl.jena.rdf.model.ModelFactory; | ||
|
||
/** | ||
* A wrapping {@link Iterator} that calculates two differences between a | ||
|
@@ -30,39 +32,39 @@ | |
* | ||
* @author ajs6f | ||
* @since Oct 24, 2013 | ||
* @param <E> The type of element common to both source and set. | ||
*/ | ||
public class DifferencingIterator<E> extends AbstractIterator<E> { | ||
public class GraphDifferencingIterator extends AbstractIterator<Triple> { | ||
This comment has been minimized.
Sorry, something went wrong.
ajs6f
Contributor
|
||
|
||
Set<? extends E> notCommon; | ||
Graph notCommon; | ||
|
||
private Set<E> common; | ||
private Graph common; | ||
|
||
private Iterator<E> source; | ||
private Iterator<Triple> source; | ||
|
||
/** | ||
* Ordinary constructor. | ||
* | ||
* @param original | ||
* @param source | ||
*/ | ||
public DifferencingIterator(final Set<? extends E> original, | ||
final Iterator<E> source) { | ||
public GraphDifferencingIterator(final Model original, | ||
final Iterator<Triple> source) { | ||
super(); | ||
this.notCommon = newHashSet(original); | ||
this.common = newHashSet(); | ||
this.notCommon = original.getGraph(); | ||
this.common = ModelFactory.createDefaultModel().getGraph(); | ||
this.source = source; | ||
} | ||
|
||
@Override | ||
protected E computeNext() { | ||
protected Triple computeNext() { | ||
if (source.hasNext()) { | ||
E next = source.next(); | ||
Triple next = source.next(); | ||
// we only want to return this element if it is not common | ||
// to the two inputs | ||
while (common.contains(next) || notCommon.contains(next)) { | ||
// it was common, so shift it to common | ||
if (notCommon.remove(next)) { | ||
if (notCommon.contains(next)) { | ||
notCommon.delete(next); | ||
common.add(next); | ||
} | ||
// move onto the next candidate | ||
|
@@ -82,7 +84,7 @@ protected E computeNext() { | |
* | ||
* @return The elements that turned out to be common to the two inputs. | ||
*/ | ||
public Set<E> common() { | ||
public Graph common() { | ||
return source.hasNext() ? null : common; | ||
} | ||
|
||
|
@@ -91,7 +93,7 @@ public Set<E> common() { | |
* | ||
* @return The elements that turned out not to be common to the two inputs. | ||
*/ | ||
public Set<? extends E> notCommon() { | ||
public Graph notCommon() { | ||
return source.hasNext() ? null : notCommon; | ||
} | ||
|
||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Copyright 2014 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 org.junit.Test; | ||
|
||
/** | ||
* <p>DifferencingIteratorTest class.</p> | ||
* | ||
* @author ksclarke | ||
*/ | ||
public class GraphDifferencingIteratorTest { | ||
|
||
@Test | ||
public void yepWeShouldHaveSome() { | ||
This comment has been minimized.
Sorry, something went wrong.
ajs6f
Contributor
|
||
|
||
} | ||
} |
I prefer to return the result for chaining, but it's not a big thing.