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

Commit

Permalink
rhbz804871 - RPC for translation history
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Aug 10, 2012
1 parent c8120b4 commit b62d804
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 10 deletions.
6 changes: 6 additions & 0 deletions zanata-war/src/main/java/org/zanata/dao/AbstractDAOImpl.java
Expand Up @@ -39,7 +39,9 @@ public void setSession(Session s)
protected Session getSession()
{
if (session == null)
{
throw new IllegalStateException("Session has not been set on DAO before usage");
}
return session;
}

Expand All @@ -54,9 +56,13 @@ public T findById(ID id, boolean lock)
{
T entity;
if (lock)
{
entity = (T) getSession().load(getPersistentClass(), id, LockMode.UPGRADE);
}
else
{
entity = (T) getSession().load(getPersistentClass(), id);
}

return entity;
}
Expand Down

This file was deleted.

@@ -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()));

}
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}

0 comments on commit b62d804

Please sign in to comment.