Merge lp:~zeitgeist/zeitgeist/some-fixes into lp:~zeitgeist/zeitgeist/bluebird
- some-fixes
- Merge into bluebird
Proposed by
Seif Lotfy
Status: | Merged |
---|---|
Merged at revision: | 239 |
Proposed branch: | lp:~zeitgeist/zeitgeist/some-fixes |
Merge into: | lp:~zeitgeist/zeitgeist/bluebird |
Diff against target: |
364 lines (+99/-121) 3 files modified
extensions/blacklist.vala (+3/-4) src/datamodel.vala (+72/-64) src/engine.vala (+24/-53) |
To merge this branch: | bzr merge lp:~zeitgeist/zeitgeist/some-fixes |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michal Hruby (community) | Needs Fixing | ||
Review via email: mp+74927@code.launchpad.net |
Commit message
* moved parse_negation and parse_wildcard into the datamodel for unversal usage (not sure this is the right thing to do though)
* reduced duplication of check_field_match in datamodel by moving it outside the EVent and Subject classes into Zeitgeist namespace
* throw Errors if MOVE_EVENT invalid
* throw Error in find_related_uris
* remove fixed FIXMEs
Description of the change
To post a comment you must log in.
- 241. By Seif Lotfy
-
fixed missing space and added a FIXME
Revision history for this message
Michal Hruby (mhr3) wrote : | # |
Oh and also [19]: it doesn't need any fix, it'll be working fine.
- 242. By Seif Lotfy
-
remove fixme
- 243. By Seif Lotfy
-
make bool check_field_match, parse_wildcard and parse_negation private
- 244. By Seif Lotfy
-
added whitespaces
- 245. By Seif Lotfy
-
implemented the pre_insert_events logic
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'extensions/blacklist.vala' |
2 | --- extensions/blacklist.vala 2011-09-05 13:09:08 +0000 |
3 | +++ extensions/blacklist.vala 2011-09-13 15:48:12 +0000 |
4 | @@ -98,10 +98,9 @@ |
5 | public override void pre_insert_events (GenericArray<Event?> events, |
6 | BusName? sender) |
7 | { |
8 | - // FIXME: do template matching... |
9 | - // for event in events: |
10 | - // for tmpl in blacklist: |
11 | - // if event.matches_template(tmpl): event = null |
12 | + for (int i=0; i < events.length; i++) |
13 | + foreach (var tmpl in blacklist.get_values()) |
14 | + if (events[i].matches_template(tmpl)) events[i] = null; |
15 | } |
16 | |
17 | public void add_template (string template_id, Variant event_template) |
18 | |
19 | === modified file 'src/datamodel.vala' |
20 | --- src/datamodel.vala 2011-08-30 13:57:04 +0000 |
21 | +++ src/datamodel.vala 2011-09-13 15:48:12 +0000 |
22 | @@ -252,6 +252,68 @@ |
23 | // must be immediately available to the user |
24 | ANY = 2 // The event subjects may or may not be available |
25 | } |
26 | + |
27 | + // Used by get_where_clause_from_event_templates |
28 | + /** |
29 | + * Check if the value starts with the negation operator. If it does, |
30 | + * remove the operator from the value and return true. Otherwise, |
31 | + * return false. |
32 | + */ |
33 | + private bool parse_negation (ref string val) |
34 | + { |
35 | + if (!val.has_prefix ("!")) |
36 | + return false; |
37 | + val = val.substring (1); |
38 | + return true; |
39 | + } |
40 | + |
41 | + // Used by get_where_clause_from_event_templates |
42 | + /** |
43 | + * Check if the value ends with the wildcard character. If it does, |
44 | + * remove the wildcard character from the value and return true. |
45 | + * Otherwise, return false. |
46 | + */ |
47 | + private bool parse_wildcard (ref string val) |
48 | + { |
49 | + if (!val.has_suffix ("*")) |
50 | + return false; |
51 | + unowned uint8[] val_data = val.data; |
52 | + val_data[val_data.length-1] = '\0'; |
53 | + return true; |
54 | + } |
55 | + |
56 | + private bool check_field_match (string property, |
57 | + string template_property, bool is_symbol = false, |
58 | + bool can_wildcard = false) |
59 | + { |
60 | + var matches = false; |
61 | + var temp_string = template_property; |
62 | + var is_negated = parse_negation(ref temp_string); |
63 | + var temp_property = template_property; |
64 | + if (is_negated) |
65 | + temp_property = temp_property[1:template_property.length]; |
66 | + |
67 | + if (temp_property == "") { |
68 | + return true; |
69 | + } |
70 | + else if (temp_property == property) |
71 | + { |
72 | + matches = true; |
73 | + } |
74 | + else if (is_symbol && |
75 | + Symbol.get_all_parents (property).index (temp_property ) > -1) |
76 | + { |
77 | + matches = true; |
78 | + } |
79 | + else if (can_wildcard && parse_wildcard(ref temp_string)) |
80 | + { |
81 | + if (property.index_of ( |
82 | + temp_property [0:temp_property.length-1]) > -1) |
83 | + matches = true; |
84 | + } |
85 | + debug ("Checking matches for %s", temp_property); |
86 | + return (is_negated) ? !matches : matches; |
87 | + } |
88 | |
89 | public class Event : Object |
90 | { |
91 | @@ -384,42 +446,14 @@ |
92 | } |
93 | } |
94 | |
95 | - private bool check_field_match (string event_property, |
96 | - string event_template_property, bool is_symbol = false, |
97 | - bool can_wildcard = false) |
98 | - { |
99 | - var matches = false; |
100 | - |
101 | - // FIXME: use common code! |
102 | - var is_negated = (event_template_property[0] == '!'); |
103 | - var template_property = event_template_property; |
104 | - if (is_negated) |
105 | - template_property = template_property[1:template_property.length]; |
106 | - |
107 | - if (template_property == "") { |
108 | - return true; |
109 | - } |
110 | - else if (template_property == event_property) |
111 | - { |
112 | - matches = true; |
113 | - } |
114 | - else if (is_symbol && |
115 | - Symbol.get_all_parents (event_property).index (template_property) > -1) |
116 | - { |
117 | - matches = true; |
118 | - } |
119 | - else if (can_wildcard && template_property.has_suffix("*")) // FIXME: use common code? |
120 | - { |
121 | - if (event_property.index_of ( |
122 | - template_property[0:template_property.length-1]) > -1) |
123 | - matches = true; |
124 | - } |
125 | - debug ("Checking matches for %s", event_template_property); |
126 | - return (is_negated) ? !matches : matches; |
127 | - } |
128 | + |
129 | |
130 | public bool matches_event (Event event) |
131 | { |
132 | + /** |
133 | + Interpret *this* as the template an match *event* against it. |
134 | + This method is the dual method of :meth:`matches_template` |
135 | + */ |
136 | return event.matches_template (this); |
137 | } |
138 | |
139 | @@ -451,7 +485,6 @@ |
140 | if (!check_field_match (this.origin, template_event.origin, false, true)) |
141 | return false; |
142 | |
143 | - //FIXME: Check for subject matching |
144 | if (template_event.subjects.length == 0) |
145 | return true; |
146 | |
147 | @@ -544,7 +577,7 @@ |
148 | if (subject_props >= 8) |
149 | current_uri = iter.next_value().get_string (); |
150 | else |
151 | - current_uri = ""; // FIXME: uri? |
152 | + current_uri = uri; |
153 | } |
154 | |
155 | public Variant to_variant () |
156 | @@ -562,37 +595,12 @@ |
157 | return vb.end (); |
158 | } |
159 | |
160 | - // FIXME: Why is this duplicated??? delete, delete, delete. |
161 | - private bool check_field_match (string subj_property, string subj_template_property, |
162 | - bool is_symbol = false, bool can_wildcard = false) |
163 | - { |
164 | - var matches = false; |
165 | - var is_negated = (subj_template_property[0] == '!'); |
166 | - |
167 | - var template_property = subj_template_property; |
168 | - if (is_negated) |
169 | - template_property = template_property[1:template_property.length]; |
170 | - |
171 | - if (template_property == "") |
172 | - return true; |
173 | - else if (template_property == subj_property) |
174 | - matches = true; |
175 | - else if (is_symbol && |
176 | - Symbol.get_all_parents (subj_property).index (template_property) > -1) |
177 | - matches = true; |
178 | - else if (can_wildcard && template_property.has_suffix("*")) |
179 | - if (subj_property.index_of(template_property[0:template_property.length-1]) > -1) |
180 | - matches = true; |
181 | - if (is_negated){ |
182 | - matches = !matches; |
183 | - } |
184 | - debug("Checking matches for %s", subj_template_property); |
185 | - return matches; |
186 | - } |
187 | - |
188 | - // FIXME: what's the point of this function? |
189 | public bool matches_subject (Subject subject) |
190 | { |
191 | + /** |
192 | + Interpret *this* as the template an match *subject* against it. |
193 | + This method is the dual method of :meth:`matches_template` |
194 | + */ |
195 | return subject.matches_template (this); |
196 | } |
197 | |
198 | |
199 | === modified file 'src/engine.vala' |
200 | --- src/engine.vala 2011-09-08 17:49:17 +0000 |
201 | +++ src/engine.vala 2011-09-13 15:48:12 +0000 |
202 | @@ -128,8 +128,8 @@ |
203 | } |
204 | if (rc != Sqlite.DONE) |
205 | { |
206 | - warning ("Error: %d, %s\n", rc, db.errmsg ()); |
207 | - // FIXME: throw some error?? |
208 | + throw new EngineError.DATABASE_ERROR ("Error: %d, %s\n", |
209 | + rc, db.errmsg ()); |
210 | } |
211 | |
212 | var results = new GenericArray<Event?> (); |
213 | @@ -195,8 +195,6 @@ |
214 | //if (!where.may_have_results ()) |
215 | // return new uint32[0]; |
216 | |
217 | - // FIXME: IDs: SELECT DISTINCT / events: SELECT |
218 | - // Is the former faster or can we just do the unique'ing on our side? |
219 | string sql; |
220 | if (distinct) |
221 | sql = "SELECT DISTINCT id FROM event_view "; |
222 | @@ -377,7 +375,6 @@ |
223 | * Only URIs for subjects matching the indicated `result_event_templates` |
224 | * and `result_storage_state` are returned. |
225 | */ |
226 | - //FIXME: implement calculation |
227 | if (result_type == ResultType.MOST_RECENT_EVENTS || |
228 | result_type == ResultType.LEAST_RECENT_EVENTS) |
229 | { |
230 | @@ -388,11 +385,10 @@ |
231 | uint32[] ids = find_event_ids (time_range, event_templates, |
232 | storage_state, 0, ResultType.LEAST_RECENT_EVENTS); |
233 | |
234 | - // FIXME: If no results for the event_templates is found raise error |
235 | if (event_templates.length > 0 && ids.length == 0) |
236 | { |
237 | - //throw new EngineError.INVALID_ARGUMENT( |
238 | - // "No results found for the event_templates"); |
239 | + throw new EngineError.INVALID_ARGUMENT ( |
240 | + "No results found for the event_templates"); |
241 | return new string[0]; |
242 | } |
243 | |
244 | @@ -406,7 +402,6 @@ |
245 | |
246 | // From here we create several graphs with the maximum depth of 2 |
247 | // and push all the nodes and vertices (events) in one pot together |
248 | - // FIXME: the depth should be adaptable |
249 | |
250 | uint32[] pot = new uint32[ids.length + result_ids.length]; |
251 | |
252 | @@ -596,13 +591,18 @@ |
253 | if (event.interpretation == ZG.MOVE_EVENT |
254 | && subject.uri == subject.current_uri) |
255 | { |
256 | - //FIXME: throw Error here |
257 | + throw new EngineError.INVALID_ARGUMENT ("Illegal event: unless |
258 | + event.interpretation is 'MOVE_EVENT' then subject.uri |
259 | + and subject.current_uri have to be the same"); |
260 | return 0; |
261 | } |
262 | else if (event.interpretation != ZG.MOVE_EVENT |
263 | && subject.uri != subject.current_uri) |
264 | { |
265 | - //FIXME: throw Error here |
266 | + throw new EngineError.INVALID_ARGUMENT ("Redundant event: |
267 | + event.interpretation indicates the uri has been moved |
268 | + yet the subject.uri and subject.current_uri are |
269 | + identical"); |
270 | return 0; |
271 | } |
272 | |
273 | @@ -634,7 +634,7 @@ |
274 | |
275 | // FIXME: Should we add something just like TableLookup but with LRU |
276 | // for those? Or is embedding the query faster? Needs testing! |
277 | - |
278 | + |
279 | int rc; |
280 | unowned Sqlite.Statement insert_stmt = database.event_insertion_stmt; |
281 | |
282 | @@ -750,7 +750,6 @@ |
283 | */ |
284 | public void close () |
285 | { |
286 | - // FIXME: unload extensions |
287 | database.close(); |
288 | } |
289 | |
290 | @@ -970,25 +969,6 @@ |
291 | return where; |
292 | } |
293 | |
294 | - // FIXME: remove this |
295 | - private static string[] NEGATION_SUPPORTED = { |
296 | - "actor", "current_uri", "interpretation", "manifestation", |
297 | - "mimetype", "origin", "uri" }; |
298 | - |
299 | - // Used by get_where_clause_from_event_templates |
300 | - /** |
301 | - * Check if the value starts with the negation operator. If it does, |
302 | - * remove the operator from the value and return true. Otherwise, |
303 | - * return false. |
304 | - */ |
305 | - protected bool parse_negation (ref string val) |
306 | - { |
307 | - if (!val.has_prefix ("!")) |
308 | - return false; |
309 | - val = val.substring (1); // FIXME: fix for unicode |
310 | - return true; |
311 | - } |
312 | - |
313 | // Used by get_where_clause_from_event_templates |
314 | /** |
315 | * If the value starts with the negation operator, throw an |
316 | @@ -1005,25 +985,6 @@ |
317 | throw new EngineError.INVALID_ARGUMENT (error_message); |
318 | } |
319 | |
320 | - // FIXME: remove this |
321 | - private static string[] WILDCARDS_SUPPORTED = { |
322 | - "actor", "current_uri", "mimetype", "origin", "uri" }; |
323 | - |
324 | - // Used by get_where_clause_from_event_templates |
325 | - /** |
326 | - * Check if the value ends with the wildcard character. If it does, |
327 | - * remove the wildcard character from the value and return true. |
328 | - * Otherwise, return false. |
329 | - */ |
330 | - protected bool parse_wildcard (ref string val) |
331 | - { |
332 | - if (!val.has_suffix ("*")) |
333 | - return false; |
334 | - unowned uint8[] val_data = val.data; |
335 | - val_data[val_data.length-1] = '\0'; |
336 | - return true; |
337 | - } |
338 | - |
339 | // Used by get_where_clause_from_event_templates |
340 | /** |
341 | * If the value ends with the wildcard character, throw an error. |
342 | @@ -1049,10 +1010,20 @@ |
343 | |
344 | WhereClause subwhere = new WhereClause( |
345 | WhereClause.Type.OR, negated); |
346 | - foreach (string uri in symbols) |
347 | + |
348 | + if (symbols.length() == 1) |
349 | { |
350 | subwhere.add_match_condition (table_name, |
351 | - lookup_table.get_id (uri)); |
352 | + lookup_table.get_id (_symbol)); |
353 | + } |
354 | + else |
355 | + { |
356 | + string in_sql = ""; |
357 | + foreach (string uri in symbols) |
358 | + in_sql += "%i,".printf(lookup_table.get_id (uri)); |
359 | + string sql = "%s %s IN (%s)".printf(table_name, |
360 | + (negated) ? "NOT": "", in_sql[0:-1]); |
361 | + subwhere.add(sql); |
362 | } |
363 | return subwhere; |
364 | } |
[Merge line numbers as here on LP]
[15,29]: I don't like those methods being public in datamodel, it's an implementation detail.
[190,221,247,256]: Missing space before '('
[238]: It doesn't seem to be fixed. :P
Not really sure what to do about the first one, I'd rather have it inside Engine (public static) for the time being.