Search in sources :

Example 1 with SearchIndexTypeEntity

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

the class SearchIndexServiceImplTest method testCreateSearchIndexEntity.

@Test
public void testCreateSearchIndexEntity() {
    // Create a search index key.
    SearchIndexKey searchIndexKey = new SearchIndexKey(SEARCH_INDEX_NAME);
    // Create a search index create request.
    SearchIndexCreateRequest searchIndexCreateRequest = new SearchIndexCreateRequest(SEARCH_INDEX_TYPE);
    // 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 search index entity from the search index create request.
    SearchIndexEntity searchIndexEntity = searchIndexServiceImpl.createSearchIndexEntity(searchIndexCreateRequest, searchIndexTypeEntity, searchIndexStatusEntity);
    // Verify the external calls.
    verifyNoMoreInteractions(alternateKeyHelper, businessObjectDefinitionDao, businessObjectDefinitionHelper, configurationDaoHelper, searchIndexDao, searchIndexDaoHelper, searchIndexHelperService, searchIndexStatusDaoHelper, searchIndexTypeDaoHelper);
    // Validate the returned object.
    assertNotNull(searchIndexEntity);
    assertNotNull(searchIndexEntity.getType());
    assertEquals(SEARCH_INDEX_TYPE, searchIndexEntity.getType().getCode());
    assertNotNull(searchIndexEntity.getStatus());
    assertEquals(SEARCH_INDEX_STATUS, searchIndexEntity.getStatus().getCode());
    assertNull(searchIndexEntity.getCreatedBy());
    assertNull(searchIndexEntity.getCreatedOn());
    assertNull(searchIndexEntity.getUpdatedBy());
    assertNull(searchIndexEntity.getUpdatedOn());
}
Also used : SearchIndexStatusEntity(org.finra.herd.model.jpa.SearchIndexStatusEntity) SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) SearchIndexTypeEntity(org.finra.herd.model.jpa.SearchIndexTypeEntity) SearchIndexCreateRequest(org.finra.herd.model.api.xml.SearchIndexCreateRequest) SearchIndexEntity(org.finra.herd.model.jpa.SearchIndexEntity) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 2 with SearchIndexTypeEntity

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

the class SearchIndexDaoHelper method getActiveSearchIndex.

/**
 * Fetches the name of the active index for the specified type
 *
 * @param indexType the type of the search index
 * @return the name of the active index
 */
public String getActiveSearchIndex(String indexType) {
    // Get the search index type and ensure it exists.
    SearchIndexTypeEntity searchIndexTypeEntity = searchIndexTypeDaoHelper.getSearchIndexTypeEntity(indexType);
    // Fetch the list of all search index entities for the specified type and get the active entity
    List<SearchIndexEntity> searchIndexEntities = searchIndexDao.getSearchIndexEntities(searchIndexTypeEntity);
    searchIndexEntities = searchIndexEntities.stream().filter(searchIndexEntity -> searchIndexEntity.getActive() != null && searchIndexEntity.getActive().equals(Boolean.TRUE)).collect(Collectors.toList());
    if (searchIndexEntities.size() == 0) {
        throw new ObjectNotFoundException(String.format("No active search index found for type \"%s\".", indexType));
    }
    return searchIndexEntities.get(0).getName();
}
Also used : ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) SearchIndexTypeEntity(org.finra.herd.model.jpa.SearchIndexTypeEntity) SearchIndexEntity(org.finra.herd.model.jpa.SearchIndexEntity)

Example 3 with SearchIndexTypeEntity

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

the class SearchIndexTypeDaoTestHelper method createSearchIndexTypeEntity.

/**
 * Creates and persists a new search index type entity.
 *
 * @param typeCode the code of the search index type
 *
 * @return the newly created search index type entity
 */
public SearchIndexTypeEntity createSearchIndexTypeEntity(String typeCode) {
    SearchIndexTypeEntity searchIndexTypeEntity;
    searchIndexTypeEntity = searchIndexTypeDao.getSearchIndexTypeByCode(typeCode);
    if (searchIndexTypeEntity == null) {
        searchIndexTypeEntity = new SearchIndexTypeEntity();
        searchIndexTypeEntity.setCode(typeCode);
        searchIndexTypeEntity = searchIndexTypeDao.saveAndRefresh(searchIndexTypeEntity);
    }
    return searchIndexTypeEntity;
}
Also used : SearchIndexTypeEntity(org.finra.herd.model.jpa.SearchIndexTypeEntity)

Example 4 with SearchIndexTypeEntity

use of org.finra.herd.model.jpa.SearchIndexTypeEntity 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);
}
Also used : SearchIndexStatusEntity(org.finra.herd.model.jpa.SearchIndexStatusEntity) SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) SearchIndexActivationCreateRequest(org.finra.herd.model.api.xml.SearchIndexActivationCreateRequest) SearchIndex(org.finra.herd.model.api.xml.SearchIndex) SearchIndexTypeEntity(org.finra.herd.model.jpa.SearchIndexTypeEntity) SearchIndexActivation(org.finra.herd.model.api.xml.SearchIndexActivation) Timestamp(java.sql.Timestamp) SearchIndexEntity(org.finra.herd.model.jpa.SearchIndexEntity) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with SearchIndexTypeEntity

use of org.finra.herd.model.jpa.SearchIndexTypeEntity 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);
}
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) SearchIndexCreateRequest(org.finra.herd.model.api.xml.SearchIndexCreateRequest) SearchIndexEntity(org.finra.herd.model.jpa.SearchIndexEntity) Test(org.junit.Test)

Aggregations

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