r7514 - in dumbhippo/trunk/server/src/com/dumbhippo: live persistence server/dm server/impl



Author: marinaz
Date: 2008-09-25 16:50:57 -0500 (Thu, 25 Sep 2008)
New Revision: 7514

Modified:
   dumbhippo/trunk/server/src/com/dumbhippo/live/ExternalAccountChangedEvent.java
   dumbhippo/trunk/server/src/com/dumbhippo/persistence/ExternalAccount.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ExternalAccountDMO.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ExternalAccountKey.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/impl/ExternalAccountChangePropagatorBean.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/impl/HttpMethodsBean.java
Log:
Update ExternalAccountKey to use the name from OnlineAccountType, so that the change updates 
work for new types that don't have an ExternalAccountType.

Update ExternalAccount::hasAccountInfo() to return true if ExternalAccountType is not available and the external account has a non-empty handle.

Modified: dumbhippo/trunk/server/src/com/dumbhippo/live/ExternalAccountChangedEvent.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/live/ExternalAccountChangedEvent.java	2008-09-24 23:24:58 UTC (rev 7513)
+++ dumbhippo/trunk/server/src/com/dumbhippo/live/ExternalAccountChangedEvent.java	2008-09-25 21:50:57 UTC (rev 7514)
@@ -1,7 +1,7 @@
 package com.dumbhippo.live;
 
 import com.dumbhippo.identity20.Guid;
-import com.dumbhippo.persistence.ExternalAccountType;
+import com.dumbhippo.persistence.OnlineAccountType;
 
 /**
  * Event sent when an external account changes for a user
@@ -10,16 +10,19 @@
 public class ExternalAccountChangedEvent implements LiveEvent {
 	private static final long serialVersionUID = 1L;
 	
+	private long id = -1;
+	
 	private Guid userId;
 
-	private ExternalAccountType type;
+	private String type;	
 	
 	/**
 	 * @param userId the userID
 	 */
-	public ExternalAccountChangedEvent(Guid userID, ExternalAccountType type) {
+	public ExternalAccountChangedEvent(Guid userID, OnlineAccountType type, long id) {
 		this.userId = userID;
-		this.type = type;
+		this.type = type.getName();
+		this.id = id;
 	}
 
 	public Guid getUserId() {
@@ -30,7 +33,11 @@
 		return null;
 	}
 
-	public ExternalAccountType getType() {
+	public String getType() {
 		return type;
 	}
+	
+	public long getId() {
+		return id;
+	}
 }

Modified: dumbhippo/trunk/server/src/com/dumbhippo/persistence/ExternalAccount.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/persistence/ExternalAccount.java	2008-09-24 23:24:58 UTC (rev 7513)
+++ dumbhippo/trunk/server/src/com/dumbhippo/persistence/ExternalAccount.java	2008-09-25 21:50:57 UTC (rev 7514)
@@ -320,7 +320,8 @@
 	 */
 	@Transient
 	public boolean hasAccountInfo() {
-		return accountType != null && accountType.getHasAccountInfo(handle, extra);
+		return ((accountType != null && accountType.getHasAccountInfo(handle, extra)) || 
+		        (accountType == null && handle != null && handle.trim().length() > 0 ));
 	}
 	
 	public static int compare(ExternalAccount first, ExternalAccount second) {

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ExternalAccountDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ExternalAccountDMO.java	2008-09-24 23:24:58 UTC (rev 7513)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ExternalAccountDMO.java	2008-09-25 21:50:57 UTC (rev 7514)
@@ -7,6 +7,7 @@
 import javax.ejb.EJB;
 import javax.persistence.EntityManager;
 
+import com.dumbhippo.Site;
 import com.dumbhippo.Thumbnail;
 import com.dumbhippo.dm.DMObject;
 import com.dumbhippo.dm.DMSession;
@@ -19,7 +20,7 @@
 import com.dumbhippo.persistence.User;
 import com.dumbhippo.server.ExternalAccountSystem;
 import com.dumbhippo.server.NotFoundException;
-import com.dumbhippo.server.views.SystemViewpoint;
+import com.dumbhippo.server.views.UserViewpoint;
 
 @DMO(classId="http://mugshot.org/p/o/externalAccount";, resourceBase="/o/externalAccount")
 public abstract class ExternalAccountDMO extends DMObject<ExternalAccountKey> {
@@ -41,17 +42,11 @@
 	@Override
 	protected void init() throws NotFoundException {
 		ExternalAccountKey key = getKey();
-		
-		long id = key.getId();
-		if (id >= 0) {
-			externalAccount = em.find(ExternalAccount.class, id);
-		} else {
-			User user = em.find(User.class, key.getUserId().toString());
-			if (user == null)
-				throw new NotFoundException("No such user");
+		User user = em.find(User.class, key.getUserId().toString());
+		if (user == null)
+		    throw new NotFoundException("No such user");
 			
-			externalAccount = externalAccountSystem.lookupExternalAccount(SystemViewpoint.getInstance(), user, key.getType());
-		}
+		externalAccount = externalAccountSystem.lookupExternalAccount(new UserViewpoint(user, Site.NONE), String.valueOf(key.getId()));
 	}
 		
 	// FIXME: probably should add enum support and only convert to string when going to XML

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ExternalAccountKey.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ExternalAccountKey.java	2008-09-24 23:24:58 UTC (rev 7513)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ExternalAccountKey.java	2008-09-25 21:50:57 UTC (rev 7514)
@@ -5,16 +5,17 @@
 import com.dumbhippo.identity20.Guid;
 import com.dumbhippo.identity20.Guid.ParseException;
 import com.dumbhippo.persistence.ExternalAccount;
-import com.dumbhippo.persistence.ExternalAccountType;
+import com.dumbhippo.persistence.OnlineAccountType;
 
 public class ExternalAccountKey implements DMKey {
+	
 	private static final long serialVersionUID = 7179756386307688402L;
 	
 	private transient long id = -1; // doesn't really need to be transient, 
 	                                // but we do it this way for consistency
 	                                // with the string form
 	private Guid userId;
-	private ExternalAccountType type;
+	private String type;
 	
 	public ExternalAccountKey(String keyString) throws BadIdException {
 		if (keyString.length() > 15 && keyString.charAt(14) == '.') {
@@ -25,31 +26,41 @@
 			}
 			
 			try {
-				type = ExternalAccountType.valueOf(keyString.substring(15));
-			} catch (IllegalArgumentException e) {
-				throw new BadIdException("Bad external account type in ID", e);
+			    type = keyString.substring(15, keyString.indexOf(".", 15));
+			} catch (IndexOutOfBoundsException e) {
+				throw new BadIdException("The key " + keyString + " did not contain a second period separating the type from id", e);
 			}
+			
+			try {
+			    id = Long.parseLong(keyString.substring(keyString.indexOf(".", 15) + 1));
+			    
+			} catch (NumberFormatException e) {
+				throw new BadIdException("Bad external account id in key " + keyString, e);
+			} catch (IndexOutOfBoundsException e) {
+				throw new BadIdException("Missing external account id in key " + keyString, e);	
+			}	
 		} else {
-			throw new BadIdException("Bad external account resource ID");
+			throw new BadIdException("Bad external account resource id in key " + keyString);
 		}
 	}
 	
 	public ExternalAccountKey(ExternalAccount externalAccount) {
 		id = externalAccount.getId();
 		userId = externalAccount.getAccount().getOwner().getGuid();
-		type = externalAccount.getAccountType();
+		type = externalAccount.getOnlineAccountType().getName();
 	}
 	
-	public ExternalAccountKey(Guid userId, ExternalAccountType type) {
+	public ExternalAccountKey(Guid userId, OnlineAccountType type, long id) {
 		this.userId = userId;
-		this.type = type;
+		this.type = type.getName();
+		this.id = id;
 	}
 	
 	public long getId() {
 		return id;
 	}
 
-	public ExternalAccountType getType() {
+	public String getType() {
 		return type;
 	}
 
@@ -67,7 +78,9 @@
 	
 	@Override
 	public int hashCode() {
-		return userId.hashCode() + type.ordinal();
+		// casting a long to an int should just chop off the bits if the long is too large, so it's
+		// ok to do that here
+		return userId.hashCode() + type.hashCode() + (int)id;
 	}
 	
 	@Override
@@ -77,11 +90,11 @@
 		
 		ExternalAccountKey other = (ExternalAccountKey)o;
 		
-		return type == other.type && userId.equals(other.userId);
+		return type.equals(other.type) && userId.equals(other.userId) && (id == other.id);
 	}
 
 	@Override
 	public String toString() {
-		return userId.toString() + "." + type.name();
+		return userId.toString() + "." + type + "." + String.valueOf(id);
 	}
 }

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/ExternalAccountChangePropagatorBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/ExternalAccountChangePropagatorBean.java	2008-09-24 23:24:58 UTC (rev 7513)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/ExternalAccountChangePropagatorBean.java	2008-09-25 21:50:57 UTC (rev 7514)
@@ -22,7 +22,7 @@
 	private static final Logger logger = GlobalSetup.getLogger(ExternalAccountChangePropagator.class);
 
 	private void notify(User user, ExternalAccount external) {
-		LiveState.getInstance().queueUpdate(new ExternalAccountChangedEvent(user.getGuid(), external.getAccountType()));		
+		LiveState.getInstance().queueUpdate(new ExternalAccountChangedEvent(user.getGuid(),  external.getOnlineAccountType(), external.getId()));		
 	}
 	
 	public void onExternalAccountCreated(User user, ExternalAccount external) {
@@ -33,7 +33,7 @@
 	public void onExternalAccountLovedAndEnabledMaybeChanged(User user, ExternalAccount external) {
 		DataService.currentSessionRW().changed(UserDMO.class, user.getGuid(), "lovedAccounts");
 		DataService.currentSessionRW().changed(ExternalAccountDMO.class, new ExternalAccountKey(external), "link");
-                DataService.currentSessionRW().changed(ExternalAccountDMO.class, new ExternalAccountKey(external), "username");
+        DataService.currentSessionRW().changed(ExternalAccountDMO.class, new ExternalAccountKey(external), "username");
 		notify(user, external);
 	}
 }

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/HttpMethodsBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/HttpMethodsBean.java	2008-09-24 23:24:58 UTC (rev 7513)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/HttpMethodsBean.java	2008-09-25 21:50:57 UTC (rev 7514)
@@ -1626,6 +1626,8 @@
 			        quip = null;
 	        }
 	        external.setQuip(quip);
+	        // while we don't really need this call hare because externalAccountSystem.setSentiment() above makes it as well,
+	        // it's better to be clear in making it here as well along with the setting of a quip 
 	        DataService.currentSessionRW().changed(ExternalAccountDMO.class, new ExternalAccountKey(external), "quip");
 	    } else {
 	    	throw new RuntimeException("OnlineAccountType " + onlineAccountType + " did no have a corresponding ExternalAccountType.");



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]