Package: ReferencedListPropertyStrategy
ReferencedListPropertyStrategy
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ReferencedListPropertyStrategy(EntityType, ListAttribute, Descriptor, EntityMappingHelper) |
|
|
|
|
|
||||||||||||||||||||
addValueFromAxiom(Axiom) |
|
|
|
|
|
||||||||||||||||||||
createListDescriptor(Axiom) |
|
|
|
|
|
||||||||||||||||||||
createListValueDescriptor(Object) |
|
|
|
|
|
||||||||||||||||||||
extractListValues(List, Object, AxiomValueGatherer) |
|
|
|
|
|
||||||||||||||||||||
lambda$addValueFromAxiom$0(Axiom) |
|
|
|
|
|
||||||||||||||||||||
lambda$addValueFromAxiom$1(Axiom) |
|
|
|
|
|
||||||||||||||||||||
lambda$extractListValues$2(ReferencedListValueDescriptor, List, Object) |
|
|
|
|
|
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 cz.cvut.kbss.jopa.model.descriptors.Descriptor;
18: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
19: import cz.cvut.kbss.jopa.model.metamodel.ListAttribute;
20: import cz.cvut.kbss.jopa.utils.EntityPropertiesUtils;
21: import cz.cvut.kbss.ontodriver.descriptor.ReferencedListDescriptor;
22: import cz.cvut.kbss.ontodriver.descriptor.ReferencedListDescriptorImpl;
23: import cz.cvut.kbss.ontodriver.descriptor.ReferencedListValueDescriptor;
24: import cz.cvut.kbss.ontodriver.model.Assertion;
25: import cz.cvut.kbss.ontodriver.model.Axiom;
26: import cz.cvut.kbss.ontodriver.model.NamedResource;
27:
28: import java.net.URI;
29: import java.util.Collection;
30: import java.util.List;
31:
32: class ReferencedListPropertyStrategy<X> extends
33: ListPropertyStrategy<ReferencedListDescriptor, ReferencedListValueDescriptor, X> {
34:
35: ReferencedListPropertyStrategy(EntityType<X> et, ListAttribute<? super X, ?> att, Descriptor descriptor,
36: 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 List<K> pendingItems = resolveUnpersistedItems(list, listDescriptor);
70:• if (!pendingItems.isEmpty()) {
71: pendingItems.forEach(item -> referenceSavingResolver.registerPendingReference(item, listDescriptor, list));
72: return;
73: }
74: addListElementsToListValueDescriptor(listDescriptor, list);
75: valueBuilder.addReferencedListValues(listDescriptor);
76: }
77:
78: @Override
79: ReferencedListValueDescriptor createListValueDescriptor(X instance) {
80: final URI owner = EntityPropertiesUtils.getIdentifier(instance, et);
81: final Assertion hasList = Assertion
82: .createObjectPropertyAssertion(listAttribute.getIRI().toURI(), listAttribute.isInferred());
83: final Assertion hasNext = Assertion.createObjectPropertyAssertion(listAttribute
84: .getOWLObjectPropertyHasNextIRI().toURI(), listAttribute.isInferred());
85: final Assertion hasContent = Assertion.createObjectPropertyAssertion(listAttribute
86: .getOWLPropertyHasContentsIRI().toURI(), listAttribute.isInferred());
87: final ReferencedListValueDescriptor descriptor = new ReferencedListValueDescriptor(
88: NamedResource.create(owner), hasList, hasNext, hasContent);
89: descriptor.setContext(getAttributeContext());
90: return descriptor;
91: }
92: }