This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rhbz804871 - RPC for translation history
- Loading branch information
Patrick Huang
committed
Aug 10, 2012
1 parent
c8120b4
commit b62d804
Showing
6 changed files
with
217 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
zanata-war/src/main/java/org/zanata/webtrans/client/ui/TranslationHistoryView.ui.xml
This file was deleted.
Oops, something went wrong.
95 changes: 95 additions & 0 deletions
95
zanata-war/src/main/java/org/zanata/webtrans/server/rpc/GetTranslationHistoryHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package org.zanata.webtrans.server.rpc; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.jboss.seam.ScopeType; | ||
import org.jboss.seam.annotations.In; | ||
import org.jboss.seam.annotations.Name; | ||
import org.jboss.seam.annotations.Scope; | ||
import org.zanata.dao.TextFlowDAO; | ||
import org.zanata.exception.ZanataServiceException; | ||
import org.zanata.model.HLocale; | ||
import org.zanata.model.HTextFlow; | ||
import org.zanata.model.HTextFlowTargetHistory; | ||
import org.zanata.security.ZanataIdentity; | ||
import org.zanata.service.LocaleService; | ||
import org.zanata.webtrans.server.ActionHandlerFor; | ||
import org.zanata.webtrans.shared.model.TransHistoryItem; | ||
import org.zanata.webtrans.shared.rpc.GetTranslationHistoryAction; | ||
import org.zanata.webtrans.shared.rpc.GetTranslationHistoryResult; | ||
|
||
import com.google.common.base.Function; | ||
import com.google.common.collect.Collections2; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
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> | ||
*/ | ||
@Name("webtrans.gwt.GetTranslationHistoryHandler") | ||
@Scope(ScopeType.STATELESS) | ||
@ActionHandlerFor(GetTranslationHistoryAction.class) | ||
@Slf4j | ||
public class GetTranslationHistoryHandler extends AbstractActionHandler<GetTranslationHistoryAction, GetTranslationHistoryResult> | ||
{ | ||
@In | ||
ZanataIdentity identity; | ||
|
||
@In | ||
LocaleService localeServiceImpl; | ||
|
||
@In | ||
TextFlowDAO textFlowDAO; | ||
|
||
@Override | ||
public GetTranslationHistoryResult execute(GetTranslationHistoryAction action, ExecutionContext context) throws ActionException | ||
{ | ||
identity.checkLoggedIn(); | ||
log.debug("get translation history for text flow id {}", action.getTransUnitId()); | ||
|
||
HLocale hLocale; | ||
try | ||
{ | ||
hLocale = localeServiceImpl.validateLocaleByProjectIteration(action.getWorkspaceId().getLocaleId(), action.getWorkspaceId().getProjectIterationId().getProjectSlug(), action.getWorkspaceId().getProjectIterationId().getIterationSlug()); | ||
} | ||
catch (ZanataServiceException e) | ||
{ | ||
throw new ActionException(e); | ||
} | ||
|
||
HTextFlow hTextFlow = textFlowDAO.findById(action.getTransUnitId().getId(), false); | ||
|
||
Map<Integer,HTextFlowTargetHistory> history = hTextFlow.getTargets().get(hLocale.getId()).getHistory(); | ||
|
||
|
||
List<TransHistoryItem> historyItems = ImmutableList.copyOf(Collections2.transform(history.values(), new TargetHistoryToTransHistoryItemFunction())); | ||
return new GetTranslationHistoryResult(historyItems); | ||
} | ||
|
||
@Override | ||
public void rollback(GetTranslationHistoryAction action, GetTranslationHistoryResult result, ExecutionContext context) throws ActionException | ||
{ | ||
} | ||
|
||
private static class TargetHistoryToTransHistoryItemFunction implements Function<HTextFlowTargetHistory, TransHistoryItem> | ||
{ | ||
private final SimpleDateFormat dateFormat; | ||
|
||
public TargetHistoryToTransHistoryItemFunction() | ||
{ | ||
this.dateFormat = new SimpleDateFormat(); | ||
} | ||
|
||
@Override | ||
public TransHistoryItem apply(HTextFlowTargetHistory targetHistory) | ||
{ | ||
return new TransHistoryItem(targetHistory.getVersionNum(), targetHistory.getContents(), targetHistory.getState(), targetHistory.getLastModifiedBy().getName(), dateFormat.format(targetHistory.getLastChanged())); | ||
|
||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
zanata-war/src/main/java/org/zanata/webtrans/shared/model/TransHistoryItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.zanata.webtrans.shared.model; | ||
|
||
import java.util.List; | ||
|
||
import org.zanata.common.ContentState; | ||
import com.google.gwt.user.client.rpc.IsSerializable; | ||
|
||
/** | ||
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a> | ||
*/ | ||
public class TransHistoryItem implements IsSerializable | ||
{ | ||
private Integer versionNum; | ||
private List<String> contents; | ||
private ContentState status; | ||
private String modifiedBy; | ||
private String modifiedDate; | ||
|
||
@SuppressWarnings("unused") | ||
private TransHistoryItem() | ||
{ | ||
} | ||
|
||
public TransHistoryItem(Integer versionNum, List<String> contents, ContentState status, String modifiedBy, String modifiedDate) | ||
{ | ||
this.versionNum = versionNum; | ||
this.contents = contents; | ||
this.status = status; | ||
this.modifiedBy = modifiedBy; | ||
this.modifiedDate = modifiedDate; | ||
} | ||
|
||
public Integer getVersionNum() | ||
{ | ||
return versionNum; | ||
} | ||
|
||
public List<String> getContents() | ||
{ | ||
return contents; | ||
} | ||
|
||
public ContentState getStatus() | ||
{ | ||
return status; | ||
} | ||
|
||
public String getModifiedBy() | ||
{ | ||
return modifiedBy; | ||
} | ||
|
||
public String getModifiedDate() | ||
{ | ||
return modifiedDate; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
zanata-war/src/main/java/org/zanata/webtrans/shared/rpc/GetTranslationHistoryAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.zanata.webtrans.shared.rpc; | ||
|
||
import org.zanata.webtrans.shared.model.TransUnitId; | ||
|
||
/** | ||
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a> | ||
*/ | ||
public class GetTranslationHistoryAction extends AbstractWorkspaceAction<GetTranslationHistoryResult> | ||
{ | ||
private TransUnitId transUnitId; | ||
|
||
public GetTranslationHistoryAction(TransUnitId transUnitId) | ||
{ | ||
this.transUnitId = transUnitId; | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
private GetTranslationHistoryAction() | ||
{ | ||
} | ||
|
||
public TransUnitId getTransUnitId() | ||
{ | ||
return transUnitId; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
zanata-war/src/main/java/org/zanata/webtrans/shared/rpc/GetTranslationHistoryResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.zanata.webtrans.shared.rpc; | ||
|
||
import java.util.List; | ||
|
||
import org.zanata.webtrans.shared.model.TransHistoryItem; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
import net.customware.gwt.dispatch.shared.Result; | ||
|
||
/** | ||
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a> | ||
*/ | ||
public class GetTranslationHistoryResult implements DispatchResult | ||
{ | ||
private List<TransHistoryItem> historyItems = Lists.newArrayList(); | ||
|
||
|
||
@SuppressWarnings("unused") | ||
private GetTranslationHistoryResult() | ||
{ | ||
} | ||
|
||
public GetTranslationHistoryResult(List<TransHistoryItem> historyItems) | ||
{ | ||
this.historyItems = historyItems; | ||
} | ||
|
||
public List<TransHistoryItem> getHistoryItems() | ||
{ | ||
return historyItems; | ||
} | ||
} |