Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions admin-ui/src/main/java/eu/knowledge/engine/admin/MetadataKB.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.ResourceFactory;
import org.apache.jena.shared.PrefixMapping;
import org.apache.jena.sparql.graph.PrefixMappingMem;
import org.apache.jena.sparql.lang.arq.javacc.ParseException;
Expand Down Expand Up @@ -125,6 +126,7 @@ public BindingSet handleNewKnowledgeBase(ReactExchangeInfo ei) {

Resource kb = model.listSubjectsWithProperty(RDF.type, Vocab.KNOWLEDGE_BASE).next();
this.metadata.add(model);
model.close();
LOG.debug("Modified metadata with new KB '{}'.", kb);
} catch (ParseException e) {
LOG.error("{}", e);
Expand Down Expand Up @@ -155,6 +157,8 @@ public BindingSet handleChangedKnowledgeBase(ReactExchangeInfo ei) {

this.metadata.add(model);

model.close();

LOG.debug("Modified metadata with changed KB '{}'.", kb);

} catch (ParseException e) {
Expand All @@ -167,26 +171,23 @@ public BindingSet handleRemovedKnowledgeBase(ReactExchangeInfo ei) {
if (!this.canReceiveUpdates())
return new BindingSet();

try {
Model model = eu.knowledge.engine.smartconnector.impl.Util.generateModel(this.aKI.getPattern(),
ei.getArgumentBindings());
// this is also a little complex... we have to:
// - extract the knowledge base that this message is about
// - delete all old data about that knowledge base

// this is also a little complex... we have to:
// - extract the knowledge base that this message is about
// - delete all old data about that knowledge base
String kbUri = ei.getArgumentBindings().iterator().next().get("kb");
Resource kb = this.metadata.createResource(kbUri.substring(1, kbUri.length() - 1));

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());
LOG.info("KB '{}'.", kb);

UpdateRequest updateRequest = UpdateFactory.create(query);
UpdateAction.execute(updateRequest, this.metadata);
String query = String.format("DELETE { %s } WHERE { %s FILTER (?kb = <%s>) } ",
this.metaGraphPattern.getPattern(), this.metaGraphPattern.getPattern(), kb.toString());

LOG.debug("Modified metadata with deleted KB '{}'.", kb);
UpdateRequest updateRequest = UpdateFactory.create(query);
UpdateAction.execute(updateRequest, this.metadata);

LOG.debug("Modified metadata with deleted KB '{}'.", kb);

} catch (ParseException e) {
LOG.error("{}", e);
}
return new BindingSet();
}

Expand All @@ -198,6 +199,10 @@ public void fetchInitialData() {
// execute actual *ask* and use previously defined Knowledge Interaction.
this.getSC().ask(this.aKI, new BindingSet()).thenAccept(askResult -> {
try {

if (this.metadata != null)
this.metadata.close();

// using the BindingSet#generateModel() helper method, we can combine the graph
// pattern and the bindings for its variables into a valid RDF Model.
this.metadata = eu.knowledge.engine.smartconnector.impl.Util.generateModel(this.aKI.getPattern(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ private OtherKnowledgeBase constructOtherKnowledgeBaseFromBindingSet(BindingSet

}

model.close();

URI kbId = null;
try {
kbId = new URI(kb.getURI());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import javax.cache.CacheManager;
import javax.cache.Caching;
import javax.cache.configuration.MutableConfiguration;
import javax.cache.expiry.CreatedExpiryPolicy;
import javax.cache.expiry.AccessedExpiryPolicy;
import javax.cache.expiry.Duration;
import javax.cache.spi.CachingProvider;

Expand Down Expand Up @@ -40,7 +40,7 @@ public class Util {
CacheManager cacheManager = cachingProvider.getCacheManager();
MutableConfiguration<String, Node> config = new MutableConfiguration<String, Node>()
.setTypes(String.class, Node.class).setStoreByValue(false)
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(Duration.ONE_HOUR));
.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(Duration.TEN_MINUTES));
nodeCache = cacheManager.createCache("nodeCache", config);
}

Expand Down Expand Up @@ -100,7 +100,7 @@ public static Model generateModel(GraphPattern graphPattern, BindingSet variable
}
return m;
}

public static Set<TriplePattern> translateGraphPatternTo(GraphPattern pattern) {

TriplePattern tp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ public boolean isUpToDate(AskKnowledgeInteraction askKnowledgeInteraction,
isUpToDate &= isKnowledgeBaseUpToDate(aKnowledgeBase, m);
}
}
m.close();

} catch (InterruptedException | ExecutionException | ParseException e) {
LOG.error("{}", e);
Expand Down
Loading