r7158 - in dumbhippo/trunk/server/src/com/dumbhippo: dm server/blocks server/dm server/impl



Author: otaylor
Date: 2008-01-09 10:55:42 -0600 (Wed, 09 Jan 2008)
New Revision: 7158

Added:
   dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupMemberBlockDMO.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupRevisionBlockDMO.java
Modified:
   dumbhippo/trunk/server/src/com/dumbhippo/dm/CachedFeed.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/blocks/GroupMemberBlockHandlerBean.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/blocks/GroupMemberBlockView.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/dm/BlockDMO.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/dm/DataService.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupChatBlockDMO.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupDMO.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/impl/GroupSystemBean.java
Log:
GroupDMO GroupSystemBean: Add a viewer-dependent "status" property to GroupDMO

GroupMemberBlockDMO GroupRevisionBlockDMO GroupMemberBlockHandlerBean BlockDMO
 DataService: Export GROUP_MEMBER and GROUP_REVISION blocks via the data model.

GroupChatBlockDMO: Remove unnecessary getChatId() method
GroupMemberBlockView.java: Suppress a warning
CachedFeed: Fix a bug when allocating the array larger


Modified: dumbhippo/trunk/server/src/com/dumbhippo/dm/CachedFeed.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/dm/CachedFeed.java	2008-01-09 01:08:22 UTC (rev 7157)
+++ dumbhippo/trunk/server/src/com/dumbhippo/dm/CachedFeed.java	2008-01-09 16:55:42 UTC (rev 7158)
@@ -61,7 +61,7 @@
 		while (pos > 0 && timestamp >= items[pos -1].time)
 			pos--;
 		
-		if (pos >= items.length) {
+		if (itemCount >= items.length) {
 			int newLength = items.length * 2;
 			if (newLength < 0)
 				throw new OutOfMemoryError();

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/blocks/GroupMemberBlockHandlerBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/blocks/GroupMemberBlockHandlerBean.java	2008-01-09 01:08:22 UTC (rev 7157)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/blocks/GroupMemberBlockHandlerBean.java	2008-01-09 16:55:42 UTC (rev 7158)
@@ -15,6 +15,9 @@
 import com.dumbhippo.persistence.StackReason;
 import com.dumbhippo.persistence.User;
 import com.dumbhippo.server.NotFoundException;
+import com.dumbhippo.server.dm.BlockDMOKey;
+import com.dumbhippo.server.dm.DataService;
+import com.dumbhippo.server.dm.GroupMemberBlockDMO;
 import com.dumbhippo.server.views.GroupView;
 import com.dumbhippo.server.views.PersonView;
 import com.dumbhippo.server.views.UserViewpoint;
@@ -136,6 +139,15 @@
 		if (a == null)
 			return; // ignore "resource" members
 		
+		Block block;
+		try {
+			 block = stacker.queryBlock(getKey(member.getGroup(), a.getOwner()));
+		} catch (NotFoundException e) {
+			// Could possibly occur if the account owning the resource of the member changes
+			// since we don't create new blocks in that case
+			return;
+		}
+		
 		// we no longer consider membership status changes as group participation,
 		// because they make group mugshots too noisy
 		switch (member.getStatus()) {
@@ -152,5 +164,7 @@
 			break;
 			// don't add a default case, we want a warning if any are missing
 		}
+		
+		DataService.currentSessionRW().changed(GroupMemberBlockDMO.class, new BlockDMOKey(block), "status");
 	}
 }

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/blocks/GroupMemberBlockView.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/blocks/GroupMemberBlockView.java	2008-01-09 01:08:22 UTC (rev 7157)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/blocks/GroupMemberBlockView.java	2008-01-09 16:55:42 UTC (rev 7158)
@@ -113,6 +113,9 @@
 			return "Invited to";
 		case ACTIVE:
 			return "Joined";
+		case NONMEMBER:
+		case REMOVED:
+			break;
 		}	
 		
 		if (isStoppedFollowing())

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/BlockDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/BlockDMO.java	2008-01-09 01:08:22 UTC (rev 7157)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/BlockDMO.java	2008-01-09 16:55:42 UTC (rev 7158)
@@ -102,6 +102,12 @@
 		case GROUP_CHAT:
 			return GroupChatBlockDMO.class;
 
+		case GROUP_MEMBER: 
+			return GroupMemberBlockDMO.class;
+			
+		case GROUP_REVISION:		
+			return GroupRevisionBlockDMO.class;
+
 		case MUSIC_CHAT:
 			return MusicChatBlockDMO.class;
 			
@@ -118,8 +124,6 @@
 			return PostBlockDMO.class;
 			
 		default:
-		case GROUP_MEMBER: 
-		case GROUP_REVISION:		
 		case OBSOLETE_EXTERNAL_ACCOUNT_UPDATE:
 		case OBSOLETE_EXTERNAL_ACCOUNT_UPDATE_SELF:
 		case OBSOLETE_BLOG_PERSON:

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/DataService.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/DataService.java	2008-01-09 01:08:22 UTC (rev 7157)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/DataService.java	2008-01-09 16:55:42 UTC (rev 7158)
@@ -93,16 +93,20 @@
 		model.addDMClass(AmazonWishListItemBlockDMO.class);
 		model.addDMClass(AmazonReviewBlockDMO.class);
 		model.addDMClass(GroupChatBlockDMO.class);
+		model.addDMClass(GroupMemberBlockDMO.class);
+		model.addDMClass(GroupRevisionBlockDMO.class);
 		model.addDMClass(MusicChatBlockDMO.class);
 		model.addDMClass(MusicPersonBlockDMO.class);
-		model.addDMClass(NetflixMovieBlockDMO.class);	
+		model.addDMClass(NetflixMovieBlockDMO.class);
+		
 		model.addDMClass(ThumbnailsBlockDMO.class);
 		model.addDMClass(FacebookEventBlockDMO.class);
 		model.addDMClass(FlickrPersonBlockDMO.class);
 		model.addDMClass(FlickrPhotosetBlockDMO.class);
 		model.addDMClass(PicasaPersonBlockDMO.class);
+
 		model.addDMClass(PostBlockDMO.class);
-		
+
 		model.addDMClass(ChatMessageDMO.class);
 		model.addDMClass(BlockMessageDMO.class);
 		model.addDMClass(GroupMessageDMO.class);

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupChatBlockDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupChatBlockDMO.java	2008-01-09 01:08:22 UTC (rev 7157)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupChatBlockDMO.java	2008-01-09 16:55:42 UTC (rev 7158)
@@ -11,11 +11,6 @@
 		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());

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupDMO.java	2008-01-09 01:08:22 UTC (rev 7157)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupDMO.java	2008-01-09 16:55:42 UTC (rev 7158)
@@ -8,6 +8,7 @@
 import com.dumbhippo.dm.DMObject;
 import com.dumbhippo.dm.DMSession;
 import com.dumbhippo.dm.annotations.DMFilter;
+import com.dumbhippo.dm.annotations.DMInit;
 import com.dumbhippo.dm.annotations.DMO;
 import com.dumbhippo.dm.annotations.DMProperty;
 import com.dumbhippo.dm.annotations.Inject;
@@ -16,7 +17,10 @@
 import com.dumbhippo.persistence.AccountClaim;
 import com.dumbhippo.persistence.Group;
 import com.dumbhippo.persistence.GroupMember;
+import com.dumbhippo.persistence.MembershipStatus;
 import com.dumbhippo.server.NotFoundException;
+import com.dumbhippo.server.views.UserViewpoint;
+import com.dumbhippo.server.views.Viewpoint;
 
 @DMO(classId="http://mugshot.org/p/o/group";, resourceBase="/o/group")
 @DMFilter("viewer.canSeeGroup(this)")
@@ -27,11 +31,24 @@
 	@Inject
 	private DMSession session;
 	
+	@Inject
+	private Viewpoint viewpoint;
+
 	private Group group;
 	
+	Set<UserDMO> invitedToFollowMembers;
+	Set<UserDMO> followerMembers;
+	Set<UserDMO> invitedMembers;
+	Set<UserDMO> activeMembers;
+	Set<UserDMO> removedMembers;
+	
+	Set<UserDMO> canSeeMembers;
+	
 	protected GroupDMO(Guid key) {
 		super(key);
 	}
+	
+	static private final int MEMBERS_GROUP = 1;
 
 	@Override
 	protected void init() throws NotFoundException {
@@ -59,21 +76,109 @@
 	public boolean isPublic() {
 		return group.isPublic();
 	}
+	
+	private boolean viewerIsInSet(Guid viewerId, String propertyName) {
+		try {
+			@SuppressWarnings("unchecked")
+			Set<Guid> guids = (Set<Guid>)session.getRawProperty(GroupDMO.class, getKey(), propertyName);
+			return guids.contains(viewerId);
+		} catch (NotFoundException e) {
+			return false;
+		}
+	}
+	
+	@DMProperty(cached=false, defaultInclude=true)
+	public String getStatus() {
+		MembershipStatus status = MembershipStatus.NONMEMBER;
+		
+		if (viewpoint instanceof UserViewpoint) {
+			Guid viewerId = ((UserViewpoint)viewpoint).getViewerId();
+			
+			if (viewerIsInSet(viewerId, "activeMembers"))
+				status = MembershipStatus.ACTIVE;
+			else if (viewerIsInSet(viewerId, "followerMembers"))
+				status = MembershipStatus.FOLLOWER;
+			else if (viewerIsInSet(viewerId, "invitedMembers"))
+				status = MembershipStatus.INVITED;
+			else if (viewerIsInSet(viewerId, "invitedToFollowMembers"))
+				status = MembershipStatus.INVITED_TO_FOLLOW;
+			else if (viewerIsInSet(viewerId, "removedMembers"))
+				status = MembershipStatus.REMOVED;
+		}
+		
+		return status.name();
+	}
+	
+	@DMInit(group=MEMBERS_GROUP)
+	public void initMembers() {
+		invitedToFollowMembers = new HashSet<UserDMO>();
+		followerMembers = new HashSet<UserDMO>();
+		removedMembers = new HashSet<UserDMO>();
+		invitedMembers = new HashSet<UserDMO>();
+		activeMembers = new HashSet<UserDMO>();
+		canSeeMembers = new HashSet<UserDMO>();
 
-	// 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()));
+			AccountClaim accountClaim = gm.getMember().getAccountClaim();
+			if (accountClaim != null) {
+				UserDMO user = session.findUnchecked(UserDMO.class, accountClaim.getOwner().getGuid());
+				
+				switch (gm.getStatus()) {
+				case NONMEMBER:
+					break;
+				case INVITED_TO_FOLLOW:
+					invitedToFollowMembers.add(user);
+					break;
+				case FOLLOWER:
+					followerMembers.add(user);
+					break;
+				case REMOVED:
+					removedMembers.add(user);
+					break;
+				case INVITED:
+					invitedMembers.add(user);
+					break;
+				case ACTIVE:
+					activeMembers.add(user);
+					break;
+				}
+			
+				if (gm.getStatus().getCanSeeSecretGroup())
+					canSeeMembers.add(session.findUnchecked(UserDMO.class, accountClaim.getOwner().getGuid()));
 			}
 		}
-		
-		return result;
 	}
+
+	// These are used to compute the status
+	@DMProperty(group=MEMBERS_GROUP)
+	public Set<UserDMO> getInvitedToFollowMembers() {
+		return invitedToFollowMembers;
+	}
+	
+	@DMProperty(group=MEMBERS_GROUP)
+	public Set<UserDMO> getFollowerMembers() {
+		return followerMembers;
+	}
+
+	@DMProperty(group=MEMBERS_GROUP)
+	public Set<UserDMO> getRemovedMembers() {
+		return removedMembers;
+	}
+
+	@DMProperty(group=MEMBERS_GROUP)
+	public Set<UserDMO> getInvitedMembers() {
+		return invitedMembers;
+	}
+
+	@DMProperty(group=MEMBERS_GROUP)
+	public Set<UserDMO> getActiveMembers() {
+		return activeMembers;
+	}
+
+	// for visibility purposes; this will include members that have removed themselves, so
+	// it shouldn't be used for display purposes.
+	@DMProperty(group=MEMBERS_GROUP)
+	public Set<UserDMO> getCanSeeMembers() {
+		return canSeeMembers;
+	}
 }

Added: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupMemberBlockDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupMemberBlockDMO.java	2008-01-09 01:08:22 UTC (rev 7157)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupMemberBlockDMO.java	2008-01-09 16:55:42 UTC (rev 7158)
@@ -0,0 +1,33 @@
+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.GroupMemberBlockView;
+
+ DMO(classId="http://mugshot.org/p/o/groupMemberBlock";)
+public abstract class GroupMemberBlockDMO extends BlockDMO {
+	protected GroupMemberBlockDMO(BlockDMOKey key) {
+		super(key);
+	}
+
+	@DMProperty(defaultInclude=true, defaultChildren="+")
+	public GroupDMO getGroup() {
+		return session.findUnchecked(GroupDMO.class, ((GroupMemberBlockView)blockView).getGroupView().getGroup().getGuid());
+	}
+	
+	@DMProperty(defaultInclude=true, defaultChildren="+")
+	public UserDMO getMember() {
+		return session.findUnchecked(UserDMO.class, ((GroupMemberBlockView)blockView).getMemberView().getUser().getGuid());
+	}
+	
+	@DMProperty(defaultInclude=true)
+	public String getStatus() {
+		return ((GroupMemberBlockView)blockView).getStatus().name();
+	}
+	
+	@Override
+	public StoreKey<?,?> getVisibilityDelegate() {
+		return getGroup().getStoreKey();
+	}
+}

Added: dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupRevisionBlockDMO.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupRevisionBlockDMO.java	2008-01-09 01:08:22 UTC (rev 7157)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/dm/GroupRevisionBlockDMO.java	2008-01-09 16:55:42 UTC (rev 7158)
@@ -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.GroupRevisionBlockView;
+
+ DMO(classId="http://mugshot.org/p/o/groupRevisionBlock";)
+public abstract class GroupRevisionBlockDMO extends BlockDMO {
+	protected GroupRevisionBlockDMO(BlockDMOKey key) {
+		super(key);
+	}
+
+	@DMProperty(defaultInclude=true, defaultChildren="+")
+	public GroupDMO getGroup() {
+		return session.findUnchecked(GroupDMO.class, ((GroupRevisionBlockView)blockView).getGroupView().getGroup().getGuid());
+	}
+	
+	@DMProperty(defaultInclude=true, defaultChildren="+")
+	public UserDMO getRevisor() {
+		return session.findUnchecked(UserDMO.class, ((GroupRevisionBlockView)blockView).getRevisorView().getUser().getGuid());
+	}
+	
+	@Override
+	public StoreKey<?,?> getVisibilityDelegate() {
+		return getGroup().getStoreKey();
+	}
+}

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/GroupSystemBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/GroupSystemBean.java	2008-01-09 01:08:22 UTC (rev 7157)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/GroupSystemBean.java	2008-01-09 16:55:42 UTC (rev 7158)
@@ -22,6 +22,7 @@
 import com.dumbhippo.Pair;
 import com.dumbhippo.StringUtils;
 import com.dumbhippo.TypeUtils;
+import com.dumbhippo.dm.ReadWriteSession;
 import com.dumbhippo.identity20.Guid;
 import com.dumbhippo.identity20.Guid.ParseException;
 import com.dumbhippo.live.GroupEvent;
@@ -53,6 +54,7 @@
 import com.dumbhippo.server.RevisionControl;
 import com.dumbhippo.server.dm.DataService;
 import com.dumbhippo.server.dm.GroupDMO;
+import com.dumbhippo.server.dm.UserClientMatcher;
 import com.dumbhippo.server.util.EJBUtil;
 import com.dumbhippo.server.views.GroupMemberView;
 import com.dumbhippo.server.views.GroupView;
@@ -112,6 +114,25 @@
 		return g;
 	}
 
+	private void invalidateGroupMemberStatus(GroupMember groupMember) {
+		ReadWriteSession session = DataService.currentSessionRW();
+		
+		Guid groupId = groupMember.getGroup().getGuid();
+		
+		session.changed(GroupDMO.class, groupId, "invitedToFollowMembers");
+		session.changed(GroupDMO.class, groupId, "followerMembers");
+		session.changed(GroupDMO.class, groupId, "invitedMembers");
+		session.changed(GroupDMO.class, groupId, "removedMembers");
+		session.changed(GroupDMO.class, groupId, "activeMembers");
+		session.changed(GroupDMO.class, groupId, "canSeeMembers");
+
+		AccountClaim ac = groupMember.getMember().getAccountClaim();
+		if (ac != null) {
+			Guid memberUserId = ac.getOwner().getGuid();
+			session.changed(GroupDMO.class, groupId, "status", new UserClientMatcher(memberUserId));
+		}
+	}
+	
 	private GroupMember getGroupMemberForUser(Group group, User user, boolean fixupExpected) throws NotFoundException {
 		List<GroupMember> allMembers = new ArrayList<GroupMember>(); 
 		for (GroupMember member : group.getMembers()) {
@@ -178,6 +199,7 @@
 				accountMember.setAdders(adders);
 			em.persist(accountMember);
 			group.getMembers().add(accountMember);
+			invalidateGroupMemberStatus(accountMember);
 			notifier.onGroupMemberCreated(accountMember, System.currentTimeMillis(), true);
 		}
 
@@ -382,7 +404,7 @@
 			notifier.onGroupMemberCreated(groupMember, now, notifyGroupMembers);
 		}
 		
-		DataService.currentSessionRW().changed(GroupDMO.class, group.getGuid(), "canSeeMembers");
+		invalidateGroupMemberStatus(groupMember);
         LiveState.getInstance().queueUpdate(new GroupEvent(group.getGuid(), groupMember.getMember().getGuid(),
         		GroupEvent.Detail.MEMBERS_CHANGED));
 	}
@@ -486,7 +508,7 @@
 			groupMember.setStatus(MembershipStatus.REMOVED);
 			
 			notifier.onGroupMemberStatusChanged(groupMember, System.currentTimeMillis(), true);
-			DataService.currentSessionRW().changed(GroupDMO.class, group.getGuid(), "canSeeMembers");
+			invalidateGroupMemberStatus(groupMember);
 	        LiveState.getInstance().queueUpdate(new GroupEvent(group.getGuid(),
 	        		groupMember.getMember().getGuid(), GroupEvent.Detail.MEMBERS_CHANGED));
 		} else if (groupMember.getStatus().ordinal() < MembershipStatus.REMOVED.ordinal()) {
@@ -496,7 +518,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");
+			invalidateGroupMemberStatus(groupMember);
 			LiveState.getInstance().queueUpdate(new GroupEvent(group.getGuid(),
 					groupMember.getMember().getGuid(), GroupEvent.Detail.MEMBERS_CHANGED));
 		} else {



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