r7187 - dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive



Author: otaylor
Date: 2008-01-11 10:01:17 -0600 (Fri, 11 Jan 2008)
New Revision: 7187

Added:
   dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/LegacyBlocksIQHandler.java
   dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/LegacyContactsIQHandler.java
   dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/LegacyGroupIQHandler.java
Removed:
   dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/OldBlocksIQHandler.java
   dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/OldContactsIQHandler.java
   dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/OldGroupIQHandler.java
Modified:
   dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/HippoPlugin.java
Log:
Consistently use Legacy* not Old* to name pre-data-model IQ handlers

Modified: dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/HippoPlugin.java
===================================================================
--- dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/HippoPlugin.java	2008-01-11 00:09:12 UTC (rev 7186)
+++ dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/HippoPlugin.java	2008-01-11 16:01:17 UTC (rev 7187)
@@ -90,15 +90,15 @@
 			addIQHandler(new HotnessIQHandler());	
 			addIQHandler(new RecentPostsIQHandler());
 			addIQHandler(new PostControlsIQHandler());
-			addIQHandler(new OldGroupIQHandler());	
+			addIQHandler(new LegacyGroupIQHandler());	
 			addIQHandler(new GroupsIQHandler());	
-			addIQHandler(new OldBlocksIQHandler());
+			addIQHandler(new LegacyBlocksIQHandler());
 			addIQHandler(new BlocksIQHandler());
 			addIQHandler(new AccountQuestionIQHandler());
 			addIQHandler(new SettingsIQHandler());			
 			addIQHandler(new LegacySettingsIQHandler());
 			addIQHandler(new WhereImIQHandler());
-			addIQHandler(new OldContactsIQHandler());
+			addIQHandler(new LegacyContactsIQHandler());
 			addIQHandler(new ContactsIQHandler());
 			addIQHandler(new EntityIQHandler());			
 			

Copied: dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/LegacyBlocksIQHandler.java (from rev 7170, dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/OldBlocksIQHandler.java)
===================================================================
--- dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/OldBlocksIQHandler.java	2008-01-10 03:53:49 UTC (rev 7170)
+++ dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/LegacyBlocksIQHandler.java	2008-01-11 16:01:17 UTC (rev 7187)
@@ -0,0 +1,150 @@
+package com.dumbhippo.jive;
+
+import java.util.Collections;
+import java.util.List;
+
+import javax.ejb.EJB;
+
+import org.dom4j.Element;
+import org.jivesoftware.util.Log;
+import org.xmpp.packet.IQ;
+
+import com.dumbhippo.TypeUtils;
+import com.dumbhippo.XmlBuilder;
+import com.dumbhippo.identity20.Guid;
+import com.dumbhippo.identity20.Guid.ParseException;
+import com.dumbhippo.jive.annotations.IQHandler;
+import com.dumbhippo.jive.annotations.IQMethod;
+import com.dumbhippo.persistence.UserBlockData;
+import com.dumbhippo.server.NotFoundException;
+import com.dumbhippo.server.Pageable;
+import com.dumbhippo.server.Stacker;
+import com.dumbhippo.server.ViewStreamBuilder;
+import com.dumbhippo.server.blocks.BlockView;
+import com.dumbhippo.server.views.ObjectView;
+import com.dumbhippo.server.views.UserViewpoint;
+import com.dumbhippo.server.views.ViewStream;
+
+ IQHandler(namespace=LegacyBlocksIQHandler.BLOCKS_NAMESPACE)
+public class LegacyBlocksIQHandler extends AnnotatedIQHandler {
+	static final String BLOCKS_NAMESPACE = "http://dumbhippo.com/protocol/blocks";; 
+	
+	@EJB
+	private Stacker stacker;
+	
+	@EJB
+	private ViewStreamBuilder viewStreamBuilder;
+
+	public LegacyBlocksIQHandler() {
+		super("Old Hippo Blocks IQ Handler");
+		Log.debug("creating OldBlocksIQHandler");
+	}
+	
+	private String getBlocksXml(UserViewpoint viewpoint, String filter, String elementName, List<BlockView> views) {
+		List<ObjectView> objectList = TypeUtils.castList(ObjectView.class, views);
+		
+		XmlBuilder xml = new XmlBuilder();
+		
+		xml.openElement(elementName,
+					    "xmlns", BLOCKS_NAMESPACE,
+					    "filter", filter,
+				        "serverTime", Long.toString(System.currentTimeMillis()));
+		
+		ViewStream stream = viewStreamBuilder.buildStream(viewpoint, objectList);
+		stream.writeToXmlBuilder(xml);
+		
+		xml.closeElement();
+		
+		return xml.toString();
+	}
+
+	private boolean parseBoolean(String value) throws IQException {
+        if (value.equals("true"))
+        	return true;
+        else if (value.equals("false"))
+        	return false;
+        else
+        	throw IQException.createBadRequest("Unrecognized boolean value '" + value + "'");
+	}
+	
+	@IQMethod(name="blocks", type=IQ.Type.get)
+	public void getBlocks(UserViewpoint viewpoint, IQ request, IQ reply) throws IQException {
+		Element child = request.getChildElement();
+		
+        String lastTimestampStr = child.attributeValue("lastTimestamp");
+        if (lastTimestampStr == null)
+        	throw IQException.createBadRequest("get/blocks IQ missing lastTimestamp attribute");
+        
+        String filter = child.attributeValue("filter");
+        boolean filterProvided = (filter != null);
+        if (!filterProvided) {
+        	filter = stacker.getUserStackFilterPrefs(viewpoint.getViewer());
+        } else {
+        	stacker.setUserStackFilterPrefs(viewpoint.getViewer(), filter);
+        }
+        
+        long lastTimestamp;
+        try {
+        	lastTimestamp = Long.parseLong(lastTimestampStr);
+        } catch (NumberFormatException e) {
+        	throw IQException.createBadRequest("get/blocks IQ lastTimestamp attribute not valid");
+        }      
+        
+		Pageable<BlockView> pageable = new Pageable<BlockView>("stack");
+		pageable.setPosition(0);
+		pageable.setInitialPerPage(25);
+		stacker.pageStack(viewpoint, viewpoint.getViewer(), pageable, lastTimestamp, filter, false);
+		List<BlockView> views = pageable.getResults();
+		
+		// If views.size() == 0, there can be no missing unanswered questions; skip to avoid having
+		// to deal with the 'views.size() - 1 == -1' case
+		if (lastTimestamp <= 0 && views.size() > 0) {
+			long earliestTimestamp = views.get(views.size() - 1).getUserBlockData().getStackTimestampAsLong();
+			views.addAll(stacker.getUnansweredQuestions(viewpoint, earliestTimestamp));
+		}
+		
+		String xml = getBlocksXml(viewpoint, filterProvided ? null : filter, "blocks", views);
+        
+		reply.setChildElement(XmlParser.elementFromXml(xml));
+	}
+
+	@IQMethod(name="blockHushed", type=IQ.Type.set)
+	public void setBlockHushed(UserViewpoint viewpoint, IQ request, IQ reply) throws IQException {
+		Element child = request.getChildElement();
+		
+        String blockId = child.attributeValue("blockId");
+        if (blockId == null)
+        	throw IQException.createBadRequest("missing blockId attribute");
+        Guid blockGuid;
+        try {
+        	blockGuid = new Guid(blockId);
+        } catch (ParseException e) {
+        	throw IQException.createBadRequest("invalid blockId attribute");
+        }
+        
+        UserBlockData userBlockData;
+        try {
+			userBlockData = stacker.lookupUserBlockData(viewpoint, blockGuid);
+		} catch (NotFoundException e) {
+        	throw IQException.createBadRequest("blockId attribute doesn't refer to a recognized block for this user");
+		}
+        
+        String value = child.attributeValue("hushed");
+        if (value == null)
+        	throw IQException.createBadRequest("missing hushed attribute");
+        
+        boolean hushed = parseBoolean(value);
+        
+        stacker.setBlockHushed(userBlockData, hushed);
+        
+        BlockView blockView;
+		try {
+			blockView = stacker.loadBlock(viewpoint, userBlockData);
+		} catch (NotFoundException e) {
+			throw new RuntimeException("Can't load block view for the user's own block", e);
+		}
+        
+		String xml = getBlocksXml(viewpoint, null, "blockHushed", Collections.singletonList(blockView));
+		reply.setChildElement(XmlParser.elementFromXml(xml));
+	}
+}

Copied: dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/LegacyContactsIQHandler.java (from rev 7169, dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/OldContactsIQHandler.java)
===================================================================
--- dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/OldContactsIQHandler.java	2008-01-10 03:26:26 UTC (rev 7169)
+++ dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/LegacyContactsIQHandler.java	2008-01-11 16:01:17 UTC (rev 7187)
@@ -0,0 +1,90 @@
+package com.dumbhippo.jive;
+
+import java.util.List;
+import java.util.Set;
+
+import javax.ejb.EJB;
+
+import org.jivesoftware.util.Log;
+import org.xmpp.packet.IQ;
+
+import com.dumbhippo.TypeUtils;
+import com.dumbhippo.XmlBuilder;
+import com.dumbhippo.jive.annotations.IQHandler;
+import com.dumbhippo.jive.annotations.IQMethod;
+import com.dumbhippo.server.GroupSystem;
+import com.dumbhippo.server.PersonViewer;
+import com.dumbhippo.server.ViewStreamBuilder;
+import com.dumbhippo.server.views.GroupView;
+import com.dumbhippo.server.views.ObjectView;
+import com.dumbhippo.server.views.PersonView;
+import com.dumbhippo.server.views.PersonViewExtra;
+import com.dumbhippo.server.views.UserViewpoint;
+import com.dumbhippo.server.views.ViewStream;
+
+/** 
+ * IQ handler for getting / monitoring your social network (groups, contacts)
+ * 
+ * TODO: switch all users to the data model and delete this
+ * 
+ * @author Havoc Pennington
+ *
+ */
+ IQHandler(namespace=LegacyContactsIQHandler.CONTACTS_NAMESPACE)
+public class LegacyContactsIQHandler extends AnnotatedIQHandler {
+	static final String CONTACTS_NAMESPACE = "http://dumbhippo.com/protocol/contacts";;
+	
+	@EJB
+	private GroupSystem groupSystem;
+	
+	@EJB
+	private PersonViewer personViewer;
+	
+	@EJB
+	private ViewStreamBuilder viewStreamBuilder;
+	
+	public LegacyContactsIQHandler() {
+		super("Hippo contacts IQ Handler");
+		Log.debug("creating ContactsIQHandler");
+	}
+	
+	@IQMethod(name="contacts", type=IQ.Type.get)
+	public void getContacts(UserViewpoint viewpoint, IQ request, IQ reply) throws IQException {
+		List<PersonView> persons = personViewer.getContacts(viewpoint, viewpoint.getViewer(),
+				0, -1, PersonViewExtra.CONTACT_STATUS);
+		// Add the user themself to the list of returned contacts (whether or not the
+		// viewer is in their own contact list getContacts() strips it out.)
+		persons.add(personViewer.getPersonView(viewpoint, viewpoint.getViewer(), PersonViewExtra.CONTACT_STATUS));
+		
+		ViewStream stream = viewStreamBuilder.buildStream(viewpoint, TypeUtils.castList(ObjectView.class, persons));
+		
+		XmlBuilder xml = new XmlBuilder();
+		
+		xml.openElement("contacts",
+			    "xmlns", CONTACTS_NAMESPACE);
+		
+		stream.writeToXmlBuilder(xml);
+		
+		xml.closeElement();
+		
+		reply.setChildElement(XmlParser.elementFromXml(xml.toString()));
+	}
+	
+	@IQMethod(name="groups", type=IQ.Type.get)
+	public void getGroups(UserViewpoint viewpoint, IQ request, IQ reply) throws IQException {
+		Set<GroupView> groups = groupSystem.findGroups(viewpoint, viewpoint.getViewer());
+		
+		ViewStream stream = viewStreamBuilder.buildStream(viewpoint, TypeUtils.castSet(ObjectView.class, groups));
+		
+		XmlBuilder xml = new XmlBuilder();
+		
+		xml.openElement("groups",
+			    "xmlns", CONTACTS_NAMESPACE);
+		
+		stream.writeToXmlBuilder(xml);
+		
+		xml.closeElement();
+		
+		reply.setChildElement(XmlParser.elementFromXml(xml.toString()));
+	}
+}

Copied: dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/LegacyGroupIQHandler.java (from rev 7184, dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/OldGroupIQHandler.java)
===================================================================
--- dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/OldGroupIQHandler.java	2008-01-10 23:22:48 UTC (rev 7184)
+++ dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/LegacyGroupIQHandler.java	2008-01-11 16:01:17 UTC (rev 7187)
@@ -0,0 +1,63 @@
+package com.dumbhippo.jive;
+
+import org.dom4j.Element;
+import org.jivesoftware.util.Log;
+import org.jivesoftware.openfire.IQHandlerInfo;
+import org.jivesoftware.openfire.auth.UnauthorizedException;
+import org.xmpp.packet.IQ;
+import org.xmpp.packet.JID;
+import org.xmpp.packet.PacketError.Condition;
+
+import com.dumbhippo.identity20.Guid;
+import com.dumbhippo.identity20.Guid.ParseException;
+import com.dumbhippo.server.MessengerGlue;
+import com.dumbhippo.server.NotFoundException;
+import com.dumbhippo.server.util.EJBUtil;
+
+public class LegacyGroupIQHandler extends AbstractIQHandler {
+
+	private IQHandlerInfo info;
+	
+	public LegacyGroupIQHandler() {
+		super("DumbHippo Group IQ Handler");
+		
+		Log.debug("creating Group handler");
+		info = new IQHandlerInfo("groupSystem", "http://dumbhippo.com/protocol/groupSystem";);
+	}
+
+	@Override
+	public IQ handleIQ(IQ packet) throws UnauthorizedException {
+		
+		Log.debug("handling IQ packet " + packet);
+		JID from = packet.getFrom();
+		IQ reply = IQ.createResultIQ(packet);
+		
+		Element element = packet.getChildElement();
+		String type = element.attributeValue("op");		
+		String groupId = element.attributeValue("groupId");
+		String userId = element.attributeValue("userId");
+		
+		MessengerGlue glue = EJBUtil.defaultLookup(MessengerGlue.class);
+		if (type.equals("addMember")) {
+			try {
+				glue.addGroupMember(Guid.parseTrustedJabberId(from.getNode()), 
+								    new Guid(groupId), new Guid(userId));
+			} catch (NotFoundException e) {
+				Log.error(e);
+				reply.setError(Condition.internal_server_error);
+			} catch (ParseException e) {
+				Log.error(e);
+				reply.setError(Condition.internal_server_error);
+			}
+		} else {
+			reply.setError(Condition.item_not_found);
+		}
+		
+		return reply;
+	}
+
+	@Override
+	public IQHandlerInfo getInfo() {
+		return info;
+	}
+}

Deleted: dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/OldBlocksIQHandler.java
===================================================================
--- dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/OldBlocksIQHandler.java	2008-01-11 00:09:12 UTC (rev 7186)
+++ dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/OldBlocksIQHandler.java	2008-01-11 16:01:17 UTC (rev 7187)
@@ -1,150 +0,0 @@
-package com.dumbhippo.jive;
-
-import java.util.Collections;
-import java.util.List;
-
-import javax.ejb.EJB;
-
-import org.dom4j.Element;
-import org.jivesoftware.util.Log;
-import org.xmpp.packet.IQ;
-
-import com.dumbhippo.TypeUtils;
-import com.dumbhippo.XmlBuilder;
-import com.dumbhippo.identity20.Guid;
-import com.dumbhippo.identity20.Guid.ParseException;
-import com.dumbhippo.jive.annotations.IQHandler;
-import com.dumbhippo.jive.annotations.IQMethod;
-import com.dumbhippo.persistence.UserBlockData;
-import com.dumbhippo.server.NotFoundException;
-import com.dumbhippo.server.Pageable;
-import com.dumbhippo.server.Stacker;
-import com.dumbhippo.server.ViewStreamBuilder;
-import com.dumbhippo.server.blocks.BlockView;
-import com.dumbhippo.server.views.ObjectView;
-import com.dumbhippo.server.views.UserViewpoint;
-import com.dumbhippo.server.views.ViewStream;
-
- IQHandler(namespace=OldBlocksIQHandler.BLOCKS_NAMESPACE)
-public class OldBlocksIQHandler extends AnnotatedIQHandler {
-	static final String BLOCKS_NAMESPACE = "http://dumbhippo.com/protocol/blocks";; 
-	
-	@EJB
-	private Stacker stacker;
-	
-	@EJB
-	private ViewStreamBuilder viewStreamBuilder;
-
-	public OldBlocksIQHandler() {
-		super("Old Hippo Blocks IQ Handler");
-		Log.debug("creating OldBlocksIQHandler");
-	}
-	
-	private String getBlocksXml(UserViewpoint viewpoint, String filter, String elementName, List<BlockView> views) {
-		List<ObjectView> objectList = TypeUtils.castList(ObjectView.class, views);
-		
-		XmlBuilder xml = new XmlBuilder();
-		
-		xml.openElement(elementName,
-					    "xmlns", BLOCKS_NAMESPACE,
-					    "filter", filter,
-				        "serverTime", Long.toString(System.currentTimeMillis()));
-		
-		ViewStream stream = viewStreamBuilder.buildStream(viewpoint, objectList);
-		stream.writeToXmlBuilder(xml);
-		
-		xml.closeElement();
-		
-		return xml.toString();
-	}
-
-	private boolean parseBoolean(String value) throws IQException {
-        if (value.equals("true"))
-        	return true;
-        else if (value.equals("false"))
-        	return false;
-        else
-        	throw IQException.createBadRequest("Unrecognized boolean value '" + value + "'");
-	}
-	
-	@IQMethod(name="blocks", type=IQ.Type.get)
-	public void getBlocks(UserViewpoint viewpoint, IQ request, IQ reply) throws IQException {
-		Element child = request.getChildElement();
-		
-        String lastTimestampStr = child.attributeValue("lastTimestamp");
-        if (lastTimestampStr == null)
-        	throw IQException.createBadRequest("get/blocks IQ missing lastTimestamp attribute");
-        
-        String filter = child.attributeValue("filter");
-        boolean filterProvided = (filter != null);
-        if (!filterProvided) {
-        	filter = stacker.getUserStackFilterPrefs(viewpoint.getViewer());
-        } else {
-        	stacker.setUserStackFilterPrefs(viewpoint.getViewer(), filter);
-        }
-        
-        long lastTimestamp;
-        try {
-        	lastTimestamp = Long.parseLong(lastTimestampStr);
-        } catch (NumberFormatException e) {
-        	throw IQException.createBadRequest("get/blocks IQ lastTimestamp attribute not valid");
-        }      
-        
-		Pageable<BlockView> pageable = new Pageable<BlockView>("stack");
-		pageable.setPosition(0);
-		pageable.setInitialPerPage(25);
-		stacker.pageStack(viewpoint, viewpoint.getViewer(), pageable, lastTimestamp, filter, false);
-		List<BlockView> views = pageable.getResults();
-		
-		// If views.size() == 0, there can be no missing unanswered questions; skip to avoid having
-		// to deal with the 'views.size() - 1 == -1' case
-		if (lastTimestamp <= 0 && views.size() > 0) {
-			long earliestTimestamp = views.get(views.size() - 1).getUserBlockData().getStackTimestampAsLong();
-			views.addAll(stacker.getUnansweredQuestions(viewpoint, earliestTimestamp));
-		}
-		
-		String xml = getBlocksXml(viewpoint, filterProvided ? null : filter, "blocks", views);
-        
-		reply.setChildElement(XmlParser.elementFromXml(xml));
-	}
-
-	@IQMethod(name="blockHushed", type=IQ.Type.set)
-	public void setBlockHushed(UserViewpoint viewpoint, IQ request, IQ reply) throws IQException {
-		Element child = request.getChildElement();
-		
-        String blockId = child.attributeValue("blockId");
-        if (blockId == null)
-        	throw IQException.createBadRequest("missing blockId attribute");
-        Guid blockGuid;
-        try {
-        	blockGuid = new Guid(blockId);
-        } catch (ParseException e) {
-        	throw IQException.createBadRequest("invalid blockId attribute");
-        }
-        
-        UserBlockData userBlockData;
-        try {
-			userBlockData = stacker.lookupUserBlockData(viewpoint, blockGuid);
-		} catch (NotFoundException e) {
-        	throw IQException.createBadRequest("blockId attribute doesn't refer to a recognized block for this user");
-		}
-        
-        String value = child.attributeValue("hushed");
-        if (value == null)
-        	throw IQException.createBadRequest("missing hushed attribute");
-        
-        boolean hushed = parseBoolean(value);
-        
-        stacker.setBlockHushed(userBlockData, hushed);
-        
-        BlockView blockView;
-		try {
-			blockView = stacker.loadBlock(viewpoint, userBlockData);
-		} catch (NotFoundException e) {
-			throw new RuntimeException("Can't load block view for the user's own block", e);
-		}
-        
-		String xml = getBlocksXml(viewpoint, null, "blockHushed", Collections.singletonList(blockView));
-		reply.setChildElement(XmlParser.elementFromXml(xml));
-	}
-}

Deleted: dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/OldContactsIQHandler.java
===================================================================
--- dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/OldContactsIQHandler.java	2008-01-11 00:09:12 UTC (rev 7186)
+++ dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/OldContactsIQHandler.java	2008-01-11 16:01:17 UTC (rev 7187)
@@ -1,90 +0,0 @@
-package com.dumbhippo.jive;
-
-import java.util.List;
-import java.util.Set;
-
-import javax.ejb.EJB;
-
-import org.jivesoftware.util.Log;
-import org.xmpp.packet.IQ;
-
-import com.dumbhippo.TypeUtils;
-import com.dumbhippo.XmlBuilder;
-import com.dumbhippo.jive.annotations.IQHandler;
-import com.dumbhippo.jive.annotations.IQMethod;
-import com.dumbhippo.server.GroupSystem;
-import com.dumbhippo.server.PersonViewer;
-import com.dumbhippo.server.ViewStreamBuilder;
-import com.dumbhippo.server.views.GroupView;
-import com.dumbhippo.server.views.ObjectView;
-import com.dumbhippo.server.views.PersonView;
-import com.dumbhippo.server.views.PersonViewExtra;
-import com.dumbhippo.server.views.UserViewpoint;
-import com.dumbhippo.server.views.ViewStream;
-
-/** 
- * IQ handler for getting / monitoring your social network (groups, contacts)
- * 
- * TODO: switch all users to the data model and delete this
- * 
- * @author Havoc Pennington
- *
- */
- IQHandler(namespace=OldContactsIQHandler.CONTACTS_NAMESPACE)
-public class OldContactsIQHandler extends AnnotatedIQHandler {
-	static final String CONTACTS_NAMESPACE = "http://dumbhippo.com/protocol/contacts";;
-	
-	@EJB
-	private GroupSystem groupSystem;
-	
-	@EJB
-	private PersonViewer personViewer;
-	
-	@EJB
-	private ViewStreamBuilder viewStreamBuilder;
-	
-	public OldContactsIQHandler() {
-		super("Hippo contacts IQ Handler");
-		Log.debug("creating ContactsIQHandler");
-	}
-	
-	@IQMethod(name="contacts", type=IQ.Type.get)
-	public void getContacts(UserViewpoint viewpoint, IQ request, IQ reply) throws IQException {
-		List<PersonView> persons = personViewer.getContacts(viewpoint, viewpoint.getViewer(),
-				0, -1, PersonViewExtra.CONTACT_STATUS);
-		// Add the user themself to the list of returned contacts (whether or not the
-		// viewer is in their own contact list getContacts() strips it out.)
-		persons.add(personViewer.getPersonView(viewpoint, viewpoint.getViewer(), PersonViewExtra.CONTACT_STATUS));
-		
-		ViewStream stream = viewStreamBuilder.buildStream(viewpoint, TypeUtils.castList(ObjectView.class, persons));
-		
-		XmlBuilder xml = new XmlBuilder();
-		
-		xml.openElement("contacts",
-			    "xmlns", CONTACTS_NAMESPACE);
-		
-		stream.writeToXmlBuilder(xml);
-		
-		xml.closeElement();
-		
-		reply.setChildElement(XmlParser.elementFromXml(xml.toString()));
-	}
-	
-	@IQMethod(name="groups", type=IQ.Type.get)
-	public void getGroups(UserViewpoint viewpoint, IQ request, IQ reply) throws IQException {
-		Set<GroupView> groups = groupSystem.findGroups(viewpoint, viewpoint.getViewer());
-		
-		ViewStream stream = viewStreamBuilder.buildStream(viewpoint, TypeUtils.castSet(ObjectView.class, groups));
-		
-		XmlBuilder xml = new XmlBuilder();
-		
-		xml.openElement("groups",
-			    "xmlns", CONTACTS_NAMESPACE);
-		
-		stream.writeToXmlBuilder(xml);
-		
-		xml.closeElement();
-		
-		reply.setChildElement(XmlParser.elementFromXml(xml.toString()));
-	}
-}

Deleted: dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/OldGroupIQHandler.java
===================================================================
--- dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/OldGroupIQHandler.java	2008-01-11 00:09:12 UTC (rev 7186)
+++ dumbhippo/trunk/openfire/src/plugins/hippo/src/java/com/dumbhippo/jive/OldGroupIQHandler.java	2008-01-11 16:01:17 UTC (rev 7187)
@@ -1,63 +0,0 @@
-package com.dumbhippo.jive;
-
-import org.dom4j.Element;
-import org.jivesoftware.util.Log;
-import org.jivesoftware.openfire.IQHandlerInfo;
-import org.jivesoftware.openfire.auth.UnauthorizedException;
-import org.xmpp.packet.IQ;
-import org.xmpp.packet.JID;
-import org.xmpp.packet.PacketError.Condition;
-
-import com.dumbhippo.identity20.Guid;
-import com.dumbhippo.identity20.Guid.ParseException;
-import com.dumbhippo.server.MessengerGlue;
-import com.dumbhippo.server.NotFoundException;
-import com.dumbhippo.server.util.EJBUtil;
-
-public class OldGroupIQHandler extends AbstractIQHandler {
-
-	private IQHandlerInfo info;
-	
-	public OldGroupIQHandler() {
-		super("DumbHippo Group IQ Handler");
-		
-		Log.debug("creating Group handler");
-		info = new IQHandlerInfo("groupSystem", "http://dumbhippo.com/protocol/groupSystem";);
-	}
-
-	@Override
-	public IQ handleIQ(IQ packet) throws UnauthorizedException {
-		
-		Log.debug("handling IQ packet " + packet);
-		JID from = packet.getFrom();
-		IQ reply = IQ.createResultIQ(packet);
-		
-		Element element = packet.getChildElement();
-		String type = element.attributeValue("op");		
-		String groupId = element.attributeValue("groupId");
-		String userId = element.attributeValue("userId");
-		
-		MessengerGlue glue = EJBUtil.defaultLookup(MessengerGlue.class);
-		if (type.equals("addMember")) {
-			try {
-				glue.addGroupMember(Guid.parseTrustedJabberId(from.getNode()), 
-								    new Guid(groupId), new Guid(userId));
-			} catch (NotFoundException e) {
-				Log.error(e);
-				reply.setError(Condition.internal_server_error);
-			} catch (ParseException e) {
-				Log.error(e);
-				reply.setError(Condition.internal_server_error);
-			}
-		} else {
-			reply.setError(Condition.item_not_found);
-		}
-		
-		return reply;
-	}
-
-	@Override
-	public IQHandlerInfo getInfo() {
-		return info;
-	}
-}



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