Search in sources :

Example 16 with TagKey

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

the class BusinessObjectDefinitionServiceTest method testSearchBusinessObjectDefinitionValidParams.

@Test
public void testSearchBusinessObjectDefinitionValidParams() {
    // Set up test data.
    Set<BusinessObjectDefinition> expectedBusinessObjectDefinitions = setUpTestEntitiesForSearchTesting();
    // Retrieve the actual business object definition objects from the search response.
    BusinessObjectDefinitionSearchResponse searchResponse = businessObjectDefinitionService.searchBusinessObjectDefinitions(new BusinessObjectDefinitionSearchRequest(Arrays.asList(new BusinessObjectDefinitionSearchFilter(NO_EXCLUSION_SEARCH_FILTER, Arrays.asList(new BusinessObjectDefinitionSearchKey(new TagKey(TAG_TYPE, TAG_CODE), INCLUDE_TAG_HIERARCHY))))), Sets.newHashSet(FIELD_DATA_PROVIDER_NAME, FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION));
    Set<BusinessObjectDefinition> actualBusinessObjectDefinitions = new HashSet<>(searchResponse.getBusinessObjectDefinitions());
    assertEquals(expectedBusinessObjectDefinitions, actualBusinessObjectDefinitions);
}
Also used : BusinessObjectDefinition(org.finra.herd.model.api.xml.BusinessObjectDefinition) BusinessObjectDefinitionSearchKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchKey) TagKey(org.finra.herd.model.api.xml.TagKey) BusinessObjectDefinitionSearchRequest(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchRequest) BusinessObjectDefinitionSearchFilter(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter) BusinessObjectDefinitionSearchResponse(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchResponse) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with TagKey

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

the class BusinessObjectDefinitionServiceTest method testSearchBusinessObjectDefinitionsOnlyDataProviderName.

@Test
public void testSearchBusinessObjectDefinitionsOnlyDataProviderName() {
    // Set up test data.
    Set<BusinessObjectDefinition> expectedBusinessObjectDefinitions = setUpTestEntitiesForSearchTesting();
    // Remove fields which are not expected from the expected business object definition objects.
    for (BusinessObjectDefinition businessObjectDefinition : expectedBusinessObjectDefinitions) {
        businessObjectDefinition.setDisplayName(null);
        businessObjectDefinition.setShortDescription(null);
    }
    // Retrieve the actual business object definition objects from the search response.
    BusinessObjectDefinitionSearchResponse searchResponse = businessObjectDefinitionService.searchBusinessObjectDefinitions(new BusinessObjectDefinitionSearchRequest(Arrays.asList(new BusinessObjectDefinitionSearchFilter(NO_EXCLUSION_SEARCH_FILTER, Arrays.asList(new BusinessObjectDefinitionSearchKey(new TagKey(TAG_TYPE, TAG_CODE), INCLUDE_TAG_HIERARCHY))))), Sets.newHashSet(FIELD_DATA_PROVIDER_NAME));
    Set<BusinessObjectDefinition> actualBusinessObjectDefinitions = new HashSet<>(searchResponse.getBusinessObjectDefinitions());
    assertEquals(actualBusinessObjectDefinitions, expectedBusinessObjectDefinitions);
}
Also used : BusinessObjectDefinition(org.finra.herd.model.api.xml.BusinessObjectDefinition) BusinessObjectDefinitionSearchKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchKey) TagKey(org.finra.herd.model.api.xml.TagKey) BusinessObjectDefinitionSearchRequest(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchRequest) BusinessObjectDefinitionSearchFilter(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter) BusinessObjectDefinitionSearchResponse(org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchResponse) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with TagKey

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

the class IndexSearchDaoImpl method buildIndexSearchResults.

/**
 * Extracts and builds a list of {@link IndexSearchResult}s from a given {@link SearchResult}
 *
 * @param fields the specified fields to be included in the response
 * @param tagActiveIndex the name of the active tag index
 * @param bdefActiveIndex the name of the active business object definition index
 * @param searchResult the raw search result returned by the elasticsearch client
 * @param isHighlightingEnabled boolean which specifies if highlighting is requested or not
 *
 * @return A {@link List} of {@link IndexSearchResult} which represent the search response
 */
private List<IndexSearchResult> buildIndexSearchResults(Set<String> fields, String tagActiveIndex, String bdefActiveIndex, SearchResult searchResult, Boolean isHighlightingEnabled) {
    final Integer tagShortDescMaxLength = configurationHelper.getProperty(ConfigurationValue.TAG_SHORT_DESCRIPTION_LENGTH, Integer.class);
    final Integer businessObjectDefinitionShortDescMaxLength = configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class);
    List<IndexSearchResult> indexSearchResults = new ArrayList<>();
    final List<SearchResult.Hit<Map, Void>> searchHitList = searchResult.getHits(Map.class);
    // For each indexSearch hit
    for (final SearchResult.Hit<Map, Void> hit : searchHitList) {
        // Get the source map from the indexSearch hit
        @SuppressWarnings("unchecked") final Map<String, Object> sourceMap = hit.source;
        // Get the index from which this result is from
        final String index = hit.index;
        // Create a new document to populate with the indexSearch results
        final IndexSearchResult indexSearchResult = new IndexSearchResult();
        // Populate the results
        indexSearchResult.setSearchIndexKey(new SearchIndexKey(index));
        if (fields.contains(DISPLAY_NAME_FIELD)) {
            indexSearchResult.setDisplayName((String) sourceMap.get(DISPLAY_NAME_SOURCE));
        }
        // Populate tag index specific key
        if (index.equals(tagActiveIndex)) {
            if (fields.contains(SHORT_DESCRIPTION_FIELD)) {
                indexSearchResult.setShortDescription(HerdStringUtils.getShortDescription((String) sourceMap.get(DESCRIPTION_SOURCE), tagShortDescMaxLength));
            }
            final TagKey tagKey = new TagKey();
            tagKey.setTagCode((String) sourceMap.get(TAG_CODE_SOURCE));
            tagKey.setTagTypeCode((String) ((Map) sourceMap.get(TAG_TYPE)).get(CODE));
            indexSearchResult.setIndexSearchResultType(SearchIndexTypeEntity.SearchIndexTypes.TAG.name());
            indexSearchResult.setIndexSearchResultKey(new IndexSearchResultKey(tagKey, null));
        } else // Populate business object definition key
        if (index.equals(bdefActiveIndex)) {
            if (fields.contains(SHORT_DESCRIPTION_FIELD)) {
                indexSearchResult.setShortDescription(HerdStringUtils.getShortDescription((String) sourceMap.get(DESCRIPTION_SOURCE), businessObjectDefinitionShortDescMaxLength));
            }
            final BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey();
            businessObjectDefinitionKey.setNamespace((String) ((Map) sourceMap.get(NAMESPACE)).get(CODE));
            businessObjectDefinitionKey.setBusinessObjectDefinitionName((String) sourceMap.get(NAME_SOURCE));
            indexSearchResult.setIndexSearchResultType(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
            indexSearchResult.setIndexSearchResultKey(new IndexSearchResultKey(null, businessObjectDefinitionKey));
        } else {
            throw new IllegalStateException(String.format("Search result index name \"%s\" does not match any of the active search indexes. tagActiveIndex=%s bdefActiveIndex=%s", index, tagActiveIndex, bdefActiveIndex));
        }
        if (BooleanUtils.isTrue(isHighlightingEnabled)) {
            // Fetch configured 'tag' values for highlighting
            String preTag = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_HIGHLIGHT_PRETAGS);
            String postTag = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_HIGHLIGHT_POSTTAGS);
            // Extract highlighted content from the search hit and clean html tags except the pre/post-tags as configured
            Highlight highlightedContent = extractHighlightedContent(hit, preTag, postTag);
            // Set highlighted content in the response element
            indexSearchResult.setHighlight(highlightedContent);
        }
        indexSearchResults.add(indexSearchResult);
    }
    return indexSearchResults;
}
Also used : Highlight(org.finra.herd.model.api.xml.Highlight) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) ArrayList(java.util.ArrayList) IndexSearchResult(org.finra.herd.model.api.xml.IndexSearchResult) SearchResult(io.searchbox.core.SearchResult) IndexSearchResultKey(org.finra.herd.model.api.xml.IndexSearchResultKey) SearchHit(org.elasticsearch.search.SearchHit) SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) TagKey(org.finra.herd.model.api.xml.TagKey) IndexSearchResult(org.finra.herd.model.api.xml.IndexSearchResult) Map(java.util.Map) HashMap(java.util.HashMap)

Example 19 with TagKey

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

the class TagServiceTest method testUpdateTag.

@Test
public void testUpdateTag() {
    // Create a parent tag key.
    TagKey parentTagKey = new TagKey(TAG_TYPE, TAG_CODE);
    // Create a parent tag entity.
    tagDaoTestHelper.createTagEntity(parentTagKey, TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION);
    // Create a tag key.
    TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE_2);
    // Create and persist a tag entity without a parent tag.
    TagEntity tagEntity = tagDaoTestHelper.createTagEntity(tagKey, TAG_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2);
    // Update the tag.
    Tag updatedTag = tagService.updateTag(tagKey, new TagUpdateRequest(TAG_DISPLAY_NAME_3, TAG_SEARCH_SCORE_MULTIPLIER_3, TAG_DESCRIPTION_3, parentTagKey));
    // Validate the returned object.
    assertEquals(new Tag(tagEntity.getId(), tagKey, TAG_DISPLAY_NAME_3, TAG_SEARCH_SCORE_MULTIPLIER_3, TAG_DESCRIPTION_3, tagEntity.getCreatedBy(), tagEntity.getUpdatedBy(), HerdDateUtils.getXMLGregorianCalendarValue(tagEntity.getUpdatedOn()), parentTagKey, NO_TAG_HAS_CHILDREN_FLAG), updatedTag);
}
Also used : TagUpdateRequest(org.finra.herd.model.api.xml.TagUpdateRequest) 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 20 with TagKey

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

the class TagServiceTest method testGetTags.

@Test
public void testGetTags() {
    // Create and persist a tag type entity.
    TagTypeEntity tagTypeEntity = tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION);
    // Create and persist two tag entities for the same tag type.
    tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE, TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION);
    tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_2, TAG_TYPE_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2);
    // Retrieve a list of tag keys.
    TagListResponse resultTagKeys = tagService.getTags(TAG_TYPE, NO_PARENT_TAG_CODE);
    // Validate the returned object.
    assertNotNull(resultTagKeys);
    assertEquals(Arrays.asList(new TagChild(new TagKey(TAG_TYPE, TAG_CODE), TAG_HAS_NO_CHILDREN), new TagChild(new TagKey(TAG_TYPE, TAG_CODE_2), TAG_HAS_NO_CHILDREN)), resultTagKeys.getTagChildren());
}
Also used : TagChild(org.finra.herd.model.api.xml.TagChild) TagListResponse(org.finra.herd.model.api.xml.TagListResponse) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) TagKey(org.finra.herd.model.api.xml.TagKey) Test(org.junit.Test)

Aggregations

TagKey (org.finra.herd.model.api.xml.TagKey)140 Test (org.junit.Test)133 TagEntity (org.finra.herd.model.jpa.TagEntity)54 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)39 Tag (org.finra.herd.model.api.xml.Tag)38 BusinessObjectDefinitionTagKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionTagKey)37 ArrayList (java.util.ArrayList)25 BusinessObjectDefinitionSearchFilter (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter)21 BusinessObjectDefinitionSearchKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchKey)21 TagUpdateRequest (org.finra.herd.model.api.xml.TagUpdateRequest)17 TagCreateRequest (org.finra.herd.model.api.xml.TagCreateRequest)15 HashSet (java.util.HashSet)13 BusinessObjectDefinition (org.finra.herd.model.api.xml.BusinessObjectDefinition)13 BusinessObjectDefinitionSearchRequest (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchRequest)13 BusinessObjectDefinitionSearchResponse (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchResponse)12 TagTypeEntity (org.finra.herd.model.jpa.TagTypeEntity)12 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)11 BusinessObjectDefinitionTag (org.finra.herd.model.api.xml.BusinessObjectDefinitionTag)10 BusinessObjectDefinitionTagCreateRequest (org.finra.herd.model.api.xml.BusinessObjectDefinitionTagCreateRequest)10 BusinessObjectDefinitionTagKeys (org.finra.herd.model.api.xml.BusinessObjectDefinitionTagKeys)10