r7010 - in dumbhippo/trunk/server/src/com/dumbhippo: server server/impl web/servlets
- From: commits mugshot org
- To: online-desktop-list gnome org
- Subject: r7010 - in dumbhippo/trunk/server/src/com/dumbhippo: server server/impl web/servlets
- Date: Mon, 10 Dec 2007 17:49:20 -0600 (CST)
Author: marinaz
Date: 2007-12-10 17:49:14 -0600 (Mon, 10 Dec 2007)
New Revision: 7010
Modified:
dumbhippo/trunk/server/src/com/dumbhippo/server/FacebookTracker.java
dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java
dumbhippo/trunk/server/src/com/dumbhippo/web/servlets/FacebookServlet.java
Log:
Create a Mugshot account based on Facebook user's user id
if we don't have a corresponding user on Mugshot.
Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/FacebookTracker.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/FacebookTracker.java 2007-12-10 23:11:56 UTC (rev 7009)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/FacebookTracker.java 2007-12-10 23:49:14 UTC (rev 7010)
@@ -16,6 +16,8 @@
public void updateOrCreateFacebookAccount(UserViewpoint viewpoint, String sessionKey, String facebookUserId, boolean applicationEnabled) throws FacebookSystemException;
+ public User createNewUserWithFacebookAccount(String sessionKey, String facebookUserId, boolean applicationEnabled) throws FacebookSystemException;
+
public void updateFbmlForUser(User user);
public void updateMessageCount(long facebookAccountId);
Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java 2007-12-10 23:11:56 UTC (rev 7009)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java 2007-12-10 23:49:14 UTC (rev 7010)
@@ -23,6 +23,7 @@
import com.dumbhippo.GlobalSetup;
import com.dumbhippo.Pair;
import com.dumbhippo.Site;
+import com.dumbhippo.persistence.Account;
import com.dumbhippo.persistence.AccountClaim;
import com.dumbhippo.persistence.ExternalAccount;
import com.dumbhippo.persistence.ExternalAccountType;
@@ -34,6 +35,7 @@
import com.dumbhippo.persistence.FacebookResource;
import com.dumbhippo.persistence.Sentiment;
import com.dumbhippo.persistence.User;
+import com.dumbhippo.server.AccountSystem;
import com.dumbhippo.server.Configuration;
import com.dumbhippo.server.ExternalAccountSystem;
import com.dumbhippo.server.FacebookSystem;
@@ -96,6 +98,9 @@
@EJB
private IdentitySpider identitySpider;
+ @EJB
+ private AccountSystem accounts;
+
@PostConstruct
public void init() {
cacheFactory.injectCaches(this);
@@ -147,8 +152,22 @@
identitySpider.addVerifiedOwnershipClaim(viewpoint.getViewer(), res);
externalAccount.setExtra(Long.toString(facebookAccount.getId()));
}
+ } else if (res != null && facebookAccount == null) {
+ // this can only happen if we are creating a new User and already had to set their FacebookResource
+ AccountClaim ac = res.getAccountClaim();
+ if (ac != null) {
+ if (!ac.getOwner().equals(viewpoint.getViewer())) {
+ throw new FacebookSystemException("Facebook account " + facebookUserId + " is claimed by someone else: " + ac.getOwner());
+ }
+ } else {
+ logger.warn("Had a FacebookResource for " + facebookUserId + " with no account claim and no corresponding FacebookAccount");
+ identitySpider.addVerifiedOwnershipClaim(viewpoint.getViewer(), res);
+ }
+ facebookAccount = new FacebookAccount(externalAccount, facebookUserId);
+ em.persist(facebookAccount);
+ externalAccount.setExtra(Long.toString(facebookAccount.getId()));
} else {
- throw new RuntimeException("Facebook resource was " + res + ", while Facebook account was " + facebookAccount + ". If one of them exists, the other one should not be null.");
+ throw new RuntimeException("Facebook resource was " + res + ", while Facebook account was " + facebookAccount + ". Every FacebookAccount should have a corresponding FacebookResource.");
}
} else {
facebookAccount = em.find(FacebookAccount.class, Long.parseLong(externalAccount.getExtra()));
@@ -189,6 +208,15 @@
}
}
+ public User createNewUserWithFacebookAccount(String sessionKey, String facebookUserId, boolean applicationEnabled) throws FacebookSystemException {
+ FacebookResource res = new FacebookResource(facebookUserId);
+ em.persist(res);
+ Account account = accounts.createAccountFromResource(res);
+ User user = account.getOwner();
+ updateOrCreateFacebookAccount(new UserViewpoint(user, Site.MUGSHOT), sessionKey, facebookUserId, applicationEnabled);
+ return user;
+ }
+
private FacebookAccount getFacebookAccount(String facebookUserId) {
Query accountQuery = em.createQuery("from FacebookAccount f where f.facebookUserId = :facebookUserId");
accountQuery.setParameter("facebookUserId", facebookUserId);
Modified: dumbhippo/trunk/server/src/com/dumbhippo/web/servlets/FacebookServlet.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/web/servlets/FacebookServlet.java 2007-12-10 23:11:56 UTC (rev 7009)
+++ dumbhippo/trunk/server/src/com/dumbhippo/web/servlets/FacebookServlet.java 2007-12-10 23:49:14 UTC (rev 7010)
@@ -104,25 +104,26 @@
IdentitySpider identitySpider = WebEJBUtil.defaultLookup(IdentitySpider.class);
try {
user = identitySpider.lookupUserByFacebookUserId(SystemViewpoint.getInstance(), facebookUserId);
- if (user != null) {
- try {
- FacebookTracker facebookTracker = WebEJBUtil.defaultLookup(FacebookTracker.class);
+ FacebookTracker facebookTracker = WebEJBUtil.defaultLookup(FacebookTracker.class);
+ try {
+ if (user != null) {
userViewpoint = new UserViewpoint(user, Site.MUGSHOT);
// TODO: can change this into updateExistingFacebookAccount
facebookTracker.updateOrCreateFacebookAccount(userViewpoint, sessionKey, facebookUserId, true);
- } catch (FacebookSystemException e) {
- errorMessage = e.getMessage();
- }
- } else {
- // TODO: create FacebookResource based on the facebookUserId and a user that is claiming this resource
- }
+ } else {
+ // need to create a new user based on the Facebook user id
+ user = facebookTracker.createNewUserWithFacebookAccount(sessionKey, facebookUserId, true);
+ }
+ } catch (FacebookSystemException e) {
+ errorMessage = e.getMessage();
+ }
} catch (NotFoundException e) {
// nothing to do
// TODO: check in which case NotFoundException is thrown as opposed to the user being null
}
}
}
-
+
// this returns some code in FBML we'll return for our app page on Facebook
// it intentionally points to my test server for now
XmlBuilder xml = new XmlBuilder();
@@ -235,7 +236,7 @@
xml.appendTextNode("fb:message", "Success");
xml.openElement("ul");
for (ExternalAccountType accountType : accountsSetSuccessful) {
- accountsSetSuccessfulBuilder.append(accountType.getName() + ", ");
+ accountsSetSuccessfulBuilder.append(accountType.getSiteName() + ", ");
}
if (accountsSetSuccessfulBuilder.length() > 2) {
if (accountsSetSuccessful.size() > 1)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]