[folks] Bug 653619 — Add company details



commit 30ee4db520551b24aca28febc28925445b8edd7a
Author: Philip Withnall <philip tecnocode co uk>
Date:   Tue Aug 9 12:19:11 2011 +0200

    Bug 653619 â Add company details
    
    I dislike Tracker, ontologies, Sparql and drinking games.
    
    Closes: bgo#653619

 NEWS                                        |    2 ++
 backends/tracker/lib/trf-persona-store.vala |   25 ++++++++++++++++++-------
 backends/tracker/lib/trf-persona.vala       |   16 ++++++++++------
 backends/tracker/lib/trf-util.vala          |    3 +++
 folks/role-details.vala                     |   20 ++++++++++++++++----
 tests/lib/tracker/backend.vala              |    6 +++---
 tests/tracker/add-persona.vala              |    6 +++++-
 tests/tracker/role-details-interface.vala   |    5 +++--
 tests/tracker/set-roles.vala                |    2 ++
 9 files changed, 62 insertions(+), 23 deletions(-)
---
diff --git a/NEWS b/NEWS
index 6a67650..0117be6 100644
--- a/NEWS
+++ b/NEWS
@@ -29,6 +29,7 @@ Bugs fixed:
 * Bug 649296 â Folks backend files shouldn't begin with "lib"
 * Bug 652657 â Allow writing to properties of all personas
 * Bug 655008 â Tidy up error handling in eds backend
+* Bug 653619 â Add company details
 
 API changes:
 * Swf.Persona retains and exposes its libsocialweb Contact
@@ -47,6 +48,7 @@ API changes:
 * Add AvatarCache class
 * Add ObjectCache class
 * Remove leaked internal PotentialMatch.result_to_string() method
+* Add RoleDetails:role property
 
 Overview of changes from libfolks 0.5.1 to libfolks 0.5.2
 =========================================================
diff --git a/backends/tracker/lib/trf-persona-store.vala b/backends/tracker/lib/trf-persona-store.vala
index 2ac30cf..06b5515 100644
--- a/backends/tracker/lib/trf-persona-store.vala
+++ b/backends/tracker/lib/trf-persona-store.vala
@@ -62,6 +62,7 @@ internal enum Trf.AfflInfoFields
   AFFL_TRACKER_ID,
   AFFL_ROLE,
   AFFL_ORG,
+  AFFL_TITLE,
   AFFL_POBOX,
   AFFL_DISTRICT,
   AFFL_COUNTY,
@@ -107,7 +108,8 @@ internal enum Trf.RoleFields
 {
   TRACKER_ID,
   ROLE,
-  DEPARTMENT
+  DEPARTMENT,
+  TITLE
 }
 
 internal enum Trf.IMFields
@@ -236,7 +238,8 @@ public class Trf.PersonaStore : Folks.PersonaStore
     "GROUP_CONCAT " +
     " (fn:concat(tracker:id(?affl), '\t', " +
     "  tracker:coalesce(nco:role(?affl),''), '\t', " +
-    "  tracker:coalesce(nco:department(?affl),'')),  " +
+    "  tracker:coalesce(nco:department(?affl),''), '\t', " +
+    "  tracker:coalesce(nco:title(?affl),'')), " +
     "'\\n') " +
     "WHERE { ?_contact nco:hasAffiliation " +
     "?affl }) " +
@@ -561,9 +564,11 @@ public class Trf.PersonaStore : Folks.PersonaStore
                   builder.predicate ("a");
                   builder.object (Trf.OntologyDefs.NCO_AFFILIATION);
                   builder.predicate (Trf.OntologyDefs.NCO_ROLE);
-                  builder.object_string (r.title);
+                  builder.object_string (r.role);
                   builder.predicate (Trf.OntologyDefs.NCO_ORG);
                   builder.object_string (r.organisation_name);
+                  builder.predicate (Trf.OntologyDefs.NCO_TITLE);
+                  builder.object_string (r.title);
 
                   builder.subject ("_:p");
                   builder.predicate (Trf.OntologyDefs.NCO_HAS_AFFILIATION);
@@ -1461,8 +1466,8 @@ public class Trf.PersonaStore : Folks.PersonaStore
                   if (affl_info.title != null ||
                       affl_info.org != null)
                     {
-                      p._add_role (affl_info.affl_tracker_id, affl_info.title,
-                          affl_info.org);
+                      p._add_role (affl_info.affl_tracker_id, affl_info.role,
+                          affl_info.title, affl_info.org);
                     }
                 }
 
@@ -1639,6 +1644,7 @@ public class Trf.PersonaStore : Folks.PersonaStore
         "tracker:id(?a) " +
         Trf.OntologyDefs.NCO_ROLE + "(?a) " +
         Trf.OntologyDefs.NCO_ORG + "(?a) " +
+        Trf.OntologyDefs.NCO_TITLE + "(?a) " +
         Trf.OntologyDefs.NCO_POBOX + "(?postal) " +
         Trf.OntologyDefs.NCO_DISTRICT + "(?postal) " +
         Trf.OntologyDefs.NCO_COUNTY + "(?postal) " +
@@ -1687,10 +1693,12 @@ public class Trf.PersonaStore : Folks.PersonaStore
 
               affl_info.affl_tracker_id = cursor.get_string
                   (Trf.AfflInfoFields.AFFL_TRACKER_ID).dup ();
-              affl_info.title = cursor.get_string
+              affl_info.role = cursor.get_string
                   (Trf.AfflInfoFields.AFFL_ROLE).dup ();
               affl_info.org = cursor.get_string
                   (Trf.AfflInfoFields.AFFL_ORG).dup ();
+              affl_info.title = cursor.get_string
+                  (Trf.AfflInfoFields.AFFL_TITLE).dup ();
 
               var po_box = cursor.get_string
                   (Trf.AfflInfoFields.AFFL_POBOX).dup ();
@@ -2030,6 +2038,7 @@ public class Trf.PersonaStore : Folks.PersonaStore
         " " + Trf.OntologyDefs.NCO_HAS_AFFILIATION + " ?a . " +
         " OPTIONAL { ?a " + Trf.OntologyDefs.NCO_ORG +  " ?o } . " +
         " OPTIONAL { ?a " + Trf.OntologyDefs.NCO_ROLE + " ?r } . " +
+        " OPTIONAL { ?a " + Trf.OntologyDefs.NCO_TITLE + " ?t } . " +
         " FILTER(tracker:id(?p) = %s) " +
         "} ";
 
@@ -2048,9 +2057,11 @@ public class Trf.PersonaStore : Folks.PersonaStore
           builder.predicate ("a");
           builder.object (Trf.OntologyDefs.NCO_AFFILIATION);
           builder.predicate (Trf.OntologyDefs.NCO_ROLE);
-          builder.object_string (r.title);
+          builder.object_string (r.role);
           builder.predicate (Trf.OntologyDefs.NCO_ORG);
           builder.object_string (r.organisation_name);
+          builder.predicate (Trf.OntologyDefs.NCO_TITLE);
+          builder.object_string (r.title);
           builder.subject ("?contact");
           builder.predicate (Trf.OntologyDefs.NCO_HAS_AFFILIATION);
           builder.object (affl);
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index 56f8eed..72c722f 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -751,21 +751,25 @@ public class Trf.Persona : Folks.Persona,
         {
           string[] r_info = r.split ("\t");
           var tracker_id = r_info[Trf.RoleFields.TRACKER_ID];
-          var title = r_info[Trf.RoleFields.ROLE];
+          var role = r_info[Trf.RoleFields.ROLE];
+          var title = r_info[Trf.RoleFields.TITLE];
           var organisation = r_info[Trf.RoleFields.DEPARTMENT];
 
-          var role = new Role (title, organisation, tracker_id);
-          roles.add (role);
+          var new_role = new Role (title, organisation, tracker_id);
+          new_role.role = role;
+          roles.add (new_role);
         }
 
       this._roles = roles;
       this._roles_ro = this._roles.read_only_view;
     }
 
-  internal bool _add_role (string tracker_id, string? title, string? org)
+  internal bool _add_role (string tracker_id, string? role, string? title, string? org)
     {
-      var role = new Role (title, org, tracker_id);
-      if (this._roles.add (role))
+      var new_role = new Role (title, org, tracker_id);
+      new_role.role = role;
+
+      if (this._roles.add (new_role))
         {
           this.notify_property ("roles");
           return true;
diff --git a/backends/tracker/lib/trf-util.vala b/backends/tracker/lib/trf-util.vala
index a3f1138..1270b5f 100644
--- a/backends/tracker/lib/trf-util.vala
+++ b/backends/tracker/lib/trf-util.vala
@@ -54,6 +54,8 @@ internal class Trf.AfflInfo : Object
 
   public string org  { get; set; }
 
+  public string role { get; set; }
+
   public Folks.PostalAddress postal_address;
 
   public string email { get; set; }
@@ -151,6 +153,7 @@ public class Trf.OntologyDefs : Object
   public static const string NCO_COUNTRY = "nco:country";
   public static const string NCO_REGION = "nco:region";
   public static const string NCO_ROLE = "nco:role";
+  public static const string NCO_TITLE = "nco:title";
   public static const string NCO_ORG = "nco:org";
   public static const string NCO_URL_PREFIX =
       "<http://www.semanticdesktop.org/ontologies/2007/03/22/";;
diff --git a/folks/role-details.vala b/folks/role-details.vala
index 98b5e5e..8a2c489 100644
--- a/folks/role-details.vala
+++ b/folks/role-details.vala
@@ -35,11 +35,22 @@ public class Folks.Role : Object
   public string organisation_name { get; set; }
 
   /**
-   * The name of the position held.
+   * The title of the position held.
+   *
+   * For example: âDirector, Ministry of Silly Walksâ
    */
   public string title { get; set; }
 
   /**
+   * The role of the position.
+   *
+   * For example: âProgrammerâ
+   *
+   * @since UNRELEASED
+   */
+  public string role { get; set; }
+
+  /**
    * The UID that distinguishes this role.
    */
   public string uid { get; set; }
@@ -88,6 +99,7 @@ public class Folks.Role : Object
   public static bool equal (Role a, Role b)
     {
       return (a.title == b.title) &&
+          (a.role == b.role) &&
           (a.organisation_name == b.organisation_name);
     }
 
@@ -99,7 +111,7 @@ public class Folks.Role : Object
    */
   public static uint hash (Role r)
     {
-      return r.organisation_name.hash () + r.title.hash ();
+      return r.organisation_name.hash () ^ r.title.hash () ^ r.role.hash ();
     }
 
   /**
@@ -109,8 +121,8 @@ public class Folks.Role : Object
    */
   public string to_string ()
     {
-      var str = _("Title: %s , Organisation: %s");
-      return str.printf (this.title, this.organisation_name);
+      var str = _("Title: %s, Organisation: %s, Role: %s");
+      return str.printf (this.title, this.organisation_name, this.role);
     }
 }
 
diff --git a/tests/lib/tracker/backend.vala b/tests/lib/tracker/backend.vala
index 01a6394..bffba10 100644
--- a/tests/lib/tracker/backend.vala
+++ b/tests/lib/tracker/backend.vala
@@ -304,7 +304,7 @@ public class TrackerTest.Backend
           " . <%smyaffiliation> nco:hasIMAddress " +
           " <%s>  ";
       const string af_t = " . <affl:001> a nco:Affiliation; " +
-          "nco:role '%s'; nco:department '%s' ";
+          "nco:title '%s'; nco:department '%s'; nco:role '%s' ";
       const string postal_t = " . <affl:001> a nco:Affiliation ; " +
           "nco:hasPostalAddress <postal:001> . " +
           " <postal:001> a nco:PostalAddress ; " +
@@ -485,7 +485,7 @@ public class TrackerTest.Backend
       if (affiliation != "")
         {
           string[] role_info = affiliation.split (",");
-          q += af_t.printf (role_info[0], role_info[1]);
+          q += af_t.printf (role_info[0], role_info[1], role_info[2]);
         }
 
       if (postal_address != "")
@@ -541,4 +541,4 @@ public class TrackerTest.Backend
 
       return ret;
     }
-}
\ No newline at end of file
+}
diff --git a/tests/tracker/add-persona.vala b/tests/tracker/add-persona.vala
index 328cf0e..0d049c9 100644
--- a/tests/tracker/add-persona.vala
+++ b/tests/tracker/add-persona.vala
@@ -47,6 +47,7 @@ public class AddPersonaTests : Folks.TestCase
   private string _phone_2;
   private string _title_1;
   private string _organisation_1;
+  private string _role_1;
   private PostalAddress _address;
   private string _po_box = "12345";
   private string _locality = "locality";
@@ -97,6 +98,7 @@ public class AddPersonaTests : Folks.TestCase
       this._phone_2 = "54321";
       this._title_1 = "CFO";
       this._organisation_1 = "Example Inc.";
+      this._role_1 = "Role";
 
       var types =  new HashSet<string> ();
       this._address = new PostalAddress (this._po_box,
@@ -263,6 +265,7 @@ public class AddPersonaTests : Folks.TestCase
       Value? v12 = Value (typeof (Set<Role>));
       var roles = new HashSet<Role> ();
       Role r1 = new Role (this._title_1, this._organisation_1);
+      r1.role = this._role_1;
       roles.add (r1);
       v12.set_object (roles);
       details.insert (Folks.PersonaStore.detail_key (PersonaDetail.ROLES),
@@ -461,7 +464,8 @@ public class AddPersonaTests : Folks.TestCase
       foreach (var r in i.roles)
         {
           if (r.title == this._title_1 &&
-              r.organisation_name == this._organisation_1)
+              r.organisation_name == this._organisation_1 &&
+              r.role == this._role_1)
             {
               this._properties_found.replace ("role-1", true);
             }
diff --git a/tests/tracker/role-details-interface.vala b/tests/tracker/role-details-interface.vala
index 17e7013..d1c3e19 100644
--- a/tests/tracker/role-details-interface.vala
+++ b/tests/tracker/role-details-interface.vala
@@ -56,7 +56,7 @@ public class RoleDetailsInterfaceTests : Folks.TestCase
       this._main_loop = new GLib.MainLoop (null, false);
       Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> ();
       this._fullname = "persona #1";
-      this._affiliaton = "boss,Company";
+      this._affiliaton = "boss,Company,Role";
 
       c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._fullname);
       c1.set (Trf.OntologyDefs.NCO_HAS_AFFILIATION, this._affiliaton);
@@ -112,7 +112,8 @@ public class RoleDetailsInterfaceTests : Folks.TestCase
               foreach (var role in i.roles)
                 {
                   if (role.title == "boss" &&
-                      role.organisation_name == "Company")
+                      role.organisation_name == "Company" &&
+                      role.role == "Role")
                     {
                       this._found_role = true;
                       this._main_loop.quit ();
diff --git a/tests/tracker/set-roles.vala b/tests/tracker/set-roles.vala
index 08f3b83..13858eb 100644
--- a/tests/tracker/set-roles.vala
+++ b/tests/tracker/set-roles.vala
@@ -60,6 +60,7 @@ public class SetRolesTests : Folks.TestCase
       this._tracker_backend.add_contact (c1);
 
       this._role = new Role ("some title", "some organisation");
+      this._role.role = "some role";
 
       this._tracker_backend.set_up ();
 
@@ -113,6 +114,7 @@ public class SetRolesTests : Folks.TestCase
               Gee.HashSet<Role> roles = new HashSet<Role>
                   ((GLib.HashFunc) Role.hash, (GLib.EqualFunc) Role.equal);
               var r = new Role ("some title", "some organisation");
+              r.role = "some role";
               roles.add ((owned) r);
 
               foreach (var p in i.personas)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]