Author: batosai
Date: 2008-08-10 15:11:50 +0000 (Sun, 10 Aug 2008)
New Revision: 21716
Modified:
trunk/apps/WoT/src/plugins/WoT/IdentityFetcher.java
trunk/apps/WoT/src/plugins/WoT/WoT.java
Log:
Move the code to find an identity by its URI to WoT.
Modified: trunk/apps/WoT/src/plugins/WoT/IdentityFetcher.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/IdentityFetcher.java 2008-08-10 14:57:02 UTC
(rev 21715)
+++ trunk/apps/WoT/src/plugins/WoT/IdentityFetcher.java 2008-08-10 15:11:50 UTC
(rev 21716)
@@ -83,18 +83,8 @@
public void onSuccess(FetchResult result, ClientGetter state) {
// Find the identity we just fetched
- Identity identity = null;
-
- // This is ugly, I could not find a request able to find the
good identity
- ObjectSet<Identity> search = db.queryByExample(Identity.class);
- while (search.hasNext()) {
- Identity id = search.next();
-
if(id.getRequestURI().getRoutingKey().equals(state.getURI().getRoutingKey())) {
- identity = id;
- break;
- }
- }
- if (identity == null) {
+ Identity identity = wot.getIdentityByURI(new
FreenetURI(state.getURI()));
+ if (identity == null) { // This should never happen but...
System.out.println("Error, identity not found");
return;
}
Modified: trunk/apps/WoT/src/plugins/WoT/WoT.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoT.java 2008-08-10 14:57:02 UTC (rev
21715)
+++ trunk/apps/WoT/src/plugins/WoT/WoT.java 2008-08-10 15:11:50 UTC (rev
21716)
@@ -8,6 +8,8 @@
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
+import freenet.keys.FreenetURI;
+
/**
* The Web of Trust
*
@@ -166,5 +168,21 @@
ObjectSet<Identity> identities =
db.queryByExample(Identity.class);
return identities.size() - getNbOwnIdentities();
}
+
+ public Identity getIdentityByURI(FreenetURI uri) {
+
+ Identity identity = null;
+
+ // This is ugly, I could not find a request able to find the
good identity
+ ObjectSet<Identity> search = db.queryByExample(Identity.class);
+ while (search.hasNext()) {
+ Identity id = search.next();
+
if(id.getRequestURI().getRoutingKey().equals(uri.getRoutingKey())) {
+ identity = id;
+ break;
+ }
+ }
+ return identity;
+ }
}