Author: batosai
Date: 2008-08-16 14:28:10 +0000 (Sat, 16 Aug 2008)
New Revision: 21932

Modified:
   trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
Log:
Refactor in order to update LastChange date at each modification.

Modified: trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoTplugin.java       2008-08-16 08:49:52 UTC 
(rev 21931)
+++ trunk/apps/WoT/src/plugins/WoT/WoTplugin.java       2008-08-16 14:28:10 UTC 
(rev 21932)
@@ -151,13 +151,8 @@
        private void setTrust(OwnIdentity truster, Identity trustee, int value, 
String comment) throws TransformerConfigurationException, 
FileNotFoundException, ParserConfigurationException, TransformerException, 
IOException, InsertException, Db4oIOException, DatabaseClosedException, 
InvalidParameterException {

                wot.setTrust(new Trust(truster, trustee, value, comment));
-               
-               if(truster.getLastInsert() != null) { // Insert already in 
progress
-                       truster.setLastInsert(null);
-                       db.store(truster);
-                       new IdentityInserter(db, client).insert(truster);
-               }
-               
+               truster.setLastChange(new Date());
+               db.store(truster);
                db.commit();    
        }

@@ -211,7 +206,39 @@
                new IdentityInserter(db, client).insert(identity);      
                return identity;
        }
+       
+       private void addContext(String identity, String context) throws 
InvalidParameterException, MalformedURLException, UnknownIdentityException {
+               Identity id = wot.getOwnIdentityByURI(identity);
+               id.addContext(context, db);
+               id.setLastChange(new Date());
+               db.store(id);
+       }
+       
+       private void removeContext(String identity, String context) throws 
InvalidParameterException, MalformedURLException, UnknownIdentityException {
+               Identity id = wot.getOwnIdentityByURI(identity);
+               id.removeContext(context, db);
+               id.setLastChange(new Date());
+               db.store(id);
+       }

+       private void setProperty(String identity, String property, String 
value) throws InvalidParameterException, MalformedURLException, 
UnknownIdentityException {
+               Identity id = wot.getOwnIdentityByURI(identity);
+               id.setProp(property, value, db);
+               id.setLastChange(new Date());
+               db.store(id);
+       }
+       
+       private String getProperty(String identity, String property) throws 
InvalidParameterException, MalformedURLException, UnknownIdentityException {
+               return wot.getIdentityByURI(identity).getProp(property);
+       }
+       
+       private void removeProperty(String identity, String property) throws 
InvalidParameterException, MalformedURLException, UnknownIdentityException {
+               Identity id = wot.getOwnIdentityByURI(identity);
+               id.removeProp(property, db);
+               id.setLastChange(new Date());
+               db.store(id);
+       }
+
        @Override
        public String handleHTTPPut(HTTPRequest request) throws 
PluginHTTPException {
                return null;
@@ -418,8 +445,7 @@

                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);
+               addContext(params.get("Identity"), params.get("Context"));

                sfs.putAppend("Message", "ContextAdded");
                return sfs;
@@ -431,8 +457,7 @@

                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);
+               removeContext(params.get("Identity"), params.get("Context"));

                sfs.putAppend("Message", "ContextRemoved");
                return sfs;
@@ -444,8 +469,7 @@

                if(params.get("Identity") == null || params.get("Property") == 
null || params.get("Value") == null) throw new 
InvalidParameterException("Missing mandatory parameter");

-               Identity identity = 
wot.getOwnIdentityByURI(params.get("Identity"));
-               identity.setProp(params.get("Property"), params.get("Value"), 
db);
+               setProperty(params.get("Identity"), params.get("Property"), 
params.get("Value"));

                sfs.putAppend("Message", "PropertyAdded");
                return sfs;
@@ -457,23 +481,19 @@

                if(params.get("Identity") == null || params.get("Property") == 
null) throw new InvalidParameterException("Missing mandatory parameter");

-               Identity identity = 
wot.getIdentityByURI(params.get("Identity"));
-               
                sfs.putAppend("Message", "PropertyValue");
-               sfs.putAppend("Property", 
identity.getProp(params.get("Property")));
+               sfs.putAppend("Property", getProperty(params.get("Identity"), 
params.get("Property")));

                return sfs;
        }

-       
        private SimpleFieldSet handleRemoveProperty(SimpleFieldSet params) 
throws InvalidParameterException, MalformedURLException, 
UnknownIdentityException {

                SimpleFieldSet sfs = new SimpleFieldSet(false);

                if(params.get("Identity") == null || params.get("Property") == 
null) throw new InvalidParameterException("Missing mandatory parameter");

-               Identity identity = 
wot.getOwnIdentityByURI(params.get("Identity"));
-               identity.removeProp(params.get("Property"), db);
+               removeProperty(params.get("Identity"), params.get("Property"));

                sfs.putAppend("Message", "PropertyRemoved");
                return sfs;


Reply via email to