Search in sources :

Example 11 with SearchIndexEntity

use of org.finra.herd.model.jpa.SearchIndexEntity 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)

Example 12 with SearchIndexEntity

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

the class SearchIndexValidationServiceTest method searchIndexValidation.

private void searchIndexValidation(SearchIndexKey searchIndexKey, SearchIndexValidationCreateRequest searchIndexValidationCreateRequest, String searchIndexType) {
    // Create the search index type entity
    SearchIndexTypeEntity searchIndexTypeEntity = new SearchIndexTypeEntity();
    searchIndexTypeEntity.setCode(searchIndexType);
    // Create a search index entity
    SearchIndexEntity searchIndexEntity = new SearchIndexEntity();
    searchIndexEntity.setName(SEARCH_INDEX_NAME);
    searchIndexEntity.setType(searchIndexTypeEntity);
    // validation response
    boolean sizeCheck = ThreadLocalRandom.current().nextDouble() < 0.5;
    boolean spotCheckPercentage = ThreadLocalRandom.current().nextDouble() < 0.5;
    boolean spotCheckMostRecent = ThreadLocalRandom.current().nextDouble() < 0.5;
    // Mock some of the external call responses.
    @SuppressWarnings("unchecked") Future<Void> mockedFuture = mock(Future.class);
    // Mock the external calls.
    when(alternateKeyHelper.validateStringParameter("Search index name", SEARCH_INDEX_NAME)).thenReturn(SEARCH_INDEX_NAME);
    when(searchIndexDaoHelper.getSearchIndexEntity(searchIndexKey)).thenReturn(searchIndexEntity);
    when(businessObjectDefinitionService.indexValidateAllBusinessObjectDefinitions(SEARCH_INDEX_NAME)).thenReturn(new AsyncResult<>(null));
    when(businessObjectDefinitionService.indexSizeCheckValidationBusinessObjectDefinitions(SEARCH_INDEX_NAME)).thenReturn(sizeCheck);
    when(businessObjectDefinitionService.indexSpotCheckPercentageValidationBusinessObjectDefinitions(SEARCH_INDEX_NAME)).thenReturn(spotCheckPercentage);
    when(businessObjectDefinitionService.indexSpotCheckMostRecentValidationBusinessObjectDefinitions(SEARCH_INDEX_NAME)).thenReturn(spotCheckMostRecent);
    when(tagService.indexValidateAllTags(SEARCH_INDEX_NAME)).thenReturn(new AsyncResult<>(null));
    when(tagService.indexSizeCheckValidationTags(SEARCH_INDEX_NAME)).thenReturn(sizeCheck);
    when(tagService.indexSpotCheckPercentageValidationTags(SEARCH_INDEX_NAME)).thenReturn(spotCheckPercentage);
    when(tagService.indexSpotCheckMostRecentValidationTags(SEARCH_INDEX_NAME)).thenReturn(spotCheckMostRecent);
    // Create a search index.
    SearchIndexValidation response = searchIndexValidationService.createSearchIndexValidation(searchIndexValidationCreateRequest);
    // Verify the external calls.
    verify(alternateKeyHelper).validateStringParameter("Search index name", SEARCH_INDEX_NAME);
    verify(searchIndexDaoHelper).getSearchIndexEntity(searchIndexKey);
    if (searchIndexType.equals(SearchIndexTypeEntity.SearchIndexTypes.TAG.name())) {
        // verify that full validation is invoked only if specified in the request
        if (searchIndexValidationCreateRequest.isPerformFullSearchIndexValidation()) {
            verify(tagService, times(1)).indexValidateAllTags(SEARCH_INDEX_NAME);
        } else {
            verify(tagService, times(0)).indexValidateAllTags(SEARCH_INDEX_NAME);
        }
        verify(tagService).indexSizeCheckValidationTags(SEARCH_INDEX_NAME);
        verify(tagService).indexSpotCheckPercentageValidationTags(SEARCH_INDEX_NAME);
        verify(tagService).indexSpotCheckMostRecentValidationTags(SEARCH_INDEX_NAME);
        verifyNoMoreInteractions(alternateKeyHelper, searchIndexDaoHelper, tagService);
        // Validate the returned object.
        assertEquals(new SearchIndexValidation(searchIndexKey, response.getValidateStartTime(), sizeCheck, spotCheckPercentage, spotCheckMostRecent), response);
    } else {
        // verify that full validation is invoked only if specified in the request
        if (searchIndexValidationCreateRequest.isPerformFullSearchIndexValidation()) {
            verify(businessObjectDefinitionService, times(1)).indexValidateAllBusinessObjectDefinitions(SEARCH_INDEX_NAME);
        } else {
            verify(businessObjectDefinitionService, times(0)).indexValidateAllBusinessObjectDefinitions(SEARCH_INDEX_NAME);
        }
        verify(businessObjectDefinitionService).indexSizeCheckValidationBusinessObjectDefinitions(SEARCH_INDEX_NAME);
        verify(businessObjectDefinitionService).indexSpotCheckPercentageValidationBusinessObjectDefinitions(SEARCH_INDEX_NAME);
        verify(businessObjectDefinitionService).indexSpotCheckMostRecentValidationBusinessObjectDefinitions(SEARCH_INDEX_NAME);
        verifyNoMoreInteractions(alternateKeyHelper, searchIndexDaoHelper, businessObjectDefinitionService);
        // Validate the returned object.
        assertEquals(new SearchIndexValidation(searchIndexKey, response.getValidateStartTime(), sizeCheck, spotCheckPercentage, spotCheckMostRecent), response);
    }
}
Also used : SearchIndexTypeEntity(org.finra.herd.model.jpa.SearchIndexTypeEntity) SearchIndexValidation(org.finra.herd.model.api.xml.SearchIndexValidation) SearchIndexEntity(org.finra.herd.model.jpa.SearchIndexEntity)

Example 13 with SearchIndexEntity

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

the class SearchIndexDaoImpl method getSearchIndexByKey.

@Override
public SearchIndexEntity getSearchIndexByKey(SearchIndexKey searchIndexKey) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<SearchIndexEntity> criteria = builder.createQuery(SearchIndexEntity.class);
    // The criteria root is the search index.
    Root<SearchIndexEntity> elasticsearchIndexEntityRoot = criteria.from(SearchIndexEntity.class);
    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate predicate = builder.equal(elasticsearchIndexEntityRoot.get(SearchIndexEntity_.name), searchIndexKey.getSearchIndexName());
    // Add all clauses to the query.
    criteria.select(elasticsearchIndexEntityRoot).where(predicate);
    // Execute the query and return the result.
    return executeSingleResultQuery(criteria, String.format("Found more than one search index with name \"%s\".", searchIndexKey.getSearchIndexName()));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SearchIndexEntity(org.finra.herd.model.jpa.SearchIndexEntity) Predicate(javax.persistence.criteria.Predicate)

Example 14 with SearchIndexEntity

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

the class SearchIndexDaoImpl method getSearchIndexEntities.

@Override
public List<SearchIndexEntity> getSearchIndexEntities(SearchIndexTypeEntity searchIndexTypeEntity) {
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<SearchIndexEntity> criteria = builder.createQuery(SearchIndexEntity.class);
    // The criteria root is the search index.
    Root<SearchIndexEntity> searchIndexEntityRoot = criteria.from(SearchIndexEntity.class);
    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate predicate = builder.equal(searchIndexEntityRoot.get(SearchIndexEntity_.type), searchIndexTypeEntity);
    // Add all clauses to the query.
    criteria.select(searchIndexEntityRoot).where(predicate);
    // Return the list of entities.
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SearchIndexEntity(org.finra.herd.model.jpa.SearchIndexEntity) Predicate(javax.persistence.criteria.Predicate)

Example 15 with SearchIndexEntity

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

the class SearchIndexDaoImpl method getSearchIndexes.

@Override
public List<SearchIndexKey> getSearchIndexes() {
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<String> criteria = builder.createQuery(String.class);
    // The criteria root is the search index.
    Root<SearchIndexEntity> searchIndexEntityRoot = criteria.from(SearchIndexEntity.class);
    // Get the columns.
    Path<String> searchIndexNameColumn = searchIndexEntityRoot.get(SearchIndexEntity_.name);
    // Add all clauses to the query.
    criteria.select(searchIndexNameColumn).orderBy(builder.asc(searchIndexNameColumn));
    // Run the query to get a list of search index names back.
    List<String> searchIndexNames = entityManager.createQuery(criteria).getResultList();
    // Populate the "keys" objects from the returned search index names.
    List<SearchIndexKey> searchIndexKeys = new ArrayList<>();
    for (String searchIndexName : searchIndexNames) {
        searchIndexKeys.add(new SearchIndexKey(searchIndexName));
    }
    // Returned the list of keys.
    return searchIndexKeys;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) ArrayList(java.util.ArrayList) SearchIndexEntity(org.finra.herd.model.jpa.SearchIndexEntity)

Aggregations

SearchIndexEntity (org.finra.herd.model.jpa.SearchIndexEntity)26 Test (org.junit.Test)12 SearchIndexKey (org.finra.herd.model.api.xml.SearchIndexKey)11 SearchIndexTypeEntity (org.finra.herd.model.jpa.SearchIndexTypeEntity)8 SearchIndex (org.finra.herd.model.api.xml.SearchIndex)7 SearchIndexStatusEntity (org.finra.herd.model.jpa.SearchIndexStatusEntity)7 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)6 Timestamp (java.sql.Timestamp)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 Predicate (javax.persistence.criteria.Predicate)2 Settings (org.elasticsearch.common.settings.Settings)2 DocsStats (org.elasticsearch.index.shard.DocsStats)2 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)2 SearchIndexActivation (org.finra.herd.model.api.xml.SearchIndexActivation)2 SearchIndexCreateRequest (org.finra.herd.model.api.xml.SearchIndexCreateRequest)2 SearchIndexValidation (org.finra.herd.model.api.xml.SearchIndexValidation)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 SearchIndexActivationCreateRequest (org.finra.herd.model.api.xml.SearchIndexActivationCreateRequest)1