use of org.finra.herd.model.api.xml.Facet 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.api.xml.Facet 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.api.xml.Facet 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.api.xml.Facet in project herd by FINRAOS.
the class BusinessObjectDefinitionRestControllerIndexTest method testIndexSearchBusinessObjectDefinitions.
@Test
public void testIndexSearchBusinessObjectDefinitions() {
// 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(false, businessObjectDefinitionSearchKeyList));
// 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 businessObjectDefinitionSearchRequest = 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);
// Create a business object definition entity list to return from the search business object definitions by tags function
List<BusinessObjectDefinitionEntity> businessObjectDefinitionEntityList = new ArrayList<>();
businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, businessObjectDefinitionServiceTestHelper.getNewAttributes()));
businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME_2, DATA_PROVIDER_NAME_2, BDEF_DESCRIPTION_2, businessObjectDefinitionServiceTestHelper.getNewAttributes()));
// 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.
for (BusinessObjectDefinitionEntity businessObjectDefinitionEntity : ImmutableSet.copyOf(businessObjectDefinitionEntityList)) {
// 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
BusinessObjectDefinition businessObjectDefinition = new BusinessObjectDefinition();
// Populate the business object definition
businessObjectDefinition.setNamespace(businessObjectDefinitionEntity.getNamespace().getCode());
businessObjectDefinition.setBusinessObjectDefinitionName(businessObjectDefinitionEntity.getName());
businessObjectDefinition.setDataProviderName(businessObjectDefinitionEntity.getDataProvider().getName());
businessObjectDefinition.setShortDescription(StringUtils.left(businessObjectDefinitionEntity.getDescription(), SHORT_DESCRIPTION_LENGTH));
businessObjectDefinition.setDisplayName(businessObjectDefinitionEntity.getDisplayName());
businessObjectDefinitions.add(businessObjectDefinition);
}
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);
List<Facet> tagTypeFacets = new ArrayList<>();
for (TagTypeIndexSearchResponseDto tagTypeIndexSearchResponse : ImmutableSet.copyOf(tagTypeIndexSearchResponseDtos)) {
List<Facet> tagFacets = new ArrayList<>();
for (TagIndexSearchResponseDto tagIndexSearchResponseDto : tagTypeIndexSearchResponse.getTagIndexSearchResponseDtos()) {
Facet tagFacet = new Facet(tagIndexSearchResponseDto.getTagDisplayName(), tagIndexSearchResponseDto.getCount(), FacetTypeEnum.TAG.value(), tagIndexSearchResponseDto.getTagCode(), null);
tagFacets.add(tagFacet);
}
tagTypeFacets.add(new Facet(tagTypeIndexSearchResponse.getDisplayName(), null, FacetTypeEnum.TAG_TYPE.value(), tagTypeIndexSearchResponse.getCode(), tagFacets));
}
// Construct business object search response.
BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponse = new BusinessObjectDefinitionIndexSearchResponse();
businessObjectDefinitionSearchResponse.setBusinessObjectDefinitions(businessObjectDefinitions);
businessObjectDefinitionSearchResponse.setFacets(tagTypeFacets);
// Mock the call to the business object definition service
when(businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionSearchRequest, fields)).thenReturn(businessObjectDefinitionSearchResponse);
// Create a business object definition.
BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponseFromRestCall = businessObjectDefinitionRestController.indexSearchBusinessObjectDefinitions(fields, businessObjectDefinitionSearchRequest);
// Verify the method call to businessObjectDefinitionService.indexAllBusinessObjectDefinitions()
verify(businessObjectDefinitionService, times(1)).indexSearchBusinessObjectDefinitions(businessObjectDefinitionSearchRequest, fields);
// Validate the returned object.
assertThat("Business object definition index search response was null.", businessObjectDefinitionSearchResponseFromRestCall, not(nullValue()));
assertThat("Business object definition index search response was not correct.", businessObjectDefinitionSearchResponseFromRestCall, is(businessObjectDefinitionSearchResponse));
assertThat("Business object definition index search response was not an instance of BusinessObjectDefinitionSearchResponse.class.", businessObjectDefinitionSearchResponseFromRestCall, instanceOf(BusinessObjectDefinitionIndexSearchResponse.class));
}
use of org.finra.herd.model.api.xml.Facet 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;
}
Aggregations