use of org.finra.herd.model.api.xml.SearchIndex in project herd by FINRAOS.
the class SearchIndexActivationServiceImpl method createSearchIndexActivation.
@Override
public SearchIndexActivation createSearchIndexActivation(SearchIndexActivationCreateRequest request) {
// Validate the request
validateSearchIndexActivationRequest(request);
// Ensure that search index for the specified search index key exists.
SearchIndexEntity searchIndexEntity = searchIndexDaoHelper.getSearchIndexEntity(request.getSearchIndexKey());
// Activate the specified search index entity.
searchIndexDaoHelper.activateSearchIndex(searchIndexEntity);
SearchIndex searchIndex = createSearchIndexFromEntity(searchIndexEntity);
return new SearchIndexActivation(searchIndex.getSearchIndexKey(), searchIndex.getSearchIndexType(), searchIndex.getSearchIndexStatus(), searchIndex.isActive(), searchIndex.getCreatedByUserId(), searchIndex.getCreatedOn(), searchIndex.getLastUpdatedOn());
}
use of org.finra.herd.model.api.xml.SearchIndex in project herd by FINRAOS.
the class SearchIndexServiceImpl method createSearchIndexFromEntity.
/**
* Creates a search index object from the persisted entity.
*
* @param searchIndexEntity the search index entity
*
* @return the search index
*/
protected SearchIndex createSearchIndexFromEntity(SearchIndexEntity searchIndexEntity) {
SearchIndex searchIndex = new SearchIndex();
searchIndex.setSearchIndexKey(new SearchIndexKey(searchIndexEntity.getName()));
searchIndex.setSearchIndexType(searchIndexEntity.getType().getCode());
searchIndex.setSearchIndexStatus(searchIndexEntity.getStatus().getCode());
if (searchIndexEntity.getActive() != null) {
searchIndex.setActive(searchIndexEntity.getActive());
} else {
searchIndex.setActive(Boolean.FALSE);
}
searchIndex.setCreatedByUserId(searchIndexEntity.getCreatedBy());
searchIndex.setCreatedOn(HerdDateUtils.getXMLGregorianCalendarValue(searchIndexEntity.getCreatedOn()));
searchIndex.setLastUpdatedOn(HerdDateUtils.getXMLGregorianCalendarValue(searchIndexEntity.getUpdatedOn()));
return searchIndex;
}
use of org.finra.herd.model.api.xml.SearchIndex in project herd by FINRAOS.
the class SearchIndexServiceImpl method getSearchIndex.
@Override
public SearchIndex getSearchIndex(SearchIndexKey searchIndexKey) {
// Perform validation and trim.
validateSearchIndexKey(searchIndexKey);
// Retrieve and ensure that a search index already exists with the specified key.
SearchIndexEntity searchIndexEntity = searchIndexDaoHelper.getSearchIndexEntity(searchIndexKey);
// Create the search index object from the persisted entity.
SearchIndex searchIndex = createSearchIndexFromEntity(searchIndexEntity);
DocsStats docsStats = indexFunctionsDao.getIndexStats(searchIndexKey.getSearchIndexName());
// Retrieve index settings from the actual search index. A non-existing search index name results in a "no such index" internal server error.
Settings settings = indexFunctionsDao.getIndexSettings(searchIndexKey.getSearchIndexName());
String searchIndexType = searchIndexEntity.getType().getCode();
String documentType = null;
// Currently, only search index for business object definitions and tag are supported.
if (SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name().equalsIgnoreCase(searchIndexType)) {
documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
} else if (SearchIndexTypeEntity.SearchIndexTypes.TAG.name().equalsIgnoreCase(searchIndexType)) {
documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_TAG_DOCUMENT_TYPE, String.class);
} else {
throw new IllegalArgumentException(String.format("Search index type with code \"%s\" is not supported.", searchIndexType));
}
long indexCount = indexFunctionsDao.getNumberOfTypesInIndex(searchIndexKey.getSearchIndexName(), documentType);
// Update the search index statistics.
searchIndex.setSearchIndexStatistics(createSearchIndexStatistics(settings, docsStats, indexCount));
return searchIndex;
}
use of org.finra.herd.model.api.xml.SearchIndex in project herd by FINRAOS.
the class SearchIndexRestControllerTest method testGetSearchIndex.
@Test
public void testGetSearchIndex() {
// Create a search index key.
SearchIndexKey searchIndexKey = new SearchIndexKey(SEARCH_INDEX_NAME);
// Create a search index get response.
SearchIndex searchIndex = new SearchIndex(searchIndexKey, SEARCH_INDEX_TYPE, SEARCH_INDEX_STATUS, SEARCH_INDEX_DEFAULT_ACTIVE_FLAG, NO_SEARCH_INDEX_STATISTICS, USER_ID, CREATED_ON, UPDATED_ON);
// Mock the call to the search index service.
when(searchIndexService.getSearchIndex(searchIndexKey)).thenReturn(searchIndex);
// Get a search index.
SearchIndex response = searchIndexRestController.getSearchIndex(SEARCH_INDEX_NAME);
// Verify the calls.
verify(searchIndexService, times(1)).getSearchIndex(new SearchIndexKey(SEARCH_INDEX_NAME));
// Validate the returned object.
assertEquals(searchIndex, response);
}
use of org.finra.herd.model.api.xml.SearchIndex in project herd by FINRAOS.
the class SearchIndexServiceTest method testGetSearchIndex.
@Test
public void testGetSearchIndex() {
// Create a search index key.
SearchIndexKey searchIndexKey = new SearchIndexKey(SEARCH_INDEX_NAME);
// Create the search index entity.
SearchIndexEntity searchIndexEntity = createTestSearchIndexEntity();
// Mock some of the external call responses.
@SuppressWarnings("unchecked") DocsStats mockedDocsStats = mock(DocsStats.class);
java.util.Map<String, String> map = new HashMap<>();
map.put(IndexMetaData.SETTING_INDEX_UUID, SEARCH_INDEX_STATISTICS_INDEX_UUID);
map.put(IndexMetaData.SETTING_CREATION_DATE, Long.toString(SEARCH_INDEX_STATISTICS_CREATION_DATE.toGregorianCalendar().getTimeInMillis()));
Settings settings = Settings.builder().put(map).build();
// Mock the external calls.
when(alternateKeyHelper.validateStringParameter("Search index name", SEARCH_INDEX_NAME)).thenReturn(SEARCH_INDEX_NAME);
when(searchIndexDaoHelper.getSearchIndexEntity(searchIndexKey)).thenReturn(searchIndexEntity);
when(indexFunctionsDao.getIndexSettings(SEARCH_INDEX_NAME)).thenReturn(settings);
when(indexFunctionsDao.getIndexStats(SEARCH_INDEX_NAME)).thenReturn(mockedDocsStats);
when(mockedDocsStats.getCount()).thenReturn(SEARCH_INDEX_STATISTICS_NUMBER_OF_ACTIVE_DOCUMENTS);
when(mockedDocsStats.getDeleted()).thenReturn(SEARCH_INDEX_STATISTICS_NUMBER_OF_DELETED_DOCUMENTS);
when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("doc");
when(indexFunctionsDao.getNumberOfTypesInIndex(any(), any())).thenReturn(0l);
// Get a search index.
SearchIndex response = searchIndexService.getSearchIndex(searchIndexKey);
// Verify the external calls.
verify(alternateKeyHelper).validateStringParameter("Search index name", SEARCH_INDEX_NAME);
verify(searchIndexDaoHelper).getSearchIndexEntity(searchIndexKey);
verify(mockedDocsStats).getCount();
verify(mockedDocsStats).getDeleted();
verify(indexFunctionsDao).getIndexSettings(SEARCH_INDEX_NAME);
verify(indexFunctionsDao).getIndexStats(SEARCH_INDEX_NAME);
verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
verify(indexFunctionsDao).getNumberOfTypesInIndex(any(), any());
verifyNoMoreInteractions(alternateKeyHelper, businessObjectDefinitionDao, businessObjectDefinitionHelper, configurationDaoHelper, configurationHelper, indexFunctionsDao, searchIndexDao, searchIndexDaoHelper, searchIndexHelperService, searchIndexStatusDaoHelper, searchIndexTypeDaoHelper);
// response.getSearchIndexStatistics().setIndexCreationDate(SEARCH_INDEX_STATISTICS_CREATION_DATE);
// Validate the returned object.
assertEquals(new SearchIndex(searchIndexKey, SEARCH_INDEX_TYPE_BDEF, SEARCH_INDEX_STATUS, SEARCH_INDEX_DEFAULT_ACTIVE_FLAG, new SearchIndexStatistics(SEARCH_INDEX_STATISTICS_CREATION_DATE, SEARCH_INDEX_STATISTICS_NUMBER_OF_ACTIVE_DOCUMENTS, SEARCH_INDEX_STATISTICS_NUMBER_OF_DELETED_DOCUMENTS, SEARCH_INDEX_STATISTICS_INDEX_UUID, 0l), USER_ID, CREATED_ON, UPDATED_ON), response);
}
Aggregations