← Back to team overview

zeitgeist team mailing list archive

[Merge] lp:~zeitgeist/zeitgeist/some-fixes into lp:~zeitgeist/zeitgeist/bluebird

 

Seif Lotfy has proposed merging lp:~zeitgeist/zeitgeist/some-fixes into lp:~zeitgeist/zeitgeist/bluebird.

Requested reviews:
  Zeitgeist Framework Team (zeitgeist)

For more details, see:
https://code.launchpad.net/~zeitgeist/zeitgeist/some-fixes/+merge/74927
-- 
https://code.launchpad.net/~zeitgeist/zeitgeist/some-fixes/+merge/74927
Your team Zeitgeist Framework Team is requested to review the proposed merge of lp:~zeitgeist/zeitgeist/some-fixes into lp:~zeitgeist/zeitgeist/bluebird.
=== modified file 'src/datamodel.vala'
--- src/datamodel.vala	2011-08-30 13:57:04 +0000
+++ src/datamodel.vala	2011-09-11 22:24:23 +0000
@@ -252,6 +252,68 @@
                              // must be immediately available to the user
         ANY             = 2  // The event subjects may or may not be available
     }
+    
+    // Used by get_where_clause_from_event_templates
+    /**
+     * Check if the value starts with the negation operator. If it does,
+     * remove the operator from the value and return true. Otherwise,
+     * return false.
+     */
+    public bool parse_negation (ref string val)
+    {
+        if (!val.has_prefix ("!"))
+            return false;
+        val = val.substring (1); // FIXME: fix for unicode
+        return true;
+    }
+    
+    // Used by get_where_clause_from_event_templates
+    /**
+     * Check if the value ends with the wildcard character. If it does,
+     * remove the wildcard character from the value and return true.
+     * Otherwise, return false.
+     */
+    public bool parse_wildcard (ref string val)
+    {
+        if (!val.has_suffix ("*"))
+            return false;
+        unowned uint8[] val_data = val.data;
+        val_data[val_data.length-1] = '\0';
+        return true;
+    }
+    
+    public bool check_field_match (string property,
+            string template_property, bool is_symbol = false,
+            bool can_wildcard = false)
+    {
+        var matches = false;
+        var temp_string = template_property;
+        var is_negated = parse_negation(ref temp_string);
+        var temp_property = template_property;
+        if (is_negated)
+            temp_property  = temp_property[1:template_property.length];
+
+        if (temp_property  == "") {
+            return true;
+        }
+        else if (temp_property  == property)
+        {
+            matches = true;
+        }
+        else if (is_symbol &&
+            Symbol.get_all_parents (property).index (temp_property ) > -1)
+        {
+            matches = true;
+        }
+        else if (can_wildcard && parse_wildcard(ref temp_string))
+        {
+            if (property.index_of (
+                    temp_property [0:temp_property.length-1]) > -1)
+                matches = true;
+        }
+        debug ("Checking matches for %s", temp_property);
+        return (is_negated) ? !matches : matches;
+    }
 
     public class Event : Object
     {
@@ -384,42 +446,14 @@
             }
        }
 
-        private bool check_field_match (string event_property,
-            string event_template_property, bool is_symbol = false,
-            bool can_wildcard = false)
-        {
-            var matches = false;
-
-            // FIXME: use common code!
-            var is_negated = (event_template_property[0] == '!');
-            var template_property = event_template_property;
-            if (is_negated)
-                template_property = template_property[1:template_property.length];
-
-            if (template_property == "") {
-                return true;
-            }
-            else if (template_property == event_property)
-            {
-                matches = true;
-            }
-            else if (is_symbol &&
-                Symbol.get_all_parents (event_property).index (template_property) > -1)
-            {
-                matches = true;
-            }
-            else if (can_wildcard && template_property.has_suffix("*")) // FIXME: use common code?
-            {
-                if (event_property.index_of (
-                        template_property[0:template_property.length-1]) > -1)
-                    matches = true;
-            }
-            debug ("Checking matches for %s", event_template_property);
-            return (is_negated) ? !matches : matches;
-        }
+        
 
         public bool matches_event (Event event)
         {
+            /**
+            Interpret *this* as the template an match *event* against it.
+            This method is the dual method of :meth:`matches_template`
+            */
             return event.matches_template (this);
         }
 
@@ -451,7 +485,6 @@
             if (!check_field_match (this.origin, template_event.origin, false, true))
                 return false;
 
-            //FIXME: Check for subject matching
             if (template_event.subjects.length == 0)
                 return true;
 
@@ -544,7 +577,7 @@
             if (subject_props >= 8)
                 current_uri = iter.next_value().get_string ();
             else
-                current_uri = ""; // FIXME: uri?
+                current_uri = uri;
         }
 
         public Variant to_variant ()
@@ -562,37 +595,12 @@
             return vb.end ();
         }
 
-        // FIXME: Why is this duplicated??? delete, delete, delete.
-        private bool check_field_match (string subj_property, string subj_template_property,
-             bool is_symbol = false, bool can_wildcard = false)
-        {
-            var matches = false;
-            var is_negated = (subj_template_property[0] == '!');
-
-            var template_property = subj_template_property;
-            if (is_negated)
-                template_property = template_property[1:template_property.length];
-
-            if (template_property == "")
-                return true;
-            else if (template_property == subj_property)
-                matches = true;
-            else if (is_symbol &&
-                Symbol.get_all_parents (subj_property).index (template_property) > -1)
-                matches = true;
-            else if (can_wildcard && template_property.has_suffix("*"))
-                if (subj_property.index_of(template_property[0:template_property.length-1]) > -1)
-                    matches = true;
-            if (is_negated){
-                matches = !matches;
-            }
-            debug("Checking matches for %s", subj_template_property);
-            return matches;
-        }
-
-        // FIXME: what's the point of this function?
         public bool matches_subject (Subject subject)
         {
+            /**
+            Interpret *this* as the template an match *subject* against it.
+            This method is the dual method of :meth:`matches_template`
+            */
             return subject.matches_template (this);
         }
 

=== modified file 'src/engine.vala'
--- src/engine.vala	2011-09-08 17:49:17 +0000
+++ src/engine.vala	2011-09-11 22:24:23 +0000
@@ -128,8 +128,8 @@
         }
         if (rc != Sqlite.DONE)
         {
-            warning ("Error: %d, %s\n", rc, db.errmsg ());
-            // FIXME: throw some error??
+            throw new EngineError.DATABASE_ERROR("Error: %d, %s\n", 
+                rc, db.errmsg ());
         }
 
         var results = new GenericArray<Event?> ();
@@ -195,8 +195,6 @@
         //if (!where.may_have_results ())
         //    return new uint32[0];
 
-        // FIXME: IDs: SELECT DISTINCT / events: SELECT
-        // Is the former faster or can we just do the unique'ing on our side?
         string sql;
         if (distinct)
             sql = "SELECT DISTINCT id FROM event_view ";
@@ -377,7 +375,6 @@
         * Only URIs for subjects matching the indicated `result_event_templates`
         * and `result_storage_state` are returned.
         */
-        //FIXME: implement calculation
         if (result_type == ResultType.MOST_RECENT_EVENTS ||
             result_type == ResultType.LEAST_RECENT_EVENTS)
         {
@@ -388,11 +385,10 @@
             uint32[] ids = find_event_ids (time_range, event_templates,
                 storage_state, 0, ResultType.LEAST_RECENT_EVENTS);
 
-            // FIXME: If no results for the event_templates is found raise error
             if (event_templates.length > 0 && ids.length == 0)
             {
-                //throw new EngineError.INVALID_ARGUMENT(
-                //    "No results found for the event_templates");
+                throw new EngineError.INVALID_ARGUMENT(
+                    "No results found for the event_templates");
                 return new string[0];
             }
 
@@ -406,7 +402,6 @@
 
             // From here we create several graphs with the maximum depth of 2
             // and push all the nodes and vertices (events) in one pot together
-            // FIXME: the depth should be adaptable
 
             uint32[] pot = new uint32[ids.length + result_ids.length];
 
@@ -427,7 +422,6 @@
 
             database.assert_query_success(rc, "SQL error");
 
-            // FIXME: fix this ugly code
             var temp_related_uris = new GenericArray<RelatedUri?>();
 
             while ((rc = stmt.step()) == Sqlite.ROW)
@@ -596,13 +590,18 @@
                 if (event.interpretation == ZG.MOVE_EVENT
                     && subject.uri == subject.current_uri)
                 {
-                    //FIXME: throw Error here
+                    throw new EngineError.INVALID_ARGUMENT("Illegal event: unless
+                        event.interpretation is 'MOVE_EVENT' then subject.uri
+                        and subject.current_uri have to be the same");
                     return 0;
                 }
                 else if (event.interpretation != ZG.MOVE_EVENT
                     && subject.uri != subject.current_uri)
                 {
-                    //FIXME: throw Error here
+                    throw new EngineError.INVALID_ARGUMENT("Redundant event: 
+                        event.interpretation indicates the uri has been moved 
+                        yet the subject.uri and subject.current_uri are 
+                        identical");
                     return 0;
                 }
 
@@ -970,25 +969,6 @@
             return where;
     }
 
-    // FIXME: remove this
-    private static string[] NEGATION_SUPPORTED = {
-        "actor", "current_uri", "interpretation", "manifestation",
-        "mimetype", "origin", "uri" };
-
-    // Used by get_where_clause_from_event_templates
-    /**
-     * Check if the value starts with the negation operator. If it does,
-     * remove the operator from the value and return true. Otherwise,
-     * return false.
-     */
-    protected bool parse_negation (ref string val)
-    {
-        if (!val.has_prefix ("!"))
-            return false;
-        val = val.substring (1); // FIXME: fix for unicode
-        return true;
-    }
-
     // Used by get_where_clause_from_event_templates
     /**
      * If the value starts with the negation operator, throw an
@@ -1005,25 +985,6 @@
         throw new EngineError.INVALID_ARGUMENT (error_message);
     }
 
-    // FIXME: remove this
-    private static string[] WILDCARDS_SUPPORTED = {
-        "actor", "current_uri", "mimetype", "origin", "uri" };
-
-    // Used by get_where_clause_from_event_templates
-    /**
-     * Check if the value ends with the wildcard character. If it does,
-     * remove the wildcard character from the value and return true.
-     * Otherwise, return false.
-     */
-    protected bool parse_wildcard (ref string val)
-    {
-        if (!val.has_suffix ("*"))
-            return false;
-        unowned uint8[] val_data = val.data;
-        val_data[val_data.length-1] = '\0';
-        return true;
-    }
-
     // Used by get_where_clause_from_event_templates
     /**
      * If the value ends with the wildcard character, throw an error.
@@ -1049,10 +1010,20 @@
 
         WhereClause subwhere = new WhereClause(
             WhereClause.Type.OR, negated);
-        foreach (string uri in symbols)
+
+        if (symbols.length() == 1)
         {
             subwhere.add_match_condition (table_name,
-                lookup_table.get_id (uri));
+                lookup_table.get_id (_symbol));
+        }
+        else
+        {
+            string in_sql = "";
+            foreach (string uri in symbols)
+                in_sql += "%i,".printf(lookup_table.get_id (uri));
+            string sql = "%s %s IN (%s)".printf(table_name,
+                (negated) ? "NOT": "", in_sql[0:-1]);
+            subwhere.add(sql);
         }
         return subwhere;
     }


Follow ups