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