zeitgeist team mailing list archive
-
zeitgeist team
-
Mailing list archive
-
Message #04045
[Branch ~zeitgeist/zeitgeist/bluebird] Rev 239: Merge lp:~zeitgeist/zeitgeist/some-fixes branch with more fixes
Merge authors:
Seif Lotfy (seif)
Related merge proposals:
https://code.launchpad.net/~zeitgeist/zeitgeist/some-fixes/+merge/74927
proposed by: Seif Lotfy (seif)
review: Needs Fixing - Michal Hruby (mhr3)
https://code.launchpad.net/~zeitgeist/zeitgeist/bb_IN_OR/+merge/74683
proposed by: Seif Lotfy (seif)
------------------------------------------------------------
revno: 239 [merge]
committer: Michal Hruby <michal.mhr@xxxxxxxxx>
branch nick: bluebird
timestamp: Wed 2011-09-14 20:37:44 +0200
message:
Merge lp:~zeitgeist/zeitgeist/some-fixes branch with more fixes
modified:
extensions/blacklist.vala
src/datamodel.vala
src/engine.vala
--
lp:~zeitgeist/zeitgeist/bluebird
https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird
Your team Zeitgeist Framework Team is subscribed to branch lp:~zeitgeist/zeitgeist/bluebird.
To unsubscribe from this branch go to https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird/+edit-subscription
=== modified file 'extensions/blacklist.vala'
--- extensions/blacklist.vala 2011-09-05 13:09:08 +0000
+++ extensions/blacklist.vala 2011-09-14 18:37:44 +0000
@@ -98,10 +98,9 @@
public override void pre_insert_events (GenericArray<Event?> events,
BusName? sender)
{
- // FIXME: do template matching...
- // for event in events:
- // for tmpl in blacklist:
- // if event.matches_template(tmpl): event = null
+ for (int i=0; i < events.length; i++)
+ foreach (var tmpl in blacklist.get_values ())
+ if (events[i].matches_template (tmpl)) events[i] = null;
}
public void add_template (string template_id, Variant event_template)
=== modified file 'src/datamodel.vala'
--- src/datamodel.vala 2011-08-30 13:57:04 +0000
+++ src/datamodel.vala 2011-09-14 18:37:44 +0000
@@ -252,6 +252,37 @@
// must be immediately available to the user
ANY = 2 // The event subjects may or may not be available
}
+
+ private bool check_field_match (string property,
+ string template_property, bool is_symbol = false,
+ bool can_wildcard = false)
+ {
+ var matches = false;
+ var parsed = template_property;
+ var is_negated = Engine.parse_negation (ref parsed);
+
+ if (parsed == "")
+ {
+ return true;
+ }
+ else if (parsed == property)
+ {
+ matches = true;
+ }
+ // FIXME: this won't work!
+ else if (is_symbol &&
+ Symbol.get_all_parents (property).index (parsed) > -1)
+ {
+ matches = true;
+ }
+ else if (can_wildcard && Engine.parse_wildcard (ref parsed))
+ {
+ if (property.has_prefix (parsed)) matches = true;
+ }
+
+ debug ("Checking matches for %s", parsed);
+ return (is_negated) ? !matches : matches;
+ }
public class Event : Object
{
@@ -384,44 +415,7 @@
}
}
- 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)
- {
- return event.matches_template (this);
- }
+
public bool matches_template (Event template_event)
{
@@ -451,7 +445,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 +537,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,40 +555,6 @@
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)
- {
- return subject.matches_template (this);
- }
-
public bool matches_template (Subject template_subject)
{
/**
=== modified file 'src/engine.vala'
--- src/engine.vala 2011-09-08 17:49:17 +0000
+++ src/engine.vala 2011-09-14 18:37:44 +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,12 +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");
- return new string[0];
+ throw new EngineError.INVALID_ARGUMENT (
+ "No results found for the event_templates");
}
// Pick out the result_ids for the filtered results we would like to
@@ -406,7 +401,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];
@@ -545,7 +539,9 @@
return results;
}
else
+ {
throw new EngineError.DATABASE_ERROR ("Unsupported ResultType.");
+ }
}
public uint32[] insert_events (GenericArray<Event> events,
@@ -565,7 +561,7 @@
}
public uint32 insert_event (Event event,
- BusName? sender=null)
+ BusName? sender=null) throws EngineError
requires (event.id == 0)
requires (event.num_subjects () > 0)
{
@@ -596,14 +592,18 @@
if (event.interpretation == ZG.MOVE_EVENT
&& subject.uri == subject.current_uri)
{
- //FIXME: throw Error here
- return 0;
+ 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");
}
else if (event.interpretation != ZG.MOVE_EVENT
&& subject.uri != subject.current_uri)
{
- //FIXME: throw Error here
- return 0;
+ 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");
}
uris.add (subject.current_uri);
@@ -970,18 +970,13 @@
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)
+ public static bool parse_negation (ref string val)
{
if (!val.has_prefix ("!"))
return false;
@@ -1005,17 +1000,13 @@
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)
+ public static bool parse_wildcard (ref string val)
{
if (!val.has_suffix ("*"))
return false;
@@ -1044,16 +1035,38 @@
{
string _symbol = symbol;
bool negated = parse_negation (ref _symbol);
- List<string> symbols = Symbol.get_all_children (symbol);
- symbols.append (_symbol);
+ List<unowned string> symbols = Symbol.get_all_children (symbol);
+ symbols.prepend (_symbol);
WhereClause subwhere = new WhereClause(
WhereClause.Type.OR, negated);
- foreach (string uri in symbols)
+
+ /*
+ foreach (unowned string uri in symbols)
{
subwhere.add_match_condition (table_name,
lookup_table.get_id (uri));
}
+ */
+ if (symbols.length () == 1)
+ {
+ subwhere.add_match_condition (table_name,
+ lookup_table.get_id (_symbol));
+ }
+ else
+ {
+ var sb = new StringBuilder ();
+ foreach (string uri in symbols)
+ {
+ sb.append_printf ("%d,", lookup_table.get_id (uri));
+ }
+ sb.truncate (sb.len - 1);
+
+ string sql = "%s %s IN (%s)".printf(table_name,
+ (negated) ? "NOT": "", sb.str);
+ subwhere.add(sql);
+ }
+
return subwhere;
}