Author: ieb
Date: Thu Sep 18 05:13:16 2008
New Revision: 696646

URL: http://svn.apache.org/viewvc?rev=696646&view=rev
Log:
Added Score to Friends object to support the concept of topFriends, started to 
sort out special cases for queries in the Person Service.

Modified:
    
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/FriendDb.java
    
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/spi/PersonServiceDb.java

Modified: 
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/FriendDb.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/FriendDb.java?rev=696646&r1=696645&r2=696646&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/FriendDb.java
 (original)
+++ 
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/FriendDb.java
 Thu Sep 18 05:13:16 2008
@@ -23,6 +23,7 @@
 import org.apache.shindig.social.opensocial.model.ListField;
 import org.apache.shindig.social.opensocial.model.Person;
 
+import javax.persistence.Basic;
 import javax.persistence.Column;
 import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
@@ -68,6 +69,10 @@
   @JoinColumn(name = "friend_id", referencedColumnName = "oid")
   protected Person friend;
 
+  @Basic
+  @Column(name="score")
+  protected int score;
+
   /**
    * The friendship has properties.
    */

Modified: 
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/spi/PersonServiceDb.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/spi/PersonServiceDb.java?rev=696646&r1=696645&r2=696646&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/spi/PersonServiceDb.java
 (original)
+++ 
incubator/shindig/trunk/java/samples/src/main/java/org/apache/shindig/social/opensocial/jpa/spi/PersonServiceDb.java
 Thu Sep 18 05:13:16 2008
@@ -43,8 +43,8 @@
 import java.util.concurrent.Future;
 
 /**
- * Implements the PersonService from the SPI binding to the JPA model and 
providing
- * queries to support the OpenSocial implementation.
+ * Implements the PersonService from the SPI binding to the JPA model and 
providing queries to
+ * support the OpenSocial implementation.
  */
 public class PersonServiceDb implements PersonService {
 
@@ -57,6 +57,7 @@
   /**
    * Create the PersonServiceDb, injecting an entity manager that is 
configured with the social
    * model.
+   * 
    * @param entityManager the entity manager containing the social model.
    */
   @Inject
@@ -114,7 +115,7 @@
       plist = getListQuery(sb.toString(), paramList, collectionOptions);
     }
     case friends: {
-      // select all friends
+      // select all friends (subset of contacts)
       StringBuilder sb = new StringBuilder();
       sb.append(PersonDb.JPQL_FINDPERSON_BY_FRIENDS);
       addInClause(sb, "id", paramList.size());
@@ -252,8 +253,22 @@
     int filterPos = 0;
     if (FilterSpecification.isValid(filter)) {
       if (FilterSpecification.isSpecial(filter)) {
-        if ("hasApp".equals(filter)) {
-        } else if ("topFriends".equals(filter)) {
+        if (PersonService.HAS_APP_FILTER.equals(filter)) {
+          // Retrieves all friends with any data for this application.
+          // TODO: how do we determine which application is being talked about
+        } else if (PersonService.TOP_FRIENDS_FILTER.equals(filter)) {
+          // Retrieves only the user's top friends, this is defined here by 
the implementation
+          // and there is an assumption that the sort order has already been 
applied.
+          // to do this we need to modify the collections options
+          // there will only ever b x friends in the list and it will only 
ever start at 1
+          collectionOptions.setFirst(1);
+          collectionOptions.setMax(20);
+          
+        } else if (PersonService.ALL_FILTER.equals(filter)) {
+           // select all, ie no filtering
+        } else if (PersonService.IS_WITH_FRIENDS_FILTER.equals(filter)) {
+          // all matches must also be friends with the value of the filter.
+
         }
       } else {
         sb.append("p.").append(filter);
@@ -290,14 +305,19 @@
   private void addOrderClause(StringBuilder sb, CollectionOptions 
collectionOptions) {
     String sortBy = collectionOptions.getSortBy();
     if (sortBy != null && sortBy.length() > 0) {
-      sb.append(" order by p.").append(sortBy);
-      switch (collectionOptions.getSortOrder()) {
-      case ascending:
-        sb.append(" asc ");
-        break;
-      case descending:
-        sb.append(" desc ");
-        break;
+      if (PersonService.TOP_FRIENDS_SORT.equals(sortBy)) {
+        // this assumes that the query is a join with the friends store.
+        sb.append(" order by f.score ");
+      } else {
+        sb.append(" order by p.").append(sortBy);
+        switch (collectionOptions.getSortOrder()) {
+        case ascending:
+          sb.append(" asc ");
+          break;
+        case descending:
+          sb.append(" desc ");
+          break;
+        }
       }
     }
   }


Reply via email to