use of org.finra.herd.model.jpa.SearchIndexEntity 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();
}
use of org.finra.herd.model.jpa.SearchIndexEntity 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.jpa.SearchIndexEntity in project herd by FINRAOS.
the class SearchIndexDaoTest method testGetSearchIndexEntities.
@Test
public void testGetSearchIndexEntities() {
// Create database entities required for testing
SearchIndexEntity searchIndexEntity = searchIndexDaoTestHelper.createSearchIndexEntity(SEARCH_INDEX_NAME, SEARCH_INDEX_TYPE, SEARCH_INDEX_STATUS);
SearchIndexEntity searchIndexEntity1 = searchIndexDaoTestHelper.createSearchIndexEntity(SEARCH_INDEX_NAME_2, SEARCH_INDEX_TYPE_2, SEARCH_INDEX_STATUS_2);
// Retrieve the search index keys and validate the results.
assertEquals(Arrays.asList(searchIndexEntity), searchIndexDao.getSearchIndexEntities(searchIndexEntity.getType()));
assertEquals(Arrays.asList(searchIndexEntity1), searchIndexDao.getSearchIndexEntities(searchIndexEntity1.getType()));
}
use of org.finra.herd.model.jpa.SearchIndexEntity in project herd by FINRAOS.
the class SearchIndexDaoTestHelper method createSearchIndexEntity.
/**
* Creates and persists a new search index entity.
*
* @param searchIndexName the name of the search index
* @param typeCode the code of the search index type
* @param statusCode the code of the search index status
*
* @return the newly created search index entity
*/
public SearchIndexEntity createSearchIndexEntity(String searchIndexName, String typeCode, String statusCode) {
SearchIndexEntity searchIndexEntity = new SearchIndexEntity();
searchIndexEntity.setName(searchIndexName);
searchIndexEntity.setType(searchIndexTypeDaoTestHelper.createSearchIndexTypeEntity(typeCode));
searchIndexEntity.setStatus(searchIndexStatusDaoTestHelper.createSearchIndexStatusEntity(statusCode));
return searchIndexDao.saveAndRefresh(searchIndexEntity);
}
use of org.finra.herd.model.jpa.SearchIndexEntity 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);
}
Aggregations