Skip to content

Commit

Permalink
[Enhancement #209] Test data property referenced list updates, fix is…
Browse files Browse the repository at this point in the history
…sues.
  • Loading branch information
ledsoft committed Dec 6, 2023
1 parent 3a588c2 commit ef8c390
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public static List<OWLClassA> createReferencedList(int size) {
return lst;
}

public static List<LocalDate> createDataPropertyList() {
final List<LocalDate> list = new ArrayList<>(DEFAULT_SIZE);
for (int i = DEFAULT_SIZE; i >= 0; i--) {
list.add(LocalDate.now().minusDays(i));
}
return list;
}

public static List<URI> createListOfIdentifiers() {
return createSimpleList().stream().map(OWLClassA::getUri).collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,10 +795,7 @@ void persistSupportsAnnotationPropertyValueMappedToSimpleLiteral() throws Except
@Test
void persistSupportsReferencedListsContainingDataPropertyLiteralValues() {
this.em = getEntityManager("persistSupportsReferencedListsContainingDataPropertyLiteralValues", false);
entityM.setLiteralReferencedList(new ArrayList<>());
for (int i = 5; i >= 0; i--) {
entityM.getLiteralReferencedList().add(LocalDate.now().minusDays(i));
}
entityM.setLiteralReferencedList(Generators.createDataPropertyList());
persist(entityM);

for (int i = 0; i < entityM.getLiteralReferencedList().size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.net.URI;
import java.net.URL;
import java.time.Instant;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;
Expand Down Expand Up @@ -1405,4 +1406,20 @@ void concurrentTransactionsLeaveDataInConsistentState() {
final OWLClassA result = em.find(OWLClassA.class, entityA.getUri());
assertEquals(a2String, result.getStringAttribute());
}

@Test
void updateSupportsChangesInDataPropertyReferencedLists() {
this.em = getEntityManager("updateSupportsChangesInDataPropertyReferencedLists", false);
entityM.setLiteralReferencedList(Generators.createDataPropertyList());
persist(entityM);

final List<LocalDate> updatedList = new ArrayList<>(entityM.getLiteralReferencedList());
updatedList.set(Generators.randomPositiveInt(0, updatedList.size()), LocalDate.now().minusDays(365));
updatedList.add(LocalDate.now().plusDays(365));
entityM.setLiteralReferencedList(updatedList);
transactional(() -> em.merge(entityM));

final OWLClassM result = findRequired(OWLClassM.class, entityM.getKey());
assertEquals(updatedList, result.getLiteralReferencedList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import cz.cvut.kbss.ontodriver.descriptor.ReferencedListValueDescriptor;
import cz.cvut.kbss.ontodriver.model.Assertion;
import cz.cvut.kbss.ontodriver.model.Axiom;
import cz.cvut.kbss.ontodriver.model.NamedResource;
import cz.cvut.kbss.ontodriver.rdf4j.connector.Connector;
import cz.cvut.kbss.ontodriver.rdf4j.exception.Rdf4jDriverException;
import cz.cvut.kbss.ontodriver.rdf4j.util.ValueConverter;
Expand Down Expand Up @@ -185,7 +184,7 @@ <V> void appendNewNodes(ReferencedListValueDescriptor<V> listDescriptor, MergeRe
assert i > 0;
final Collection<Statement> toAdd = new ArrayList<>((listDescriptor.getValues().size() - i) * 2);
while (i < listDescriptor.getValues().size()) {
final Value content = toRdf4jValue(listDescriptor.getListProperty(), listDescriptor.getValues().get(i));
final Value content = toRdf4jValue(listDescriptor.getNodeContent(), listDescriptor.getValues().get(i));
previous = createListNode(owner, hasNext, hasContent, content, context, previous, toAdd);
i++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import cz.cvut.kbss.ontodriver.descriptor.ReferencedListDescriptor;
import cz.cvut.kbss.ontodriver.exception.IntegrityConstraintViolatedException;
import cz.cvut.kbss.ontodriver.model.Assertion;
import cz.cvut.kbss.ontodriver.model.Axiom;
import cz.cvut.kbss.ontodriver.model.AxiomImpl;
import cz.cvut.kbss.ontodriver.model.NamedResource;
Expand Down Expand Up @@ -99,7 +98,7 @@ private Statement getNodeContent(Resource node) throws Rdf4jDriverException {

@Override
public T currentContent() {
return (T) ValueConverter.fromRdf4jValue(listDescriptor.getListProperty(), currentContent.getObject())
return (T) ValueConverter.fromRdf4jValue(listDescriptor.getNodeContent(), currentContent.getObject())
.orElse(null);
}

Expand Down Expand Up @@ -145,13 +144,8 @@ public void replaceCurrentWith(T newContent) throws Rdf4jDriverException {
connector.removeStatements(Collections.singleton(currentContent));
final Resource node = (Resource) currentNode.getObject();
final Statement stmt = vf
.createStatement(node, hasContentProperty, valueConverter.toRdf4jValue(listDescriptor.getListProperty(), newContent),
.createStatement(node, hasContentProperty, valueConverter.toRdf4jValue(listDescriptor.getNodeContent(), newContent),
context);
connector.addStatements(Collections.singleton(stmt));
}

protected Axiom<NamedResource> createAxiom(Resource subject, Assertion assertion, Resource value) {
final NamedResource subjectRes = NamedResource.create(subject.stringValue());
return new AxiomImpl<>(subjectRes, assertion, new Value<>(NamedResource.create(value.stringValue())));
}
}

0 comments on commit ef8c390

Please sign in to comment.