Search in sources :

Example 21 with SearchIndexEntity

use of org.finra.herd.model.jpa.SearchIndexEntity 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;
}
Also used : SearchIndex(org.finra.herd.model.api.xml.SearchIndex) DocsStats(org.elasticsearch.index.shard.DocsStats) SearchIndexEntity(org.finra.herd.model.jpa.SearchIndexEntity) Settings(org.elasticsearch.common.settings.Settings)

Example 22 with SearchIndexEntity

use of org.finra.herd.model.jpa.SearchIndexEntity in project herd by FINRAOS.

the class SearchIndexServiceTest method createTestSearchIndexEntity.

/**
 * Creates a test search index entity along with the relative database entities.
 *
 * @return the search index entity
 */
private SearchIndexEntity createTestSearchIndexEntity() {
    // Creates a test search index type entity.
    SearchIndexTypeEntity searchIndexTypeEntity = new SearchIndexTypeEntity();
    searchIndexTypeEntity.setCode(SEARCH_INDEX_TYPE_BDEF);
    // Creates a test search index status entity.
    SearchIndexStatusEntity searchIndexStatusEntity = new SearchIndexStatusEntity();
    searchIndexStatusEntity.setCode(SEARCH_INDEX_STATUS);
    // Create 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);
    return searchIndexEntity;
}
Also used : SearchIndexStatusEntity(org.finra.herd.model.jpa.SearchIndexStatusEntity) SearchIndexTypeEntity(org.finra.herd.model.jpa.SearchIndexTypeEntity) Timestamp(java.sql.Timestamp) SearchIndexEntity(org.finra.herd.model.jpa.SearchIndexEntity)

Example 23 with SearchIndexEntity

use of org.finra.herd.model.jpa.SearchIndexEntity 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);
}
Also used : SearchIndexStatistics(org.finra.herd.model.api.xml.SearchIndexStatistics) HashMap(java.util.HashMap) SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) SearchIndex(org.finra.herd.model.api.xml.SearchIndex) DocsStats(org.elasticsearch.index.shard.DocsStats) SearchIndexEntity(org.finra.herd.model.jpa.SearchIndexEntity) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 24 with SearchIndexEntity

use of org.finra.herd.model.jpa.SearchIndexEntity in project herd by FINRAOS.

the class SearchIndexServiceTest method testDeleteSearchIndex.

@Test
public void testDeleteSearchIndex() {
    // Create a search index key.
    SearchIndexKey searchIndexKey = new SearchIndexKey(SEARCH_INDEX_NAME);
    // Create the search index entity.
    SearchIndexEntity searchIndexEntity = createTestSearchIndexEntity();
    // Mock the external calls.
    when(indexFunctionsDao.isIndexExists(any())).thenReturn(true);
    when(alternateKeyHelper.validateStringParameter("Search index name", SEARCH_INDEX_NAME)).thenReturn(SEARCH_INDEX_NAME);
    when(searchIndexDaoHelper.getSearchIndexEntity(searchIndexKey)).thenReturn(searchIndexEntity);
    // Delete a search index.
    SearchIndex response = searchIndexService.deleteSearchIndex(searchIndexKey);
    // Verify the external calls.
    verify(alternateKeyHelper).validateStringParameter("Search index name", SEARCH_INDEX_NAME);
    verify(searchIndexDaoHelper).getSearchIndexEntity(searchIndexKey);
    verify(indexFunctionsDao).isIndexExists(any());
    verify(indexFunctionsDao).deleteIndex(any());
    verify(searchIndexDao).delete(searchIndexEntity);
    verifyNoMoreInteractions(alternateKeyHelper, businessObjectDefinitionDao, businessObjectDefinitionHelper, configurationDaoHelper, configurationHelper, indexFunctionsDao, searchIndexDao, searchIndexDaoHelper, searchIndexHelperService, searchIndexStatusDaoHelper, searchIndexTypeDaoHelper);
    // Validate the returned object.
    assertEquals(new SearchIndex(searchIndexKey, SEARCH_INDEX_TYPE_BDEF, SEARCH_INDEX_STATUS, SEARCH_INDEX_DEFAULT_ACTIVE_FLAG, NO_SEARCH_INDEX_STATISTICS, USER_ID, CREATED_ON, UPDATED_ON), response);
}
Also used : SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) SearchIndex(org.finra.herd.model.api.xml.SearchIndex) SearchIndexEntity(org.finra.herd.model.jpa.SearchIndexEntity) Test(org.junit.Test)

Example 25 with SearchIndexEntity

use of org.finra.herd.model.jpa.SearchIndexEntity in project herd by FINRAOS.

the class SearchIndexServiceImplTest method testCreateSearchIndexFromEntity.

@Test
public void testCreateSearchIndexFromEntity() {
    // Create a search index key.
    SearchIndexKey searchIndexKey = new SearchIndexKey(SEARCH_INDEX_NAME);
    // Creates a test search index type entity.
    SearchIndexTypeEntity searchIndexTypeEntity = new SearchIndexTypeEntity();
    searchIndexTypeEntity.setCode(SEARCH_INDEX_TYPE);
    // Creates a test search index status entity.
    SearchIndexStatusEntity searchIndexStatusEntity = new SearchIndexStatusEntity();
    searchIndexStatusEntity.setCode(SEARCH_INDEX_STATUS);
    // Create 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);
    // Create a search index object from the search index entity.
    SearchIndex searchIndex = searchIndexServiceImpl.createSearchIndexFromEntity(searchIndexEntity);
    // Verify the external calls.
    verifyNoMoreInteractions(alternateKeyHelper, businessObjectDefinitionDao, businessObjectDefinitionHelper, configurationDaoHelper, configurationHelper, searchIndexDao, searchIndexDaoHelper, searchIndexHelperService, searchIndexStatusDaoHelper, searchIndexTypeDaoHelper);
    // Validate the returned object.
    assertEquals(new SearchIndex(searchIndexKey, SEARCH_INDEX_TYPE, SEARCH_INDEX_STATUS, SEARCH_INDEX_DEFAULT_ACTIVE_FLAG, NO_SEARCH_INDEX_STATISTICS, USER_ID, CREATED_ON, UPDATED_ON), searchIndex);
}
Also used : SearchIndexStatusEntity(org.finra.herd.model.jpa.SearchIndexStatusEntity) SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) SearchIndex(org.finra.herd.model.api.xml.SearchIndex) SearchIndexTypeEntity(org.finra.herd.model.jpa.SearchIndexTypeEntity) Timestamp(java.sql.Timestamp) SearchIndexEntity(org.finra.herd.model.jpa.SearchIndexEntity) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Aggregations

SearchIndexEntity (org.finra.herd.model.jpa.SearchIndexEntity)26 Test (org.junit.Test)12 SearchIndexKey (org.finra.herd.model.api.xml.SearchIndexKey)11 SearchIndexTypeEntity (org.finra.herd.model.jpa.SearchIndexTypeEntity)8 SearchIndex (org.finra.herd.model.api.xml.SearchIndex)7 SearchIndexStatusEntity (org.finra.herd.model.jpa.SearchIndexStatusEntity)7 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)6 Timestamp (java.sql.Timestamp)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 Predicate (javax.persistence.criteria.Predicate)2 Settings (org.elasticsearch.common.settings.Settings)2 DocsStats (org.elasticsearch.index.shard.DocsStats)2 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)2 SearchIndexActivation (org.finra.herd.model.api.xml.SearchIndexActivation)2 SearchIndexCreateRequest (org.finra.herd.model.api.xml.SearchIndexCreateRequest)2 SearchIndexValidation (org.finra.herd.model.api.xml.SearchIndexValidation)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 SearchIndexActivationCreateRequest (org.finra.herd.model.api.xml.SearchIndexActivationCreateRequest)1