Skip to content

Commit

Permalink
Bump org.apache.jena:apache-jena-libs from 4.10.0 to 5.2.0 (#547)
Browse files Browse the repository at this point in the history
* Bump org.apache.jena:apache-jena-libs from 4.10.0 to 5.2.0

Bumps org.apache.jena:apache-jena-libs from 4.10.0 to 5.2.0.

---
updated-dependencies:
- dependency-name: org.apache.jena:apache-jena-libs
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* Bump org.apache.jena:apache-jena-libs from 4.10.0 to 5.2.0

Bumps org.apache.jena:apache-jena-libs from 4.10.0 to 5.2.0.

---
updated-dependencies:
- dependency-name: org.apache.jena:apache-jena-libs
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* Replace usages of removed methods

* Revert Node_Literal changes

* Add isConcrete() check for statements that used Node_Concrete but now use Node

* Added a AdminUI unit test and a few isConcrete() checks.

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: lathouwerssam <[email protected]>
Co-authored-by: Barry Nouwt <[email protected]>
  • Loading branch information
3 people authored Nov 8, 2024
1 parent 954ca4b commit 37ad896
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 66 deletions.
13 changes: 6 additions & 7 deletions admin-ui/src/main/java/eu/knowledge/engine/admin/AdminUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.SimpleSelector;
import org.apache.jena.shared.PrefixMapping;
import org.apache.jena.sparql.graph.PrefixMappingMem;
import org.apache.jena.sparql.lang.arq.ParseException;
Expand Down Expand Up @@ -184,9 +183,9 @@ public BindingSet handleChangedKnowledgeBaseKnowledge(ReactExchangeInfo ei) {
// - delete all old data about that knowledge base
// - insert the *new* data about that knowledge base

Resource kb = model.query(new SimpleSelector(null, RDF.type, Vocab.KNOWLEDGE_BASE)).listSubjects().next();
String query = String.format("DELETE { %s } WHERE { %s FILTER (?kb = <%s>) } ",
this.metaGraphPattern.getPattern(), this.metaGraphPattern.getPattern(), kb.toString());
Resource kb = model.listSubjectsWithProperty(RDF.type, Vocab.KNOWLEDGE_BASE).next();
String query = String.format("DELETE { %s } WHERE { %s FILTER (?kb = <%s>) } ", this.metaGraphPattern.getPattern(), this.metaGraphPattern.getPattern(), kb.toString());

UpdateRequest updateRequest = UpdateFactory.create(query);
UpdateAction.execute(updateRequest, this.model);

Expand Down Expand Up @@ -215,9 +214,9 @@ public BindingSet handleRemovedKnowledgeBaseKnowledge(ReactExchangeInfo ei) {
// - extract the knowledge base that this message is about
// - delete all old data about that knowledge base

Resource kb = model.query(new SimpleSelector(null, RDF.type, Vocab.KNOWLEDGE_BASE)).listSubjects().next();
String query = String.format("DELETE { %s } WHERE { %s FILTER (?kb = <%s>) } ",
this.metaGraphPattern.getPattern(), this.metaGraphPattern.getPattern(), kb.toString());
Resource kb = model.listSubjectsWithProperty(RDF.type, Vocab.KNOWLEDGE_BASE).next();
String query = String.format("DELETE { %s } WHERE { %s FILTER (?kb = <%s>) } ", this.metaGraphPattern.getPattern(), this.metaGraphPattern.getPattern(), kb.toString());

UpdateRequest updateRequest = UpdateFactory.create(query);
UpdateAction.execute(updateRequest, this.model);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,44 @@ public void testSmartConnectorAllRouteWithoutMetaData() throws InterruptedExcept
stopKbs();
}

@Test
public void testSmartConnectorUpdate() throws InterruptedException {
startKbs();

try {
URI uri = new URI("http://localhost:8283/admin/sc/all/false");
HttpRequest request = HttpRequest.newBuilder(uri).GET().build();

HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());

eu.knowledge.engine.admin.model.SmartConnector[] result = objectMapper.readValue(response.body(),
eu.knowledge.engine.admin.model.SmartConnector[].class);
ArrayList<eu.knowledge.engine.admin.model.SmartConnector> list = new ArrayList<>();
Collections.addAll(list, result);
assertNotNull(list);
assertEquals(2, list.size());
assertEquals(1, list.get(0).getKnowledgeInteractions().size());
assertEquals(200, response.statusCode());

// now stop one KB and check if the admin UI correctly updates.
stopKb(kb1);
Thread.sleep(1000);

response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());

result = objectMapper.readValue(response.body(), eu.knowledge.engine.admin.model.SmartConnector[].class);
list = new ArrayList<>();
Collections.addAll(list, result);
assertEquals(1, list.size());
assertEquals(200, response.statusCode());

} catch (IOException | InterruptedException | URISyntaxException e) {
LOG.warn("Was not able to retrieve smart connectors", e);
fail();
}
stopKb(kb2);
}

@AfterAll
public void cleanup() {
LOG.info("Clean up: {}", TestApiRoutes.class.getSimpleName());
Expand Down Expand Up @@ -252,12 +290,13 @@ public void smartConnectorReady(SmartConnector aSC) {
}

public void stopKbs() {
if (kb1 != null) {
kb1.stop();
}
stopKb(kb1);
stopKb(kb2);
}

if (kb2 != null) {
kb2.stop();
public void stopKb(MockedKnowledgeBase aKb) {
if (aKb != null) {
aKb.stop();
}
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<version>4.10.0</version>
<version>5.2.0</version>
<type>pom</type>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,29 @@
import java.util.Map;

import org.apache.jena.graph.Node;
import org.apache.jena.graph.Node_Concrete;

import org.apache.jena.sparql.core.Var;
import org.apache.jena.sparql.graph.PrefixMappingZero;
import org.apache.jena.sparql.sse.SSE;
import org.apache.jena.sparql.util.FmtUtils;

import eu.knowledge.engine.reasoner.api.Binding;

public class Binding extends HashMap<Var, Node_Concrete> {
public class Binding extends HashMap<Var, Node> {

private static final long serialVersionUID = 2381462612239850018L;

public Binding() {
super();
}

public Binding(Var variable, Node_Concrete lit) {
public Binding(Var variable, Node lit) {
super();
if (!lit.isConcrete())
throw new IllegalArgumentException(
"Binding values should be concrete nodes (either RDF literals or RDF URIs).");
this.put(variable, lit);
}

public Binding(String variable, String val) {
this(Var.alloc(variable), (Node_Concrete) SSE.parseNode(val));
this(Var.alloc(variable), (Node) SSE.parseNode(val));
}

public Binding(Binding b) {
Expand All @@ -48,13 +47,17 @@ public Node get(String variable) {
}

public Node put(String variable, String val) {
return this.put(Var.alloc(variable), (Node_Concrete) SSE.parseNode(val));
Node n = SSE.parseNode(val);
if (!n.isConcrete())
throw new IllegalArgumentException(
"Binding values should be concrete nodes (either RDF literals or RDF URIs).");
return this.put(Var.alloc(variable), n);
}

public Map<String, String> toMap() {

Map<String, String> result = new HashMap<String, String>();
for (Map.Entry<Var, Node_Concrete> entry : this.entrySet()) {
for (Map.Entry<Var, Node> entry : this.entrySet()) {
// TODO: Util function that does the stringForNode without prefixes
result.put(entry.getKey().getName(), FmtUtils.stringForNode(entry.getValue(), new PrefixMappingZero()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.Set;

import org.apache.jena.graph.Node;
import org.apache.jena.graph.Node_Concrete;
import org.apache.jena.sparql.core.Var;
import org.apache.jena.sparql.graph.PrefixMappingZero;
import org.apache.jena.sparql.sse.SSE;
Expand All @@ -20,7 +19,7 @@
*/
public class TripleVarBinding {

private Map<TripleNode, Node_Concrete> tripleVarMapping;
private Map<TripleNode, Node> tripleVarMapping;

/**
* Optimize the getVarValue method.
Expand Down Expand Up @@ -57,7 +56,7 @@ public TripleVarBinding(Set<TriplePattern> aGraphPattern, Binding aBinding) {

public TripleVarBinding(TripleVarBinding b) {
this();
for (Map.Entry<TripleNode, Node_Concrete> entry : b.tripleVarMapping.entrySet()) {
for (Map.Entry<TripleNode, Node> entry : b.tripleVarMapping.entrySet()) {
this.put(entry.getKey(), entry.getValue());
}

Expand All @@ -66,24 +65,28 @@ public TripleVarBinding(TripleVarBinding b) {
}
}

public Set<Map.Entry<TripleNode, Node_Concrete>> entrySet() {
public Set<Map.Entry<TripleNode, Node>> entrySet() {
return tripleVarMapping.entrySet();
}

public Set<TripleNode> getTripleVars() {
return tripleVarMapping.keySet();
}

public void put(TripleNode aTripleVar, Node_Concrete aLiteral) {
public void put(TripleNode aTripleVar, Node aLiteral) {
assert aTripleVar.node.isVariable();

if (!aLiteral.isConcrete())
throw new IllegalArgumentException(
"Binding values should be concrete nodes (either RDF literals or URIs) and not '"
+ aLiteral.toString() + "'");

tripleVarMapping.put(aTripleVar, aLiteral);
variableTripleVarMapping.put((Var) aTripleVar.node, aTripleVar);
}

public void put(TripleNode aTripleVar, String aLiteral) {
assert aTripleVar.node.isVariable();
tripleVarMapping.put(aTripleVar, (Node_Concrete) SSE.parseNode(aLiteral));
variableTripleVarMapping.put((Var) aTripleVar.node, aTripleVar);
this.put(aTripleVar, (Node) SSE.parseNode(aLiteral));
}

/**
Expand All @@ -97,7 +100,7 @@ public void put(TripleNode aTripleVar, String aLiteral) {
public Binding toBinding() {

Binding b = new Binding();
for (Map.Entry<TripleNode, Node_Concrete> entry : this.tripleVarMapping.entrySet()) {
for (Map.Entry<TripleNode, Node> entry : this.tripleVarMapping.entrySet()) {
assert entry.getKey().node.isVariable();
b.put((Var) entry.getKey().node, entry.getValue());
}
Expand All @@ -111,7 +114,7 @@ public Binding toBinding() {
public boolean isConflicting(TripleVarBinding tvb) {

Node l;
for (Map.Entry<TripleNode, Node_Concrete> e : this.tripleVarMapping.entrySet()) {
for (Map.Entry<TripleNode, Node> e : this.tripleVarMapping.entrySet()) {
assert e.getKey().node.isVariable();
l = tvb.getVarValue((Var) e.getKey().node);

Expand All @@ -126,15 +129,15 @@ public boolean isConflicting(TripleVarBinding tvb) {
* We assume all occurrences of a var have the same literal, we just return the
* first one found.
*
* @param var
* @param variable
* @return
*/
public Node_Concrete getVarValue(Var variable) {
public Node getVarValue(Var variable) {
TripleNode tripleVar = this.variableTripleVarMapping.get(variable);
return this.get(tripleVar);
}

public Node_Concrete get(TripleNode key) {
public Node get(TripleNode key) {
return this.tripleVarMapping.get(key);
}

Expand Down Expand Up @@ -196,7 +199,7 @@ public String toString() {
StringBuilder sb = new StringBuilder();
String prefix = "";
sb.append("{");
for (Map.Entry<TripleNode, Node_Concrete> entry : this.tripleVarMapping.entrySet()) {
for (Map.Entry<TripleNode, Node> entry : this.tripleVarMapping.entrySet()) {
sb.append(prefix).append(entry.getKey().node).append("=")
.append(FmtUtils.stringForNode(entry.getValue(), new PrefixMappingZero()));
prefix = ",";
Expand Down Expand Up @@ -228,7 +231,7 @@ public TripleVarBinding merge(TripleVarBinding otherB) {
return b;
}

private void putAll(Map<TripleNode, Node_Concrete> aTripleVarMapping) {
private void putAll(Map<TripleNode, Node> aTripleVarMapping) {

for (TripleNode tv : aTripleVarMapping.keySet()) {
assert tv.node.isVariable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.concurrent.ConcurrentHashMap;

import org.apache.jena.graph.Node;
import org.apache.jena.graph.Node_Concrete;
import org.apache.jena.sparql.core.Var;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -153,7 +152,7 @@ public String toString() {
/**
* Simply the union between the two bindingsets. Does nothing complex for now.
*
* @param gbs
* @param aGraphBindingSet
* @return
*/
public TripleVarBindingSet merge(TripleVarBindingSet aGraphBindingSet) {
Expand Down Expand Up @@ -232,18 +231,18 @@ public TripleVarBindingSet translate(Set<TriplePattern> graphPattern, Set<Match>
&& !fromB.get(fromTVar).equals(toBVarValue)) {
skip = true; // conflict, so skip
}
} else if (fromTNode.node instanceof Var && toTNode.node instanceof Node_Concrete) {
} else if (fromTNode.node instanceof Var && toTNode.node.isConcrete()) {
var fromTVar = new TripleNode(fromTriple, (Var) fromTNode.node, fromTNode.nodeIdx);
if (fromB.containsKey(fromTVar) && !fromB.get(fromTVar).equals(toTNode.node)) {
skip = true; // conflict, so skip
}
} else if (fromTNode.node instanceof Node_Concrete && toTNode.node instanceof Var) {
} else if (fromTNode.node.isConcrete() && toTNode.node instanceof Var) {
var toTVar = new TripleNode(toTriple, (Var) toTNode.node, toTNode.nodeIdx);
if (toB.containsVar((Var) toTVar.node)
&& !toB.getVarValue((Var) toTVar.node).equals(fromTNode.node)) {
skip = true;
} else if (!toB.containsVar((Var) toTVar.node)) {
toB.put(toTVar, (Node_Concrete) fromTNode.node);
toB.put(toTVar, fromTNode.node);
}
}
}
Expand Down Expand Up @@ -332,9 +331,9 @@ public void printDebuggingTable() {
Set<TripleNode> nodes = tvb.getTripleNodes(tp);
if (!nodes.isEmpty()) {

Node_Concrete subject = null;
Node_Concrete predicate = null;
Node_Concrete object = null;
Node subject = null;
Node predicate = null;
Node object = null;

for (TripleNode tn : nodes) {
if (tn.nodeIdx == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.Set;

import org.apache.jena.graph.Node;
import org.apache.jena.graph.Node_Concrete;

import eu.knowledge.engine.reasoner.BaseRule;
import eu.knowledge.engine.reasoner.api.TripleNode;
Expand Down Expand Up @@ -160,9 +159,9 @@ public void printDebuggingTable() {
Set<TripleNode> nodes = tvb.getTripleNodes(tp);
if (!nodes.isEmpty()) {

Node_Concrete subject = null;
Node_Concrete predicate = null;
Node_Concrete object = null;
Node subject = null;
Node predicate = null;
Node object = null;

for (TripleNode tn : nodes) {
if (tn.nodeIdx == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void test() throws InterruptedException, ExecutionException, ParseExcepti

Model m = ModelFactory.createDefaultModel();
for (Binding binding : results2) {
m.add(m.asStatement(new Triple(binding.get("s"), binding.get("p"), binding.get("o"))));
m.add(m.asStatement(Triple.create(binding.get("s"), binding.get("p"), binding.get("o"))));
}

// Model m = Util.generateModel(new TriplePattern(genericTriple), results2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@
import java.util.Set;

import org.apache.jena.graph.Node;
import org.apache.jena.graph.Node_Concrete;
import org.apache.jena.sparql.graph.PrefixMappingZero;
import org.apache.jena.sparql.sse.SSE;
import org.apache.jena.sparql.util.FmtUtils;
import org.junit.jupiter.api.Test;

import eu.knowledge.engine.reasoner.api.Binding;
import eu.knowledge.engine.reasoner.api.BindingSet;
import eu.knowledge.engine.reasoner.api.TriplePattern;
import eu.knowledge.engine.reasoner.api.TripleNode;
import eu.knowledge.engine.reasoner.api.TripleVarBinding;
import eu.knowledge.engine.reasoner.api.TripleVarBindingSet;

public class BindingTest {

Expand All @@ -28,7 +21,7 @@ public void testGraphPatternBindingSets() {
TriplePattern t1 = new TriplePattern("?a <type> <Sensor>");
TriplePattern t2 = new TriplePattern("?a <hasVal> ?b");
TripleVarBinding tb1 = new TripleVarBinding();
tb1.put(new TripleNode(t1, "?a", 0), (Node_Concrete) SSE.parseNode("<sensor1>"));
tb1.put(new TripleNode(t1, "?a", 0), (Node) SSE.parseNode("<sensor1>"));

TripleVarBinding tb2 = new TripleVarBinding();
tb2.put(new TripleNode(t2, "?b", 2), "22");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static Model generateModel(TriplePattern tp, BindingSet variableBindings)
newNodes[i] = newN;
}

m.add(m.asStatement(new Triple(newNodes[0], newNodes[1], newNodes[2])));
m.add(m.asStatement(Triple.create(newNodes[0], newNodes[1], newNodes[2])));
}
return m;
}
Expand Down
Loading

0 comments on commit 37ad896

Please sign in to comment.