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);
}
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);
}
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);
}
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;
}
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;
}
Aggregations