Search in sources :

Example 1 with SearchIndexValidation

use of org.finra.herd.model.api.xml.SearchIndexValidation in project herd by FINRAOS.

the class SearchIndexValidationServiceImpl method createSearchIndexValidation.

@Override
public SearchIndexValidation createSearchIndexValidation(SearchIndexValidationCreateRequest request) {
    // validate the request
    validateSearchIndexValidationRequest(request);
    // Ensure that search index for the specified search index key exists. Fetch the type
    SearchIndexEntity searchIndexEntity = searchIndexDaoHelper.getSearchIndexEntity(request.getSearchIndexKey());
    String searchIndexType = searchIndexEntity.getType().getCode();
    String indexName = request.getSearchIndexKey().getSearchIndexName();
    boolean sizeCheck = false;
    boolean spotCheckPercentage = false;
    boolean spotCheckMostRecent = false;
    // Currently, only search index for business object definitions and tag are supported.
    if (SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name().equalsIgnoreCase(searchIndexType)) {
        // only perform full validation if specified in the request
        if (BooleanUtils.isTrue(request.isPerformFullSearchIndexValidation())) {
            businessObjectDefinitionService.indexValidateAllBusinessObjectDefinitions(indexName);
        }
        sizeCheck = businessObjectDefinitionService.indexSizeCheckValidationBusinessObjectDefinitions(indexName);
        spotCheckPercentage = businessObjectDefinitionService.indexSpotCheckPercentageValidationBusinessObjectDefinitions(indexName);
        spotCheckMostRecent = businessObjectDefinitionService.indexSpotCheckMostRecentValidationBusinessObjectDefinitions(indexName);
    } else if (SearchIndexTypeEntity.SearchIndexTypes.TAG.name().equalsIgnoreCase(searchIndexType)) {
        // only perform full validation if specified in the request
        if (BooleanUtils.isTrue(request.isPerformFullSearchIndexValidation())) {
            tagService.indexValidateAllTags(indexName);
        }
        sizeCheck = tagService.indexSizeCheckValidationTags(indexName);
        spotCheckPercentage = tagService.indexSpotCheckPercentageValidationTags(indexName);
        spotCheckMostRecent = tagService.indexSpotCheckMostRecentValidationTags(indexName);
    }
    return new SearchIndexValidation(request.getSearchIndexKey(), getXMLGregorianCalendarValue(new Date()), sizeCheck, spotCheckPercentage, spotCheckMostRecent);
}
Also used : SearchIndexValidation(org.finra.herd.model.api.xml.SearchIndexValidation) SearchIndexEntity(org.finra.herd.model.jpa.SearchIndexEntity) Date(java.util.Date)

Example 2 with SearchIndexValidation

use of org.finra.herd.model.api.xml.SearchIndexValidation 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 3 with SearchIndexValidation

use of org.finra.herd.model.api.xml.SearchIndexValidation in project herd by FINRAOS.

the class SearchIndexValidationRestControllerTest method testCreateSearchIndexValidation.

@Test
public void testCreateSearchIndexValidation() {
    // Create a search index validation create request.
    SearchIndexValidationCreateRequest searchIndexValidationCreateRequest = new SearchIndexValidationCreateRequest(new SearchIndexKey(SEARCH_INDEX_NAME), PERFORM_FULL_SEARCH_INDEX_VALIDATION);
    // Create a search index validation response.
    SearchIndexValidation searchIndexValidation = new SearchIndexValidation(new SearchIndexKey(SEARCH_INDEX_NAME), SEARCH_INDEX_STATISTICS_CREATION_DATE, false, false, false);
    // Mock the call to the search index validation service.
    when(searchIndexValidationService.createSearchIndexValidation(searchIndexValidationCreateRequest)).thenReturn(searchIndexValidation);
    // Create a search index validation.
    SearchIndexValidation response = searchIndexValidationRestController.createSearchIndexValidation(searchIndexValidationCreateRequest);
    // Verify the calls.
    verify(searchIndexValidationService, times(1)).createSearchIndexValidation(searchIndexValidationCreateRequest);
    response.setValidateStartTime(SEARCH_INDEX_STATISTICS_CREATION_DATE);
    // Validate the returned object.
    assertEquals(searchIndexValidation, response);
}
Also used : SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) SearchIndexValidationCreateRequest(org.finra.herd.model.api.xml.SearchIndexValidationCreateRequest) SearchIndexValidation(org.finra.herd.model.api.xml.SearchIndexValidation) Test(org.junit.Test)

Aggregations

SearchIndexValidation (org.finra.herd.model.api.xml.SearchIndexValidation)3 SearchIndexEntity (org.finra.herd.model.jpa.SearchIndexEntity)2 Date (java.util.Date)1 SearchIndexKey (org.finra.herd.model.api.xml.SearchIndexKey)1 SearchIndexValidationCreateRequest (org.finra.herd.model.api.xml.SearchIndexValidationCreateRequest)1 SearchIndexTypeEntity (org.finra.herd.model.jpa.SearchIndexTypeEntity)1 Test (org.junit.Test)1