Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge branch '1.6' into integration/master
Browse files Browse the repository at this point in the history
Conflicts:
	zanata-war/src/test/java/org/zanata/webtrans/client/presenter/TranslationPresenterTest.java
	zanata-war/src/test/java/org/zanata/webtrans/client/presenter/WorkspaceUsersPresenterTest.java
  • Loading branch information
seanf committed Jun 26, 2012
2 parents c1e59e5 + 84c8c8e commit 6cafbe3
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 44 deletions.
Expand Up @@ -111,9 +111,9 @@ public void checkLoggedIn()
@Observer("org.jboss.seam.preDestroyContext.SESSION")
public void logout()
{
if (Events.exists() && getPrincipal() != null)
if (Events.exists() && getCredentials() != null)
{
Events.instance().raiseEvent(USER_LOGOUT_EVENT, getPrincipal().getName());
Events.instance().raiseEvent(USER_LOGOUT_EVENT, getCredentials().getUsername());
}
super.logout();
}
Expand Down
Expand Up @@ -93,13 +93,16 @@ public void addUser(EditorClientId editorClientId, UserPanelSessionItem item)
public void removeUser(EditorClientId editorClientId)
{
userSessionMap.remove(editorClientId);
// FIXME remove from colorListMap (memory leak)
}

public Map<EditorClientId, UserPanelSessionItem> getUserSessionMap()
{
return userSessionMap;
}

// TODO what we pass is really editorClientId
// Should we be passing sessionId? See also memory leak above.
public String getColor(String sessionId)
{
if (colorListMap.containsKey(sessionId))
Expand Down
Expand Up @@ -152,12 +152,20 @@ public boolean removeEditorClient(EditorClientId editorClientId)
PersonSessionDetails details = sessions.remove(editorClientId);
if (details != null)
{
// TODO remove editorClientId from httpSessionToEditorClientId, instead of waiting until logout
log.info("Removed user {0} with editorClientId {1} from workspace {2}", details.getPerson().getId(), editorClientId, workspaceContext);
return true;
String httpSessionId = editorClientId.getHttpSessionId();
Collection<EditorClientId> clientIds = httpSessionToEditorClientId.get(httpSessionId);
if (clientIds != null)
{
clientIds.remove(editorClientId);
log.info("Removed user {0} with editorClientId {1} from workspace {2}", details.getPerson().getId(), editorClientId, workspaceContext);
return true;
}
else
{
log.warn("Unable to remove user {0} with editorClientId {1} from workspace {2}", details.getPerson().getId(), editorClientId, workspaceContext);
}
}
}

return false;
}

Expand Down
Expand Up @@ -24,6 +24,7 @@
import org.zanata.common.EntityStatus;
import org.zanata.common.LocaleId;
import org.zanata.dao.AccountDAO;
import org.zanata.model.HAccount;
import org.zanata.model.HIterationProject;
import org.zanata.model.HLocale;
import org.zanata.model.HPerson;
Expand Down Expand Up @@ -82,8 +83,24 @@ public void start()
public void exitWorkspace(String username)
{
String httpSessionId = getSessionId();
LOGGER.info("User logout: Removing {} from all workspaces, session: {}", username, httpSessionId);
HPerson person = accountDAO.getByUsername(username).getPerson();
if (httpSessionId == null)
{
LOGGER.debug("Logout: null session");
return;
}
LOGGER.info("Logout: Removing user {} from all workspaces, session: {}", username, httpSessionId);
String personName = "<unknown>";
String personEmail = "<unknown>";
HAccount account = accountDAO.getByUsername(username);
if (account != null)
{
HPerson person = account.getPerson();
if (person != null)
{
personName = person.getName();
personEmail = person.getEmail();
}
}
ImmutableSet<TranslationWorkspace> workspaceSet = ImmutableSet.copyOf(workspaceMap.values());
for (TranslationWorkspace workspace : workspaceSet)
{
Expand All @@ -92,7 +109,7 @@ public void exitWorkspace(String username)
{
LOGGER.info("Publishing ExitWorkspace event for user {} with editorClientId {} from workspace {}", new Object[] { username, editorClientId, workspace.getWorkspaceContext() });
// Send GWT Event to client to update the userlist
ExitWorkspace event = new ExitWorkspace(editorClientId, new Person(new PersonId(username), person.getName(), gravatarServiceImpl.getUserImageUrl(16, person.getEmail())));
ExitWorkspace event = new ExitWorkspace(editorClientId, new Person(new PersonId(username), personName, gravatarServiceImpl.getUserImageUrl(16, personEmail)));
workspace.publish(event);
}
}
Expand Down
Expand Up @@ -77,7 +77,7 @@ public ActivateWorkspaceResult execute(ActivateWorkspaceAction action, Execution
WorkspaceId workspaceId = action.getWorkspaceId();
TranslationWorkspace workspace = translationWorkspaceManager.getOrRegisterWorkspace(workspaceId);
String httpSessionId = ServletContexts.instance().getRequest().getSession().getId();
EditorClientId editorClientId = new EditorClientId(httpSessionId + ":" + generateEditorClientNum());
EditorClientId editorClientId = new EditorClientId(httpSessionId, generateEditorClientNum());
workspace.addEditorClient(httpSessionId, editorClientId, person.getId());
// Send EnterWorkspace event to clients
EnterWorkspace event = new EnterWorkspace(editorClientId, person);
Expand Down
Expand Up @@ -15,50 +15,83 @@ public final class EditorClientId implements Identifier<String>, Serializable
// generated
private static final long serialVersionUID = 6713691712353126602L;

private String id;
private String httpSessionId;
private long editorClientNum;

@SuppressWarnings("unused")
private EditorClientId()
{
}

public EditorClientId(String id)
public EditorClientId(String httpSessionId, long editorClientNum)
{
if (id == null || id.isEmpty())
if (httpSessionId == null || httpSessionId.isEmpty())
{
throw new IllegalStateException("Invalid Id");
}
this.id = id;
this.httpSessionId = httpSessionId;
this.editorClientNum = editorClientNum;
}

@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (obj == null)
{
return false;
}
if (!(obj instanceof EditorClientId))
{
return false;
if (obj instanceof EditorClientId)
}
EditorClientId other = (EditorClientId) obj;
if (editorClientNum != other.editorClientNum)
{
return ((EditorClientId) obj).id.equals(id);
return false;
}
return super.equals(obj);
if (httpSessionId == null)
{
if (other.httpSessionId != null)
{
return false;
}
}
else if (!httpSessionId.equals(other.httpSessionId))
{
return false;
}
return true;
}

@Override
public int hashCode()
{
return id.hashCode();
final int prime = 31;
int result = 1;
result = prime * result + (int) (editorClientNum ^ (editorClientNum >>> 32));
result = prime * result + ((httpSessionId == null) ? 0 : httpSessionId.hashCode());
return result;
}

public String getHttpSessionId()
{
return httpSessionId;
}

@Override
public String toString()
{
return id;
return getValue();
}

@Override
public String getValue()
{
return id;
return httpSessionId + ":" + editorClientNum;
}

}
Expand Up @@ -355,8 +355,8 @@ public void updateParticipantsOnEnterWorkspace()

// expect lookup translator list
Map<EditorClientId, Person> participants = new HashMap<EditorClientId, Person>();
participants.put(new EditorClientId("sessionId1"), new Person(new PersonId("bob"), "Bob Smith", "http://www.gravatar.com/avatar/bob@zanata.org?d=mm&s=16"));
participants.put(new EditorClientId("sessionId2"), new Person(new PersonId("smith"), "Smith Bob", "http://www.gravatar.com/avatar/smith@zanata.org?d=mm&s=16"));
participants.put(new EditorClientId("sessionId1", 1), new Person(new PersonId("bob"), "Bob Smith", "http://www.gravatar.com/avatar/bob@zanata.org?d=mm&s=16"));
participants.put(new EditorClientId("sessionId2", 1), new Person(new PersonId("smith"), "Smith Bob", "http://www.gravatar.com/avatar/smith@zanata.org?d=mm&s=16"));
capturedTranslatorListRequest = new Capture<GetTranslatorList>();
capturedTranslatorListRequestCallback = new Capture<AsyncCallback<GetTranslatorListResult>>();

Expand All @@ -371,13 +371,13 @@ public void updateParticipantsOnEnterWorkspace()
mockWorkspaceUsersPresenter.dispatchChatAction(null, TEST_HAS_JONINED_WORKSPACE_MESSAGE, MESSAGE_TYPE.SYSTEM_MSG);
expectLastCall();

mockWorkspaceUsersPresenter.addTranslator(new EditorClientId("sessionId1"), new Person(new PersonId("bob"), "Bob Smith", "http://www.gravatar.com/avatar/bob@zanata.org?d=mm&s=16"), null);
mockWorkspaceUsersPresenter.addTranslator(new EditorClientId("sessionId1", 1), new Person(new PersonId("bob"), "Bob Smith", "http://www.gravatar.com/avatar/bob@zanata.org?d=mm&s=16"), null);
expectLastCall();

// simulate enter workspace event
EnterWorkspaceEvent event = createMock(EnterWorkspaceEvent.class);

expect(event.getEditorClientId()).andReturn(new EditorClientId("sessionId1"));
expect(event.getEditorClientId()).andReturn(new EditorClientId("sessionId1", 1));
expect(event.getPerson()).andReturn(new Person(new PersonId("bob"), "Bob Smith", "http://www.gravatar.com/avatar/bob@zanata.org?d=mm&s=16")).times(2);

replay(mockDispatcher, mockDisplay, mockMessages, mockWorkspaceUsersPresenter, event);
Expand All @@ -396,9 +396,9 @@ public void updateParticipantsOnExitWorkspace()

// expect lookup translator list
Map<EditorClientId, Person> participants = new HashMap<EditorClientId, Person>();
participants.put(new EditorClientId("sessionId1"), new Person(new PersonId("john"), "John Jones", "http://www.gravatar.com/avatar/john@zanata.org?d=mm&s=16"));
participants.put(new EditorClientId("sessionId2"), new Person(new PersonId("jones"), "Jones John", "http://www.gravatar.com/avatar/jones@zanata.org?d=mm&s=16"));
participants.put(new EditorClientId("sessionId2"), new Person(new PersonId("jim"), "Jim Jones", "http://www.gravatar.com/avatar/jim@zanata.org?d=mm&s=16"));
participants.put(new EditorClientId("sessionId1", 1), new Person(new PersonId("john"), "John Jones", "http://www.gravatar.com/avatar/john@zanata.org?d=mm&s=16"));
participants.put(new EditorClientId("sessionId2", 1), new Person(new PersonId("jones"), "Jones John", "http://www.gravatar.com/avatar/jones@zanata.org?d=mm&s=16"));
participants.put(new EditorClientId("sessionId2", 1), new Person(new PersonId("jim"), "Jim Jones", "http://www.gravatar.com/avatar/jim@zanata.org?d=mm&s=16"));


capturedTranslatorListRequest = new Capture<GetTranslatorList>();
Expand All @@ -408,13 +408,13 @@ public void updateParticipantsOnExitWorkspace()
mockDisplay.setParticipantsTitle(TEST_USERS_ONLINE_MESSAGE);
expectLastCall().once(); // once for now

mockWorkspaceUsersPresenter.removeTranslator(new EditorClientId("sessionId1"), new Person(new PersonId("john"), "John Jones", "http://www.gravatar.com/avatar/john@zanata.org?d=mm&s=16"));
mockWorkspaceUsersPresenter.removeTranslator(new EditorClientId("sessionId1", 1), new Person(new PersonId("john"), "John Jones", "http://www.gravatar.com/avatar/john@zanata.org?d=mm&s=16"));
expectLastCall().once();

// simulate enter workspace event
ExitWorkspaceEvent event = createMock(ExitWorkspaceEvent.class);

expect(event.getEditorClientId()).andReturn(new EditorClientId("sessionId1"));
expect(event.getEditorClientId()).andReturn(new EditorClientId("sessionId1", 1));
expect(event.getPerson()).andReturn(new Person(new PersonId("john"), "John Jones", "http://www.gravatar.com/avatar/john@zanata.org?d=mm&s=16"));
expect(mockWorkspaceUsersPresenter.getTranslatorsSize()).andReturn(2);

Expand Down Expand Up @@ -499,7 +499,7 @@ private void fireReadOnlyAndCheckResponse()
private void setupDefaultMockExpectations()
{
Map<EditorClientId, PersonSessionDetails> people = new HashMap<EditorClientId, PersonSessionDetails>();
people.put(new EditorClientId("sessionId"), new PersonSessionDetails(new Person(new PersonId("jones"), "Joey Jones", "http://www.gravatar.com/avatar/joey@zanata.org?d=mm&s=16"), null));
people.put(new EditorClientId("sessionId", 1), new PersonSessionDetails(new Person(new PersonId("jones"), "Joey Jones", "http://www.gravatar.com/avatar/joey@zanata.org?d=mm&s=16"), null));

setupDefaultMockExpectations(people);
}
Expand Down
Expand Up @@ -91,9 +91,9 @@ public void setNonEmptyUserList()
Person person2 = new Person(new PersonId("person2"), "Smith John", "http://www.gravatar.com/avatar/smith@zanata.org?d=mm&s=16");
Person person3 = new Person(new PersonId("person3"), "Smohn Jith", "http://www.gravatar.com/avatar/smohn@zanata.org?d=mm&s=16");

EditorClientId editorClientId1 = new EditorClientId("sessionId1");
EditorClientId editorClientId2 = new EditorClientId("sessionId2");
EditorClientId editorClientId3 = new EditorClientId("sessionId3");
EditorClientId editorClientId1 = new EditorClientId("sessionId1", 1);
EditorClientId editorClientId2 = new EditorClientId("sessionId2", 1);
EditorClientId editorClientId3 = new EditorClientId("sessionId3", 1);

HasManageUserPanel mockPanel1 = createMock(HasManageUserPanel.class);
HasManageUserPanel mockPanel2 = createMock(HasManageUserPanel.class);
Expand All @@ -108,9 +108,9 @@ public void setNonEmptyUserList()
mockDisplay.appendChat(null, null, PUBLIC_CHANNEL_WARN, MESSAGE_TYPE.SYSTEM_WARNING);
expectLastCall().once();

expect(mockSessionService.getColor("sessionId1")).andReturn("color1");
expect(mockSessionService.getColor("sessionId2")).andReturn("color2");
expect(mockSessionService.getColor("sessionId3")).andReturn("color3");
expect(mockSessionService.getColor(editorClientId1.getValue())).andReturn("color1");
expect(mockSessionService.getColor(editorClientId2.getValue())).andReturn("color2");
expect(mockSessionService.getColor(editorClientId3.getValue())).andReturn("color3");

expect(mockSessionService.getUserPanel(editorClientId1)).andReturn(mockItem1);
expect(mockSessionService.getUserPanel(editorClientId2)).andReturn(mockItem2);
Expand All @@ -134,9 +134,9 @@ public void setNonEmptyUserList()
workspaceUsersPresenter.bind();

Map<EditorClientId, PersonSessionDetails> people = new HashMap<EditorClientId, PersonSessionDetails>();
people.put(new EditorClientId("sessionId1"), new PersonSessionDetails(person1, null));
people.put(new EditorClientId("sessionId2"), new PersonSessionDetails(person2, null));
people.put(new EditorClientId("sessionId3"), new PersonSessionDetails(person3, null));
people.put(editorClientId1, new PersonSessionDetails(person1, null));
people.put(editorClientId2, new PersonSessionDetails(person2, null));
people.put(editorClientId3, new PersonSessionDetails(person3, null));
workspaceUsersPresenter.initUserList(people);

verifyAll();
Expand Down
Expand Up @@ -30,7 +30,7 @@ public void execute()
Log.info("ENTER DummyActivateWorkspaceCommand.execute()");
WorkspaceContext context = new WorkspaceContext(action.getWorkspaceId(), "Dummy Workspace", "Mock Sweedish", false);

Identity identity = new Identity(new EditorClientId("123456"), new Person(new PersonId("bob"), "Bob The Builder", "http://www.gravatar.com/avatar/bob@zanata.org?d=mm&s=16"));
Identity identity = new Identity(new EditorClientId("123456", 1), new Person(new PersonId("bob"), "Bob The Builder", "http://www.gravatar.com/avatar/bob@zanata.org?d=mm&s=16"));
callback.onSuccess(new ActivateWorkspaceResult(context, identity));
Log.info("EXIT DummyActivateWorkspaceCommand.execute()");
}
Expand Down
Expand Up @@ -28,7 +28,7 @@ public void execute()
Log.info("ENTER DummyGetTranslatorListCommand.execute()");

HashMap<EditorClientId, PersonSessionDetails> translator = new HashMap<EditorClientId, PersonSessionDetails>();
translator.put(new EditorClientId("dummySession"), new PersonSessionDetails(new Person(new PersonId("personID"), "Some Person with an Incredibly Long Name", "http://www.gravatar.com/avatar/longname@zanata.org?d=mm&s=16"), null));
translator.put(new EditorClientId("dummySession", 1), new PersonSessionDetails(new Person(new PersonId("personID"), "Some Person with an Incredibly Long Name", "http://www.gravatar.com/avatar/longname@zanata.org?d=mm&s=16"), null));
callback.onSuccess(new GetTranslatorListResult(translator, translator.size()));
Log.info("EXIT DummyGetTranslatorListCommand.execute()");
}
Expand Down
Expand Up @@ -51,9 +51,9 @@ public void setUp()
public void onTimeoutRemove()
{
ConcurrentMap<EditorClientId, PersonId> sessions = new MapMaker().makeMap();
sessions.put(new EditorClientId("a"), new PersonId("person a"));
sessions.put(new EditorClientId("b"), new PersonId("person b"));
sessions.put(new EditorClientId("a", 1), new PersonId("person a"));
sessions.put(new EditorClientId("b", 1), new PersonId("person b"));

sessions.remove(new EditorClientId("a"));
sessions.remove(new EditorClientId("a", 1));
}
}

0 comments on commit 6cafbe3

Please sign in to comment.