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

Commit

Permalink
Merge branch 'integration/master' into rhbz786630
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Apr 18, 2013
2 parents 3a4a39b + 228a526 commit 30085fe
Show file tree
Hide file tree
Showing 96 changed files with 1,628 additions and 1,112 deletions.
11 changes: 11 additions & 0 deletions zanata-war/pom.xml
Expand Up @@ -52,6 +52,17 @@
</resources>

<plugins>
<plugin>
<groupId>org.zanata</groupId>
<artifactId>zanata-maven-plugin</artifactId>
<version>2.2.0</version>
<configuration>
<srcDir>src</srcDir>
<transDir>src</transDir>
<!-- only one translation file has been prepared so far -->
<includes>main/resources/messages.properties</includes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
Expand Down
Expand Up @@ -135,6 +135,7 @@ public void joinTribe()
languageTeamServiceImpl.joinLanguageTeam(this.language, authenticatedAccount.getPerson().getId());
Events.instance().raiseEvent("personJoinedTribe");
log.info("{0} joined tribe {1}", authenticatedAccount.getUsername(), this.language);
// FIXME use localizable string
FacesMessages.instance().add("You are now a member of the {0} language team", getLocale().retrieveNativeName());
}
catch (Exception e)
Expand Down
Expand Up @@ -494,9 +494,20 @@ public void setLocaleId(String localeId)
this.localeId = localeId;
}

public boolean isPoProject()
public boolean isKnownProjectType()
{
ProjectType type = projectIterationDAO.getBySlug(projectSlug, iterationSlug).getProjectType();
return type != null;
}

public boolean isPoProject()
{
HProjectIteration projectIteration = projectIterationDAO.getBySlug(projectSlug, iterationSlug);
ProjectType type = projectIteration.getProjectType();
if (type == null)
{
type = projectIteration.getProject().getDefaultProjectType();
}
return type == ProjectType.Gettext || type == ProjectType.Podir;
}

Expand Down
2 changes: 1 addition & 1 deletion zanata-war/src/main/java/org/zanata/action/UserAction.java
Expand Up @@ -148,7 +148,7 @@ public String save()
}
else
{
FacesMessages.instance().addToControl("username", "Username '" + getUsername() + "' is not available");
FacesMessages.instance().addToControl("username", messages.get("jsf.UsernameNotAvailable"));
setUsername(originalUsername); // reset the username field
return "failure";
}
Expand Down
Expand Up @@ -400,6 +400,9 @@ public String getCopyTransEstimatedTimeLeft()
return formatTimePeriod(handle.getEstimatedTimeRemaining());
}

// FIXME this is not localizable
// Define 4 UI strings: completed by you, canceled by you, completed by [username], canceled by [username]
// OR define UI strings for each of completed/canceled, and another for 'you'
public String getCopyTransStatusMessage()
{
if (!isCopyTransRunning())
Expand Down Expand Up @@ -524,6 +527,10 @@ public void setStatsOption(StatUnit statsOption)
public boolean isPoProject()
{
ProjectType type = getProjectIteration().getProjectType();
if (type == null)
{
type = getProjectIteration().getProject().getDefaultProjectType();
}
return type == ProjectType.Gettext || type == ProjectType.Podir;
}
}
7 changes: 4 additions & 3 deletions zanata-war/src/main/java/org/zanata/dao/DocumentDAO.java
Expand Up @@ -24,6 +24,7 @@
import org.zanata.model.HLocale;
import org.zanata.model.HProjectIteration;
import org.zanata.model.HRawDocument;
import org.zanata.model.HTextFlowTarget;
import org.zanata.model.StatusCount;

@Name("documentDAO")
Expand Down Expand Up @@ -138,18 +139,18 @@ public Long getTotalWordCountForDocument(HDocument document)

}

public Long getLastTranslatedTargetId(Long documentId, LocaleId localeId)
public HTextFlowTarget getLastTranslatedTarget(Long documentId, LocaleId localeId)
{
Session session = getSession();

StringBuilder query = new StringBuilder();

query.append("select tft.id from HTextFlowTarget tft ");
query.append("from HTextFlowTarget tft ");
query.append("where tft.textFlow.document.id = :docId ");
query.append("and tft.locale.localeId = :localeId ");
query.append("order by tft.lastChanged DESC");

return (Long) session.createQuery(query.toString())
return (HTextFlowTarget) session.createQuery(query.toString())
.setParameter("docId", documentId)
.setParameter("localeId", localeId)
.setCacheable(true)
Expand Down
12 changes: 9 additions & 3 deletions zanata-war/src/main/java/org/zanata/dao/TextFlowTargetDAO.java
Expand Up @@ -281,18 +281,24 @@ public HTextFlowTarget getTextFlowTarget(HTextFlow hTextFlow, HLocale hLocale)
return hTextFlowTarget;
}

public HTextFlowTarget getTextFlowTarget(HTextFlow hTextFlow, LocaleId localeId)
public HTextFlowTarget getTextFlowTarget(Long hTextFlowId, LocaleId localeId)
{
HTextFlowTarget hTextFlowTarget =
(HTextFlowTarget)getSession().createQuery(
"select tft from HTextFlowTarget tft where tft.textFlow = :textFlow and tft.locale.localeId = :localeId")
.setParameter("textFlow", hTextFlow)
"select tft from HTextFlowTarget tft where tft.textFlow.id = :hTextFlowId and tft.locale.localeId = :localeId")
.setParameter("hTextFlowId", hTextFlowId)
.setParameter("localeId", localeId)
.setComment("TextFlowTargetDAO.getTextFlowTarget")
.uniqueResult();
return hTextFlowTarget;
}

public HTextFlowTarget getTextFlowTarget(HTextFlow hTextFlow, LocaleId localeId)
{
HTextFlowTarget hTextFlowTarget = (HTextFlowTarget) getSession().createQuery("select tft from HTextFlowTarget tft where tft.textFlow = :textFlow and tft.locale.localeId = :localeId").setParameter("textFlow", hTextFlow).setParameter("localeId", localeId).setComment("TextFlowTargetDAO.getTextFlowTarget").uniqueResult();
return hTextFlowTarget;
}

public Long getTextFlowTargetId(HTextFlow hTextFlow, LocaleId localeId)
{
Query q = getSession().createQuery("select tft.id from HTextFlowTarget tft where tft.textFlow = :textFlow and tft.locale.localeId = :localeId");
Expand Down
Expand Up @@ -145,7 +145,8 @@ public interface TranslationFileService
String extractExtension(String fileNameOrExtension);

/**
* @return true if the specified document is of type po
* @return true if the specified document is of type po, false if it is any other
* type, including null.
*/
boolean isPoDocument(String projectSlug, String iterationSlug, String docId);

Expand Down
Expand Up @@ -24,6 +24,7 @@
import org.apache.lucene.util.OpenBitSet;
import org.zanata.common.ContentState;
import org.zanata.common.LocaleId;
import org.zanata.webtrans.shared.model.DocumentStatus;
import org.zanata.webtrans.shared.model.ValidationId;

/**
Expand Down Expand Up @@ -65,12 +66,14 @@ public interface TranslationStateCache
void textFlowStateUpdated(Long textFlowId, LocaleId localeId, ContentState newState);

/**
* Returns last modified HTextFlowTarget for the given locale id of the documentId
* Returns DocumentStatus of last modified HTextFlowTarget for the given
* locale id of the documentId
*
* @param documentId
* @param localeId
* @return
*/
Long getDocLastTranslatedTextFlowTarget(Long documentId, LocaleId localeId);
DocumentStatus getDocStats(Long documentId, LocaleId localeId);

/**
* Return boolean of textFlowTarget has validation error against validation
Expand Down
Expand Up @@ -58,11 +58,13 @@ public interface ValidationService
*
* Returns count of transUnit that has error
*
* @param validationIds
*
* @param hDocs
* @param validations
* @param localeId
*/
boolean runValidations(HDocument hDoc, List<ValidationId> validationIds, LocaleId localeId);
boolean runDocValidations(Long hDocId, List<ValidationId> validationIds, LocaleId localeId);

/**
* Filter list of text flow with those only contains validation error
Expand All @@ -73,4 +75,17 @@ public interface ValidationService
* @throws IOException
*/
List<HTextFlow> filterHasErrorTexFlow(List<HTextFlow> textFlows, List<ValidationId> validationIds, LocaleId localeId, int startIndex, int maxSize);


/**
* Run validation check on HTextFlow and HTextFlowTarget with specific locale
* from HDocument against validations rules defined in version
*
* Returns count of transUnit that has error
*
* @param hDocs
* @param validations
* @param localeId
*/
boolean runDocValidationsWithServerRules(HDocument hDoc, LocaleId localeId);
}
Expand Up @@ -88,6 +88,7 @@ public String getConfigurationFileContents(String projectSlug, String iterationS
var.append(" <project-version>").append(iterationSlug).append("</project-version>\n");
if (useOfflinePo)
{
// FIXME this comment could be localized
var.append(" <!-- NB project-type set to 'offlinepo' to allow offline po translation\n")
.append(" from non-po documents, project-type on server is '")
.append(String.valueOf(projectType).toLowerCase()).append("' -->\n")
Expand All @@ -97,6 +98,7 @@ else if ( projectType != null )
{
if( projectType == ProjectType.Gettext )
{
// FIXME this comment could be localized
var.append(" <!-- NB project-type set to 'podir' to allow uploads, but original was 'gettext' -->\n");
var.append(" <project-type>").append(ProjectType.Podir.toString().toLowerCase()).append("</project-type>\n");
}
Expand Down
Expand Up @@ -83,9 +83,8 @@ public String sendActivationEmail(String emailTemplate, String toName, String to

log.info("Sent activation account email: toName '{0}', toEmailAddress '{1}'", toName, toEmailAddr);
return "#{messages['jsf.Account.ActivationMessage']}";

}

@Override
public String sendToLanguageCoordinators(String emailTemplate, List<HPerson> coordinators, String fromName, String fromLoginName, String replyEmail, String subject, String message, String language)
{
Expand Down Expand Up @@ -206,7 +205,7 @@ public String getReceivedReason()
{
return receivedReason;
}

public String getActivationKey()
{
return activationKey;
Expand Down
Expand Up @@ -21,13 +21,15 @@
package org.zanata.service.impl;

import java.net.URI;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.apache.commons.lang.StringUtils;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
Expand All @@ -53,6 +55,7 @@
import org.zanata.rest.service.ZPathService;
import org.zanata.service.TranslationStateCache;
import org.zanata.util.DateUtil;
import org.zanata.webtrans.shared.model.DocumentStatus;

/**
* Default implementation for the
Expand Down Expand Up @@ -143,7 +146,19 @@ public ContainerTranslationStatistics getStatistics(String projectSlug, String i

HTextFlowTarget target = localeServiceImpl.getLastTranslated(projectSlug, iterationSlug, locId);

TranslationStatistics transUnitStats = getMessageStats(count, locId, target);
String lastModifiedBy = "";
Date lastModifiedDate = null;

if (target != null)
{
lastModifiedDate = target.getLastChanged();
if (target.getLastModifiedBy() != null)
{
lastModifiedBy = target.getLastModifiedBy().getAccount().getUsername();
}
}

TranslationStatistics transUnitStats = getMessageStats(count, locId, lastModifiedDate, lastModifiedBy);
transUnitStats.setRemainingHours(getRemainingHours(count.get(ContentState.NeedReview), count.get(ContentState.New)));
iterationStats.addStats(transUnitStats);

Expand All @@ -156,7 +171,7 @@ public ContainerTranslationStatistics getStatistics(String projectSlug, String i
wordCount = new TransUnitWords(0, 0, (int) iterationTotalWords);
}

TranslationStatistics wordsStats = getWordsStats(wordCount, locId, target);
TranslationStatistics wordsStats = getWordsStats(wordCount, locId, lastModifiedDate, lastModifiedBy);
wordsStats.setRemainingHours(getRemainingHours(wordCount.get(ContentState.NeedReview), wordCount.get(ContentState.New)));
iterationStats.addStats(wordsStats);
}
Expand Down Expand Up @@ -234,15 +249,9 @@ public ContainerTranslationStatistics getStatistics(String projectSlug, String i
{
count = stats.getUnitCount();
}
Long id = translationStateCacheImpl.getDocLastTranslatedTextFlowTarget(document.getId(), locale);
HTextFlowTarget target = null;

if (id != null)
{
target = textFlowTargetDAO.findById(id, false);
}
DocumentStatus docStat = translationStateCacheImpl.getDocStats(document.getId(), locale);

TranslationStatistics transUnitStats = getMessageStats(count, locale, target);
TranslationStatistics transUnitStats = getMessageStats(count, locale, docStat.getLastTranslatedDate(), docStat.getLastTranslatedBy());
transUnitStats.setRemainingHours(getRemainingHours(count.get(ContentState.NeedReview), count.get(ContentState.New)));
docStats.addStats(transUnitStats);

Expand All @@ -258,7 +267,7 @@ public ContainerTranslationStatistics getStatistics(String projectSlug, String i
{
wordCount = stats.getWordCount();
}
TranslationStatistics wordsStats = getWordsStats(wordCount, locale, target);
TranslationStatistics wordsStats = getWordsStats(wordCount, locale, docStat.getLastTranslatedDate(), docStat.getLastTranslatedBy());
wordsStats.setRemainingHours(getRemainingHours(wordCount.get(ContentState.NeedReview), wordCount.get(ContentState.New)));
docStats.addStats(wordsStats);
}
Expand All @@ -267,7 +276,7 @@ public ContainerTranslationStatistics getStatistics(String projectSlug, String i
return docStats;
}

private TranslationStatistics getWordsStats(TransUnitWords wordCount, LocaleId locale, HTextFlowTarget lastTranslatedTarget)
private TranslationStatistics getWordsStats(TransUnitWords wordCount, LocaleId locale, Date lastChanged, String lastModifiedBy)
{
TranslationStatistics stats = new TranslationStatistics();
stats.setLocale(locale.getId());
Expand All @@ -276,11 +285,11 @@ private TranslationStatistics getWordsStats(TransUnitWords wordCount, LocaleId l
stats.setUntranslated(wordCount.get(ContentState.New));
stats.setNeedReview(wordCount.get(ContentState.NeedReview));
stats.setTotal(wordCount.getTotal());
stats.setLastTranslated(getLastTranslated(lastTranslatedTarget));
stats.setLastTranslated(getLastTranslated(lastChanged, lastModifiedBy));
return stats;
}

private TranslationStatistics getMessageStats(TransUnitCount unitCount, LocaleId locale, HTextFlowTarget lastTranslatedTarget)
private TranslationStatistics getMessageStats(TransUnitCount unitCount, LocaleId locale, Date lastChanged, String lastModifiedBy)
{
TranslationStatistics stats = new TranslationStatistics();
stats.setLocale(locale.getId());
Expand All @@ -290,25 +299,24 @@ private TranslationStatistics getMessageStats(TransUnitCount unitCount, LocaleId
stats.setNeedReview(unitCount.get(ContentState.NeedReview));
stats.setTotal(unitCount.getTotal());

stats.setLastTranslated(getLastTranslated(lastTranslatedTarget));
stats.setLastTranslated(getLastTranslated(lastChanged, lastModifiedBy));
return stats;
}

private String getLastTranslated(HTextFlowTarget lastTranslatedTarget)
private String getLastTranslated(Date lastChanged, String lastModifiedBy)
{
StringBuilder result = new StringBuilder();

if (lastTranslatedTarget != null)
if (lastChanged != null)
{
result.append(DateUtil.formatShortDate(lastTranslatedTarget.getLastChanged()));
result.append(DateUtil.formatShortDate(lastChanged));

if (lastTranslatedTarget.getLastModifiedBy() != null)
if (!StringUtils.isEmpty(lastModifiedBy))
{
result.append(" by ");
result.append(lastTranslatedTarget.getLastModifiedBy().getAccount().getUsername());
result.append(lastModifiedBy);
}
}

return result.toString();
}

Expand Down
Expand Up @@ -396,6 +396,10 @@ public boolean isPoDocument(String projectSlug, String iterationSlug, String doc
{
HProjectIteration projectIteration = projectIterationDAO.getBySlug(projectSlug, iterationSlug);
ProjectType projectType = projectIteration.getProjectType();
if (projectType == null)
{
projectType = projectIteration.getProject().getDefaultProjectType();
}
if (projectType == ProjectType.Gettext || projectType == ProjectType.Podir)
{
return true;
Expand Down

0 comments on commit 30085fe

Please sign in to comment.