r7126 - in dumbhippo/trunk/server/src/com/dumbhippo: server/dm server/impl server/views web/servlets



Author: otaylor
Date: 2008-01-03 15:21:56 -0600 (Thu, 03 Jan 2008)
New Revision: 7126

Added:
   dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupChatBlockDMO.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupMessageDMO.java
Modified:
   dumbhippo/trunk/server/src/com/dumbhippo/server/dm/BlockDMO.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ChatMessageDMO.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/dm/DataService.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupDMO.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/impl/GroupSystemBean.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/impl/HttpMethodsBean.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/views/AnonymousViewpoint.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/views/SystemViewpoint.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/views/UserViewpoint.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/views/Viewpoint.java
   dumbhippo/trunk/server/src/com/dumbhippo/web/servlets/GroupPhotoServlet.java
Log:
GroupDMO: Add group data model object
Viewpoint UserViewpoint SystemViewpoint AnonymousViewpoint: Add canSeeGroup()
GroupSystemBean HttpMethodsBean GroupPhotoServlet: Notify on changes to
  GroupDMO properties

GroupChatBlockDMO BlockDMO: Add data model object for group chat blocks


Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/BlockDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/BlockDMO.java	2008-01-02 20:00:34 UTC (rev 7125)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/BlockDMO.java	2008-01-03 21:21:56 UTC (rev 7126)
@@ -88,9 +88,11 @@
 		case PICASA_PERSON:
 			return PicasaPersonBlockDMO.class;
 			
+		case GROUP_CHAT:
+			return GroupChatBlockDMO.class;
+
 		default:
 		case GROUP_MEMBER: 
-		case GROUP_CHAT:
 		case MUSIC_PERSON:
 		case FACEBOOK_EVENT:
 		case FLICKR_PHOTOSET:

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ChatMessageDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ChatMessageDMO.java	2008-01-02 20:00:34 UTC (rev 7125)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/ChatMessageDMO.java	2008-01-03 21:21:56 UTC (rev 7126)
@@ -36,6 +36,7 @@
 		case POST:
 			return PostMessageDMO.class;
 		case GROUP:
+			return GroupMessageDMO.class;
 		case TRACK:
 			return null;
 		}

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/DataService.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/DataService.java	2008-01-02 20:00:34 UTC (rev 7125)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/DataService.java	2008-01-03 21:21:56 UTC (rev 7126)
@@ -89,17 +89,20 @@
 		model.addDMClass(ApplicationDMO.class);
 		
 		model.addDMClass(BlockDMO.class);
+		model.addDMClass(GroupChatBlockDMO.class);
 		model.addDMClass(ThumbnailsBlockDMO.class);
 		model.addDMClass(PicasaPersonBlockDMO.class);
 		model.addDMClass(PostBlockDMO.class);
 		
 		model.addDMClass(ChatMessageDMO.class);
 		model.addDMClass(BlockMessageDMO.class);
+		model.addDMClass(GroupMessageDMO.class);
 		model.addDMClass(PostMessageDMO.class);
 
 		model.addDMClass(ContactDMO.class);
 		model.addDMClass(DesktopSettingDMO.class);
 		model.addDMClass(ExternalAccountDMO.class);
+		model.addDMClass(GroupDMO.class);
 		model.addDMClass(PostDMO.class);
 		
 		model.addDMClass(ThumbnailDMO.class);

Added: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupChatBlockDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupChatBlockDMO.java	2008-01-02 20:00:34 UTC (rev 7125)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupChatBlockDMO.java	2008-01-03 21:21:56 UTC (rev 7126)
@@ -0,0 +1,28 @@
+package com.dumbhippo.server.dm;
+
+import com.dumbhippo.dm.annotations.DMO;
+import com.dumbhippo.dm.annotations.DMProperty;
+import com.dumbhippo.dm.store.StoreKey;
+import com.dumbhippo.server.blocks.GroupChatBlockView;
+
+ DMO(classId="http://mugshot.org/p/o/groupChatBlock";)
+public abstract class GroupChatBlockDMO extends BlockDMO {
+	protected GroupChatBlockDMO(BlockDMOKey key) {
+		super(key);
+	}
+
+	@Override
+	public String getChatId() {
+		return ((GroupChatBlockView)blockView).getGroupView().getGroup().getId();
+	}
+	
+	@DMProperty(defaultInclude=true, defaultChildren="+")
+	public GroupDMO getGroup() {
+		return session.findUnchecked(GroupDMO.class, ((GroupChatBlockView)blockView).getGroupView().getGroup().getGuid());
+	}
+	
+	@Override
+	public StoreKey<?,?> getVisibilityDelegate() {
+		return getGroup().getStoreKey();
+	}
+}

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupDMO.java	2008-01-02 20:00:34 UTC (rev 7125)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupDMO.java	2008-01-03 21:21:56 UTC (rev 7126)
@@ -1,15 +1,21 @@
 package com.dumbhippo.server.dm;
 
+import java.util.HashSet;
+import java.util.Set;
+
 import javax.persistence.EntityManager;
 
 import com.dumbhippo.dm.DMObject;
+import com.dumbhippo.dm.DMSession;
 import com.dumbhippo.dm.annotations.DMFilter;
 import com.dumbhippo.dm.annotations.DMO;
 import com.dumbhippo.dm.annotations.DMProperty;
 import com.dumbhippo.dm.annotations.Inject;
 import com.dumbhippo.dm.annotations.PropertyType;
 import com.dumbhippo.identity20.Guid;
+import com.dumbhippo.persistence.AccountClaim;
 import com.dumbhippo.persistence.Group;
+import com.dumbhippo.persistence.GroupMember;
 import com.dumbhippo.server.NotFoundException;
 
 @DMO(classId="http://mugshot.org/p/o/group";, resourceBase="/o/group")
@@ -18,6 +24,9 @@
 	@Inject
 	private EntityManager em;
 	
+	@Inject
+	private DMSession session;
+	
 	private Group group;
 	
 	protected GroupDMO(Guid key) {
@@ -45,4 +54,26 @@
 	public String getHomeUrl() {
 		return "/group?who=" + group.getId();
 	}
+	
+	@DMProperty
+	public boolean isPublic() {
+		return group.isPublic();
+	}
+
+	// for visibility purposes; this will include members that have removed themselves, so
+	// it shouldn't be used for display purposes.
+	@DMProperty
+	public Set<UserDMO> getCanSeeMembers() {
+		Set<UserDMO> result = new HashSet<UserDMO>();
+		
+		for (GroupMember gm : group.getMembers()) {
+			if (gm.getStatus().getCanSeeSecretGroup()) {
+				AccountClaim accountClaim = gm.getMember().getAccountClaim();
+				if (accountClaim != null)
+					result.add(session.findUnchecked(UserDMO.class, accountClaim.getOwner().getGuid()));
+			}
+		}
+		
+		return result;
+	}
 }

Added: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupMessageDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupMessageDMO.java	2008-01-02 20:00:34 UTC (rev 7125)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupMessageDMO.java	2008-01-03 21:21:56 UTC (rev 7126)
@@ -0,0 +1,26 @@
+package com.dumbhippo.server.dm;
+
+import com.dumbhippo.dm.annotations.DMO;
+import com.dumbhippo.dm.store.StoreKey;
+import com.dumbhippo.persistence.GroupMessage;
+import com.dumbhippo.server.NotFoundException;
+
+ DMO(classId="http://mugshot.org/p/o/groupMessage";)
+public abstract class GroupMessageDMO extends ChatMessageDMO {
+	protected GroupMessageDMO(ChatMessageKey key) {
+		super(key);
+	}
+
+	@Override
+	protected void init() throws NotFoundException {
+		message = em.find(GroupMessage.class, getKey().getId());
+		if (message == null)
+			throw new NotFoundException("No such group message");
+	}
+	
+	@Override
+	public StoreKey<?,?> getVisibilityDelegate() {
+		GroupDMO group = session.findUnchecked(GroupDMO.class, ((GroupMessage)message).getGroup().getGuid()); 
+		return group.getStoreKey();
+	}
+}

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/GroupSystemBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/GroupSystemBean.java	2008-01-02 20:00:34 UTC (rev 7125)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/GroupSystemBean.java	2008-01-03 21:21:56 UTC (rev 7126)
@@ -51,6 +51,8 @@
 import com.dumbhippo.server.Pageable;
 import com.dumbhippo.server.PersonViewer;
 import com.dumbhippo.server.RevisionControl;
+import com.dumbhippo.server.dm.DataService;
+import com.dumbhippo.server.dm.GroupDMO;
 import com.dumbhippo.server.util.EJBUtil;
 import com.dumbhippo.server.views.GroupMemberView;
 import com.dumbhippo.server.views.GroupView;
@@ -380,6 +382,7 @@
 			notifier.onGroupMemberCreated(groupMember, now, notifyGroupMembers);
 		}
 		
+		DataService.currentSessionRW().changed(GroupDMO.class, group.getGuid(), "canSeeMembers");
         LiveState.getInstance().queueUpdate(new GroupEvent(group.getGuid(), groupMember.getMember().getGuid(),
         		GroupEvent.Detail.MEMBERS_CHANGED));
 	}
@@ -413,6 +416,7 @@
 		boolean needToInviteFollowers = (group.getAccess() != GroupAccess.PUBLIC && open);
 		
 		group.setAccess(open ? GroupAccess.PUBLIC : GroupAccess.PUBLIC_INVITE);
+		DataService.currentSessionRW().changed(GroupDMO.class, group.getGuid(), "isPublic");
 		
 		int followers = -1;
 		int invitedFollowers = -1;
@@ -482,6 +486,7 @@
 			groupMember.setStatus(MembershipStatus.REMOVED);
 			
 			notifier.onGroupMemberStatusChanged(groupMember, System.currentTimeMillis(), true);
+			DataService.currentSessionRW().changed(GroupDMO.class, group.getGuid(), "canSeeMembers");
 	        LiveState.getInstance().queueUpdate(new GroupEvent(group.getGuid(),
 	        		groupMember.getMember().getGuid(), GroupEvent.Detail.MEMBERS_CHANGED));
 		} else if (groupMember.getStatus().ordinal() < MembershipStatus.REMOVED.ordinal()) {
@@ -491,6 +496,7 @@
 			
 			// we don't stackGroupMember here, we only care about transitions to REMOVED for timestamp 
 			// updating (right now anyway)
+			DataService.currentSessionRW().changed(GroupDMO.class, group.getGuid(), "canSeeMembers");
 			LiveState.getInstance().queueUpdate(new GroupEvent(group.getGuid(),
 					groupMember.getMember().getGuid(), GroupEvent.Detail.MEMBERS_CHANGED));
 		} else {
@@ -946,6 +952,8 @@
 			throw new RuntimeException("invalid stock photo name");
 		
 		group.setStockPhoto(photo);
+		
+		DataService.currentSessionRW().changed(GroupDMO.class, group.getGuid(), "photoUrl");
 	}
 
 	public GroupView loadGroup(Viewpoint viewpoint, Guid guid) throws NotFoundException {

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/HttpMethodsBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/HttpMethodsBean.java	2008-01-02 20:00:34 UTC (rev 7125)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/HttpMethodsBean.java	2008-01-03 21:21:56 UTC (rev 7126)
@@ -126,6 +126,7 @@
 import com.dumbhippo.server.dm.DataService;
 import com.dumbhippo.server.dm.ExternalAccountDMO;
 import com.dumbhippo.server.dm.ExternalAccountKey;
+import com.dumbhippo.server.dm.GroupDMO;
 import com.dumbhippo.server.dm.UserDMO;
 import com.dumbhippo.server.util.EJBUtil;
 import com.dumbhippo.server.views.EntityView;
@@ -566,6 +567,7 @@
 					
 		group.setName(name);
 		revisionControl.persistRevision(new GroupNameChangedRevision(viewpoint.getViewer(), group, new Date(), name));
+		DataService.currentSessionRW().changed(GroupDMO.class, group.getGuid(), "name");
 	}
 	
 	public void doSetGroupDescription(UserViewpoint viewpoint, Group group, String description) {

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/views/AnonymousViewpoint.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/views/AnonymousViewpoint.java	2008-01-02 20:00:34 UTC (rev 7125)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/views/AnonymousViewpoint.java	2008-01-03 21:21:56 UTC (rev 7126)
@@ -75,6 +75,16 @@
 	
 
 	@Override
+	public boolean canSeeGroup(Guid groupId) {
+		try {
+			DMSession session = DataService.getModel().currentSession();
+			return (Boolean)session.getRawProperty(PostDMO.class, groupId, "public");
+		} catch (NotFoundException e) {
+			return false;
+		}
+	}
+
+	@Override
 	public boolean canSeeBlock(BlockDMOKey blockKey) {
 		return blockKey.getType().getBlockVisibility() == BlockVisibility.PUBLIC;
 	}

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/views/SystemViewpoint.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/views/SystemViewpoint.java	2008-01-02 20:00:34 UTC (rev 7125)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/views/SystemViewpoint.java	2008-01-03 21:21:56 UTC (rev 7126)
@@ -4,8 +4,11 @@
 import com.dumbhippo.dm.DMSession;
 import com.dumbhippo.identity20.Guid;
 import com.dumbhippo.persistence.User;
+import com.dumbhippo.server.NotFoundException;
 import com.dumbhippo.server.dm.BlockDMOKey;
 import com.dumbhippo.server.dm.ChatMessageKey;
+import com.dumbhippo.server.dm.DataService;
+import com.dumbhippo.server.dm.PostDMO;
 
 /**
  * SystemViewpoint represents the systems view of the database.
@@ -66,6 +69,11 @@
 	}	
 	
 	@Override
+	public boolean canSeeGroup(Guid groupId) {
+		return true;
+	}
+
+	@Override
 	public boolean canSeeBlock(BlockDMOKey blockKey) {
 		return true;
 	}

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/views/UserViewpoint.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/views/UserViewpoint.java	2008-01-02 20:00:34 UTC (rev 7125)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/views/UserViewpoint.java	2008-01-03 21:21:56 UTC (rev 7126)
@@ -12,6 +12,7 @@
 import com.dumbhippo.server.dm.BlockDMO;
 import com.dumbhippo.server.dm.BlockDMOKey;
 import com.dumbhippo.server.dm.ContactDMO;
+import com.dumbhippo.server.dm.GroupDMO;
 import com.dumbhippo.server.dm.PostDMO;
 import com.dumbhippo.server.dm.UserDMO;
 import com.dumbhippo.server.util.EJBUtil;
@@ -149,6 +150,21 @@
 		
 		return false;
 	}
+	
+	@Override
+	public boolean canSeeGroup(Guid groupId) {
+		try {
+			boolean isPublic = (Boolean)session.getRawProperty(GroupDMO.class, groupId, "public");
+			if (isPublic)
+				return true;
+			
+			@SuppressWarnings("unchecked")
+			Set<Guid> members = (Set<Guid>)session.getRawProperty(PostDMO.class, groupId, "canSeeMembers");
+			return members.contains(viewerId);
+		} catch (NotFoundException e) {
+			return false;
+		}
+	}
 
 	@Override
 	public boolean canSeePost(Guid postId) {

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/views/Viewpoint.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/views/Viewpoint.java	2008-01-02 20:00:34 UTC (rev 7125)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/views/Viewpoint.java	2008-01-03 21:21:56 UTC (rev 7126)
@@ -52,8 +52,9 @@
 	
 	public abstract boolean canSeeFriendsOnly(Guid userId);
 	public abstract boolean canSeePrivate(Guid userId);
+	public abstract boolean canSeeBlock(BlockDMOKey blockKey);
 	public abstract boolean canSeeContact(Guid contactId);
-	public abstract boolean canSeeBlock(BlockDMOKey blockKey);
+	public abstract boolean canSeeGroup(Guid groupId);
 	public abstract boolean canSeePost(Guid postId);
 	
 	public abstract Site getSite();

Modified: dumbhippo/trunk/server/src/com/dumbhippo/web/servlets/GroupPhotoServlet.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/web/servlets/GroupPhotoServlet.java	2008-01-02 20:00:34 UTC (rev 7125)
+++ dumbhippo/trunk/server/src/com/dumbhippo/web/servlets/GroupPhotoServlet.java	2008-01-03 21:21:56 UTC (rev 7126)
@@ -73,7 +73,7 @@
 		groupSystem.incrementGroupVersion(group);
 		
 		// if we upload a photo we have to remove the stock photo that 
-		// would otherwise override
+		// would otherwise override. This also takes care of notifying groupDMO.photoUrl
 		groupSystem.setStockPhoto(viewpoint, group, null);
 		
 		doFinalRedirect(request, response);



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