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

Commit

Permalink
work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-sl-eng committed Mar 1, 2013
1 parent c639b34 commit 87e4cc5
Show file tree
Hide file tree
Showing 26 changed files with 87 additions and 57 deletions.
1 change: 0 additions & 1 deletion zanata-war/src/main/java/org/zanata/dao/DocumentDAO.java
@@ -1,6 +1,5 @@
package org.zanata.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down
Expand Up @@ -433,23 +433,32 @@ public void onSuccess(DownloadAllFilesResult result)
});
}

@Override
public void runValidation()
{
ArrayList<ValidationId> idList = new ArrayList<ValidationId>();
ArrayList<ValidationId> valIds = new ArrayList<ValidationId>();
ArrayList<Long> docIds = new ArrayList<Long>();
for(DocumentNode node: display.getDocumentListTable().getVisibleItems())
{
docIds.add(node.getDocInfo().getId().getId());
}


for (ValidationAction valAction : validationService.getValidationMap().values())
{
if (valAction.getValidationInfo().isEnabled())
{
idList.add(valAction.getValidationInfo().getId());
valIds.add(valAction.getValidationInfo().getId());
}
}

Log.info("doc==========================" + docIds.size());
Log.info("val=========================" + valIds.size());

if (!idList.isEmpty())
if (!valIds.isEmpty() && !docIds.isEmpty())
{
dispatcher.execute(new RunValidationAction(idList), new AsyncCallback<RunValidationResult>()
dispatcher.execute(new RunValidationAction(valIds, docIds), new AsyncCallback<RunValidationResult>()
{

@Override
public void onFailure(Throwable caught)
{
Expand Down
Expand Up @@ -81,6 +81,8 @@ interface Listener
void onUploadFile();

void updateDownloadFileProgress();

void runValidation();
}

void setLayout(String layout);
Expand Down
Expand Up @@ -76,6 +76,10 @@ public class DocumentListView extends Composite implements DocumentListDisplay

@UiField
PushButton downloadAllFiles;

@UiField
PushButton runValidation;


@UiField(provided = true)
DocumentListPager pager;
Expand Down Expand Up @@ -189,6 +193,12 @@ public void onDownloadAllFilesClick(ClickEvent event)
{
confirmationBox.center();
}

@UiHandler("runValidation")
public void onRunValidationClicked(ClickEvent event)
{
listener.runValidation();
}

@Override
public void setStatsFilter(String option)
Expand Down
Expand Up @@ -70,6 +70,7 @@
<g:RadioButton ui:field="statsByWord" styleName="{style.optionStyle} {style.statsOption}" name="statsOption"/>
<g:RadioButton ui:field="statsByMsg" styleName="{style.optionStyle} {style.statsOption}" name="statsOption"/>
<g:PushButton ui:field="downloadAllFiles" addStyleNames="{style.downloadAllFilesButton}"/>
<g:PushButton ui:field="runValidation" addStyleNames="{style.downloadAllFilesButton}"/>
</g:HTMLPanel>
</g:cell>
</g:HorizontalPanel>
Expand Down
Expand Up @@ -20,13 +20,12 @@
import org.zanata.webtrans.shared.model.DocumentId;
import org.zanata.webtrans.shared.model.TransUnit;
import org.zanata.webtrans.shared.model.WorkspaceId;
import org.zanata.webtrans.shared.rpc.GetDocumentList;
import org.zanata.webtrans.shared.rpc.RunValidationAction;
import org.zanata.webtrans.shared.rpc.RunValidationResult;

@Name("webtrans.gwt.RunValidationHandler")
@Scope(ScopeType.STATELESS)
@ActionHandlerFor(GetDocumentList.class)
@ActionHandlerFor(RunValidationAction.class)
public class RunValidationHandler extends AbstractActionHandler<RunValidationAction, RunValidationResult>
{
@In
Expand Down
Expand Up @@ -4,7 +4,7 @@

public class DocumentId implements Identifier<Long>, IsSerializable
{
private long id;
private Long id;

private String docId;

Expand All @@ -14,7 +14,7 @@ private DocumentId()
{
}

public DocumentId(long id, String docId)
public DocumentId(Long id, String docId)
{
this.id = id;
this.docId = docId;
Expand All @@ -29,7 +29,7 @@ public String toString()
@Override
public int hashCode()
{
return (int) id;
return id.intValue();
}

@Override
Expand All @@ -38,7 +38,7 @@ public Long getValue()
return id;
}

public long getId()
public Long getId()
{
return id;
}
Expand Down
Expand Up @@ -15,19 +15,26 @@ public class RunValidationAction extends AbstractWorkspaceAction<RunValidationRe
private static final long serialVersionUID = 1L;

private List<ValidationId> validationIds;
private List<Long> docIds;

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

public RunValidationAction(List<ValidationId> validationIds)
public RunValidationAction(List<ValidationId> validationIds, List<Long> docIds)
{
this.validationIds = validationIds;
this.docIds = docIds;
}

public List<ValidationId> getValidationIds()
{
return validationIds;
}

public List<Long> getDocIds()
{
return docIds;
}
}
Expand Up @@ -156,7 +156,7 @@ public void testGetTextFlowByDocumentIdWithConstraint()
{
HLocale deLocale = getEm().find(HLocale.class, 3L);

List<HTextFlow> result = dao.getTextFlowByDocumentIdWithConstraint(new DocumentId(4, ""), deLocale, FilterConstraints.filterBy("mssg").excludeApproved().excludeFuzzy(), 0, 10);
List<HTextFlow> result = dao.getTextFlowByDocumentIdWithConstraint(new DocumentId(new Long(4), ""), deLocale, FilterConstraints.filterBy("mssg").excludeApproved().excludeFuzzy(), 0, 10);

assertThat(result, Matchers.hasSize(1));
}
Expand Down
Expand Up @@ -36,7 +36,7 @@ public class FilterConstraintToQueryTest
private Query query;
@Mock
private HLocale hLocale;
private DocumentId documentId = new DocumentId(1, "");
private DocumentId documentId = new DocumentId(new Long(1), "");

@BeforeMethod
public void beforeMethod()
Expand Down
Expand Up @@ -43,6 +43,7 @@
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.client.service.UserOptionsService;
import org.zanata.webtrans.client.service.ValidationService;
import org.zanata.webtrans.client.ui.DocumentNode;
import org.zanata.webtrans.client.view.DocumentListDisplay;
import org.zanata.webtrans.shared.model.DocumentId;
Expand Down Expand Up @@ -84,6 +85,8 @@ public class DocumentListPresenterTest
@Mock
private UserOptionsService mockUserOptionsService;
@Mock
private ValidationService mockValidationService;
@Mock
private CachingDispatchAsync mockDispatcher;

private UserConfigHolder configHolder;
Expand Down Expand Up @@ -113,7 +116,7 @@ public void beforeMethod()
configHolder = new UserConfigHolder();
when(mockUserOptionsService.getConfigHolder()).thenReturn(configHolder);
dataProviderList = new ArrayList<DocumentNode>();
documentListPresenter = new DocumentListPresenter(mockDisplay, mockEventBus, mockDispatcher, mockUserWorkspaceContext, mockMessages, mockHistory, mockUserOptionsService);
documentListPresenter = new DocumentListPresenter(mockDisplay, mockEventBus, mockDispatcher, mockUserWorkspaceContext, mockMessages, mockHistory, mockUserOptionsService, mockValidationService);

workspaceId = new WorkspaceId(new ProjectIterationId("projectSlug", "iterationSlug", ProjectType.Podir), LocaleId.EN_US);

Expand Down
Expand Up @@ -190,7 +190,7 @@ public void fireCopyEvent()
@Test
public void fireSearchEvent()
{
DocumentInfo docInfo = new DocumentInfo(new DocumentId(1, ""), "test", "test/path", LocaleId.EN_US, new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date());
DocumentInfo docInfo = new DocumentInfo(new DocumentId(new Long(1), ""), "test", "test/path", LocaleId.EN_US, new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date());
userWorkspaceContext.setSelectedDoc(docInfo);

when(messages.searchGlossary()).thenReturn("Search glossary");
Expand All @@ -213,7 +213,7 @@ public void fireSearchEvent()
public void fireSearchEventInSequentialWillBlockSecondRequestUntilFirstReturn()
{
// Given:
DocumentInfo docInfo = new DocumentInfo(new DocumentId(1, ""), "test", "test/path", LocaleId.EN_US, new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date());
DocumentInfo docInfo = new DocumentInfo(new DocumentId(new Long(1), ""), "test", "test/path", LocaleId.EN_US, new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date());
userWorkspaceContext.setSelectedDoc(docInfo);
when(messages.searchGlossary()).thenReturn("Search glossary");
when(display.getGlossaryTextBox()).thenReturn(mockGlossaryTextBox);
Expand All @@ -237,7 +237,7 @@ public void fireSearchEventInSequentialWillBlockSecondRequestUntilFirstReturn()
@Test
public void fireSearchEventOnSuccessCallbackWithGlossaryResults()
{
DocumentInfo docInfo = new DocumentInfo(new DocumentId(1, ""), "test", "test/path", LocaleId.EN_US, new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date());
DocumentInfo docInfo = new DocumentInfo(new DocumentId(new Long(1), ""), "test", "test/path", LocaleId.EN_US, new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date());
userWorkspaceContext.setSelectedDoc(docInfo);

when(messages.searchGlossary()).thenReturn("Search glossary");
Expand Down Expand Up @@ -265,7 +265,7 @@ public void fireSearchEventOnSuccessCallbackWithGlossaryResults()
@Test
public void fireSearchEventOnSuccessCallbackButNoGlossaryFound()
{
DocumentInfo docInfo = new DocumentInfo(new DocumentId(1, ""), "test", "test/path", LocaleId.EN_US, new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date());
DocumentInfo docInfo = new DocumentInfo(new DocumentId(new Long(1), ""), "test", "test/path", LocaleId.EN_US, new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date());
userWorkspaceContext.setSelectedDoc(docInfo);

when(messages.searchGlossary()).thenReturn("Search glossary");
Expand All @@ -291,7 +291,7 @@ public void fireSearchEventOnSuccessCallbackButNoGlossaryFound()
@Test
public void fireSearchEventOnFailureCallback()
{
DocumentInfo docInfo = new DocumentInfo(new DocumentId(1, ""), "test", "test/path", LocaleId.EN_US, new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date());
DocumentInfo docInfo = new DocumentInfo(new DocumentId(new Long(1), ""), "test", "test/path", LocaleId.EN_US, new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date());
userWorkspaceContext.setSelectedDoc(docInfo);

when(messages.searchGlossary()).thenReturn("Search glossary");
Expand All @@ -315,7 +315,7 @@ public void fireSearchEventOnFailureCallback()
@Test
public void createGlossaryRequestForTransUnit()
{
DocumentInfo docInfo = new DocumentInfo(new DocumentId(1, ""), "test", "test/path", LocaleId.EN_US, new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date());
DocumentInfo docInfo = new DocumentInfo(new DocumentId(new Long(1), ""), "test", "test/path", LocaleId.EN_US, new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date());
userWorkspaceContext.setSelectedDoc(docInfo);
when(messages.searchGlossary()).thenReturn("Search glossary");
when(display.getGlossaryTextBox()).thenReturn(mockGlossaryTextBox);
Expand Down
Expand Up @@ -184,7 +184,7 @@ public void fireCopyEvent()
public void createTMRequestForTransUnit()
{
WorkspaceId workspaceId = new WorkspaceId(new ProjectIterationId("projectSlug", "iterationSlug", ProjectType.Podir), LocaleId.EN_US);
DocumentInfo docInfo = new DocumentInfo(new DocumentId(1, ""), "test", "test/path", LocaleId.EN_US, new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date());
DocumentInfo docInfo = new DocumentInfo(new DocumentId(new Long(1), ""), "test", "test/path", LocaleId.EN_US, new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date());

when(display.getTmTextBox()).thenReturn(tMTextBox);
when(tMTextBox.getText()).thenReturn("query");
Expand All @@ -209,7 +209,7 @@ public void willDoNothingIfAlreadyHaveSubmittedRequest()
LocaleId localeId = new LocaleId("zh");
ProjectIterationId projectIterationId = new ProjectIterationId("project", "master", ProjectType.Podir);
when(userWorkspaceContext.getWorkspaceContext()).thenReturn(new WorkspaceContext(new WorkspaceId(projectIterationId, localeId), "workspaceName", localeId.getId()));
when(userWorkspaceContext.getSelectedDoc()).thenReturn(new DocumentInfo(new DocumentId(1, ""), "doc.txt", "/pot", new LocaleId("en-US"), new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date()));
when(userWorkspaceContext.getSelectedDoc()).thenReturn(new DocumentInfo(new DocumentId(new Long(1), ""), "doc.txt", "/pot", new LocaleId("en-US"), new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date()));

// When:
presenter.createTMRequestForTransUnit(TestFixture.makeTransUnit(1));
Expand Down Expand Up @@ -254,7 +254,7 @@ public void canFireSearchEvent()
ProjectIterationId projectIterationId = new ProjectIterationId("project", "master", ProjectType.Podir);
when(userWorkspaceContext.getWorkspaceContext()).thenReturn(new WorkspaceContext(new WorkspaceId(projectIterationId, targetLocale), "workspaceName", targetLocale.getId()));
LocaleId sourceLocale = new LocaleId("en-US");
when(userWorkspaceContext.getSelectedDoc()).thenReturn(new DocumentInfo(new DocumentId(1, ""), "doc.txt", "/pot", sourceLocale, new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date()));
when(userWorkspaceContext.getSelectedDoc()).thenReturn(new DocumentInfo(new DocumentId(new Long(1), ""), "doc.txt", "/pot", sourceLocale, new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date()));
when(display.getTmTextBox()).thenReturn(tMTextBox);
when(tMTextBox.getText()).thenReturn("search query");
when(display.getSearchType()).thenReturn(searchType);
Expand Down Expand Up @@ -282,7 +282,7 @@ public void fireSearchEventCallbackOnFailure()
LocaleId localeId = new LocaleId("zh");
ProjectIterationId projectIterationId = new ProjectIterationId("project", "master", ProjectType.Podir);
when(userWorkspaceContext.getWorkspaceContext()).thenReturn(new WorkspaceContext(new WorkspaceId(projectIterationId, localeId), "workspaceName", localeId.getId()));
when(userWorkspaceContext.getSelectedDoc()).thenReturn(new DocumentInfo(new DocumentId(1, ""), "doc.txt", "/pot", new LocaleId("en-US"), new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date()));
when(userWorkspaceContext.getSelectedDoc()).thenReturn(new DocumentInfo(new DocumentId(new Long(1), ""), "doc.txt", "/pot", new LocaleId("en-US"), new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date()));
when(display.getTmTextBox()).thenReturn(tMTextBox);
when(display.getSearchType()).thenReturn(searchType);

Expand All @@ -307,7 +307,7 @@ public void fireSearchEventCallbackOnSuccess()
LocaleId localeId = new LocaleId("zh");
ProjectIterationId projectIterationId = new ProjectIterationId("project", "master", ProjectType.Podir);
when(userWorkspaceContext.getWorkspaceContext()).thenReturn(new WorkspaceContext(new WorkspaceId(projectIterationId, localeId), "workspaceName", localeId.getId()));
when(userWorkspaceContext.getSelectedDoc()).thenReturn(new DocumentInfo(new DocumentId(1, ""), "doc.txt", "/pot", new LocaleId("en-US"), new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date()));
when(userWorkspaceContext.getSelectedDoc()).thenReturn(new DocumentInfo(new DocumentId(new Long(1), ""), "doc.txt", "/pot", new LocaleId("en-US"), new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date()));
when(display.getTmTextBox()).thenReturn(tMTextBox);
when(tMTextBox.getText()).thenReturn("search query");
when(display.getSearchType()).thenReturn(searchType);
Expand Down Expand Up @@ -336,7 +336,7 @@ public void fireSearchEventCallbackOnSuccessButResultIsEmpty()
LocaleId localeId = new LocaleId("zh");
ProjectIterationId projectIterationId = new ProjectIterationId("project", "master", ProjectType.Podir);
when(userWorkspaceContext.getWorkspaceContext()).thenReturn(new WorkspaceContext(new WorkspaceId(projectIterationId, localeId), "workspaceName", localeId.getId()));
when(userWorkspaceContext.getSelectedDoc()).thenReturn(new DocumentInfo(new DocumentId(1, ""), "doc.txt", "/pot", new LocaleId("en-US"), new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date()));
when(userWorkspaceContext.getSelectedDoc()).thenReturn(new DocumentInfo(new DocumentId(new Long(1), ""), "doc.txt", "/pot", new LocaleId("en-US"), new TranslationStats(), "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date()));
when(display.getTmTextBox()).thenReturn(tMTextBox);
when(display.getSearchType()).thenReturn(searchType);
when(searchType.getValue()).thenReturn(SearchType.FUZZY);
Expand Down
Expand Up @@ -44,7 +44,7 @@ public void execute()
Log.info("ENTER DummyActivateWorkspaceCommand.execute()");
WorkspaceContext context = new WorkspaceContext(action.getWorkspaceId(), "Dummy Workspace", "Mock Sweedish");
UserWorkspaceContext userWorkspaceContext = new UserWorkspaceContext(context, true, true, true);
userWorkspaceContext.setSelectedDoc(new DocumentInfo(new DocumentId(1, "Dummy path/Dummy doc"), "Dummy doc", "Dummy path", LocaleId.EN_US, null, "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date()));
userWorkspaceContext.setSelectedDoc(new DocumentInfo(new DocumentId(new Long(1), "Dummy path/Dummy doc"), "Dummy doc", "Dummy path", LocaleId.EN_US, null, "Translator", new Date(), new HashMap<String, String>(), "last translator", new Date()));

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"));

Expand Down

0 comments on commit 87e4cc5

Please sign in to comment.