Search in sources :

Example 96 with TagEntity

use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.

the class TagServiceTest method testGetTagLowerCaseParameters.

@Test
public void testGetTagLowerCaseParameters() {
    // Create and persist a tag entity.
    TagEntity tagEntity = tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE, TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION);
    // Get the tag using lower case input parameters.
    Tag resultTag = tagService.getTag(new TagKey(TAG_TYPE.toLowerCase(), TAG_CODE.toLowerCase()));
    // Validate the returned object.
    assertEquals(new Tag(tagEntity.getId(), new TagKey(TAG_TYPE, TAG_CODE), TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, tagEntity.getCreatedBy(), tagEntity.getUpdatedBy(), HerdDateUtils.getXMLGregorianCalendarValue(tagEntity.getUpdatedOn()), NO_PARENT_TAG_KEY, NO_TAG_HAS_CHILDREN_FLAG), resultTag);
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity) TagKey(org.finra.herd.model.api.xml.TagKey) Tag(org.finra.herd.model.api.xml.Tag) Test(org.junit.Test)

Example 97 with TagEntity

use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.

the class TagServiceTest method testCreateTagWithParent.

@Test
public void testCreateTagWithParent() {
    // Create and persist a tag type entity.
    tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION);
    // Create a tag key.
    TagKey parentTagKey = new TagKey(TAG_TYPE, TAG_CODE);
    // Create a parent tag.
    Tag parentTag = tagService.createTag(new TagCreateRequest(parentTagKey, TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, NO_PARENT_TAG_KEY));
    // Get the parent tag entity.
    TagEntity parentTagEntity = tagDao.getTagByKey(parentTagKey);
    assertNotNull(parentTagEntity);
    // Validate the response object.
    assertEquals(new Tag(parentTagEntity.getId(), new TagKey(TAG_TYPE, TAG_CODE), TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, parentTagEntity.getCreatedBy(), parentTagEntity.getUpdatedBy(), HerdDateUtils.getXMLGregorianCalendarValue(parentTagEntity.getUpdatedOn()), NO_PARENT_TAG_KEY, NO_TAG_HAS_CHILDREN_FLAG), parentTag);
    // Create a tag key.
    TagKey childTagKey = new TagKey(TAG_TYPE, TAG_CODE_2);
    // Create a child tag.
    Tag childTag = tagService.createTag(new TagCreateRequest(childTagKey, TAG_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2, parentTagKey));
    // Get the child tag entity.
    TagEntity childTagEntity = tagDao.getTagByKey(childTagKey);
    assertNotNull(childTagEntity);
    assertEquals(new Tag(childTagEntity.getId(), childTagKey, TAG_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2, childTagEntity.getCreatedBy(), childTagEntity.getUpdatedBy(), HerdDateUtils.getXMLGregorianCalendarValue(childTagEntity.getUpdatedOn()), parentTagKey, NO_TAG_HAS_CHILDREN_FLAG), childTag);
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity) TagKey(org.finra.herd.model.api.xml.TagKey) TagCreateRequest(org.finra.herd.model.api.xml.TagCreateRequest) Tag(org.finra.herd.model.api.xml.Tag) Test(org.junit.Test)

Example 98 with TagEntity

use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.

the class TagServiceTest method testGetTagTrimParameters.

@Test
public void testGetTagTrimParameters() {
    // Create and persist a tag entity.
    TagEntity tagEntity = tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE, TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION);
    // Retrieve the tag using input parameters with leading and trailing empty spaces.
    Tag resultTag = tagService.getTag(new TagKey(addWhitespace(TAG_TYPE), addWhitespace(TAG_CODE)));
    // Validate the returned object.
    assertEquals(new Tag(tagEntity.getId(), new TagKey(TAG_TYPE, TAG_CODE), TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, tagEntity.getCreatedBy(), tagEntity.getUpdatedBy(), HerdDateUtils.getXMLGregorianCalendarValue(tagEntity.getUpdatedOn()), NO_PARENT_TAG_KEY, NO_TAG_HAS_CHILDREN_FLAG), resultTag);
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity) TagKey(org.finra.herd.model.api.xml.TagKey) Tag(org.finra.herd.model.api.xml.Tag) Test(org.junit.Test)

Example 99 with TagEntity

use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.

the class TagServiceTest method testGetTagUpperCaseParameters.

@Test
public void testGetTagUpperCaseParameters() {
    // Create and persist a tag entity.
    TagEntity tagEntity = tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE, TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION);
    // Get the tag using uppercase input parameters.
    Tag resultTag = tagService.getTag(new TagKey(TAG_TYPE.toUpperCase(), TAG_CODE.toUpperCase()));
    // Validate the returned object.
    assertEquals(new Tag(tagEntity.getId(), new TagKey(TAG_TYPE, TAG_CODE), TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, tagEntity.getCreatedBy(), tagEntity.getUpdatedBy(), HerdDateUtils.getXMLGregorianCalendarValue(tagEntity.getUpdatedOn()), NO_PARENT_TAG_KEY, NO_TAG_HAS_CHILDREN_FLAG), resultTag);
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity) TagKey(org.finra.herd.model.api.xml.TagKey) Tag(org.finra.herd.model.api.xml.Tag) Test(org.junit.Test)

Example 100 with TagEntity

use of org.finra.herd.model.jpa.TagEntity 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

TagEntity (org.finra.herd.model.jpa.TagEntity)111 Test (org.junit.Test)77 TagKey (org.finra.herd.model.api.xml.TagKey)55 ArrayList (java.util.ArrayList)44 TagTypeEntity (org.finra.herd.model.jpa.TagTypeEntity)33 Tag (org.finra.herd.model.api.xml.Tag)28 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)15 SearchIndexUpdateDto (org.finra.herd.model.dto.SearchIndexUpdateDto)14 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)13 TagUpdateRequest (org.finra.herd.model.api.xml.TagUpdateRequest)12 ElasticsearchResponseDto (org.finra.herd.model.dto.ElasticsearchResponseDto)11 BusinessObjectDefinitionTagEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity)11 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)10 Predicate (javax.persistence.criteria.Predicate)9 BusinessObjectDefinitionSearchKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchKey)9 TagCreateRequest (org.finra.herd.model.api.xml.TagCreateRequest)9 BusinessObjectDefinitionIndexSearchResponse (org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse)8 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)8 BusinessObjectDefinitionSearchFilter (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter)8 BusinessObjectDefinitionIndexSearchResponseDto (org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto)8