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

Commit

Permalink
fix duplicate apperance of concurrent translators
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Oct 2, 2012
1 parent 8f1b43b commit a53ca83
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
Expand Up @@ -68,4 +68,9 @@ private void updateEditorTranslatorList(TransUnitId selectedTransUnitId, Person
}
}
}

public void removeUser(EditorClientId editorClientId)
{
sessionService.removeUser(editorClientId);
}
}
Expand Up @@ -56,7 +56,6 @@
import org.zanata.webtrans.shared.model.UserWorkspaceContext;
import org.zanata.webtrans.shared.util.FindByTransUnitIdPredicate;
import com.allen_sauer.gwt.log.client.Log;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.gwt.core.client.GWT;
Expand All @@ -65,8 +64,7 @@
import com.google.inject.Singleton;

import net.customware.gwt.presenter.client.EventBus;
import static org.zanata.webtrans.client.events.NavTransUnitEvent.NavigationType.NextEntry;
import static org.zanata.webtrans.client.events.NavTransUnitEvent.NavigationType.PrevEntry;
import static com.google.common.base.Objects.equal;

@Singleton
// @formatter:off
Expand Down Expand Up @@ -156,7 +154,7 @@ public void saveCurrent(ContentState status)

public boolean currentEditorContentHasChanged()
{
return display != null && !Objects.equal(display.getCachedTargets(), display.getNewTargets());
return display != null && !equal(display.getCachedTargets(), display.getNewTargets());
}

private ToggleEditor getCurrentEditor()
Expand Down Expand Up @@ -192,7 +190,6 @@ public void showEditors(final TransUnitId currentTransUnitId)
else
{
display.focusEditor(currentEditorIndex);
editorTranslators.updateTranslator(currentEditors, currentTransUnitId);
revealDisplay();
}
}
Expand Down Expand Up @@ -228,13 +225,16 @@ public void onTransUnitEdit(final TransUnitEditEvent event)
{
if (event.getSelectedTransUnit() != null)
{
editorTranslators.clearTranslatorList(currentEditors);
editorTranslators.updateTranslator(currentEditors, currentTransUnitId);
}
}

@Override
public void onExitWorkspace(ExitWorkspaceEvent event)
{
// FIXME editorTranslators and workspaceUsersPresenter both share session user map. Remove an entry from the map will cause one of it out of sync with the map.
// editorTranslators.removeUser(event.getEditorClientId());
editorTranslators.clearTranslatorList(currentEditors);
editorTranslators.updateTranslator(currentEditors, currentTransUnitId);
}
Expand Down Expand Up @@ -361,7 +361,7 @@ public void onCancel(TransUnitId transUnitId)

private void ensureRowSelection(TransUnitId transUnitId)
{
if (!Objects.equal(currentTransUnitId, transUnitId))
if (!equal(currentTransUnitId, transUnitId))
{
//user click on buttons that is not on current selected row
eventBus.fireEvent(new TableRowSelectedEvent(transUnitId));
Expand Down Expand Up @@ -408,7 +408,7 @@ public void onUserConfigChanged(UserConfigChangeEvent event)
@Override
public void onRequestValidation(RequestValidationEvent event)
{
if (Objects.equal(sourceContentsPresenter.getCurrentTransUnitIdOrNull(), currentTransUnitId))
if (equal(sourceContentsPresenter.getCurrentTransUnitIdOrNull(), currentTransUnitId))
{
for (ToggleEditor editor : display.getEditors())
{
Expand Down
Expand Up @@ -25,9 +25,17 @@

import net.customware.gwt.presenter.client.EventBus;

import org.zanata.webtrans.client.events.EnterWorkspaceEvent;
import org.zanata.webtrans.client.events.EnterWorkspaceEventHandler;
import org.zanata.webtrans.client.events.ExitWorkspaceEvent;
import org.zanata.webtrans.client.events.ExitWorkspaceEventHandler;
import org.zanata.webtrans.client.events.TransUnitEditEvent;
import org.zanata.webtrans.client.events.TransUnitEditEventHandler;
import org.zanata.webtrans.client.presenter.TargetContentsPresenter;
import org.zanata.webtrans.client.presenter.WorkspaceUsersPresenter;
import org.zanata.webtrans.client.ui.HasManageUserPanel;
import org.zanata.webtrans.shared.auth.EditorClientId;
import org.zanata.webtrans.shared.model.Person;
import org.zanata.webtrans.shared.model.TransUnit;
import org.zanata.webtrans.shared.model.UserPanelSessionItem;

Expand All @@ -52,6 +60,8 @@ public UserSessionService(final EventBus eventBus, DistinctColor distinctColor)
userSessionMap = Maps.newHashMap();

eventBus.addHandler(TransUnitEditEvent.getType(), this);
// eventBus.addHandler(ExitWorkspaceEvent.getType(), this);
// eventBus.addHandler(EnterWorkspaceEvent.getType(), this);
}

@Override
Expand Down
Expand Up @@ -29,6 +29,7 @@
import org.hamcrest.Matchers;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
Expand All @@ -53,6 +54,7 @@
import org.zanata.webtrans.client.ui.ToggleEditor;
import org.zanata.webtrans.client.ui.UndoLink;
import org.zanata.webtrans.client.view.TargetContentsDisplay;
import org.zanata.webtrans.shared.auth.EditorClientId;
import org.zanata.webtrans.shared.auth.Identity;
import org.zanata.webtrans.shared.model.TransUnit;
import org.zanata.webtrans.shared.model.TransUnitId;
Expand All @@ -70,6 +72,7 @@
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
Expand Down Expand Up @@ -571,11 +574,17 @@ public void onExitWorkspaceEvent()
selectedTU = currentPageRows.get(0);
ArrayList<ToggleEditor> currentEditors = Lists.newArrayList(editor);
presenter.setStatesForTesting(selectedTU.getId(), 0, display, currentEditors);
ExitWorkspaceEvent event = mock(ExitWorkspaceEvent.class);
EditorClientId editorClientId = new EditorClientId("sessionId", 1);
when(event.getEditorClientId()).thenReturn(editorClientId);

presenter.onExitWorkspace(null);
presenter.onExitWorkspace(event);

verify(editorTranslators).clearTranslatorList(currentEditors);
verify(editorTranslators).updateTranslator(currentEditors, selectedTU.getId());
InOrder inOrder = inOrder(editorTranslators);
// inOrder.verify(editorTranslators).removeUser(editorClientId);
inOrder.verify(editorTranslators).clearTranslatorList(currentEditors);
inOrder.verify(editorTranslators).updateTranslator(currentEditors, selectedTU.getId());
verifyNoMoreInteractions(editorTranslators);
}

@Test
Expand All @@ -589,7 +598,10 @@ public void onTransUnitEditEvent()

presenter.onTransUnitEdit(event);

verify(editorTranslators).updateTranslator(currentEditors, selectedTU.getId());
InOrder inOrder = inOrder(editorTranslators);
inOrder.verify(editorTranslators).clearTranslatorList(currentEditors);
inOrder.verify(editorTranslators).updateTranslator(currentEditors, selectedTU.getId());
verifyNoMoreInteractions(editorTranslators);
}

@Test
Expand Down

0 comments on commit a53ca83

Please sign in to comment.