@Test public void checkForNewQueryResultsNoNewResults() throws E { final long id = 123L; final SavedQuery savedQuery = new SavedQuery.Builder() .setId(id) .setConceptClusterPhrases(Collections.singleton(new ConceptClusterPhrase("raccoons", true, 0))) .build(); when(savedQueryService.get(id)).thenReturn(savedQuery); when(documentsService.queryTextIndex(any())).thenReturn(searchResults); final int numberOfResults = 0; assertEquals(numberOfResults, savedQueryController.checkForNewQueryResults(id)); }
@RequestMapping(value = NEW_RESULTS_PATH + "/{id}", method = RequestMethod.GET) public int checkForNewQueryResults(@SuppressWarnings("MVCPathVariableInspection") @PathVariable("id") final long id) throws E { int newResults = 0; final SavedQuery savedQuery = service.get(id); final ZonedDateTime dateDocsLastFetched = savedQuery.getDateDocsLastFetched(); if(savedQuery.getMaxDate() == null || savedQuery.getMaxDate().isAfter(dateDocsLastFetched)) { final Q queryRestrictions = queryRestrictionsBuilderFactory.getObject() .queryText(savedQuery.toQueryText()) .fieldText(fieldTextParser.toFieldText(savedQuery, true)) .databases(convertEmbeddableIndexes(savedQuery.getIndexes())) .minDate(dateDocsLastFetched) .minScore(savedQuery.getMinScore()) .build(); final QueryRequestBuilder<RQ, Q, ?> queryRequestBuilder = queryRequestBuilderFactory.getObject() .queryRestrictions(queryRestrictions) .maxResults(1001) .queryType(QueryRequest.QueryType.MODIFIED); addParams(queryRequestBuilder); final RQ queryRequest = queryRequestBuilder.build(); final Documents<?> searchResults = documentsService.queryTextIndex(queryRequest); newResults = searchResults.getTotalResults(); } return newResults; }
SavedQueryController { @RequestMapping(value = NEW_RESULTS_PATH + "/{id}", method = RequestMethod.GET) public int checkForNewQueryResults(@SuppressWarnings("MVCPathVariableInspection") @PathVariable("id") final long id) throws E { int newResults = 0; final SavedQuery savedQuery = service.get(id); final ZonedDateTime dateDocsLastFetched = savedQuery.getDateDocsLastFetched(); if(savedQuery.getMaxDate() == null || savedQuery.getMaxDate().isAfter(dateDocsLastFetched)) { final Q queryRestrictions = queryRestrictionsBuilderFactory.getObject() .queryText(savedQuery.toQueryText()) .fieldText(fieldTextParser.toFieldText(savedQuery, true)) .databases(convertEmbeddableIndexes(savedQuery.getIndexes())) .minDate(dateDocsLastFetched) .minScore(savedQuery.getMinScore()) .build(); final QueryRequestBuilder<RQ, Q, ?> queryRequestBuilder = queryRequestBuilderFactory.getObject() .queryRestrictions(queryRestrictions) .maxResults(1001) .queryType(QueryRequest.QueryType.MODIFIED); addParams(queryRequestBuilder); final RQ queryRequest = queryRequestBuilder.build(); final Documents<?> searchResults = documentsService.queryTextIndex(queryRequest); newResults = searchResults.getTotalResults(); } return newResults; } }
SavedQueryController { @RequestMapping(value = NEW_RESULTS_PATH + "/{id}", method = RequestMethod.GET) public int checkForNewQueryResults(@SuppressWarnings("MVCPathVariableInspection") @PathVariable("id") final long id) throws E { int newResults = 0; final SavedQuery savedQuery = service.get(id); final ZonedDateTime dateDocsLastFetched = savedQuery.getDateDocsLastFetched(); if(savedQuery.getMaxDate() == null || savedQuery.getMaxDate().isAfter(dateDocsLastFetched)) { final Q queryRestrictions = queryRestrictionsBuilderFactory.getObject() .queryText(savedQuery.toQueryText()) .fieldText(fieldTextParser.toFieldText(savedQuery, true)) .databases(convertEmbeddableIndexes(savedQuery.getIndexes())) .minDate(dateDocsLastFetched) .minScore(savedQuery.getMinScore()) .build(); final QueryRequestBuilder<RQ, Q, ?> queryRequestBuilder = queryRequestBuilderFactory.getObject() .queryRestrictions(queryRestrictions) .maxResults(1001) .queryType(QueryRequest.QueryType.MODIFIED); addParams(queryRequestBuilder); final RQ queryRequest = queryRequestBuilder.build(); final Documents<?> searchResults = documentsService.queryTextIndex(queryRequest); newResults = searchResults.getTotalResults(); } return newResults; } protected  SavedQueryController(
        final SavedSearchService<SavedQuery, SavedQuery.Builder> service,
        final DocumentsService<RQ, ?, ?, Q, D, E> documentsService,
        final FieldTextParser fieldTextParser,
        final ObjectFactory<? extends QueryRestrictionsBuilder<Q, S, ?>> queryRestrictionsBuilderFactory,
        final ObjectFactory<? extends QueryRequestBuilder<RQ, Q, ?>> queryRequestBuilderFactory
    ); }
SavedQueryController { @RequestMapping(value = NEW_RESULTS_PATH + "/{id}", method = RequestMethod.GET) public int checkForNewQueryResults(@SuppressWarnings("MVCPathVariableInspection") @PathVariable("id") final long id) throws E { int newResults = 0; final SavedQuery savedQuery = service.get(id); final ZonedDateTime dateDocsLastFetched = savedQuery.getDateDocsLastFetched(); if(savedQuery.getMaxDate() == null || savedQuery.getMaxDate().isAfter(dateDocsLastFetched)) { final Q queryRestrictions = queryRestrictionsBuilderFactory.getObject() .queryText(savedQuery.toQueryText()) .fieldText(fieldTextParser.toFieldText(savedQuery, true)) .databases(convertEmbeddableIndexes(savedQuery.getIndexes())) .minDate(dateDocsLastFetched) .minScore(savedQuery.getMinScore()) .build(); final QueryRequestBuilder<RQ, Q, ?> queryRequestBuilder = queryRequestBuilderFactory.getObject() .queryRestrictions(queryRestrictions) .maxResults(1001) .queryType(QueryRequest.QueryType.MODIFIED); addParams(queryRequestBuilder); final RQ queryRequest = queryRequestBuilder.build(); final Documents<?> searchResults = documentsService.queryTextIndex(queryRequest); newResults = searchResults.getTotalResults(); } return newResults; } protected  SavedQueryController(
        final SavedSearchService<SavedQuery, SavedQuery.Builder> service,
        final DocumentsService<RQ, ?, ?, Q, D, E> documentsService,
        final FieldTextParser fieldTextParser,
        final ObjectFactory<? extends QueryRestrictionsBuilder<Q, S, ?>> queryRestrictionsBuilderFactory,
        final ObjectFactory<? extends QueryRequestBuilder<RQ, Q, ?>> queryRequestBuilderFactory
    ); @RequestMapping(method = RequestMethod.GET) Set<SavedQuery> getAll(
        @RequestParam(name="shared", defaultValue = "false") boolean shared
    ); @RequestMapping(value = GET_SHARED, method = RequestMethod.GET) Set<SavedQuery> getShared(); @RequestMapping(method = RequestMethod.POST) SavedQuery create(
        @RequestBody final SavedQuery query
    ); @RequestMapping(value = "{id}", method = RequestMethod.PUT) SavedQuery update(
        @PathVariable("id") final long id,
        @RequestBody final SavedQuery query
    ); @RequestMapping(value = GET_SHARED + "/{id}", method = RequestMethod.PUT) SavedQuery updateShared(
            @PathVariable("id") final long id,
            @RequestBody final SavedQuery query
    ); @RequestMapping(value = "{id}", method = RequestMethod.DELETE) void delete(@SuppressWarnings("MVCPathVariableInspection") @PathVariable("id") final long id); @RequestMapping(value = NEW_RESULTS_PATH + "/{id}", method = RequestMethod.GET) int checkForNewQueryResults(@SuppressWarnings("MVCPathVariableInspection") @PathVariable("id") final long id); }
SavedQueryController { @RequestMapping(value = NEW_RESULTS_PATH + "/{id}", method = RequestMethod.GET) public int checkForNewQueryResults(@SuppressWarnings("MVCPathVariableInspection") @PathVariable("id") final long id) throws E { int newResults = 0; final SavedQuery savedQuery = service.get(id); final ZonedDateTime dateDocsLastFetched = savedQuery.getDateDocsLastFetched(); if(savedQuery.getMaxDate() == null || savedQuery.getMaxDate().isAfter(dateDocsLastFetched)) { final Q queryRestrictions = queryRestrictionsBuilderFactory.getObject() .queryText(savedQuery.toQueryText()) .fieldText(fieldTextParser.toFieldText(savedQuery, true)) .databases(convertEmbeddableIndexes(savedQuery.getIndexes())) .minDate(dateDocsLastFetched) .minScore(savedQuery.getMinScore()) .build(); final QueryRequestBuilder<RQ, Q, ?> queryRequestBuilder = queryRequestBuilderFactory.getObject() .queryRestrictions(queryRestrictions) .maxResults(1001) .queryType(QueryRequest.QueryType.MODIFIED); addParams(queryRequestBuilder); final RQ queryRequest = queryRequestBuilder.build(); final Documents<?> searchResults = documentsService.queryTextIndex(queryRequest); newResults = searchResults.getTotalResults(); } return newResults; } protected  SavedQueryController(
        final SavedSearchService<SavedQuery, SavedQuery.Builder> service,
        final DocumentsService<RQ, ?, ?, Q, D, E> documentsService,
        final FieldTextParser fieldTextParser,
        final ObjectFactory<? extends QueryRestrictionsBuilder<Q, S, ?>> queryRestrictionsBuilderFactory,
        final ObjectFactory<? extends QueryRequestBuilder<RQ, Q, ?>> queryRequestBuilderFactory
    ); @RequestMapping(method = RequestMethod.GET) Set<SavedQuery> getAll(
        @RequestParam(name="shared", defaultValue = "false") boolean shared
    ); @RequestMapping(value = GET_SHARED, method = RequestMethod.GET) Set<SavedQuery> getShared(); @RequestMapping(method = RequestMethod.POST) SavedQuery create(
        @RequestBody final SavedQuery query
    ); @RequestMapping(value = "{id}", method = RequestMethod.PUT) SavedQuery update(
        @PathVariable("id") final long id,
        @RequestBody final SavedQuery query
    ); @RequestMapping(value = GET_SHARED + "/{id}", method = RequestMethod.PUT) SavedQuery updateShared(
            @PathVariable("id") final long id,
            @RequestBody final SavedQuery query
    ); @RequestMapping(value = "{id}", method = RequestMethod.DELETE) void delete(@SuppressWarnings("MVCPathVariableInspection") @PathVariable("id") final long id); @RequestMapping(value = NEW_RESULTS_PATH + "/{id}", method = RequestMethod.GET) int checkForNewQueryResults(@SuppressWarnings("MVCPathVariableInspection") @PathVariable("id") final long id);  }