Author: batosai
Date: 2008-09-04 12:12:47 +0000 (Thu, 04 Sep 2008)
New Revision: 22405
Modified:
trunk/apps/WoT/src/plugins/WoT/Identity.java
trunk/apps/WoT/src/plugins/WoT/IdentityParser.java
trunk/apps/WoT/src/plugins/WoT/WoT.java
trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
trunk/apps/WoT/src/plugins/WoT/WotTestDrive.java
Log:
Repaired all that's been broken by recent refactor.
Still more to come...
Modified: trunk/apps/WoT/src/plugins/WoT/Identity.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/Identity.java 2008-09-04 11:53:47 UTC
(rev 22404)
+++ trunk/apps/WoT/src/plugins/WoT/Identity.java 2008-09-04 12:12:47 UTC
(rev 22405)
@@ -48,7 +48,7 @@
id = getRequestURI().getRoutingKey();
}
- public Identity (String requestURI, Date lastChange, String nickName,
String publishTrustList, String context) throws InvalidParameterException,
MalformedURLException {
+ public Identity (String requestURI, String nickName, String
publishTrustList, String context) throws InvalidParameterException,
MalformedURLException {
this(new FreenetURI(requestURI), nickName, publishTrustList,
context);
}
Modified: trunk/apps/WoT/src/plugins/WoT/IdentityParser.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/IdentityParser.java 2008-09-04 11:53:47 UTC
(rev 22404)
+++ trunk/apps/WoT/src/plugins/WoT/IdentityParser.java 2008-09-04 12:12:47 UTC
(rev 22405)
@@ -49,7 +49,7 @@
public void parse (InputStream is, FreenetURI uri) throws
InvalidParameterException, SAXException, IOException, UnknownIdentityException,
DuplicateIdentityException {
identity = Identity.getByURI(db,uri);
- if(!(identity instanceof OwnIdentity))
identity.setLastChange(new Date());
+ if(!(identity instanceof OwnIdentity)) identity.updated();
identity.setEdition(uri.getSuggestedEdition());
saxParser.parse(is, new IdentityHandler() );
@@ -88,17 +88,22 @@
Identity trustee;
try{
trustee = Identity.getByURI(db,
attrs.getValue("uri"));
+ int value =
Integer.parseInt(attrs.getValue("value"));
+ String comment =
attrs.getValue("comment");
+
+ wot.setTrust(new
Trust(identity, trustee, value, comment));
}
catch (UnknownIdentityException e) {
- trustee = new
Identity(attrs.getValue("uri"), new Date(0), "Not found yet...", "false");
- db.store(trustee);
- fetcher.fetch(trustee);
+
+ // TODO Don't create Identity
object before we succesfully fetched it !
+
+ /*
+ * trustee = new
Identity(attrs.getValue("uri"), new Date(0), "Not found yet...", "false");
+ * db.store(trustee);
+ * fetcher.fetch(trustee);
+ */
}
- int value =
Integer.parseInt(attrs.getValue("value"));
- String comment =
attrs.getValue("comment");
-
- wot.setTrust(new Trust(identity,
trustee, value, comment));
}
} catch (Exception e1) {
Logger.error(this, "Parsing error",e1);
Modified: trunk/apps/WoT/src/plugins/WoT/WoT.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoT.java 2008-09-04 11:53:47 UTC (rev
22404)
+++ trunk/apps/WoT/src/plugins/WoT/WoT.java 2008-09-04 12:12:47 UTC (rev
22405)
@@ -51,8 +51,10 @@
* @throws DatabaseClosedException
* @throws Db4oIOException
* @throws DuplicateScoreException
+ * @throws DuplicateTrustException
+ * @throws NotTrustedException
*/
- public void setTrust(Trust newTrust) throws Db4oIOException,
DatabaseClosedException, InvalidParameterException, DuplicateScoreException {
+ public void setTrust(Trust newTrust) throws Db4oIOException,
DatabaseClosedException, InvalidParameterException, DuplicateScoreException,
NotTrustedException, DuplicateTrustException {
boolean changedTrustValue = false;
boolean changedComment = false;
@@ -103,8 +105,10 @@
* @throws DatabaseClosedException
* @throws Db4oIOException
* @throws DuplicateScoreException
+ * @throws DuplicateTrustException
+ * @throws NotTrustedException
*/
- private void updateScore(OwnIdentity treeOwner, Identity identity)
throws Db4oIOException, DatabaseClosedException, InvalidParameterException,
DuplicateScoreException {
+ private void updateScore(OwnIdentity treeOwner, Identity identity)
throws Db4oIOException, DatabaseClosedException, InvalidParameterException,
DuplicateScoreException, NotTrustedException, DuplicateTrustException {
Score score;
@@ -118,7 +122,7 @@
if(identity == treeOwner) return;
// We get the trust given by the tree owner (because if it is
negative, the identity has no capacity)
- Trust trust = identity.getTrust(treeOwner, db);
+ Trust trust = identity.getReceivedTrust(treeOwner, db);
if(trust != null && trust.getValue() <= 0) hasNegativeTrust =
true;
// We get get all trust received by the identity
Modified: trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoTplugin.java 2008-09-04 11:53:47 UTC
(rev 22404)
+++ trunk/apps/WoT/src/plugins/WoT/WoTplugin.java 2008-09-04 12:12:47 UTC
(rev 22405)
@@ -88,8 +88,8 @@
seed = Identity.getByURI(db, seedURI);
} catch (UnknownIdentityException e) {
try {
- seed = new Identity(seedURI, new Date(0),
"Fetching seed identity...", "true");
- } catch (InvalidParameterException e1) {
+ seed = new Identity(seedURI, "Fetching seed
identity...", "true", "bootstrap");
+ } catch (Exception e1) {
Logger.error(this, "Seed identity error", e);
return;
}
@@ -179,7 +179,7 @@
return
web.makeEditIdentityPage(request.getPartAsString("id", 1024));
}
else if(page.equals("/restoreIdentity")) {
-
restoreIdentity(request.getPartAsString("requestURI", 1024),
request.getPartAsString("insertURI", 1024));
+ //
restoreIdentity(request.getPartAsString("requestURI", 1024),
request.getPartAsString("insertURI", 1024));
return web.makeOwnIdentitiesPage();
}
else {
@@ -190,7 +190,10 @@
return e.getLocalizedMessage();
}
}
+
+ // TODO This is OwnIdentity's job, move it there
+ /*
private void restoreIdentity(String requestURI, String insertURI)
throws InvalidParameterException, MalformedURLException, Db4oIOException,
DatabaseClosedException, DuplicateScoreException, DuplicateIdentityException {
OwnIdentity id;
@@ -257,8 +260,9 @@
fetcher.fetch(id);
}
-
- private void setTrust(HTTPRequest request) throws
NumberFormatException, TransformerConfigurationException,
FileNotFoundException, InvalidParameterException, UnknownIdentityException,
ParserConfigurationException, TransformerException, IOException,
InsertException, Db4oIOException, DatabaseClosedException,
DuplicateScoreException, DuplicateIdentityException {
+ */
+
+ private void setTrust(HTTPRequest request) throws
NumberFormatException, TransformerConfigurationException,
FileNotFoundException, InvalidParameterException, UnknownIdentityException,
ParserConfigurationException, TransformerException, IOException,
InsertException, Db4oIOException, DatabaseClosedException,
DuplicateScoreException, DuplicateIdentityException, NotTrustedException,
DuplicateTrustException {
setTrust( request.getPartAsString("truster", 1024),
request.getPartAsString("trustee",
1024),
@@ -266,7 +270,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, Db4oIOException, DatabaseClosedException,
DuplicateScoreException, DuplicateIdentityException {
+ private void setTrust(String truster, String trustee, String value,
String comment) throws InvalidParameterException, UnknownIdentityException,
NumberFormatException, TransformerConfigurationException,
FileNotFoundException, ParserConfigurationException, TransformerException,
IOException, InsertException, Db4oIOException, DatabaseClosedException,
DuplicateScoreException, DuplicateIdentityException, NotTrustedException,
DuplicateTrustException {
OwnIdentity trusterId = OwnIdentity.getByURI(db, truster);
Identity trusteeId = Identity.getByURI(db, trustee);
@@ -274,11 +278,11 @@
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, DuplicateScoreException {
+ private void setTrust(OwnIdentity truster, Identity trustee, int value,
String comment) throws TransformerConfigurationException,
FileNotFoundException, ParserConfigurationException, TransformerException,
IOException, InsertException, Db4oIOException, DatabaseClosedException,
InvalidParameterException, DuplicateScoreException, NotTrustedException,
DuplicateTrustException {
Trust trust = new Trust(truster, trustee, value, comment);
wot.setTrust(trust);
- truster.setLastChange(new Date());
+ truster.updated();
db.store(truster);
db.commit();
}
@@ -288,23 +292,26 @@
}
private Identity addIdentity(String requestURI) throws
MalformedURLException, InvalidParameterException, FetchException,
DuplicateIdentityException {
- Identity identity;
+ Identity identity = null;
try {
identity = Identity.getByURI(db, requestURI);
Logger.error(this, "Tried to manually add an identity
we already know, ignored.");
throw new InvalidParameterException("We already have
this identity");
}
catch (UnknownIdentityException e) {
+ // TODO Only add the identity after it is successfully
fetched
+ /*
identity = new Identity(requestURI, new
Date(0), "Not found yet...", "false");
db.store(identity);
db.commit();
Logger.debug(this, "Trying to fetch manually
added identity (" + identity.getRequestURI() + ")");
fetcher.fetch(identity);
+ */
}
return identity;
}
- private OwnIdentity createIdentity(HTTPRequest request) throws
TransformerConfigurationException, FileNotFoundException,
InvalidParameterException, ParserConfigurationException, TransformerException,
IOException, InsertException, Db4oIOException, DatabaseClosedException,
DuplicateScoreException {
+ private OwnIdentity createIdentity(HTTPRequest request) throws
TransformerConfigurationException, FileNotFoundException,
InvalidParameterException, ParserConfigurationException, TransformerException,
IOException, InsertException, Db4oIOException, DatabaseClosedException,
DuplicateScoreException, NotTrustedException, DuplicateTrustException {
return createIdentity(
request.getPartAsString("insertURI",1024),
request.getPartAsString("requestURI",1024),
@@ -313,15 +320,16 @@
"testing");
}
- private OwnIdentity createIdentity(String nickName, String
publishTrustList, String context) throws TransformerConfigurationException,
FileNotFoundException, InvalidParameterException, ParserConfigurationException,
TransformerException, IOException, InsertException, Db4oIOException,
DatabaseClosedException, DuplicateScoreException {
+ private OwnIdentity createIdentity(String nickName, String
publishTrustList, String context) throws TransformerConfigurationException,
FileNotFoundException, InvalidParameterException, ParserConfigurationException,
TransformerException, IOException, InsertException, Db4oIOException,
DatabaseClosedException, DuplicateScoreException, NotTrustedException,
DuplicateTrustException {
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, Db4oIOException, DatabaseClosedException,
DuplicateScoreException {
+ private OwnIdentity createIdentity(String insertURI, String requestURI,
String nickName, String publishTrustList, String context) throws
InvalidParameterException, TransformerConfigurationException,
FileNotFoundException, ParserConfigurationException, TransformerException,
IOException, InsertException, Db4oIOException, DatabaseClosedException,
DuplicateScoreException, NotTrustedException, DuplicateTrustException {
- OwnIdentity identity = new OwnIdentity(insertURI, requestURI,
new Date(0), new Date(), nickName, publishTrustList);
+ // TODO Add context in the creation form
+ OwnIdentity identity = new OwnIdentity(insertURI, requestURI,
nickName, publishTrustList, "testing");
identity.addContext(context, db);
db.store(identity);
@@ -342,7 +350,6 @@
private void addContext(String identity, String context) throws
InvalidParameterException, MalformedURLException, UnknownIdentityException,
DuplicateIdentityException {
Identity id = OwnIdentity.getByURI(db, identity);
id.addContext(context, db);
- id.setLastChange(new Date());
db.store(id);
Logger.debug(this, "Added context '" + context + "' to identity
'" + id.getNickName() + "'");
@@ -351,7 +358,6 @@
private void removeContext(String identity, String context) throws
InvalidParameterException, MalformedURLException, UnknownIdentityException,
DuplicateIdentityException {
Identity id = OwnIdentity.getByURI(db, identity);
id.removeContext(context, db);
- id.setLastChange(new Date());
db.store(id);
Logger.debug(this, "Removed context '" + context + "' from
identity '" + id.getNickName() + "'");
@@ -360,7 +366,6 @@
private void setProperty(String identity, String property, String
value) throws InvalidParameterException, MalformedURLException,
UnknownIdentityException, DuplicateIdentityException {
Identity id = OwnIdentity.getByURI(db, identity);
id.setProp(property, value, db);
- id.setLastChange(new Date());
db.store(id);
Logger.debug(this, "Added property '" + property + "=" + value
+ "' to identity '" + id.getNickName() + "'");
@@ -373,7 +378,6 @@
private void removeProperty(String identity, String property) throws
InvalidParameterException, MalformedURLException, UnknownIdentityException,
DuplicateIdentityException {
Identity id = OwnIdentity.getByURI(db, identity);
id.removeProp(property, db);
- id.setLastChange(new Date());
db.store(id);
Logger.debug(this, "Removed property '" + property + "' from
identity '" + id.getNickName() + "'");
@@ -435,7 +439,7 @@
}
}
- private SimpleFieldSet handleCreateIdentity(SimpleFieldSet params)
throws TransformerConfigurationException, FileNotFoundException,
InvalidParameterException, ParserConfigurationException, TransformerException,
IOException, InsertException, Db4oIOException, DatabaseClosedException,
DuplicateScoreException {
+ private SimpleFieldSet handleCreateIdentity(SimpleFieldSet params)
throws TransformerConfigurationException, FileNotFoundException,
InvalidParameterException, ParserConfigurationException, TransformerException,
IOException, InsertException, Db4oIOException, DatabaseClosedException,
DuplicateScoreException, NotTrustedException, DuplicateTrustException {
SimpleFieldSet sfs = new SimpleFieldSet(false);
OwnIdentity identity;
@@ -458,7 +462,7 @@
return sfs;
}
- private SimpleFieldSet handleSetTrust(SimpleFieldSet params) throws
NumberFormatException, TransformerConfigurationException,
FileNotFoundException, InvalidParameterException, ParserConfigurationException,
TransformerException, IOException, InsertException, UnknownIdentityException,
Db4oIOException, DatabaseClosedException, DuplicateScoreException,
DuplicateIdentityException {
+ private SimpleFieldSet handleSetTrust(SimpleFieldSet params) throws
NumberFormatException, TransformerConfigurationException,
FileNotFoundException, InvalidParameterException, ParserConfigurationException,
TransformerException, IOException, InsertException, UnknownIdentityException,
Db4oIOException, DatabaseClosedException, DuplicateScoreException,
DuplicateIdentityException, NotTrustedException, DuplicateTrustException {
SimpleFieldSet sfs = new SimpleFieldSet(false);
@@ -483,7 +487,7 @@
return sfs;
}
- private SimpleFieldSet handleGetIdentity(SimpleFieldSet params) throws
InvalidParameterException, MalformedURLException, FetchException,
UnknownIdentityException, DuplicateScoreException, DuplicateIdentityException {
+ private SimpleFieldSet handleGetIdentity(SimpleFieldSet params) throws
InvalidParameterException, MalformedURLException, FetchException,
UnknownIdentityException, DuplicateScoreException, DuplicateIdentityException,
DuplicateTrustException {
SimpleFieldSet sfs = new SimpleFieldSet(false);
@@ -494,9 +498,12 @@
OwnIdentity treeOwner = OwnIdentity.getByURI(db,
params.get("TreeOwner"));
Identity identity = Identity.getByURI(db,
params.get("Identity"));
- Trust trust = identity.getTrust(treeOwner, db);
- if(trust != null) sfs.putAppend("Trust",
String.valueOf(trust.getValue()));
- else sfs.putAppend("Trust", "null");
+ try {
+ Trust trust = identity.getReceivedTrust(treeOwner, db);
+ sfs.putAppend("Trust",
String.valueOf(trust.getValue()));
+ } catch (NotTrustedException e1) {
+ sfs.putAppend("Trust", "null");
+ }
Score score;
try {
@@ -508,7 +515,7 @@
sfs.putAppend("Rank", "null");
}
- Iterator<String> contexts = identity.getContextsIterator();
+ Iterator<String> contexts = identity.getContexts();
for(int i = 1 ; contexts.hasNext() ; i++)
sfs.putAppend("Context"+i, contexts.next());
return sfs;
Modified: trunk/apps/WoT/src/plugins/WoT/WotTestDrive.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WotTestDrive.java 2008-09-04 11:53:47 UTC
(rev 22404)
+++ trunk/apps/WoT/src/plugins/WoT/WotTestDrive.java 2008-09-04 12:12:47 UTC
(rev 22405)
@@ -174,7 +174,7 @@
OwnIdentity id = null;
FreenetURI[] keypair = client.generateKeyPair("WoT");
try {
- id = new OwnIdentity(keypair[0].toString(),
keypair[1].toString(), new Date(0), new Date(), nickName, "true");
+ id = new OwnIdentity(keypair[0].toString(),
keypair[1].toString(), nickName, "true", "testing");
id.addContext("Testing", db);
db.store(id);
@@ -183,7 +183,7 @@
db.store(score);
out.append("OK");
- } catch (InvalidParameterException e) {
+ } catch (Exception e) {
out.append("NOK\n");
out.append(e.getMessage());
}