r6925 - in dumbhippo/trunk/server/src/com/dumbhippo/server: . impl



Author: marinaz
Date: 2007-11-16 17:56:40 -0600 (Fri, 16 Nov 2007)
New Revision: 6925

Modified:
   dumbhippo/trunk/server/src/com/dumbhippo/server/FacebookTracker.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/StackerBean.java
Log:
Update Facebook profile box each time a non-Facebook activity block is stacked 
for a user who participated in the activity.

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/FacebookTracker.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/FacebookTracker.java	2007-11-16 23:46:21 UTC (rev 6924)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/FacebookTracker.java	2007-11-16 23:56:40 UTC (rev 6925)
@@ -5,6 +5,7 @@
 import javax.ejb.Local;
 
 import com.dumbhippo.persistence.FacebookAccount;
+import com.dumbhippo.persistence.User;
 import com.dumbhippo.server.views.UserViewpoint;
 import com.dumbhippo.services.FacebookPhotoDataView;
 
@@ -15,6 +16,8 @@
 	
 	public void updateOrCreateFacebookAccount(UserViewpoint viewpoint, String sessionKey, String facebookUserId, boolean applicationEnabled) throws FacebookSystemException;
 
+	public void updateFbmlForUser(User user);
+	
 	public void updateMessageCount(long facebookAccountId);
 	
 	public void updateTaggedPhotos(long facebookAccountId);

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookSystemBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookSystemBean.java	2007-11-16 23:46:21 UTC (rev 6924)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookSystemBean.java	2007-11-16 23:56:40 UTC (rev 6925)
@@ -89,7 +89,7 @@
 	
 	public FacebookAccount lookupFacebookAccount(Viewpoint viewpoint, User user) throws NotFoundException {
 		if (!em.contains(user.getAccount()))
-			throw new RuntimeException("detached account in lookupExternalAccount()");
+			user = EJBUtil.lookupGuid(em, User.class, user.getGuid());
 	
 		ExternalAccount externalAccount = externalAccounts.lookupExternalAccount(viewpoint, user, ExternalAccountType.FACEBOOK);
 

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java	2007-11-16 23:46:21 UTC (rev 6924)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java	2007-11-16 23:56:40 UTC (rev 6925)
@@ -15,6 +15,7 @@
 import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
 
+import org.jboss.annotation.IgnoreDependency;
 import org.slf4j.Logger;
 
 import com.dumbhippo.GlobalSetup;
@@ -31,14 +32,17 @@
 import com.dumbhippo.persistence.User;
 import com.dumbhippo.server.Configuration;
 import com.dumbhippo.server.ExternalAccountSystem;
+import com.dumbhippo.server.FacebookSystem;
 import com.dumbhippo.server.FacebookSystemException;
 import com.dumbhippo.server.FacebookTracker;
+import com.dumbhippo.server.NotFoundException;
 import com.dumbhippo.server.Notifier;
 import com.dumbhippo.server.Pageable;
 import com.dumbhippo.server.Stacker;
 import com.dumbhippo.server.blocks.BlockView;
 import com.dumbhippo.server.util.EJBUtil;
 import com.dumbhippo.server.views.AnonymousViewpoint;
+import com.dumbhippo.server.views.SystemViewpoint;
 import com.dumbhippo.server.views.UserViewpoint;
 import com.dumbhippo.services.FacebookPhotoDataView;
 import com.dumbhippo.services.FacebookWebServices;
@@ -72,6 +76,7 @@
 	private Notifier notifier;
 	
 	@EJB
+	@IgnoreDependency
 	private Stacker stacker;
 	
 	@WebServiceCache
@@ -80,6 +85,9 @@
 	@EJB
 	private CacheFactory cacheFactory;	
 	
+	@EJB
+	private FacebookSystem facebookSystem;
+	
 	@PostConstruct
 	public void init() {
 		cacheFactory.injectCaches(this);
@@ -98,6 +106,9 @@
 			facebookAccount = em.find(FacebookAccount.class, Long.parseLong(externalAccount.getExtra()));
 			if (facebookAccount == null)
 				throw new RuntimeException("Invalid FacebookAccount id " + externalAccount.getExtra() + " is stored in externalAccount " + externalAccount);
+			// make sure the sentiment is LOVE; there is currently no way to unset it from the user interface,
+			// but we should allow changing the sentiment to HATE or at least INDIFFERENT in the future
+			externalAccounts.setSentiment(externalAccount, Sentiment.LOVE);
 		}
 		
 		FacebookWebServices ws = new FacebookWebServices(REQUEST_TIMEOUT, config);
@@ -121,6 +132,7 @@
 			facebookAccount = em.find(FacebookAccount.class, Long.parseLong(externalAccount.getExtra()));
 			if (facebookAccount == null)
 				throw new RuntimeException("Invalid FacebookAccount id " + externalAccount.getExtra() + " is stored in externalAccount " + externalAccount);
+			externalAccounts.setSentiment(externalAccount, Sentiment.LOVE);
 		}
 		
 		if (facebookAccount.getFacebookUserId() != null 
@@ -142,6 +154,29 @@
 		    notifier.onFacebookEvent(facebookAccount.getExternalAccount().getAccount().getOwner(), loginStatusEvent);
 	}
 	
+	@TransactionAttribute(TransactionAttributeType.NEVER)
+	public void updateFbmlForUser(final User user) {
+		TxUtils.assertNoTransaction();
+		try {
+			FacebookAccount facebookAccount = TxUtils.runInTransaction(new Callable<FacebookAccount>() {
+				public FacebookAccount call() {
+					try {
+					    return facebookSystem.lookupFacebookAccount(SystemViewpoint.getInstance(), user);
+					} catch (NotFoundException e) {
+						return null;
+					}
+				}	
+			});
+		    if (facebookAccount != null && facebookAccount.isApplicationEnabled()) {
+		        FacebookWebServices ws = new FacebookWebServices(REQUEST_TIMEOUT, config);
+			    ws.setProfileFbml(facebookAccount, createFbmlForUser(user));
+            }		    
+		} catch (Exception e) {
+			logger.error("Caught an exception when getting a FacebookAccount for {}: {}", user, e.getMessage());
+			throw new RuntimeException(e);            			
+		}
+	}
+	
 	// FIXME this is calling web services with a transaction open, which holds 
 	// a db connection open so other threads can't use it, and could also 
 	// time out the transaction

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/StackerBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/StackerBean.java	2007-11-16 23:46:21 UTC (rev 6924)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/StackerBean.java	2007-11-16 23:56:40 UTC (rev 6925)
@@ -54,6 +54,7 @@
 import com.dumbhippo.persistence.User;
 import com.dumbhippo.persistence.UserBlockData;
 import com.dumbhippo.server.ChatSystem;
+import com.dumbhippo.server.FacebookTracker;
 import com.dumbhippo.server.GroupSystem;
 import com.dumbhippo.server.IdentitySpider;
 import com.dumbhippo.server.MusicSystem;
@@ -128,6 +129,9 @@
 	@EJB
 	private XmppMessageSender xmppMessageSystem;	
 	
+	@EJB
+	private FacebookTracker facebookTracker;
+	
 	private Map<BlockType,BlockHandler> handlers;
 	
 	private BlockHandler getHandler(Block block) {
@@ -722,10 +726,18 @@
 				Block attached = em.find(Block.class, block.getId());
 				if (updateAllUserBlockDatas) {
 				    updateUserBlockDatas(attached, (participant != null ? participant.getGuid() : null), reason);
-			     } else if (participant != null) {
-			    	 updateParticipantUserBlockData(attached, participant.getGuid(), reason);					    	 
-			     }
+			    } else if (participant != null) {
+			        updateParticipantUserBlockData(attached, participant.getGuid(), reason);	
+			    }				
 				updateGroupBlockDatas(attached, isGroupParticipation, reason);
+
+				if (participant != null && block.getBlockType() != BlockType.FACEBOOK_EVENT) {
+				    TxUtils.runOnCommit(new Runnable() {
+					    public void run() {
+					    	facebookTracker.updateFbmlForUser(participant);
+					    }
+				    });
+				}	 
 			}
 		});
 	}



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