r7017 - in dumbhippo/trunk/server/src/com/dumbhippo: server server/impl web/servlets
- From: commits mugshot org
- To: online-desktop-list gnome org
- Subject: r7017 - in dumbhippo/trunk/server/src/com/dumbhippo: server server/impl web/servlets
- Date: Tue, 11 Dec 2007 12:41:52 -0600 (CST)
Author: marinaz
Date: 2007-12-11 12:41:43 -0600 (Tue, 11 Dec 2007)
New Revision: 7017
Modified:
dumbhippo/trunk/server/src/com/dumbhippo/server/IdentitySpider.java
dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java
dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java
dumbhippo/trunk/server/src/com/dumbhippo/web/servlets/FacebookServlet.java
Log:
User lookup based on a resource information functions in IdentitySpider return
null if no user owns the resource and throw NotFoundException if the corresponding
resource was not found. This is a bit confusing. Fixed Facebook code to handle
both cases and improved the documentation for these functions a bit.
Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/IdentitySpider.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/IdentitySpider.java 2007-12-11 18:18:10 UTC (rev 7016)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/IdentitySpider.java 2007-12-11 18:41:43 UTC (rev 7017)
@@ -147,8 +147,8 @@
* they own it.
*
* @param email the possibly-owned email address
- * @return the owning person, or null if none
- * @throws NotFoundException
+ * @return the owning person, or null if no one owns the resource
+ * @throws NotFoundException if the resource is not found
*/
public User lookupUserByEmail(Viewpoint viewpoint, String email) throws NotFoundException;
Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java 2007-12-11 18:18:10 UTC (rev 7016)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java 2007-12-11 18:41:43 UTC (rev 7017)
@@ -209,8 +209,15 @@
}
public User createNewUserWithFacebookAccount(String sessionKey, String facebookUserId, boolean applicationEnabled) throws FacebookSystemException {
- FacebookResource res = new FacebookResource(facebookUserId);
- em.persist(res);
+ // the resource might have already existed, but not claimed by anyone
+ FacebookResource res;
+ try {
+ res = identitySpider.lookupFacebook(facebookUserId);
+ assert(res.getAccountClaim() == null);
+ } catch (NotFoundException e) {
+ 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);
Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java 2007-12-11 18:18:10 UTC (rev 7016)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java 2007-12-11 18:41:43 UTC (rev 7017)
@@ -111,22 +111,24 @@
public User lookupUserByEmail(Viewpoint viewpoint, String email) throws NotFoundException {
EmailResource res = lookupEmail(email);
+ // lookupEmail will normally throw a NotFoundException if the resource is not found,
+ // so it's not clear in what situation res will be null
if (res == null)
- return null;
+ throw new NotFoundException("Resource was null");
return lookupUserByResource(viewpoint, res);
}
public User lookupUserByAim(Viewpoint viewpoint, String aim) throws NotFoundException {
AimResource res = lookupAim(aim);
if (res == null)
- return null;
+ throw new NotFoundException("Resource was null");
return lookupUserByResource(viewpoint, res);
}
public User lookupUserByFacebookUserId(Viewpoint viewpoint, String facebookUserId) throws NotFoundException {
FacebookResource res = lookupFacebook(facebookUserId);
if (res == null)
- return null;
+ throw new NotFoundException("Resource was null");
return lookupUserByResource(viewpoint, res);
}
Modified: dumbhippo/trunk/server/src/com/dumbhippo/web/servlets/FacebookServlet.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/web/servlets/FacebookServlet.java 2007-12-11 18:18:10 UTC (rev 7016)
+++ dumbhippo/trunk/server/src/com/dumbhippo/web/servlets/FacebookServlet.java 2007-12-11 18:41:43 UTC (rev 7017)
@@ -102,25 +102,32 @@
String sessionKey = facebookParams.get(FacebookParam.SESSION_KEY.toString()).toString();
String facebookUserId = facebookParams.get(FacebookParam.USER.toString()).toString();
IdentitySpider identitySpider = WebEJBUtil.defaultLookup(IdentitySpider.class);
- try {
+ FacebookTracker facebookTracker = WebEJBUtil.defaultLookup(FacebookTracker.class);
+
+ try {
user = identitySpider.lookupUserByFacebookUserId(SystemViewpoint.getInstance(), facebookUserId);
- 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);
- } 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 means we did not have a resource for this Facebook user id in the system
+ // nothing to do here, but we will try to create a user with this resource below
}
+
+ if (user == null) {
+ try {
+ // need to create a new user based on the Facebook user id
+ user = facebookTracker.createNewUserWithFacebookAccount(sessionKey, facebookUserId, true);
+ } catch (FacebookSystemException e) {
+ errorMessage = e.getMessage();
+ }
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]