r7518 - in dumbhippo/trunk: openfire/src/plugins/hippo/src/java/com/dumbhippo/jive server/src/com/dumbhippo/server server/src/com/dumbhippo/server/impl



Author: marinaz
Date: 2008-10-21 00:42:11 -0500 (Tue, 21 Oct 2008)
New Revision: 7518

Modified:
   dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/AccountsIQHandler.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/IdentitySpider.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java
Log:
AccountsIQHandler.java: add a method for removing external accounts or Google e-mail given the resource id or the e-mail respectively

IdentitySpider.java, IdentitySpiderBean.java: fix the check that ensures we keep at least one e-mail resource claim to just check e-mail resources and throw a HumanVisibleException if we are trying to remove the last e-mail resource claim for the user 

Modified: dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/AccountsIQHandler.java
===================================================================
--- dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/AccountsIQHandler.java	2008-10-20 21:50:28 UTC (rev 7517)
+++ dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/AccountsIQHandler.java	2008-10-21 05:42:11 UTC (rev 7518)
@@ -20,10 +20,14 @@
 
 import com.dumbhippo.GlobalSetup;
 import com.dumbhippo.XmlBuilder;
+import com.dumbhippo.dm.BadIdException;
 import com.dumbhippo.jive.annotations.IQHandler;
 import com.dumbhippo.jive.annotations.IQMethod;
+import com.dumbhippo.persistence.ExternalAccount;
 import com.dumbhippo.persistence.ExternalAccountType;
 import com.dumbhippo.persistence.OnlineAccountType;
+import com.dumbhippo.persistence.Resource;
+import com.dumbhippo.persistence.Sentiment;
 import com.dumbhippo.persistence.ValidationException;
 import com.dumbhippo.server.ClaimVerifier;
 import com.dumbhippo.server.ExternalAccountSystem;
@@ -33,6 +37,7 @@
 import com.dumbhippo.server.NotFoundException;
 import com.dumbhippo.server.OnlineDesktopSystem;
 import com.dumbhippo.server.XmlMethodException;
+import com.dumbhippo.server.dm.ExternalAccountKey;
 import com.dumbhippo.server.util.EJBUtil;
 import com.dumbhippo.server.views.SystemViewpoint;
 import com.dumbhippo.server.views.UserViewpoint;
@@ -176,4 +181,36 @@
      	    }    
 	    }
 	}
+	
+	@IQMethod(name="removeOnlineAccount", type=IQ.Type.set)
+	@IQParams({"accountType", "resourceId"})
+	public void removeOnlineAccount(UserViewpoint viewpoint, String accountType, String resourceId) throws IQException {
+		logger.debug("inside removeOnlineAccount");
+		
+		if (accountType.equals("google")) {
+		    IdentitySpider identitySpider = EJBUtil.defaultLookup(IdentitySpider.class);
+			try {
+				Resource resource = identitySpider.lookupEmail(resourceId);
+				identitySpider.removeVerifiedOwnershipClaim(viewpoint, viewpoint.getViewer(), resource);
+			} catch (NotFoundException e) {
+				throw IQException.createBadRequest("Did not find an e-mail for " + resourceId);
+		    } catch (HumanVisibleException e) {
+		    	throw IQException.createBadRequest(e.getMessage());
+		    }
+		} else {    
+			String externalAccountPath = "externalAccount/";
+			String keyString = resourceId.substring(resourceId.indexOf(externalAccountPath) + externalAccountPath.length());
+	        try {           
+			    ExternalAccountKey externalAccountKey = new ExternalAccountKey(keyString);
+			    String accountId = String.valueOf(externalAccountKey.getId());
+			    ExternalAccountSystem externalAccountSystem = EJBUtil.defaultLookup(ExternalAccountSystem.class);
+		        ExternalAccount external = externalAccountSystem.lookupExternalAccount(viewpoint, accountId);
+		        externalAccountSystem.setSentiment(external, Sentiment.INDIFFERENT);
+	        } catch (BadIdException e) {
+	        	throw IQException.createBadRequest(e.getMessage());
+	        } catch (NotFoundException e) {
+		        throw IQException.createBadRequest("Online account with resoure id " + resourceId + " did not exist on the server.");
+	        }
+		}        
+	}
 }

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/IdentitySpider.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/IdentitySpider.java	2008-10-20 21:50:28 UTC (rev 7517)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/IdentitySpider.java	2008-10-21 05:42:11 UTC (rev 7518)
@@ -202,7 +202,7 @@
 	 * @param owner the owner in the claim
 	 * @param res the resource they currently may own
 	 */
-	public void removeVerifiedOwnershipClaim(UserViewpoint viewpoint, User owner, Resource res);
+	public void removeVerifiedOwnershipClaim(UserViewpoint viewpoint, User owner, Resource res) throws HumanVisibleException;
 	
 	public Contact findContactByResource(User owner, Resource resource) throws NotFoundException;	
 	

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java	2008-10-20 21:50:28 UTC (rev 7517)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java	2008-10-21 05:42:11 UTC (rev 7518)
@@ -64,6 +64,7 @@
 import com.dumbhippo.server.ExternalAccountSystem;
 import com.dumbhippo.server.GroupSystem;
 import com.dumbhippo.server.HippoProperty;
+import com.dumbhippo.server.HumanVisibleException;
 import com.dumbhippo.server.IdentitySpider;
 import com.dumbhippo.server.IdentitySpiderRemote;
 import com.dumbhippo.server.NotFoundException;
@@ -580,22 +581,40 @@
 		    	 onlineDesktop.onGoogleServicedEmailChange(SystemViewpoint.getInstance(), claimedOwner, (EmailResource)res);
 		    }						
 		}
-	}
+	} 
 
 	public void removeVerifiedOwnershipClaim(UserViewpoint viewpoint,
-			User owner, Resource res) {
+			User owner, Resource res) throws HumanVisibleException {
 		Collection<Contact> oldContacts = findResourceContacts(res);
 		
 		if (!viewpoint.isOfUser(owner)) {
 			throw new RuntimeException(
 					"can only remove your own ownership claims");
 		}
+
 		Set<AccountClaim> claims = owner.getAccountClaims();
-		if (claims.size() < 2) {
-			// UI shouldn't let this happen, but we double-check here
-			throw new RuntimeException(
-					"you have to keep at least one address on an account");
+
+		// normally, any user will claim their Account resource, up to one FacebookResource,
+		// and multiple email, aim, and xmpp resources 
+		// it's possible to not have a single EmailResource if a user has a FacebookResource,
+		// but once an EmailResource has been added, we don't allow deleting the last EmailResource
+		// we are currently never deleting a FacebookResource claim
+		if (res instanceof EmailResource) {
+		    int emailClaimsCounter = 0;	
+			for (AccountClaim claim : claims) {
+			    if (claim.getResource() instanceof EmailResource) {
+			    	emailClaimsCounter++;
+			    	if (emailClaimsCounter > 1)
+			    		break;
+			    }
+			}
+			if (emailClaimsCounter < 2)	{
+				// UI shouldn't let this happen, but we double-check here
+				throw new HumanVisibleException(
+						"You have to keep at least one e-mail address on your user account.");
+			}
 		}
+
 		for (AccountClaim claim : claims) {
 			if (claim.getResource().equals(res)) {
 				logger.debug("Found claim for {} on {}, removing it", owner,



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