use of org.finra.herd.model.api.xml.SearchIndexKey in project herd by FINRAOS.
the class SearchIndexDaoTest method testGetSearchIndexByKey.
@Test
public void testGetSearchIndexByKey() {
// Create database entities required for testing.
SearchIndexEntity searchIndexEntity = searchIndexDaoTestHelper.createSearchIndexEntity(SEARCH_INDEX_NAME, SEARCH_INDEX_TYPE, SEARCH_INDEX_STATUS);
// Retrieve the search index entity and validate the results.
assertEquals(searchIndexEntity, searchIndexDao.getSearchIndexByKey(new SearchIndexKey(SEARCH_INDEX_NAME)));
// Test case sensitivity for the search index name.
assertNull(searchIndexDao.getSearchIndexByKey(new SearchIndexKey(SEARCH_INDEX_NAME.toUpperCase())));
assertNull(searchIndexDao.getSearchIndexByKey(new SearchIndexKey(SEARCH_INDEX_NAME.toLowerCase())));
// Confirm negative results when using non-existing search index name.
assertNull(searchIndexDao.getSearchIndexByKey(new SearchIndexKey("I_DO_NOT_EXIST")));
}
use of org.finra.herd.model.api.xml.SearchIndexKey in project herd by FINRAOS.
the class IndexSearchDaoImpl method buildIndexSearchResults.
/**
* Extracts and builds a list of {@link IndexSearchResult}s from a given {@link SearchResult}
*
* @param fields the specified fields to be included in the response
* @param tagActiveIndex the name of the active tag index
* @param bdefActiveIndex the name of the active business object definition index
* @param searchResult the raw search result returned by the elasticsearch client
* @param isHighlightingEnabled boolean which specifies if highlighting is requested or not
*
* @return A {@link List} of {@link IndexSearchResult} which represent the search response
*/
private List<IndexSearchResult> buildIndexSearchResults(Set<String> fields, String tagActiveIndex, String bdefActiveIndex, SearchResult searchResult, Boolean isHighlightingEnabled) {
final Integer tagShortDescMaxLength = configurationHelper.getProperty(ConfigurationValue.TAG_SHORT_DESCRIPTION_LENGTH, Integer.class);
final Integer businessObjectDefinitionShortDescMaxLength = configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class);
List<IndexSearchResult> indexSearchResults = new ArrayList<>();
final List<SearchResult.Hit<Map, Void>> searchHitList = searchResult.getHits(Map.class);
// For each indexSearch hit
for (final SearchResult.Hit<Map, Void> hit : searchHitList) {
// Get the source map from the indexSearch hit
@SuppressWarnings("unchecked") final Map<String, Object> sourceMap = hit.source;
// Get the index from which this result is from
final String index = hit.index;
// Create a new document to populate with the indexSearch results
final IndexSearchResult indexSearchResult = new IndexSearchResult();
// Populate the results
indexSearchResult.setSearchIndexKey(new SearchIndexKey(index));
if (fields.contains(DISPLAY_NAME_FIELD)) {
indexSearchResult.setDisplayName((String) sourceMap.get(DISPLAY_NAME_SOURCE));
}
// Populate tag index specific key
if (index.equals(tagActiveIndex)) {
if (fields.contains(SHORT_DESCRIPTION_FIELD)) {
indexSearchResult.setShortDescription(HerdStringUtils.getShortDescription((String) sourceMap.get(DESCRIPTION_SOURCE), tagShortDescMaxLength));
}
final TagKey tagKey = new TagKey();
tagKey.setTagCode((String) sourceMap.get(TAG_CODE_SOURCE));
tagKey.setTagTypeCode((String) ((Map) sourceMap.get(TAG_TYPE)).get(CODE));
indexSearchResult.setIndexSearchResultType(SearchIndexTypeEntity.SearchIndexTypes.TAG.name());
indexSearchResult.setIndexSearchResultKey(new IndexSearchResultKey(tagKey, null));
} else // Populate business object definition key
if (index.equals(bdefActiveIndex)) {
if (fields.contains(SHORT_DESCRIPTION_FIELD)) {
indexSearchResult.setShortDescription(HerdStringUtils.getShortDescription((String) sourceMap.get(DESCRIPTION_SOURCE), businessObjectDefinitionShortDescMaxLength));
}
final BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey();
businessObjectDefinitionKey.setNamespace((String) ((Map) sourceMap.get(NAMESPACE)).get(CODE));
businessObjectDefinitionKey.setBusinessObjectDefinitionName((String) sourceMap.get(NAME_SOURCE));
indexSearchResult.setIndexSearchResultType(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
indexSearchResult.setIndexSearchResultKey(new IndexSearchResultKey(null, businessObjectDefinitionKey));
} else {
throw new IllegalStateException(String.format("Search result index name \"%s\" does not match any of the active search indexes. tagActiveIndex=%s bdefActiveIndex=%s", index, tagActiveIndex, bdefActiveIndex));
}
if (BooleanUtils.isTrue(isHighlightingEnabled)) {
// Fetch configured 'tag' values for highlighting
String preTag = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_HIGHLIGHT_PRETAGS);
String postTag = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_HIGHLIGHT_POSTTAGS);
// Extract highlighted content from the search hit and clean html tags except the pre/post-tags as configured
Highlight highlightedContent = extractHighlightedContent(hit, preTag, postTag);
// Set highlighted content in the response element
indexSearchResult.setHighlight(highlightedContent);
}
indexSearchResults.add(indexSearchResult);
}
return indexSearchResults;
}
use of org.finra.herd.model.api.xml.SearchIndexKey in project herd by FINRAOS.
the class SearchIndexActivationServiceTest method testSearchIndexActivation.
@Test
@Ignore
public void testSearchIndexActivation() {
// Get the search index type value.
String searchIndexType = SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name();
SearchIndexTypeEntity searchIndexTypeEntity = new SearchIndexTypeEntity();
searchIndexTypeEntity.setCode(searchIndexType);
// Get the search index status value.
String searchIndexStatus = SearchIndexStatusEntity.SearchIndexStatuses.READY.name();
// Creates a test search index status entity.
SearchIndexStatusEntity searchIndexStatusEntity = new SearchIndexStatusEntity();
searchIndexStatusEntity.setCode(searchIndexStatus);
// Create a search index entity
SearchIndexEntity searchIndexEntity = searchIndexDaoTestHelper.createSearchIndexEntity(SEARCH_INDEX_NAME, searchIndexType, searchIndexStatus);
// Search index key
SearchIndexKey searchIndexKey = new SearchIndexKey(SEARCH_INDEX_NAME);
// Create a search index entity response
SearchIndexEntity responseSearchIndexEntity = new SearchIndexEntity();
responseSearchIndexEntity.setName(SEARCH_INDEX_NAME);
responseSearchIndexEntity.setType(searchIndexTypeEntity);
responseSearchIndexEntity.setActive(Boolean.TRUE);
responseSearchIndexEntity.setCreatedBy(USER_ID);
responseSearchIndexEntity.setCreatedOn(new Timestamp(CREATED_ON.toGregorianCalendar().getTimeInMillis()));
responseSearchIndexEntity.setUpdatedOn(new Timestamp(UPDATED_ON.toGregorianCalendar().getTimeInMillis()));
// Create a search index activation request.
SearchIndexActivationCreateRequest searchIndexActivationCreateRequest = new SearchIndexActivationCreateRequest();
searchIndexActivationCreateRequest.setSearchIndexKey(searchIndexKey);
// Mock the external calls.
when(alternateKeyHelper.validateStringParameter("Search index name", SEARCH_INDEX_NAME)).thenReturn(SEARCH_INDEX_NAME);
when(searchIndexDaoHelper.getSearchIndexEntity(searchIndexKey)).thenReturn(searchIndexEntity);
when(searchIndexDao.getSearchIndexEntities(searchIndexTypeEntity)).thenReturn(Arrays.asList(searchIndexEntity));
when(searchIndexDao.saveAndRefresh(any(SearchIndexEntity.class))).thenReturn(responseSearchIndexEntity);
// Call the method under test.
SearchIndexActivation response = searchIndexActivationService.createSearchIndexActivation(searchIndexActivationCreateRequest);
// Verify the external calls.
verify(alternateKeyHelper).validateStringParameter("Search index name", SEARCH_INDEX_NAME);
verify(searchIndexDaoHelper).getSearchIndexEntity(searchIndexKey);
verify(searchIndexDao).getSearchIndexEntities(searchIndexTypeEntity);
verify(searchIndexDao).saveAndRefresh(any(SearchIndexEntity.class));
verifyNoMoreInteractions(alternateKeyHelper, searchIndexDao, searchIndexDaoHelper);
// Validate the returned object.
assertEquals(new SearchIndex(searchIndexKey, searchIndexType, searchIndexStatus, SEARCH_INDEX_ACTIVE_FLAG, NO_SEARCH_INDEX_STATISTICS, USER_ID, CREATED_ON, UPDATED_ON), response);
}
use of org.finra.herd.model.api.xml.SearchIndexKey in project herd by FINRAOS.
the class SearchIndexServiceTest method testCreateSearchIndex.
@Test
public void testCreateSearchIndex() {
// Create a search index key.
SearchIndexKey searchIndexKey = new SearchIndexKey(SEARCH_INDEX_NAME);
// Get the search index type value.
String searchIndexType = SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name();
// Get the search index status value.
String searchIndexStatus = SearchIndexStatusEntity.SearchIndexStatuses.BUILDING.name();
// Create a search index create request.
SearchIndexCreateRequest searchIndexCreateRequest = new SearchIndexCreateRequest(searchIndexType);
// Creates a test search index type entity.
SearchIndexTypeEntity searchIndexTypeEntity = new SearchIndexTypeEntity();
searchIndexTypeEntity.setCode(searchIndexType);
// Creates a test search index status entity.
SearchIndexStatusEntity searchIndexStatusEntity = new SearchIndexStatusEntity();
searchIndexStatusEntity.setCode(searchIndexStatus);
// Creates a test search index entity.
SearchIndexEntity searchIndexEntity = new SearchIndexEntity();
searchIndexEntity.setName(SEARCH_INDEX_NAME);
searchIndexEntity.setType(searchIndexTypeEntity);
searchIndexEntity.setStatus(searchIndexStatusEntity);
searchIndexEntity.setCreatedBy(USER_ID);
searchIndexEntity.setCreatedOn(new Timestamp(CREATED_ON.toGregorianCalendar().getTimeInMillis()));
searchIndexEntity.setUpdatedOn(new Timestamp(UPDATED_ON.toGregorianCalendar().getTimeInMillis()));
searchIndexEntity.setActive(Boolean.FALSE);
// Mock some of the external call responses.
@SuppressWarnings("unchecked") Future<Void> mockedFuture = mock(Future.class);
// Mock the external calls.
when(alternateKeyHelper.validateStringParameter("Search index type", searchIndexType)).thenReturn(searchIndexType);
when(searchIndexTypeDaoHelper.getSearchIndexTypeEntity(searchIndexType)).thenReturn(searchIndexTypeEntity);
when(searchIndexStatusDaoHelper.getSearchIndexStatusEntity(searchIndexStatus)).thenReturn(searchIndexStatusEntity);
when(searchIndexDao.saveAndRefresh(any(SearchIndexEntity.class))).thenReturn(searchIndexEntity);
when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE);
when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_INDEX_NAME, String.class)).thenReturn(SEARCH_INDEX_ALIAS_BDEF);
when(configurationDaoHelper.getClobProperty(ConfigurationValue.ELASTICSEARCH_BDEF_MAPPINGS_JSON.getKey())).thenReturn(SEARCH_INDEX_MAPPING);
when(configurationDaoHelper.getClobProperty(ConfigurationValue.ELASTICSEARCH_BDEF_SETTINGS_JSON.getKey())).thenReturn(SEARCH_INDEX_SETTINGS);
when(searchIndexHelperService.indexAllBusinessObjectDefinitions(searchIndexKey, SEARCH_INDEX_DOCUMENT_TYPE)).thenReturn(mockedFuture);
// Create a search index.
SearchIndex response = searchIndexService.createSearchIndex(searchIndexCreateRequest);
// Verify the external calls.
verify(alternateKeyHelper).validateStringParameter("Search index type", searchIndexType);
verify(searchIndexTypeDaoHelper).getSearchIndexTypeEntity(searchIndexType);
verify(searchIndexStatusDaoHelper).getSearchIndexStatusEntity(searchIndexStatus);
verify(searchIndexDao).saveAndRefresh(any(SearchIndexEntity.class));
verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
verify(configurationHelper, times(2)).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_INDEX_NAME, String.class);
verify(configurationDaoHelper).getClobProperty(ConfigurationValue.ELASTICSEARCH_BDEF_MAPPINGS_JSON.getKey());
verify(configurationDaoHelper).getClobProperty(ConfigurationValue.ELASTICSEARCH_BDEF_SETTINGS_JSON.getKey());
verify(indexFunctionsDao).createIndex(any(), any(), any(), any(), any());
verify(searchIndexHelperService).indexAllBusinessObjectDefinitions(searchIndexKey, SEARCH_INDEX_DOCUMENT_TYPE);
verifyNoMoreInteractions(alternateKeyHelper, businessObjectDefinitionDao, businessObjectDefinitionHelper, configurationDaoHelper, configurationHelper, indexFunctionsDao, searchIndexDao, searchIndexDaoHelper, searchIndexHelperService, searchIndexStatusDaoHelper, searchIndexTypeDaoHelper);
// Validate the returned object.
assertEquals(new SearchIndex(searchIndexKey, searchIndexType, searchIndexStatus, SEARCH_INDEX_DEFAULT_ACTIVE_FLAG, NO_SEARCH_INDEX_STATISTICS, USER_ID, CREATED_ON, UPDATED_ON), response);
}
use of org.finra.herd.model.api.xml.SearchIndexKey in project herd by FINRAOS.
the class IndexSearchServiceTest method testIndexSearchWithResultTypeFilter.
@Test
public void testIndexSearchWithResultTypeFilter() {
// Create an index search key
final IndexSearchKey indexSearchKey = new IndexSearchKey();
// Create a tag key
final IndexSearchResultTypeKey resultTypeKey = new IndexSearchResultTypeKey(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
indexSearchKey.setIndexSearchResultTypeKey(resultTypeKey);
// Create an index search keys list and add the previously defined key to it
final List<IndexSearchKey> indexSearchKeys = Collections.singletonList(indexSearchKey);
// Create an index search filter with the keys previously defined
final IndexSearchFilter indexSearchFilter = new IndexSearchFilter(EXCLUSION_SEARCH_FILTER, indexSearchKeys);
List<IndexSearchFilter> indexSearchFilters = Collections.singletonList(indexSearchFilter);
// Create index search request
final IndexSearchRequest indexSearchRequest = new IndexSearchRequest(SEARCH_TERM, indexSearchFilters, null, false);
// 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);
// Mock the call to the index search service
when(alternateKeyHelper.validateStringParameter("An", "index search result type", SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name())).thenReturn(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
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(alternateKeyHelper).validateStringParameter("An", "index search result type", SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
verify(searchIndexTypeDaoHelper).getSearchIndexTypeEntity(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
verify(searchIndexDaoHelper).getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
verify(searchIndexDaoHelper).getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.TAG.name());
verify(indexSearchDao).indexSearch(indexSearchRequest, fields, NO_MATCH, SEARCH_INDEX_NAME, SEARCH_INDEX_NAME_2);
verifyNoMoreInteractionsHelper();
// Validate the result.
assertEquals(indexSearchResponse, result);
}
Aggregations