Skip to content

Package: PluralAnnotationPropertyStrategy

PluralAnnotationPropertyStrategy

nameinstructionbranchcomplexitylinemethod
PluralAnnotationPropertyStrategy(EntityType, AbstractPluralAttribute, 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%
addAxiomValue(Axiom)
M: 0 C: 34
100%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 0 C: 7
100%
M: 0 C: 1
100%
buildAxiomValuesFromInstance(Object, AxiomValueGatherer)
M: 4 C: 53
93%
M: 1 C: 7
88%
M: 1 C: 4
80%
M: 0 C: 13
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%
lambda$resolveValueMapper$0(Object)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$resolveValueMapper$1(Object)
M: 0 C: 15
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
resolveValueMapper()
M: 0 C: 9
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
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%
toAxiomValue(Object)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jopa.oom;
19:
20: import cz.cvut.kbss.jopa.model.MultilingualString;
21: import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
22: import cz.cvut.kbss.jopa.model.metamodel.AbstractPluralAttribute;
23: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
24: import cz.cvut.kbss.jopa.oom.converter.ToLexicalFormConverter;
25: import cz.cvut.kbss.jopa.utils.IdentifierTransformer;
26: import cz.cvut.kbss.ontodriver.model.Assertion;
27: import cz.cvut.kbss.ontodriver.model.Axiom;
28: import cz.cvut.kbss.ontodriver.model.NamedResource;
29: import cz.cvut.kbss.ontodriver.model.Value;
30:
31: import java.util.Collection;
32: import java.util.Collections;
33: import java.util.Objects;
34: import java.util.Set;
35: import java.util.function.Function;
36: import java.util.stream.Collectors;
37:
38: class PluralAnnotationPropertyStrategy<X> extends PluralDataPropertyStrategy<X> {
39:
40: PluralAnnotationPropertyStrategy(EntityType<X> et, AbstractPluralAttribute<? super X, ?, ?> att,
41: Descriptor attributeDescriptor, EntityMappingHelper mapper) {
42: super(et, att, attributeDescriptor, mapper);
43: }
44:
45: @Override
46: void addAxiomValue(Axiom<?> ax) {
47: final Object value = ax.getValue().getValue();
48:• if (isValidRange(value)) {
49: values.add(toAttributeValue(value));
50:• } else if (value instanceof NamedResource && IdentifierTransformer.isValidIdentifierType(elementType)) {
51: values.add(IdentifierTransformer
52: .transformToIdentifier(ToLexicalFormConverter.INSTANCE.convertToAttribute(value),
53: elementType));
54: }
55: }
56:
57: @Override
58: void buildAxiomValuesFromInstance(X instance, AxiomValueGatherer valueBuilder) {
59: final Object value = extractFieldValueFromInstance(instance);
60:• assert value instanceof Collection || value == null;
61: final Collection<?> valueCollection = (Collection<?>) value;
62:• if (valueCollection == null || valueCollection.isEmpty()) {
63: valueBuilder.addValue(createAssertion(), Value.nullValue(), getAttributeWriteContext());
64: } else {
65: final Function<Object, Collection<Value<?>>> mapper = resolveValueMapper();
66: final Set<Value<?>> assertionValues =
67: valueCollection.stream().filter(Objects::nonNull).map(mapper).flatMap(Collection::stream)
68: .collect(Collectors.toSet());
69: valueBuilder.addValues(createAssertion(),
70: filterOutInferredValues(valueBuilder.getSubjectIdentifier(), assertionValues),
71: getAttributeWriteContext());
72: }
73: }
74:
75: private Function<Object, Collection<Value<?>>> resolveValueMapper() {
76:• if (SingularAnnotationPropertyStrategy.isResourceIdentifierType(elementType)) {
77: return v -> Collections.singleton(new Value<>(NamedResource.create(IdentifierTransformer.valueAsUri(v))));
78: } else {
79:• return v -> v instanceof MultilingualString ?
80: SingularMultilingualStringFieldStrategy.translationsToLangStrings(
81: (MultilingualString) v).collect(Collectors.toList()) : Collections.singleton(convertToAxiomValue(v));
82: }
83: }
84:
85: @Override
86: Collection<Value<?>> toAxiomValue(Object value) {
87: return resolveValueMapper().apply(value);
88: }
89:
90: @Override
91: Assertion createAssertion() {
92: return Assertion
93: .createAnnotationPropertyAssertion(attribute.getIRI().toURI(), getLanguage(), attribute.isInferred());
94: }
95: }