Skip to content

Package: PluralObjectPropertyStrategy

PluralObjectPropertyStrategy

nameinstructionbranchcomplexitylinemethod
PluralObjectPropertyStrategy(EntityType, AbstractPluralAttribute, Descriptor, EntityMappingHelper)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
addValueFromAxiom(Axiom)
M: 0 C: 53
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
buildInstanceFieldValue(Object)
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%
createAssertion()
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getAttributeValueContext()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
static {...}
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) 2020 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.AbstractPluralAttribute;
19: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
20: import cz.cvut.kbss.jopa.utils.CollectionFactory;
21: import cz.cvut.kbss.jopa.utils.IdentifierTransformer;
22: import cz.cvut.kbss.ontodriver.model.Assertion;
23: import cz.cvut.kbss.ontodriver.model.Axiom;
24: import cz.cvut.kbss.ontodriver.model.NamedResource;
25: import org.slf4j.Logger;
26: import org.slf4j.LoggerFactory;
27:
28: import java.net.URI;
29: import java.util.Collection;
30:
31: abstract class PluralObjectPropertyStrategy<Y extends AbstractPluralAttribute<? super X, ?, ?>, X>
32: extends FieldStrategy<Y, X> {
33:
34: private static final Logger LOG = LoggerFactory.getLogger(PluralObjectPropertyStrategy.class);
35:
36: private final Collection<Object> values;
37:
38: PluralObjectPropertyStrategy(EntityType<X> et, Y att, Descriptor descriptor, EntityMappingHelper mapper) {
39: super(et, att, descriptor, mapper);
40: this.values = CollectionFactory.createDefaultCollection(att.getCollectionType());
41: }
42:
43: @Override
44: void addValueFromAxiom(Axiom<?> ax) {
45: final NamedResource valueIdentifier = (NamedResource) ax.getValue().getValue();
46:• if (IdentifierTransformer.isValidIdentifierType(attribute.getBindableJavaType())) {
47: values.add(IdentifierTransformer
48: .transformToIdentifier(valueIdentifier.getIdentifier(), attribute.getBindableJavaType()));
49: } else {
50: final Object value = mapper.getEntityFromCacheOrOntology(attribute.getBindableJavaType(),
51: valueIdentifier.getIdentifier(), entityDescriptor.getAttributeDescriptor(attribute));
52:• if (value != null) {
53: values.add(value);
54: } else {
55: LOG.trace("Value of axiom {} could not be loaded as entity filling attribute {}.", ax, attribute);
56: }
57: }
58: }
59:
60: @Override
61: void buildInstanceFieldValue(Object instance) {
62:• if (!values.isEmpty()) {
63: setValueOnInstance(instance, values);
64: }
65: }
66:
67: /**
68: * Gets the context in which this attribute values are stored.
69: * <p>
70: * I.e., this context may (and usually will be) different from the context in which this attribute's property assertion is stored, since that
71: * is usually stored in the subject's context.
72: *
73: * @return Attribute value (referenced entity) context
74: * @see Descriptor#areAssertionsInSubjectContext()
75: */
76: URI getAttributeValueContext() {
77: return entityDescriptor.getAttributeDescriptor(attribute).getContext();
78: }
79:
80: @Override
81: Assertion createAssertion() {
82: return Assertion.createObjectPropertyAssertion(attribute.getIRI().toURI(), attribute.isInferred());
83: }
84: }