Skip to content

Package: AbstractSesameIterator

AbstractSesameIterator

nameinstructionbranchcomplexitylinemethod
AbstractSesameIterator(ListDescriptor, Connector, ValueFactory)
M: 0 C: 41
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
checkNodeIsResource(Statement)
M: 0 C: 10
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
checkSuccessorMax(Collection, URI)
M: 0 C: 25
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
createAxiom(Resource, Assertion, Resource)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.ontodriver.sesame;
16:
17: import java.util.Collection;
18: import java.util.HashSet;
19:
20: import org.openrdf.model.Resource;
21: import org.openrdf.model.Statement;
22: import org.openrdf.model.URI;
23: import org.openrdf.model.ValueFactory;
24:
25: import cz.cvut.kbss.ontodriver.exception.IntegrityConstraintViolatedException;
26: import cz.cvut.kbss.ontodriver.sesame.connector.Connector;
27: import cz.cvut.kbss.ontodriver.descriptor.ListDescriptor;
28: import cz.cvut.kbss.ontodriver.model.Assertion;
29: import cz.cvut.kbss.ontodriver.model.Axiom;
30: import cz.cvut.kbss.ontodriver.model.AxiomImpl;
31: import cz.cvut.kbss.ontodriver.model.NamedResource;
32: import cz.cvut.kbss.ontodriver.model.Value;
33:
34: abstract class AbstractSesameIterator implements SesameIterator {
35:
36: protected final Resource listOwner;
37: protected final URI hasListProperty;
38: protected final URI hasNextProperty;
39: protected final URI context;
40: protected final boolean includeInferred;
41:
42: protected final Connector connector;
43: protected final ValueFactory vf;
44:
45: public AbstractSesameIterator(ListDescriptor listDescriptor, Connector connector,
46: ValueFactory vf) {
47: this.listOwner = SesameUtils.toSesameUri(listDescriptor.getListOwner().getIdentifier(), vf);
48: this.hasListProperty = SesameUtils.toSesameUri(listDescriptor.getListProperty()
49: .getIdentifier(), vf);
50: this.hasNextProperty = SesameUtils.toSesameUri(
51: listDescriptor.getNextNode().getIdentifier(), vf);
52: this.context = SesameUtils.toSesameUri(listDescriptor.getContext(), vf);
53: this.includeInferred = listDescriptor.getListProperty().isInferred();
54: this.connector = connector;
55: this.vf = vf;
56: }
57:
58: protected void checkSuccessorMax(Collection<Statement> stmts, URI property) {
59: // We don't mind the same statement multiple times, it could have been added during transaction
60:• if (new HashSet<>(stmts).size() > 1) {
61: throw new IntegrityConstraintViolatedException(
62: "Invalid number of values found for assertion " + property
63: + ". Expected 1, got " + stmts.size());
64: }
65: }
66:
67: protected void checkNodeIsResource(Statement stmt) {
68:• if (!(stmt.getObject() instanceof Resource)) {
69: throw new IntegrityConstraintViolatedException(
70: "Invalid property value. Expected object property value, got literal.");
71: }
72: }
73:
74: protected Axiom<NamedResource> createAxiom(Resource subject, Assertion assertion, Resource value) {
75: final NamedResource subjectRes = NamedResource.create(subject.stringValue());
76: return new AxiomImpl<>(subjectRes, assertion, new Value<>(NamedResource.create(value.stringValue())));
77: }
78: }