Skip to content

Package: ReferencedListPropertyStrategy

ReferencedListPropertyStrategy

nameinstructionbranchcomplexitylinemethod
ReferencedListPropertyStrategy(EntityType, ListAttribute, Descriptor, EntityMappingHelper)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
addValueFromAxiom(Axiom)
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
createListDescriptor(Axiom)
M: 0 C: 42
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
createListValueDescriptor(Object)
M: 0 C: 47
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
extractListValues(List, Object, AxiomValueGatherer)
M: 0 C: 46
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
lambda$addValueFromAxiom$0(Axiom)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
lambda$addValueFromAxiom$1(Axiom)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
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.jopa.oom;
16:
17: import java.net.URI;
18: import java.util.Collection;
19: import java.util.List;
20:
21: import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
22: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
23: import cz.cvut.kbss.jopa.model.metamodel.ListAttribute;
24: import cz.cvut.kbss.jopa.utils.EntityPropertiesUtils;
25: import cz.cvut.kbss.ontodriver.descriptor.ReferencedListDescriptor;
26: import cz.cvut.kbss.ontodriver.descriptor.ReferencedListDescriptorImpl;
27: import cz.cvut.kbss.ontodriver.descriptor.ReferencedListValueDescriptor;
28: import cz.cvut.kbss.ontodriver.model.Assertion;
29: import cz.cvut.kbss.ontodriver.model.Axiom;
30: import cz.cvut.kbss.ontodriver.model.NamedResource;
31:
32: class ReferencedListPropertyStrategy<X> extends
33: ListPropertyStrategy<ReferencedListDescriptor, ReferencedListValueDescriptor, X> {
34:
35: public ReferencedListPropertyStrategy(EntityType<X> et, ListAttribute<? super X, ?> att,
36: Descriptor descriptor, EntityMappingHelper mapper) {
37: super(et, att, descriptor, mapper);
38: }
39:
40: @Override
41: void addValueFromAxiom(Axiom<?> ax) {
42: final ReferencedListDescriptor listDescriptor = createListDescriptor(ax);
43: final Collection<Axiom<NamedResource>> sequence = mapper.loadReferencedList(listDescriptor);
44: sequence.stream().filter(a -> a.getAssertion().getIdentifier()
45: .equals(listAttribute.getOWLPropertyHasContentsIRI().toURI()))
46: .forEach(super::addValueFromAxiom);
47: }
48:
49: @Override
50: ReferencedListDescriptor createListDescriptor(Axiom<?> ax) {
51: final NamedResource owner = ax.getSubject();
52:
53: final boolean inferred = listAttribute.isInferred();
54: final Assertion listProperty = Assertion.createObjectPropertyAssertion(listAttribute
55: .getIRI().toURI(), inferred);
56: final Assertion nextNodeProperty = Assertion.createObjectPropertyAssertion(listAttribute
57: .getOWLObjectPropertyHasNextIRI().toURI(), inferred);
58: final Assertion nodeContentProperty = Assertion.createObjectPropertyAssertion(listAttribute
59: .getOWLPropertyHasContentsIRI().toURI(), inferred);
60: final ReferencedListDescriptor listDescriptor = new ReferencedListDescriptorImpl(owner,
61: listProperty, nextNodeProperty, nodeContentProperty);
62: listDescriptor.setContext(getAttributeContext());
63: return listDescriptor;
64: }
65:
66: @Override
67: <K> void extractListValues(List<K> list, X instance, AxiomValueGatherer valueBuilder) {
68: final ReferencedListValueDescriptor listDescriptor = createListValueDescriptor(instance);
69: final Class<K> elemType = (Class<K>) listAttribute.getBindableJavaType();
70: final EntityType<K> valueType = mapper.getEntityType(elemType);
71:• if (list != null) {
72:• for (K item : list) {
73: final URI itemUri = resolveValueIdentifier(item, valueType);
74: cascadeResolver.resolveFieldCascading(pluralAtt, item, getAttributeContext());
75: listDescriptor.addValue(NamedResource.create(itemUri));
76: }
77: }
78: valueBuilder.addReferencedListValues(listDescriptor);
79: }
80:
81: @Override
82: ReferencedListValueDescriptor createListValueDescriptor(X instance) {
83: final URI owner = EntityPropertiesUtils.getPrimaryKey(instance, et);
84: final Assertion hasList = Assertion
85: .createObjectPropertyAssertion(listAttribute.getIRI().toURI(), listAttribute.isInferred());
86: final Assertion hasNext = Assertion.createObjectPropertyAssertion(listAttribute
87: .getOWLObjectPropertyHasNextIRI().toURI(), listAttribute.isInferred());
88: final Assertion hasContent = Assertion.createObjectPropertyAssertion(listAttribute
89: .getOWLPropertyHasContentsIRI().toURI(), listAttribute.isInferred());
90: final ReferencedListValueDescriptor descriptor = new ReferencedListValueDescriptor(
91: NamedResource.create(owner), hasList, hasNext, hasContent);
92: descriptor.setContext(getAttributeContext());
93: return descriptor;
94: }
95: }