r6936 - in dumbhippo/trunk: . server/src/com/dumbhippo/persistence server/src/com/dumbhippo/server server/src/com/dumbhippo/server/impl



Author: marinaz
Date: 2007-11-20 18:32:51 -0600 (Tue, 20 Nov 2007)
New Revision: 6936

Added:
   dumbhippo/trunk/server/src/com/dumbhippo/persistence/FacebookResource.java
Modified:
   dumbhippo/trunk/.classpath
   dumbhippo/trunk/server/src/com/dumbhippo/server/FacebookSystem.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookSystemBean.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java
Log:
Set initial profile FBML outside of a transaction.

Add FacebookResource class that will allow us to have Facebook accounts 
be uniquely claimed by AccountClaims. Add a migration function for creating
FacebookResources for existing FacebookAccounts. 

Modified: dumbhippo/trunk/.classpath
===================================================================
--- dumbhippo/trunk/.classpath	2007-11-20 23:05:42 UTC (rev 6935)
+++ dumbhippo/trunk/.classpath	2007-11-21 00:32:51 UTC (rev 6936)
@@ -112,6 +112,6 @@
 	<classpathentry kind="lib" path="openfire/src/plugins/userImportExport/lib/msv.jar"/>
 	<classpathentry kind="lib" path="openfire/src/plugins/userImportExport/lib/isorelax.jar"/>
 	<classpathentry kind="var" path="HIPPO_TRUNK_LIB/server/dom4j-1.6.1.jar"/>
-	<classpathentry kind="lib" path="lib/server/facebook.jar"/>
+	<classpathentry kind="lib" path="HIPPO_TRUNK_LIB/server/facebook.jar"/>
 	<classpathentry kind="output" path="eclipse-build"/>
 </classpath>

Added: dumbhippo/trunk/server/src/com/dumbhippo/persistence/FacebookResource.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/persistence/FacebookResource.java	2007-11-20 23:05:42 UTC (rev 6935)
+++ dumbhippo/trunk/server/src/com/dumbhippo/persistence/FacebookResource.java	2007-11-21 00:32:51 UTC (rev 6936)
@@ -0,0 +1,40 @@
+package com.dumbhippo.persistence;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Transient;
+
+ Entity
+public class FacebookResource extends Resource {
+	
+	private static final long serialVersionUID = 0L;
+	
+	private String facebookUserId;
+	
+	protected FacebookResource() {}
+	
+	public FacebookResource(String facebookUserId) {
+		this.facebookUserId = facebookUserId;
+	}
+
+	@Column(unique=true, nullable=false)
+	public String getFacebookUserId() {
+		return facebookUserId;
+	}
+	
+	protected void setFacebookUserId(String facebookUserId) {
+		this.facebookUserId = facebookUserId;
+	}
+	
+	@Override
+	@Transient
+	public String getHumanReadableString() {
+		return "Facebook user " + getFacebookUserId();
+	}
+		
+	@Override
+	@Transient
+	public String getDerivedNickname() {
+		return getHumanReadableString();
+	}
+}

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/FacebookSystem.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/FacebookSystem.java	2007-11-20 23:05:42 UTC (rev 6935)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/FacebookSystem.java	2007-11-21 00:32:51 UTC (rev 6936)
@@ -53,4 +53,7 @@
 	
 	public void updateUserIds(List<FacebookAccount> detachedFacebookAccounts);
 	
+	// this is a migration function needed for creating FacebookResource objects that can be claimed
+	// with AccountClaim; only run this once we make the facebookUserId in FacebookAccount unique and not null
+	public void createFacebookResources();
 }

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookSystemBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookSystemBean.java	2007-11-20 23:05:42 UTC (rev 6935)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookSystemBean.java	2007-11-21 00:32:51 UTC (rev 6936)
@@ -11,6 +11,7 @@
 import javax.ejb.TransactionAttribute;
 import javax.ejb.TransactionAttributeType;
 import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
 import javax.persistence.PersistenceContext;
 import javax.persistence.Query;
 
@@ -25,11 +26,13 @@
 import com.dumbhippo.persistence.FacebookAccount;
 import com.dumbhippo.persistence.FacebookEvent;
 import com.dumbhippo.persistence.FacebookEventType;
+import com.dumbhippo.persistence.FacebookResource;
 import com.dumbhippo.persistence.User;
 import com.dumbhippo.server.Configuration;
 import com.dumbhippo.server.ExternalAccountSystem;
 import com.dumbhippo.server.FacebookSystem;
 import com.dumbhippo.server.HippoProperty;
+import com.dumbhippo.server.IdentitySpider;
 import com.dumbhippo.server.NotFoundException;
 import com.dumbhippo.server.Configuration.PropertyNotFoundException;
 import com.dumbhippo.server.util.EJBUtil;
@@ -56,6 +59,9 @@
 	@EJB
 	private Configuration config;
 	
+	@EJB
+	private IdentitySpider identitySpider;
+	
 	public List<FacebookAccount> getAllAccounts() {
 		List<?> list = em.createQuery("SELECT fa FROM FacebookAccount fa").getResultList();
 		return TypeUtils.castList(FacebookAccount.class, list);
@@ -225,4 +231,22 @@
 		    }
 		} 
 	}
+
+	public void createFacebookResources() {
+		List<FacebookAccount> facebookAccounts = getAllAccounts();
+		for (FacebookAccount facebookAccount : facebookAccounts) {
+			Query q = em.createQuery("from FacebookResource f where f.facebookUserId = :facebookUserId");
+			q.setParameter("facebookUserId", facebookAccount.getFacebookUserId());
+
+			FacebookResource res;
+			try {
+				res = (FacebookResource) q.getSingleResult();
+				logger.warn("resource {} already existed when we were running createFacebookResources", res);
+			} catch (NoResultException e) {
+				res = new FacebookResource(facebookAccount.getFacebookUserId());
+				em.persist(res);
+				identitySpider.addVerifiedOwnershipClaim(facebookAccount.getExternalAccount().getAccount().getOwner(), res);
+			}
+		}
+	}
 }

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java	2007-11-20 23:05:42 UTC (rev 6935)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java	2007-11-21 00:32:51 UTC (rev 6936)
@@ -145,13 +145,19 @@
 	    if (sessionKey != null)
 		    facebookAccount.setSessionKeyValid(true);	
 	    facebookAccount.setApplicationEnabled(applicationEnabled);
-			
-		FacebookWebServices ws = new FacebookWebServices(REQUEST_TIMEOUT, config);
-		ws.setProfileFbml(facebookAccount, createFbmlForUser(viewpoint.getViewer()));
 
 		FacebookEvent loginStatusEvent = getLoginStatusEvent(facebookAccount, true);
 		if (loginStatusEvent != null)  
 		    notifier.onFacebookEvent(facebookAccount.getExternalAccount().getAccount().getOwner(), loginStatusEvent);
+		
+		if (applicationEnabled) {
+			final User user = viewpoint.getViewer();
+		    TxUtils.runOnCommit(new Runnable() {
+			    public void run() {
+			    	updateFbmlForUser(user);
+			    }
+		    });
+		}	 
 	}
 	
 	@TransactionAttribute(TransactionAttributeType.NEVER)

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java	2007-11-20 23:05:42 UTC (rev 6935)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java	2007-11-21 00:32:51 UTC (rev 6936)
@@ -39,6 +39,7 @@
 import com.dumbhippo.persistence.EmailResource;
 import com.dumbhippo.persistence.ExternalAccount;
 import com.dumbhippo.persistence.ExternalAccountType;
+import com.dumbhippo.persistence.FacebookResource;
 import com.dumbhippo.persistence.Group;
 import com.dumbhippo.persistence.GuidPersistable;
 import com.dumbhippo.persistence.LinkResource;
@@ -407,6 +408,9 @@
 			DataService.currentSessionRW().changed(UserDMO.class, claimedOwner.getGuid(), "aim");
 		else if (res instanceof XmppResource)
 			DataService.currentSessionRW().changed(UserDMO.class, claimedOwner.getGuid(), "xmpp");
+		// TODO: is there a list of property names anywhere that needs to be updated?
+		else if (res instanceof FacebookResource)
+			DataService.currentSessionRW().changed(UserDMO.class, claimedOwner.getGuid(), "facebook");
 		
 		// People may have listed the newly claimed resource as a contact
 		Collection<Guid> newContacters = findResourceContacters(res);



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