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

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Oct 15, 2013
1 parent c09fbb4 commit 4ea6763
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 54 deletions.
Expand Up @@ -439,10 +439,9 @@ public void onProjectStatsUpdated(ProjectStatsUpdatedEvent event) {
.getStats(localeId.getId(), StatUnit.MESSAGE);
TranslationStatistics currentMsgStats =
projectStats.getStats(localeId.getId(), StatUnit.MESSAGE);

if (currentMsgStats == null) {
if (msgStats != null) {
projectStats.addStats(msgStats);
projectStats.addStats(copyFrom(msgStats));
}
} else {
currentMsgStats.add(msgStats);
Expand All @@ -455,7 +454,7 @@ public void onProjectStatsUpdated(ProjectStatsUpdatedEvent event) {

if (currentWordStats == null) {
if (wordStats != null) {
projectStats.addStats(wordStats);
projectStats.addStats(copyFrom(wordStats));
}
} else {
currentWordStats.add(wordStats);
Expand All @@ -464,6 +463,19 @@ public void onProjectStatsUpdated(ProjectStatsUpdatedEvent event) {
refreshStatsDisplay();
}

/**
* Create new instance copy of TranslationStatistic
* @param from
* @return
*/
private TranslationStatistics copyFrom(TranslationStatistics from) {
TranslationStatistics stats = new TranslationStatistics(from.getUnit());
stats.setLocale(from.getLocale());
stats.add(from);

return stats;
}

@Override
public void onNotification(NotificationEvent event) {
if (event.getSeverity() == Severity.Warning
Expand Down
Expand Up @@ -27,6 +27,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.TreeMap;

import javax.servlet.http.HttpServletResponse;

Expand Down Expand Up @@ -84,6 +85,8 @@
import com.allen_sauer.gwt.log.client.Log;
import com.google.common.base.Objects;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent;
Expand All @@ -100,9 +103,9 @@ public class DocumentListPresenter extends WidgetPresenter<DocumentListDisplay>
private final UserOptionsService userOptionsService;
private final LocaleId localeId;

private HashMap<DocumentId, DocumentNode> nodes;
private HashMap<DocumentId, Integer> pageRows;
private ArrayList<DocumentNode> filteredNodes;
private TreeMap<DocumentId, DocumentNode> nodes = Maps.newTreeMap();
private HashMap<DocumentId, Integer> pageRows = Maps.newHashMap();
private ArrayList<DocumentNode> filteredNodes = Lists.newArrayList();

private final CachingDispatchAsync dispatcher;

Expand All @@ -112,7 +115,7 @@ public class DocumentListPresenter extends WidgetPresenter<DocumentListDisplay>
* For quick lookup of document id by full path (including document name).
* Primarily for use with history token.
*/
private HashMap<String, DocumentId> idsByPath;
private HashMap<String, DocumentId> idsByPath = Maps.newHashMap();

private final PathDocumentFilter filter = new PathDocumentFilter();

Expand All @@ -132,10 +135,6 @@ public DocumentListPresenter(DocumentListDisplay display,
new QueueDispatcher<GetDocumentStats, GetDocumentStatsResult>(
dispatcher);

nodes = new HashMap<DocumentId, DocumentNode>();
filteredNodes = new ArrayList<DocumentNode>();
pageRows = new HashMap<DocumentId, Integer>();

localeId =
userWorkspaceContext.getWorkspaceContext().getWorkspaceId()
.getLocaleId();
Expand Down Expand Up @@ -276,18 +275,14 @@ public void onRevealDisplay() {
}

public void setDocuments(List<DocumentInfo> sortedDocumentList) {
nodes =
new HashMap<DocumentId, DocumentNode>(sortedDocumentList.size());
filteredNodes.clear();
nodes.clear();
idsByPath.clear();

idsByPath = new HashMap<String, DocumentId>(sortedDocumentList.size());
for (DocumentInfo doc : sortedDocumentList) {
idsByPath.put(doc.getPath() + doc.getName(), doc.getId());
DocumentNode node = new DocumentNode(doc);
nodes.put(doc.getId(), node);
filteredNodes.add(node);
nodes.put(doc.getId(), new DocumentNode(doc));
}
updatePageCountAndGotoFirstPage();
runFilter();
}

public void queryStats() {
Expand All @@ -313,7 +308,7 @@ public void queryStats() {
* Facilitate unit testing. Will be no-op if in client(GWT compiled) mode.
*/
protected void setStatesForTest(ArrayList<DocumentNode> sortedNodes,
HashMap<DocumentId, DocumentNode> nodes) {
TreeMap<DocumentId, DocumentNode> nodes) {
if (!GWT.isClient()) {
this.filteredNodes = sortedNodes;
this.nodes = nodes;
Expand Down Expand Up @@ -345,18 +340,29 @@ public void onSuccess(GetDocumentStatsResult result) {
display.updateLastTranslated(row,
docInfo.getLastTranslated());
}

eventBus.fireEvent(new DocumentStatsUpdatedEvent(entry
.getKey(), docInfo.getStats()));
eventBus.fireEvent(new ProjectStatsUpdatedEvent(docInfo
.getStats()));
}

docStatQueueDispatcher.executeQueue();
}
};

private void debug(String from) {
for (DocumentNode node : filteredNodes) {
String log = from + "-" + node.getDocInfo().getName();

if (node.getDocInfo().getStats() != null) {
log += node.getDocInfo().getStats().getStats();
}
Log.info(log);
}
}

private List<DocumentId> convertFromNodetoId(List<DocumentNode> nodes) {
ArrayList<DocumentId> documentIds = new ArrayList<DocumentId>();
ArrayList<DocumentId> documentIds = Lists.newArrayList();

for (DocumentNode node : nodes) {
documentIds.add(node.getDocInfo().getId());
Expand Down Expand Up @@ -646,7 +652,7 @@ public void onRunDocValidation(RunDocValidationEvent event) {
userOptionsService.getConfigHolder().getState()
.getEnabledValidationIds();
if (!valIds.isEmpty() && !pageRows.keySet().isEmpty()) {
ArrayList<DocumentId> docList = new ArrayList<DocumentId>();
ArrayList<DocumentId> docList = Lists.newArrayList();
for (DocumentId documentId : pageRows.keySet()) {
display.showRowLoading(pageRows.get(documentId));
docList.add(documentId);
Expand Down
Expand Up @@ -39,6 +39,7 @@
import org.zanata.webtrans.shared.model.UserWorkspaceContext;

import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Anchor;
Expand Down Expand Up @@ -193,8 +194,7 @@ public HashMap<DocumentId, Integer> buildContent(List<DocumentNode> nodes,
boolean statsByWords) {
clearContent();

HashMap<DocumentId, Integer> pageRows =
new HashMap<DocumentId, Integer>();
HashMap<DocumentId, Integer> pageRows = Maps.newHashMap();

for (int i = 0; i < nodes.size(); i++) {
DocumentNode node = nodes.get(i);
Expand Down
Expand Up @@ -43,6 +43,7 @@
import org.zanata.webtrans.shared.model.UserWorkspaceContext;
import org.zanata.webtrans.shared.model.WorkspaceId;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
Expand Down
Expand Up @@ -5,8 +5,8 @@
import com.google.gwt.user.client.rpc.IsSerializable;

//@Immutable
public class DocumentId implements Identifier<Long>, IsSerializable,
Serializable {
public class DocumentId implements Identifier<Long>, Comparable,
IsSerializable, Serializable {
private static final long serialVersionUID = 1L;

private Long id;
Expand Down Expand Up @@ -56,4 +56,17 @@ public boolean equals(Object obj) {
}
return obj instanceof DocumentId && ((DocumentId) obj).id.equals(id);
}

@Override
public int compareTo(Object o) {
if (o == this) {
return 0;
}
if (o == null) {
return -1;
}

DocumentId compareTo = (DocumentId) o;
return this.getDocId().compareTo(compareTo.getDocId());
}
}
@@ -1,6 +1,7 @@
package org.zanata.webtrans.client.presenter;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isA;
import static org.mockito.Mockito.atLeastOnce;
Expand Down Expand Up @@ -590,8 +591,9 @@ public void onProjectStatsUpdated() {
ProjectStatsUpdatedEvent event = new ProjectStatsUpdatedEvent(newStats);
presenter.onProjectStatsUpdated(event);

assertThat(projectStats.getStats(),
Matchers.contains(unitStats, wordStats));
assertThat("project stats should contains stats in the event",
projectStats.getStats().size(), is(2));

verify(display, times(2)).setStats(projectStats, true);
}

Expand Down
Expand Up @@ -17,6 +17,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

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

Expand Down Expand Up @@ -207,16 +208,15 @@ public void generatesDocumentStatsOnTuUpdate() {
.setMsgContext("msgContext").setRowIndex(1)
.setVerNum(1).build();
TransUnitUpdateInfo updateInfo =
new TransUnitUpdateInfo(true, true, new DocumentId(2222L, ""),
newTransUnit, 3, 0, ContentState.NeedReview);
new TransUnitUpdateInfo(true, true, new DocumentId(2222L,
"match/exact/filter"), newTransUnit, 3, 0,
ContentState.NeedReview);
TransUnitUpdatedEvent mockEvent = mock(TransUnitUpdatedEvent.class);

when(mockEvent.getUpdateInfo()).thenReturn(updateInfo);

ArrayList<DocumentInfo> documentInfos = buildSampleDocumentArray();

documentListPresenter.bind();
documentListPresenter.setDocuments(documentInfos);
documentListPresenter.setDocuments(buildSampleDocumentArray());
documentListPresenter.onTransUnitUpdated(mockEvent);

verify(mockEventBus, times(1)).fireEvent(
Expand Down Expand Up @@ -413,8 +413,8 @@ public void commaSeparatedFilter() {
String filterText = " does/not, not/match ,no/filter ";

documentListPresenter.bind();
documentListPresenter.setDocuments(buildSampleDocumentArray());
documentListPresenter.updateFilterAndRun(filterText, false, false);
documentListPresenter.setDocuments(buildSampleDocumentArray());

// simulate firing history change event
HistoryToken historyTokenWithFilter = new HistoryToken();
Expand Down Expand Up @@ -467,20 +467,19 @@ public void getDocumentInfo() {
documentListPresenter.bind();
documentListPresenter.setDocuments(buildSampleDocumentArray());

DocumentInfo docInfo =
documentListPresenter
.getDocumentInfo(new DocumentId(1111L, ""));
assertThat(docInfo, is(equalTo(new DocumentInfo(new DocumentId(1111L,
""), "doc111", "first/path/", LocaleId.EN_US,
DocumentId doc1 = new DocumentId(1111L, "no/filter/matches");
DocumentInfo docInfo = documentListPresenter.getDocumentInfo(doc1);

assertThat(docInfo, is(equalTo(new DocumentInfo(doc1, "doc111",
"first/path/", LocaleId.EN_US,
new ContainerTranslationStatistics(), new AuditInfo(new Date(),
"Translator"), new HashMap<String, String>(),
new AuditInfo(new Date(), "last translator")))));

docInfo =
documentListPresenter
.getDocumentInfo(new DocumentId(3333L, ""));
assertThat(docInfo, is(equalTo(new DocumentInfo(new DocumentId(3333L,
""), "doc123", "third/path/", LocaleId.EN_US,
DocumentId doc2 = new DocumentId(3333L, "does/not/match/exact/filter");
docInfo = documentListPresenter.getDocumentInfo(doc2);
assertThat(docInfo, is(equalTo(new DocumentInfo(doc2, "doc123",
"third/path/", LocaleId.EN_US,
new ContainerTranslationStatistics(), new AuditInfo(new Date(),
"Translator"), new HashMap<String, String>(),
new AuditInfo(new Date(), "last translator")))));
Expand Down Expand Up @@ -525,8 +524,8 @@ public void onWorkspaceContextUpdated() {
public void queryStats() {
ArrayList<DocumentInfo> documentInfoList = buildSampleDocumentArray();
ArrayList<DocumentNode> sortedNodes = new ArrayList<DocumentNode>();
HashMap<DocumentId, DocumentNode> nodes =
new HashMap<DocumentId, DocumentNode>();
TreeMap<DocumentId, DocumentNode> nodes =
new TreeMap<DocumentId, DocumentNode>();
HashMap<DocumentId, ContainerTranslationStatistics> statMap =
new HashMap<DocumentId, ContainerTranslationStatistics>();
HashMap<DocumentId, AuditInfo> lastTranslatedMap =
Expand Down Expand Up @@ -596,23 +595,24 @@ private ArrayList<DocumentInfo> buildSampleDocumentArray() {
.toString()));

DocumentInfo docInfo =
new DocumentInfo(new DocumentId(1111L, ""), "matches",
"no/filter", LocaleId.EN_US, stats, new AuditInfo(
new Date(), "Translator"),
new DocumentInfo(new DocumentId(1111L, "no/filter/matches"),
"matches", "no/filter", LocaleId.EN_US, stats,
new AuditInfo(new Date(), "Translator"),
new HashMap<String, String>(), new AuditInfo(
new Date(), "last translator"));
docList.add(docInfo);

docInfo =
new DocumentInfo(new DocumentId(2222L, ""), "filter",
"match/exact/", LocaleId.EN_US, stats, new AuditInfo(
new Date(), "Translator"),
new DocumentInfo(new DocumentId(2222L, "match/exact/filter"),
"filter", "match/exact/", LocaleId.EN_US, stats,
new AuditInfo(new Date(), "Translator"),
new HashMap<String, String>(), new AuditInfo(
new Date(), "last translator"));
docList.add(docInfo);

docInfo =
new DocumentInfo(new DocumentId(3333L, ""), "filter",
new DocumentInfo(new DocumentId(3333L,
"does/not/match/exact/filter"), "filter",
"does/not/match/exact/", LocaleId.EN_US, stats,
new AuditInfo(new Date(), "Translator"),
new HashMap<String, String>(), new AuditInfo(
Expand Down

0 comments on commit 4ea6763

Please sign in to comment.