Search in sources :

Example 11 with SearchIndexKey

use of org.finra.herd.model.api.xml.SearchIndexKey in project herd by FINRAOS.

the class SearchIndexDaoImpl method getSearchIndexes.

@Override
public List<SearchIndexKey> getSearchIndexes() {
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<String> criteria = builder.createQuery(String.class);
    // The criteria root is the search index.
    Root<SearchIndexEntity> searchIndexEntityRoot = criteria.from(SearchIndexEntity.class);
    // Get the columns.
    Path<String> searchIndexNameColumn = searchIndexEntityRoot.get(SearchIndexEntity_.name);
    // Add all clauses to the query.
    criteria.select(searchIndexNameColumn).orderBy(builder.asc(searchIndexNameColumn));
    // Run the query to get a list of search index names back.
    List<String> searchIndexNames = entityManager.createQuery(criteria).getResultList();
    // Populate the "keys" objects from the returned search index names.
    List<SearchIndexKey> searchIndexKeys = new ArrayList<>();
    for (String searchIndexName : searchIndexNames) {
        searchIndexKeys.add(new SearchIndexKey(searchIndexName));
    }
    // Returned the list of keys.
    return searchIndexKeys;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) ArrayList(java.util.ArrayList) SearchIndexEntity(org.finra.herd.model.jpa.SearchIndexEntity)

Example 12 with SearchIndexKey

use of org.finra.herd.model.api.xml.SearchIndexKey in project herd by FINRAOS.

the class SearchIndexDaoHelperTest method testGetSearchIndexEntity.

@Test
public void testGetSearchIndexEntity() {
    // Create and persist database entities required for testing.
    SearchIndexEntity searchIndexEntity = searchIndexDaoTestHelper.createSearchIndexEntity(SEARCH_INDEX_NAME, SEARCH_INDEX_TYPE, SEARCH_INDEX_STATUS);
    // Retrieve the search index entity.
    assertEquals(searchIndexEntity, searchIndexDaoHelper.getSearchIndexEntity(new SearchIndexKey(SEARCH_INDEX_NAME)));
    // Try to retrieve a non-existing search index.
    try {
        searchIndexDaoHelper.getSearchIndexEntity(new SearchIndexKey(I_DO_NOT_EXIST));
        fail();
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Search index with name \"%s\" doesn't exist.", I_DO_NOT_EXIST), e.getMessage());
    }
}
Also used : SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) SearchIndexEntity(org.finra.herd.model.jpa.SearchIndexEntity) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 13 with SearchIndexKey

use of org.finra.herd.model.api.xml.SearchIndexKey in project herd by FINRAOS.

the class IndexSearchServiceTest method testIndexSearchWithMatch.

@Test
public void testIndexSearchWithMatch() {
    // Create a tag key.
    TagKey tagKey = new TagKey(TAG_TYPE_CODE, TAG_CODE);
    // Create an index search request.
    final IndexSearchRequest indexSearchRequest = new IndexSearchRequest(SEARCH_TERM, ImmutableList.of(new IndexSearchFilter(EXCLUSION_SEARCH_FILTER, ImmutableList.of(new IndexSearchKey(tagKey, NO_INDEX_SEARCH_RESULT_TYPE_KEY))), new IndexSearchFilter(EXCLUSION_SEARCH_FILTER, ImmutableList.of(new IndexSearchKey(NO_TAG_KEY, new IndexSearchResultTypeKey(INDEX_SEARCH_RESULT_TYPE))))), Collections.singletonList(ElasticsearchHelper.TAG_FACET), ENABLE_HIT_HIGHLIGHTING);
    // Create a set of fields.
    final Set<String> fields = Sets.newHashSet(FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION);
    // Create a set of match fields.
    final Set<String> match = Sets.newHashSet(MATCH_COLUMN);
    // Create a new index search result key and populate it with a tag key
    final IndexSearchResultKey indexSearchResultKeyBusinessObjectDefinition = new IndexSearchResultKey(null, new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME));
    // Create a new index search result key and populate it with a tag key
    final IndexSearchResultKey indexSearchResultKeyTag = new IndexSearchResultKey(new TagKey(TAG_TYPE, TAG_CODE), null);
    // Create a new index search results
    final IndexSearchResult indexSearchResultBusinessObjectDefinition = new IndexSearchResult(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name(), new SearchIndexKey(BUSINESS_OBJECT_DEFINITION_SEARCH_INDEX_NAME), indexSearchResultKeyBusinessObjectDefinition, BDEF_DISPLAY_NAME, BDEF_SHORT_DESCRIPTION, null);
    final IndexSearchResult indexSearchResultTag = new IndexSearchResult(SearchIndexTypeEntity.SearchIndexTypes.TAG.name(), new SearchIndexKey(TAG_SEARCH_INDEX_NAME), indexSearchResultKeyTag, TAG_DISPLAY_NAME, TAG_DESCRIPTION, null);
    // Create a list to contain the index search results
    final List<IndexSearchResult> indexSearchResults = new ArrayList<>();
    indexSearchResults.add(indexSearchResultBusinessObjectDefinition);
    indexSearchResults.add(indexSearchResultTag);
    // Construct an index search response
    final IndexSearchResponse indexSearchResponse = new IndexSearchResponse(TOTAL_INDEX_SEARCH_RESULTS, indexSearchResults, null);
    // Construct a search index entity
    SearchIndexTypeEntity searchIndexTypeEntity = new SearchIndexTypeEntity();
    searchIndexTypeEntity.setCode(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
    // Create a tag type entity.
    TagTypeEntity tagTypeEntity = new TagTypeEntity();
    tagTypeEntity.setCode(tagKey.getTagTypeCode());
    // Create a tag entity.
    TagEntity tagEntity = new TagEntity();
    tagEntity.setTagCode(tagKey.getTagCode());
    tagEntity.setTagType(tagTypeEntity);
    // Mock the call to the index search service
    when(tagDaoHelper.getTagEntity(tagKey)).thenReturn(tagEntity);
    when(alternateKeyHelper.validateStringParameter("An", "index search result type", INDEX_SEARCH_RESULT_TYPE)).thenReturn(INDEX_SEARCH_RESULT_TYPE);
    when(searchIndexDaoHelper.getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name())).thenReturn(SEARCH_INDEX_NAME);
    when(searchIndexDaoHelper.getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.TAG.name())).thenReturn(SEARCH_INDEX_NAME_2);
    when(indexSearchDao.indexSearch(indexSearchRequest, fields, match, SEARCH_INDEX_NAME, SEARCH_INDEX_NAME_2)).thenReturn(indexSearchResponse);
    // Call the method under test.
    IndexSearchResponse result = indexSearchService.indexSearch(indexSearchRequest, fields, match);
    // Verify the external calls.
    verify(tagHelper).validateTagKey(tagKey);
    verify(tagDaoHelper).getTagEntity(tagKey);
    verify(alternateKeyHelper).validateStringParameter("An", "index search result type", INDEX_SEARCH_RESULT_TYPE);
    verify(searchIndexTypeDaoHelper).getSearchIndexTypeEntity(INDEX_SEARCH_RESULT_TYPE);
    verify(indexSearchDao).indexSearch(indexSearchRequest, fields, match, SEARCH_INDEX_NAME, SEARCH_INDEX_NAME_2);
    verify(searchIndexDaoHelper).getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
    verify(searchIndexDaoHelper).getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.TAG.name());
    verifyNoMoreInteractionsHelper();
    // Validate the result.
    assertEquals(indexSearchResponse, result);
}
Also used : IndexSearchKey(org.finra.herd.model.api.xml.IndexSearchKey) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) ArrayList(java.util.ArrayList) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) IndexSearchResultTypeKey(org.finra.herd.model.api.xml.IndexSearchResultTypeKey) IndexSearchRequest(org.finra.herd.model.api.xml.IndexSearchRequest) SearchIndexTypeEntity(org.finra.herd.model.jpa.SearchIndexTypeEntity) IndexSearchResultKey(org.finra.herd.model.api.xml.IndexSearchResultKey) SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) TagEntity(org.finra.herd.model.jpa.TagEntity) IndexSearchResponse(org.finra.herd.model.api.xml.IndexSearchResponse) TagKey(org.finra.herd.model.api.xml.TagKey) IndexSearchResult(org.finra.herd.model.api.xml.IndexSearchResult) IndexSearchFilter(org.finra.herd.model.api.xml.IndexSearchFilter) Test(org.junit.Test)

Example 14 with SearchIndexKey

use of org.finra.herd.model.api.xml.SearchIndexKey in project herd by FINRAOS.

the class IndexSearchServiceTest method testIndexSearch.

@Test
public void testIndexSearch() {
    // Create a tag key.
    TagKey tagKey = new TagKey(TAG_TYPE_CODE, TAG_CODE);
    // Create an index search request.
    final IndexSearchRequest indexSearchRequest = new IndexSearchRequest(SEARCH_TERM, ImmutableList.of(new IndexSearchFilter(EXCLUSION_SEARCH_FILTER, ImmutableList.of(new IndexSearchKey(tagKey, NO_INDEX_SEARCH_RESULT_TYPE_KEY))), new IndexSearchFilter(EXCLUSION_SEARCH_FILTER, ImmutableList.of(new IndexSearchKey(NO_TAG_KEY, new IndexSearchResultTypeKey(INDEX_SEARCH_RESULT_TYPE))))), Collections.singletonList(ElasticsearchHelper.TAG_FACET), ENABLE_HIT_HIGHLIGHTING);
    // Create a set of fields.
    final Set<String> fields = Sets.newHashSet(FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION);
    // Create a new index search result key and populate it with a tag key
    final IndexSearchResultKey indexSearchResultKeyBusinessObjectDefinition = new IndexSearchResultKey(null, new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME));
    // Create a new index search result key and populate it with a tag key
    final IndexSearchResultKey indexSearchResultKeyTag = new IndexSearchResultKey(new TagKey(TAG_TYPE, TAG_CODE), null);
    // Create a new index search results
    final IndexSearchResult indexSearchResultBusinessObjectDefinition = new IndexSearchResult(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name(), new SearchIndexKey(BUSINESS_OBJECT_DEFINITION_SEARCH_INDEX_NAME), indexSearchResultKeyBusinessObjectDefinition, BDEF_DISPLAY_NAME, BDEF_SHORT_DESCRIPTION, null);
    final IndexSearchResult indexSearchResultTag = new IndexSearchResult(SearchIndexTypeEntity.SearchIndexTypes.TAG.name(), new SearchIndexKey(TAG_SEARCH_INDEX_NAME), indexSearchResultKeyTag, TAG_DISPLAY_NAME, TAG_DESCRIPTION, null);
    // Create a list to contain the index search results
    final List<IndexSearchResult> indexSearchResults = new ArrayList<>();
    indexSearchResults.add(indexSearchResultBusinessObjectDefinition);
    indexSearchResults.add(indexSearchResultTag);
    // Construct an index search response
    final IndexSearchResponse indexSearchResponse = new IndexSearchResponse(TOTAL_INDEX_SEARCH_RESULTS, indexSearchResults, null);
    // Construct a search index entity
    SearchIndexTypeEntity searchIndexTypeEntity = new SearchIndexTypeEntity();
    searchIndexTypeEntity.setCode(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
    // Create a tag type entity.
    TagTypeEntity tagTypeEntity = new TagTypeEntity();
    tagTypeEntity.setCode(tagKey.getTagTypeCode());
    // Create a tag entity.
    TagEntity tagEntity = new TagEntity();
    tagEntity.setTagCode(tagKey.getTagCode());
    tagEntity.setTagType(tagTypeEntity);
    // Mock the call to the index search service
    when(tagDaoHelper.getTagEntity(tagKey)).thenReturn(tagEntity);
    when(alternateKeyHelper.validateStringParameter("An", "index search result type", INDEX_SEARCH_RESULT_TYPE)).thenReturn(INDEX_SEARCH_RESULT_TYPE);
    when(searchIndexDaoHelper.getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name())).thenReturn(SEARCH_INDEX_NAME);
    when(searchIndexDaoHelper.getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.TAG.name())).thenReturn(SEARCH_INDEX_NAME_2);
    when(indexSearchDao.indexSearch(indexSearchRequest, fields, NO_MATCH, SEARCH_INDEX_NAME, SEARCH_INDEX_NAME_2)).thenReturn(indexSearchResponse);
    // Call the method under test.
    IndexSearchResponse result = indexSearchService.indexSearch(indexSearchRequest, fields, NO_MATCH);
    // Verify the external calls.
    verify(tagHelper).validateTagKey(tagKey);
    verify(tagDaoHelper).getTagEntity(tagKey);
    verify(alternateKeyHelper).validateStringParameter("An", "index search result type", INDEX_SEARCH_RESULT_TYPE);
    verify(searchIndexTypeDaoHelper).getSearchIndexTypeEntity(INDEX_SEARCH_RESULT_TYPE);
    verify(indexSearchDao).indexSearch(indexSearchRequest, fields, NO_MATCH, SEARCH_INDEX_NAME, SEARCH_INDEX_NAME_2);
    verify(searchIndexDaoHelper).getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
    verify(searchIndexDaoHelper).getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.TAG.name());
    verifyNoMoreInteractionsHelper();
    // Validate the result.
    assertEquals(indexSearchResponse, result);
}
Also used : IndexSearchKey(org.finra.herd.model.api.xml.IndexSearchKey) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) ArrayList(java.util.ArrayList) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) IndexSearchResultTypeKey(org.finra.herd.model.api.xml.IndexSearchResultTypeKey) IndexSearchRequest(org.finra.herd.model.api.xml.IndexSearchRequest) SearchIndexTypeEntity(org.finra.herd.model.jpa.SearchIndexTypeEntity) IndexSearchResultKey(org.finra.herd.model.api.xml.IndexSearchResultKey) SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) TagEntity(org.finra.herd.model.jpa.TagEntity) IndexSearchResponse(org.finra.herd.model.api.xml.IndexSearchResponse) TagKey(org.finra.herd.model.api.xml.TagKey) IndexSearchResult(org.finra.herd.model.api.xml.IndexSearchResult) IndexSearchFilter(org.finra.herd.model.api.xml.IndexSearchFilter) Test(org.junit.Test)

Example 15 with SearchIndexKey

use of org.finra.herd.model.api.xml.SearchIndexKey in project herd by FINRAOS.

the class IndexSearchServiceTest method testIndexSearchMissingOptionalParameters.

@Test
public void testIndexSearchMissingOptionalParameters() {
    // Create an index search request.
    final IndexSearchRequest indexSearchRequest = new IndexSearchRequest(SEARCH_TERM, NO_INDEX_SEARCH_FILTERS, NO_INDEX_SEARCH_FACET_FIELDS, NO_ENABLE_HIT_HIGHLIGHTING);
    // Create a new index search result key and populate it with a tag key
    final IndexSearchResultKey indexSearchResultKeyBusinessObjectDefinition = new IndexSearchResultKey(null, new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME));
    // Create a new index search result key and populate it with a tag key
    final IndexSearchResultKey indexSearchResultKeyTag = new IndexSearchResultKey(new TagKey(TAG_TYPE, TAG_CODE), null);
    // Create a new index search results
    final IndexSearchResult indexSearchResultBusinessObjectDefinition = new IndexSearchResult(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name(), new SearchIndexKey(BUSINESS_OBJECT_DEFINITION_SEARCH_INDEX_NAME), indexSearchResultKeyBusinessObjectDefinition, BDEF_DISPLAY_NAME, BDEF_SHORT_DESCRIPTION, null);
    final IndexSearchResult indexSearchResultTag = new IndexSearchResult(SearchIndexTypeEntity.SearchIndexTypes.TAG.name(), new SearchIndexKey(TAG_SEARCH_INDEX_NAME), indexSearchResultKeyTag, TAG_DISPLAY_NAME, TAG_DESCRIPTION, null);
    // Create a list to contain the index search results
    final List<IndexSearchResult> indexSearchResults = new ArrayList<>();
    indexSearchResults.add(indexSearchResultBusinessObjectDefinition);
    indexSearchResults.add(indexSearchResultTag);
    // Construct an index search response
    final IndexSearchResponse indexSearchResponse = new IndexSearchResponse(TOTAL_INDEX_SEARCH_RESULTS, indexSearchResults, null);
    // Construct a search index entity
    SearchIndexTypeEntity searchIndexTypeEntity = new SearchIndexTypeEntity();
    searchIndexTypeEntity.setCode(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
    // Mock the call to the index search service
    when(searchIndexDaoHelper.getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name())).thenReturn(SEARCH_INDEX_NAME);
    when(searchIndexDaoHelper.getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.TAG.name())).thenReturn(SEARCH_INDEX_NAME_2);
    when(indexSearchDao.indexSearch(indexSearchRequest, NO_FIELDS, NO_MATCH, SEARCH_INDEX_NAME, SEARCH_INDEX_NAME_2)).thenReturn(indexSearchResponse);
    // Call the method under test.
    IndexSearchResponse result = indexSearchService.indexSearch(indexSearchRequest, NO_FIELDS, NO_MATCH);
    // Verify the external calls.
    verify(indexSearchDao).indexSearch(indexSearchRequest, NO_FIELDS, NO_MATCH, SEARCH_INDEX_NAME, SEARCH_INDEX_NAME_2);
    verify(searchIndexDaoHelper).getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
    verify(searchIndexDaoHelper).getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.TAG.name());
    verifyNoMoreInteractionsHelper();
    // Validate the result.
    assertEquals(indexSearchResponse, result);
}
Also used : BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) IndexSearchResponse(org.finra.herd.model.api.xml.IndexSearchResponse) TagKey(org.finra.herd.model.api.xml.TagKey) ArrayList(java.util.ArrayList) IndexSearchResult(org.finra.herd.model.api.xml.IndexSearchResult) IndexSearchRequest(org.finra.herd.model.api.xml.IndexSearchRequest) SearchIndexTypeEntity(org.finra.herd.model.jpa.SearchIndexTypeEntity) IndexSearchResultKey(org.finra.herd.model.api.xml.IndexSearchResultKey) Test(org.junit.Test)

Aggregations

SearchIndexKey (org.finra.herd.model.api.xml.SearchIndexKey)33 Test (org.junit.Test)28 SearchIndexEntity (org.finra.herd.model.jpa.SearchIndexEntity)11 SearchIndex (org.finra.herd.model.api.xml.SearchIndex)10 SearchIndexTypeEntity (org.finra.herd.model.jpa.SearchIndexTypeEntity)8 ArrayList (java.util.ArrayList)6 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)6 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)5 IndexSearchResult (org.finra.herd.model.api.xml.IndexSearchResult)5 IndexSearchResultKey (org.finra.herd.model.api.xml.IndexSearchResultKey)5 SearchIndexValidationCreateRequest (org.finra.herd.model.api.xml.SearchIndexValidationCreateRequest)5 TagKey (org.finra.herd.model.api.xml.TagKey)5 SearchIndexStatusEntity (org.finra.herd.model.jpa.SearchIndexStatusEntity)5 IndexSearchRequest (org.finra.herd.model.api.xml.IndexSearchRequest)4 IndexSearchResponse (org.finra.herd.model.api.xml.IndexSearchResponse)4 Timestamp (java.sql.Timestamp)3 IndexSearchFilter (org.finra.herd.model.api.xml.IndexSearchFilter)3 IndexSearchKey (org.finra.herd.model.api.xml.IndexSearchKey)3 IndexSearchResultTypeKey (org.finra.herd.model.api.xml.IndexSearchResultTypeKey)3 SearchIndexCreateRequest (org.finra.herd.model.api.xml.SearchIndexCreateRequest)3