~noskcaj/ubuntu/trusty/gnome-documents/3.10.2

« back to all changes in this revision

Viewing changes to src/miner/gd-gdata-miner.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2012-06-29 13:16:35 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20120629131635-tkocc51xk4c37a39
Tags: 0.5.3-0ubuntu1
* New upstream release.
* debian/control.in:
  - Bump minimum GTK
  - Build-depend on libzapojit-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
#include "gd-gdata-goa-authorizer.h"
27
27
#include "gd-gdata-miner.h"
 
28
#include "gd-miner-tracker.h"
28
29
#include "gd-utils.h"
29
30
 
30
31
#define MINER_IDENTIFIER "gd:gdata:miner:86ec9bc9-c242-427f-aa19-77b5a2c9b6f0"
43
44
  GList *pending_jobs;
44
45
};
45
46
 
46
 
static gchar *
47
 
_tracker_utils_format_into_graph (const gchar *graph)
48
 
{
49
 
  return (graph != NULL) ? g_strdup_printf ("INTO <%s> ", graph) : g_strdup ("");
50
 
}
51
 
 
52
47
static gboolean
53
48
_tracker_sparql_connection_toggle_favorite (TrackerSparqlConnection *connection,
54
49
                                            GCancellable *cancellable,
85
80
  return retval;
86
81
}
87
82
 
88
 
static gboolean
89
 
_tracker_sparql_connection_insert_or_replace_triple (TrackerSparqlConnection *connection,
90
 
                                                     GCancellable *cancellable,
91
 
                                                     GError **error,
92
 
                                                     const gchar *graph,
93
 
                                                     const gchar *resource,
94
 
                                                     const gchar *property_name,
95
 
                                                     const gchar *property_value)
96
 
{
97
 
  GString *insert;
98
 
  gchar *graph_str;
99
 
  gboolean retval = TRUE;
100
 
 
101
 
  graph_str = _tracker_utils_format_into_graph (graph);
102
 
 
103
 
  insert = g_string_new (NULL);
104
 
  g_string_append_printf 
105
 
    (insert,
106
 
     "INSERT OR REPLACE %s { <%s> a nie:InformationElement ; %s \"%s\" }",
107
 
     graph_str, resource, property_name, property_value);
108
 
 
109
 
  g_debug ("Insert or replace triple: query %s", insert->str);
110
 
 
111
 
  tracker_sparql_connection_update (connection, insert->str, 
112
 
                                    G_PRIORITY_DEFAULT, cancellable,
113
 
                                    error);
114
 
 
115
 
  g_string_free (insert, TRUE);
116
 
 
117
 
  if (*error != NULL)
118
 
    retval = FALSE;
119
 
 
120
 
  g_free (graph_str);
121
 
 
122
 
  return retval;
123
 
}
124
 
 
125
 
static gboolean
126
 
_tracker_sparql_connection_set_triple (TrackerSparqlConnection *connection,
127
 
                                       GCancellable *cancellable,
128
 
                                       GError **error,
129
 
                                       const gchar *graph,
130
 
                                       const gchar *resource,
131
 
                                       const gchar *property_name,
132
 
                                       const gchar *property_value)
133
 
{
134
 
  GString *delete;
135
 
  gboolean retval = TRUE;
136
 
 
137
 
  delete = g_string_new (NULL);
138
 
  g_string_append_printf 
139
 
    (delete,
140
 
     "DELETE { <%s> %s ?val } WHERE { <%s> %s ?val }", resource,
141
 
     property_name, resource, property_name);
142
 
 
143
 
  tracker_sparql_connection_update (connection, delete->str, 
144
 
                                    G_PRIORITY_DEFAULT, cancellable,
145
 
                                    error);
146
 
 
147
 
  g_string_free (delete, TRUE);
148
 
  if (*error != NULL)
149
 
    {
150
 
      retval = FALSE;
151
 
      goto out;
152
 
    }
153
 
 
154
 
  retval = 
155
 
    _tracker_sparql_connection_insert_or_replace_triple (connection, 
156
 
                                                         cancellable, error,
157
 
                                                         graph, resource,
158
 
                                                         property_name, property_value);
159
 
 
160
 
 out:
161
 
  return retval;
162
 
}
163
 
 
164
83
static gchar*
165
84
_tracker_utils_ensure_contact_resource (TrackerSparqlConnection *connection,
166
85
                                        GCancellable *cancellable,
251
170
  return retval;
252
171
}
253
172
 
254
 
static gchar*
255
 
_tracker_sparql_connection_ensure_resource (TrackerSparqlConnection *connection,
256
 
                                            GCancellable *cancellable,
257
 
                                            GError **error,
258
 
                                            const gchar *graph,
259
 
                                            const gchar *identifier,
260
 
                                            const gchar *class,
261
 
                                            ...)
262
 
{
263
 
  GString *select, *insert, *inner;
264
 
  va_list args;
265
 
  const gchar *arg;
266
 
  TrackerSparqlCursor *cursor;
267
 
  gboolean res;
268
 
  gchar *retval = NULL;
269
 
  gchar *graph_str;
270
 
  GVariant *insert_res;
271
 
  GVariantIter *iter;
272
 
  gchar *key = NULL, *val = NULL;
273
 
 
274
 
  /* build the inner query with all the classes */
275
 
  va_start (args, class);
276
 
  inner = g_string_new (NULL);
277
 
 
278
 
  for (arg = class; arg != NULL; arg = va_arg (args, const gchar *))
279
 
    g_string_append_printf (inner, " a %s; ", arg);
280
 
 
281
 
  g_string_append_printf (inner, "nao:identifier \"%s\"", identifier);
282
 
 
283
 
  va_end (args);
284
 
 
285
 
  /* query if such a resource is already in the DB */
286
 
  select = g_string_new (NULL);
287
 
  g_string_append_printf (select, 
288
 
                          "SELECT ?urn WHERE { ?urn %s }", inner->str);
289
 
 
290
 
  cursor = tracker_sparql_connection_query (connection,
291
 
                                            select->str,
292
 
                                            cancellable, error);
293
 
 
294
 
  g_string_free (select, TRUE);
295
 
 
296
 
  if (*error != NULL)
297
 
    goto out;
298
 
 
299
 
  res = tracker_sparql_cursor_next (cursor, cancellable, error);
300
 
 
301
 
  if (*error != NULL)
302
 
    goto out;
303
 
 
304
 
  if (res)
305
 
    {
306
 
      /* return the found resource */
307
 
      retval = g_strdup (tracker_sparql_cursor_get_string (cursor, 0, NULL));
308
 
      g_debug ("Found resource in the store: %s", retval);
309
 
      goto out;
310
 
    }
311
 
 
312
 
  /* not found, create the resource */
313
 
  insert = g_string_new (NULL);
314
 
  graph_str = _tracker_utils_format_into_graph (graph);
315
 
 
316
 
  g_string_append_printf (insert, "INSERT %s { _:res %s }", 
317
 
                          graph_str, inner->str);
318
 
  g_free (graph_str);
319
 
  g_string_free (inner, TRUE);
320
 
 
321
 
  insert_res = 
322
 
    tracker_sparql_connection_update_blank (connection, insert->str,
323
 
                                            G_PRIORITY_DEFAULT, NULL, error);
324
 
 
325
 
  g_string_free (insert, TRUE);
326
 
 
327
 
  if (*error != NULL)
328
 
    goto out;
329
 
 
330
 
  /* the result is an "aaa{ss}" variant */
331
 
  g_variant_get (insert_res, "aaa{ss}", &iter);
332
 
  g_variant_iter_next (iter, "aa{ss}", &iter);
333
 
  g_variant_iter_next (iter, "a{ss}", &iter);
334
 
  g_variant_iter_next (iter, "{ss}", &key, &val);
335
 
 
336
 
  g_variant_iter_free (iter);
337
 
  g_variant_unref (insert_res);
338
 
 
339
 
  if (g_strcmp0 (key, "res") == 0)
340
 
    {
341
 
      retval = val;
342
 
    }
343
 
  else
344
 
    {
345
 
      g_free (val);
346
 
      goto out;
347
 
    }
348
 
 
349
 
  g_debug ("Created a new resource: %s", retval);
350
 
 
351
 
 out:
352
 
  g_clear_object (&cursor);
353
 
  return retval;
354
 
}
355
173
 
356
174
typedef struct {
357
175
  GdGDataMiner *self;
517
335
  else if (GDATA_IS_DOCUMENTS_FOLDER (doc_entry))
518
336
    class = "nfo:DataContainer";
519
337
 
520
 
  resource = _tracker_sparql_connection_ensure_resource
 
338
  resource = gd_miner_tracker_sparql_connection_ensure_resource
521
339
    (job->connection, 
522
340
     job->cancellable, error,
523
341
     resource_url, identifier,
528
346
 
529
347
  datasource_urn = g_strdup_printf ("gd:goa-account:%s", 
530
348
                                    goa_account_get_id (job->account));
531
 
  _tracker_sparql_connection_set_triple 
 
349
  gd_miner_tracker_sparql_connection_set_triple
532
350
    (job->connection, job->cancellable, error,
533
351
     identifier, resource,
534
352
     "nie:dataSource", datasource_urn);
541
359
  alternate = gdata_entry_look_up_link (entry, GDATA_LINK_ALTERNATE);
542
360
  alternate_uri = gdata_link_get_uri (alternate);
543
361
 
544
 
  _tracker_sparql_connection_insert_or_replace_triple
 
362
  gd_miner_tracker_sparql_connection_insert_or_replace_triple
545
363
    (job->connection, 
546
364
     job->cancellable, error,
547
365
     identifier, resource,
559
377
      parent_resource_id = 
560
378
        g_strdup_printf ("gd:collection:%s", gdata_link_get_uri (parent));
561
379
 
562
 
      parent_resource_urn = _tracker_sparql_connection_ensure_resource
 
380
      parent_resource_urn = gd_miner_tracker_sparql_connection_ensure_resource
563
381
        (job->connection, job->cancellable, error,
564
382
         NULL, parent_resource_id,
565
383
         "nfo:RemoteDataObject", "nfo:DataContainer", NULL);
568
386
      if (*error != NULL)
569
387
        goto out;
570
388
 
571
 
      _tracker_sparql_connection_insert_or_replace_triple
 
389
      gd_miner_tracker_sparql_connection_insert_or_replace_triple
572
390
        (job->connection,
573
391
         job->cancellable, error,
574
392
         identifier, resource,
598
416
  if (*error != NULL)
599
417
    goto out;
600
418
 
601
 
  _tracker_sparql_connection_insert_or_replace_triple
 
419
  gd_miner_tracker_sparql_connection_insert_or_replace_triple
602
420
    (job->connection, 
603
421
     job->cancellable, error,
604
422
     identifier, resource,
607
425
  if (*error != NULL)
608
426
    goto out;
609
427
 
610
 
  _tracker_sparql_connection_insert_or_replace_triple
 
428
  gd_miner_tracker_sparql_connection_insert_or_replace_triple
611
429
    (job->connection, 
612
430
     job->cancellable, error,
613
431
     identifier, resource,
631
449
      if (*error != NULL)
632
450
        goto out;
633
451
 
634
 
      _tracker_sparql_connection_insert_or_replace_triple
 
452
      gd_miner_tracker_sparql_connection_insert_or_replace_triple
635
453
        (job->connection, 
636
454
         job->cancellable, error,
637
455
         identifier, resource,
673
491
                                                                 scope_value,
674
492
                                                                 "");
675
493
 
676
 
      _tracker_sparql_connection_insert_or_replace_triple
 
494
      gd_miner_tracker_sparql_connection_insert_or_replace_triple
677
495
        (job->connection,
678
496
         job->cancellable, error,
679
497
         identifier, resource,
686
504
    }
687
505
 
688
506
  date = gd_iso8601_from_timestamp (gdata_entry_get_published (entry));
689
 
  _tracker_sparql_connection_insert_or_replace_triple
 
507
  gd_miner_tracker_sparql_connection_insert_or_replace_triple
690
508
    (job->connection, 
691
509
     job->cancellable, error,
692
510
     identifier, resource,
697
515
    goto out;
698
516
 
699
517
  date = gd_iso8601_from_timestamp (gdata_entry_get_updated (entry));
700
 
  _tracker_sparql_connection_insert_or_replace_triple
 
518
  gd_miner_tracker_sparql_connection_insert_or_replace_triple
701
519
    (job->connection, 
702
520
     job->cancellable, error,
703
521
     identifier, resource,