r7034 - dumbhippo/trunk/server/src/com/dumbhippo/server/dm
- From: commits mugshot org
- To: online-desktop-list gnome org
- Subject: r7034 - dumbhippo/trunk/server/src/com/dumbhippo/server/dm
- Date: Tue, 11 Dec 2007 18:51:16 -0600 (CST)
Author: otaylor
Date: 2007-12-11 18:51:15 -0600 (Tue, 11 Dec 2007)
New Revision: 7034
Added:
dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ThumbnailType.java
Modified:
dumbhippo/trunk/server/src/com/dumbhippo/server/dm/BlockDMOKey.java
dumbhippo/trunk/server/src/com/dumbhippo/server/dm/PicasaAlbumThumbnailDMO.java
dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ThumbnailDMO.java
dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ThumbnailKey.java
dumbhippo/trunk/server/src/com/dumbhippo/server/dm/YouTubeThumbnailDMO.java
Log:
ThumbnailType ThumbnailKey YouTubeThumbnailDMO PicasaAlbumThumnailDMO:
Add the type of the thumbnail to ThumbnailKey
ThumbnailDMO: Add a @MetaConstruct so that reconstruction from cached
data works
BlockDMOKey.java: Fix a cut-and-pasted error message
Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/BlockDMOKey.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/BlockDMOKey.java 2007-12-12 00:02:18 UTC (rev 7033)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/BlockDMOKey.java 2007-12-12 00:51:15 UTC (rev 7034)
@@ -30,7 +30,7 @@
try {
type = BlockType.valueOf(keyString.substring(15));
} catch (IllegalArgumentException e) {
- throw new BadIdException("Bad external account type in ID", e);
+ throw new BadIdException("Bad block type in ID", e);
}
} else {
throw new BadIdException("Bad external account resource ID");
Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/PicasaAlbumThumbnailDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/PicasaAlbumThumbnailDMO.java 2007-12-12 00:02:18 UTC (rev 7033)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/PicasaAlbumThumbnailDMO.java 2007-12-12 00:51:15 UTC (rev 7034)
@@ -66,11 +66,11 @@
}
}
- throw new NotFoundException("Can't find video");
+ throw new NotFoundException("Can't find album");
}
}
public static ThumbnailKey getKey(User user, PicasaAlbum album) {
- return new ThumbnailKey(user.getGuid(), extractExtra(album.getThumbnailHref()), album);
+ return new ThumbnailKey(user.getGuid(), ThumbnailType.PICASA_ALBUM, extractExtra(album.getThumbnailHref()), album);
}
}
Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ThumbnailDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ThumbnailDMO.java 2007-12-12 00:02:18 UTC (rev 7033)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ThumbnailDMO.java 2007-12-12 00:51:15 UTC (rev 7034)
@@ -4,6 +4,7 @@
import com.dumbhippo.dm.DMObject;
import com.dumbhippo.dm.annotations.DMO;
import com.dumbhippo.dm.annotations.DMProperty;
+import com.dumbhippo.dm.annotations.MetaConstruct;
import com.dumbhippo.dm.annotations.PropertyType;
import com.dumbhippo.server.NotFoundException;
@@ -14,6 +15,18 @@
protected ThumbnailDMO(ThumbnailKey key) {
super(key);
}
+
+ @MetaConstruct
+ public static Class<? extends ThumbnailDMO> getDMOClass(ThumbnailKey key) {
+ switch (key.getType()) {
+ case PICASA_ALBUM:
+ return PicasaAlbumThumbnailDMO.class;
+ case YOUTUBE:
+ return YouTubeThumbnailDMO.class;
+ }
+
+ return null;
+ }
@Override
protected void init() throws NotFoundException {
Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ThumbnailKey.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ThumbnailKey.java 2007-12-12 00:02:18 UTC (rev 7033)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ThumbnailKey.java 2007-12-12 00:51:15 UTC (rev 7034)
@@ -10,7 +10,7 @@
* ThumbnailDMO is an abstract class rather than an interface, all its
* subclasses need to have the same key type. (And we don't support
* datamodel properties on interfaces currently.) The form of a
- * ThumnailKey is a pair of a userId and a string, where the exact
+ * ThumbnailKey is <userId>.<type>.<string>, where the exact
* interpretation of the string is up to the subclass.
*
* We also support storing the Thumbnail object in the key transiently
@@ -23,6 +23,7 @@
private transient Object object;
private Guid userId;
+ private ThumbnailType type;
private String extra;
public ThumbnailKey(String keyString) throws BadIdException {
@@ -32,20 +33,32 @@
} catch (ParseException e) {
throw new BadIdException("Bad GUID type in external account ID", e);
}
-
- extra = keyString.substring(15);
} else {
throw new BadIdException("Bad thumbnail resource ID");
}
+
+ int nextDot = keyString.indexOf('.', 15);
+ if (nextDot < 0)
+ throw new BadIdException("Bad thumbnail resource ID");
+
+ try {
+ type = ThumbnailType.valueOf(keyString.substring(15, nextDot));
+ } catch (IllegalArgumentException e) {
+ throw new BadIdException("Bad thumbnail type in ID", e);
+ }
+
+ extra = keyString.substring(nextDot + 1);
}
- public ThumbnailKey(Guid userId, String extra) {
+ public ThumbnailKey(Guid userId, ThumbnailType type, String extra) {
this.userId = userId;
+ this.type = type;
this.extra = extra;
}
- public ThumbnailKey(Guid userId, String extra, Object object) {
+ public ThumbnailKey(Guid userId, ThumbnailType type, String extra, Object object) {
this.userId = userId;
+ this.type = type;
this.extra = extra;
this.object = object;
}
@@ -57,6 +70,10 @@
public String getExtra() {
return extra;
}
+
+ public ThumbnailType getType() {
+ return type;
+ }
public Guid getUserId() {
return userId;
@@ -65,14 +82,14 @@
@Override
public ThumbnailKey clone() {
if (object != null)
- return new ThumbnailKey(userId, extra);
+ return new ThumbnailKey(userId, type, extra);
else
return this;
}
@Override
public int hashCode() {
- return userId.hashCode() * 11 + extra.hashCode() * 17;
+ return userId.hashCode() * 11 + extra.hashCode() * 17 + type.ordinal();
}
@Override
@@ -82,11 +99,11 @@
ThumbnailKey other = (ThumbnailKey)o;
- return userId.equals(other.userId) && extra.equals(other.extra);
+ return userId.equals(other.userId) && type == other.type && extra.equals(other.extra);
}
@Override
public String toString() {
- return userId.toString() + "." + extra;
+ return userId.toString() + "." + type.name() + "." + extra;
}
}
Added: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ThumbnailType.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ThumbnailType.java 2007-12-12 00:02:18 UTC (rev 7033)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ThumbnailType.java 2007-12-12 00:51:15 UTC (rev 7034)
@@ -0,0 +1,6 @@
+package com.dumbhippo.server.dm;
+
+public enum ThumbnailType {
+ PICASA_ALBUM,
+ YOUTUBE
+}
Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/YouTubeThumbnailDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/YouTubeThumbnailDMO.java 2007-12-12 00:02:18 UTC (rev 7033)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/YouTubeThumbnailDMO.java 2007-12-12 00:51:15 UTC (rev 7034)
@@ -68,6 +68,6 @@
}
public static ThumbnailKey getKey(User user, YouTubeVideo video) {
- return new ThumbnailKey(user.getGuid(), extractExtra(video.getThumbnailHref()), video);
+ return new ThumbnailKey(user.getGuid(), ThumbnailType.YOUTUBE, extractExtra(video.getThumbnailHref()), video);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]