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

Commit

Permalink
Add document statistic endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Sep 29, 2014
1 parent f234f10 commit 120eb90
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 21 deletions.
Expand Up @@ -40,10 +40,10 @@

import com.google.common.collect.Lists;

@Name("versionLocalesService")
@Path(VersionLocalesResource.SERVICE_PATH)
@Name("projectVersionService")
@Path(ProjectVersionResource.SERVICE_PATH)
@Transactional
public class VersionLocalesService implements VersionLocalesResource {
public class ProjectVersionService implements ProjectVersionResource {

@PathParam("projectSlug")
private String projectSlug;
Expand All @@ -58,7 +58,7 @@ public class VersionLocalesService implements VersionLocalesResource {
private ProjectIterationDAO projectIterationDAO;

@Override
public Response get() {
public Response getLocales() {
HProjectIteration version =
projectIterationDAO.getBySlug(projectSlug, versionSlug);
if (version == null) {
Expand Down
Expand Up @@ -48,23 +48,10 @@

import com.google.common.collect.Lists;

@Name("transUnitStatusService")
@Name("transUnitService")
@Path(TransUnitResource.SERVICE_PATH)
@Transactional
public class TransUnitService implements TransUnitResource {

@PathParam("projectSlug")
private String projectSlug;

@PathParam("versionSlug")
private String versionSlug;

@PathParam("docId")
private String docId;

@PathParam("localeId")
private String localeId;

@In
private TextFlowTargetDAO textFlowTargetDAO;

Expand All @@ -75,7 +62,8 @@ public class TransUnitService implements TransUnitResource {
private LocaleDAO localeDAO;

@Override
public Response getStatus() {
public Response getStatus(String projectSlug, String versionSlug,
String docId, String localeId) {

HDocument document =
documentDAO.getByProjectIterationAndDocId(projectSlug,
Expand Down
Expand Up @@ -20,14 +20,18 @@
*/
package org.zanata.service.impl;

import java.lang.reflect.Type;
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.core.GenericEntity;
import javax.ws.rs.core.Response;

import org.apache.commons.lang.StringUtils;
import org.jboss.resteasy.util.GenericType;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
Expand All @@ -43,6 +47,8 @@
import org.zanata.model.HTextFlowTarget;
import org.zanata.rest.NoSuchEntityException;
import org.zanata.rest.dto.Link;
import org.zanata.rest.dto.Locale;
import org.zanata.rest.dto.TransUnitStatus;
import org.zanata.rest.dto.stats.ContainerTranslationStatistics;
import org.zanata.rest.dto.stats.TranslationStatistics;
import org.zanata.rest.dto.stats.TranslationStatistics.StatUnit;
Expand All @@ -53,6 +59,8 @@
import org.zanata.util.StatisticsUtil;
import org.zanata.webtrans.shared.model.DocumentStatus;

import com.google.common.collect.Lists;

/**
* Default implementation for the
* {@link org.zanata.rest.service.StatisticsResource} interface. This is a
Expand Down Expand Up @@ -93,7 +101,7 @@ public ContainerTranslationStatistics getStatistics(String projectSlug,
if (locales.length == 0) {
List<HLocale> iterationLocales =
localeServiceImpl.getSupportedLanguageByProjectIteration(
projectSlug, iterationSlug);
projectSlug, iterationSlug);
localeIds = new LocaleId[iterationLocales.size()];
for (int i = 0, iterationLocalesSize = iterationLocales.size(); i < iterationLocalesSize; i++) {
HLocale loc = iterationLocales.get(i);
Expand Down Expand Up @@ -201,7 +209,7 @@ public ContainerTranslationStatistics getStatistics(String projectSlug,
if (locales.length == 0) {
List<HLocale> iterationLocales =
localeServiceImpl.getSupportedLanguageByProjectIteration(
projectSlug, iterationSlug);
projectSlug, iterationSlug);
localeIds = new LocaleId[iterationLocales.size()];
for (int i = 0, iterationLocalesSize = iterationLocales.size(); i < iterationLocalesSize; i++) {
HLocale loc = iterationLocales.get(i);
Expand Down Expand Up @@ -266,6 +274,34 @@ public ContainerTranslationStatistics getStatistics(String projectSlug,
return docStatistics;
}

@Override
public Response getDocumentStatistics(String projectSlug,
String versionSlug, String docId, String localeId) {
HDocument doc =
documentDAO.getByProjectIterationAndDocId(projectSlug,
versionSlug, docId);

if(doc == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}

ContainerTranslationStatistics docStats =
getDocStatistics(doc.getId(), new LocaleId(localeId));

TranslationStatistics docWordStatistic =
docStats.getStats(localeId, StatUnit.WORD);
TranslationStatistics docMsgStatistic =
docStats.getStats(localeId, StatUnit.MESSAGE);

Type genericType = new GenericType<List<TranslationStatistics>>() {
}.getGenericType();
Object entity =
new GenericEntity<List<TranslationStatistics>>(
Lists.newArrayList(docWordStatistic, docMsgStatistic),
genericType);
return Response.ok(entity).build();
}

private TranslationStatistics getWordsStats(TransUnitWords wordCount,
LocaleId locale, Date lastChanged, String lastModifiedBy) {
TranslationStatistics stats =
Expand Down

0 comments on commit 120eb90

Please sign in to comment.