[folks] [Tracker] Re-use phone-numbers/emails if they already exist
- From: Raul Gutierrez Segales <raulgs src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] [Tracker] Re-use phone-numbers/emails if they already exist
- Date: Tue, 5 Apr 2011 13:53:25 +0000 (UTC)
commit 86d5976cc17efe0ad9bc4185e74606eb81d7d683
Author: Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
Date: Tue Apr 5 13:15:45 2011 +0100
[Tracker] Re-use phone-numbers/emails if they already exist
NEWS | 1 +
backends/tracker/lib/trf-persona-store.vala | 59 +++++++++++++++++++++-----
2 files changed, 48 insertions(+), 12 deletions(-)
---
diff --git a/NEWS b/NEWS
index ae4f84c..a451427 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,7 @@ Bugs fixed:
* Bug 645413 â?? Write support for Tracker
* Bug 645441 â?? Mechanism to specify primary backend
* Bug 638280 â?? Add a libsocialweb backend
+* Deal with duplicated phones/e-mails in Tracker
API changes:
* Add equal () to StructuredName
diff --git a/backends/tracker/lib/trf-persona-store.vala b/backends/tracker/lib/trf-persona-store.vala
index 874030b..c006268 100644
--- a/backends/tracker/lib/trf-persona-store.vala
+++ b/backends/tracker/lib/trf-persona-store.vala
@@ -475,12 +475,19 @@ public class Trf.PersonaStore : Folks.PersonaStore
foreach (var e in email_addresses)
{
var email_affl = "_:email_affl%d".printf (email_cnt);
- var email = "_:email%d".printf (email_cnt);
- builder.subject (email);
- builder.predicate ("a");
- builder.object (Trf.OntologyDefs.NCO_EMAIL);
- builder.predicate (Trf.OntologyDefs.NCO_EMAIL_PROP);
- builder.object_string (e.value);
+ var email = yield this._urn_from_property (
+ Trf.OntologyDefs.NCO_EMAIL,
+ Trf.OntologyDefs.NCO_EMAIL_PROP, e.value);
+
+ if (email == "")
+ {
+ email = "_:email%d".printf (email_cnt);
+ builder.subject (email);
+ builder.predicate ("a");
+ builder.object (Trf.OntologyDefs.NCO_EMAIL);
+ builder.predicate (Trf.OntologyDefs.NCO_EMAIL_PROP);
+ builder.object_string (e.value);
+ }
builder.subject (email_affl);
builder.predicate ("a");
@@ -553,12 +560,19 @@ public class Trf.PersonaStore : Folks.PersonaStore
foreach (var p in phone_numbers)
{
var phone_affl = "_:phone_affl%d".printf (phone_cnt);
- var phone = "_:phone%d".printf (phone_cnt);
- builder.subject (phone);
- builder.predicate ("a");
- builder.object (Trf.OntologyDefs.NCO_PHONE);
- builder.predicate (Trf.OntologyDefs.NCO_PHONE_PROP);
- builder.object_string (p.value);
+ var phone = yield this._urn_from_property (
+ Trf.OntologyDefs.NCO_PHONE,
+ Trf.OntologyDefs.NCO_PHONE_PROP, p.value);
+
+ if (phone == "")
+ {
+ phone = "_:phone%d".printf (phone_cnt);
+ builder.subject (phone);
+ builder.predicate ("a");
+ builder.object (Trf.OntologyDefs.NCO_PHONE);
+ builder.predicate (Trf.OntologyDefs.NCO_PHONE_PROP);
+ builder.object_string (p.value);
+ }
builder.subject (phone_affl);
builder.predicate ("a");
@@ -2219,4 +2233,25 @@ public class Trf.PersonaStore : Folks.PersonaStore
var id = ((Trf.Persona) persona).tracker_id ();
return yield this._urn_from_tracker_id (id);
}
+
+ /**
+ * Helper method to figure out if a constrained property
+ * already exists.
+ */
+ private async string _urn_from_property (string class_name,
+ string property_name,
+ string property_value)
+ {
+ const string query_template = "SELECT " +
+ " fn:concat('<', ?o, '>') " +
+ "WHERE { " +
+ " ?o a %s ; " +
+ " %s ?prop_val . " +
+ "FILTER (?prop_val = '%s') " +
+ "}";
+
+ string query = query_template.printf (class_name,
+ property_name, property_value);
+ return yield this._single_value_query (query);
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]