Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
interaction: add global variable store
cominch4e4e7a99f889
diff --git a/htroot/DemoServletInteraction.html b/htroot/DemoServletInteraction.htmlindex c455e5d60..c2dc04b1f 100644--- a/htroot/DemoServletInteraction.html+++ b/htroot/DemoServletInteraction.html@@ -12,7 +12,7 @@<body id="index"><p>- JavaScript example: Permanent storage of value+ JavaScript example: Permanent storage of value, assigned to logged in user account</p><br/>@@ -50,6 +50,36 @@</script>+ </p>++ <br/>+ <br/>++ <p>+ JavaScript example: Load value from global RDF store+ </p>+ <br/>++ <br/>++ <p>++ <input id="output" type="text" name="output" value="--"/>+ <input type="submit" name="sub" onclick="storevalueglobal ('http://virtual.x/global/entry1', 'http://virtual.x/global/hasvalue', document.getElementById('output').value)"/>++ l++ <script type="text/javascript" charset="utf-8">+++ var oldvalue = loadvalueglobal ('http://virtual.x/global/entry1', 'http://virtual.x/global/hasvalue');++ document.getElementById('output').value = oldvalue;++++ </script>+</p>diff --git a/htroot/interaction/Triple.java b/htroot/interaction/Triple.javaindex f183049ae..fa1a3c2fb 100644--- a/htroot/interaction/Triple.java+++ b/htroot/interaction/Triple.java@@ -32,6 +32,7 @@ package interaction;import net.yacy.cora.protocol.HeaderFramework;import net.yacy.cora.protocol.RequestHeader;import net.yacy.interaction.Interaction;+import net.yacy.kelondro.logging.Log;import net.yacy.search.Switchboard;import de.anomic.data.UserDB;import de.anomic.server.serverObjects;@@ -99,7 +100,8 @@ public class Triple {String s = "";String p = "";String o = "";- String from = "";++ Boolean global = false;if(post != null){@@ -118,20 +120,18 @@ public class Triple {if(post.containsKey("o")){o = post.get("o");}-- if(post.containsKey("from")){- from = post.get("from");- }++ global = post.containsKey("global");}if (post.containsKey("load")) {-- o = Interaction.TripleGet(s, p, username);++ o = Interaction.TripleGet(s, p, global ? "" : username);} else {- Interaction.Triple(url, s, p, o, username);+ Interaction.Triple(url, s, p, o, global ? "" : username);}prop.put("result", o);diff --git a/htroot/interaction/interaction.js b/htroot/interaction/interaction.jsindex 2a79cba32..d9eb432ea 100644--- a/htroot/interaction/interaction.js+++ b/htroot/interaction/interaction.js@@ -42,6 +42,15 @@ function storevalue (s, p, o) {}+function storevalueglobal (s, p, o) {++ $.getJSON('/currentyacypeer/interaction/Triple.json?global=true&url='+document.location.href+'&s='+s+'&p='+p+'&o='+o, function(data) {+++ });++}+function loadvalue (s, p) {var res = {result: ""};@@ -55,6 +64,23 @@ function loadvalue (s, p) {});+ return res.result;++}++function loadvalueglobal (s, p) {++ var res = {result: ""};++ $.ajaxSetup({async: false});++ $.getJSON('/currentyacypeer/interaction/Triple.json?global=true&s='+s+'&p='+p+'&load=true', function (data) {++ res = data;++ });++return res.result;}\ No newline at end of filediff --git a/source/net/yacy/interaction/Interaction.java b/source/net/yacy/interaction/Interaction.javaindex 11bd984dc..f917764bb 100644--- a/source/net/yacy/interaction/Interaction.java+++ b/source/net/yacy/interaction/Interaction.java@@ -448,22 +448,53 @@ public static String Contribution(String url, String comment, String from, Strinreturn "";}++public static String Triple(String url, String s, String p, String o) {+ return Triple (url, s, p, o, "");+}++public static String Triple(String url, String s, String p, String o, String username) {++ final Switchboard sb = Switchboard.getSwitchboard();++ if (username != "") {+ username = "/"+username;+ }++ Resource r = TripleStore.model.getResource(s+username);+ Property pr = TripleStore.model.getProperty(p);++ TripleStore.model.removeAll(r, pr, (Resource) null);+++ r.addProperty(pr, o);+++ Log.logInfo ("TRIPLESTORE", "PUT "+username+" / "+s+" - "+p+" - "+o);+-public static String Triple(String url, String s, String p, String o, String from) {- Resource r = TripleStore.model.getResource(s+"/"+from);- Property pr = TripleStore.model.getProperty(p);- TripleStore.model.removeAll(r, pr, (Resource) null);- r.addProperty(pr, o);- Log.logInfo ("TRIPLESTORE", "PUT "+from+" / "+s+" - "+p+" - "+o);return "";}-public static String TripleGet(String s, String p, String username) {- Resource r = TripleStore.model.getResource(s+"/"+username);+public static String TripleGet(String s, String p) {+ return TripleGet (s, p, "");+}++public static String TripleGet(String s, String p, String username) {++ final Switchboard sb = Switchboard.getSwitchboard();++ if (username != "") {+ username = "/"+username;+ }++ Resource r = TripleStore.model.getResource(s+username);Property pr = TripleStore.model.getProperty(p);- StmtIterator iter = TripleStore.model.listStatements(r, pr, (Resource) null);- Log.logInfo ("TRIPLESTORE", "GET "+s+" - "+p);+ StmtIterator iter = TripleStore.model.listStatements(r, pr, (Resource) null);++ Log.logInfo ("TRIPLESTORE", "GET "+username+" / "+s+" - "+p+" ... ");+while (iter.hasNext()) {String obj = iter.nextStatement().getObject().toString();