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: generating validation reports in document list view:
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Mar 21, 2013
1 parent efedc53 commit 6055958
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 51 deletions.
@@ -0,0 +1,84 @@
package org.zanata.webtrans.client.events;

import java.util.Date;
import java.util.List;

import org.zanata.common.LocaleId;
import org.zanata.webtrans.shared.model.DocumentId;
import org.zanata.webtrans.shared.model.TransUnitValidationResult;

import com.google.gwt.event.shared.GwtEvent;

public class DocValidationReportResultEvent extends GwtEvent<DocValidationReportResultHandler>
{
private Date startTime;
private Date endTime;
private List<TransUnitValidationResult> result;
private LocaleId localeId;
private DocumentId documentId;

public DocValidationReportResultEvent(DocumentId documentId, Date startTime, Date endTime, List<TransUnitValidationResult> result, LocaleId localeId)
{
this.startTime = startTime;
this.endTime = endTime;
this.result = result;
this.localeId = localeId;
this.documentId = documentId;
}

/**
* Handler type.
*/
private static Type<DocValidationReportResultHandler> TYPE;

/**
* Gets the type associated with this event.
*
* @return returns the handler type
*/
public static Type<DocValidationReportResultHandler> getType()
{
if (TYPE == null)
{
TYPE = new Type<DocValidationReportResultHandler>();
}
return TYPE;
}

@Override
public com.google.gwt.event.shared.GwtEvent.Type<DocValidationReportResultHandler> getAssociatedType()
{
return getType();
}

@Override
protected void dispatch(DocValidationReportResultHandler handler)
{
handler.onCompleteRunDocReportValidation(this);
}

public Date getStartTime()
{
return startTime;
}

public Date getEndTime()
{
return endTime;
}

public List<TransUnitValidationResult> getResult()
{
return result;
}

public LocaleId getLocaleId()
{
return localeId;
}

public DocumentId getDocumentId()
{
return documentId;
}
}
@@ -0,0 +1,28 @@
/*
* Copyright 2010, Red Hat, Inc. and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.zanata.webtrans.client.events;

import com.google.gwt.event.shared.EventHandler;

public interface DocValidationReportResultHandler extends EventHandler
{
void onCompleteRunDocReportValidation(DocValidationReportResultEvent event);
}
Expand Up @@ -7,13 +7,13 @@

import com.google.gwt.event.shared.GwtEvent;

public class RunDocValidationResultEvent extends GwtEvent<RunDocValidationResultHandler>
public class DocValidationResultEvent extends GwtEvent<DocValidationResultHandler>
{
private Date startTime;
private Date endTime;
private Set<DocumentId> errorDocs;

public RunDocValidationResultEvent(Date startTime, Date endTime, Set<DocumentId> errorDocs)
public DocValidationResultEvent(Date startTime, Date endTime, Set<DocumentId> errorDocs)
{
this.startTime = startTime;
this.endTime = endTime;
Expand All @@ -23,30 +23,30 @@ public RunDocValidationResultEvent(Date startTime, Date endTime, Set<DocumentId>
/**
* Handler type.
*/
private static Type<RunDocValidationResultHandler> TYPE;
private static Type<DocValidationResultHandler> TYPE;

/**
* Gets the type associated with this event.
*
* @return returns the handler type
*/
public static Type<RunDocValidationResultHandler> getType()
public static Type<DocValidationResultHandler> getType()
{
if (TYPE == null)
{
TYPE = new Type<RunDocValidationResultHandler>();
TYPE = new Type<DocValidationResultHandler>();
}
return TYPE;
}

@Override
public com.google.gwt.event.shared.GwtEvent.Type<RunDocValidationResultHandler> getAssociatedType()
public com.google.gwt.event.shared.GwtEvent.Type<DocValidationResultHandler> getAssociatedType()
{
return getType();
}

@Override
protected void dispatch(RunDocValidationResultHandler handler)
protected void dispatch(DocValidationResultHandler handler)
{
handler.onCompleteRunDocValidation(this);
}
Expand Down
Expand Up @@ -22,7 +22,7 @@

import com.google.gwt.event.shared.EventHandler;

public interface RunDocValidationResultHandler extends EventHandler
public interface DocValidationResultHandler extends EventHandler
{
void onCompleteRunDocValidation(RunDocValidationResultEvent event);
void onCompleteRunDocValidation(DocValidationResultEvent event);
}
Expand Up @@ -42,7 +42,7 @@
import org.zanata.webtrans.client.events.ProjectStatsUpdatedEvent;
import org.zanata.webtrans.client.events.RunDocValidationEvent;
import org.zanata.webtrans.client.events.RunDocValidationEventHandler;
import org.zanata.webtrans.client.events.RunDocValidationResultEvent;
import org.zanata.webtrans.client.events.DocValidationResultEvent;
import org.zanata.webtrans.client.events.TransUnitUpdatedEvent;
import org.zanata.webtrans.client.events.TransUnitUpdatedEventHandler;
import org.zanata.webtrans.client.events.UserConfigChangeEvent;
Expand Down Expand Up @@ -556,7 +556,7 @@ public void onFailure(Throwable caught)
{
eventBus.fireEvent(new NotificationEvent(NotificationEvent.Severity.Error, "Unable to run validation"));
display.showLoading(false);
eventBus.fireEvent(new RunDocValidationResultEvent(startTime, new Date(), null));
eventBus.fireEvent(new DocValidationResultEvent(startTime, new Date(), null));
}

@Override
Expand All @@ -577,7 +577,7 @@ public void onSuccess(RunDocValidationResult result)
}
dataProvider.refresh();
display.showLoading(false);
eventBus.fireEvent(new RunDocValidationResultEvent(startTime, new Date(), resultMap.keySet()));
eventBus.fireEvent(new DocValidationResultEvent(startTime, new Date(), resultMap.keySet()));
}
});
}
Expand Down
Expand Up @@ -26,28 +26,24 @@
import net.customware.gwt.presenter.client.EventBus;
import net.customware.gwt.presenter.client.widget.WidgetPresenter;

import org.zanata.webtrans.client.events.NotificationEvent;
import org.zanata.webtrans.client.events.NotificationEvent.Severity;
import org.zanata.webtrans.client.events.DocValidationReportResultEvent;
import org.zanata.webtrans.client.events.DocValidationReportResultHandler;
import org.zanata.webtrans.client.events.DocValidationResultEvent;
import org.zanata.webtrans.client.events.DocValidationResultHandler;
import org.zanata.webtrans.client.events.RunDocValidationEvent;
import org.zanata.webtrans.client.events.RunDocValidationResultEvent;
import org.zanata.webtrans.client.events.RunDocValidationResultHandler;
import org.zanata.webtrans.client.events.WorkspaceContextUpdateEvent;
import org.zanata.webtrans.client.events.WorkspaceContextUpdateEventHandler;
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.client.service.ValidationService;
import org.zanata.webtrans.client.view.ValidationOptionsDisplay;
import org.zanata.webtrans.shared.model.DocumentId;
import org.zanata.webtrans.shared.model.ValidationAction;
import org.zanata.webtrans.shared.model.ValidationInfo;
import org.zanata.webtrans.shared.rpc.DownloadAllFilesResult;
import org.zanata.webtrans.shared.rpc.RunDocValidationReportAction;
import org.zanata.webtrans.shared.rpc.RunDocValidationReportResult;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.event.logical.shared.HasValueChangeHandlers;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.inject.Inject;

/**
Expand All @@ -56,30 +52,27 @@
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*
**/
public class ValidationOptionsPresenter extends WidgetPresenter<ValidationOptionsDisplay> implements ValidationOptionsDisplay.Listener, WorkspaceContextUpdateEventHandler, RunDocValidationResultHandler
public class ValidationOptionsPresenter extends WidgetPresenter<ValidationOptionsDisplay> implements ValidationOptionsDisplay.Listener, WorkspaceContextUpdateEventHandler, DocValidationResultHandler, DocValidationReportResultHandler
{
private final ValidationService validationService;
private final WebTransMessages messages;
private final CachingDispatchAsync dispatcher;
private final UserConfigHolder configHolder;
private MainView currentView;
private Set<DocumentId> errorDocs;

@Inject
public ValidationOptionsPresenter(ValidationOptionsDisplay display, EventBus eventBus, CachingDispatchAsync dispatcher, final ValidationService validationService, final WebTransMessages messages, final UserConfigHolder configHolder)
public ValidationOptionsPresenter(ValidationOptionsDisplay display, EventBus eventBus, final ValidationService validationService, final WebTransMessages messages)
{
super(display, eventBus);
this.validationService = validationService;
this.messages = messages;
this.dispatcher = dispatcher;
this.configHolder = configHolder;
}

@Override
protected void onBind()
{
registerHandler(eventBus.addHandler(WorkspaceContextUpdateEvent.getType(), this));
registerHandler(eventBus.addHandler(RunDocValidationResultEvent.getType(), this));
registerHandler(eventBus.addHandler(DocValidationResultEvent.getType(), this));
registerHandler(eventBus.addHandler(DocValidationReportResultEvent.getType(), this));
initDisplay();

display.updateValidationResult(null, null);
Expand Down Expand Up @@ -170,7 +163,7 @@ public void onRunValidation()
}

@Override
public void onCompleteRunDocValidation(RunDocValidationResultEvent event)
public void onCompleteRunDocValidation(DocValidationResultEvent event)
{
display.updateValidationResult(event.getStartTime(), event.getEndTime());
errorDocs = event.getErrorDocs();
Expand All @@ -183,28 +176,17 @@ public void onCompleteRunDocValidation(RunDocValidationResultEvent event)
@Override
public void onRequestValidationReport()
{
// display.showReportPopup(errorDocs);
for (final DocumentId documentId : errorDocs)
{
dispatcher.execute(new RunDocValidationReportAction(configHolder.getState().getEnabledValidationIds(), documentId.getId()), new AsyncCallback<RunDocValidationReportResult>()
{
@Override
public void onFailure(Throwable caught)
{
eventBus.fireEvent(new NotificationEvent(Severity.Error, "Error generating report for document " + documentId));
}

@Override
public void onSuccess(RunDocValidationReportResult result)
{
// display.updateReport(documentId, result.getResult());
}
});
}
validationService.executeValidationReportQueue(errorDocs);
}

private boolean hasErrorReport()
{
return errorDocs != null && !errorDocs.isEmpty();
}

@Override
public void onCompleteRunDocReportValidation(DocValidationReportResultEvent event)
{
display.updateDocValidationReport(event.getDocumentId(), event.getLocaleId(), event.getResult(), event.getStartTime(), event.getEndTime());
}
}
Expand Up @@ -21,11 +21,14 @@
package org.zanata.webtrans.client.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

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

import org.zanata.webtrans.client.events.DocValidationReportResultEvent;
import org.zanata.webtrans.client.events.DocumentSelectionEvent;
import org.zanata.webtrans.client.events.DocumentSelectionHandler;
import org.zanata.webtrans.client.events.NotificationEvent;
Expand All @@ -38,12 +41,17 @@
import org.zanata.webtrans.client.presenter.UserConfigHolder;
import org.zanata.webtrans.client.resources.TableEditorMessages;
import org.zanata.webtrans.client.resources.ValidationMessages;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.client.ui.HasUpdateValidationWarning;
import org.zanata.webtrans.shared.model.DocumentId;
import org.zanata.webtrans.shared.model.ValidationAction;
import org.zanata.webtrans.shared.model.ValidationId;
import org.zanata.webtrans.shared.model.ValidationInfo;
import org.zanata.webtrans.shared.rpc.RunDocValidationReportAction;
import org.zanata.webtrans.shared.rpc.RunDocValidationReportResult;
import org.zanata.webtrans.shared.validation.ValidationFactory;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.inject.Inject;
import com.google.inject.Singleton;

Expand All @@ -61,13 +69,15 @@ public class ValidationService implements RunValidationEventHandler, TransUnitSe
private Map<ValidationId, ValidationAction> validationMap;
private final ValidationFactory validationFactory;
private final UserConfigHolder configHolder;
private final CachingDispatchAsync dispatcher;

@Inject
public ValidationService(final EventBus eventBus, final TableEditorMessages messages, final ValidationMessages validationMessages, final UserConfigHolder configHolder)
public ValidationService(final CachingDispatchAsync dispatcher, final EventBus eventBus, final TableEditorMessages messages, final ValidationMessages validationMessages, final UserConfigHolder configHolder)
{
this.eventBus = eventBus;
this.messages = messages;
this.configHolder = configHolder;
this.dispatcher = dispatcher;

validationFactory = new ValidationFactory(validationMessages);

Expand Down Expand Up @@ -195,4 +205,26 @@ private void updateConfigHolder()
}
configHolder.setEnabledValidationIds(enabledValidations);
}

public void executeValidationReportQueue(Set<DocumentId> errorDocs)
{
for (final DocumentId documentId : errorDocs)
{
final Date startTime = new Date();
dispatcher.execute(new RunDocValidationReportAction(configHolder.getState().getEnabledValidationIds(), documentId.getId()), new AsyncCallback<RunDocValidationReportResult>()
{
@Override
public void onFailure(Throwable caught)
{
eventBus.fireEvent(new NotificationEvent(Severity.Error, "Error generating report for document " + documentId));
}

@Override
public void onSuccess(RunDocValidationReportResult result)
{
eventBus.fireEvent(new DocValidationReportResultEvent(documentId, startTime, new Date(), result.getResult(), result.getLocaleId()));
}
});
}
}
}

0 comments on commit 6055958

Please sign in to comment.