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

Commit

Permalink
Implemen TM merge and searchreplace to handle validation error
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Sep 4, 2013
1 parent b34ef8f commit e13fcf8
Show file tree
Hide file tree
Showing 24 changed files with 321 additions and 192 deletions.
Expand Up @@ -44,9 +44,10 @@ public interface TranslationService
*
* @param localeId
* @param translationRequests
* @param runValidationCheck - Should be true by default
* @return information about each translation change
*/
List<TranslationResult> translate(LocaleId localeId, List<TransUnitUpdateRequest> translationRequests);
List<TranslationResult> translate(LocaleId localeId, List<TransUnitUpdateRequest> translationRequests, boolean skipValidationCheck);


/**
Expand Down Expand Up @@ -112,5 +113,6 @@ public interface TranslationResult
HTextFlowTarget getTranslatedTextFlowTarget();
int getBaseVersionNum();
ContentState getBaseContentState();
List<String> getErrorMessages();
}
}
Expand Up @@ -11,7 +11,6 @@
import org.zanata.model.HDocument;
import org.zanata.model.HProjectIteration;
import org.zanata.model.HTextFlow;
import org.zanata.webtrans.shared.model.TransUnitUpdateRequest;
import org.zanata.webtrans.shared.model.ValidationAction;
import org.zanata.webtrans.shared.model.ValidationId;

Expand Down Expand Up @@ -79,11 +78,13 @@ List<HTextFlow> filterHasWarningOrErrorTextFlow(List<HTextFlow> textFlows, List<
boolean runDocValidationsWithServerRules(HDocument hDoc, LocaleId localeId);

/**
* Run "Error" state validations check on update request state to 'translated'
* Run 'Error' state validations check against sources and translations
* @param projectVersion
* @param localeId
* @param updateRequest
* @param sources
* @param translations
* @return list of error message
*/
List<String> runUpdateRequestValidationsWithServerRules(HProjectIteration projectVersion, LocaleId localeId, TransUnitUpdateRequest updateRequest);
List<String> runUpdateRequestValidationsWithServerRules(HProjectIteration projectVersion, LocaleId localeId,
List<String> sources, List<String> translations);
}

Large diffs are not rendered by default.

Expand Up @@ -16,7 +16,6 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.log.Log;
import org.zanata.common.ContentState;
import org.zanata.common.LocaleId;
import org.zanata.dao.DocumentDAO;
import org.zanata.dao.ProjectDAO;
Expand All @@ -33,7 +32,6 @@
import org.zanata.service.ValidationService;
import org.zanata.webtrans.server.rpc.TransUnitTransformer;
import org.zanata.webtrans.shared.model.DocumentStatus;
import org.zanata.webtrans.shared.model.TransUnitUpdateRequest;
import org.zanata.webtrans.shared.model.ValidationAction;
import org.zanata.webtrans.shared.model.ValidationAction.State;
import org.zanata.webtrans.shared.model.ValidationId;
Expand Down Expand Up @@ -320,22 +318,17 @@ private boolean textFlowTargetHasWarningOrError(Long textFlowId, List<Validation

@Override
public List<String> runUpdateRequestValidationsWithServerRules(HProjectIteration projectVersion, LocaleId localeId,
TransUnitUpdateRequest updateRequest)
List<String> sources, List<String> translations)
{
Collection<ValidationAction> validationActions = getValidationAction(projectVersion, State.Error);
List<String> errorList = Lists.newArrayList();

if (updateRequest.getNewContentState() == ContentState.Translated)
{
HTextFlow tf = textFlowDAO.findById(updateRequest.getTransUnitId().getId(), false);

String tf_content0 = tf.getContents().get(0);
String tft_content0 = updateRequest.getNewContents().get(0);
String tf_content0 = sources.get(0);
String tft_content0 = translations.get(0);

for (ValidationAction action : validationActions)
{
errorList.addAll(action.validate(tf_content0, tft_content0));
}
for (ValidationAction action : validationActions)
{
errorList.addAll(action.validate(tf_content0, tft_content0));
}

return errorList;
Expand Down
Expand Up @@ -49,7 +49,6 @@
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.client.service.GetTransUnitActionContextHolder;
import org.zanata.webtrans.client.ui.SearchResultsDocumentTable;
import org.zanata.webtrans.client.ui.UndoLink;
import org.zanata.webtrans.shared.model.TransUnit;
import org.zanata.webtrans.shared.model.TransUnitId;
Expand Down Expand Up @@ -79,7 +78,6 @@
import com.google.gwt.view.client.MultiSelectionModel;
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SelectionChangeEvent.Handler;
import com.google.gwt.view.client.SelectionModel;
import com.google.inject.Inject;
import com.google.inject.Provider;

Expand Down Expand Up @@ -1059,6 +1057,10 @@ private List<TransUnitUpdateInfo> processSuccessfulReplacements(final List<Trans
refreshInfoDisplay(replaceInfo);
}
}
else
{
eventBus.fireEvent(new NotificationEvent(Severity.Error, messages.replaceTextFailure(updateInfo.getTransUnit().getId().toString(), updateInfo.getErrorMessages())));
}
// individual failure behaviour not yet defined
}
return successfulReplacements;
Expand Down
@@ -1,5 +1,7 @@
package org.zanata.webtrans.client.resources;

import java.util.List;

import com.google.gwt.i18n.client.LocalizableResource.DefaultLocale;
import com.google.gwt.i18n.client.LocalizableResource.Generate;
import com.google.gwt.i18n.client.Messages;
Expand All @@ -15,8 +17,8 @@ public interface TableEditorMessages extends Messages
@DefaultMessage("Failed to load data from server")
String notifyLoadFailed();

@DefaultMessage("Save FAILED: {0}")
String notifyUpdateFailed(String errorMessage);
@DefaultMessage("Save FAILED: {0}, messages: {1,list,string}")
String notifyUpdateFailed(String errorMessage, List<String> errorMessages);

@DefaultMessage("Row {0} (Id {1}) Saved")
String notifyUpdateSaved(int rowIndex, String id);
Expand Down
@@ -1,5 +1,7 @@
package org.zanata.webtrans.client.resources;

import java.util.List;

import com.google.gwt.i18n.client.LocalizableResource.DefaultLocale;
import com.google.gwt.i18n.client.LocalizableResource.Generate;
import com.google.gwt.i18n.client.Messages;
Expand Down Expand Up @@ -190,6 +192,9 @@ public interface WebTransMessages extends Messages
@DefaultMessage("Successfully replaced text")
String replacedTextSuccess();

@DefaultMessage("Replace text failed in text flow {0}, error message: {1,list,string}")
String replaceTextFailure(String id, List<String> errorMessages);

@DefaultMessage("Replace text failed")
String replaceTextFailure();

Expand Down
Expand Up @@ -21,6 +21,8 @@

package org.zanata.webtrans.client.service;

import java.util.List;

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

import org.zanata.common.ContentState;
Expand All @@ -47,6 +49,7 @@

import com.allen_sauer.gwt.log.client.Log;
import com.google.common.base.Objects;
import com.google.common.collect.Lists;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.inject.Inject;
import com.google.inject.Provider;
Expand All @@ -69,7 +72,10 @@ public class TransUnitSaveService implements TransUnitSaveEventHandler, CheckSta
private final SaveEventQueue queue;

@Inject
public TransUnitSaveService(EventBus eventBus, CachingDispatchAsync dispatcher, Provider<UndoLink> undoLinkProvider, DocumentListPresenter documentListPresenter, TargetContentsPresenter targetContentsPresenter, TableEditorMessages messages, NavigationService navigationService, Provider<GoToRowLink> goToRowLinkProvider, SaveEventQueue queue)
public TransUnitSaveService(EventBus eventBus, CachingDispatchAsync dispatcher, Provider<UndoLink> undoLinkProvider,
DocumentListPresenter documentListPresenter, TargetContentsPresenter targetContentsPresenter,
TableEditorMessages messages, NavigationService navigationService, Provider<GoToRowLink> goToRowLinkProvider,
SaveEventQueue queue)
{
this.messages = messages;
this.eventBus = eventBus;
Expand Down Expand Up @@ -121,9 +127,11 @@ private void performSave(TransUnitId idToSave)
targetContentsPresenter.setEditingState(idToSave, TargetContentsDisplay.EditingState.SAVING);
TransUnitUpdated.UpdateType updateType = workoutUpdateType(forSaving.getStatus());

UpdateTransUnit updateTransUnit = new UpdateTransUnit(new TransUnitUpdateRequest(idToSave, forSaving.getTargets(), forSaving.getAdjustedStatus(), forSaving.getVerNum()), updateType);
UpdateTransUnit updateTransUnit = new UpdateTransUnit(new TransUnitUpdateRequest(idToSave,
forSaving.getTargets(), forSaving.getAdjustedStatus(), forSaving.getVerNum()), updateType);
Log.info("about to save translation: " + updateTransUnit);
dispatcher.execute(updateTransUnit, new UpdateTransUnitCallback(forSaving, documentListPresenter.getCurrentDocument(), idToSave));
dispatcher.execute(updateTransUnit,
new UpdateTransUnitCallback(forSaving, documentListPresenter.getCurrentDocument(), idToSave));
}

/**
Expand All @@ -140,7 +148,8 @@ public void onCheckStateHasChanged(CheckStateHasChangedEvent event)
}

boolean targetChanged = !Objects.equal(transUnit.getTargets(), event.getTargets());
boolean targetUnchangedButCanSaveAsApproved = (event.getAdjustedState() == ContentState.Translated) && !Objects.equal(transUnit.getStatus(), event.getAdjustedState());
boolean targetUnchangedButCanSaveAsApproved = (event.getAdjustedState() == ContentState.Translated)
&& !Objects.equal(transUnit.getStatus(), event.getAdjustedState());

if (targetChanged)
{
Expand All @@ -155,25 +164,27 @@ else if (targetUnchangedButCanSaveAsApproved)
eventBus.fireEvent(NavTransUnitEvent.NEXT_ENTRY_EVENT);
}
}

private boolean stateHasNotChanged(TransUnitSaveEvent event)
{
TransUnit transUnit = navigationService.getByIdOrNull(event.getTransUnitId());
if (transUnit == null)
{
return false;
}
Log.info("id:" + transUnit.getId() + " old contents: " + transUnit.getTargets() + " state: " + transUnit.getStatus());
return Objects.equal(transUnit.getStatus(), event.getAdjustedStatus()) && Objects.equal(transUnit.getTargets(), event.getTargets());
Log.info("id:" + transUnit.getId() + " old contents: " + transUnit.getTargets() + " state: "
+ transUnit.getStatus());
return Objects.equal(transUnit.getStatus(), event.getAdjustedStatus())
&& Objects.equal(transUnit.getTargets(), event.getTargets());
}

private TransUnitUpdated.UpdateType workoutUpdateType(ContentState status)
{
if(status == ContentState.Approved || status == ContentState.Rejected)
if (status == ContentState.Approved || status == ContentState.Rejected)
{
return TransUnitUpdated.UpdateType.WebEditorSaveReview;
}
else if(status == ContentState.NeedReview)
else if (status == ContentState.NeedReview)
{
return TransUnitUpdated.UpdateType.WebEditorSaveFuzzy;
}
Expand Down Expand Up @@ -201,7 +212,7 @@ public UpdateTransUnitCallback(TransUnitSaveEvent event, DocumentInfo docInfo, T
public void onFailure(Throwable e)
{
Log.error("UpdateTransUnit failure ", e);
saveFailure();
saveFailure(Lists.newArrayList(e.getMessage()));
}

@Override
Expand All @@ -211,7 +222,8 @@ public void onSuccess(UpdateTransUnitResult result)
Log.debug("save resulted TU: " + updatedTU.debugString());
if (result.isSingleSuccess())
{
eventBus.fireEvent(new NotificationEvent(NotificationEvent.Severity.Info, messages.notifyUpdateSaved(updatedTU.getRowIndex(), updatedTU.getId().toString()), goToRowLink));
eventBus.fireEvent(new NotificationEvent(NotificationEvent.Severity.Info, messages.notifyUpdateSaved(
updatedTU.getRowIndex(), updatedTU.getId().toString()), goToRowLink));
int rowIndexOnPage = navigationService.findRowIndexById(updatedTU.getId());
if (rowIndexOnPage != NavigationService.UNDEFINED)
{
Expand All @@ -226,19 +238,20 @@ public void onSuccess(UpdateTransUnitResult result)
}
else
{
saveFailure();
saveFailure(result.getUpdateInfoList().get(0).getErrorMessages());
}
if (queue.hasPending())
{
performSave(id);
}
}

private void saveFailure()
private void saveFailure(List<String> errorMessages)
{
queue.removeAllPending(event.getTransUnitId());
targetContentsPresenter.setEditingState(event.getTransUnitId(), TargetContentsDisplay.EditingState.UNSAVED);
eventBus.fireEvent(new NotificationEvent(NotificationEvent.Severity.Error, messages.notifyUpdateFailed("id " + id), goToRowLink));
eventBus.fireEvent(new NotificationEvent(NotificationEvent.Severity.Error, messages.notifyUpdateFailed("id "
+ id, errorMessages), goToRowLink));
}
}
}
Expand Up @@ -21,6 +21,10 @@

package org.zanata.webtrans.server.rpc;

import lombok.extern.slf4j.Slf4j;
import net.customware.gwt.dispatch.server.ExecutionContext;
import net.customware.gwt.dispatch.shared.ActionException;

import org.apache.commons.lang.StringUtils;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
Expand Down Expand Up @@ -48,12 +52,6 @@
import org.zanata.webtrans.shared.rpc.AddReviewCommentAction;
import org.zanata.webtrans.shared.rpc.AddReviewCommentResult;
import org.zanata.webtrans.shared.rpc.TransUnitUpdated;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;

import lombok.extern.slf4j.Slf4j;
import net.customware.gwt.dispatch.server.ExecutionContext;
import net.customware.gwt.dispatch.shared.ActionException;

/**
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
Expand Down Expand Up @@ -126,7 +124,7 @@ private void publishTransUnitUpdatedEvent(AddReviewCommentAction action, HLocale
{
HTextFlow textFlow = hTextFlowTarget.getTextFlow();
TransUnit transUnit = transUnitTransformer.transform(textFlow, hTextFlowTarget, hLocale);
TransUnitUpdated transUnitUpdated = new TransUnitUpdated(new TransUnitUpdateInfo(true, false, action.getDocumentId(), transUnit, textFlow.getWordCount().intValue(), transUnit.getVerNum(), transUnit.getStatus()), action.getEditorClientId(), TransUnitUpdated.UpdateType.AddComment);
TransUnitUpdated transUnitUpdated = new TransUnitUpdated(new TransUnitUpdateInfo(true, false, action.getDocumentId(), transUnit, textFlow.getWordCount().intValue(), transUnit.getVerNum(), transUnit.getStatus(), null), action.getEditorClientId(), TransUnitUpdated.UpdateType.AddComment);
workspace.publish(transUnitUpdated);
}

Expand Down
Expand Up @@ -67,11 +67,13 @@ public class RevertTransUnitUpdatesHandler extends AbstractActionHandler<RevertT
@Override
public UpdateTransUnitResult execute(RevertTransUnitUpdates action, ExecutionContext context) throws ActionException
{
SecurityService.SecurityCheckResult securityCheckResult = securityServiceImpl.checkPermission(action, SecurityService.TranslationAction.MODIFY);
SecurityService.SecurityCheckResult securityCheckResult = securityServiceImpl.checkPermission(action,
SecurityService.TranslationAction.MODIFY);
HLocale hLocale = securityCheckResult.getLocale();
TranslationWorkspace workspace = securityCheckResult.getWorkspace();

List<TranslationResult> revertResults = translationServiceImpl.revertTranslations(hLocale.getLocaleId(), action.getUpdatesToRevert());
List<TranslationResult> revertResults = translationServiceImpl.revertTranslations(hLocale.getLocaleId(),
action.getUpdatesToRevert());

UpdateTransUnitResult results = new UpdateTransUnitResult();
for (TranslationResult translationResult : revertResults)
Expand All @@ -80,7 +82,10 @@ public UpdateTransUnitResult execute(RevertTransUnitUpdates action, ExecutionCon
HTextFlow hTextFlow = newTarget.getTextFlow();
int wordCount = hTextFlow.getWordCount().intValue();
TransUnit tu = transUnitTransformer.transform(hTextFlow, newTarget.getLocale());
TransUnitUpdateInfo updateInfo = new TransUnitUpdateInfo(translationResult.isTranslationSuccessful(), translationResult.isTargetChanged(), new DocumentId(hTextFlow.getDocument().getId(), hTextFlow.getDocument().getDocId()), tu, wordCount, translationResult.getBaseVersionNum(), translationResult.getBaseContentState());
TransUnitUpdateInfo updateInfo = new TransUnitUpdateInfo(translationResult.isTranslationSuccessful(),
translationResult.isTargetChanged(), new DocumentId(hTextFlow.getDocument().getId(), hTextFlow
.getDocument().getDocId()), tu, wordCount, translationResult.getBaseVersionNum(),
translationResult.getBaseContentState(), translationResult.getErrorMessages());

workspace.publish(new TransUnitUpdated(updateInfo, action.getEditorClientId(), UpdateType.Revert));
results.addUpdateResult(updateInfo);
Expand All @@ -89,7 +94,8 @@ public UpdateTransUnitResult execute(RevertTransUnitUpdates action, ExecutionCon
}

@Override
public void rollback(RevertTransUnitUpdates action, UpdateTransUnitResult result, ExecutionContext context) throws ActionException
public void rollback(RevertTransUnitUpdates action, UpdateTransUnitResult result, ExecutionContext context)
throws ActionException
{
}
}
Expand Up @@ -88,7 +88,7 @@ protected UpdateTransUnitResult doTranslation(LocaleId localeId, TranslationWork
TransUnitUpdated.UpdateType updateType)
{
UpdateTransUnitResult result = new UpdateTransUnitResult();
List<TranslationResult> translationResults = translationServiceImpl.translate(localeId, updateRequests);
List<TranslationResult> translationResults = translationServiceImpl.translate(localeId, updateRequests, true);
for (TranslationResult translationResult : translationResults)
{
HTextFlowTarget newTarget = translationResult.getTranslatedTextFlowTarget();
Expand All @@ -98,7 +98,7 @@ protected UpdateTransUnitResult doTranslation(LocaleId localeId, TranslationWork
TransUnitUpdateInfo updateInfo = new TransUnitUpdateInfo(translationResult.isTranslationSuccessful(),
translationResult.isTargetChanged(), new DocumentId(hTextFlow.getDocument().getId(), hTextFlow
.getDocument().getDocId()), tu, wordCount, translationResult.getBaseVersionNum(),
translationResult.getBaseContentState());
translationResult.getBaseContentState(), translationResult.getErrorMessages());
workspace.publish(new TransUnitUpdated(updateInfo, editorClientId, updateType));

result.addUpdateResult(updateInfo);
Expand Down

0 comments on commit e13fcf8

Please sign in to comment.