Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

interaction: add special table interaction

cominche14f2881ae51
diff --git a/htroot/DemoServletInteraction.html b/htroot/DemoServletInteraction.html
index c2dc04b1f..0dd6478ff 100644
--- a/htroot/DemoServletInteraction.html
+++ b/htroot/DemoServletInteraction.html
@@ -23,7 +23,7 @@
<script type="text/javascript" charset="utf-8">
- var oldvalue = loadvalue ('http://virtual.x/document/uniquenameDemo123', 'http://virtual.x/hasvalue');
+ var oldvalue = loadvalue_t ('http://virtual.x/document/uniquenameDemo123', 'http://virtual.x/hasvalue');
if (oldvalue == "") {
oldvalue = "0";
@@ -42,7 +42,7 @@
skin: 'round',
onstatechange: function(value) {
- storevalue ('http://virtual.x/document/uniquenameDemo123', 'http://virtual.x/hasvalue', value);
+ storevalue_t ('http://virtual.x/document/uniquenameDemo123', 'http://virtual.x/hasvalue', value);
}
}
diff --git a/htroot/interaction/OverlayInteraction.html b/htroot/interaction/OverlayInteraction.html
index d68b4569a..91623314e 100644
--- a/htroot/interaction/OverlayInteraction.html
+++ b/htroot/interaction/OverlayInteraction.html
@@ -65,7 +65,7 @@ document <img src="/currentyacypeer/env/grafics/bad.png" width="16px" height="16
<script type="text/javascript" charset="utf-8">
- var oldvalue = loadvalue ('#[link]#', 'http://virtual.x/hastags');
+ var oldvalue = loadvalue_t ('#[link]#', 'http://virtual.x/hastags');
document.getElementById('tags').value = oldvalue;
@@ -78,7 +78,7 @@ document <img src="/currentyacypeer/env/grafics/bad.png" width="16px" height="16
'maxChars' : 0,
'placeholderColor' : '#666666',
'onChange' : function () {
- storevalue ('#[link]#', 'http://virtual.x/hastags', document.getElementById('tags').value);
+ storevalue_t ('#[link]#', 'http://virtual.x/hastags', document.getElementById('tags').value);
}
});
diff --git a/htroot/interaction/Table.java b/htroot/interaction/Table.java
new file mode 100644
index 000000000..fe180aa75
--- /dev/null
+++ b/htroot/interaction/Table.java
@@ -0,0 +1,144 @@
+package interaction;
+
+//ViewLog_p.java
+//-----------------------
+//part of the AnomicHTTPD caching proxy
+//(C) by Michael Peter Christen; [email protected]
+//first published on http://www.anomic.de
+//Frankfurt, Germany, 2004
+//
+//This File is contributed by Alexander Schier
+//last major change: 14.12.2004
+//
+//This program is free software; you can redistribute it and/or modify
+//it under the terms of the GNU General Public License as published by
+//the Free Software Foundation; either version 2 of the License, or
+//(at your option) any later version.
+//
+//This program is distributed in the hope that it will be useful,
+//but WITHOUT ANY WARRANTY; without even the implied warranty of
+//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//GNU General Public License for more details.
+//
+//You should have received a copy of the GNU General Public License
+//along with this program; if not, write to the Free Software
+//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+//You must compile this file with
+//javac -classpath .:../classes ViewLog_p.java
+//if the shell's current path is HTROOT
+
+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;
+import de.anomic.server.serverSwitch;
+
+public class Table {
+
+ public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
+
+ final Switchboard sb = (Switchboard) env;
+
+ final serverObjects prop = new serverObjects();
+
+ UserDB.Entry entry=null;
+
+
+
+ //default values
+ prop.put("enabled_logged_in", "0");
+ prop.put("enabled_logged-in_limit", "0");
+ String username = "anonymous";
+ prop.put("enabled_status", "0");
+ //identified via HTTPPassword
+ entry=sb.userDB.proxyAuth((header.get(RequestHeader.AUTHORIZATION, "xxxxxx")));
+ if(entry != null){
+ prop.put("enabled_logged-in_identified-by", "1");
+ //try via cookie
+ }else{
+ entry=sb.userDB.cookieAuth(header.getHeaderCookies());
+ prop.put("enabled_logged-in_identified-by", "2");
+ //try via ip
+ if(entry == null){
+ entry=sb.userDB.ipAuth((header.get(HeaderFramework.CONNECTION_PROP_CLIENTIP, "xxxxxx")));
+ if(entry != null){
+ prop.put("enabled_logged-in_identified-by", "0");
+ }
+ }
+ }
+
+ //identified via userDB
+ if(entry != null){
+ prop.put("enabled_logged-in", "1");
+ username = entry.getUserName();
+ if(entry.getTimeLimit() > 0){
+ prop.put("enabled_logged-in_limit", "1");
+ final long limit=entry.getTimeLimit();
+ final long used=entry.getTimeUsed();
+ prop.put("enabled_logged-in_limit_timelimit", limit);
+ prop.put("enabled_logged-in_limit_timeused", used);
+ int percent=0;
+ if(limit!=0 && used != 0)
+ percent=(int)((float)used/(float)limit*100);
+ prop.put("enabled_logged-in_limit_percent", percent/3);
+ prop.put("enabled_logged-in_limit_percent2", (100-percent)/3);
+ }
+ //logged in via static Password
+ }else if(sb.verifyAuthentication(header)){
+ prop.put("enabled_logged-in", "2");
+ username = "staticadmin";
+ //identified via form-login
+ //TODO: this does not work for a static admin, yet.
+ }
+
+ String url = "";
+ String s = "";
+ String p = "";
+ String o = "";
+
+ Boolean global = false;
+
+ if(post != null){
+
+ if(post.containsKey("url")){
+ url = post.get("url");
+ }
+
+ if(post.containsKey("s")){
+ s = post.get("s");
+ }
+
+ if(post.containsKey("p")){
+ p = post.get("p");
+ }
+
+ if(post.containsKey("o")){
+ o = post.get("o");
+ }
+
+ global = post.containsKey("global");
+
+ }
+
+ if (post.containsKey("load")) {
+
+ o = Interaction.GetTableentry(s, p, global ? "" : username, "");
+
+ } else {
+
+ Interaction.Tableentry(s, p, o, global ? "" : username, "");
+
+ }
+
+ prop.put("result", o);
+
+
+
+ return prop;
+ }
+}
diff --git a/htroot/interaction/Table.json b/htroot/interaction/Table.json
new file mode 100644
index 000000000..bad0493c2
--- /dev/null
+++ b/htroot/interaction/Table.json
@@ -0,0 +1,4 @@
+{
+ "url": "#[url]#",
+ "result": "#[result]#"
+}
\ No newline at end of file
diff --git a/htroot/interaction/interaction.js b/htroot/interaction/interaction.js
index d9eb432ea..78646610f 100644
--- a/htroot/interaction/interaction.js
+++ b/htroot/interaction/interaction.js
@@ -33,6 +33,15 @@ function triple (url, s, p, o, username) {
}
+function storevalue_t (s, p, o) {
+
+ $.getJSON('/currentyacypeer/interaction/Table.json?url='+document.location.href+'&s='+s+'&p='+p+'&o='+o, function(data) {
+
+
+ });
+
+}
+
function storevalue (s, p, o) {
$.getJSON('/currentyacypeer/interaction/Triple.json?url='+document.location.href+'&s='+s+'&p='+p+'&o='+o, function(data) {
@@ -68,6 +77,23 @@ function loadvalue (s, p) {
}
+function loadvalue_t (s, p) {
+
+ var res = {result: ""};
+
+ $.ajaxSetup({async: false});
+
+ $.getJSON('/currentyacypeer/interaction/Table.json?s='+s+'&p='+p+'&load=true', function (data) {
+
+ res = data;
+
+ });
+
+
+ return res.result;
+
+}
+
function loadvalueglobal (s, p) {
var res = {result: ""};
diff --git a/source/net/yacy/interaction/Interaction.java b/source/net/yacy/interaction/Interaction.java
index 81dd454b0..9e247f94d 100644
--- a/source/net/yacy/interaction/Interaction.java
+++ b/source/net/yacy/interaction/Interaction.java
@@ -3,10 +3,12 @@ package net.yacy.interaction;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import net.yacy.cora.document.UTF8;
import net.yacy.cora.protocol.http.HTTPClient;
+import net.yacy.kelondro.blob.Tables.Row;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
@@ -381,7 +383,46 @@ public static String Feedback(String url, String comment, String from, String pe
return "";
}
-public static String Contribution(String url, String comment, String from, String peer) {
+
+
+public static String Contribution(String url, String value, String username, String peer) {
+ return Tableentry(url, "comment", value, username, peer);
+}
+
+
+public static String GetTableentry(String url, String type, String username, String peer) {
+
+ final Switchboard sb = Switchboard.getSwitchboard();
+
+ try {
+ Iterator<Row> it = sb.tables.iterator(username+"_contribution", "url", url.getBytes());
+
+ Log.logInfo ("TABLE", "GET "+username+" / "+url+" - "+type+" ...");
+
+ it = sb.tables.orderBy(it, -1, "timestamp_creation").iterator();
+
+ while (it.hasNext()) {
+ Row r = it.next();
+
+ if (!it.hasNext()) {
+
+ if (r.containsKey(type)) {
+ Log.logInfo ("TABLE", "GET "+username+" / "+url+" - "+type+" - "+r.get(type, ""));
+ return r.get(type, "");
+ }
+ }
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return "";
+
+
+}
+
+public static String Tableentry(String url, String type, String comment, String from, String peer) {
final Switchboard sb = Switchboard.getSwitchboard();
@@ -390,7 +431,8 @@ public static String Contribution(String url, String comment, String from, Strin
}
Boolean processlocal = false;
-
+ Log.logInfo ("TABLE", "PUT "+from+" / "+url+" - "+type+" - "+comment);
+
if (!sb.getConfig("interaction.contribution.accumulationpeer", "").equals("")) {
if (sb.getConfig("interaction.contribution.accumulationpeer", "").equals(sb.peers.myName())) {
@@ -431,12 +473,13 @@ public static String Contribution(String url, String comment, String from, Strin
map.put("url", url.getBytes());
map.put("username", from.getBytes());
map.put("peer", peer.getBytes());
- map.put("status", "new".getBytes());
- map.put("comment", comment.getBytes());
+ map.put("status", "new".getBytes());
+ map.put("type", type.getBytes());
+ map.put(type, comment.getBytes());
map.put("timestamp_creation", date.getBytes());
try {
- sb.tables.insert("contribution", map);
+ sb.tables.insert(from+"_contribution", map);
} catch (final IOException e) {
Log.logException(e);
} catch (RowSpaceExceededException e) {