You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by wo...@apache.org on 2011/06/03 17:37:36 UTC
svn commit: r1131076 - in
/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social:
core/model/ActivityEntryImpl.java opensocial/model/ActivityEntry.java
sample/spi/JsonDbOpensocialService.java
Author: woodser
Date: Fri Jun 3 15:37:35 2011
New Revision: 1131076
URL: http://svn.apache.org/viewvc?rev=1131076&view=rev
Log:
Committing patch to sort Activity Streams in descending order by publish date: https://issues.apache.org/jira/browse/SHINDIG-1544
Modified:
shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/model/ActivityEntryImpl.java
shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/ActivityEntry.java
shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java
Modified: shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/model/ActivityEntryImpl.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/model/ActivityEntryImpl.java?rev=1131076&r1=1131075&r2=1131076&view=diff
==============================================================================
--- shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/model/ActivityEntryImpl.java (original)
+++ shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/model/ActivityEntryImpl.java Fri Jun 3 15:37:35 2011
@@ -185,4 +185,23 @@ public class ActivityEntryImpl implement
public void setOpenSocial(Extension openSocial) {
this.openSocial = openSocial;
}
+
+ /**
+ * Sorts ActivityEntries in ascending order based on publish date.
+ *
+ * @param that is the ActivityEntry to compare to this ActivityEntry
+ *
+ * @return int represents how the ActivityEntries compare
+ */
+ public int compareTo(ActivityEntry that) {
+ if (this.getPublished() == null && that.getPublished() == null) {
+ return 0; // both are null, equal
+ } else if (this.getPublished() == null) {
+ return -1; // this is null, comes before real date
+ } else if (that.getPublished() == null) {
+ return 1; // that is null, this comes after
+ } else { // compare publish dates in lexicographical order
+ return this.getPublished().compareTo(that.getPublished());
+ }
+ }
}
Modified: shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/ActivityEntry.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/ActivityEntry.java?rev=1131076&r1=1131075&r2=1131076&view=diff
==============================================================================
--- shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/ActivityEntry.java (original)
+++ shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/ActivityEntry.java Fri Jun 3 15:37:35 2011
@@ -29,7 +29,7 @@ import com.google.inject.ImplementedBy;
*/
@ImplementedBy(ActivityEntryImpl.class)
@Exportablebean
-public interface ActivityEntry {
+public interface ActivityEntry extends Comparable<ActivityEntry> {
/**
* Fields that represent the JSON elements.
Modified: shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java?rev=1131076&r1=1131075&r2=1131076&view=diff
==============================================================================
--- shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java (original)
+++ shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java Fri Jun 3 15:37:35 2011
@@ -24,6 +24,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeSet;
import java.util.concurrent.Future;
import javax.servlet.http.HttpServletResponse;
@@ -39,7 +40,6 @@ import org.apache.shindig.protocol.conve
import org.apache.shindig.protocol.model.SortOrder;
import org.apache.shindig.social.opensocial.model.Activity;
import org.apache.shindig.social.opensocial.model.ActivityEntry;
-import org.apache.shindig.social.opensocial.model.ActivityObject;
import org.apache.shindig.social.opensocial.model.Album;
import org.apache.shindig.social.opensocial.model.MediaItem;
import org.apache.shindig.social.opensocial.model.Message;
@@ -1282,7 +1282,6 @@ public class JsonDbOpensocialService imp
}
}
}
-
throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST, "Activity not found: " + activityId);
} catch (JSONException je) {
throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(), je);
@@ -1307,6 +1306,7 @@ public class JsonDbOpensocialService imp
}
}
}
+ Collections.sort(result, Collections.reverseOrder());
return ImmediateFuture.newInstance(new RestfulCollection<ActivityEntry>(result));
} catch (JSONException je) {
throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(), je);
@@ -1338,6 +1338,7 @@ public class JsonDbOpensocialService imp
}
}
}
+ Collections.sort(result, Collections.reverseOrder());
return ImmediateFuture.newInstance(new RestfulCollection<ActivityEntry>(result));
} catch (JSONException je) {
throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(), je);