Search in sources :

Example 21 with BusinessObjectDefinitionSearchFilter

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

the class BusinessObjectDefinitionServiceIndexTest method indexSearchBusinessObjectDefinitionsFacetFields.

private void indexSearchBusinessObjectDefinitionsFacetFields(List<String> facetFields) {
    // Create a new business object definition search filter list with the new business object definition search key list
    List<BusinessObjectDefinitionSearchFilter> businessObjectDefinitionSearchFilterList = new ArrayList<>();
    // 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, facetFields);
    // 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);
    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);
    List<TagTypeIndexSearchResponseDto> tagTypeIndexSearchResponseDtos = new ArrayList<>();
    List<TagIndexSearchResponseDto> tagIndexSearchResponseDtos = new ArrayList<>();
    tagIndexSearchResponseDtos.add(new TagIndexSearchResponseDto(TAG_CODE, TAG_COUNT, TAG_DISPLAY_NAME));
    tagIndexSearchResponseDtos.add(new TagIndexSearchResponseDto(TAG_CODE_2, TAG_COUNT, TAG_DISPLAY_NAME_2));
    TagTypeIndexSearchResponseDto tagTypeIndexSearchResponseDto = new TagTypeIndexSearchResponseDto(TAG_TYPE, tagIndexSearchResponseDtos, TAG_TYPE_DISPLAY_NAME);
    tagTypeIndexSearchResponseDtos.add(tagTypeIndexSearchResponseDto);
    ElasticsearchResponseDto elasticsearchResponseDto = new ElasticsearchResponseDto();
    elasticsearchResponseDto.setBusinessObjectDefinitionIndexSearchResponseDtos(businessObjectDefinitionIndexSearchResponseDtoList);
    elasticsearchResponseDto.setTagTypeIndexSearchResponseDtos(tagTypeIndexSearchResponseDtos);
    // 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(businessObjectDefinitionIndexSearchDao.findAllBusinessObjectDefinitions(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));
    assertThat("The tag type code in the search response is not correct.", businessObjectDefinitionSearchResponse.getFacets().get(0).getFacetId(), is(TAG_TYPE));
    assertThat("The tag code in the search response is not correct.", businessObjectDefinitionSearchResponse.getFacets().get(0).getFacets().get(0).getFacetId(), is(TAG_CODE));
    // 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(businessObjectDefinitionIndexSearchDao).findAllBusinessObjectDefinitions(any(), any(), any());
    verifyNoMoreInteractionsHelper();
}
Also used : TagIndexSearchResponseDto(org.finra.herd.model.dto.TagIndexSearchResponseDto) 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) BusinessObjectDefinitionIndexSearchResponseDto(org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto) TagTypeIndexSearchResponseDto(org.finra.herd.model.dto.TagTypeIndexSearchResponseDto) ElasticsearchResponseDto(org.finra.herd.model.dto.ElasticsearchResponseDto) BusinessObjectDefinitionIndexSearchResponse(org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse)

Example 22 with BusinessObjectDefinitionSearchFilter

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

the class BusinessObjectDefinitionServiceIndexTest method testIndexSearchBusinessObjectDefinitionReturnsEmptyResponseForEmptyTagEntities.

@Test
public void testIndexSearchBusinessObjectDefinitionReturnsEmptyResponseForEmptyTagEntities() {
    // Create a tag key.
    TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE);
    // Create a tag entity.
    TagEntity tagEntity = new TagEntity();
    // Create  a new business object definition search key for use in the business object definition search key list with an empty tag key
    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<>());
    // 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(tagKey)).thenReturn(tagEntity);
    when(businessObjectDefinitionIndexSearchDao.searchBusinessObjectDefinitionsByTags(any(), any(), any(), any())).thenReturn(new ElasticsearchResponseDto());
    // Call the method under test
    BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponse = businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionIndexSearchRequest, new HashSet<>());
    assertThat("Expected empty response", CollectionUtils.isEmpty(businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions()));
    // Verify the calls to external methods
    verify(searchIndexDaoHelper).getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF);
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
    verify(tagHelper).validateTagKey(tagKey);
    verify(tagDaoHelper).getTagEntity(tagKey);
    verify(businessObjectDefinitionIndexSearchDao).searchBusinessObjectDefinitionsByTags(any(), any(), any(), any());
    verifyNoMoreInteractionsHelper();
}
Also used : BusinessObjectDefinitionSearchKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchKey) TagEntity(org.finra.herd.model.jpa.TagEntity) TagKey(org.finra.herd.model.api.xml.TagKey) ArrayList(java.util.ArrayList) BusinessObjectDefinitionIndexSearchRequest(org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchRequest) ElasticsearchResponseDto(org.finra.herd.model.dto.ElasticsearchResponseDto) BusinessObjectDefinitionIndexSearchResponse(org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse) BusinessObjectDefinitionSearchFilter(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter) Test(org.junit.Test)

Example 23 with BusinessObjectDefinitionSearchFilter

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

the class BusinessObjectDefinitionServiceIndexTest method testIndexSearchBusinessObjectDefinitionsWithMultipleTagsIncludeTagHierarchy.

@Test
public void testIndexSearchBusinessObjectDefinitionsWithMultipleTagsIncludeTagHierarchy() {
    // 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, 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, 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(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 entity to return from the tag dao helper get tag entity method
    TagEntity tagEntityTwo = new TagEntity();
    tagEntity.setTagCode(TAG_CODE_2);
    // 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.getTagEntity(businessObjectDefinitionSearchKeyTwo.getTagKey())).thenReturn(tagEntityTwo);
    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(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(tagDaoHelper).getTagChildrenEntities(tagEntity);
    verify(tagDaoHelper).getTagChildrenEntities(tagEntityTwo);
    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 24 with BusinessObjectDefinitionSearchFilter

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

the class BusinessObjectDefinitionServiceIndexTest method testIndexSearchBusinessObjectDefinitionsInvalidFacet.

@Test
public void testIndexSearchBusinessObjectDefinitionsInvalidFacet() {
    // Create a new business object definition search filter list with the new business object definition search key list
    List<BusinessObjectDefinitionSearchFilter> businessObjectDefinitionSearchFilterList = new ArrayList<>();
    // Create a list of facet fields
    List<String> facetFields = new ArrayList<>();
    facetFields.add("Invalid");
    // 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, facetFields);
    // 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);
    // Mock the call to external methods
    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);
    // Call the method under test
    try {
        businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionIndexSearchRequest, fields);
        fail("Should have caught an exception.");
    } catch (IllegalArgumentException illegalArgumentException) {
        assertThat("The IllegalArgumentException message is not correct.", illegalArgumentException.getMessage(), is("Facet field \"invalid\" is not supported."));
    }
    // Verify the calls to external methods
    verify(searchIndexDaoHelper).getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF);
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
    verifyNoMoreInteractionsHelper();
}
Also used : ArrayList(java.util.ArrayList) BusinessObjectDefinitionIndexSearchRequest(org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchRequest) BusinessObjectDefinitionSearchFilter(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter) Test(org.junit.Test)

Example 25 with BusinessObjectDefinitionSearchFilter

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

the class BusinessObjectDefinitionServiceImpl method indexSearchBusinessObjectDefinitions.

@Override
public BusinessObjectDefinitionIndexSearchResponse indexSearchBusinessObjectDefinitions(BusinessObjectDefinitionIndexSearchRequest searchRequest, Set<String> fieldsRequested) {
    // Get the configured values for index name and document type
    final String indexName = searchIndexDaoHelper.getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
    final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
    // Validate the business object definition search fields
    validateSearchResponseFields(fieldsRequested);
    // Create a new object to hold the search index response
    ElasticsearchResponseDto elasticsearchResponseDto;
    Set<String> facetFields = new HashSet<>();
    if (CollectionUtils.isNotEmpty(searchRequest.getFacetFields())) {
        facetFields.addAll(validateFacetFields(new HashSet<>(searchRequest.getFacetFields())));
    }
    // If the request contains search filters
    if (CollectionUtils.isNotEmpty(searchRequest.getBusinessObjectDefinitionSearchFilters())) {
        // Validate the search request.
        validateBusinessObjectDefinitionIndexSearchRequest(searchRequest);
        List<Map<SearchFilterType, List<TagEntity>>> tagEntitiesPerSearchFilter = new ArrayList<>();
        // Iterate through all search filters and extract tag keys
        for (BusinessObjectDefinitionSearchFilter searchFilter : searchRequest.getBusinessObjectDefinitionSearchFilters()) {
            List<TagEntity> tagEntities = new ArrayList<>();
            Map<SearchFilterType, List<TagEntity>> searchFilterTypeListMap = new HashMap<>();
            if (BooleanUtils.isTrue(searchFilter.isIsExclusionSearchFilter())) {
                searchFilterTypeListMap.put(SearchFilterType.EXCLUSION_SEARCH_FILTER, tagEntities);
                validateExclusionSearchFilter(searchFilter);
            } else {
                searchFilterTypeListMap.put(SearchFilterType.INCLUSION_SEARCH_FILTER, tagEntities);
            }
            for (BusinessObjectDefinitionSearchKey searchKey : searchFilter.getBusinessObjectDefinitionSearchKeys()) {
                // Get the actual tag entity from its key.
                // TODO: bulk fetch tags and their children from the search index after we start indexing tags
                TagEntity tagEntity = tagDaoHelper.getTagEntity(searchKey.getTagKey());
                tagEntities.add(tagEntity);
                // If includeTagHierarchy is true, get list of children tag entities down the hierarchy of the specified tag.
                if (BooleanUtils.isTrue(searchKey.isIncludeTagHierarchy())) {
                    tagEntities.addAll(tagDaoHelper.getTagChildrenEntities(tagEntity));
                }
            }
            // Collect all tag entities and their children (if included) into separate lists
            tagEntitiesPerSearchFilter.add(searchFilterTypeListMap);
        }
        // Use the tag type entities lists to search in the search index for business object definitions
        elasticsearchResponseDto = businessObjectDefinitionIndexSearchDao.searchBusinessObjectDefinitionsByTags(indexName, documentType, tagEntitiesPerSearchFilter, facetFields);
    } else {
        // Else get all of the business object definitions
        elasticsearchResponseDto = businessObjectDefinitionIndexSearchDao.findAllBusinessObjectDefinitions(indexName, documentType, facetFields);
    }
    // Create a list to hold the business object definitions that will be returned as part of the search response
    List<BusinessObjectDefinition> businessObjectDefinitions = new ArrayList<>();
    // Retrieve all unique business object definition entities and construct a list of business object definitions based on the requested fields.
    if (elasticsearchResponseDto.getBusinessObjectDefinitionIndexSearchResponseDtos() != null) {
        for (BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto : ImmutableSet.copyOf(elasticsearchResponseDto.getBusinessObjectDefinitionIndexSearchResponseDtos())) {
            // Convert the business object definition entity to a business object definition and
            // add it to the list of business object definitions that will be
            // returned as a part of the search response
            businessObjectDefinitions.add(createBusinessObjectDefinitionFromDto(businessObjectDefinitionIndexSearchResponseDto, fieldsRequested));
        }
    }
    List<Facet> tagTypeFacets = null;
    if (CollectionUtils.isNotEmpty(searchRequest.getFacetFields()) && elasticsearchResponseDto.getTagTypeIndexSearchResponseDtos() != null) {
        tagTypeFacets = new ArrayList<>();
        // construct a list of facet information
        for (TagTypeIndexSearchResponseDto tagTypeIndexSearchResponseDto : elasticsearchResponseDto.getTagTypeIndexSearchResponseDtos()) {
            List<Facet> tagFacets = new ArrayList<>();
            for (TagIndexSearchResponseDto tagIndexSearchResponseDto : tagTypeIndexSearchResponseDto.getTagIndexSearchResponseDtos()) {
                Facet tagFacet = new Facet(tagIndexSearchResponseDto.getTagDisplayName(), tagIndexSearchResponseDto.getCount(), FacetTypeEnum.TAG.value(), tagIndexSearchResponseDto.getTagCode(), null);
                tagFacets.add(tagFacet);
            }
            tagTypeFacets.add(new Facet(tagTypeIndexSearchResponseDto.getDisplayName(), null, FacetTypeEnum.TAG_TYPE.value(), tagTypeIndexSearchResponseDto.getCode(), tagFacets));
        }
    }
    // Construct business object search response.
    BusinessObjectDefinitionIndexSearchResponse searchResponse = new BusinessObjectDefinitionIndexSearchResponse();
    searchResponse.setBusinessObjectDefinitions(businessObjectDefinitions);
    searchResponse.setFacets(tagTypeFacets);
    return searchResponse;
}
Also used : BusinessObjectDefinitionSearchKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchKey) BusinessObjectDefinition(org.finra.herd.model.api.xml.BusinessObjectDefinition) SearchFilterType(org.finra.herd.model.dto.SearchFilterType) HashMap(java.util.HashMap) TagIndexSearchResponseDto(org.finra.herd.model.dto.TagIndexSearchResponseDto) ArrayList(java.util.ArrayList) BusinessObjectDefinitionSearchFilter(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter) TagEntity(org.finra.herd.model.jpa.TagEntity) BusinessObjectDefinitionIndexSearchResponseDto(org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto) TagTypeIndexSearchResponseDto(org.finra.herd.model.dto.TagTypeIndexSearchResponseDto) List(java.util.List) ArrayList(java.util.ArrayList) ElasticsearchResponseDto(org.finra.herd.model.dto.ElasticsearchResponseDto) BusinessObjectDefinitionIndexSearchResponse(org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Facet(org.finra.herd.model.api.xml.Facet)

Aggregations

BusinessObjectDefinitionSearchFilter (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter)25 BusinessObjectDefinitionSearchKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchKey)23 Test (org.junit.Test)22 TagKey (org.finra.herd.model.api.xml.TagKey)21 BusinessObjectDefinition (org.finra.herd.model.api.xml.BusinessObjectDefinition)14 BusinessObjectDefinitionSearchRequest (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchRequest)13 HashSet (java.util.HashSet)12 BusinessObjectDefinitionSearchResponse (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchResponse)12 ArrayList (java.util.ArrayList)11 BusinessObjectDefinitionIndexSearchRequest (org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchRequest)10 BusinessObjectDefinitionIndexSearchResponse (org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse)10 ElasticsearchResponseDto (org.finra.herd.model.dto.ElasticsearchResponseDto)9 TagEntity (org.finra.herd.model.jpa.TagEntity)8 BusinessObjectDefinitionIndexSearchResponseDto (org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto)7 DataProvider (org.finra.herd.model.dto.DataProvider)6 Namespace (org.finra.herd.model.dto.Namespace)6 TagIndexSearchResponseDto (org.finra.herd.model.dto.TagIndexSearchResponseDto)3 TagTypeIndexSearchResponseDto (org.finra.herd.model.dto.TagTypeIndexSearchResponseDto)3 Facet (org.finra.herd.model.api.xml.Facet)2 HashMap (java.util.HashMap)1