Search in sources :

Example 1 with BusinessObjectDefinitionIndexSearchResponseDto

use of org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto in project herd by FINRAOS.

the class BusinessObjectDefinitionIndexSearchDaoImpl method scrollSearchResultsIntoBusinessObjectDefinitionDto.

/**
 * Private method to handle scrolling through the results from the search request and adding them to a business object definition entity list.
 *
 * @param searchRequestBuilder the the search request to scroll through
 * @param indexName the index name
 * @return list of business object definition entities
 */
private List<BusinessObjectDefinitionIndexSearchResponseDto> scrollSearchResultsIntoBusinessObjectDefinitionDto(final SearchRequestBuilder searchRequestBuilder, String indexName) {
    // Retrieve the search response
    final Search.Builder searchBuilder = new Search.Builder(searchRequestBuilder.toString()).addIndex(indexName);
    searchBuilder.setParameter(Parameters.SIZE, ELASTIC_SEARCH_SCROLL_PAGE_SIZE);
    searchBuilder.setParameter(Parameters.SCROLL, new TimeValue(ELASTIC_SEARCH_SCROLL_KEEP_ALIVE_TIME).toString());
    JestResult jestResult = jestClientHelper.searchExecute(searchBuilder.build());
    List<BusinessObjectDefinitionIndexSearchResponseDto> businessObjectDefinitionIndexSearchResponseDtoList = new ArrayList<>();
    List<BusinessObjectDefinitionIndexSearchResponseDto> resultList = jestResult.getSourceAsObjectList(BusinessObjectDefinitionIndexSearchResponseDto.class);
    while (resultList.size() != 0) {
        businessObjectDefinitionIndexSearchResponseDtoList.addAll(resultList);
        String scrollId = jestResult.getJsonObject().get(SCROLL_ID).getAsString();
        SearchScroll scroll = new SearchScroll.Builder(scrollId, new TimeValue(ELASTIC_SEARCH_SCROLL_KEEP_ALIVE_TIME).toString()).build();
        jestResult = jestClientHelper.searchScrollExecute(scroll);
        resultList = jestResult.getSourceAsObjectList(BusinessObjectDefinitionIndexSearchResponseDto.class);
    }
    return businessObjectDefinitionIndexSearchResponseDtoList;
}
Also used : SearchScroll(io.searchbox.core.SearchScroll) Search(io.searchbox.core.Search) BusinessObjectDefinitionIndexSearchResponseDto(org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto) ArrayList(java.util.ArrayList) TimeValue(org.elasticsearch.common.unit.TimeValue) JestResult(io.searchbox.client.JestResult)

Example 2 with BusinessObjectDefinitionIndexSearchResponseDto

use of org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto in project herd by FINRAOS.

the class BusinessObjectDefinitionServiceIndexTest method testIndexSearchBusinessObjectDefinitionsWithMultipleTagsWithIsExclusionSearchFilter.

@Test
public void testIndexSearchBusinessObjectDefinitionsWithMultipleTagsWithIsExclusionSearchFilter() {
    // Create new tag keys
    TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE);
    TagKey tagKeyTwo = new TagKey(TAG_TYPE_2, TAG_CODE_2);
    // Create a new business object definition search key for use in the business object definition search key list
    BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKey = new BusinessObjectDefinitionSearchKey(tagKey, NOT_INCLUDE_TAG_HIERARCHY);
    // Create another new business object definition search key for use in the business object definition search key list
    BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKeyTwo = new BusinessObjectDefinitionSearchKey(tagKeyTwo, NOT_INCLUDE_TAG_HIERARCHY);
    // Create a new business object definition search key list with both the tag keys and the include tag hierarchy boolean flag
    List<BusinessObjectDefinitionSearchKey> businessObjectDefinitionSearchKeyList = new ArrayList<>();
    businessObjectDefinitionSearchKeyList.add(businessObjectDefinitionSearchKey);
    businessObjectDefinitionSearchKeyList.add(businessObjectDefinitionSearchKeyTwo);
    // Create a new business object definition search filter list with the new business object definition search key list
    List<BusinessObjectDefinitionSearchFilter> businessObjectDefinitionSearchFilterList = new ArrayList<>();
    businessObjectDefinitionSearchFilterList.add(new BusinessObjectDefinitionSearchFilter(true, businessObjectDefinitionSearchKeyList));
    // Create a new business object definition search request that will be used when testing the index search business object definitions method
    BusinessObjectDefinitionIndexSearchRequest businessObjectDefinitionIndexSearchRequest = new BusinessObjectDefinitionIndexSearchRequest(businessObjectDefinitionSearchFilterList, new ArrayList<>());
    // Create a new fields set that will be used when testing the index search business object definitions method
    Set<String> fields = Sets.newHashSet(FIELD_DATA_PROVIDER_NAME, FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION);
    // Create a tag entity to return from the tag dao helper get tag entity method
    TagEntity tagEntity = new TagEntity();
    tagEntity.setTagCode(TAG_CODE);
    // Create a tag entity to return from the tag dao helper get tag entity method
    TagEntity tagEntityTwo = new TagEntity();
    tagEntity.setTagCode(TAG_CODE_2);
    List<BusinessObjectDefinitionIndexSearchResponseDto> businessObjectDefinitionIndexSearchResponseDtoList = new ArrayList<>();
    BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto1 = new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME), BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, BDEF_NAME, new Namespace(NAMESPACE));
    BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto2 = new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME_2), BDEF_DESCRIPTION_2, BDEF_DISPLAY_NAME_2, BDEF_NAME_2, new Namespace(NAMESPACE));
    businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto1);
    businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto2);
    ElasticsearchResponseDto elasticsearchResponseDto = new ElasticsearchResponseDto();
    elasticsearchResponseDto.setBusinessObjectDefinitionIndexSearchResponseDtos(businessObjectDefinitionIndexSearchResponseDtoList);
    // Mock the call to external methods
    when(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class)).thenReturn(SHORT_DESCRIPTION_LENGTH);
    when(searchIndexDaoHelper.getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF)).thenReturn(SEARCH_INDEX_NAME);
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE);
    when(tagDaoHelper.getTagEntity(businessObjectDefinitionSearchKey.getTagKey())).thenReturn(tagEntity);
    when(tagDaoHelper.getTagEntity(businessObjectDefinitionSearchKeyTwo.getTagKey())).thenReturn(tagEntityTwo);
    when(businessObjectDefinitionIndexSearchDao.searchBusinessObjectDefinitionsByTags(any(), any(), any(), any())).thenReturn(elasticsearchResponseDto);
    // Call the method under test
    BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponse = businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionIndexSearchRequest, fields);
    assertThat("Business object definition service index search business object definitions method response is null, but it should not be.", businessObjectDefinitionSearchResponse, not(nullValue()));
    assertThat("The first business object definition name in the search response is not correct.", businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(0).getBusinessObjectDefinitionName(), is(BDEF_NAME));
    assertThat("The second business object definition name in the search response is not correct.", businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(1).getBusinessObjectDefinitionName(), is(BDEF_NAME_2));
    // Verify the calls to external methods
    verify(configurationHelper, times(2)).getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class);
    verify(searchIndexDaoHelper).getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF);
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
    verify(tagHelper).validateTagKey(businessObjectDefinitionSearchKey.getTagKey());
    verify(tagHelper).validateTagKey(businessObjectDefinitionSearchKeyTwo.getTagKey());
    verify(tagDaoHelper).getTagEntity(businessObjectDefinitionSearchKey.getTagKey());
    verify(tagDaoHelper).getTagEntity(businessObjectDefinitionSearchKeyTwo.getTagKey());
    verify(businessObjectDefinitionIndexSearchDao).searchBusinessObjectDefinitionsByTags(any(), any(), any(), any());
    verifyNoMoreInteractionsHelper();
}
Also used : BusinessObjectDefinitionSearchKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchKey) ArrayList(java.util.ArrayList) BusinessObjectDefinitionIndexSearchRequest(org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchRequest) BusinessObjectDefinitionSearchFilter(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter) Namespace(org.finra.herd.model.dto.Namespace) DataProvider(org.finra.herd.model.dto.DataProvider) TagEntity(org.finra.herd.model.jpa.TagEntity) BusinessObjectDefinitionIndexSearchResponseDto(org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto) TagKey(org.finra.herd.model.api.xml.TagKey) ElasticsearchResponseDto(org.finra.herd.model.dto.ElasticsearchResponseDto) BusinessObjectDefinitionIndexSearchResponse(org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse) Test(org.junit.Test)

Example 3 with BusinessObjectDefinitionIndexSearchResponseDto

use of org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto in project herd by FINRAOS.

the class BusinessObjectDefinitionServiceIndexTest method testIndexSearchBusinessObjectDefinitionsDoNotIncludeTagHierarchy.

@Test
public void testIndexSearchBusinessObjectDefinitionsDoNotIncludeTagHierarchy() {
    // Create a new tag key with a tag type and a tag code
    TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE);
    // Create  a new business object definition search key for use in the business object definition search key list
    BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKey = new BusinessObjectDefinitionSearchKey(tagKey, NOT_INCLUDE_TAG_HIERARCHY);
    // Create a new business object definition search key list with the tag key and the include tag hierarchy boolean flag
    List<BusinessObjectDefinitionSearchKey> businessObjectDefinitionSearchKeyList = new ArrayList<>();
    businessObjectDefinitionSearchKeyList.add(businessObjectDefinitionSearchKey);
    // Create a new business object definition search filter list with the new business object definition search key list
    List<BusinessObjectDefinitionSearchFilter> businessObjectDefinitionSearchFilterList = new ArrayList<>();
    businessObjectDefinitionSearchFilterList.add(new BusinessObjectDefinitionSearchFilter(NO_EXCLUSION_SEARCH_FILTER, businessObjectDefinitionSearchKeyList));
    // Create a new business object definition search request that will be used when testing the index search business object definitions method
    BusinessObjectDefinitionIndexSearchRequest businessObjectDefinitionIndexSearchRequest = new BusinessObjectDefinitionIndexSearchRequest(businessObjectDefinitionSearchFilterList, new ArrayList<>());
    // Create a new fields set that will be used when testing the index search business object definitions method
    Set<String> fields = Sets.newHashSet(FIELD_DATA_PROVIDER_NAME, FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION);
    // Create a tag entity to return from the tag dao helper get tag entity method
    TagEntity tagEntity = new TagEntity();
    tagEntity.setTagCode(TAG_CODE);
    List<BusinessObjectDefinitionIndexSearchResponseDto> businessObjectDefinitionIndexSearchResponseDtoList = new ArrayList<>();
    BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto1 = new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME), BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, BDEF_NAME, new Namespace(NAMESPACE));
    BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto2 = new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME_2), BDEF_DESCRIPTION_2, BDEF_DISPLAY_NAME_2, BDEF_NAME_2, new Namespace(NAMESPACE));
    businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto1);
    businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto2);
    ElasticsearchResponseDto elasticsearchResponseDto = new ElasticsearchResponseDto();
    elasticsearchResponseDto.setBusinessObjectDefinitionIndexSearchResponseDtos(businessObjectDefinitionIndexSearchResponseDtoList);
    // Mock the call to external methods
    when(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class)).thenReturn(SHORT_DESCRIPTION_LENGTH);
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE);
    when(tagDaoHelper.getTagEntity(businessObjectDefinitionSearchKey.getTagKey())).thenReturn(tagEntity);
    when(businessObjectDefinitionIndexSearchDao.searchBusinessObjectDefinitionsByTags(any(), any(), any(), any())).thenReturn(elasticsearchResponseDto);
    // Call the method under test
    BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponse = businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionIndexSearchRequest, fields);
    assertThat("Business object definition service index search business object definitions method response is null, but it should not be.", businessObjectDefinitionSearchResponse, not(nullValue()));
    assertThat("The first business object definition name in the search response is not correct.", businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(0).getBusinessObjectDefinitionName(), is(BDEF_NAME));
    assertThat("The second business object definition name in the search response is not correct.", businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(1).getBusinessObjectDefinitionName(), is(BDEF_NAME_2));
    // Verify the calls to external methods
    verify(configurationHelper, times(2)).getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class);
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
    verify(tagHelper).validateTagKey(tagKey);
    verify(tagDaoHelper).getTagEntity(businessObjectDefinitionSearchKey.getTagKey());
    verify(businessObjectDefinitionIndexSearchDao).searchBusinessObjectDefinitionsByTags(any(), any(), any(), any());
    verifyNoMoreInteractionsHelper();
}
Also used : BusinessObjectDefinitionSearchKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchKey) ArrayList(java.util.ArrayList) BusinessObjectDefinitionIndexSearchRequest(org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchRequest) BusinessObjectDefinitionSearchFilter(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter) Namespace(org.finra.herd.model.dto.Namespace) DataProvider(org.finra.herd.model.dto.DataProvider) TagEntity(org.finra.herd.model.jpa.TagEntity) BusinessObjectDefinitionIndexSearchResponseDto(org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto) TagKey(org.finra.herd.model.api.xml.TagKey) ElasticsearchResponseDto(org.finra.herd.model.dto.ElasticsearchResponseDto) BusinessObjectDefinitionIndexSearchResponse(org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse) Test(org.junit.Test)

Example 4 with BusinessObjectDefinitionIndexSearchResponseDto

use of org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto in project herd by FINRAOS.

the class BusinessObjectDefinitionServiceIndexTest method testIndexSearchBusinessObjectDefinitionsIncludeTagHierarchy.

@Test
public void testIndexSearchBusinessObjectDefinitionsIncludeTagHierarchy() {
    // Create a new tag key with a tag type and a tag code
    TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE);
    // Create  a new business object definition search key for use in the business object definition search key list
    BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKey = new BusinessObjectDefinitionSearchKey(tagKey, INCLUDE_TAG_HIERARCHY);
    // Create a new business object definition search key list with the tag key and the include tag hierarchy boolean flag
    List<BusinessObjectDefinitionSearchKey> businessObjectDefinitionSearchKeyList = new ArrayList<>();
    businessObjectDefinitionSearchKeyList.add(businessObjectDefinitionSearchKey);
    // Create a new business object definition search filter list with the new business object definition search key list
    List<BusinessObjectDefinitionSearchFilter> businessObjectDefinitionSearchFilterList = new ArrayList<>();
    businessObjectDefinitionSearchFilterList.add(new BusinessObjectDefinitionSearchFilter(NO_EXCLUSION_SEARCH_FILTER, businessObjectDefinitionSearchKeyList));
    // Create a new business object definition search request that will be used when testing the index search business object definitions method
    BusinessObjectDefinitionIndexSearchRequest businessObjectDefinitionIndexSearchRequest = new BusinessObjectDefinitionIndexSearchRequest(businessObjectDefinitionSearchFilterList, new ArrayList<>());
    // Create a new fields set that will be used when testing the index search business object definitions method
    Set<String> fields = Sets.newHashSet(FIELD_DATA_PROVIDER_NAME, FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION);
    // Create a tag entity to return from the tag dao helper get tag entity method
    TagEntity tagEntity = new TagEntity();
    tagEntity.setTagCode(TAG_CODE);
    // Create a tag child entity to enter into the tag children entities list
    TagEntity tagChildEntity = new TagEntity();
    tagChildEntity.setTagCode(TAG_CODE_2);
    // Create a tag children entity list to return from the tag dao helper tag children entities method
    List<TagEntity> tagChildrenEntityList = new ArrayList<>();
    tagChildrenEntityList.add(tagChildEntity);
    List<BusinessObjectDefinitionIndexSearchResponseDto> businessObjectDefinitionIndexSearchResponseDtoList = new ArrayList<>();
    BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto1 = new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME), BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, BDEF_NAME, new Namespace(NAMESPACE));
    BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto2 = new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME_2), BDEF_DESCRIPTION_2, BDEF_DISPLAY_NAME_2, BDEF_NAME_2, new Namespace(NAMESPACE));
    businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto1);
    businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto2);
    ElasticsearchResponseDto elasticsearchResponseDto = new ElasticsearchResponseDto();
    elasticsearchResponseDto.setBusinessObjectDefinitionIndexSearchResponseDtos(businessObjectDefinitionIndexSearchResponseDtoList);
    // Mock the call to external methods
    when(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class)).thenReturn(SHORT_DESCRIPTION_LENGTH);
    when(searchIndexDaoHelper.getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF)).thenReturn(SEARCH_INDEX_NAME);
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE);
    when(tagDaoHelper.getTagEntity(businessObjectDefinitionSearchKey.getTagKey())).thenReturn(tagEntity);
    when(tagDaoHelper.getTagChildrenEntities(tagEntity)).thenReturn(tagChildrenEntityList);
    when(businessObjectDefinitionIndexSearchDao.searchBusinessObjectDefinitionsByTags(any(), any(), any(), any())).thenReturn(elasticsearchResponseDto);
    // Call the method under test
    BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponse = businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionIndexSearchRequest, fields);
    assertThat("Business object definition service index search business object definitions method response is null, but it should not be.", businessObjectDefinitionSearchResponse, not(nullValue()));
    assertThat("The first business object definition name in the search response is not correct.", businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(0).getBusinessObjectDefinitionName(), is(BDEF_NAME));
    assertThat("The second business object definition name in the search response is not correct.", businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(1).getBusinessObjectDefinitionName(), is(BDEF_NAME_2));
    // Verify the calls to external methods
    verify(configurationHelper, times(2)).getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class);
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
    verify(searchIndexDaoHelper).getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF);
    verify(tagHelper).validateTagKey(tagKey);
    verify(tagDaoHelper).getTagEntity(businessObjectDefinitionSearchKey.getTagKey());
    verify(tagDaoHelper).getTagChildrenEntities(tagEntity);
    verify(businessObjectDefinitionIndexSearchDao).searchBusinessObjectDefinitionsByTags(any(), any(), any(), any());
    verifyNoMoreInteractionsHelper();
}
Also used : BusinessObjectDefinitionSearchKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchKey) ArrayList(java.util.ArrayList) BusinessObjectDefinitionIndexSearchRequest(org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchRequest) BusinessObjectDefinitionSearchFilter(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter) Namespace(org.finra.herd.model.dto.Namespace) DataProvider(org.finra.herd.model.dto.DataProvider) TagEntity(org.finra.herd.model.jpa.TagEntity) BusinessObjectDefinitionIndexSearchResponseDto(org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto) TagKey(org.finra.herd.model.api.xml.TagKey) ElasticsearchResponseDto(org.finra.herd.model.dto.ElasticsearchResponseDto) BusinessObjectDefinitionIndexSearchResponse(org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse) Test(org.junit.Test)

Example 5 with BusinessObjectDefinitionIndexSearchResponseDto

use of org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto in project herd by FINRAOS.

the class BusinessObjectDefinitionIndexSearchDaoTest method testSearchBusinessObjectDefinitionByTagsFunction.

@Test
public void testSearchBusinessObjectDefinitionByTagsFunction() throws Exception {
    SearchResult searchResult = mock(SearchResult.class);
    JestResult jestResult = mock(JestResult.class);
    Terms.Bucket tagTypeCodeBucket = mock(Terms.Bucket.class);
    List<Terms.Bucket> tagTypeCodeBucketList = new ArrayList<>();
    tagTypeCodeBucketList.add(tagTypeCodeBucket);
    // Mock the call to external methods
    when(jestClientHelper.searchExecute(any(Search.class))).thenReturn(searchResult);
    List<TagTypeIndexSearchResponseDto> tagTypeIndexSearchResponseDtoList = new ArrayList<>();
    when(elasticsearchHelper.getNestedTagTagIndexSearchResponseDto(any(SearchResult.class))).thenReturn(tagTypeIndexSearchResponseDtoList);
    List<BusinessObjectDefinitionIndexSearchResponseDto> businessObjectDefinitionIndexSearchResponseDtoList = Arrays.asList(new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider("data provider"), "description 1", "display name", "bdefname", new Namespace("namespace")));
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("_scroll_id", "100");
    when(searchResult.getSourceAsObjectList(BusinessObjectDefinitionIndexSearchResponseDto.class)).thenReturn(businessObjectDefinitionIndexSearchResponseDtoList);
    when(jestClientHelper.searchScrollExecute(any())).thenReturn(jestResult);
    when(searchResult.getJsonObject()).thenReturn(jsonObject);
    // Get test tag entity
    TagEntity tagEntity = new TagEntity();
    tagEntity.setTagCode("TAG_CODE");
    TagTypeEntity tagTypeEntity = new TagTypeEntity();
    tagTypeEntity.setCode("TAG_TYPE_CODE");
    tagTypeEntity.setDisplayName("DISPLAY_NAME");
    tagTypeEntity.setOrderNumber(1);
    tagEntity.setTagType(tagTypeEntity);
    List<TagEntity> tagEntities = new ArrayList<>();
    tagEntities.add(tagEntity);
    // List<Map<SearchFilterType, List<TagEntity>>>
    Map<SearchFilterType, List<TagEntity>> searchFilterTypeListMap = new HashMap<>();
    searchFilterTypeListMap.put(SearchFilterType.INCLUSION_SEARCH_FILTER, tagEntities);
    List<Map<SearchFilterType, List<TagEntity>>> tagEnLists = Collections.singletonList(searchFilterTypeListMap);
    // Call the method under test.
    ElasticsearchResponseDto result = businessObjectDefinitionIndexSearchDao.searchBusinessObjectDefinitionsByTags("INDEX_NAME", "DOCUMENT_TYPE", tagEnLists, new HashSet<>());
    // Verify the external calls.
    verify(jestClientHelper).searchExecute(any());
    // Validate the results.
    assertEquals(new ElasticsearchResponseDto(businessObjectDefinitionIndexSearchResponseDtoList, null, null, null), result);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) JsonObject(com.google.gson.JsonObject) DataProvider(org.finra.herd.model.dto.DataProvider) TagEntity(org.finra.herd.model.jpa.TagEntity) Search(io.searchbox.core.Search) TagTypeIndexSearchResponseDto(org.finra.herd.model.dto.TagTypeIndexSearchResponseDto) ArrayList(java.util.ArrayList) List(java.util.List) JestResult(io.searchbox.client.JestResult) SearchFilterType(org.finra.herd.model.dto.SearchFilterType) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) SearchResult(io.searchbox.core.SearchResult) Namespace(org.finra.herd.model.dto.Namespace) BusinessObjectDefinitionIndexSearchResponseDto(org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto) ElasticsearchResponseDto(org.finra.herd.model.dto.ElasticsearchResponseDto) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)11 BusinessObjectDefinitionIndexSearchResponseDto (org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto)11 ElasticsearchResponseDto (org.finra.herd.model.dto.ElasticsearchResponseDto)10 DataProvider (org.finra.herd.model.dto.DataProvider)9 Namespace (org.finra.herd.model.dto.Namespace)9 TagEntity (org.finra.herd.model.jpa.TagEntity)8 Test (org.junit.Test)8 BusinessObjectDefinitionIndexSearchResponse (org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse)7 BusinessObjectDefinitionSearchFilter (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter)7 BusinessObjectDefinitionIndexSearchRequest (org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchRequest)6 BusinessObjectDefinitionSearchKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchKey)6 TagKey (org.finra.herd.model.api.xml.TagKey)5 TagTypeIndexSearchResponseDto (org.finra.herd.model.dto.TagTypeIndexSearchResponseDto)5 JestResult (io.searchbox.client.JestResult)4 Search (io.searchbox.core.Search)4 JsonObject (com.google.gson.JsonObject)3 SearchResult (io.searchbox.core.SearchResult)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3