[folks] [Tracker] Implement support for LocalIDDetails
- From: Raul Gutierrez Segales <raulgs src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] [Tracker] Implement support for LocalIDDetails
- Date: Fri, 8 Apr 2011 17:29:29 +0000 (UTC)
commit 45b7cb6e75b359c2996f3f97132e6077bb86e955
Author: Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
Date: Thu Apr 7 17:35:10 2011 +0100
[Tracker] Implement support for LocalIDDetails
backends/tracker/lib/trf-persona-store.vala | 129 ++++++++++++++++++++++++++-
backends/tracker/lib/trf-persona.vala | 55 +++++++++++-
backends/tracker/lib/trf-util.vala | 4 +
3 files changed, 186 insertions(+), 2 deletions(-)
---
diff --git a/backends/tracker/lib/trf-persona-store.vala b/backends/tracker/lib/trf-persona-store.vala
index abf7a64..378d762 100644
--- a/backends/tracker/lib/trf-persona-store.vala
+++ b/backends/tracker/lib/trf-persona-store.vala
@@ -49,7 +49,8 @@ internal enum Trf.Fields
ROLES,
NOTE,
GENDER,
- POSTAL_ADDRESS
+ POSTAL_ADDRESS,
+ LOCAL_IDS_PROPERTY
}
internal enum Trf.AfflInfoFields
@@ -266,6 +267,16 @@ public class Trf.PersonaStore : Folks.PersonaStore
"WHERE { ?_contact nco:hasAffiliation " +
"?affl . ?affl nco:hasPostalAddress ?postal }) " +
+ /* Linking between Trf.Personas */
+ "(SELECT " +
+ "GROUP_CONCAT " +
+ " (?prop_value, " +
+ "',') " +
+ "WHERE { ?_contact nao:hasProperty ?prop . " +
+ " ?prop nao:propertyName ?prop_name . " +
+ " ?prop nao:propertyValue ?prop_value . " +
+ " FILTER (?prop_name = 'folks-linking-ids') } ) " +
+
"{ ?_contact a nco:PersonContact . %s } " +
"ORDER BY tracker:id(?_contact) ";
@@ -676,6 +687,23 @@ public class Trf.PersonaStore : Folks.PersonaStore
url_cnt++;
}
}
+ else if (k == Folks.PersonaStore.detail_key (PersonaDetail.LOCAL_IDS))
+ {
+ var local_ids = (Gee.HashSet<string>) v.get_object ();
+ string ids = Trf.PersonaStore.serialize_local_ids (local_ids);
+
+ builder.subject ("_:folks_ids");
+ builder.predicate ("a");
+ builder.object (Trf.OntologyDefs.NAO_PROPERTY);
+ builder.predicate (Trf.OntologyDefs.NAO_PROPERTY_NAME);
+ builder.object_string ("folks-linking-ids");
+ builder.predicate (Trf.OntologyDefs.NAO_PROPERTY_VALUE);
+ builder.object_string (ids);
+
+ builder.subject ("_:p");
+ builder.predicate (Trf.OntologyDefs.NAO_HAS_PROPERTY);
+ builder.object ("_:folks_ids");
+ }
else
{
throw new PersonaStoreError.INVALID_ARGUMENT (
@@ -710,6 +738,48 @@ public class Trf.PersonaStore : Folks.PersonaStore
return ret;
}
+ /**
+ * Transform HashSet<string> to "id1,id2,.."
+ *
+ * @since UNRELEASED
+ */
+ public static string serialize_local_ids (Gee.HashSet<string> local_ids)
+ {
+ var str = "";
+
+ foreach (var id in local_ids)
+ {
+ if (str != "")
+ {
+ str += ",";
+ }
+ str += id;
+ }
+
+ return str;
+ }
+
+ /**
+ * Transform from id1,id2,.. to HashSet<string>
+ *
+ * @since UNRELEASED
+ */
+ public static Gee.HashSet<string> unserialize_local_ids (string local_ids)
+ {
+ Gee.HashSet<string> ids = new Gee.HashSet<string> ();
+
+ if (local_ids != "")
+ {
+ string[] ids_a = local_ids.split (",");
+ foreach (var id in ids_a)
+ {
+ ids.add (id);
+ }
+ }
+
+ return ids;
+ }
+
/**
* Remove a { link Persona} from the PersonaStore.
*
@@ -1003,6 +1073,9 @@ public class Trf.PersonaStore : Folks.PersonaStore
Trf.OntologyDefs.NCO_FEMALE);
this._urn_prefix.set (Trf.OntologyDefs.NCO_URL_PREFIX + "nco#photo>",
Trf.OntologyDefs.NCO_PHOTO);
+ this._urn_prefix.set (
+ Trf.OntologyDefs.NAO_URL_PREFIX + "nao#hasProperty>",
+ Trf.OntologyDefs.NAO_PROPERTY);
}
private void _graph_updated_cb (DBusConnection connection,
@@ -1364,6 +1437,16 @@ public class Trf.PersonaStore : Folks.PersonaStore
}
p._set_avatar (avatar_url);
}
+ else if (e.pred_id == this._prefix_tracker_id.get
+ (Trf.OntologyDefs.NAO_PROPERTY))
+ {
+ string local_ids = "";
+ if (adding)
+ {
+ local_ids = yield this._get_local_ids (e.subject_id);
+ }
+ p._set_local_ids (local_ids);
+ }
}
private async string _get_property
@@ -1381,6 +1464,21 @@ public class Trf.PersonaStore : Folks.PersonaStore
return yield this._single_value_query (query);
}
+ private async string _get_local_ids (int subject_tracker_id)
+ {
+ const string query_t = "SELECT " +
+ " ?prop_value " +
+ "WHERE { " +
+ " ?p a " + Trf.OntologyDefs.NCO_PERSON + " ; " +
+ Trf.OntologyDefs.NAO_HAS_PROPERTY + " ?prop . " +
+ " ?prop " + Trf.OntologyDefs.NAO_PROPERTY_NAME + " ?prop_name . " +
+ " ?prop " + Trf.OntologyDefs.NAO_PROPERTY_VALUE + " ?prop_value . " +
+ " FILTER (tracker:id(?p) = %d && ?prop_name = 'folks-linking-ids' ) } ";
+
+ string query = query_t.printf(subject_tracker_id);
+ return yield this._single_value_query (query);
+ }
+
/*
* This should be kept in sync with Trf.AfflInfoFields
*/
@@ -1557,6 +1655,8 @@ public class Trf.PersonaStore : Folks.PersonaStore
{
Gee.HashSet<string> ret = new Gee.HashSet<string> ();
+ debug ("[_multi_value_query] %s", query);
+
try
{
Sparql.Cursor cursor = yield this._connection.query_async (query);
@@ -1610,6 +1710,33 @@ public class Trf.PersonaStore : Folks.PersonaStore
yield this._tracker_update (query, "change_alias");
}
+ internal async void _set_local_ids (Trf.Persona persona,
+ Gee.HashSet<string> local_ids)
+ {
+ const string query_t = "DELETE " +
+ " { ?p " + Trf.OntologyDefs.NAO_HAS_PROPERTY + " ?prop } " +
+ "WHERE { " +
+ " ?p a " + Trf.OntologyDefs.NCO_PERSON + " ; " +
+ Trf.OntologyDefs.NAO_HAS_PROPERTY + " ?prop . " +
+ " ?prop " + Trf.OntologyDefs.NAO_PROPERTY_NAME + " ?prop_name . " +
+ " FILTER (tracker:id(?p) = %s && ?name = 'folks-linking-ids' ) } " +
+ "INSERT { " +
+ " _:prop a " + Trf.OntologyDefs.NAO_PROPERTY + " ; " +
+ Trf.OntologyDefs.NAO_PROPERTY_NAME + " 'folks-linking-ids' ; " +
+ Trf.OntologyDefs.NAO_PROPERTY_VALUE + " '%s' . " +
+ " ?p " + Trf.OntologyDefs.NAO_HAS_PROPERTY + " _:prop " +
+ "} " +
+ "WHERE { " +
+ " ?p a nco:PersonContact . " +
+ "FILTER (tracker:id(?p) = %s) } ";
+
+ string ids = Trf.PersonaStore.serialize_local_ids (local_ids);
+
+ string query = query_t.printf (persona.tracker_id (), ids,
+ persona.tracker_id ());
+ yield this._tracker_update (query, "_set_local_ids");
+ }
+
internal async void _set_is_favourite (Folks.Persona persona,
bool is_favourite)
{
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index 84b2222..92f5686 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -37,6 +37,7 @@ public class Trf.Persona : Folks.Persona,
FavouriteDetails,
GenderDetails,
ImDetails,
+ LocalIdDetails,
NameDetails,
NoteDetails,
PhoneDetails,
@@ -47,7 +48,7 @@ public class Trf.Persona : Folks.Persona,
private string _alias;
private bool _is_favourite;
private const string[] _linkable_properties =
- {"im-addresses"};
+ {"im-addresses", "local-ids"};
private GLib.List<FieldDetails> _phone_numbers;
private GLib.List<FieldDetails> _email_addresses;
private weak Sparql.Cursor _cursor;
@@ -303,6 +304,30 @@ public class Trf.Persona : Folks.Persona,
}
}
+ private HashSet<string> _local_ids = new HashSet<string> ();
+ /**
+ * IDs used to link { link Trf.Persona}s.
+ */
+ public HashSet<string> local_ids
+ {
+ get
+ {
+ if (this._local_ids.contains (this.uid) == false)
+ {
+ this._local_ids.add (this.uid);
+ }
+ return this._local_ids;
+ }
+ set
+ {
+ if (value.contains (this.uid) == false)
+ {
+ value.add (this.uid);
+ }
+ ((Trf.PersonaStore) this.store)._set_local_ids (this, value);
+ }
+ }
+
/**
* Build a IID.
*
@@ -384,6 +409,13 @@ public class Trf.Persona : Folks.Persona,
callback (protocol + ":" + address);
});
}
+ else if (prop_name == "local-ids")
+ {
+ foreach (var id in this._local_ids)
+ {
+ callback (id);
+ }
+ }
else
{
/* Chain up */
@@ -482,6 +514,7 @@ public class Trf.Persona : Folks.Persona,
this._update_note ();
this._update_gender ();
this._update_postal_addresses ();
+ this._update_local_ids ();
}
private void _update_postal_addresses ()
@@ -534,6 +567,19 @@ public class Trf.Persona : Folks.Persona,
this._postal_addresses = (owned) postal_addresses;
}
+ private void _update_local_ids ()
+ {
+ string local_ids = this._cursor.get_string
+ (Trf.Fields.LOCAL_IDS_PROPERTY).dup ();
+
+ if (local_ids == null)
+ {
+ return;
+ }
+
+ this._set_local_ids (local_ids);
+ }
+
internal bool _add_postal_address (PostalAddress postal_address)
{
foreach (unowned PostalAddress pa in this._postal_addresses)
@@ -746,6 +792,13 @@ public class Trf.Persona : Folks.Persona,
return true;
}
+ internal bool _set_local_ids (string local_ids)
+ {
+ this._local_ids = Trf.PersonaStore.unserialize_local_ids (local_ids);
+ this.notify_property ("local-ids");
+ return true;
+ }
+
private void _update_im_addresses ()
{
string addresses = this._cursor.get_string (
diff --git a/backends/tracker/lib/trf-util.vala b/backends/tracker/lib/trf-util.vala
index f000231..a3f1138 100644
--- a/backends/tracker/lib/trf-util.vala
+++ b/backends/tracker/lib/trf-util.vala
@@ -112,6 +112,10 @@ public class Trf.OntologyDefs : Object
public static const string NCO_BLOG = "nco:blogUrl";
public static const string NAO_FAVORITE = "nao:predefined-tag-favorite";
public static const string NAO_TAG = "nao:hasTag";
+ public static const string NAO_PROPERTY = "nao:Property";
+ public static const string NAO_HAS_PROPERTY = "nao:hasProperty";
+ public static const string NAO_PROPERTY_NAME = "nao:propertyName";
+ public static const string NAO_PROPERTY_VALUE = "nao:propertyValue";
public static const string NCO_HAS_EMAIL = "nco:hasEmailAddress";
public static const string NCO_EMAIL = "nco:EmailAddress";
public static const string NCO_EMAIL_PROP = "nco:emailAddress";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]