r7140 - in dumbhippo/trunk/server/src/com/dumbhippo: persistence server server/dm server/impl
- From: commits mugshot org
- To: online-desktop-list gnome org
- Subject: r7140 - in dumbhippo/trunk/server/src/com/dumbhippo: persistence server server/dm server/impl
- Date: Mon, 7 Jan 2008 15:25:45 -0600 (CST)
Author: otaylor
Date: 2008-01-07 15:25:40 -0600 (Mon, 07 Jan 2008)
New Revision: 7140
Added:
dumbhippo/trunk/server/src/com/dumbhippo/server/dm/MusicChatBlockDMO.java
dumbhippo/trunk/server/src/com/dumbhippo/server/dm/MusicPersonBlockDMO.java
dumbhippo/trunk/server/src/com/dumbhippo/server/dm/TrackMessageDMO.java
Modified:
dumbhippo/trunk/server/src/com/dumbhippo/persistence/BlockType.java
dumbhippo/trunk/server/src/com/dumbhippo/server/MusicSystem.java
dumbhippo/trunk/server/src/com/dumbhippo/server/dm/BlockDMO.java
dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ChatMessageDMO.java
dumbhippo/trunk/server/src/com/dumbhippo/server/dm/DataService.java
dumbhippo/trunk/server/src/com/dumbhippo/server/impl/MusicSystemBean.java
Log:
MusicPersonBlockDMO MusicChatBlockDMO BlockDMO: Add music blocks
to the data model
TrackMessageDMO ChatMessageDMO: Add track messages to the data model
MusicSystem[Bean]: Add a method to get the track history in a feed-friendly
form (TrackHistory, with start/max/minTimestamp)
BlockType: Make MUSIC_PERSON block visibility PUBLIC rather than DELEGATE
Modified: dumbhippo/trunk/server/src/com/dumbhippo/persistence/BlockType.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/persistence/BlockType.java 2008-01-07 19:24:25 UTC (rev 7139)
+++ dumbhippo/trunk/server/src/com/dumbhippo/persistence/BlockType.java 2008-01-07 21:25:40 UTC (rev 7140)
@@ -74,7 +74,14 @@
MUSIC_PERSON { // 3
@Override
public BlockVisibility getBlockVisibility() {
- return BlockVisibility.DELEGATE;
+ // The rule we use elsewhere is "visible if the
+ // user has any track plays", but that doesn't fit into into any of
+ // our block visibility types. Using PUBLIC shouldn't in information
+ // leakage ... at worst, things might look a little funny. An alternative
+ // would be to use DELEGATE make the always-visible first track the
+ // delegate (requires fixing null-delegate == not-visible rather than
+ // the current NullPointerException)
+ return BlockVisibility.PUBLIC;
}
@Override
Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/MusicSystem.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/MusicSystem.java 2008-01-07 19:24:25 UTC (rev 7139)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/MusicSystem.java 2008-01-07 21:25:40 UTC (rev 7140)
@@ -40,6 +40,7 @@
public boolean hasTrackHistory(Viewpoint viewpoint, User user);
public List<TrackView> getLatestTrackViews(Viewpoint viewpoint, User user, int maxResults);
+ public List<TrackHistory> getLatestTracks(Viewpoint viewpoint, User user, int start, int max, long minTimestamp);
/**
* Returns a track view for a matching track.
Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/BlockDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/BlockDMO.java 2008-01-07 19:24:25 UTC (rev 7139)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/BlockDMO.java 2008-01-07 21:25:40 UTC (rev 7140)
@@ -85,21 +85,25 @@
case ACCOUNT_QUESTION:
return AccountQuestionBlockDMO.class;
- case POST:
- return PostBlockDMO.class;
+ case GROUP_CHAT:
+ return GroupChatBlockDMO.class;
+
+ case MUSIC_CHAT:
+ return MusicChatBlockDMO.class;
+ case MUSIC_PERSON:
+ return MusicPersonBlockDMO.class;
+
case PICASA_PERSON:
return PicasaPersonBlockDMO.class;
- case GROUP_CHAT:
- return GroupChatBlockDMO.class;
-
+ case POST:
+ return PostBlockDMO.class;
+
default:
case GROUP_MEMBER:
- case MUSIC_PERSON:
case FACEBOOK_EVENT:
case FLICKR_PHOTOSET:
- case MUSIC_CHAT:
case GROUP_REVISION:
case NETFLIX_MOVIE:
case AMAZON_REVIEW:
Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ChatMessageDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ChatMessageDMO.java 2008-01-07 19:24:25 UTC (rev 7139)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ChatMessageDMO.java 2008-01-07 21:25:40 UTC (rev 7140)
@@ -38,7 +38,7 @@
case GROUP:
return GroupMessageDMO.class;
case TRACK:
- return null;
+ return TrackMessageDMO.class;
}
return null;
Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/DataService.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/DataService.java 2008-01-07 19:24:25 UTC (rev 7139)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/DataService.java 2008-01-07 21:25:40 UTC (rev 7140)
@@ -91,6 +91,8 @@
model.addDMClass(BlockDMO.class);
model.addDMClass(AccountQuestionBlockDMO.class);
model.addDMClass(GroupChatBlockDMO.class);
+ model.addDMClass(MusicChatBlockDMO.class);
+ model.addDMClass(MusicPersonBlockDMO.class);
model.addDMClass(ThumbnailsBlockDMO.class);
model.addDMClass(PicasaPersonBlockDMO.class);
model.addDMClass(PostBlockDMO.class);
@@ -99,6 +101,7 @@
model.addDMClass(BlockMessageDMO.class);
model.addDMClass(GroupMessageDMO.class);
model.addDMClass(PostMessageDMO.class);
+ model.addDMClass(TrackMessageDMO.class);
model.addDMClass(ContactDMO.class);
model.addDMClass(DesktopSettingDMO.class);
Added: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/MusicChatBlockDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/MusicChatBlockDMO.java 2008-01-07 19:24:25 UTC (rev 7139)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/MusicChatBlockDMO.java 2008-01-07 21:25:40 UTC (rev 7140)
@@ -0,0 +1,22 @@
+package com.dumbhippo.server.dm;
+
+import com.dumbhippo.dm.annotations.DMO;
+import com.dumbhippo.dm.annotations.DMProperty;
+import com.dumbhippo.server.blocks.MusicChatBlockView;
+
+ DMO(classId="http://mugshot.org/p/o/musicPersonBlock")
+public abstract class MusicChatBlockDMO extends BlockDMO {
+ protected MusicChatBlockDMO(BlockDMOKey key) {
+ super(key);
+ }
+
+ @DMProperty(defaultInclude=true, defaultChildren="+")
+ public TrackDMO getTrack() {
+ return session.findUnchecked(TrackDMO.class, ((MusicChatBlockView)blockView).getTrack().getTrackHistory().getTrack().getId());
+ }
+
+ @DMProperty(defaultInclude=true)
+ public long getTrackPlayTime() {
+ return ((MusicChatBlockView)blockView).getTrack().getTrackHistory().getLastUpdated().getTime();
+ }
+}
Added: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/MusicPersonBlockDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/MusicPersonBlockDMO.java 2008-01-07 19:24:25 UTC (rev 7139)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/MusicPersonBlockDMO.java 2008-01-07 21:25:40 UTC (rev 7140)
@@ -0,0 +1,48 @@
+package com.dumbhippo.server.dm;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.ejb.EJB;
+
+import com.dumbhippo.dm.DMFeed;
+import com.dumbhippo.dm.DMFeedItem;
+import com.dumbhippo.dm.annotations.DMO;
+import com.dumbhippo.dm.annotations.DMProperty;
+import com.dumbhippo.persistence.TrackHistory;
+import com.dumbhippo.persistence.User;
+import com.dumbhippo.server.MusicSystem;
+import com.dumbhippo.server.blocks.MusicPersonBlockView;
+import com.dumbhippo.server.views.SystemViewpoint;
+
+ DMO(classId="http://mugshot.org/p/o/musicChatBlock")
+public abstract class MusicPersonBlockDMO extends BlockDMO {
+ @EJB
+ private MusicSystem musicSystem;
+
+ protected MusicPersonBlockDMO(BlockDMOKey key) {
+ super(key);
+ }
+
+ @DMProperty(defaultInclude=true, defaultChildren="+", defaultMaxFetch=5)
+ public DMFeed<TrackDMO> getTracks() {
+ return new TracksFeed();
+ }
+
+ private class TracksFeed implements DMFeed<TrackDMO> {
+ public Iterator<DMFeedItem<TrackDMO>> iterator(int start, int max, long minTimestamp) {
+ User user = ((MusicPersonBlockView)blockView).getPersonSource().getUser();
+
+ List<TrackHistory> tracks = musicSystem.getLatestTracks(SystemViewpoint.getInstance(), user, start, max, minTimestamp);
+
+ List<DMFeedItem<TrackDMO>> items = new ArrayList<DMFeedItem<TrackDMO>>();
+ for (TrackHistory track : tracks) {
+ TrackDMO trackDMO = session.findUnchecked(TrackDMO.class, track.getTrack().getId());
+ items.add(new DMFeedItem<TrackDMO>(trackDMO, track.getLastUpdated().getTime()));
+ }
+
+ return items.iterator();
+ }
+ }
+}
Added: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/TrackMessageDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/TrackMessageDMO.java 2008-01-07 19:24:25 UTC (rev 7139)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/TrackMessageDMO.java 2008-01-07 21:25:40 UTC (rev 7140)
@@ -0,0 +1,30 @@
+package com.dumbhippo.server.dm;
+
+import com.dumbhippo.dm.annotations.DMO;
+import com.dumbhippo.dm.store.StoreKey;
+import com.dumbhippo.persistence.TrackMessage;
+import com.dumbhippo.server.NotFoundException;
+
+ DMO(classId="http://mugshot.org/p/o/trackMessage")
+public abstract class TrackMessageDMO extends ChatMessageDMO {
+ protected TrackMessageDMO(ChatMessageKey key) {
+ super(key);
+ }
+
+ @Override
+ protected void init() throws NotFoundException {
+ message = em.find(TrackMessage.class, getKey().getId());
+ if (message == null)
+ throw new NotFoundException("No such track message");
+ }
+
+ @Override
+ public StoreKey<?,?> getVisibilityDelegate() {
+ // This is "pointless", since tracks are always visible. The reason for doing it this way
+ // is simply that we want to return some visible object. (null visibility delegate means
+ // "not visible", not "visible")
+
+ TrackDMO track = session.findUnchecked(TrackDMO.class, ((TrackMessage)message).getTrackHistory().getTrack().getId());
+ return track.getStoreKey();
+ }
+}
Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/MusicSystemBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/MusicSystemBean.java 2008-01-07 19:24:25 UTC (rev 7139)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/MusicSystemBean.java 2008-01-07 21:25:40 UTC (rev 7140)
@@ -281,7 +281,7 @@
}
public TrackHistory getCurrentTrack(Viewpoint viewpoint, User user) throws NotFoundException {
- List<TrackHistory> list = getTrackHistory(viewpoint, user, History.LATEST, 0, 1);
+ List<TrackHistory> list = getTrackHistory(viewpoint, user, History.LATEST, 0, 1, -1);
if (list.isEmpty())
throw new NotFoundException("No current track");
return list.get(0);
@@ -292,7 +292,7 @@
FREQUENT
}
- private List<TrackHistory> getTrackHistory(Viewpoint viewpoint, User user, History type, int firstResult, int maxResults) {
+ private List<TrackHistory> getTrackHistory(Viewpoint viewpoint, User user, History type, int firstResult, int maxResults, long minTimestamp) {
//logger.debug("getTrackHistory() type {} for {} max results " + maxResults, type, user);
if (!identitySpider.getMusicSharingEnabled(user, Enabled.AND_ACCOUNT_IS_ACTIVE)) {
@@ -313,9 +313,16 @@
break;
}
- q = em.createQuery("FROM TrackHistory h WHERE h.user = :user " +
- order);
+ String select;
+ if (minTimestamp > 0)
+ select = " AND h.lastUpdated >= :minTimestamp ";
+ else
+ select = "";
+
+ q = em.createQuery("FROM TrackHistory h WHERE h.user = :user " + select + order);
q.setParameter("user", user);
+ if (minTimestamp > 0)
+ q.setParameter("minTimestamp", minTimestamp);
q.setFirstResult(firstResult);
q.setMaxResults(maxResults);
@@ -868,10 +875,15 @@
public List<TrackView> getLatestTrackViews(Viewpoint viewpoint, User user, int maxResults) {
//logger.debug("getLatestTrackViews() for user {}", user);
- List<TrackHistory> history = getTrackHistory(viewpoint, user, History.LATEST, 0, maxResults);
+ List<TrackHistory> history = getTrackHistory(viewpoint, user, History.LATEST, 0, maxResults, -1);
return getViewsFromTrackHistories(viewpoint, history, false);
}
+ public List<TrackHistory> getLatestTracks(Viewpoint viewpoint, User user, int start, int max, long minTimestamp) {
+ return getTrackHistory(viewpoint, user, History.LATEST, start, max, minTimestamp);
+ }
+
+
private Query buildSongQuery(Viewpoint viewpoint, String artist, String album, String name, int maxResults) throws NotFoundException {
int count = 0;
if (artist != null)
@@ -1289,7 +1301,7 @@
}
public long getLatestPlayTime(Viewpoint viewpoint, User user) {
- List<TrackHistory> history = getTrackHistory(viewpoint, user, History.LATEST, 0, 1);
+ List<TrackHistory> history = getTrackHistory(viewpoint, user, History.LATEST, 0, 1, -1);
if (history.isEmpty())
return 0;
else
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]