Search in sources :

Example 6 with SearchIndexStatusEntity

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());
    }
}
Also used : SearchIndexStatusEntity(org.finra.herd.model.jpa.SearchIndexStatusEntity) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 7 with SearchIndexStatusEntity

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));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SearchIndexStatusEntity(org.finra.herd.model.jpa.SearchIndexStatusEntity) Predicate(javax.persistence.criteria.Predicate)

Example 8 with SearchIndexStatusEntity

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);
}
Also used : SearchIndexStatusEntity(org.finra.herd.model.jpa.SearchIndexStatusEntity) SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) SearchIndexTypeEntity(org.finra.herd.model.jpa.SearchIndexTypeEntity) SearchIndexEntity(org.finra.herd.model.jpa.SearchIndexEntity)

Example 9 with SearchIndexStatusEntity

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;
}
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 10 with SearchIndexStatusEntity

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);
}
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

SearchIndexStatusEntity (org.finra.herd.model.jpa.SearchIndexStatusEntity)10 SearchIndexEntity (org.finra.herd.model.jpa.SearchIndexEntity)7 SearchIndexTypeEntity (org.finra.herd.model.jpa.SearchIndexTypeEntity)6 SearchIndexKey (org.finra.herd.model.api.xml.SearchIndexKey)5 Test (org.junit.Test)5 Timestamp (java.sql.Timestamp)4 SearchIndex (org.finra.herd.model.api.xml.SearchIndex)3 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)3 SearchIndexCreateRequest (org.finra.herd.model.api.xml.SearchIndexCreateRequest)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Predicate (javax.persistence.criteria.Predicate)1 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)1 SearchIndexActivation (org.finra.herd.model.api.xml.SearchIndexActivation)1 SearchIndexActivationCreateRequest (org.finra.herd.model.api.xml.SearchIndexActivationCreateRequest)1 Ignore (org.junit.Ignore)1