GetProjectTransUnitLists action, ExecutionContext context)
throws ActionException {
identity.checkLoggedIn();
log.info("Searching all targets for workspace {}",
action.getWorkspaceId());
HLocale hLocale;
try {
hLocale =
localeServiceImpl.validateLocaleByProjectIteration(action
.getWorkspaceId().getLocaleId(), action
.getWorkspaceId().getProjectIterationId()
.getProjectSlug(), action.getWorkspaceId()
.getProjectIterationId().getIterationSlug());
} catch (ZanataServiceException e) {
throw new ActionException(e);
}
HashMap<Long, List<TransUnit>> matchingTUs =
new HashMap<Long, List<TransUnit>>();
HashMap<Long, String> docPaths = new HashMap<Long, String>();
if (Strings.isNullOrEmpty(action.getSearchString())) {
// TODO empty searches shouldn't be requested, consider replacing
// this
// with an error, or making behaviour return all targets for the
// project (consider performance).
return new GetProjectTransUnitListsResult(action, docPaths,
matchingTUs);
}
FilterConstraints filterConstraints =
FilterConstraints.builder().filterBy(action.getSearchString())
.caseSensitive(action.isCaseSensitive())
.checkInSource(action.isSearchInSource())
.checkInTarget(action.isSearchInTarget()).build();
List<HTextFlow> matchingFlows =
textFlowSearchServiceImpl.findTextFlows(
action.getWorkspaceId(), action.getDocumentPaths(),
filterConstraints);
log.info("Returned {} results for search", matchingFlows.size());
// FIXME remove when analyzer handles leading & trailing whitespace
boolean needsWhitespaceCheck =
!action.getSearchString().equals(
action.getSearchString().trim());
Iterable<HTextFlow> result = matchingFlows;
if (needsWhitespaceCheck) {
// FIXME temporary check for leading and trailing whitespace to
// compensate
// for NGramAnalyzer trimming strings before tokenization. This
// should
// be removed when updating to a lucene version with the whitespace
// issue resolved.
result =
Iterables.filter(
matchingFlows,
new WhitespaceMatchPredicate(action, hLocale
.getId()));
}
for (HTextFlow textFlow : result) {
List<TransUnit> listForDoc =