Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for VIVO-3871 #393

Merged
merged 5 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public void addWithoutNotify(Triple t) {
performAdd(t);
}

public final void deleteWithoutNotify(Triple t) {
public void deleteWithoutNotify(Triple t) {
checkOpen();
performDelete(t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,33 @@

public class BulkOntModelImpl extends OntModelImpl {

public BulkOntModelImpl(OntModelSpec spec) {
super(spec);
}

public BulkOntModelImpl(OntModelSpec owlMem, Model bareModel) {
super(owlMem, bareModel);
}
public BulkOntModelImpl(OntModelSpec spec) {
super(spec);
}

@Override
public Model remove(Model m) {
Graph unwrappedGraph = GraphUtils.unwrapUnionGraphs(graph);
if (unwrappedGraph instanceof BulkGraphMem) {
GraphUtils.deleteFrom((BulkGraphMem) unwrappedGraph, m.getGraph());
} else {
super.remove(m);
}
return this;
}
public BulkOntModelImpl(OntModelSpec owlMem, Model bareModel) {
super(owlMem, bareModel);
}

@Override
public Model add(Model m) {
Graph unwrappedGraph = GraphUtils.unwrapUnionGraphs(graph);
if (unwrappedGraph instanceof BulkGraphMem) {
GraphUtils.addInto((BulkGraphMem) unwrappedGraph, m.getGraph());
} else {
super.add(m);
}
return this;
}
@Override
public Model remove(Model m) {
Graph unwrappedGraph = GraphUtils.unwrapUnionGraphs(graph);
if (unwrappedGraph instanceof BulkGraphMem) {
GraphUtils.deleteFrom((BulkGraphMem) unwrappedGraph, m.getGraph());
} else {
super.remove(m);
}
return this;
}

@Override
public Model add(Model m) {
Graph unwrappedGraph = GraphUtils.unwrapUnionGraphs(graph);
if (unwrappedGraph instanceof BulkGraphMem) {
GraphUtils.addInto((BulkGraphMem) unwrappedGraph, m.getGraph());
} else {
super.add(m);
}
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ final public class GraphUtils {

public static Graph unwrapUnionGraphs(Graph graph) {
if (graph != null && graph instanceof MultiUnion) {
List<Graph> subGraphs = ((MultiUnion) graph).getSubGraphs();
if (subGraphs == null || subGraphs.isEmpty()) {
return ((MultiUnion) graph).getBaseGraph();
}
return unwrapUnionGraphs(((MultiUnion)graph).getBaseGraph());
}
return graph;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
import java.util.List;

import org.junit.Test;

import org.apache.jena.graph.Triple;
import org.apache.jena.graph.impl.GraphWithPerform;
import org.apache.jena.mem.GraphMem;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.ontology.impl.OntModelImpl;
import org.apache.jena.rdf.listeners.StatementListener;
import org.apache.jena.rdf.model.Literal;
import org.apache.jena.rdf.model.Model;
Expand All @@ -27,6 +28,8 @@
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.ResourceFactory;
import org.apache.jena.rdf.model.Statement;
import org.apache.jena.rdf.model.impl.ModelCom;
import org.apache.jena.shared.Lock;

import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
import edu.cornell.mannlib.vitro.testing.RecordingProxy;
Expand Down Expand Up @@ -65,6 +68,9 @@
* presumably the bulk updaters will be removed completely.
*/
public class VitroModelFactoryTest extends AbstractTestClass {

private String testData = "src/test/resources/edu/cornell/mannlib/vitro/webapp/rdfservice/adapters/vitro_model_factory_test_data.n3";

private static final Statement SINGLE_STATEMENT = stmt(
resource("http://subject"), property("http://add"),
literal("object"));
Expand Down Expand Up @@ -463,7 +469,53 @@ public void addMultipleToVitroOntUnion() {
.test();
}

// ----------------------------------------------------------------------
@Test
public void testCreateNewBulkOntModel() {
TestBulkGraphMem spyGraph = new TestBulkGraphMem();
Model baseModel = new ModelCom(spyGraph);
baseModel = wrap(wrap(wrap(baseModel)));
OntModel ontModel = VitroModelFactory.createOntologyModel(baseModel);
Model inputModel = ModelFactory.createDefaultModel();
try {
inputModel.enterCriticalSection(Lock.WRITE);
inputModel.read(testData);
} finally {
inputModel.leaveCriticalSection();
}
assertEquals(0, spyGraph.countAddWithoutNotify);
assertEquals(0, spyGraph.countDeleteWithoutNotify);
ontModel.add(inputModel);
assertEquals(5, spyGraph.countAddWithoutNotify);
assertEquals(0, spyGraph.countDeleteWithoutNotify);

ontModel.remove(inputModel);
assertEquals(5, spyGraph.countAddWithoutNotify);
assertEquals(5, spyGraph.countDeleteWithoutNotify);
}

private OntModelImpl wrap(Model baseModel) {
return new OntModelImpl(OWL_MEM, baseModel);
}

private static class TestBulkGraphMem extends BulkGraphMem {
int countDeleteWithoutNotify = 0;
int countAddWithoutNotify = 0;

@Override
public void addWithoutNotify(Triple t) {
checkOpen();
performAdd(t);
countAddWithoutNotify++;
}
@Override
public final void deleteWithoutNotify(Triple t) {
checkOpen();
performDelete(t);
countDeleteWithoutNotify++;
}
}

// ----------------------------------------------------------------------
// OntModel of Union of Models
//
// This shouldn't hold any surprises, should it?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<test:bob> <test:has_publication> <test:bob_publication1> .
<test:bob> <test:has_publication> <test:bob_publication2> .
<test:bob> <test:has_publication> <test:bob_publication3> .
<test:alice> <test:has_publication> <test:alice_publication1> .
<test:alice> <test:has_publication> <test:alice_publication2> .