Author: batosai
Date: 2008-09-03 19:54:01 +0000 (Wed, 03 Sep 2008)
New Revision: 22379

Modified:
   trunk/apps/WoT/src/plugins/WoT/Identity.java
Log:
Search identities by id (routing key).

Modified: trunk/apps/WoT/src/plugins/WoT/Identity.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/Identity.java        2008-09-03 19:14:01 UTC 
(rev 22378)
+++ trunk/apps/WoT/src/plugins/WoT/Identity.java        2008-09-03 19:54:01 UTC 
(rev 22379)
@@ -49,21 +49,24 @@
        public Identity (String requestURI, Date lastChange, String nickName, 
String publishTrustList, String context) throws InvalidParameterException, 
MalformedURLException {
                this(new FreenetURI(requestURI), nickName, publishTrustList, 
context);
        }
-

        @SuppressWarnings("unchecked")
-       public static Identity getByURI (ObjectContainer db, FreenetURI uri) 
throws UnknownIdentityException, DuplicateIdentityException {
-               
+       public static Identity getById (ObjectContainer db, byte[] id) throws 
DuplicateIdentityException, UnknownIdentityException {
                Query query = db.query();
                query.constrain(Identity.class);
-               
query.descend("requestURI").constrain(uri.toString().substring(uri.toString().indexOf("@")
 + 1, uri.toString().indexOf("/")));
+               query.descend("id").constrain(id);
                ObjectSet<Identity> result = query.execute();

-               if(result.size() == 0) throw new UnknownIdentityException("No 
identity has this request URI ("+uri.toString()+")");
-               if(result.size() > 1) throw new 
DuplicateIdentityException("There are two Identities matching this URI : " + 
uri.toString());
+               if(result.size() == 0) throw new 
UnknownIdentityException(id.toString());
+               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());
+       }
+       
        public static Identity getByURI (ObjectContainer db, String uri) throws 
UnknownIdentityException, DuplicateIdentityException, MalformedURLException {
                return getByURI(db, new FreenetURI(uri));
        }
@@ -78,6 +81,7 @@
         * @throws  
         */
        public Score getScore(OwnIdentity treeOwner, ObjectContainer db) throws 
NotInTrustTreeException, DuplicateScoreException {
+               
                //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");


Reply via email to