Skip to content

Package: EntityDeconstructor

EntityDeconstructor

nameinstructionbranchcomplexitylinemethod
EntityDeconstructor(ObjectOntologyMapperImpl)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
addAssertions(Object, EntityType, FieldSpecification, Descriptor, AxiomValueGatherer)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
createAxiomValueBuilder(URI, Descriptor)
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%
mapEntityToAxioms(URI, Object, EntityType, Descriptor)
M: 10 C: 29
74%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 2 C: 7
78%
M: 0 C: 1
100%
mapFieldToAxioms(URI, Object, Field, EntityType, Descriptor)
M: 6 C: 19
76%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 6
75%
M: 0 C: 1
100%
setReferenceSavingResolver(ReferenceSavingResolver)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
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: *
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.FieldSpecification;
20: import cz.cvut.kbss.jopa.oom.exceptions.EntityDeconstructionException;
21: import cz.cvut.kbss.ontodriver.model.NamedResource;
22:
23: import java.lang.reflect.Field;
24: import java.net.URI;
25:
26: class EntityDeconstructor {
27:
28: private final EntityMappingHelper mapper;
29: private ReferenceSavingResolver referenceSavingResolver;
30:
31: EntityDeconstructor(ObjectOntologyMapperImpl mapper) {
32: this.mapper = mapper;
33: }
34:
35: void setReferenceSavingResolver(ReferenceSavingResolver referenceSavingResolver) {
36: this.referenceSavingResolver = referenceSavingResolver;
37: }
38:
39: <T> AxiomValueGatherer mapEntityToAxioms(URI identifier, T entity, EntityType<T> et, Descriptor descriptor) {
40:• assert identifier != null;
41:
42: final AxiomValueGatherer valueBuilder = createAxiomValueBuilder(identifier, descriptor);
43: try {
44:• for (FieldSpecification<? super T, ?> att : et.getFieldSpecifications()) {
45: addAssertions(entity, et, att, descriptor, valueBuilder);
46: }
47:
48: } catch (IllegalArgumentException | IllegalAccessException e) {
49: throw new EntityDeconstructionException(e);
50: }
51: return valueBuilder;
52: }
53:
54: private static AxiomValueGatherer createAxiomValueBuilder(URI primaryKey, Descriptor descriptor) {
55: return new AxiomValueGatherer(NamedResource.create(primaryKey), descriptor.getContext());
56: }
57:
58: private <T> void addAssertions(T entity, EntityType<T> et,
59: FieldSpecification<? super T, ?> fieldSpec, Descriptor entityDescriptor,
60: final AxiomValueGatherer valueBuilder) throws IllegalAccessException {
61: final FieldStrategy<? extends FieldSpecification<? super T, ?>, T> fs = FieldStrategy
62: .createFieldStrategy(et, fieldSpec, entityDescriptor, mapper);
63: fs.setReferenceSavingResolver(referenceSavingResolver);
64: fs.buildAxiomValuesFromInstance(entity, valueBuilder);
65: }
66:
67: <T> AxiomValueGatherer mapFieldToAxioms(URI primaryKey, T entity, Field field, EntityType<T> et,
68: Descriptor descriptor) {
69: final FieldSpecification<? super T, ?> fieldSpec = et
70: .getFieldSpecification(field.getName());
71: final AxiomValueGatherer valueBuilder = createAxiomValueBuilder(primaryKey, descriptor);
72: try {
73: addAssertions(entity, et, fieldSpec, descriptor, valueBuilder);
74: } catch (IllegalAccessException e) {
75: throw new EntityDeconstructionException(e);
76: }
77: return valueBuilder;
78: }
79: }