Package: ReferencedListDataPropertyStrategy
ReferencedListDataPropertyStrategy
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ReferencedListDataPropertyStrategy(EntityType, ListAttributeImpl, Descriptor, EntityMappingHelper) |
|
|
|
|
|
||||||||||||||||||||
addAxiomValue(Axiom) |
|
|
|
|
|
||||||||||||||||||||
buildAxiomValuesFromInstance(Object, AxiomValueGatherer) |
|
|
|
|
|
||||||||||||||||||||
buildAxiomsFromInstance(Object) |
|
|
|
|
|
||||||||||||||||||||
buildInstanceFieldValue(Object) |
|
|
|
|
|
||||||||||||||||||||
createListDescriptor(Axiom) |
|
|
|
|
|
||||||||||||||||||||
createListValueDescriptor(Object) |
|
|
|
|
|
||||||||||||||||||||
hasValue() |
|
|
|
|
|
||||||||||||||||||||
isValidRange(Object) |
|
|
|
|
|
||||||||||||||||||||
lambda$addAxiomValue$0(Axiom) |
|
|
|
|
|
||||||||||||||||||||
lambda$addAxiomValue$1(Axiom) |
|
|
|
|
|
||||||||||||||||||||
lambda$buildAxiomValuesFromInstance$2(ReferencedListValueDescriptor, Object) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
Coverage
1: package cz.cvut.kbss.jopa.oom;
2:
3: import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
4: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
5: import cz.cvut.kbss.jopa.model.metamodel.ListAttributeImpl;
6: import cz.cvut.kbss.jopa.utils.EntityPropertiesUtils;
7: import cz.cvut.kbss.ontodriver.descriptor.ReferencedListDescriptor;
8: import cz.cvut.kbss.ontodriver.descriptor.ReferencedListValueDescriptor;
9: import cz.cvut.kbss.ontodriver.model.Axiom;
10: import cz.cvut.kbss.ontodriver.model.NamedResource;
11:
12: import java.util.ArrayList;
13: import java.util.Collection;
14: import java.util.List;
15: import java.util.Objects;
16: import java.util.Set;
17:
18: class ReferencedListDataPropertyStrategy<X> extends DataPropertyFieldStrategy<ListAttributeImpl<? super X, ?>, X> {
19:
20: private final Class<?> elementType;
21:
22: private final List<Object> values = new ArrayList<>();
23:
24: ReferencedListDataPropertyStrategy(EntityType<X> et, ListAttributeImpl<? super X, ?> att,
25: Descriptor attributeDescriptor, EntityMappingHelper mapper) {
26: super(et, att, attributeDescriptor, mapper);
27: this.elementType = att.getElementType().getJavaType();
28: }
29:
30: @Override
31: void addAxiomValue(Axiom<?> head) {
32: final ReferencedListDescriptor listDescriptor = createListDescriptor(head);
33: final Collection<Axiom<?>> sequence = mapper.loadReferencedList(listDescriptor);
34: sequence.stream()
35: .filter(item -> item.getAssertion().getIdentifier()
36: .equals(attribute.getHasContentsPropertyIRI().toURI()))
37: .forEach(item -> {
38: final Object value = item.getValue().getValue();
39:• if (isValidRange(value)) {
40: values.add(toAttributeValue(value));
41: }
42: });
43: }
44:
45: ReferencedListDescriptor createListDescriptor(Axiom<?> ax) {
46: final NamedResource owner = ax.getSubject();
47: final ReferencedListDescriptor listDescriptor = ListDescriptorFactory.createReferencedListDescriptor(owner, attribute);
48: listDescriptor.setContext(getAttributeWriteContext());
49: return listDescriptor;
50: }
51:
52: @Override
53: boolean hasValue() {
54:• return !values.isEmpty();
55: }
56:
57: @Override
58: boolean isValidRange(Object value) {
59:• return elementType.isAssignableFrom(value.getClass()) || canBeConverted(value);
60: }
61:
62: @Override
63: void buildInstanceFieldValue(Object instance) {
64: setValueOnInstance(instance, values);
65: }
66:
67: @Override
68: void buildAxiomValuesFromInstance(X instance, AxiomValueGatherer valueBuilder) {
69: final Object value = extractFieldValueFromInstance(instance);
70:• assert value instanceof List || value == null;
71:
72: final ReferencedListValueDescriptor<Object> listDescriptor = createListValueDescriptor(instance);
73: final List<?> list = (List<?>) value;
74:• if (list != null) {
75: list.stream().filter(Objects::nonNull)
76: .forEach(v -> listDescriptor.addValue(converter.convertToAxiomValue(v)));
77: }
78: valueBuilder.addReferencedListValues(listDescriptor);
79: }
80:
81: private <V> ReferencedListValueDescriptor<V> createListValueDescriptor(X instance) {
82: final NamedResource owner = NamedResource.create(EntityPropertiesUtils.getIdentifier(instance, et));
83: final ReferencedListValueDescriptor<V> descriptor = ListDescriptorFactory.createReferencedListValueDescriptor(owner, attribute);
84: descriptor.setContext(getAttributeWriteContext());
85: return descriptor;
86: }
87:
88: @Override
89: Set<Axiom<?>> buildAxiomsFromInstance(X instance) {
90: throw new UnsupportedOperationException("Method not supported for referenced lists.");
91: }
92: }