r7148 - dumbhippo/trunk/server/src/com/dumbhippo/server/dm
- From: commits mugshot org
- To: online-desktop-list gnome org
- Subject: r7148 - dumbhippo/trunk/server/src/com/dumbhippo/server/dm
- Date: Tue, 8 Jan 2008 11:48:11 -0600 (CST)
Author: otaylor
Date: 2008-01-08 11:48:11 -0600 (Tue, 08 Jan 2008)
New Revision: 7148
Added:
dumbhippo/trunk/server/src/com/dumbhippo/server/dm/AmazonReviewBlockDMO.java
dumbhippo/trunk/server/src/com/dumbhippo/server/dm/AmazonWishListItemBlockDMO.java
dumbhippo/trunk/server/src/com/dumbhippo/server/dm/NetflixMovieBlockDMO.java
dumbhippo/trunk/server/src/com/dumbhippo/server/dm/NetflixMovieDMO.java
dumbhippo/trunk/server/src/com/dumbhippo/server/dm/NetflixMovieKey.java
Modified:
dumbhippo/trunk/server/src/com/dumbhippo/server/dm/BlockDMO.java
dumbhippo/trunk/server/src/com/dumbhippo/server/dm/DataService.java
Log:
NetflixMovieBLockDMO NetflixMovieDMO NetflixMovieKey.java BlockDMO DataService:
Export netflix blocks via data model
AmazonWishListItemBlockDMO AmazonReviewBlockDMO BlockDMO DataService:
Export amazon blocks via data model
Added: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/AmazonReviewBlockDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/AmazonReviewBlockDMO.java 2008-01-08 17:11:13 UTC (rev 7147)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/AmazonReviewBlockDMO.java 2008-01-08 17:48:11 UTC (rev 7148)
@@ -0,0 +1,38 @@
+package com.dumbhippo.server.dm;
+
+import com.dumbhippo.dm.annotations.DMO;
+import com.dumbhippo.dm.annotations.DMProperty;
+import com.dumbhippo.dm.annotations.PropertyType;
+import com.dumbhippo.server.blocks.AmazonActivityBlockView;
+
+ DMO(classId="http://mugshot.org/p/o/amazonReviewBlock")
+public abstract class AmazonReviewBlockDMO extends BlockDMO {
+ protected AmazonReviewBlockDMO(BlockDMOKey key) {
+ super(key);
+ }
+
+ @DMProperty(defaultInclude=true, type=PropertyType.URL)
+ public String getImageUrl() {
+ return ((AmazonActivityBlockView)blockView).getImageUrl();
+ }
+
+ @DMProperty(defaultInclude=true)
+ public int getImageWidth() {
+ return ((AmazonActivityBlockView)blockView).getImageWidth();
+ }
+
+ @DMProperty(defaultInclude=true)
+ public int getImageHeight() {
+ return ((AmazonActivityBlockView)blockView).getImageHeight();
+ }
+
+ @DMProperty(defaultInclude=true)
+ public String getReviewTitle() {
+ return ((AmazonActivityBlockView)blockView).getReviewTitle();
+ }
+
+ @DMProperty(defaultInclude=true)
+ public int getReviewRating() {
+ return ((AmazonActivityBlockView)blockView).getReviewRating();
+ }
+}
Added: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/AmazonWishListItemBlockDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/AmazonWishListItemBlockDMO.java 2008-01-08 17:11:13 UTC (rev 7147)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/AmazonWishListItemBlockDMO.java 2008-01-08 17:48:11 UTC (rev 7148)
@@ -0,0 +1,43 @@
+package com.dumbhippo.server.dm;
+
+import com.dumbhippo.dm.annotations.DMO;
+import com.dumbhippo.dm.annotations.DMProperty;
+import com.dumbhippo.dm.annotations.PropertyType;
+import com.dumbhippo.server.blocks.AmazonActivityBlockView;
+
+ DMO(classId="http://mugshot.org/p/o/amazonReviewBlock")
+public abstract class AmazonWishListItemBlockDMO extends BlockDMO {
+ protected AmazonWishListItemBlockDMO(BlockDMOKey key) {
+ super(key);
+ }
+
+ @DMProperty(defaultInclude=true, type=PropertyType.URL)
+ public String getImageUrl() {
+ return ((AmazonActivityBlockView)blockView).getImageUrl();
+ }
+
+ @DMProperty(defaultInclude=true)
+ public int getImageWidth() {
+ return ((AmazonActivityBlockView)blockView).getImageWidth();
+ }
+
+ @DMProperty(defaultInclude=true)
+ public int getImageHeight() {
+ return ((AmazonActivityBlockView)blockView).getImageHeight();
+ }
+
+ @DMProperty(defaultInclude=true)
+ public String getListName() {
+ return ((AmazonActivityBlockView)blockView).getListName();
+ }
+
+ @DMProperty(defaultInclude=true, type=PropertyType.URL)
+ public String getListLink() {
+ return ((AmazonActivityBlockView)blockView).getListLink();
+ }
+
+ @DMProperty(defaultInclude=true)
+ public String getComment() {
+ return ((AmazonActivityBlockView)blockView).getListItemComment();
+ }
+}
Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/BlockDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/BlockDMO.java 2008-01-08 17:11:13 UTC (rev 7147)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/BlockDMO.java 2008-01-08 17:48:11 UTC (rev 7148)
@@ -85,6 +85,12 @@
case ACCOUNT_QUESTION:
return AccountQuestionBlockDMO.class;
+ case AMAZON_REVIEW:
+ return AmazonReviewBlockDMO.class;
+
+ case AMAZON_WISH_LIST_ITEM:
+ return AmazonWishListItemBlockDMO.class;
+
case GROUP_CHAT:
return GroupChatBlockDMO.class;
@@ -94,6 +100,9 @@
case MUSIC_PERSON:
return MusicPersonBlockDMO.class;
+ case NETFLIX_MOVIE:
+ return NetflixMovieBlockDMO.class;
+
case PICASA_PERSON:
return PicasaPersonBlockDMO.class;
@@ -105,9 +114,6 @@
case FACEBOOK_EVENT:
case FLICKR_PHOTOSET:
case GROUP_REVISION:
- case NETFLIX_MOVIE:
- case AMAZON_REVIEW:
- case AMAZON_WISH_LIST_ITEM:
case OBSOLETE_EXTERNAL_ACCOUNT_UPDATE:
case OBSOLETE_EXTERNAL_ACCOUNT_UPDATE_SELF:
case OBSOLETE_BLOG_PERSON:
Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/DataService.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/DataService.java 2008-01-08 17:11:13 UTC (rev 7147)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/DataService.java 2008-01-08 17:48:11 UTC (rev 7148)
@@ -90,9 +90,12 @@
model.addDMClass(BlockDMO.class);
model.addDMClass(AccountQuestionBlockDMO.class);
+ model.addDMClass(AmazonWishListItemBlockDMO.class);
+ model.addDMClass(AmazonReviewBlockDMO.class);
model.addDMClass(GroupChatBlockDMO.class);
model.addDMClass(MusicChatBlockDMO.class);
model.addDMClass(MusicPersonBlockDMO.class);
+ model.addDMClass(NetflixMovieBlockDMO.class);
model.addDMClass(ThumbnailsBlockDMO.class);
model.addDMClass(PicasaPersonBlockDMO.class);
model.addDMClass(PostBlockDMO.class);
@@ -108,6 +111,7 @@
model.addDMClass(ExternalAccountDMO.class);
model.addDMClass(GroupDMO.class);
model.addDMClass(PostDMO.class);
+ model.addDMClass(NetflixMovieDMO.class);
model.addDMClass(ThumbnailDMO.class);
model.addDMClass(PicasaAlbumThumbnailDMO.class);
Added: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/NetflixMovieBlockDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/NetflixMovieBlockDMO.java 2008-01-08 17:11:13 UTC (rev 7147)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/NetflixMovieBlockDMO.java 2008-01-08 17:48:11 UTC (rev 7148)
@@ -0,0 +1,35 @@
+package com.dumbhippo.server.dm;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.dumbhippo.dm.annotations.DMO;
+import com.dumbhippo.dm.annotations.DMProperty;
+import com.dumbhippo.dm.annotations.PropertyType;
+import com.dumbhippo.persistence.User;
+import com.dumbhippo.server.blocks.NetflixBlockView;
+import com.dumbhippo.services.NetflixMovieView;
+
+ DMO(classId="http://mugshot.org/p/o/netflixMovieBlock")
+public abstract class NetflixMovieBlockDMO extends BlockDMO {
+ protected NetflixMovieBlockDMO(BlockDMOKey key) {
+ super(key);
+ }
+
+ @DMProperty(defaultInclude=true, type=PropertyType.URL)
+ public String getImageUrl() {
+ return ((NetflixBlockView)blockView).getImageUrl();
+ }
+
+ @DMProperty(defaultInclude=true, defaultChildren="+")
+ public List<NetflixMovieDMO> getQueuedMovies() {
+ User user = ((NetflixBlockView)blockView).getPersonSource().getUser();
+ List<NetflixMovieDMO> result = new ArrayList<NetflixMovieDMO>();
+
+ for (NetflixMovieView movie : ((NetflixBlockView)blockView).getQueuedMovies().getMovies()) {
+ result.add(session.findUnchecked(NetflixMovieDMO.class, NetflixMovieDMO.getKey(user, movie)));
+ }
+
+ return result;
+ }
+}
Added: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/NetflixMovieDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/NetflixMovieDMO.java 2008-01-08 17:11:13 UTC (rev 7147)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/NetflixMovieDMO.java 2008-01-08 17:48:11 UTC (rev 7148)
@@ -0,0 +1,96 @@
+package com.dumbhippo.server.dm;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.ejb.EJB;
+
+import com.dumbhippo.dm.DMObject;
+import com.dumbhippo.dm.annotations.DMO;
+import com.dumbhippo.dm.annotations.DMProperty;
+import com.dumbhippo.dm.annotations.PropertyType;
+import com.dumbhippo.persistence.ExternalAccount;
+import com.dumbhippo.persistence.ExternalAccountType;
+import com.dumbhippo.persistence.User;
+import com.dumbhippo.server.ExternalAccountSystem;
+import com.dumbhippo.server.IdentitySpider;
+import com.dumbhippo.server.NotFoundException;
+import com.dumbhippo.server.views.SystemViewpoint;
+import com.dumbhippo.services.NetflixMovieView;
+import com.dumbhippo.services.NetflixMoviesView;
+import com.dumbhippo.services.caches.NetflixQueueMoviesCache;
+import com.dumbhippo.services.caches.WebServiceCache;
+
+ DMO(classId="http://mugshot.org/p/o/netflixMovie", resourceBase="/o/netflixMovie")
+public abstract class NetflixMovieDMO extends DMObject<NetflixMovieKey> {
+ private NetflixMovieView movie;
+
+ @WebServiceCache
+ private NetflixQueueMoviesCache moviesCache;
+
+ @EJB
+ private ExternalAccountSystem externalAccountSystem;
+
+ @EJB
+ private IdentitySpider identitySpider;
+
+ protected NetflixMovieDMO(NetflixMovieKey key) {
+ super(key);
+ }
+
+ private static Pattern NETFLIX_URL_PATTERN = Pattern.compile("http://www.netflix.com/Movie/(?:[A-Za-z0-9_]+)/([0-9]+)(?:\\?.*)?");
+
+ private static String extractExtra(String url) {
+ Matcher m = NETFLIX_URL_PATTERN.matcher(url);
+ if (m.matches())
+ return m.group(1);
+ else
+ throw new RuntimeException("Cannot extract key from Netflix URL '" + url + "'");
+ }
+
+ @Override
+ protected void init() throws NotFoundException {
+ movie = (NetflixMovieView)getKey().getObject();
+ if (movie != null)
+ return;
+
+ User user = identitySpider.lookupUser(getKey().getUserId());
+
+ ExternalAccount netflixAccount =
+ externalAccountSystem.lookupExternalAccount(SystemViewpoint.getInstance(), user, ExternalAccountType.NETFLIX);
+
+ NetflixMoviesView moviesView = moviesCache.getSync(netflixAccount.getHandle());
+ for (NetflixMovieView m : moviesView.getMovies()) {
+ if (extractExtra(m.getUrl()).equals(getKey().getExtra())) {
+ movie = m;
+ }
+ }
+
+ if (movie == null)
+ throw new NotFoundException("Movie not found for user=" + user + " extra=" + getKey().getExtra());
+ }
+
+ @DMProperty(defaultInclude=true)
+ public String getDescription() {
+ return movie.getDescription();
+ }
+
+ @DMProperty(defaultInclude=true)
+ public int getPriority() {
+ return movie.getPriority();
+ }
+
+ @DMProperty(defaultInclude=true)
+ public String getTitle() {
+ return movie.getTitle();
+ }
+
+ @DMProperty(defaultInclude=true, type=PropertyType.URL)
+ public String getUrl() {
+ return movie.getUrl();
+ }
+
+ public static NetflixMovieKey getKey(User user, NetflixMovieView movie) {
+ return new NetflixMovieKey(user.getGuid(), extractExtra(movie.getUrl()), movie);
+ }
+}
Added: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/NetflixMovieKey.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/NetflixMovieKey.java 2008-01-08 17:11:13 UTC (rev 7147)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/NetflixMovieKey.java 2008-01-08 17:48:11 UTC (rev 7148)
@@ -0,0 +1,79 @@
+package com.dumbhippo.server.dm;
+
+import com.dumbhippo.dm.BadIdException;
+import com.dumbhippo.dm.DMKey;
+import com.dumbhippo.identity20.Guid;
+import com.dumbhippo.identity20.Guid.ParseException;
+
+public class NetflixMovieKey implements DMKey {
+ private static final long serialVersionUID = 2258099192938259545L;
+
+ private transient Object object;
+ private Guid userId;
+ private String extra;
+
+ public NetflixMovieKey(String keyString) throws BadIdException {
+ if (keyString.length() > 15 && keyString.charAt(14) == '.') {
+ try {
+ userId = new Guid(keyString.substring(0, 14));
+ } catch (ParseException e) {
+ throw new BadIdException("Bad GUID type in external account ID", e);
+ }
+ } else {
+ throw new BadIdException("Bad thumbnail resource ID");
+ }
+
+ extra = keyString.substring(15);
+ }
+
+ public NetflixMovieKey(Guid userId, String extra) {
+ this.userId = userId;
+ this.extra = extra;
+ }
+
+ public NetflixMovieKey(Guid userId, String extra, Object object) {
+ this.userId = userId;
+ this.extra = extra;
+ this.object = object;
+ }
+
+ public Object getObject() {
+ return object;
+ }
+
+ public String getExtra() {
+ return extra;
+ }
+
+ public Guid getUserId() {
+ return userId;
+ }
+
+ @Override
+ public NetflixMovieKey clone() {
+ if (object != null)
+ return new NetflixMovieKey(userId, extra);
+ else
+ return this;
+ }
+
+ @Override
+ public int hashCode() {
+ return userId.hashCode() * 11 + extra.hashCode() * 17;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (!(o instanceof NetflixMovieKey))
+ return false;
+
+ NetflixMovieKey other = (NetflixMovieKey)o;
+
+ return userId.equals(other.userId) && extra.equals(other.extra);
+ }
+
+ @Override
+ public String toString() {
+ return userId.toString() + "." + extra;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]