Hi,

in OpenSocial (2.5.1) a Person can have multiple 'email' addresses. These
are simple Strings, and so in Shindig 'emails' is declared as
"List<ListField>".

In our application we want to extend the emails to include additional
information such as if/how often an email sent to that address has bounced.

>From what I can see there is currently no "proper" way of doing that apart
from patching Person itself.

What we have done now is to patch Shindig to provide an 'Email' type, which
is currently implemented as an empty extension of ListField(Impl). In our
guice modules we then inject our custom Email implementation.

The attached patch shows the changes in Shindig.

I'm not completely happy with that approach, but I also couldn't find
anything "better" that avoids duplicating a lot of information or code.

Do you have any suggestions on how to implement our use case, or would you
consider accepting the patch as an improvement for extensibility?

Regards,
--
Andreas
Index: 
java/social-api/src/main/java/org/apache/shindig/social/core/model/EmailImpl.java
===================================================================
--- 
java/social-api/src/main/java/org/apache/shindig/social/core/model/EmailImpl.java
   (revision 0)
+++ 
java/social-api/src/main/java/org/apache/shindig/social/core/model/EmailImpl.java
   (working copy)
@@ -0,0 +1,28 @@
+/*
+ * 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.core.model;
+
+import org.apache.shindig.social.opensocial.model.Email;
+
+public class EmailImpl extends ListFieldImpl implements Email {
+  public EmailImpl() { }
+  
+  public EmailImpl(String type, String value) {
+    super(type, value);
+  }
+}
Index: 
java/social-api/src/main/java/org/apache/shindig/social/core/model/PersonImpl.java
===================================================================
--- 
java/social-api/src/main/java/org/apache/shindig/social/core/model/PersonImpl.java
  (revision 1540645)
+++ 
java/social-api/src/main/java/org/apache/shindig/social/core/model/PersonImpl.java
  (working copy)
@@ -23,6 +23,7 @@
 import org.apache.shindig.social.opensocial.model.Address;
 import org.apache.shindig.social.opensocial.model.BodyType;
 import org.apache.shindig.social.opensocial.model.Drinker;
+import org.apache.shindig.social.opensocial.model.Email;
 import org.apache.shindig.social.opensocial.model.ListField;
 import org.apache.shindig.social.opensocial.model.LookingFor;
 import org.apache.shindig.social.opensocial.model.Name;
@@ -56,7 +57,7 @@
   private Address currentLocation;
   private String displayName;
   private Enum<Drinker> drinker;
-  private List<ListField> emails;
+  private List<Email> emails;
   private String ethnicity;
   private String fashion;
   private List<String> food;
@@ -240,11 +241,11 @@
     this.drinker = newDrinker;
   }
 
-  public List<ListField> getEmails() {
+  public List<Email> getEmails() {
     return emails;
   }
 
-  public void setEmails(List<ListField> emails) {
+  public void setEmails(List<Email> emails) {
     this.emails = emails;
   }
 
Index: 
java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Email.java
===================================================================
--- 
java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Email.java
 (revision 0)
+++ 
java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Email.java
 (working copy)
@@ -0,0 +1,32 @@
+/*
+ * 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 org.apache.shindig.social.core.model.EmailImpl;
+
+import com.google.inject.ImplementedBy;
+
+/**
+ * Email address
+ * 
+ * @author andreas
+ */
+@ImplementedBy(EmailImpl.class)
+public interface Email extends ListField {
+  /* In opensocial 'email' is a simple string, this class exists to enable 
external extensions. */
+}
Index: 
java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Person.java
===================================================================
--- 
java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Person.java
        (revision 1540645)
+++ 
java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Person.java
        (working copy)
@@ -470,7 +470,7 @@
    *
    * @return a list of the person's emails
    */
-  List<ListField> getEmails();
+  List<Email> getEmails();
 
   /**
    * Set the person's Emails associated with the person.
@@ -478,7 +478,7 @@
    *
    * @param emails a list of the person's emails
    */
-  void setEmails(List<ListField> emails);
+  void setEmails(List<Email> emails);
 
   /**
    * Get the person's ethnicity, specified as a string. Container support for 
this field is
Index: 
java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonPeopleTest.java
===================================================================
--- 
java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonPeopleTest.java
  (revision 1540645)
+++ 
java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonPeopleTest.java
  (working copy)
@@ -27,6 +27,7 @@
 import org.apache.shindig.protocol.model.EnumImpl;
 import org.apache.shindig.social.core.model.AddressImpl;
 import org.apache.shindig.social.core.model.BodyTypeImpl;
+import org.apache.shindig.social.core.model.EmailImpl;
 import org.apache.shindig.social.core.model.ListFieldImpl;
 import org.apache.shindig.social.core.model.NameImpl;
 import org.apache.shindig.social.core.model.OrganizationImpl;
@@ -35,6 +36,7 @@
 import org.apache.shindig.social.opensocial.model.Address;
 import org.apache.shindig.social.opensocial.model.BodyType;
 import org.apache.shindig.social.opensocial.model.Drinker;
+import org.apache.shindig.social.opensocial.model.Email;
 import org.apache.shindig.social.opensocial.model.ListField;
 import org.apache.shindig.social.opensocial.model.LookingFor;
 import org.apache.shindig.social.opensocial.model.Name;
@@ -100,7 +102,7 @@
 
     canonical.setBirthday(new Date());
     canonical.setDrinker(new EnumImpl<Drinker>(Drinker.SOCIALLY));
-    ListField email = new ListFieldImpl("work", "dev@shindig.apache.org");
+    Email email = new EmailImpl("work", "dev@shindig.apache.org");
     canonical.setEmails(Lists.newArrayList(email));
 
     canonical.setEthnicity("developer");
Index: 
java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlPeopleTest.java
===================================================================
--- 
java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlPeopleTest.java
   (revision 1540645)
+++ 
java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlPeopleTest.java
   (working copy)
@@ -22,6 +22,7 @@
 import org.apache.shindig.protocol.model.EnumImpl;
 import org.apache.shindig.social.core.model.AddressImpl;
 import org.apache.shindig.social.core.model.BodyTypeImpl;
+import org.apache.shindig.social.core.model.EmailImpl;
 import org.apache.shindig.social.core.model.ListFieldImpl;
 import org.apache.shindig.social.core.model.NameImpl;
 import org.apache.shindig.social.core.model.OrganizationImpl;
@@ -30,6 +31,7 @@
 import org.apache.shindig.social.opensocial.model.Address;
 import org.apache.shindig.social.opensocial.model.BodyType;
 import org.apache.shindig.social.opensocial.model.Drinker;
+import org.apache.shindig.social.opensocial.model.Email;
 import org.apache.shindig.social.opensocial.model.ListField;
 import org.apache.shindig.social.opensocial.model.LookingFor;
 import org.apache.shindig.social.opensocial.model.Name;
@@ -102,7 +104,7 @@
 
     canonical.setBirthday(new Date());
     canonical.setDrinker(new EnumImpl<Drinker>(Drinker.SOCIALLY));
-    ListField email = new ListFieldImpl("work",
+    Email email = new EmailImpl("work",
         "dev@shindig.apache.org");
     canonical.setEmails(Lists.newArrayList(email));
 
Index: 
java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamAtomConverterTest.java
===================================================================
--- 
java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamAtomConverterTest.java
   (revision 1540645)
+++ 
java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamAtomConverterTest.java
   (working copy)
@@ -28,6 +28,7 @@
 import org.apache.shindig.social.SocialApiTestsGuiceModule;
 import org.apache.shindig.social.core.model.ActivityImpl;
 import org.apache.shindig.social.core.model.AddressImpl;
+import org.apache.shindig.social.core.model.EmailImpl;
 import org.apache.shindig.social.core.model.ListFieldImpl;
 import org.apache.shindig.social.core.model.MediaItemImpl;
 import org.apache.shindig.social.core.model.NameImpl;
@@ -36,6 +37,7 @@
 import org.apache.shindig.social.core.util.xstream.XStream081Configuration;
 import org.apache.shindig.social.opensocial.model.Activity;
 import org.apache.shindig.social.opensocial.model.Address;
+import org.apache.shindig.social.opensocial.model.Email;
 import org.apache.shindig.social.opensocial.model.ListField;
 import org.apache.shindig.social.opensocial.model.MediaItem;
 import org.apache.shindig.social.opensocial.model.Person;
@@ -69,8 +71,8 @@
     johnDoe.setAddresses(Lists.<Address> newArrayList(new AddressImpl(
         "My home address")));
 
-    johnDoe.setEmails(Lists.<ListField> newArrayList(new ListFieldImpl("work",
-        "john....@work.bar"), new ListFieldImpl("home", "john....@home.bar")));
+    johnDoe.setEmails(Lists.<Email> newArrayList(new EmailImpl("work",
+        "john....@work.bar"), new EmailImpl("home", "john....@home.bar")));
 
     activity = new ActivityImpl("activityId", johnDoe.getId());
 
Index: 
java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamConverterTest.java
===================================================================
--- 
java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamConverterTest.java
       (revision 1540645)
+++ 
java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamConverterTest.java
       (working copy)
@@ -25,6 +25,7 @@
 import org.apache.shindig.social.SocialApiTestsGuiceModule;
 import org.apache.shindig.social.core.model.ActivityImpl;
 import org.apache.shindig.social.core.model.AddressImpl;
+import org.apache.shindig.social.core.model.EmailImpl;
 import org.apache.shindig.social.core.model.ListFieldImpl;
 import org.apache.shindig.social.core.model.MediaItemImpl;
 import org.apache.shindig.social.core.model.NameImpl;
@@ -32,6 +33,7 @@
 import org.apache.shindig.social.core.util.xstream.XStream081Configuration;
 import org.apache.shindig.social.opensocial.model.Activity;
 import org.apache.shindig.social.opensocial.model.Address;
+import org.apache.shindig.social.opensocial.model.Email;
 import org.apache.shindig.social.opensocial.model.ListField;
 import org.apache.shindig.social.opensocial.model.MediaItem;
 import org.apache.shindig.social.opensocial.model.Person;
@@ -77,8 +79,8 @@
     johnDoe.setAddresses(Lists.<Address> newArrayList(new AddressImpl(
         "My home address")));
 
-    johnDoe.setEmails(Lists.<ListField> newArrayList(new ListFieldImpl("work",
-        "john....@work.bar"), new ListFieldImpl("home", "john....@home.bar")));
+    johnDoe.setEmails(Lists.<Email> newArrayList(new EmailImpl("work",
+        "john....@work.bar"), new EmailImpl("home", "john....@home.bar")));
 
     activity = new ActivityImpl("activityId", johnDoe.getId());
     activity.setUrl("http://foo.com/";);

Reply via email to