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

Commit

Permalink
rhbz953734 - search all places that uses ContentState.Approved and ma…
Browse files Browse the repository at this point in the history
…rk work needs to be done
  • Loading branch information
Patrick Huang committed May 22, 2013
1 parent 283b242 commit 287c410
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 27 deletions.
8 changes: 4 additions & 4 deletions zanata-war/src/main/java/org/zanata/dao/DocumentDAO.java
Expand Up @@ -186,7 +186,7 @@ public CommonContainerTranslationStatistics getStatistics(long docId, LocaleId l
{
unitCount.set(count.status, count.count.intValue());
}
int newCount = totalCount.intValue() - unitCount.get(ContentState.Approved) - unitCount.get(ContentState.NeedReview);
int newCount = totalCount.intValue() - unitCount.get(ContentState.Approved) - unitCount.get(ContentState.NeedReview) - unitCount.get(ContentState.Translated) - unitCount.get(ContentState.Rejected);
unitCount.set(ContentState.New, newCount);

// calculate word counts
Expand All @@ -208,7 +208,7 @@ public CommonContainerTranslationStatistics getStatistics(long docId, LocaleId l
{
wordCount.set(count.status, count.count.intValue());
}
long newWordCount = totalWordCount.longValue() - wordCount.get(ContentState.Approved) - wordCount.get(ContentState.NeedReview);
long newWordCount = totalWordCount.longValue() - wordCount.get(ContentState.Approved) - wordCount.get(ContentState.NeedReview) - wordCount.get(ContentState.Translated) - wordCount.get(ContentState.Rejected);
wordCount.set(ContentState.New, (int) newWordCount);


Expand Down Expand Up @@ -301,12 +301,12 @@ public Map<LocaleId, CommonContainerTranslationStatistics> getStatistics(long do
Long totalWordCount = (Long)totalCounts.get("wordCount");
for( TransUnitCount stat : transUnitCountMap.values() )
{
int newCount = totalCount.intValue() - stat.get(ContentState.Approved) - stat.get(ContentState.NeedReview);
int newCount = totalCount.intValue() - stat.get(ContentState.Approved) - stat.get(ContentState.NeedReview) - stat.get(ContentState.Translated) - stat.get(ContentState.Rejected);
stat.set(ContentState.New, newCount);
}
for( TransUnitWords stat : transUnitWordsMap.values() )
{
int newCount = totalWordCount.intValue() - stat.get(ContentState.Approved) - stat.get(ContentState.NeedReview);
int newCount = totalWordCount.intValue() - stat.get(ContentState.Approved) - stat.get(ContentState.NeedReview) - stat.get(ContentState.Translated) - stat.get(ContentState.Rejected);
stat.set(ContentState.New, newCount);
}

Expand Down
Expand Up @@ -971,6 +971,7 @@ else if (FILETYPE_TRANSLATED_APPROVED.equals(fileType) || FILETYPE_TRANSLATED_AP
boolean useFuzzy = FILETYPE_TRANSLATED_APPROVED_AND_FUZZY.equals(fileType);
for (TextFlowTarget target : transRes.getTextFlowTargets())
{
// FIXME rhbz953734 - should it include translated state?
if (target.getState() == ContentState.Approved || (useFuzzy && target.getState() == ContentState.NeedReview))
{
translations.put(target.getResId(), target);
Expand Down
Expand Up @@ -171,6 +171,7 @@ boolean transferFromTextFlows(List<TextFlow> from, HDocument to, Set<String> ena
for (HTextFlowTarget targ : textFlow.getTargets().values())
{
// if (targ.getState() != ContentState.New)
// TODO rhbz953734 - what happens if it's Translated state
if (targ.getState() == ContentState.Approved)
{
targ.setState(ContentState.NeedReview);
Expand Down
Expand Up @@ -49,6 +49,7 @@ public class FilterConstraints
private boolean includeFuzzy;
private boolean includeApproved;

//TODO rhbz953734 - need to consider other content state??
private FilterConstraints(String searchString, boolean caseSensitive, boolean searchInSource, boolean searchInTarget, boolean includeNew, boolean includeFuzzy, boolean includeApproved)
{
this.searchString = searchString;
Expand Down
Expand Up @@ -429,7 +429,7 @@ private static boolean shouldOverwrite(HTextFlowTarget currentlyStored, ContentS
{
if( currentlyStored != null )
{
if( currentlyStored.getState() == NeedReview && matchState == Approved )
if( ContentState.isDraft(currentlyStored.getState()) && matchState == Approved )
{
return true; // If it's fuzzy, replace only with approved ones
}
Expand Down
Expand Up @@ -325,7 +325,7 @@ private List<HTextFlow> findTextFlowsWithHibernateSearch(String projectSlug, Str
for (HTextFlowTarget htft : matchedTargets)
{
// manually check for case sensitive matches
if( !constraints.isCaseSensitive() || (constraints.isCaseSensitive() && contentIsValid(htft.getContents(), constraints)) )
if(!constraints.isCaseSensitive() || (contentIsValid(htft.getContents(), constraints)))
{
if (!htft.getTextFlow().getDocument().isObsolete())
{
Expand Down Expand Up @@ -381,7 +381,7 @@ private List<HTextFlow> findTextFlowsWithHibernateSearch(String projectSlug, Str
if (!resultList.contains(htf))
{
// manually check for case sensitive matches
if( !constraints.isCaseSensitive() || (constraints.isCaseSensitive() && contentIsValid(htf.getContents(), constraints)) )
if(!constraints.isCaseSensitive() || (contentIsValid(htf.getContents(), constraints)))
{
if (!htf.getDocument().isObsolete())
{
Expand All @@ -405,21 +405,6 @@ public List<HTextFlow> findTextFlows(WorkspaceId workspace, DocumentId doc, Filt
return this.findTextFlows(workspace, documentPaths, constraints);
}

private static boolean isContentStateValid(HTextFlowTarget hTextFlowTarget, FilterConstraints constraints)
{
if (hTextFlowTarget == null)
{
return constraints.isIncludeNew();
}
else
{
ContentState state = hTextFlowTarget.getState();
return (constraints.isIncludeApproved() && state == ContentState.Approved) ||
(constraints.isIncludeFuzzy() && state == ContentState.NeedReview) ||
(constraints.isIncludeNew() && state == ContentState.New);
}
}

private static boolean contentIsValid(Collection<String> contents, FilterConstraints constraints)
{
boolean valid = false;
Expand Down
Expand Up @@ -147,7 +147,7 @@ public void onTranslationStateChange(Long textFlowId, ContentState newState)
TermDocs termDocs = reader.termDocs(term);
while( termDocs.next() ) // Should only be one
{
if (newState == ContentState.Approved)
if (ContentState.isTranslated(newState))
{
log.debug("Marking TextFlow {} as translated in locale {}", textFlowId, locale);
docIdSet.set(termDocs.doc());
Expand Down
Expand Up @@ -181,6 +181,7 @@ private org.apache.lucene.search.Query generateQuery(TransMemoryQuery query, Loc
if (useTargetIndex)
{
TermQuery localeQuery = new TermQuery(new Term(IndexFieldLabels.LOCALE_ID_FIELD, targetLocale.getId()));
// FIXME rhbz953734 - we may also want to include Translated state
TermQuery stateQuery = new TermQuery(new Term(IndexFieldLabels.CONTENT_STATE_FIELD, ContentState.Approved.toString()));

BooleanQuery targetQuery = new BooleanQuery();
Expand Down
Expand Up @@ -536,6 +536,7 @@ protected Boolean work() throws Exception
targetChanged |= resourceUtils.transferFromTextFlowTarget(incomingTarget, hTarget);
targetChanged |= resourceUtils.transferFromTextFlowTargetExtensions(incomingTarget.getExtensions(true), hTarget, extensions);
}
// TODO rhbz953734 - This is coming from client push?? Assuming they are all approved all the time?
else if (incomingTarget.getState() == ContentState.Approved)
{
List<String> incomingContents = incomingTarget.getContents();
Expand Down
Expand Up @@ -200,7 +200,6 @@ private void invalidateDocLastTranslatedCache(Long documentId, LocaleId localeId

private void updateTranslatedTextFlowCache(Long textFlowId, LocaleId localeId, ContentState newState)
{
// TODO rhbz953734 - need to cater new review state
OpenBitSet bitSet = translatedTextFlowCache.get(localeId);
if (bitSet != null)
{
Expand Down
Expand Up @@ -6,6 +6,7 @@
import javax.annotation.Nullable;

import org.zanata.common.ContentState;
import org.zanata.common.util.ContentStateUtil;
import org.zanata.webtrans.shared.model.TransUnitId;

import com.google.common.base.Predicate;
Expand Down Expand Up @@ -95,11 +96,13 @@ public boolean apply(@Nullable
}
}));

// return ContentStateUtil.determineState(requestedState, newContents);
// TODO use ContentStateUtil.determineState.
// ContentState stateToSet =
// ContentStateUtil.determineState(requestedState, newContents);

// NB until then, make sure this stays consistent
// FIXME rhbz953734 - this is not consistent right now and it's duplicating from TransUnitSaveEvent
ContentState stateToSet = requestedState;
if (requestedState == ContentState.New && emptyCount == 0)
{
Expand Down
Expand Up @@ -140,6 +140,7 @@ public boolean apply(@Nullable String input)
// ContentState stateToSet = ContentStateUtil.determineState(requestedState, newContents);

// NB until then, make sure this stays consistent
// FIXME rhbz953734 - this is not consistent right now
ContentState stateToSet = requestedState;
if (requestedState == ContentState.New && emptyCount == 0)
{
Expand Down
Expand Up @@ -282,7 +282,7 @@ public void checkConfirmationBeforeSave()
TransUnitId transUnitId = getCurrentTransUnitIdOrNull();
if (userOptionsService.getConfigHolder().getState().isShowSaveApprovedWarning())
{
eventBus.fireEvent(new CheckStateHasChangedEvent(transUnitId, getNewTargets(), ContentState.Approved));
eventBus.fireEvent(new CheckStateHasChangedEvent(transUnitId, getNewTargets(), ContentState.Translated));
}
else
{
Expand Down
Expand Up @@ -140,7 +140,7 @@ public void onCheckStateHasChanged(CheckStateHasChangedEvent event)
}

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

if (targetChanged)
{
Expand Down Expand Up @@ -169,7 +169,7 @@ private boolean stateHasNotChanged(TransUnitSaveEvent event)

private TransUnitUpdated.UpdateType workoutUpdateType(ContentState status)
{
return status == ContentState.Approved ? TransUnitUpdated.UpdateType.WebEditorSave : TransUnitUpdated.UpdateType.WebEditorSaveFuzzy;
return status == ContentState.NeedReview ? TransUnitUpdated.UpdateType.WebEditorSaveFuzzy : TransUnitUpdated.UpdateType.WebEditorSave;
}

private class UpdateTransUnitCallback implements AsyncCallback<UpdateTransUnitResult>
Expand Down
Expand Up @@ -279,6 +279,7 @@ public TransUnitReplaceInfo getValue(TransUnitReplaceInfo info)
@Override
public String getCellStyleNames(Context context, TransUnitReplaceInfo info)
{
// TODO rhbz953734 - new states
String styleNames = Strings.nullToEmpty(super.getCellStyleNames(context, info));
if (info.getTransUnit().getStatus() == ContentState.Approved)
{
Expand Down
Expand Up @@ -256,6 +256,7 @@ public List<String> getValue(TransHistoryItem historyItem)
public String getCellStyleNames(Cell.Context context, TransHistoryItem historyItem)
{
String styleNames = Strings.nullToEmpty(super.getCellStyleNames(context, historyItem));
// TODO rhbz953734 - new states
if (historyItem.getStatus() == ContentState.Approved)
{
styleNames += " ApprovedStateDecoration";
Expand Down
Expand Up @@ -86,6 +86,7 @@ else if (needReview)
}
return ContentState.NeedReview;
}
// TODO rhbz953734 - we will need to decide. Gut feeling this will change to Translated (gets auto promoted to Approved in non-reviewable project)
return ContentState.Approved;
}

Expand Down

0 comments on commit 287c410

Please sign in to comment.