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

Commit

Permalink
Rename ActiveStates to ContentStateGroup, rename methods and move to …
Browse files Browse the repository at this point in the history
…gwt shared.

    Move to gwt includes a few minor changes to allow gwt-rpc serialization.
  • Loading branch information
davidmason committed Jul 10, 2013
1 parent 03e6f63 commit 33e5375
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 201 deletions.
10 changes: 5 additions & 5 deletions zanata-war/src/main/java/org/zanata/dao/TextFlowDAO.java
Expand Up @@ -41,9 +41,9 @@
import org.zanata.model.HDocument;
import org.zanata.model.HLocale;
import org.zanata.model.HTextFlow;
import org.zanata.search.ActiveStates;
import org.zanata.search.FilterConstraintToQuery;
import org.zanata.search.FilterConstraints;
import org.zanata.webtrans.shared.model.ContentStateGroup;
import org.zanata.webtrans.shared.model.DocumentId;

import com.google.common.base.Joiner;
Expand Down Expand Up @@ -172,7 +172,7 @@ public List<HTextFlow> getNavigationByDocumentId(Long documentId, HLocale hLocal
protected static String buildContentStateCondition(FilterConstraints constraints, String alias)
{

ActiveStates includedStates = constraints.getIncludedStates();
ContentStateGroup includedStates = constraints.getIncludedStates();
if (includedStates.hasAllStates() || includedStates.hasNoStates())
{
return "1";
Expand All @@ -181,17 +181,17 @@ protected static String buildContentStateCondition(FilterConstraints constraints
builder.append("(");
List<String> conditions = Lists.newArrayList();
final String column = alias + ".state";
if (constraints.getIncludedStates().isTranslatedOn())
if (constraints.getIncludedStates().hasTranslated())
{
conditions.add(column + "=2"); // Translated
conditions.add(column + "=3"); // Approved
}
if (constraints.getIncludedStates().isFuzzyOn())
if (constraints.getIncludedStates().hasFuzzy())
{
conditions.add(column + "=1"); // Fuzzy
conditions.add(column + "=4"); // Rejected
}
if (constraints.getIncludedStates().isNewOn())
if (constraints.getIncludedStates().hasNew())
{
conditions.add(column + "=0 or " + column + " is null");
}
Expand Down
146 changes: 0 additions & 146 deletions zanata-war/src/main/java/org/zanata/search/ActiveStates.java

This file was deleted.

Expand Up @@ -148,7 +148,7 @@ protected String buildStateCondition()

String stateInListWhereClause = and(textFlowAndLocaleRestriction.toString(), String.format("state in (%s)", STATE_LIST_PLACEHOLDER));
String stateInListCondition = QueryBuilder.exists().from("HTextFlowTarget").where(stateInListWhereClause).toQueryString();
if (constraints.getIncludedStates().isNewOn())
if (constraints.getIncludedStates().hasNew())
{
String nullTargetCondition = String.format("%s not in indices(tf.targets)", LOCALE_PLACEHOLDER);
if (hasSearch && constraints.isSearchInSource())
Expand Down
38 changes: 20 additions & 18 deletions zanata-war/src/main/java/org/zanata/search/FilterConstraints.java
Expand Up @@ -23,6 +23,8 @@
//TODO May want to add document(someDocument) to these constraints
//so that only one search method is needed on the interface.

import org.zanata.webtrans.shared.model.ContentStateGroup;

import lombok.Getter;

import com.google.common.base.Objects;
Expand All @@ -39,11 +41,11 @@ public class FilterConstraints
private boolean isCaseSensitive;
private boolean searchInSource;
private boolean searchInTarget;
private ActiveStates includedStates;
private ContentStateGroup includedStates;

private FilterConstraints(String searchString, boolean caseSensitive,
boolean searchInSource, boolean searchInTarget,
ActiveStates includedStates)
ContentStateGroup includedStates)
{
this.searchString = searchString;
this.isCaseSensitive = caseSensitive;
Expand Down Expand Up @@ -77,11 +79,11 @@ public static class Builder
private boolean caseSensitive;
private boolean searchInSource;
private boolean searchInTarget;
private ActiveStates.Builder states;
private ContentStateGroup.Builder states;

public Builder()
{
states = ActiveStates.builder();
states = ContentStateGroup.builder();
setKeepAll();
}

Expand All @@ -103,7 +105,7 @@ private void setKeepAll()
caseSensitive = false;
searchInSource = true;
searchInTarget = true;
states.allOn();
states.addAll();
}

public Builder keepNone()
Expand All @@ -112,7 +114,7 @@ public Builder keepNone()
caseSensitive = false;
searchInSource = false;
searchInTarget = false;
states.allOff();
states.removeAll();
return this;
}

Expand Down Expand Up @@ -140,15 +142,15 @@ public Builder checkInTarget(boolean check)
return this;
}

public Builder includeStates(ActiveStates states)
public Builder includeStates(ContentStateGroup states)
{
//FIXME this behaviour is too surprising.
// It exists because the editor UI should show all states when either
// all or none of the states are checked. This logic should just happen
// in the editor backend *before* sending a request to the server.
if (states.hasNoStates())
{
this.states.allOn();
this.states.addAll();
}
else
{
Expand All @@ -159,61 +161,61 @@ public Builder includeStates(ActiveStates states)

public Builder includeNew()
{
states.setNewOn(true);
states.includeNew(true);
return this;
}

public Builder excludeNew()
{
states.setNewOn(false);
states.includeNew(false);
return this;
}

public Builder includeFuzzy()
{
states.setFuzzyOn(true);
states.includeFuzzy(true);
return this;
}

public Builder excludeFuzzy()
{
states.setFuzzyOn(false);
states.includeFuzzy(false);
return this;
}

public Builder includeTranslated()
{
states.setTranslatedOn(true);
states.includeTranslated(true);
return this;
}

public Builder excludeTranslated()
{
states.setTranslatedOn(false);
states.includeTranslated(false);
return this;
}

public Builder includeApproved()
{
states.setApprovedOn(true);
states.includeApproved(true);
return this;
}

public Builder excludeApproved()
{
states.setApprovedOn(false);
states.includeApproved(false);
return this;
}

public Builder includeRejected()
{
states.setRejectedOn(true);
states.includeRejected(true);
return this;
}

public Builder excludeRejected()
{
states.setRejectedOn(false);
states.includeRejected(false);
return this;
}

Expand Down
Expand Up @@ -57,11 +57,11 @@
import org.zanata.model.HProjectIteration;
import org.zanata.model.HTextFlow;
import org.zanata.model.HTextFlowTarget;
import org.zanata.search.ActiveStates;
import org.zanata.search.FilterConstraintToQuery;
import org.zanata.search.FilterConstraints;
import org.zanata.service.LocaleService;
import org.zanata.service.TextFlowSearchService;
import org.zanata.webtrans.shared.model.ContentStateGroup;
import org.zanata.webtrans.shared.model.DocumentId;
import org.zanata.webtrans.shared.model.WorkspaceId;

Expand Down Expand Up @@ -140,8 +140,10 @@ private List<HTextFlow> findTextFlowsByDocumentPaths(WorkspaceId workspace, List
return Collections.emptyList();
}

ActiveStates includedStates = constraints.getIncludedStates();
if (!includedStates.isNewOn() && !includedStates.isFuzzyOn() && !includedStates.isTranslatedOn())
// FIXME this looks like it assumes only 3 states and would not work properly for getting
// e.g. only approved strings while there is a search active.
ContentStateGroup includedStates = constraints.getIncludedStates();
if (!includedStates.hasNew() && !includedStates.hasFuzzy() && !includedStates.hasTranslated())
{
// including nothing
return Collections.emptyList();
Expand Down Expand Up @@ -300,19 +302,19 @@ private List<HTextFlow> findTextFlowsWithHibernateSearch(String projectSlug, Str
}
targetQuery.add(localeQuery, Occur.MUST);

if (!constraints.getIncludedStates().isTranslatedOn())
if (!constraints.getIncludedStates().hasTranslated())
{
TermQuery approvedStateQuery = new TermQuery(new Term(IndexFieldLabels.CONTENT_STATE_FIELD, ContentState.Approved.toString()));
targetQuery.add(approvedStateQuery, Occur.MUST_NOT);
}

if (!constraints.getIncludedStates().isFuzzyOn())
if (!constraints.getIncludedStates().hasFuzzy())
{
TermQuery approvedStateQuery = new TermQuery(new Term(IndexFieldLabels.CONTENT_STATE_FIELD, ContentState.NeedReview.toString()));
targetQuery.add(approvedStateQuery, Occur.MUST_NOT);
}

if (!constraints.getIncludedStates().isNewOn())
if (!constraints.getIncludedStates().hasNew())
{
TermQuery approvedStateQuery = new TermQuery(new Term(IndexFieldLabels.CONTENT_STATE_FIELD, ContentState.New.toString()));
targetQuery.add(approvedStateQuery, Occur.MUST_NOT);
Expand Down

0 comments on commit 33e5375

Please sign in to comment.