You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by do...@apache.org on 2008/07/29 02:35:36 UTC

svn commit: r680583 - in /incubator/shindig/trunk/java/social-api/src: main/java/org/apache/shindig/social/opensocial/model/ main/java/org/apache/shindig/social/opensocial/service/ test/java/org/apache/shindig/social/opensocial/model/

Author: doll
Date: Mon Jul 28 17:35:34 2008
New Revision: 680583

URL: http://svn.apache.org/viewvc?rev=680583&view=rev
Log:
Added a helper method to Person.Field to translate from url strings into the Person.Field enum. 

Fixed the PersonHandler to point to the Person.Field default fields enum instead of having a local copy.


Added:
    incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/model/
    incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/model/PersonTest.java
Modified:
    incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Person.java
    incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/PersonHandler.java

Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Person.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Person.java?rev=680583&r1=680582&r2=680583&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Person.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Person.java Mon Jul 28 17:35:34 2008
@@ -20,10 +20,12 @@
 import org.apache.shindig.social.core.model.PersonImpl;
 
 import com.google.inject.ImplementedBy;
+import com.google.common.collect.Maps;
 
 import java.util.Date;
 import java.util.List;
 import java.util.Set;
+import java.util.Map;
 
 /**
  * see http://code.google.com/apis/opensocial/docs/0.8/reference/#opensocial.Person.Field for all
@@ -154,7 +156,7 @@
     /**
      * The json field that the instance represents.
      */
-    private final String jsonString;
+    private final String urlString;
 
     /**
      * The set of required fields.
@@ -167,13 +169,15 @@
      */
     public static final Set<String> ALL_FIELDS = EnumUtil.getEnumStrings(Field.values());
 
+    private static Map<String, Field> URL_STRING_TO_FIELD_MAP;
+
     /**
      * create a field base on the a json element.
      *
-     * @param jsonString the name of the element
+     * @param urlString the name of the element
      */
-    private Field(String jsonString) {
-      this.jsonString = jsonString;
+    private Field(String urlString) {
+      this.urlString = urlString;
     }
 
     /**
@@ -183,7 +187,24 @@
      */
     @Override
     public String toString() {
-      return this.jsonString;
+      return this.urlString;
+    }
+
+    /**
+     * Converts from a url string (usually passed in the fields= parameter) into the
+     * corresponding field enum.
+     * @param urlString The string to translate.
+     * @return The corresponding person field.
+     */
+    public static Person.Field fromUrlString(String urlString) {
+      if (URL_STRING_TO_FIELD_MAP == null) {
+        URL_STRING_TO_FIELD_MAP = Maps.newHashMap();
+        for (Person.Field field : Person.Field.values()) {
+          URL_STRING_TO_FIELD_MAP.put(field.toString(), field);
+        }
+      }
+
+      return URL_STRING_TO_FIELD_MAP.get(urlString);
     }
   }
 

Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/PersonHandler.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/PersonHandler.java?rev=680583&r1=680582&r2=680583&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/PersonHandler.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/service/PersonHandler.java Mon Jul 28 17:35:34 2008
@@ -36,10 +36,6 @@
   private PersonService personService;
 
   private static final String PEOPLE_PATH = "/people/{userId}/{groupId}/{personId}";
-  protected static final Set<String> DEFAULT_PERSON_FIELDS = Sets.newHashSet(
-      Person.Field.ID.toString(),
-      Person.Field.NAME.toString(),
-      Person.Field.THUMBNAIL_URL.toString());
 
   @Inject
   public PersonHandler(PersonService personService) {
@@ -75,7 +71,7 @@
     UserId userId = request.getUser();
     GroupId groupId = request.getGroup();
     String optionalPersonId = request.getParameters().get("personId");
-    Set<String> fields = request.getFields(DEFAULT_PERSON_FIELDS);
+    Set<String> fields = request.getFields(Person.Field.DEFAULT_FIELDS);
 
     if (groupId.getType() == GroupId.Type.self) {
       return personService.getPerson(userId, fields, request.getToken());

Added: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/model/PersonTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/model/PersonTest.java?rev=680583&view=auto
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/model/PersonTest.java (added)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/model/PersonTest.java Mon Jul 28 17:35:34 2008
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.shindig.social.opensocial.model;
+
+import junit.framework.TestCase;
+
+public class PersonTest extends TestCase {
+
+  public void testInvalidFromUrlString() throws Exception {
+    assertNull(Person.Field.fromUrlString("badness"));
+  }
+
+  public void testFromUrlString() throws Exception {
+    assertUrlStringMaps(Person.Field.NAME);
+    assertUrlStringMaps(Person.Field.THUMBNAIL_URL);
+  }
+
+  private void assertUrlStringMaps(Person.Field field) {
+    assertEquals(field, Person.Field.fromUrlString(field.toString()));
+  }
+
+}
\ No newline at end of file