Author: batosai
Date: 2008-08-31 18:14:39 +0000 (Sun, 31 Aug 2008)
New Revision: 22286

Added:
   trunk/apps/WoT/src/plugins/WoT/DuplicateScoreException.java
Modified:
   trunk/apps/WoT/src/plugins/WoT/Identity.java
   trunk/apps/WoT/src/plugins/WoT/WebInterface.java
   trunk/apps/WoT/src/plugins/WoT/WoT.java
   trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
Log:
Added detection of duplicated Score for an identity.
Will hopefully help with bug #2536.

Added: trunk/apps/WoT/src/plugins/WoT/DuplicateScoreException.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/DuplicateScoreException.java                 
        (rev 0)
+++ trunk/apps/WoT/src/plugins/WoT/DuplicateScoreException.java 2008-08-31 
18:14:39 UTC (rev 22286)
@@ -0,0 +1,19 @@
+/**
+ * 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 DuplicateScoreException extends Exception {
+       
+       private static final long serialVersionUID = -1;
+
+       public DuplicateScoreException(String message) {
+               super(message);
+       }
+}

Modified: trunk/apps/WoT/src/plugins/WoT/Identity.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/Identity.java        2008-08-31 17:50:40 UTC 
(rev 22285)
+++ trunk/apps/WoT/src/plugins/WoT/Identity.java        2008-08-31 18:14:39 UTC 
(rev 22286)
@@ -56,13 +56,16 @@
         * @param db
         * @return
         * @throws NotInTrustTreeException 
+        * @throws DuplicateScoreException 
         * @throws  
         */
-       public Score getScore(OwnIdentity treeOwner, ObjectContainer db) throws 
NotInTrustTreeException {
+       public Score getScore(OwnIdentity treeOwner, ObjectContainer db) throws 
NotInTrustTreeException, DuplicateScoreException {

                ObjectSet<Score> score = db.queryByExample(new Score(treeOwner, 
this, 0, 0, 0));
-               if(score.hasNext()) return score.next();
-               else throw new 
NotInTrustTreeException(this.getRequestURI().toString()+" is not in that trust 
tree");
+               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()+" has "+score.size()+" 
scores in "+treeOwner.getNickName()+"'s trust tree"); 
+               else return score.next();
+                
        }

        public Trust getTrust(Identity truster, ObjectContainer db) throws 
InvalidParameterException {

Modified: trunk/apps/WoT/src/plugins/WoT/WebInterface.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WebInterface.java    2008-08-31 17:50:40 UTC 
(rev 22285)
+++ trunk/apps/WoT/src/plugins/WoT/WebInterface.java    2008-08-31 18:14:39 UTC 
(rev 22286)
@@ -140,15 +140,15 @@
                return pageNode.generate();
        }

-       public String makeKnownIdentitiesPage() throws Db4oIOException, 
DatabaseClosedException, InvalidParameterException, NotInTrustTreeException {
+       public String makeKnownIdentitiesPage() throws Db4oIOException, 
DatabaseClosedException, InvalidParameterException, NotInTrustTreeException, 
DuplicateScoreException {
                return makeKnownIdentitiesPage("");
        }

-       public String makeKnownIdentitiesPage(HTTPRequest request) throws 
Db4oIOException, DatabaseClosedException, InvalidParameterException, 
NotInTrustTreeException {
+       public String makeKnownIdentitiesPage(HTTPRequest request) throws 
Db4oIOException, DatabaseClosedException, InvalidParameterException, 
NotInTrustTreeException, DuplicateScoreException {
                return 
makeKnownIdentitiesPage(request.getPartAsString("ownerURI", 1024));
        }

-       public String makeKnownIdentitiesPage(String owner) throws 
Db4oIOException, DatabaseClosedException, InvalidParameterException, 
NotInTrustTreeException {
+       public String makeKnownIdentitiesPage(String owner) throws 
Db4oIOException, DatabaseClosedException, InvalidParameterException, 
NotInTrustTreeException, DuplicateScoreException {

                Identity treeOwner = null;


Modified: trunk/apps/WoT/src/plugins/WoT/WoT.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoT.java     2008-08-31 17:50:40 UTC (rev 
22285)
+++ trunk/apps/WoT/src/plugins/WoT/WoT.java     2008-08-31 18:14:39 UTC (rev 
22286)
@@ -51,8 +51,9 @@
         * @throws InvalidParameterException 
         * @throws DatabaseClosedException 
         * @throws Db4oIOException 
+        * @throws DuplicateScoreException 
         */
-       public void setTrust(Trust newTrust) throws Db4oIOException, 
DatabaseClosedException, InvalidParameterException {
+       public void setTrust(Trust newTrust) throws Db4oIOException, 
DatabaseClosedException, InvalidParameterException, DuplicateScoreException {

                boolean changedTrustValue = false;
                boolean changedComment = false;
@@ -102,8 +103,9 @@
         * @throws InvalidParameterException 
         * @throws DatabaseClosedException 
         * @throws Db4oIOException 
+        * @throws DuplicateScoreException 
         */
-       private void updateScore(OwnIdentity treeOwner, Identity identity) 
throws Db4oIOException, DatabaseClosedException, InvalidParameterException {
+       private void updateScore(OwnIdentity treeOwner, Identity identity) 
throws Db4oIOException, DatabaseClosedException, InvalidParameterException, 
DuplicateScoreException {

                Score score;


Modified: trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoTplugin.java       2008-08-31 17:50:40 UTC 
(rev 22285)
+++ trunk/apps/WoT/src/plugins/WoT/WoTplugin.java       2008-08-31 18:14:39 UTC 
(rev 22286)
@@ -180,7 +180,7 @@
                }
        }

-       private void restoreIdentity(String requestURI, String insertURI) 
throws InvalidParameterException, MalformedURLException {
+       private void restoreIdentity(String requestURI, String insertURI) 
throws InvalidParameterException, MalformedURLException, Db4oIOException, 
DatabaseClosedException, DuplicateScoreException {

                OwnIdentity id;

@@ -247,7 +247,7 @@
                fetcher.fetch(id);
        }

-       private void setTrust(HTTPRequest request) throws 
NumberFormatException, TransformerConfigurationException, 
FileNotFoundException, InvalidParameterException, UnknownIdentityException, 
ParserConfigurationException, TransformerException, IOException, 
InsertException  {
+       private void setTrust(HTTPRequest request) throws 
NumberFormatException, TransformerConfigurationException, 
FileNotFoundException, InvalidParameterException, UnknownIdentityException, 
ParserConfigurationException, TransformerException, IOException, 
InsertException, Db4oIOException, DatabaseClosedException, 
DuplicateScoreException  {

                setTrust(       request.getPartAsString("truster", 1024),
                                        request.getPartAsString("trustee", 
1024),
@@ -255,7 +255,7 @@
                                        request.getPartAsString("comment", 
1024));
        }

-       private void setTrust(String truster, String trustee, String value, 
String comment) throws InvalidParameterException, UnknownIdentityException, 
NumberFormatException, TransformerConfigurationException, 
FileNotFoundException, ParserConfigurationException, TransformerException, 
IOException, InsertException  {
+       private void setTrust(String truster, String trustee, String value, 
String comment) throws InvalidParameterException, UnknownIdentityException, 
NumberFormatException, TransformerConfigurationException, 
FileNotFoundException, ParserConfigurationException, TransformerException, 
IOException, InsertException, Db4oIOException, DatabaseClosedException, 
DuplicateScoreException  {

                OwnIdentity trusterId = wot.getOwnIdentityByURI(truster);
                Identity trusteeId = wot.getIdentityByURI(trustee);
@@ -263,7 +263,7 @@
                setTrust((OwnIdentity)trusterId, trusteeId, 
Integer.parseInt(value), comment);
 }      

-       private void setTrust(OwnIdentity truster, Identity trustee, int value, 
String comment) throws TransformerConfigurationException, 
FileNotFoundException, ParserConfigurationException, TransformerException, 
IOException, InsertException, Db4oIOException, DatabaseClosedException, 
InvalidParameterException {
+       private void setTrust(OwnIdentity truster, Identity trustee, int value, 
String comment) throws TransformerConfigurationException, 
FileNotFoundException, ParserConfigurationException, TransformerException, 
IOException, InsertException, Db4oIOException, DatabaseClosedException, 
InvalidParameterException, DuplicateScoreException {

                Trust trust = new Trust(truster, trustee, value, comment);
                wot.setTrust(trust);
@@ -293,7 +293,7 @@
                return identity;
        }

-       private OwnIdentity createIdentity(HTTPRequest request) throws 
TransformerConfigurationException, FileNotFoundException, 
InvalidParameterException, ParserConfigurationException, TransformerException, 
IOException, InsertException {
+       private OwnIdentity createIdentity(HTTPRequest request) throws 
TransformerConfigurationException, FileNotFoundException, 
InvalidParameterException, ParserConfigurationException, TransformerException, 
IOException, InsertException, Db4oIOException, DatabaseClosedException, 
DuplicateScoreException {

                return createIdentity(  
request.getPartAsString("insertURI",1024),
                                                                
request.getPartAsString("requestURI",1024),
@@ -302,13 +302,13 @@
                                                                "testing");     
        }

-       private OwnIdentity createIdentity(String nickName, String 
publishTrustList, String context) throws TransformerConfigurationException, 
FileNotFoundException, InvalidParameterException, ParserConfigurationException, 
TransformerException, IOException, InsertException {
+       private OwnIdentity createIdentity(String nickName, String 
publishTrustList, String context) throws TransformerConfigurationException, 
FileNotFoundException, InvalidParameterException, ParserConfigurationException, 
TransformerException, IOException, InsertException, Db4oIOException, 
DatabaseClosedException, DuplicateScoreException {

                FreenetURI[] keypair = client.generateKeyPair("WoT");
                return createIdentity(keypair[0].toString(), 
keypair[1].toString(), nickName, publishTrustList, context);
        }

-       private OwnIdentity createIdentity(String insertURI, String requestURI, 
String nickName, String publishTrustList, String context) throws 
InvalidParameterException, TransformerConfigurationException, 
FileNotFoundException, ParserConfigurationException, TransformerException, 
IOException, InsertException {
+       private OwnIdentity createIdentity(String insertURI, String requestURI, 
String nickName, String publishTrustList, String context) throws 
InvalidParameterException, TransformerConfigurationException, 
FileNotFoundException, ParserConfigurationException, TransformerException, 
IOException, InsertException, Db4oIOException, DatabaseClosedException, 
DuplicateScoreException {

                OwnIdentity identity = new OwnIdentity(insertURI, requestURI, 
new Date(0), new Date(), nickName, publishTrustList);
                identity.addContext(context, db);
@@ -426,7 +426,7 @@
                }
        }

-       private SimpleFieldSet handleCreateIdentity(SimpleFieldSet params) 
throws TransformerConfigurationException, FileNotFoundException, 
InvalidParameterException, ParserConfigurationException, TransformerException, 
IOException, InsertException  {
+       private SimpleFieldSet handleCreateIdentity(SimpleFieldSet params) 
throws TransformerConfigurationException, FileNotFoundException, 
InvalidParameterException, ParserConfigurationException, TransformerException, 
IOException, InsertException, Db4oIOException, DatabaseClosedException, 
DuplicateScoreException  {

                SimpleFieldSet sfs = new SimpleFieldSet(false);
                OwnIdentity identity;
@@ -449,7 +449,7 @@
                return sfs;
        }

-       private SimpleFieldSet handleSetTrust(SimpleFieldSet params) throws 
NumberFormatException, TransformerConfigurationException, 
FileNotFoundException, InvalidParameterException, ParserConfigurationException, 
TransformerException, IOException, InsertException, UnknownIdentityException  {
+       private SimpleFieldSet handleSetTrust(SimpleFieldSet params) throws 
NumberFormatException, TransformerConfigurationException, 
FileNotFoundException, InvalidParameterException, ParserConfigurationException, 
TransformerException, IOException, InsertException, UnknownIdentityException, 
Db4oIOException, DatabaseClosedException, DuplicateScoreException  {

                SimpleFieldSet sfs = new SimpleFieldSet(false);

@@ -474,7 +474,7 @@
                return sfs;
        }

-       private SimpleFieldSet handleGetIdentity(SimpleFieldSet params) throws 
InvalidParameterException, MalformedURLException, FetchException, 
UnknownIdentityException {
+       private SimpleFieldSet handleGetIdentity(SimpleFieldSet params) throws 
InvalidParameterException, MalformedURLException, FetchException, 
UnknownIdentityException, DuplicateScoreException {

                SimpleFieldSet sfs = new SimpleFieldSet(false);



Reply via email to