Search in sources :

Example 6 with TagIndexSearchResponseDto

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

the class ElasticsearchHelper method createTagTypeFacet.

/**
 * create tag index search response facet
 *
 * @param tagTypeIndexSearchResponseDto response dto
 *
 * @return tag type facet
 */
private Facet createTagTypeFacet(TagTypeIndexSearchResponseDto tagTypeIndexSearchResponseDto) {
    List<Facet> tagFacets = new ArrayList<>();
    if (tagTypeIndexSearchResponseDto.getTagIndexSearchResponseDtos() != null) {
        for (TagIndexSearchResponseDto tagIndexSearchResponseDto : tagTypeIndexSearchResponseDto.getTagIndexSearchResponseDtos()) {
            long facetCount = tagIndexSearchResponseDto.getCount();
            Facet tagFacet = new Facet(tagIndexSearchResponseDto.getTagDisplayName(), facetCount, FacetTypeEnum.TAG.value(), tagIndexSearchResponseDto.getTagCode(), null);
            tagFacets.add(tagFacet);
        }
    }
    return new Facet(tagTypeIndexSearchResponseDto.getDisplayName(), null, FacetTypeEnum.TAG_TYPE.value(), tagTypeIndexSearchResponseDto.getCode(), tagFacets);
}
Also used : TagIndexSearchResponseDto(org.finra.herd.model.dto.TagIndexSearchResponseDto) ArrayList(java.util.ArrayList) Facet(org.finra.herd.model.api.xml.Facet)

Example 7 with TagIndexSearchResponseDto

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

the class ElasticSearchHelperTest method testGetTagTagIndexSearchResponseDto.

@Test
public void testGetTagTagIndexSearchResponseDto() {
    SearchResponse searchResponse = mock(SearchResponse.class);
    Terms terms = mock(Terms.class);
    Aggregations aggregations = mock(Aggregations.class);
    Terms.Bucket tagTypeCodeEntry = mock(Terms.Bucket.class);
    List<Terms.Bucket> tagTypeCodeEntryList = Collections.singletonList(tagTypeCodeEntry);
    when(searchResponse.getAggregations()).thenReturn(aggregations);
    when(aggregations.get(TAG_TYPE_FACET_AGGS)).thenReturn(terms);
    when(terms.getBuckets()).thenReturn(tagTypeCodeEntryList);
    when(tagTypeCodeEntry.getKeyAsString()).thenReturn(TAG_TYPE_CODE);
    when(tagTypeCodeEntry.getAggregations()).thenReturn(aggregations);
    Terms tagTypeDisplayNameAggs = mock(Terms.class);
    Terms.Bucket tagTypeDisplayNameEntry = mock(Terms.Bucket.class);
    List<Terms.Bucket> tagTypeDisplayNameEntryList = Collections.singletonList(tagTypeDisplayNameEntry);
    when(aggregations.get(TAGTYPE_NAME_AGGREGATION)).thenReturn(tagTypeDisplayNameAggs);
    when(tagTypeDisplayNameEntry.getAggregations()).thenReturn(aggregations);
    when(tagTypeDisplayNameAggs.getBuckets()).thenReturn(tagTypeDisplayNameEntryList);
    when(tagTypeDisplayNameEntry.getKeyAsString()).thenReturn(TAG_TYPE_DISPLAY_NAME);
    StringTerms tagCodeAggs = mock(StringTerms.class);
    StringTerms.Bucket tagCodeEntry = mock(StringTerms.Bucket.class);
    List<Terms.Bucket> tagCodeEntryList = Collections.singletonList(tagCodeEntry);
    when(aggregations.get(TAG_CODE_AGGREGATION)).thenReturn(tagCodeAggs);
    when(tagCodeAggs.getBuckets()).thenReturn(tagCodeEntryList);
    when(tagCodeEntry.getAggregations()).thenReturn(aggregations);
    when(tagCodeEntry.getKeyAsString()).thenReturn(TAG_CODE);
    when(tagCodeEntry.getDocCount()).thenReturn((long) TAG_CODE_COUNT);
    Terms tagNameAggs = mock(Terms.class);
    Terms.Bucket tagNameEntry = mock(Terms.Bucket.class);
    List<Terms.Bucket> tagNameEntryList = Collections.singletonList(tagNameEntry);
    when(tagNameEntry.getAggregations()).thenReturn(aggregations);
    when(aggregations.get(TAG_NAME_AGGREGATION)).thenReturn(tagNameAggs);
    when(tagNameAggs.getBuckets()).thenReturn(tagNameEntryList);
    when(tagNameEntry.getKeyAsString()).thenReturn(TAG_DISPLAY_NAME);
    List<TagTypeIndexSearchResponseDto> resultList = elasticsearchHelper.getTagTagIndexSearchResponseDto(searchResponse);
    List<TagTypeIndexSearchResponseDto> expectedList = new ArrayList<>();
    List<TagIndexSearchResponseDto> expectedTagList = new ArrayList<>();
    expectedTagList.add(new TagIndexSearchResponseDto(TAG_CODE, TAG_CODE_COUNT, TAG_DISPLAY_NAME));
    expectedList.add(new TagTypeIndexSearchResponseDto(TAG_TYPE_CODE, expectedTagList, TAG_TYPE_DISPLAY_NAME));
    assertEquals(expectedList, resultList);
}
Also used : Aggregations(org.elasticsearch.search.aggregations.Aggregations) TagIndexSearchResponseDto(org.finra.herd.model.dto.TagIndexSearchResponseDto) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) StringTerms(org.elasticsearch.search.aggregations.bucket.terms.StringTerms) ArrayList(java.util.ArrayList) SearchResponse(org.elasticsearch.action.search.SearchResponse) StringTerms(org.elasticsearch.search.aggregations.bucket.terms.StringTerms) TagTypeIndexSearchResponseDto(org.finra.herd.model.dto.TagTypeIndexSearchResponseDto) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 8 with TagIndexSearchResponseDto

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

the class ElasticSearchHelperTest method testGetFacetsResponseIncludingTag.

@Test
public void testGetFacetsResponseIncludingTag() {
    ElasticsearchResponseDto elasticsearchResponseDto = new ElasticsearchResponseDto();
    List<TagTypeIndexSearchResponseDto> nestTagTypeIndexSearchResponseDtos = new ArrayList<>();
    TagTypeIndexSearchResponseDto tagType1 = new TagTypeIndexSearchResponseDto(TAG_TYPE_CODE, null, TAG_TYPE_DISPLAY_NAME);
    TagTypeIndexSearchResponseDto tagType2 = new TagTypeIndexSearchResponseDto(TAG_TYPE_CODE_2, Collections.singletonList(new TagIndexSearchResponseDto(TAG_CODE, 1, TAG_CODE_DISPLAY_NAME)), TAG_TYPE_DISPLAY_NAME_2);
    nestTagTypeIndexSearchResponseDtos.add(tagType1);
    nestTagTypeIndexSearchResponseDtos.add(tagType2);
    elasticsearchResponseDto.setNestTagTypeIndexSearchResponseDtos(nestTagTypeIndexSearchResponseDtos);
    TagTypeIndexSearchResponseDto tagType3 = new TagTypeIndexSearchResponseDto(TAG_TYPE_CODE_2, Collections.singletonList(new TagIndexSearchResponseDto(TAG_CODE, 1, TAG_CODE_DISPLAY_NAME)), TAG_TYPE_DISPLAY_NAME_2);
    List<TagTypeIndexSearchResponseDto> tagTypeIndexSearchResponseDtos = new ArrayList<>();
    tagTypeIndexSearchResponseDtos.add(tagType3);
    elasticsearchResponseDto.setTagTypeIndexSearchResponseDtos(tagTypeIndexSearchResponseDtos);
    List<Facet> facets = elasticsearchHelper.getFacetsResponse(elasticsearchResponseDto, BUSINESS_OBJECT_DEFINITION_SEARCH_INDEX_NAME, TAG_SEARCH_INDEX_NAME);
    List<Facet> expectedFacets = new ArrayList<>();
    expectedFacets.add(new Facet(TAG_TYPE_DISPLAY_NAME, null, FacetTypeEnum.TAG_TYPE.value(), TAG_TYPE_CODE, new ArrayList<>()));
    List<Facet> tagFacet = new ArrayList<>();
    tagFacet.add(new Facet(TAG_CODE_DISPLAY_NAME, 1L, FacetTypeEnum.TAG.value(), TAG_CODE, null));
    expectedFacets.add(new Facet(TAG_TYPE_DISPLAY_NAME_2, null, FacetTypeEnum.TAG_TYPE.value(), TAG_TYPE_CODE_2, tagFacet));
    assertEquals(expectedFacets, facets);
}
Also used : TagIndexSearchResponseDto(org.finra.herd.model.dto.TagIndexSearchResponseDto) TagTypeIndexSearchResponseDto(org.finra.herd.model.dto.TagTypeIndexSearchResponseDto) ArrayList(java.util.ArrayList) ElasticsearchResponseDto(org.finra.herd.model.dto.ElasticsearchResponseDto) Facet(org.finra.herd.model.api.xml.Facet) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 9 with TagIndexSearchResponseDto

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

the class ElasticsearchHelper method getFacetsResponse.

/**
 * get the facets in the response
 *
 * @param elasticsearchResponseDto elastic search response dto
 * @param bdefActiveIndex the name of the active index for business object definitions
 * @param tagActiveIndex the name os the active index for tags
 *
 * @return facets in the response dto
 */
public List<Facet> getFacetsResponse(ElasticsearchResponseDto elasticsearchResponseDto, final String bdefActiveIndex, final String tagActiveIndex) {
    List<Facet> facets = new ArrayList<>();
    List<Facet> tagTypeFacets;
    if (elasticsearchResponseDto.getNestTagTypeIndexSearchResponseDtos() != null) {
        tagTypeFacets = new ArrayList<>();
        // construct a list of facet information
        for (TagTypeIndexSearchResponseDto tagTypeIndexSearchResponseDto : elasticsearchResponseDto.getNestTagTypeIndexSearchResponseDtos()) {
            tagTypeFacets.add(createTagTypeFacet(tagTypeIndexSearchResponseDto));
        }
        facets.addAll(tagTypeFacets);
    }
    if (elasticsearchResponseDto.getTagTypeIndexSearchResponseDtos() != null) {
        for (TagTypeIndexSearchResponseDto tagTypeIndexDto : elasticsearchResponseDto.getTagTypeIndexSearchResponseDtos()) {
            boolean foundMatchingTagType = false;
            for (Facet tagFacet : facets) {
                if (tagFacet.getFacetId().equals(tagTypeIndexDto.getCode())) {
                    foundMatchingTagType = true;
                    boolean foundMatchingTagCode = false;
                    for (TagIndexSearchResponseDto tagIndexDto : tagTypeIndexDto.getTagIndexSearchResponseDtos()) {
                        for (Facet nestedTagIndexDto : tagFacet.getFacets()) {
                            if (tagIndexDto.getTagCode().equals(nestedTagIndexDto.getFacetId())) {
                                foundMatchingTagCode = true;
                            }
                        }
                        if (!foundMatchingTagCode) {
                            tagFacet.getFacets().add(new Facet(tagIndexDto.getTagDisplayName(), tagIndexDto.getCount(), FacetTypeEnum.TAG.value(), tagIndexDto.getTagCode(), null));
                        }
                    }
                }
            }
            if (!foundMatchingTagType) {
                facets.add(createTagTypeFacet(tagTypeIndexDto));
            }
        }
    }
    if (elasticsearchResponseDto.getResultTypeIndexSearchResponseDtos() != null) {
        List<Facet> resultTypeFacets = new ArrayList<>();
        // construct a list of facet information
        for (ResultTypeIndexSearchResponseDto resultTypeIndexSearchResponseDto : elasticsearchResponseDto.getResultTypeIndexSearchResponseDtos()) {
            String facetId = getSearchIndexType(resultTypeIndexSearchResponseDto.getResultTypeDisplayName(), bdefActiveIndex, tagActiveIndex);
            Facet resultTypeFacet = new Facet(facetId, resultTypeIndexSearchResponseDto.getCount(), FacetTypeEnum.RESULT_TYPE.value(), facetId, null);
            resultTypeFacets.add(resultTypeFacet);
        }
        facets.addAll(resultTypeFacets);
    }
    return facets;
}
Also used : TagIndexSearchResponseDto(org.finra.herd.model.dto.TagIndexSearchResponseDto) ArrayList(java.util.ArrayList) TagTypeIndexSearchResponseDto(org.finra.herd.model.dto.TagTypeIndexSearchResponseDto) ResultTypeIndexSearchResponseDto(org.finra.herd.model.dto.ResultTypeIndexSearchResponseDto) Facet(org.finra.herd.model.api.xml.Facet)

Example 10 with TagIndexSearchResponseDto

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

the class ElasticsearchHelper method getTagTypeIndexSearchResponseDtosFromTerms.

/**
 * get Tag Type index response
 *
 * @param aggregation aggregation
 *
 * @return list of tag type index search dto
 */
private List<TagTypeIndexSearchResponseDto> getTagTypeIndexSearchResponseDtosFromTerms(Terms aggregation) {
    List<TagTypeIndexSearchResponseDto> tagTypeIndexSearchResponseDtos = new ArrayList<>();
    for (Terms.Bucket tagTypeCodeEntry : aggregation.getBuckets()) {
        List<TagIndexSearchResponseDto> tagIndexSearchResponseDtos = new ArrayList<>();
        TagTypeIndexSearchResponseDto tagTypeIndexSearchResponseDto = new TagTypeIndexSearchResponseDto(tagTypeCodeEntry.getKeyAsString(), tagIndexSearchResponseDtos, null);
        tagTypeIndexSearchResponseDtos.add(tagTypeIndexSearchResponseDto);
        Terms tagTypeDisplayNameAggs = tagTypeCodeEntry.getAggregations().get(TAGTYPE_NAME_AGGREGATION);
        for (Terms.Bucket tagTypeDisplayNameEntry : tagTypeDisplayNameAggs.getBuckets()) {
            tagTypeIndexSearchResponseDto.setDisplayName(tagTypeDisplayNameEntry.getKeyAsString());
            Terms tagCodeAggs = tagTypeDisplayNameEntry.getAggregations().get(TAG_CODE_AGGREGATION);
            TagIndexSearchResponseDto tagIndexSearchResponseDto;
            for (Terms.Bucket tagCodeEntry : tagCodeAggs.getBuckets()) {
                tagIndexSearchResponseDto = new TagIndexSearchResponseDto(tagCodeEntry.getKeyAsString(), tagCodeEntry.getDocCount(), null);
                tagIndexSearchResponseDtos.add(tagIndexSearchResponseDto);
                Terms tagNameAggs = tagCodeEntry.getAggregations().get(TAG_NAME_AGGREGATION);
                for (Terms.Bucket tagNameEntry : tagNameAggs.getBuckets()) {
                    tagIndexSearchResponseDto.setTagDisplayName(tagNameEntry.getKeyAsString());
                }
            }
        }
    }
    return tagTypeIndexSearchResponseDtos;
}
Also used : TagIndexSearchResponseDto(org.finra.herd.model.dto.TagIndexSearchResponseDto) TagTypeIndexSearchResponseDto(org.finra.herd.model.dto.TagTypeIndexSearchResponseDto) ArrayList(java.util.ArrayList) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms)

Aggregations

ArrayList (java.util.ArrayList)13 TagIndexSearchResponseDto (org.finra.herd.model.dto.TagIndexSearchResponseDto)13 TagTypeIndexSearchResponseDto (org.finra.herd.model.dto.TagTypeIndexSearchResponseDto)12 Facet (org.finra.herd.model.api.xml.Facet)8 ElasticsearchResponseDto (org.finra.herd.model.dto.ElasticsearchResponseDto)7 Test (org.junit.Test)6 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)5 BusinessObjectDefinitionIndexSearchResponse (org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse)3 BusinessObjectDefinitionSearchFilter (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter)3 ResultTypeIndexSearchResponseDto (org.finra.herd.model.dto.ResultTypeIndexSearchResponseDto)3 TermsAggregation (io.searchbox.core.search.aggregation.TermsAggregation)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)2 BusinessObjectDefinition (org.finra.herd.model.api.xml.BusinessObjectDefinition)2 BusinessObjectDefinitionIndexSearchRequest (org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchRequest)2 BusinessObjectDefinitionSearchKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchKey)2 BusinessObjectDefinitionIndexSearchResponseDto (org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto)2