@Test public void invalidIndexName() throws HodErrorException { final ResourceName goodIndex = new ResourceName("Good", "Good"); final ResourceName badIndex = new ResourceName("bad", "bad"); final HodError invalidIndexError = new HodError.Builder().setErrorCode(HodErrorCode.INDEX_NAME_INVALID).build(); final HodSearchResult result = HodSearchResult.builder() .index(goodIndex.getName()) .build(); final Documents<HodSearchResult> mockedResults = new Documents<>(Collections.singletonList(result), 1, null, null, null, null); when(documentsService.queryTextIndex(any())).thenThrow(new HodErrorException(invalidIndexError, HttpStatus.INTERNAL_SERVER_ERROR.value())).thenReturn(mockedResults); final Database goodDatabase = Database.builder().name(goodIndex.getName()).domain(goodIndex.getDomain()).build(); when(databasesService.getDatabases(any(HodDatabasesRequest.class))).thenReturn(Collections.singleton(goodDatabase)); when(queryRestrictions.getDatabases()).thenReturn(Arrays.asList(goodIndex, badIndex)); final Documents<HodSearchResult> results = findDocumentsService.queryTextIndex(queryRequest); assertThat(results.getDocuments(), hasSize(1)); assertNotNull(results.getWarnings()); assertThat(results.getWarnings().getInvalidDatabases(), hasSize(1)); assertEquals(badIndex, results.getWarnings().getInvalidDatabases().iterator().next()); }
@Override @Cacheable(value = FindCacheNames.DOCUMENTS, cacheResolver = CachingConfiguration.PER_USER_CACHE_RESOLVER_NAME) public Documents<HodSearchResult> queryTextIndex(final HodQueryRequest queryRequest) throws HodErrorException { try { return documentsService.queryTextIndex(queryRequest); } catch (final HodErrorException e) { if (e.getErrorCode() == HodErrorCode.INDEX_NAME_INVALID) { final Boolean publicIndexesEnabled = findConfigService.getConfig().getHod().getPublicIndexesEnabled(); final HodDatabasesRequest databasesRequest = databasesRequestBuilderFactory.getObject().publicIndexesEnabled(publicIndexesEnabled).build(); final Set<Database> updatedDatabases = databasesService.getDatabases(databasesRequest); final QueryRestrictions<ResourceName> queryRestrictions = queryRequest.getQueryRestrictions(); final Set<ResourceName> badIndexes = new HashSet<>(queryRestrictions.getDatabases()); for (final Database database : updatedDatabases) { final ResourceName resourceIdentifier = new ResourceName(database.getDomain(), database.getName()); badIndexes.remove(resourceIdentifier); } final Collection<ResourceName> goodIndexes = new ArrayList<>(queryRestrictions.getDatabases()); goodIndexes.removeAll(badIndexes); final HodQueryRequest queryRequestWithoutBadIndexes = queryRequest.toBuilder() .queryRestrictions(queryRequest.getQueryRestrictions() .toBuilder() .databases(goodIndexes) .build()) .build(); final Documents<HodSearchResult> resultDocuments = documentsService.queryTextIndex(queryRequestWithoutBadIndexes); final Warnings warnings = new Warnings(badIndexes); return new Documents<>( resultDocuments.getDocuments(), resultDocuments.getTotalResults(), resultDocuments.getExpandedQuery(), resultDocuments.getSuggestion(), resultDocuments.getAutoCorrection(), warnings); } else { throw e; } } }
FindHodDocumentService implements HodDocumentsService { @Override @Cacheable(value = FindCacheNames.DOCUMENTS, cacheResolver = CachingConfiguration.PER_USER_CACHE_RESOLVER_NAME) public Documents<HodSearchResult> queryTextIndex(final HodQueryRequest queryRequest) throws HodErrorException { try { return documentsService.queryTextIndex(queryRequest); } catch (final HodErrorException e) { if (e.getErrorCode() == HodErrorCode.INDEX_NAME_INVALID) { final Boolean publicIndexesEnabled = findConfigService.getConfig().getHod().getPublicIndexesEnabled(); final HodDatabasesRequest databasesRequest = databasesRequestBuilderFactory.getObject().publicIndexesEnabled(publicIndexesEnabled).build(); final Set<Database> updatedDatabases = databasesService.getDatabases(databasesRequest); final QueryRestrictions<ResourceName> queryRestrictions = queryRequest.getQueryRestrictions(); final Set<ResourceName> badIndexes = new HashSet<>(queryRestrictions.getDatabases()); for (final Database database : updatedDatabases) { final ResourceName resourceIdentifier = new ResourceName(database.getDomain(), database.getName()); badIndexes.remove(resourceIdentifier); } final Collection<ResourceName> goodIndexes = new ArrayList<>(queryRestrictions.getDatabases()); goodIndexes.removeAll(badIndexes); final HodQueryRequest queryRequestWithoutBadIndexes = queryRequest.toBuilder() .queryRestrictions(queryRequest.getQueryRestrictions() .toBuilder() .databases(goodIndexes) .build()) .build(); final Documents<HodSearchResult> resultDocuments = documentsService.queryTextIndex(queryRequestWithoutBadIndexes); final Warnings warnings = new Warnings(badIndexes); return new Documents<>( resultDocuments.getDocuments(), resultDocuments.getTotalResults(), resultDocuments.getExpandedQuery(), resultDocuments.getSuggestion(), resultDocuments.getAutoCorrection(), warnings); } else { throw e; } } } }
FindHodDocumentService implements HodDocumentsService { @Override @Cacheable(value = FindCacheNames.DOCUMENTS, cacheResolver = CachingConfiguration.PER_USER_CACHE_RESOLVER_NAME) public Documents<HodSearchResult> queryTextIndex(final HodQueryRequest queryRequest) throws HodErrorException { try { return documentsService.queryTextIndex(queryRequest); } catch (final HodErrorException e) { if (e.getErrorCode() == HodErrorCode.INDEX_NAME_INVALID) { final Boolean publicIndexesEnabled = findConfigService.getConfig().getHod().getPublicIndexesEnabled(); final HodDatabasesRequest databasesRequest = databasesRequestBuilderFactory.getObject().publicIndexesEnabled(publicIndexesEnabled).build(); final Set<Database> updatedDatabases = databasesService.getDatabases(databasesRequest); final QueryRestrictions<ResourceName> queryRestrictions = queryRequest.getQueryRestrictions(); final Set<ResourceName> badIndexes = new HashSet<>(queryRestrictions.getDatabases()); for (final Database database : updatedDatabases) { final ResourceName resourceIdentifier = new ResourceName(database.getDomain(), database.getName()); badIndexes.remove(resourceIdentifier); } final Collection<ResourceName> goodIndexes = new ArrayList<>(queryRestrictions.getDatabases()); goodIndexes.removeAll(badIndexes); final HodQueryRequest queryRequestWithoutBadIndexes = queryRequest.toBuilder() .queryRestrictions(queryRequest.getQueryRestrictions() .toBuilder() .databases(goodIndexes) .build()) .build(); final Documents<HodSearchResult> resultDocuments = documentsService.queryTextIndex(queryRequestWithoutBadIndexes); final Warnings warnings = new Warnings(badIndexes); return new Documents<>( resultDocuments.getDocuments(), resultDocuments.getTotalResults(), resultDocuments.getExpandedQuery(), resultDocuments.getSuggestion(), resultDocuments.getAutoCorrection(), warnings); } else { throw e; } } } @Autowired  FindHodDocumentService(
            final HodDatabasesService databasesService,
            @Qualifier(DOCUMENTS_SERVICE_BEAN_NAME)
            final HodDocumentsService documentsService,
            final ObjectFactory<HodDatabasesRequestBuilder> databasesRequestBuilderFactory,
            final ConfigService<HodFindConfig> configService
    ); }
FindHodDocumentService implements HodDocumentsService { @Override @Cacheable(value = FindCacheNames.DOCUMENTS, cacheResolver = CachingConfiguration.PER_USER_CACHE_RESOLVER_NAME) public Documents<HodSearchResult> queryTextIndex(final HodQueryRequest queryRequest) throws HodErrorException { try { return documentsService.queryTextIndex(queryRequest); } catch (final HodErrorException e) { if (e.getErrorCode() == HodErrorCode.INDEX_NAME_INVALID) { final Boolean publicIndexesEnabled = findConfigService.getConfig().getHod().getPublicIndexesEnabled(); final HodDatabasesRequest databasesRequest = databasesRequestBuilderFactory.getObject().publicIndexesEnabled(publicIndexesEnabled).build(); final Set<Database> updatedDatabases = databasesService.getDatabases(databasesRequest); final QueryRestrictions<ResourceName> queryRestrictions = queryRequest.getQueryRestrictions(); final Set<ResourceName> badIndexes = new HashSet<>(queryRestrictions.getDatabases()); for (final Database database : updatedDatabases) { final ResourceName resourceIdentifier = new ResourceName(database.getDomain(), database.getName()); badIndexes.remove(resourceIdentifier); } final Collection<ResourceName> goodIndexes = new ArrayList<>(queryRestrictions.getDatabases()); goodIndexes.removeAll(badIndexes); final HodQueryRequest queryRequestWithoutBadIndexes = queryRequest.toBuilder() .queryRestrictions(queryRequest.getQueryRestrictions() .toBuilder() .databases(goodIndexes) .build()) .build(); final Documents<HodSearchResult> resultDocuments = documentsService.queryTextIndex(queryRequestWithoutBadIndexes); final Warnings warnings = new Warnings(badIndexes); return new Documents<>( resultDocuments.getDocuments(), resultDocuments.getTotalResults(), resultDocuments.getExpandedQuery(), resultDocuments.getSuggestion(), resultDocuments.getAutoCorrection(), warnings); } else { throw e; } } } @Autowired  FindHodDocumentService(
            final HodDatabasesService databasesService,
            @Qualifier(DOCUMENTS_SERVICE_BEAN_NAME)
            final HodDocumentsService documentsService,
            final ObjectFactory<HodDatabasesRequestBuilder> databasesRequestBuilderFactory,
            final ConfigService<HodFindConfig> configService
    ); @Override @Cacheable(value = FindCacheNames.DOCUMENTS, cacheResolver = CachingConfiguration.PER_USER_CACHE_RESOLVER_NAME) Documents<HodSearchResult> queryTextIndex(final HodQueryRequest queryRequest); @Override @Cacheable(value = FindCacheNames.SIMILAR_DOCUMENTS, cacheResolver = CachingConfiguration.PER_USER_CACHE_RESOLVER_NAME) Documents<HodSearchResult> findSimilar(final HodSuggestRequest suggestRequest); @Override List<HodSearchResult> getDocumentContent(final HodGetContentRequest getContentRequest); @Override String getStateToken(final HodQueryRestrictions queryRestrictions, final int maxResults, final boolean promotions); @Override StateTokenAndResultCount getStateTokenAndResultCount(final HodQueryRestrictions queryRestrictions, final int maxResults, final boolean promotions); }
FindHodDocumentService implements HodDocumentsService { @Override @Cacheable(value = FindCacheNames.DOCUMENTS, cacheResolver = CachingConfiguration.PER_USER_CACHE_RESOLVER_NAME) public Documents<HodSearchResult> queryTextIndex(final HodQueryRequest queryRequest) throws HodErrorException { try { return documentsService.queryTextIndex(queryRequest); } catch (final HodErrorException e) { if (e.getErrorCode() == HodErrorCode.INDEX_NAME_INVALID) { final Boolean publicIndexesEnabled = findConfigService.getConfig().getHod().getPublicIndexesEnabled(); final HodDatabasesRequest databasesRequest = databasesRequestBuilderFactory.getObject().publicIndexesEnabled(publicIndexesEnabled).build(); final Set<Database> updatedDatabases = databasesService.getDatabases(databasesRequest); final QueryRestrictions<ResourceName> queryRestrictions = queryRequest.getQueryRestrictions(); final Set<ResourceName> badIndexes = new HashSet<>(queryRestrictions.getDatabases()); for (final Database database : updatedDatabases) { final ResourceName resourceIdentifier = new ResourceName(database.getDomain(), database.getName()); badIndexes.remove(resourceIdentifier); } final Collection<ResourceName> goodIndexes = new ArrayList<>(queryRestrictions.getDatabases()); goodIndexes.removeAll(badIndexes); final HodQueryRequest queryRequestWithoutBadIndexes = queryRequest.toBuilder() .queryRestrictions(queryRequest.getQueryRestrictions() .toBuilder() .databases(goodIndexes) .build()) .build(); final Documents<HodSearchResult> resultDocuments = documentsService.queryTextIndex(queryRequestWithoutBadIndexes); final Warnings warnings = new Warnings(badIndexes); return new Documents<>( resultDocuments.getDocuments(), resultDocuments.getTotalResults(), resultDocuments.getExpandedQuery(), resultDocuments.getSuggestion(), resultDocuments.getAutoCorrection(), warnings); } else { throw e; } } } @Autowired  FindHodDocumentService(
            final HodDatabasesService databasesService,
            @Qualifier(DOCUMENTS_SERVICE_BEAN_NAME)
            final HodDocumentsService documentsService,
            final ObjectFactory<HodDatabasesRequestBuilder> databasesRequestBuilderFactory,
            final ConfigService<HodFindConfig> configService
    ); @Override @Cacheable(value = FindCacheNames.DOCUMENTS, cacheResolver = CachingConfiguration.PER_USER_CACHE_RESOLVER_NAME) Documents<HodSearchResult> queryTextIndex(final HodQueryRequest queryRequest); @Override @Cacheable(value = FindCacheNames.SIMILAR_DOCUMENTS, cacheResolver = CachingConfiguration.PER_USER_CACHE_RESOLVER_NAME) Documents<HodSearchResult> findSimilar(final HodSuggestRequest suggestRequest); @Override List<HodSearchResult> getDocumentContent(final HodGetContentRequest getContentRequest); @Override String getStateToken(final HodQueryRestrictions queryRestrictions, final int maxResults, final boolean promotions); @Override StateTokenAndResultCount getStateTokenAndResultCount(final HodQueryRestrictions queryRestrictions, final int maxResults, final boolean promotions);  }