Author: batosai
Date: 2008-08-14 22:06:56 +0000 (Thu, 14 Aug 2008)
New Revision: 21878
Modified:
trunk/apps/WoT/src/plugins/WoT/Identity.java
trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
Log:
Added FCP messages to handle contexts.
Modified: trunk/apps/WoT/src/plugins/WoT/Identity.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/Identity.java 2008-08-14 21:48:20 UTC
(rev 21877)
+++ trunk/apps/WoT/src/plugins/WoT/Identity.java 2008-08-14 22:06:56 UTC
(rev 21878)
@@ -9,6 +9,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
+import java.util.Iterator;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
@@ -223,8 +224,9 @@
* @throws InvalidParameterException if the context is blank
*/
public void addContext(String context, ObjectContainer db) throws
InvalidParameterException {
- if(context.length() == 0) throw new
InvalidParameterException("Blank context");
- if(!contexts.contains(context)) contexts.add(context);
+ String newContext = context.trim();
+ if(newContext.length() == 0) throw new
InvalidParameterException("Blank context");
+ if(!contexts.contains(newContext)) contexts.add(newContext);
db.store(contexts);
}
@@ -241,9 +243,15 @@
* Removes a context from this identity
* @param context
* @param db
+ * @throws InvalidParameterException
*/
- public void removeContext(String context, ObjectContainer db) {
+ public void removeContext(String context, ObjectContainer db) throws
InvalidParameterException {
+ if(contexts.size() == 1) throw new
InvalidParameterException("Only one context left");
contexts.remove(context);
db.store(contexts);
}
+
+ public Iterator<String> getContexts() {
+ return contexts.iterator();
+ }
}
Modified: trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoTplugin.java 2008-08-14 21:48:20 UTC
(rev 21877)
+++ trunk/apps/WoT/src/plugins/WoT/WoTplugin.java 2008-08-14 22:06:56 UTC
(rev 21878)
@@ -10,6 +10,7 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Date;
+import java.util.Iterator;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerConfigurationException;
@@ -246,6 +247,12 @@
else if(params.get("Message").equals("GetTrustees")) {
replysender.send(handleGetTrustees(params),
data);
}
+ else if(params.get("Message").equals("AddContext")) {
+ replysender.send(handleAddContext(params),
data);
+ }
+ else if(params.get("Message").equals("RemoveContext")) {
+ replysender.send(handleRemoveContext(params),
data);
+ }
else {
throw new Exception("Unknown message (" +
params.get("Message") + ")");
}
@@ -314,13 +321,9 @@
OwnIdentity treeOwner =
wot.getOwnIdentityByURI(params.get("TreeOwner"));
Identity identity =
wot.getIdentityByURI(params.get("Identity"));
- try {
- Trust trust = identity.getTrust(treeOwner, db);
- sfs.putAppend("Trust",
String.valueOf(trust.getValue()));
- }
- catch(InvalidParameterException e) {
- sfs.putAppend("Trust", "null");
- }
+ Trust trust = identity.getTrust(treeOwner, db);
+ if(trust != null) sfs.putAppend("Trust",
String.valueOf(trust.getValue()));
+ else sfs.putAppend("Trust", "null");
Score score;
try {
@@ -332,6 +335,9 @@
sfs.putAppend("Rank", "null");
}
+ Iterator<String> contexts = identity.getContexts();
+ for(int i = 1 ; contexts.hasNext() ; i++)
sfs.putAppend("Context"+i, contexts.next());
+
return sfs;
}
@@ -342,6 +348,8 @@
if(params.get("TreeOwner") == null || params.get("Select") ==
null) throw new InvalidParameterException("Missing mandatory parameter");
sfs.putAppend("Message", "Identities");
+
+ // TODO Add context selection
ObjectSet<Score> result =
wot.getIdentitiesByScore(params.get("TreeOwner"), params.get("Select").trim());
for(int i = 1 ; result.hasNext() ; i++)
@@ -360,6 +368,8 @@
ObjectSet<Trust> result =
wot.getTrusters(params.get("Identity"));
+ // TODO Add context selection
+
for(int i = 1 ; result.hasNext() ; i++) {
Trust trust = result.next();
sfs.putAppend("Identity"+i,
trust.getTruster().getRequestURI().toString());
@@ -379,6 +389,8 @@
ObjectSet<Trust> result =
wot.getTrustees(params.get("Identity"));
+ // TODO Add context selection
+
for(int i = 1 ; result.hasNext() ; i++) {
Trust trust = result.next();
sfs.putAppend("Identity"+i,
trust.getTrustee().getRequestURI().toString());
@@ -388,6 +400,32 @@
return sfs;
}
+ private SimpleFieldSet handleAddContext(SimpleFieldSet params) throws
InvalidParameterException, MalformedURLException, UnknownIdentityException {
+
+ SimpleFieldSet sfs = new SimpleFieldSet(false);
+
+ if(params.get("Identity") == null || params.get("Context") ==
null) throw new InvalidParameterException("Missing mandatory parameter");
+
+ Identity identity =
wot.getOwnIdentityByURI(params.get("Identity"));
+ identity.addContext(params.get("Context"), db);
+
+ sfs.putAppend("Message", "ContextAdded");
+ return sfs;
+ }
+
+ private SimpleFieldSet handleRemoveContext(SimpleFieldSet params)
throws InvalidParameterException, MalformedURLException,
UnknownIdentityException {
+
+ SimpleFieldSet sfs = new SimpleFieldSet(false);
+
+ if(params.get("Identity") == null || params.get("Context") ==
null) throw new InvalidParameterException("Missing mandatory parameter");
+
+ Identity identity =
wot.getOwnIdentityByURI(params.get("Identity"));
+ identity.removeContext(params.get("Context"), db);
+
+ sfs.putAppend("Message", "ContextRemoved");
+ return sfs;
+ }
+
private SimpleFieldSet errorMessageFCP (Exception e) {
SimpleFieldSet sfs = new SimpleFieldSet(false);