Author: batosai
Date: 2008-08-13 14:13:35 +0000 (Wed, 13 Aug 2008)
New Revision: 21805
Modified:
trunk/apps/WoT/src/plugins/WoT/WoT.java
trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
Log:
Handle GetIdentitiesByScore FCP message.
Modified: trunk/apps/WoT/src/plugins/WoT/WoT.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoT.java 2008-08-13 14:00:37 UTC (rev
21804)
+++ trunk/apps/WoT/src/plugins/WoT/WoT.java 2008-08-13 14:13:35 UTC (rev
21805)
@@ -6,9 +6,12 @@
package plugins.WoT;
import java.net.MalformedURLException;
+import java.util.HashSet;
+import java.util.Set;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
+import com.db4o.query.Constraint;
import com.db4o.query.Query;
import freenet.keys.FreenetURI;
@@ -190,5 +193,29 @@
if(result.size() == 0) throw new UnknownIdentityException("No
identity has this request URI ("+uri.toString()+")");
return result.next();
}
+
+ public ObjectSet<Score> getIdentitiesByScore (String reference, String
select) throws InvalidParameterException, MalformedURLException,
UnknownIdentityException {
+
+ Identity identity = getIdentityByURI(reference);
+ if(!(identity instanceof OwnIdentity)) throw new
InvalidParameterException("It's not an OwnIdentity");
+ OwnIdentity treeOwner = (OwnIdentity) identity;
+
+ Query query = db.query();
+ query.constrain(Score.class);
+ query.descend("treeOwner").constrain(treeOwner);
+
+ if(select.equals("+")) {
+ query.descend("score").constrain(new
Integer(0)).greater();
+ }
+ else if(select.equals("0")) {
+ query.descend("score").constrain(new Integer(0));
+ }
+ else if(select.equals("all")) {
+ // No selection to do, we select every identities that
have a score
+ }
+ else throw new InvalidParameterException("Unhandled select
value ("+select+")");
+
+ return query.execute();
+ }
}
Modified: trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoTplugin.java 2008-08-13 14:00:37 UTC
(rev 21804)
+++ trunk/apps/WoT/src/plugins/WoT/WoTplugin.java 2008-08-13 14:13:35 UTC
(rev 21805)
@@ -10,6 +10,7 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Date;
+import java.util.Set;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerConfigurationException;
@@ -452,6 +453,9 @@
else if(params.get("Message").equals("AddIdentity")) {
replysender.send(handleAddIdentity(params),
data);
}
+ else
if(params.get("Message").equals("GetIdentitiesByScore")) {
+
replysender.send(handleGetIdentitiesByScore(params), data);
+ }
else {
throw new Exception("Unknown message (" +
params.get("Message") + ")");
}
@@ -488,9 +492,9 @@
SimpleFieldSet sfs = new SimpleFieldSet(false);
- if(params.get("truster") == null || params.get("trustee") ==
null || params.get("value") == null || params.get("comment") == null) throw new
InvalidParameterException("Missing mandatory parameter");
+ if(params.get("Truster") == null || params.get("Trustee") ==
null || params.get("Value") == null || params.get("Comment") == null) throw new
InvalidParameterException("Missing mandatory parameter");
- setTrust(params.get("truster"), params.get("trustee"),
params.get("value"), params.get("comment"));
+ setTrust(params.get("Truster"), params.get("Trustee"),
params.get("Value"), params.get("Comment"));
sfs.putAppend("Message", "TrustSet");
return sfs;
@@ -500,15 +504,30 @@
SimpleFieldSet sfs = new SimpleFieldSet(false);
- if(params.get("requestURI") == null) throw new
InvalidParameterException("Missing mandatory parameter");
+ if(params.get("RequestURI") == null) throw new
InvalidParameterException("Missing mandatory parameter");
- Identity identity =
addIdentity(params.get("requestURI").trim());
+ Identity identity =
addIdentity(params.get("RequestURI").trim());
sfs.putAppend("Message", "IdentityAdded");
- sfs.putAppend("requestURI",
identity.getRequestURI().toString());
+ sfs.putAppend("RequestURI",
identity.getRequestURI().toString());
return sfs;
}
+ private SimpleFieldSet handleGetIdentitiesByScore(SimpleFieldSet
params) throws InvalidParameterException, MalformedURLException,
UnknownIdentityException {
+
+ SimpleFieldSet sfs = new SimpleFieldSet(false);
+
+ if(params.get("TreeOwner") == null || params.get("Select") ==
null) throw new InvalidParameterException("Missing mandatory parameter");
+
+ sfs.putAppend("Message", "Identities");
+
+ ObjectSet<Score> result =
wot.getIdentitiesByScore(params.get("TreeOwner"), params.get("Select").trim());
+ for(int i = 1 ; result.hasNext() ; i++)
+ sfs.putAppend("Identity"+i,
result.next().getTarget().getRequestURI().toString());
+
+ return sfs;
+ }
+
private SimpleFieldSet errorMessageFCP (Exception e) {
SimpleFieldSet sfs = new SimpleFieldSet(false);