.getId());
Map<String, TransUnitWords> wordIterationStats =
projectIterationDAO
.getAllWordStatsStatistics(iteration.getId());
ContainerTranslationStatistics iterationStats =
new ContainerTranslationStatistics();
iterationStats.setId(iterationSlug);
iterationStats.addRef(new Link(URI.create(zPathService
.generatePathForProjectIteration(iteration)), "statSource",
"PROJ_ITER"));
long iterationTotalMssgs =
projectIterationDAO
.getTotalMessageCountForIteration(iteration.getId());
long iterationTotalWords =
projectIterationDAO.getTotalWordCountForIteration(iteration
.getId());
for (LocaleId locId : localeIds) {
// trans unit level stats
TransUnitCount count = transUnitIterationStats.get(locId.getId());
// Stats might not return anything if nothing is translated
if (count == null) {
count = new TransUnitCount(0, 0, (int) iterationTotalMssgs);
}
HTextFlowTarget target =
localeServiceImpl.getLastTranslated(projectSlug,
iterationSlug, locId);
String lastModifiedBy = "";
Date lastModifiedDate = null;
if (target != null) {
lastModifiedDate = target.getLastChanged();
if (target.getLastModifiedBy() != null) {
lastModifiedBy =
target.getLastModifiedBy().getAccount()
.getUsername();
}
}
TransUnitWords wordCount = wordIterationStats.get(locId.getId());
if (wordCount == null) {
wordCount = new TransUnitWords(0, 0, (int) iterationTotalWords);
}
TranslationStatistics transUnitStats =
getMessageStats(count, locId, lastModifiedDate,
lastModifiedBy);
transUnitStats.setRemainingHours(StatisticsUtil
.getRemainingHours(wordCount));
iterationStats.addStats(transUnitStats);
// word level stats
if (includeWordStats) {
TranslationStatistics wordsStats =
getWordsStats(wordCount, locId, lastModifiedDate,
lastModifiedBy);
wordsStats.setRemainingHours(StatisticsUtil
.getRemainingHours(wordCount));
iterationStats.addStats(wordsStats);
}
}
// TODO Do in a single query
if (includeDetails) {
for (String docId : iteration.getDocuments().keySet()) {
iterationStats.addDetailedStats(this.getStatistics(projectSlug,
iterationSlug, docId, includeWordStats, locales));
}
}
return iterationStats;