Skip to content

Package: SingularAnnotationPropertyStrategy

SingularAnnotationPropertyStrategy

nameinstructionbranchcomplexitylinemethod
SingularAnnotationPropertyStrategy(EntityType, AbstractAttribute, 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: 36
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
buildAxiomValuesFromInstance(Object, AxiomValueGatherer)
M: 0 C: 66
100%
M: 0 C: 8
100%
M: 0 C: 5
100%
M: 0 C: 14
100%
M: 0 C: 1
100%
createAssertion()
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
isValidRange(Object)
M: 4 C: 20
83%
M: 1 C: 7
88%
M: 1 C: 4
80%
M: 0 C: 3
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 1
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: * <p>
4: * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
5: * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
6: * version.
7: * <p>
8: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10: * details. You should have received a copy of the GNU General Public License along with this program. If not, see
11: * <http://www.gnu.org/licenses/>.
12: */
13: package cz.cvut.kbss.jopa.oom;
14:
15: import cz.cvut.kbss.jopa.model.MultilingualString;
16: import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
17: import cz.cvut.kbss.jopa.model.metamodel.AbstractAttribute;
18: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
19: import cz.cvut.kbss.jopa.oom.converter.ToLexicalFormConverter;
20: import cz.cvut.kbss.jopa.utils.IdentifierTransformer;
21: import cz.cvut.kbss.ontodriver.model.Assertion;
22: import cz.cvut.kbss.ontodriver.model.Axiom;
23: import cz.cvut.kbss.ontodriver.model.NamedResource;
24: import cz.cvut.kbss.ontodriver.model.Value;
25:
26: class SingularAnnotationPropertyStrategy<X> extends SingularDataPropertyStrategy<X> {
27:
28: SingularAnnotationPropertyStrategy(EntityType<X> et, AbstractAttribute<? super X, ?> att, Descriptor descriptor,
29: EntityMappingHelper mapper) {
30: super(et, att, descriptor, mapper);
31: }
32:
33: @Override
34: void addValueFromAxiom(Axiom<?> ax) {
35: final Object val = ax.getValue().getValue();
36:• if (!isValidRange(val)) {
37: return;
38: }
39: verifyCardinalityConstraint(ax.getSubject());
40:• if (IdentifierTransformer.isValidIdentifierType(attribute.getJavaType())) {
41: this.value = IdentifierTransformer
42: .transformToIdentifier(ToLexicalFormConverter.INSTANCE.convertToAttribute(val),
43: attribute.getJavaType());
44: } else {
45: this.value = toAttributeValue(val);
46: }
47: }
48:
49: @Override
50: boolean isValidRange(Object value) {
51:• assert value != null;
52:
53:• return value instanceof NamedResource && IdentifierTransformer.isValidIdentifierType(attribute.getJavaType()) ||
54:• super.isValidRange(value);
55: }
56:
57: @Override
58: void buildAxiomValuesFromInstance(X instance, AxiomValueGatherer valueBuilder) {
59: final Object value = extractFieldValueFromInstance(instance);
60:• if (value == null) {
61: valueBuilder.addValue(createAssertion(), Value.nullValue(), getAttributeContext());
62: return;
63: }
64:
65:• if (IdentifierTransformer.isValidIdentifierType(attribute.getJavaType()) &&
66:• !attribute.getJavaType().isAssignableFrom(String.class)) {
67: valueBuilder.addValue(createAssertion(),
68: new Value<>(NamedResource.create(IdentifierTransformer.valueAsUri(value))), getAttributeContext());
69:• } else if (value instanceof MultilingualString) {
70: valueBuilder.addValues(createAssertion(),
71: SingularMultilingualStringFieldStrategy.translationsToLangStrings((MultilingualString) value),
72: getAttributeContext());
73: } else {
74: valueBuilder.addValue(createAssertion(), new Value<>(toAxiomValue(value)), getAttributeContext());
75: }
76: }
77:
78: @Override
79: Assertion createAssertion() {
80: return Assertion
81: .createAnnotationPropertyAssertion(attribute.getIRI().toURI(), getLanguage(), attribute.isInferred());
82: }
83: }