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: 11
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: 33
77%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 2 C: 9
82%
M: 0 C: 1
100%
mapFieldToAxioms(URI, Object, FieldSpecification, EntityType, Descriptor)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
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: * JOPA
3: * Copyright (C) 2023 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.descriptors.Descriptor;
21: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
22: import cz.cvut.kbss.jopa.model.metamodel.FieldSpecification;
23: import cz.cvut.kbss.jopa.model.metamodel.QueryAttribute;
24: import cz.cvut.kbss.jopa.oom.exception.EntityDeconstructionException;
25: import cz.cvut.kbss.ontodriver.model.NamedResource;
26:
27: import java.net.URI;
28:
29: class EntityDeconstructor {
30:
31: private final EntityMappingHelper mapper;
32: private ReferenceSavingResolver referenceSavingResolver;
33:
34: EntityDeconstructor(ObjectOntologyMapperImpl mapper) {
35: this.mapper = mapper;
36: }
37:
38: void setReferenceSavingResolver(ReferenceSavingResolver referenceSavingResolver) {
39: this.referenceSavingResolver = referenceSavingResolver;
40: }
41:
42: <T> AxiomValueGatherer mapEntityToAxioms(URI identifier, T entity, EntityType<T> et, Descriptor descriptor) {
43:• assert identifier != null;
44:
45: final AxiomValueGatherer valueBuilder = createAxiomValueBuilder(identifier, descriptor);
46: try {
47:• for (FieldSpecification<? super T, ?> att : et.getFieldSpecifications()) {
48:• if (att instanceof QueryAttribute) {
49: // Skip query based attributes, they are not mapped to axioms
50: continue;
51: }
52: addAssertions(entity, et, att, descriptor, valueBuilder);
53: }
54:
55: } catch (IllegalArgumentException e) {
56: throw new EntityDeconstructionException(e);
57: }
58: return valueBuilder;
59: }
60:
61: private static AxiomValueGatherer createAxiomValueBuilder(URI identifier, Descriptor descriptor) {
62: return new AxiomValueGatherer(NamedResource.create(identifier), descriptor.getSingleContext().orElse(null));
63: }
64:
65: private <T> void addAssertions(T entity, EntityType<T> et,
66: FieldSpecification<? super T, ?> fieldSpec, Descriptor entityDescriptor,
67: final AxiomValueGatherer valueBuilder) {
68: final FieldStrategy<? extends FieldSpecification<? super T, ?>, T> fs = FieldStrategy
69: .createFieldStrategy(et, fieldSpec, entityDescriptor, mapper);
70: fs.setReferenceSavingResolver(referenceSavingResolver);
71: fs.buildAxiomValuesFromInstance(entity, valueBuilder);
72: }
73:
74: <T> AxiomValueGatherer mapFieldToAxioms(URI primaryKey, T entity, FieldSpecification<? super T, ?> fieldSpec,
75: EntityType<T> et, Descriptor descriptor) {
76: final AxiomValueGatherer valueBuilder = createAxiomValueBuilder(primaryKey, descriptor);
77: addAssertions(entity, et, fieldSpec, descriptor, valueBuilder);
78: return valueBuilder;
79: }
80: }