This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix and move getVersionSupportedLocale test to service class
- Loading branch information
Alex Eng
committed
Apr 3, 2014
1 parent
5c7e7d7
commit 78e782a
Showing
4 changed files
with
146 additions
and
148 deletions.
There are no files selected for viewing
71 changes: 22 additions & 49 deletions
71
zanata-war/src/main/java/org/zanata/webtrans/server/rpc/GetLocaleListHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,62 @@ | ||
package org.zanata.webtrans.server.rpc; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.annotation.Nonnull; | ||
|
||
import net.customware.gwt.dispatch.server.ExecutionContext; | ||
import net.customware.gwt.dispatch.shared.ActionException; | ||
|
||
import org.jboss.seam.ScopeType; | ||
import org.jboss.seam.annotations.In; | ||
import org.jboss.seam.annotations.Name; | ||
import org.jboss.seam.annotations.Scope; | ||
import org.zanata.dao.LocaleDAO; | ||
import org.zanata.dao.ProjectDAO; | ||
import org.zanata.dao.ProjectIterationDAO; | ||
import org.zanata.model.HLocale; | ||
import org.zanata.model.HProject; | ||
import org.zanata.model.HProjectIteration; | ||
import org.zanata.security.ZanataIdentity; | ||
import org.zanata.service.LocaleService; | ||
import org.zanata.webtrans.server.ActionHandlerFor; | ||
import org.zanata.webtrans.shared.model.IdForLocale; | ||
import org.zanata.webtrans.shared.model.Locale; | ||
import org.zanata.webtrans.shared.model.ProjectIterationId; | ||
import org.zanata.webtrans.shared.rpc.GetLocaleList; | ||
import org.zanata.webtrans.shared.rpc.GetLocaleListResult; | ||
import com.google.common.collect.Lists; | ||
|
||
import net.customware.gwt.dispatch.server.ExecutionContext; | ||
import net.customware.gwt.dispatch.shared.ActionException; | ||
|
||
@Name("webtrans.gwt.GetLocaleListHandler") | ||
@Scope(ScopeType.STATELESS) | ||
@ActionHandlerFor(GetLocaleList.class) | ||
public class GetLocaleListHandler extends AbstractActionHandler<GetLocaleList, | ||
GetLocaleListResult> { | ||
public class GetLocaleListHandler extends | ||
AbstractActionHandler<GetLocaleList, GetLocaleListResult> { | ||
@In | ||
private ZanataIdentity identity; | ||
|
||
@In | ||
private LocaleDAO localeDAO; | ||
@In | ||
private ProjectIterationDAO projectIterationDAO; | ||
@In | ||
private ProjectDAO projectDAO; | ||
private ProjectIterationId iterationId; | ||
private String projectSlug; | ||
private LocaleService localeServiceImpl; | ||
|
||
@Override | ||
public GetLocaleListResult execute(GetLocaleList action, | ||
ExecutionContext context) throws ActionException { | ||
ExecutionContext context) throws ActionException { | ||
identity.checkLoggedIn(); | ||
|
||
iterationId = action.getWorkspaceId().getProjectIterationId(); | ||
projectSlug = iterationId.getProjectSlug(); | ||
|
||
List<Locale> locales = new ArrayList<Locale>(); | ||
ProjectIterationId iterationId = | ||
action.getWorkspaceId().getProjectIterationId(); | ||
String projectSlug = iterationId.getProjectSlug(); | ||
|
||
List<HLocale> hLocales = getLocaleList(); | ||
List<HLocale> hLocales = | ||
localeServiceImpl.getSupportedLanguageByProjectIteration( | ||
projectSlug, iterationId.getIterationSlug()); | ||
|
||
List<Locale> locales = Lists.newArrayList(); | ||
for (HLocale hLocale : hLocales) { | ||
Locale locale = new Locale(new IdForLocale(hLocale.getId(), | ||
hLocale.getLocaleId()), hLocale.retrieveDisplayName()); | ||
Locale locale = | ||
new Locale(new IdForLocale(hLocale.getId(), | ||
hLocale.getLocaleId()), | ||
hLocale.retrieveDisplayName()); | ||
locales.add(locale); | ||
} | ||
return new GetLocaleListResult(locales); | ||
} | ||
|
||
@Override | ||
public void rollback(GetLocaleList action, GetLocaleListResult result, | ||
ExecutionContext context) throws ActionException { | ||
} | ||
|
||
/** | ||
* | ||
* @return the current locales for this iteration | ||
*/ | ||
private List<HLocale> getLocaleList() { | ||
HProjectIteration iteration = projectIterationDAO.getBySlug(projectSlug, | ||
iterationId.getIterationSlug()); | ||
if (iteration.isOverrideLocales()) { | ||
return new ArrayList<HLocale>(iteration.getCustomizedLocales()); | ||
} | ||
return getSupportedLanguageByProject(projectSlug); | ||
} | ||
|
||
private List<HLocale> getSupportedLanguageByProject(@Nonnull String project) { | ||
HProject proj = projectDAO.getBySlug(project); | ||
if (proj.isOverrideLocales()) { | ||
return new ArrayList<HLocale>(proj.getCustomizedLocales()); | ||
} | ||
return localeDAO.findAllActiveAndEnabledByDefault(); | ||
ExecutionContext context) throws ActionException { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.