use of org.finra.herd.model.jpa.SearchIndexTypeEntity in project herd by FINRAOS.
the class SearchIndexServiceImpl method createSearchIndex.
@Override
public SearchIndex createSearchIndex(SearchIndexCreateRequest request) {
// Perform validation and trim.
validateSearchIndexCreateRequest(request);
// Get the search index type and ensure it exists.
SearchIndexTypeEntity searchIndexTypeEntity = searchIndexTypeDaoHelper.getSearchIndexTypeEntity(request.getSearchIndexType());
// Get the BUILDING search index status entity and ensure it exists.
SearchIndexStatusEntity searchIndexStatusEntity = searchIndexStatusDaoHelper.getSearchIndexStatusEntity(SearchIndexStatusEntity.SearchIndexStatuses.BUILDING.name());
// Creates the relative search index entity from the request information.
SearchIndexEntity searchIndexEntity = createSearchIndexEntity(request, searchIndexTypeEntity, searchIndexStatusEntity);
// Persist the new entity.
searchIndexEntity = searchIndexDao.saveAndRefresh(searchIndexEntity);
// Create search index key with the auto-generated search index name
SearchIndexKey searchIndexKey = new SearchIndexKey();
searchIndexKey.setSearchIndexName(searchIndexEntity.getName());
// Create the search index.
createSearchIndexHelper(searchIndexKey, searchIndexTypeEntity.getCode());
// Create and return the search index object from the persisted entity.
return createSearchIndexFromEntity(searchIndexEntity);
}
use of org.finra.herd.model.jpa.SearchIndexTypeEntity 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;
}
use of org.finra.herd.model.jpa.SearchIndexTypeEntity 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);
}
use of org.finra.herd.model.jpa.SearchIndexTypeEntity in project herd by FINRAOS.
the class SearchIndexTypeDaoHelperTest method testGetSearchIndexTypeEntity.
@Test
public void testGetSearchIndexTypeEntity() {
// Create and persist database entities required for testing.
SearchIndexTypeEntity searchIndexTypeEntity = searchIndexTypeDaoTestHelper.createSearchIndexTypeEntity(SEARCH_INDEX_TYPE);
// Retrieve the search index type entity.
assertEquals(searchIndexTypeEntity, searchIndexTypeDaoHelper.getSearchIndexTypeEntity(SEARCH_INDEX_TYPE));
// Test case insensitivity of the search index type code.
assertEquals(searchIndexTypeEntity, searchIndexTypeDaoHelper.getSearchIndexTypeEntity(SEARCH_INDEX_TYPE.toUpperCase()));
assertEquals(searchIndexTypeEntity, searchIndexTypeDaoHelper.getSearchIndexTypeEntity(SEARCH_INDEX_TYPE.toLowerCase()));
// Try to retrieve a non existing search index type.
try {
searchIndexTypeDaoHelper.getSearchIndexTypeEntity(I_DO_NOT_EXIST);
fail();
} catch (ObjectNotFoundException e) {
assertEquals(String.format("Search index type with code \"%s\" doesn't exist.", I_DO_NOT_EXIST), e.getMessage());
}
}
Aggregations