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

Commit

Permalink
Merge branch 'master' of github.com:zanata/zanata into integration/ma…
Browse files Browse the repository at this point in the history
…ster
  • Loading branch information
Patrick Huang committed May 29, 2012
2 parents 54a619e + b8c041a commit 4e3a402
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 30 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Expand Up @@ -19,9 +19,9 @@
</scm>

<properties>
<zanata.api.version>1.6.0-alpha-3</zanata.api.version>
<zanata.client.version>1.6.0-alpha-3</zanata.client.version>
<zanata.common.version>1.6.0-alpha-3</zanata.common.version>
<zanata.api.version>1.6.0-alpha-4-SNAPSHOT</zanata.api.version>
<zanata.client.version>1.6.0-alpha-4-SNAPSHOT</zanata.client.version>
<zanata.common.version>1.6.0-alpha-4-SNAPSHOT</zanata.common.version>

<!--delombok properties-->
<lombok.source.dir>${project.build.sourceDirectory}/org/zanata</lombok.source.dir>
Expand Down
16 changes: 12 additions & 4 deletions zanata-war/src/main/java/org/zanata/dao/TextFlowTargetDAO.java
Expand Up @@ -128,6 +128,12 @@ public int getTotalNeedReviewWords()
return totalCount.intValue();
}

/**
* Finds all (including obsolete) translations for 'document' in 'locale'.
* @param document
* @param locale
* @return
*/
@SuppressWarnings("unchecked")
public List<HTextFlowTarget> findAllTranslations(HDocument document, LocaleId localeId)
{
Expand All @@ -136,16 +142,20 @@ public List<HTextFlowTarget> findAllTranslations(HDocument document, LocaleId lo
"select t from HTextFlowTarget t where " +
"t.textFlow.document =:document " +
"and t.locale.localeId =:localeId " +
"and t.state !=:state " +
"order by t.textFlow.pos");
q.setParameter("document", document);
q.setParameter("localeId", localeId);
q.setParameter("state", ContentState.New);
q.setCacheable(true);
return q.list();
// @formatter:on
}

/**
* Finds non-obsolete translations for 'document' in 'locale'.
* @param document
* @param locale
* @return
*/
@SuppressWarnings("unchecked")
public List<HTextFlowTarget> findTranslations(HDocument document, HLocale locale)
{
Expand All @@ -155,12 +165,10 @@ public List<HTextFlowTarget> findTranslations(HDocument document, HLocale locale
"from HTextFlowTarget t where " +
"t.textFlow.document =:document " +
"and t.locale =:locale " +
"and t.state !=:state " +
"and t.textFlow.obsolete=false " +
"order by t.textFlow.pos");
q.setParameter("document", document);
q.setParameter("locale", locale);
q.setParameter("state", ContentState.New);
q.setCacheable(true);
return q.list();
// @formatter:on
Expand Down
Expand Up @@ -38,6 +38,7 @@
import org.zanata.dao.TextFlowTargetDAO;
import org.zanata.model.HDocument;
import org.zanata.model.HLocale;
import org.zanata.model.HTextFlowTarget;
import org.zanata.rest.dto.resource.Resource;
import org.zanata.rest.dto.resource.TranslationsResource;
import org.zanata.rest.service.ResourceUtils;
Expand Down Expand Up @@ -128,9 +129,9 @@ protected void runProcess(IterationZipFileBuildProcessHandle zipHandle) throws E
}

TranslationsResource translationResource = new TranslationsResource();
List<HTextFlowTarget> hTargets = textFlowTargetDAO.findTranslations(document, hLocale);
resourceUtils.transferToTranslationsResource(
translationResource, document, hLocale, extensions,
textFlowTargetDAO.findTranslations(document, hLocale));
translationResource, document, hLocale, extensions, hTargets);

Resource res = this.resourceUtils.buildResource( document );

Expand Down
Expand Up @@ -1353,7 +1353,7 @@ public Resource buildResource(HDocument document)
* @param locale
* @param enabledExtensions
* @param hTargets
* @return true only if some data was found (non-New translations, or some
* @return true only if some data was found (text flow targets, or some
* metadata extensions)
*/
public boolean transferToTranslationsResource(TranslationsResource transRes, HDocument document, HLocale locale, Set<String> enabledExtensions, List<HTextFlowTarget> hTargets)
Expand All @@ -1362,10 +1362,7 @@ public boolean transferToTranslationsResource(TranslationsResource transRes, HDo

for (HTextFlowTarget hTarget : hTargets)
{
if (hTarget.getState() != ContentState.New)
{
found = true;
}
found = true;
TextFlowTarget target = new TextFlowTarget();
target.setResId(hTarget.getTextFlow().getResId());
this.transferToTextFlowTarget(hTarget, target);
Expand Down
Expand Up @@ -230,9 +230,9 @@ public Response getTranslations(

HLocale hLocale = validateTargetLocale(locale, projectSlug, iterationSlug);
TranslationsResource translationResource = new TranslationsResource();
List<HTextFlowTarget> hTargets = textFlowTargetDAO.findTranslations(document, hLocale);
boolean foundData = resourceUtils.transferToTranslationsResource(
translationResource, document, hLocale, extensions,
textFlowTargetDAO.findTranslations(document, hLocale));
translationResource, document, hLocale, extensions, hTargets);

if (!foundData && !skeletons)
{
Expand Down
Expand Up @@ -41,14 +41,21 @@
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.Header;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.ImageResourceRenderer;
import com.google.gwt.view.client.CellPreviewEvent;
Expand Down Expand Up @@ -112,6 +119,9 @@ public SearchResultsDocumentTable(Delegate<TransUnitReplaceInfo> previewDelegate
}

checkboxColumn = new CheckColumn(selectionModel);
CheckboxHeader checkboxColumnHeader = new CheckboxHeader();
checkboxColumnHeader.addValueChangeHandler(selectAllHandler);

rowIndexColumn = buildRowIndexColumn();
sourceColumn = buildSourceColumn();
targetColumn = buildTargetColumn();
Expand All @@ -120,7 +130,7 @@ public SearchResultsDocumentTable(Delegate<TransUnitReplaceInfo> previewDelegate

setWidth("100%", true);

addColumn(checkboxColumn, "");
addColumn(checkboxColumn, checkboxColumnHeader);
addColumn(rowIndexColumn, messages.rowIndex());
addColumn(sourceColumn, messages.source());
addColumn(targetColumn, messages.target());
Expand Down Expand Up @@ -274,6 +284,74 @@ public Boolean getValue(TransUnitReplaceInfo info)

}

private class CheckboxHeader extends Header<Boolean> implements HasValue<Boolean> {

private boolean checked;
private HandlerManager handlerManager;

public CheckboxHeader()
{
super(new CheckboxCell());
checked = false;
}

// This method is invoked to pass the value to the CheckboxCell's render method
@Override
public Boolean getValue()
{
return checked;
}

@Override
public void onBrowserEvent(Context context, Element elem, NativeEvent nativeEvent)
{
int eventType = Event.as(nativeEvent).getTypeInt();
if (eventType == Event.ONCHANGE)
{
nativeEvent.preventDefault();
//use value setter to easily fire change event to handlers
setValue(!checked, true);
}
}

@Override
public HandlerRegistration addValueChangeHandler(ValueChangeHandler<Boolean> handler)
{
return ensureHandlerManager().addHandler(ValueChangeEvent.getType(), handler);
}

@Override
public void fireEvent(GwtEvent<?> event)
{
ensureHandlerManager().fireEvent(event);
}

@Override
public void setValue(Boolean value)
{
checked = value;
}

@Override
public void setValue(Boolean value, boolean fireEvents)
{
checked = value;
if (fireEvents)
{
ValueChangeEvent.fire(this, value);
}
}

private HandlerManager ensureHandlerManager()
{
if (handlerManager == null)
{
handlerManager = new HandlerManager(this);
}
return handlerManager;
}
}

private class ActionColumn extends Column<TransUnitReplaceInfo, TransUnitReplaceInfo>
{

Expand Down
Expand Up @@ -282,14 +282,14 @@ public HasData<TransUnitReplaceInfo> addDocument(String docName,
{
// ensure 'no results' message is no longer visible
noResultsLabel.removeFromParent();
addDocumentLabel(docName, viewDocClickHandler, searchDocClickHandler, selectAllHandler);
addDocumentLabel(docName, viewDocClickHandler, searchDocClickHandler);
SearchResultsDocumentTable table = new SearchResultsDocumentTable(previewDelegate, replaceDelegate, undoDelegate, selectionModel, selectAllHandler, messages, resources);
searchResultsPanel.add(table);
table.addStyleName("projectWideSearchResultsDocumentBody");
return table;
}

private void addDocumentLabel(String docName, ClickHandler viewDocClickHandler, ClickHandler searchDocClickHandler, ValueChangeHandler<Boolean> selectAllHandler)
private void addDocumentLabel(String docName, ClickHandler viewDocClickHandler, ClickHandler searchDocClickHandler)
{
FlowPanel docHeading = new FlowPanel();
docHeading.addStyleName("projectWideSearchResultsDocumentHeader");
Expand All @@ -298,11 +298,6 @@ private void addDocumentLabel(String docName, ClickHandler viewDocClickHandler,
docLabel.addStyleName("projectWideSearchResultsDocumentTitle");
docHeading.add(docLabel);

CheckBox selectWholeDocCheckBox = new CheckBox(messages.selectAllInDocument());
selectWholeDocCheckBox.setTitle(messages.selectAllInDocumentDetailed());
selectWholeDocCheckBox.addValueChangeHandler(selectAllHandler);
docHeading.add(selectWholeDocCheckBox);

InlineLabel searchDocLabel = new InlineLabel(messages.searchDocInEditor());
searchDocLabel.setTitle(messages.searchDocInEditorDetailed());
searchDocLabel.addClickHandler(searchDocClickHandler);
Expand Down
Expand Up @@ -3,6 +3,8 @@
import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap;

import javax.servlet.http.HttpServletRequest;

import org.hibernate.Session;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
Expand Down Expand Up @@ -79,12 +81,12 @@ public void start()
@Observer(ZanataIdentity.USER_LOGOUT_EVENT)
public void exitWorkspace(String username)
{
LOGGER.info("User logout: Removing {} from all workspaces", username);
String httpSessionId = getSessionId();
LOGGER.info("User logout: Removing {} from all workspaces, session: {}", username, httpSessionId);
HPerson person = accountDAO.getByUsername(username).getPerson();
ImmutableSet<TranslationWorkspace> workspaceSet = ImmutableSet.copyOf(workspaceMap.values());
for (TranslationWorkspace workspace : workspaceSet)
{
String httpSessionId = ServletContexts.instance().getRequest().getSession().getId();
Collection<EditorClientId> editorClients = workspace.removeEditorClients(httpSessionId);
for (EditorClientId editorClientId : editorClients)
{
Expand All @@ -96,6 +98,15 @@ public void exitWorkspace(String username)
}
}

private String getSessionId()
{
HttpServletRequest request = ServletContexts.instance().getRequest();
if (request == null)
{
return null;
}
return request.getSession().getId();
}

@Observer(ProjectHome.PROJECT_UPDATE)
public void projectUpdate(HIterationProject project)
Expand Down
Expand Up @@ -24,6 +24,8 @@
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;

import java.util.List;

import javax.ws.rs.core.Response.Status;

import org.dbunit.operation.DatabaseOperation;
Expand Down Expand Up @@ -388,6 +390,10 @@ public void deleteTranslations() throws Exception
// try to fetch them again
ClientResponse<TranslationsResource> getResponse = translationsClient.getTranslations(
"my,path,document-3.txt", LocaleId.EN_US, new StringSet(PoHeader.ID + ";" + SimpleComment.ID));
assertThat(getResponse.getStatus(), is(Status.NOT_FOUND.getStatusCode())); // 404
List<TextFlowTarget> targets = getResponse.getEntity().getTextFlowTargets();
for (TextFlowTarget target : targets)
{
assertThat(target.getState(), is(ContentState.New));
}
}
}
Expand Up @@ -24,6 +24,8 @@
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;

import java.util.List;

import javax.ws.rs.core.Response.Status;

import org.dbunit.operation.DatabaseOperation;
Expand Down Expand Up @@ -388,6 +390,10 @@ public void deleteTranslations() throws Exception
// try to fetch them again
ClientResponse<TranslationsResource> getResponse = translationsClient.getTranslations(
"my,path,document-3.txt", LocaleId.EN_US, new StringSet(PoHeader.ID + ";" + SimpleComment.ID));
assertThat(getResponse.getStatus(), is(Status.NOT_FOUND.getStatusCode())); // 404
List<TextFlowTarget> targets = getResponse.getEntity().getTextFlowTargets();
for (TextFlowTarget target : targets)
{
assertThat(target.getState(), is(ContentState.New));
}
}
}
Expand Up @@ -20,6 +20,8 @@
*/
package org.zanata.rest.compat.v1_5_0;

import java.util.List;

import org.dbunit.operation.DatabaseOperation;
import org.jboss.resteasy.client.ClientResponse;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -388,6 +390,10 @@ public void deleteTranslations() throws Exception
// try to fetch them again
ClientResponse<TranslationsResource> getResponse = translationsClient.getTranslations(
"my,path,document-3.txt", LocaleId.EN_US, new StringSet(PoHeader.ID + ";" + SimpleComment.ID));
assertThat(getResponse.getStatus(), is(Status.NOT_FOUND.getStatusCode())); // 404
List<TextFlowTarget> targets = getResponse.getEntity().getTextFlowTargets();
for (TextFlowTarget target : targets)
{
assertThat(target.getState(), is(ContentState.New));
}
}
}
Expand Up @@ -307,7 +307,7 @@ public void publishTranslations()
assertThat(response.getResponseStatus(), is(Status.OK));

getResponse = transResource.getTranslations("my.txt", de_DE, null, false);
assertThat(getResponse.getResponseStatus(), is(Status.NOT_FOUND));
assertThat(getResponse.getResponseStatus(), is(Status.OK));
}

@Test
Expand Down

0 comments on commit 4e3a402

Please sign in to comment.