Author: batosai
Date: 2008-09-03 20:20:21 +0000 (Wed, 03 Sep 2008)
New Revision: 22380
Added:
trunk/apps/WoT/src/plugins/WoT/DuplicateTrustException.java
trunk/apps/WoT/src/plugins/WoT/NotTrustedException.java
Modified:
trunk/apps/WoT/src/plugins/WoT/Identity.java
Log:
Query Trust and Score objects through SODA as Toad suggested.
Added: trunk/apps/WoT/src/plugins/WoT/DuplicateTrustException.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/DuplicateTrustException.java
(rev 0)
+++ trunk/apps/WoT/src/plugins/WoT/DuplicateTrustException.java 2008-09-03
20:20:21 UTC (rev 22380)
@@ -0,0 +1,18 @@
+/**
+ * This code is part of WoT, a plugin for Freenet. It is distributed
+ * under the GNU General Public License, version 2 (or at your option
+ * any later version). See http://www.gnu.org/ for details of the GPL.
+ */
+package plugins.WoT;
+
+/**
+ * @author Julien Cornuwel (batosai at freenetproject.org)
+ */
+public class DuplicateTrustException extends Exception {
+
+ private static final long serialVersionUID = -1;
+
+ public DuplicateTrustException(String message) {
+ super(message);
+ }
+}
Modified: trunk/apps/WoT/src/plugins/WoT/Identity.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/Identity.java 2008-09-03 19:54:01 UTC
(rev 22379)
+++ trunk/apps/WoT/src/plugins/WoT/Identity.java 2008-09-03 20:20:21 UTC
(rev 22380)
@@ -25,6 +25,7 @@
*/
public class Identity {
+ @SuppressWarnings("unused")
private byte[] id;
private FreenetURI requestURI;
@@ -50,6 +51,8 @@
this(new FreenetURI(requestURI), nickName, publishTrustList,
context);
}
+
+
@SuppressWarnings("unchecked")
public static Identity getById (ObjectContainer db, byte[] id) throws
DuplicateIdentityException, UnknownIdentityException {
Query query = db.query();
@@ -61,7 +64,6 @@
if(result.size() > 1) throw new
DuplicateIdentityException(id.toString());
return result.next();
}
-
public static Identity getByURI (ObjectContainer db, FreenetURI uri)
throws UnknownIdentityException, DuplicateIdentityException {
return getById(db, uri.getRoutingKey());
@@ -71,31 +73,46 @@
return getByURI(db, new FreenetURI(uri));
}
- /**
- * Finds the score of an identity in the database.
- * @param treeOwner
- * @param db
- * @return
- * @throws NotInTrustTreeException
- * @throws DuplicateScoreException
- * @throws
- */
+
+
+ @SuppressWarnings("unchecked")
public Score getScore(OwnIdentity treeOwner, ObjectContainer db) throws
NotInTrustTreeException, DuplicateScoreException {
+ Query query = db.query();
+ query.constrain(Score.class);
+
query.descend("treeOwner").constrain(treeOwner).and(query.descend("target").constrain(this));
+ ObjectSet<Score> result = query.execute();
- //TODO query on routing key
- ObjectSet<Score> score = db.queryByExample(new Score(treeOwner,
this, 0, 0, 0));
- if(score.size() == 0) throw new
NotInTrustTreeException(this.getRequestURI().toString()+" is not in that trust
tree");
- else if(score.size() > 1) throw new
DuplicateScoreException(this.getRequestURI().toString()+" ("+ getNickName() +")
has "+score.size()+" scores in "+treeOwner.getNickName()+"'s trust tree");
- else return score.next();
+ if(result.size() == 0) throw new
NotInTrustTreeException(this.getRequestURI().toString()+" is not in that trust
tree");
+ else if(result.size() > 1) throw new
DuplicateScoreException(this.getRequestURI().toString()+" ("+ getNickName() +")
has "+result.size()+" scores in "+treeOwner.getNickName()+"'s trust tree");
+ else return result.next();
}
- public Trust getTrust(Identity truster, ObjectContainer db) throws
InvalidParameterException {
- //TODO query on routing key
- ObjectSet<Trust> trust = db.queryByExample(new Trust(truster,
this, 0, null));
- if(trust.hasNext()) return trust.next();
- else return null;
+ @SuppressWarnings("unchecked")
+ public Trust getReceivedTrust(Identity truster, ObjectContainer db)
throws NotTrustedException, DuplicateTrustException {
+ Query query = db.query();
+ query.constrain(Trust.class);
+
query.descend("truster").constrain(truster).and(query.descend("trustee").constrain(this));
+ ObjectSet<Trust> result = query.execute();
+
+ if(result.size() == 0) throw new
NotTrustedException(truster.getNickName() + " does not trust " +
this.getNickName());
+ else if(result.size() > 1) throw new
DuplicateTrustException("Trust from " + truster.getNickName() + "to " +
this.getNickName() + " exists " + result.size() + " times in the database");
+ else return result.next();
}
+
+ @SuppressWarnings("unchecked")
+ public Trust getGivenTrust(Identity trustee, ObjectContainer db) throws
NotTrustedException, DuplicateTrustException {
+ Query query = db.query();
+ query.constrain(Trust.class);
+
query.descend("truster").constrain(this).and(query.descend("trustee").constrain(trustee));
+ ObjectSet<Trust> result = query.execute();
+
+ if(result.size() == 0) throw new
NotTrustedException(trustee.getNickName() + " does not trust " +
this.getNickName());
+ else if(result.size() > 1) throw new
DuplicateTrustException("Trust from " + this.getNickName() + "to " +
trustee.getNickName() + " exists " + result.size() + " times in the database");
+ else return result.next();
+ }
+
+
public void setRequestURI(FreenetURI requestURI) throws
InvalidParameterException {
if(requestURI.getKeyType().equals("SSK")) requestURI =
requestURI.setKeyType("USK");
if(!requestURI.getKeyType().equals("USK")) throw new
InvalidParameterException("Key type not supported");
Added: trunk/apps/WoT/src/plugins/WoT/NotTrustedException.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/NotTrustedException.java
(rev 0)
+++ trunk/apps/WoT/src/plugins/WoT/NotTrustedException.java 2008-09-03
20:20:21 UTC (rev 22380)
@@ -0,0 +1,18 @@
+/**
+ * This code is part of WoT, a plugin for Freenet. It is distributed
+ * under the GNU General Public License, version 2 (or at your option
+ * any later version). See http://www.gnu.org/ for details of the GPL.
+ */
+package plugins.WoT;
+
+/**
+ * @author Julien Cornuwel (batosai at freenetproject.org)
+ */
+public class NotTrustedException extends Exception {
+
+ private static final long serialVersionUID = -1;
+
+ public NotTrustedException(String message) {
+ super(message);
+ }
+}