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

Commit

Permalink
Merge branch 'master' into centraliseKeyboardShortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Jun 27, 2012
2 parents 29b6005 + f196925 commit 5bb8d35
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 46 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 @@ -62,6 +62,7 @@
import org.zanata.webtrans.client.service.TransUnitNavigationService;
import org.zanata.webtrans.client.service.UserSessionService;
import org.zanata.webtrans.client.ui.FilterViewConfirmationPanel;
import org.zanata.webtrans.client.ui.UndoLink;
import org.zanata.webtrans.shared.auth.AuthenticationError;
import org.zanata.webtrans.shared.auth.AuthorizationError;
import org.zanata.webtrans.shared.auth.EditorClientId;
Expand Down Expand Up @@ -100,6 +101,7 @@
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.inject.Inject;
import com.google.inject.Provider;

public class TableEditorPresenter extends WidgetPresenter<TableEditorPresenter.Display> implements HasPageNavigation
{
Expand Down Expand Up @@ -179,6 +181,7 @@ public interface Display extends WidgetDisplay, HasPageNavigation
private final TargetContentsPresenter targetContentsPresenter;

private final UserSessionService sessionService;
private final Provider<UndoLink> undoLinkProvider;

private UserConfigHolder configHolder;
private Scheduler scheduler;
Expand All @@ -188,7 +191,7 @@ public interface Display extends WidgetDisplay, HasPageNavigation
private final TransUnitNavigationService navigationService;

@Inject
public TableEditorPresenter(final Display display, final EventBus eventBus, final CachingDispatchAsync dispatcher, final Identity identity, final TableEditorMessages messages, final WorkspaceContext workspaceContext, final SourceContentsPresenter sourceContentsPresenter, final TargetContentsPresenter targetContentsPresenter, UserConfigHolder configHolder, Scheduler scheduler, TransUnitNavigationService navigationService, final UserSessionService sessionService)
public TableEditorPresenter(final Display display, final EventBus eventBus, final CachingDispatchAsync dispatcher, final Identity identity, final TableEditorMessages messages, final WorkspaceContext workspaceContext, final SourceContentsPresenter sourceContentsPresenter, final TargetContentsPresenter targetContentsPresenter, UserConfigHolder configHolder, Scheduler scheduler, TransUnitNavigationService navigationService, final UserSessionService sessionService, Provider<UndoLink> undoLinkProvider)
{
super(display, eventBus);
this.dispatcher = dispatcher;
Expand All @@ -202,6 +205,7 @@ public TableEditorPresenter(final Display display, final EventBus eventBus, fina
this.navigationService = navigationService;
this.sessionService = sessionService;

this.undoLinkProvider = undoLinkProvider;
}

/**
Expand Down Expand Up @@ -748,7 +752,9 @@ public void onSuccess(UpdateTransUnitResult result)
// FIXME check result.success
if (result.isSingleSuccess())
{
eventBus.fireEvent(new NotificationEvent(Severity.Info, messages.notifyUpdateSaved()));
UndoLink undoLink = undoLinkProvider.get();
undoLink.prepareUndoFor(result);
eventBus.fireEvent(new NotificationEvent(Severity.Info, messages.notifyUpdateSaved(), undoLink));
}
else
{
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 @@ -358,8 +358,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 @@ -374,13 +374,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 @@ -399,9 +399,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 @@ -411,13 +411,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 @@ -502,7 +502,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

0 comments on commit 5bb8d35

Please sign in to comment.