@Test public void testPerformActionWithBadSearchText() throws Exception { final String escapedSearchText = "heyNowEscaped"; final long personId = 58583L; final String nativeLuceneQuery = "abcdefgh"; context.checking(new Expectations() { { one(searchRequestBuilder).escapeAllButWildcardCharacters(SEARCH_TEXT); will(returnValue(escapedSearchText)); one(principalMock).getId(); will(returnValue(personId)); one(queryBuilder).buildNativeQuery(escapedSearchText, "background", personId); will(returnValue(nativeLuceneQuery)); one(searchRequestBuilder).buildQueryFromNativeSearchString(nativeLuceneQuery); will(throwException(new RuntimeException("OOPS"))); } }); GetDirectorySearchResultsRequest currentRequest = new GetDirectorySearchResultsRequest(SEARCH_TEXT, "background", FROM, TO, ""); ServiceActionContext currentActionContext = new ServiceActionContext(currentRequest, principalMock); PagedSet<ModelView> pagedSet = sut.execute(currentActionContext); assertEquals(FROM, pagedSet.getFromIndex()); assertEquals(TO, pagedSet.getToIndex()); assertEquals(0, pagedSet.getTotal()); context.assertIsSatisfied(); }
@SuppressWarnings("unchecked") @Override public PagedSet<ModelView> execute(final ServiceActionContext inActionContext) throws ExecutionException { long startTime = System.currentTimeMillis(); GetDirectorySearchResultsRequest currentRequest = (GetDirectorySearchResultsRequest) inActionContext .getParams(); String searchText = searchRequestBuilder.escapeAllButWildcardCharacters(currentRequest.getSearchTerm()); long userPersonId = inActionContext.getPrincipal().getId(); String nativeLuceneQuery = queryBuilder.buildNativeQuery(searchText, currentRequest.getWeightedField(), userPersonId); FullTextQuery query; try { query = searchRequestBuilder.buildQueryFromNativeSearchString(nativeLuceneQuery); } catch (Exception ex) { return new PagedSet<ModelView>(currentRequest.getStartIndex(), currentRequest.getEndIndex(), 0, new ArrayList<ModelView>()); } searchRequestBuilder.setPaging(query, currentRequest.getStartIndex(), currentRequest.getEndIndex()); List<ModelView> results = query.getResultList(); transientPropertyPopulator.populateTransientProperties(results, userPersonId, searchText); PagedSet<ModelView> pagedResults = new PagedSet<ModelView>(currentRequest.getStartIndex(), currentRequest .getEndIndex(), query.getResultSize(), results); String elapsedTime = formatElapasedTime(startTime, System.currentTimeMillis()); pagedResults.setElapsedTime(elapsedTime); log.info("Searched '" + searchText + "' in " + elapsedTime); return pagedResults; }
GetDirectorySearchResultsExecution implements ExecutionStrategy<ServiceActionContext> { @SuppressWarnings("unchecked") @Override public PagedSet<ModelView> execute(final ServiceActionContext inActionContext) throws ExecutionException { long startTime = System.currentTimeMillis(); GetDirectorySearchResultsRequest currentRequest = (GetDirectorySearchResultsRequest) inActionContext .getParams(); String searchText = searchRequestBuilder.escapeAllButWildcardCharacters(currentRequest.getSearchTerm()); long userPersonId = inActionContext.getPrincipal().getId(); String nativeLuceneQuery = queryBuilder.buildNativeQuery(searchText, currentRequest.getWeightedField(), userPersonId); FullTextQuery query; try { query = searchRequestBuilder.buildQueryFromNativeSearchString(nativeLuceneQuery); } catch (Exception ex) { return new PagedSet<ModelView>(currentRequest.getStartIndex(), currentRequest.getEndIndex(), 0, new ArrayList<ModelView>()); } searchRequestBuilder.setPaging(query, currentRequest.getStartIndex(), currentRequest.getEndIndex()); List<ModelView> results = query.getResultList(); transientPropertyPopulator.populateTransientProperties(results, userPersonId, searchText); PagedSet<ModelView> pagedResults = new PagedSet<ModelView>(currentRequest.getStartIndex(), currentRequest .getEndIndex(), query.getResultSize(), results); String elapsedTime = formatElapasedTime(startTime, System.currentTimeMillis()); pagedResults.setElapsedTime(elapsedTime); log.info("Searched '" + searchText + "' in " + elapsedTime); return pagedResults; } }
GetDirectorySearchResultsExecution implements ExecutionStrategy<ServiceActionContext> { @SuppressWarnings("unchecked") @Override public PagedSet<ModelView> execute(final ServiceActionContext inActionContext) throws ExecutionException { long startTime = System.currentTimeMillis(); GetDirectorySearchResultsRequest currentRequest = (GetDirectorySearchResultsRequest) inActionContext .getParams(); String searchText = searchRequestBuilder.escapeAllButWildcardCharacters(currentRequest.getSearchTerm()); long userPersonId = inActionContext.getPrincipal().getId(); String nativeLuceneQuery = queryBuilder.buildNativeQuery(searchText, currentRequest.getWeightedField(), userPersonId); FullTextQuery query; try { query = searchRequestBuilder.buildQueryFromNativeSearchString(nativeLuceneQuery); } catch (Exception ex) { return new PagedSet<ModelView>(currentRequest.getStartIndex(), currentRequest.getEndIndex(), 0, new ArrayList<ModelView>()); } searchRequestBuilder.setPaging(query, currentRequest.getStartIndex(), currentRequest.getEndIndex()); List<ModelView> results = query.getResultList(); transientPropertyPopulator.populateTransientProperties(results, userPersonId, searchText); PagedSet<ModelView> pagedResults = new PagedSet<ModelView>(currentRequest.getStartIndex(), currentRequest .getEndIndex(), query.getResultSize(), results); String elapsedTime = formatElapasedTime(startTime, System.currentTimeMillis()); pagedResults.setElapsedTime(elapsedTime); log.info("Searched '" + searchText + "' in " + elapsedTime); return pagedResults; } GetDirectorySearchResultsExecution(final DirectorySearchLuceneQueryBuilder inQueryBuilder,
            final ProjectionSearchRequestBuilder inSearchRequestBuilder,
            final TransientPropertyPopulator inTransientPropertyPopulator); }
GetDirectorySearchResultsExecution implements ExecutionStrategy<ServiceActionContext> { @SuppressWarnings("unchecked") @Override public PagedSet<ModelView> execute(final ServiceActionContext inActionContext) throws ExecutionException { long startTime = System.currentTimeMillis(); GetDirectorySearchResultsRequest currentRequest = (GetDirectorySearchResultsRequest) inActionContext .getParams(); String searchText = searchRequestBuilder.escapeAllButWildcardCharacters(currentRequest.getSearchTerm()); long userPersonId = inActionContext.getPrincipal().getId(); String nativeLuceneQuery = queryBuilder.buildNativeQuery(searchText, currentRequest.getWeightedField(), userPersonId); FullTextQuery query; try { query = searchRequestBuilder.buildQueryFromNativeSearchString(nativeLuceneQuery); } catch (Exception ex) { return new PagedSet<ModelView>(currentRequest.getStartIndex(), currentRequest.getEndIndex(), 0, new ArrayList<ModelView>()); } searchRequestBuilder.setPaging(query, currentRequest.getStartIndex(), currentRequest.getEndIndex()); List<ModelView> results = query.getResultList(); transientPropertyPopulator.populateTransientProperties(results, userPersonId, searchText); PagedSet<ModelView> pagedResults = new PagedSet<ModelView>(currentRequest.getStartIndex(), currentRequest .getEndIndex(), query.getResultSize(), results); String elapsedTime = formatElapasedTime(startTime, System.currentTimeMillis()); pagedResults.setElapsedTime(elapsedTime); log.info("Searched '" + searchText + "' in " + elapsedTime); return pagedResults; } GetDirectorySearchResultsExecution(final DirectorySearchLuceneQueryBuilder inQueryBuilder,
            final ProjectionSearchRequestBuilder inSearchRequestBuilder,
            final TransientPropertyPopulator inTransientPropertyPopulator); @SuppressWarnings("unchecked") @Override PagedSet<ModelView> execute(final ServiceActionContext inActionContext); }
GetDirectorySearchResultsExecution implements ExecutionStrategy<ServiceActionContext> { @SuppressWarnings("unchecked") @Override public PagedSet<ModelView> execute(final ServiceActionContext inActionContext) throws ExecutionException { long startTime = System.currentTimeMillis(); GetDirectorySearchResultsRequest currentRequest = (GetDirectorySearchResultsRequest) inActionContext .getParams(); String searchText = searchRequestBuilder.escapeAllButWildcardCharacters(currentRequest.getSearchTerm()); long userPersonId = inActionContext.getPrincipal().getId(); String nativeLuceneQuery = queryBuilder.buildNativeQuery(searchText, currentRequest.getWeightedField(), userPersonId); FullTextQuery query; try { query = searchRequestBuilder.buildQueryFromNativeSearchString(nativeLuceneQuery); } catch (Exception ex) { return new PagedSet<ModelView>(currentRequest.getStartIndex(), currentRequest.getEndIndex(), 0, new ArrayList<ModelView>()); } searchRequestBuilder.setPaging(query, currentRequest.getStartIndex(), currentRequest.getEndIndex()); List<ModelView> results = query.getResultList(); transientPropertyPopulator.populateTransientProperties(results, userPersonId, searchText); PagedSet<ModelView> pagedResults = new PagedSet<ModelView>(currentRequest.getStartIndex(), currentRequest .getEndIndex(), query.getResultSize(), results); String elapsedTime = formatElapasedTime(startTime, System.currentTimeMillis()); pagedResults.setElapsedTime(elapsedTime); log.info("Searched '" + searchText + "' in " + elapsedTime); return pagedResults; } GetDirectorySearchResultsExecution(final DirectorySearchLuceneQueryBuilder inQueryBuilder,
            final ProjectionSearchRequestBuilder inSearchRequestBuilder,
            final TransientPropertyPopulator inTransientPropertyPopulator); @SuppressWarnings("unchecked") @Override PagedSet<ModelView> execute(final ServiceActionContext inActionContext);  }