PluralMultilingualStringFieldStrategy extends DataPropertyFieldStrategy<AbstractPluralAttribute<? super X, ?, MultilingualString>, X> { @Override void buildAxiomValuesFromInstance(X instance, AxiomValueGatherer valueBuilder) { final Object value = extractFieldValueFromInstance(instance); assert value instanceof Collection || value == null; final Collection<MultilingualString> valueCollection = (Collection<MultilingualString>) value; if (valueCollection == null || valueCollection.isEmpty()) { valueBuilder.addValue(createAssertion(), Value.nullValue(), getAttributeContext()); } else { final Set<Value<?>> assertionValues = valueCollection.stream() .filter(Objects::nonNull) .flatMap(v -> v.getValue().entrySet().stream() .map(e -> new Value<>( new LangString(e.getValue(), e.getKey())))) .collect(Collectors.toSet()); valueBuilder.addValues(createAssertion(), assertionValues, getAttributeContext()); } } PluralMultilingualStringFieldStrategy(EntityType<X> et,
                                          AbstractPluralAttribute<? super X, ?, MultilingualString> att,
                                          Descriptor entityDescriptor,
                                          EntityMappingHelper mapper);   }
@Test void buildAxiomValuesTransformsAllTranslationsFromOneElementToAxiomValues() throws Exception { final PluralMultilingualStringFieldStrategy<OWLClassU> sut = createStrategy(); final OWLClassU u = new OWLClassU(ID); final MultilingualString ms = new MultilingualString(); ms.set("en", "building"); ms.set("cs", "budova"); u.setPluralStringAtt(Collections.singleton(ms)); final AxiomValueGatherer builder = new AxiomValueGatherer(INDIVIDUAL, null); sut.buildAxiomValuesFromInstance(u, builder); final AxiomValueDescriptor valueDescriptor = OOMTestUtils.getAxiomValueDescriptor(builder); assertEquals(1, valueDescriptor.getAssertions().size()); final Assertion assertion = valueDescriptor.getAssertions().iterator().next(); assertEquals(Vocabulary.P_U_PLURAL_MULTILINGUAL_ATTRIBUTE, assertion.getIdentifier().toString()); final List<Value<?>> values = valueDescriptor.getAssertionValues(assertion); verifyAssertionValues(values, ms); }
@Test void buildAxiomValuesTransformsAllTranslationsFromAllElementsToAxiomValues() throws Exception { final PluralMultilingualStringFieldStrategy<OWLClassU> sut = createStrategy(); final OWLClassU u = new OWLClassU(ID); final MultilingualString msOne = new MultilingualString(); msOne.set("en", "building"); msOne.set("cs", "budova"); final MultilingualString msTwo = new MultilingualString(); msTwo.set("en", "construction"); msTwo.set("cs", "stavba"); msTwo.set("construction"); u.setPluralStringAtt(new HashSet<>(Arrays.asList(msOne, msTwo))); final AxiomValueGatherer builder = new AxiomValueGatherer(INDIVIDUAL, null); sut.buildAxiomValuesFromInstance(u, builder); final AxiomValueDescriptor valueDescriptor = OOMTestUtils.getAxiomValueDescriptor(builder); assertEquals(1, valueDescriptor.getAssertions().size()); final Assertion assertion = valueDescriptor.getAssertions().iterator().next(); assertEquals(Vocabulary.P_U_PLURAL_MULTILINGUAL_ATTRIBUTE, assertion.getIdentifier().toString()); final List<Value<?>> values = valueDescriptor.getAssertionValues(assertion); verifyAssertionValues(values, msOne, msTwo); }
@Test void buildAxiomValuesAddsNullValueToDescriptorWhenAttributeValueIsEmpty() throws Exception { final PluralMultilingualStringFieldStrategy<OWLClassU> sut = createStrategy(); final OWLClassU u = new OWLClassU(ID); final AxiomValueGatherer builder = new AxiomValueGatherer(INDIVIDUAL, null); sut.buildAxiomValuesFromInstance(u, builder); final AxiomValueDescriptor valueDescriptor = OOMTestUtils.getAxiomValueDescriptor(builder); assertEquals(1, valueDescriptor.getAssertions().size()); final Assertion assertion = valueDescriptor.getAssertions().iterator().next(); assertEquals(Collections.singletonList(Value.nullValue()), valueDescriptor.getAssertionValues(assertion)); }