use of org.finra.herd.model.jpa.SearchIndexStatusEntity in project herd by FINRAOS.
the class SearchIndexStatusDaoHelperTest method testGetSearchIndexStatusEntity.
@Test
public void testGetSearchIndexStatusEntity() {
// Create and persist database entities required for testing.
SearchIndexStatusEntity searchIndexStatusEntity = searchIndexStatusDaoTestHelper.createSearchIndexStatusEntity(SEARCH_INDEX_STATUS);
// Retrieve the search index status entity.
assertEquals(searchIndexStatusEntity, searchIndexStatusDaoHelper.getSearchIndexStatusEntity(SEARCH_INDEX_STATUS));
// Test case insensitivity of the search index status code.
assertEquals(searchIndexStatusEntity, searchIndexStatusDaoHelper.getSearchIndexStatusEntity(SEARCH_INDEX_STATUS.toUpperCase()));
assertEquals(searchIndexStatusEntity, searchIndexStatusDaoHelper.getSearchIndexStatusEntity(SEARCH_INDEX_STATUS.toLowerCase()));
// Try to retrieve a non existing search index status.
try {
searchIndexStatusDaoHelper.getSearchIndexStatusEntity(I_DO_NOT_EXIST);
fail();
} catch (ObjectNotFoundException e) {
assertEquals(String.format("Search index status with code \"%s\" doesn't exist.", I_DO_NOT_EXIST), e.getMessage());
}
}
use of org.finra.herd.model.jpa.SearchIndexStatusEntity in project herd by FINRAOS.
the class SearchIndexStatusDaoImpl method getSearchIndexStatusByCode.
@Override
public SearchIndexStatusEntity getSearchIndexStatusByCode(String code) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<SearchIndexStatusEntity> criteria = builder.createQuery(SearchIndexStatusEntity.class);
// The criteria root is the search index status.
Root<SearchIndexStatusEntity> searchIndexStatusEntityRoot = criteria.from(SearchIndexStatusEntity.class);
// Create the standard restrictions (i.e. the standard where clauses).
Predicate predicate = builder.equal(builder.upper(searchIndexStatusEntityRoot.get(SearchIndexStatusEntity_.code)), code.toUpperCase());
// Add all clauses to the query.
criteria.select(searchIndexStatusEntityRoot).where(predicate);
// Execute the query and return the result.
return executeSingleResultQuery(criteria, String.format("Found more than one search index status with code \"%s\".", code));
}
use of org.finra.herd.model.jpa.SearchIndexStatusEntity 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.SearchIndexStatusEntity 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.SearchIndexStatusEntity 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);
}
Aggregations