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

Commit

Permalink
Refactor names, comments and method
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Nov 19, 2013
1 parent fcba5dd commit 7da486b
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 145 deletions.
29 changes: 16 additions & 13 deletions zanata-war/src/main/java/org/zanata/action/SortingType.java
Expand Up @@ -4,7 +4,6 @@
import java.util.List;

import lombok.Getter;
import lombok.Setter;

import com.google.common.collect.Lists;

Expand All @@ -13,31 +12,35 @@
*/
public class SortingType implements Serializable {

public static final String PERCENTAGE = "%";

public static final String HOURS = "hours";

public static final String WORDS = "words";

public static final String ALPHABETICAL = "alphabetical";

@Getter
private boolean descending = true;

@Getter
private String selectedSortOption = ALPHABETICAL;
private SortOption selectedSortOption = SortOption.ALPHABETICAL;

@Getter
private List<String> sortOptions = Lists.newArrayList();
private List<SortOption> sortOptions = Lists.newArrayList();

public SortingType(List<String> sortOptions) {
public SortingType(List<SortOption> sortOptions) {
this.sortOptions = sortOptions;
}

public void setSelectedSortOption(String selectedSortOption) {
public void setSelectedSortOption(SortOption selectedSortOption) {
if (this.selectedSortOption.equals(selectedSortOption)) {
descending = !descending;
}
this.selectedSortOption = selectedSortOption;
}

public enum SortOption {
PERCENTAGE("%"), HOURS("hours"), WORDS("words"), ALPHABETICAL(
"alphabetical");

@Getter
String display;

SortOption(String display) {
this.display = display;
}
}
}
Expand Up @@ -38,6 +38,7 @@
import org.jboss.seam.security.management.JpaIdentityStore;
import org.zanata.annotation.CachedMethodResult;
import org.zanata.common.LocaleId;
import org.zanata.dao.ProjectIterationDAO;
import org.zanata.dao.VersionGroupDAO;
import org.zanata.model.HAccount;
import org.zanata.model.HLocale;
Expand Down Expand Up @@ -73,6 +74,9 @@ public class VersionGroupHomeAction implements Serializable {
@In
private VersionGroupDAO versionGroupDAO;

@In
private ProjectIterationDAO projectIterationDAO;

@Getter
@Setter
private String slug;
Expand Down Expand Up @@ -101,13 +105,16 @@ public class VersionGroupHomeAction implements Serializable {

@Getter
private final SortingType languageSortingList = new SortingType(
Lists.newArrayList(SortingType.ALPHABETICAL, SortingType.HOURS,
SortingType.PERCENTAGE));
Lists.newArrayList(SortingType.SortOption.ALPHABETICAL,
SortingType.SortOption.HOURS,
SortingType.SortOption.PERCENTAGE));

@Getter
private SortingType projectSortingList = new SortingType(
Lists.newArrayList(SortingType.ALPHABETICAL, SortingType.HOURS,
SortingType.PERCENTAGE, SortingType.WORDS));
Lists.newArrayList(SortingType.SortOption.ALPHABETICAL,
SortingType.SortOption.HOURS,
SortingType.SortOption.PERCENTAGE,
SortingType.SortOption.WORDS));

private final LanguageComparator languageComparator =
new LanguageComparator(getLanguageSortingList());
Expand Down Expand Up @@ -141,19 +148,23 @@ public int compare(HLocale locale, HLocale locale2) {
item2 = locale;
}

String selectedSortOption = sortingType.getSelectedSortOption();
SortingType.SortOption selectedSortOption =
sortingType.getSelectedSortOption();

// Need to get statistic for comparison
if (!selectedSortOption.equals(SortingType.ALPHABETICAL)) {
if (!selectedSortOption.equals(SortingType.SortOption.ALPHABETICAL)) {
WordStatistic wordStatistic1 =
getStatisticForLocale(item1.getLocaleId());
getStatisticsForLocale(item1.getLocaleId());
WordStatistic wordStatistic2 =
getStatisticForLocale(item2.getLocaleId());
getStatisticsForLocale(item2.getLocaleId());

if (selectedSortOption.equals(SortingType.PERCENTAGE)) {
if (selectedSortOption
.equals(SortingType.SortOption.PERCENTAGE)) {
return Double.compare(
wordStatistic1.getPercentTranslated(),
wordStatistic2.getPercentTranslated());
} else if (selectedSortOption.equals(SortingType.HOURS)) {
} else if (selectedSortOption
.equals(SortingType.SortOption.HOURS)) {
return Double.compare(wordStatistic1.getRemainingHours(),
wordStatistic2.getRemainingHours());
}
Expand Down Expand Up @@ -184,24 +195,28 @@ public int compare(HProjectIteration locale, HProjectIteration locale2) {
item2 = locale;
}

String selectedSortOption = sortingType.getSelectedSortOption();
SortingType.SortOption selectedSortOption =
sortingType.getSelectedSortOption();
// Need to get statistic for comparison
if (!selectedSortOption.equals(SortingType.ALPHABETICAL)) {
if (!selectedSortOption.equals(SortingType.SortOption.ALPHABETICAL)) {
WordStatistic wordStatistic1 =
statisticMap.get(new VersionLocaleKey(item1.getId(),
selectedLocale.getLocaleId()));
WordStatistic wordStatistic2 =
statisticMap.get(new VersionLocaleKey(item2.getId(),
selectedLocale.getLocaleId()));

if (selectedSortOption.equals(SortingType.PERCENTAGE)) {
if (selectedSortOption
.equals(SortingType.SortOption.PERCENTAGE)) {
return Double.compare(
wordStatistic1.getPercentTranslated(),
wordStatistic2.getPercentTranslated());
} else if (selectedSortOption.equals(SortingType.HOURS)) {
} else if (selectedSortOption
.equals(SortingType.SortOption.HOURS)) {
return Double.compare(wordStatistic1.getRemainingHours(),
wordStatistic2.getRemainingHours());
} else if (selectedSortOption.equals(SortingType.WORDS)) {
} else if (selectedSortOption
.equals(SortingType.SortOption.WORDS)) {
if (wordStatistic1.getTotal() == wordStatistic2.getTotal()) {
return 0;
}
Expand Down Expand Up @@ -240,54 +255,56 @@ public List<HLocale> getActiveLocales() {
}

@CachedMethodResult
public String getStatisticFigureForLocale(String sortOption,
LocaleId localeId) {
WordStatistic statistic = getStatisticForLocale(localeId);
public String getStatisticFigureForLocale(
SortingType.SortOption sortOption, LocaleId localeId) {
WordStatistic statistic = getStatisticsForLocale(localeId);

return getStatisticFigure(sortOption, statistic);
}

@CachedMethodResult
public String getStatisticFigureForProjectWithLocale(String sortOption,
LocaleId localeId, Long projectIterationId) {
public String getStatisticFigureForProjectWithLocale(
SortingType.SortOption sortOption, LocaleId localeId,
Long projectIterationId) {
WordStatistic statistic =
statisticMap.get(new VersionLocaleKey(projectIterationId, localeId));
statisticMap.get(new VersionLocaleKey(projectIterationId,
localeId));

return getStatisticFigure(sortOption, statistic);
}

@CachedMethodResult
public String
getStatisticFigureForProject(String sortOption, Long projectIterationId) {
public String getStatisticFigureForProject(
SortingType.SortOption sortOption, Long projectIterationId) {
WordStatistic statistic = getStatisticForProject(projectIterationId);

return getStatisticFigure(sortOption, statistic);
}

private String
getStatisticFigure(String sortOption, WordStatistic statistic) {
if (sortOption.equals(SortingType.HOURS)) {
private String getStatisticFigure(SortingType.SortOption sortOption,
WordStatistic statistic) {
if (sortOption.equals(SortingType.SortOption.HOURS)) {
return StatisticsUtil.formatHours(statistic.getRemainingHours());
} else if (sortOption.equals(SortingType.WORDS)) {
} else if (sortOption.equals(SortingType.SortOption.WORDS)) {
return String.valueOf(statistic.getTotal());
} else {
return StatisticsUtil.formatPercentage(statistic
.getPercentTranslated()) + "%";
}
}

public String getStatisticUnit(String sortOption) {
if (sortOption.equals(SortingType.HOURS)) {
public String getStatisticUnit(SortingType.SortOption sortOption) {
if (sortOption.equals(SortingType.SortOption.HOURS)) {
return zanataMessages.getMessage("jsf.stats.HoursRemaining");
} else if (sortOption.equals(SortingType.WORDS)) {
} else if (sortOption.equals(SortingType.SortOption.WORDS)) {
return zanataMessages.getMessage("jsf.Words");
} else {
return zanataMessages.getMessage("jsf.Translated");
}
}

@CachedMethodResult
public WordStatistic getStatisticForLocale(LocaleId localeId) {
public WordStatistic getStatisticsForLocale(LocaleId localeId) {
WordStatistic statistic = new WordStatistic();
for (Map.Entry<VersionLocaleKey, WordStatistic> entry : statisticMap
.entrySet()) {
Expand All @@ -305,7 +322,8 @@ public WordStatistic getStatisticForProject(Long projectIterationId) {
WordStatistic statistic = new WordStatistic();
for (Map.Entry<VersionLocaleKey, WordStatistic> entry : statisticMap
.entrySet()) {
if (entry.getKey().getProjectIterationId().equals(projectIterationId)) {
if (entry.getKey().getProjectIterationId()
.equals(projectIterationId)) {
statistic.add(entry.getValue());
}
}
Expand All @@ -316,8 +334,8 @@ public WordStatistic getStatisticForProject(Long projectIterationId) {

@CachedMethodResult
public WordStatistic getSelectedLocaleStatistic(Long projectIterationId) {
return statisticMap.get(new VersionLocaleKey(projectIterationId, selectedLocale
.getLocaleId()));
return statisticMap.get(new VersionLocaleKey(projectIterationId,
selectedLocale.getLocaleId()));
}

@CachedMethodResult
Expand All @@ -343,7 +361,6 @@ private Map<LocaleId, List<HProjectIteration>> getMissingLocaleVersionMap() {
* Search for locale that is not activated in given version
*
* @param version
* @return
*/
public List<LocaleId> getMissingLocale(HProjectIteration version) {
List<LocaleId> result = Lists.newArrayList();
Expand All @@ -369,7 +386,6 @@ public String getMissingLocaleTitle(HProjectIteration version) {
* Search for version that doesn't activate given locale
*
* @param localeId
* @return
*/
public List<HProjectIteration> getMissingVersion(LocaleId localeId) {
return getMissingLocaleVersionMap().get(localeId);
Expand All @@ -385,7 +401,7 @@ public String getMissingVersionTitle(LocaleId localeId) {
}

public boolean isLocaleActivatedInVersion(HProjectIteration version,
LocaleId localeId) {
LocaleId localeId) {
List<HProjectIteration> versionList =
getMissingLocaleVersionMap().get(localeId);
return !versionList.contains(version);
Expand Down Expand Up @@ -431,7 +447,7 @@ public final class OverallStatistic {

public List<HProjectIteration> getProjectIterations() {
if (projectIterations == null) {
projectIterations = versionGroupDAO.getVersionsBySlug(slug);
projectIterations = projectIterationDAO.getByGroupSlug(slug);
}
Collections.sort(projectIterations, versionComparator);
return projectIterations;
Expand Down
Expand Up @@ -25,6 +25,7 @@
import java.util.List;
import java.util.Set;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

Expand All @@ -37,12 +38,12 @@
import org.jboss.seam.security.management.JpaIdentityStore;
import org.zanata.dao.ProjectDAO;
import org.zanata.dao.ProjectIterationDAO;
import org.zanata.dao.VersionGroupDAO;
import org.zanata.model.HAccount;
import org.zanata.model.HPerson;
import org.zanata.model.HProject;
import org.zanata.model.HProjectIteration;
import org.zanata.service.VersionGroupService;
import org.zanata.service.VersionGroupService.SelectableHProject;

import com.google.common.collect.Lists;

Expand All @@ -57,6 +58,9 @@ public class VersionGroupJoinAction implements Serializable {
@In
private ProjectDAO projectDAO;

@In
private VersionGroupDAO versionGroupDAO;

@In
private ProjectIterationDAO projectIterationDAO;

Expand All @@ -67,7 +71,7 @@ public class VersionGroupJoinAction implements Serializable {
private HAccount authenticatedAccount;

@Getter
private List<SelectableHProject> projectVersions = Lists.newArrayList();
private List<SelectableProject> projectVersions = Lists.newArrayList();

@Getter
@Setter
Expand All @@ -87,14 +91,14 @@ public void searchMaintainedProjectVersion() {
for (HProject project : maintainedProjects) {
for (HProjectIteration projectIteration : projectDAO
.getAllIterations(project.getSlug())) {
projectVersions.add(new SelectableHProject(projectIteration,
projectVersions.add(new SelectableProject(projectIteration,
false));
}
}
}

public String getGroupName() {
return versionGroupServiceImpl.getBySlug(slug).getName();
return versionGroupDAO.getBySlug(slug).getName();
}

public void searchProjectVersion() {
Expand All @@ -103,7 +107,7 @@ public void searchProjectVersion() {
HProjectIteration projectIteration =
projectIterationDAO.getBySlug(projectSlug, iterationSlug);
if (projectIteration != null) {
projectVersions.add(new SelectableHProject(projectIteration,
projectVersions.add(new SelectableProject(projectIteration,
true));
}

Expand All @@ -121,7 +125,7 @@ public String cancel() {

public String send() {
boolean isAnyVersionSelected = false;
for (SelectableHProject projectVersion : projectVersions) {
for (SelectableProject projectVersion : projectVersions) {
if (projectVersion.isSelected()) {
isAnyVersionSelected = true;
}
Expand All @@ -141,4 +145,15 @@ public String send() {

}

@AllArgsConstructor
public final class SelectableProject {

@Getter
private HProjectIteration projectIteration;

@Getter
@Setter
private boolean selected;
}

}

0 comments on commit 7da486b

Please sign in to comment.