Search in sources :

Example 76 with TagEntity

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

the class IndexSearchServiceTest method testIndexSearchWithMatch.

@Test
public void testIndexSearchWithMatch() {
    // Create a tag key.
    TagKey tagKey = new TagKey(TAG_TYPE_CODE, TAG_CODE);
    // Create an index search request.
    final IndexSearchRequest indexSearchRequest = new IndexSearchRequest(SEARCH_TERM, ImmutableList.of(new IndexSearchFilter(EXCLUSION_SEARCH_FILTER, ImmutableList.of(new IndexSearchKey(tagKey, NO_INDEX_SEARCH_RESULT_TYPE_KEY))), new IndexSearchFilter(EXCLUSION_SEARCH_FILTER, ImmutableList.of(new IndexSearchKey(NO_TAG_KEY, new IndexSearchResultTypeKey(INDEX_SEARCH_RESULT_TYPE))))), Collections.singletonList(ElasticsearchHelper.TAG_FACET), ENABLE_HIT_HIGHLIGHTING);
    // Create a set of fields.
    final Set<String> fields = Sets.newHashSet(FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION);
    // Create a set of match fields.
    final Set<String> match = Sets.newHashSet(MATCH_COLUMN);
    // Create a new index search result key and populate it with a tag key
    final IndexSearchResultKey indexSearchResultKeyBusinessObjectDefinition = new IndexSearchResultKey(null, new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME));
    // Create a new index search result key and populate it with a tag key
    final IndexSearchResultKey indexSearchResultKeyTag = new IndexSearchResultKey(new TagKey(TAG_TYPE, TAG_CODE), null);
    // Create a new index search results
    final IndexSearchResult indexSearchResultBusinessObjectDefinition = new IndexSearchResult(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name(), new SearchIndexKey(BUSINESS_OBJECT_DEFINITION_SEARCH_INDEX_NAME), indexSearchResultKeyBusinessObjectDefinition, BDEF_DISPLAY_NAME, BDEF_SHORT_DESCRIPTION, null);
    final IndexSearchResult indexSearchResultTag = new IndexSearchResult(SearchIndexTypeEntity.SearchIndexTypes.TAG.name(), new SearchIndexKey(TAG_SEARCH_INDEX_NAME), indexSearchResultKeyTag, TAG_DISPLAY_NAME, TAG_DESCRIPTION, null);
    // Create a list to contain the index search results
    final List<IndexSearchResult> indexSearchResults = new ArrayList<>();
    indexSearchResults.add(indexSearchResultBusinessObjectDefinition);
    indexSearchResults.add(indexSearchResultTag);
    // Construct an index search response
    final IndexSearchResponse indexSearchResponse = new IndexSearchResponse(TOTAL_INDEX_SEARCH_RESULTS, indexSearchResults, null);
    // Construct a search index entity
    SearchIndexTypeEntity searchIndexTypeEntity = new SearchIndexTypeEntity();
    searchIndexTypeEntity.setCode(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
    // Create a tag type entity.
    TagTypeEntity tagTypeEntity = new TagTypeEntity();
    tagTypeEntity.setCode(tagKey.getTagTypeCode());
    // Create a tag entity.
    TagEntity tagEntity = new TagEntity();
    tagEntity.setTagCode(tagKey.getTagCode());
    tagEntity.setTagType(tagTypeEntity);
    // Mock the call to the index search service
    when(tagDaoHelper.getTagEntity(tagKey)).thenReturn(tagEntity);
    when(alternateKeyHelper.validateStringParameter("An", "index search result type", INDEX_SEARCH_RESULT_TYPE)).thenReturn(INDEX_SEARCH_RESULT_TYPE);
    when(searchIndexDaoHelper.getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name())).thenReturn(SEARCH_INDEX_NAME);
    when(searchIndexDaoHelper.getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.TAG.name())).thenReturn(SEARCH_INDEX_NAME_2);
    when(indexSearchDao.indexSearch(indexSearchRequest, fields, match, SEARCH_INDEX_NAME, SEARCH_INDEX_NAME_2)).thenReturn(indexSearchResponse);
    // Call the method under test.
    IndexSearchResponse result = indexSearchService.indexSearch(indexSearchRequest, fields, match);
    // Verify the external calls.
    verify(tagHelper).validateTagKey(tagKey);
    verify(tagDaoHelper).getTagEntity(tagKey);
    verify(alternateKeyHelper).validateStringParameter("An", "index search result type", INDEX_SEARCH_RESULT_TYPE);
    verify(searchIndexTypeDaoHelper).getSearchIndexTypeEntity(INDEX_SEARCH_RESULT_TYPE);
    verify(indexSearchDao).indexSearch(indexSearchRequest, fields, match, SEARCH_INDEX_NAME, SEARCH_INDEX_NAME_2);
    verify(searchIndexDaoHelper).getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
    verify(searchIndexDaoHelper).getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.TAG.name());
    verifyNoMoreInteractionsHelper();
    // Validate the result.
    assertEquals(indexSearchResponse, result);
}
Also used : IndexSearchKey(org.finra.herd.model.api.xml.IndexSearchKey) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) ArrayList(java.util.ArrayList) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) IndexSearchResultTypeKey(org.finra.herd.model.api.xml.IndexSearchResultTypeKey) IndexSearchRequest(org.finra.herd.model.api.xml.IndexSearchRequest) SearchIndexTypeEntity(org.finra.herd.model.jpa.SearchIndexTypeEntity) IndexSearchResultKey(org.finra.herd.model.api.xml.IndexSearchResultKey) SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) TagEntity(org.finra.herd.model.jpa.TagEntity) IndexSearchResponse(org.finra.herd.model.api.xml.IndexSearchResponse) TagKey(org.finra.herd.model.api.xml.TagKey) IndexSearchResult(org.finra.herd.model.api.xml.IndexSearchResult) IndexSearchFilter(org.finra.herd.model.api.xml.IndexSearchFilter) Test(org.junit.Test)

Example 77 with TagEntity

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

the class IndexSearchServiceTest method testIndexSearch.

@Test
public void testIndexSearch() {
    // Create a tag key.
    TagKey tagKey = new TagKey(TAG_TYPE_CODE, TAG_CODE);
    // Create an index search request.
    final IndexSearchRequest indexSearchRequest = new IndexSearchRequest(SEARCH_TERM, ImmutableList.of(new IndexSearchFilter(EXCLUSION_SEARCH_FILTER, ImmutableList.of(new IndexSearchKey(tagKey, NO_INDEX_SEARCH_RESULT_TYPE_KEY))), new IndexSearchFilter(EXCLUSION_SEARCH_FILTER, ImmutableList.of(new IndexSearchKey(NO_TAG_KEY, new IndexSearchResultTypeKey(INDEX_SEARCH_RESULT_TYPE))))), Collections.singletonList(ElasticsearchHelper.TAG_FACET), ENABLE_HIT_HIGHLIGHTING);
    // Create a set of fields.
    final Set<String> fields = Sets.newHashSet(FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION);
    // Create a new index search result key and populate it with a tag key
    final IndexSearchResultKey indexSearchResultKeyBusinessObjectDefinition = new IndexSearchResultKey(null, new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME));
    // Create a new index search result key and populate it with a tag key
    final IndexSearchResultKey indexSearchResultKeyTag = new IndexSearchResultKey(new TagKey(TAG_TYPE, TAG_CODE), null);
    // Create a new index search results
    final IndexSearchResult indexSearchResultBusinessObjectDefinition = new IndexSearchResult(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name(), new SearchIndexKey(BUSINESS_OBJECT_DEFINITION_SEARCH_INDEX_NAME), indexSearchResultKeyBusinessObjectDefinition, BDEF_DISPLAY_NAME, BDEF_SHORT_DESCRIPTION, null);
    final IndexSearchResult indexSearchResultTag = new IndexSearchResult(SearchIndexTypeEntity.SearchIndexTypes.TAG.name(), new SearchIndexKey(TAG_SEARCH_INDEX_NAME), indexSearchResultKeyTag, TAG_DISPLAY_NAME, TAG_DESCRIPTION, null);
    // Create a list to contain the index search results
    final List<IndexSearchResult> indexSearchResults = new ArrayList<>();
    indexSearchResults.add(indexSearchResultBusinessObjectDefinition);
    indexSearchResults.add(indexSearchResultTag);
    // Construct an index search response
    final IndexSearchResponse indexSearchResponse = new IndexSearchResponse(TOTAL_INDEX_SEARCH_RESULTS, indexSearchResults, null);
    // Construct a search index entity
    SearchIndexTypeEntity searchIndexTypeEntity = new SearchIndexTypeEntity();
    searchIndexTypeEntity.setCode(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
    // Create a tag type entity.
    TagTypeEntity tagTypeEntity = new TagTypeEntity();
    tagTypeEntity.setCode(tagKey.getTagTypeCode());
    // Create a tag entity.
    TagEntity tagEntity = new TagEntity();
    tagEntity.setTagCode(tagKey.getTagCode());
    tagEntity.setTagType(tagTypeEntity);
    // Mock the call to the index search service
    when(tagDaoHelper.getTagEntity(tagKey)).thenReturn(tagEntity);
    when(alternateKeyHelper.validateStringParameter("An", "index search result type", INDEX_SEARCH_RESULT_TYPE)).thenReturn(INDEX_SEARCH_RESULT_TYPE);
    when(searchIndexDaoHelper.getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name())).thenReturn(SEARCH_INDEX_NAME);
    when(searchIndexDaoHelper.getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.TAG.name())).thenReturn(SEARCH_INDEX_NAME_2);
    when(indexSearchDao.indexSearch(indexSearchRequest, fields, NO_MATCH, SEARCH_INDEX_NAME, SEARCH_INDEX_NAME_2)).thenReturn(indexSearchResponse);
    // Call the method under test.
    IndexSearchResponse result = indexSearchService.indexSearch(indexSearchRequest, fields, NO_MATCH);
    // Verify the external calls.
    verify(tagHelper).validateTagKey(tagKey);
    verify(tagDaoHelper).getTagEntity(tagKey);
    verify(alternateKeyHelper).validateStringParameter("An", "index search result type", INDEX_SEARCH_RESULT_TYPE);
    verify(searchIndexTypeDaoHelper).getSearchIndexTypeEntity(INDEX_SEARCH_RESULT_TYPE);
    verify(indexSearchDao).indexSearch(indexSearchRequest, fields, NO_MATCH, SEARCH_INDEX_NAME, SEARCH_INDEX_NAME_2);
    verify(searchIndexDaoHelper).getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.BUS_OBJCT_DFNTN.name());
    verify(searchIndexDaoHelper).getActiveSearchIndex(SearchIndexTypeEntity.SearchIndexTypes.TAG.name());
    verifyNoMoreInteractionsHelper();
    // Validate the result.
    assertEquals(indexSearchResponse, result);
}
Also used : IndexSearchKey(org.finra.herd.model.api.xml.IndexSearchKey) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) ArrayList(java.util.ArrayList) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) IndexSearchResultTypeKey(org.finra.herd.model.api.xml.IndexSearchResultTypeKey) IndexSearchRequest(org.finra.herd.model.api.xml.IndexSearchRequest) SearchIndexTypeEntity(org.finra.herd.model.jpa.SearchIndexTypeEntity) IndexSearchResultKey(org.finra.herd.model.api.xml.IndexSearchResultKey) SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) TagEntity(org.finra.herd.model.jpa.TagEntity) IndexSearchResponse(org.finra.herd.model.api.xml.IndexSearchResponse) TagKey(org.finra.herd.model.api.xml.TagKey) IndexSearchResult(org.finra.herd.model.api.xml.IndexSearchResult) IndexSearchFilter(org.finra.herd.model.api.xml.IndexSearchFilter) Test(org.junit.Test)

Example 78 with TagEntity

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

the class TagDaoHelper method validateParentTagEntity.

/**
 * Validate the update tag request parent tag key. The parent tag should not be on the children tree of the updated tag. No more than MAX_HIERARCHY_LEVEL is
 * allowed to update parent-child relation.
 *
 * @param tagEntity the tag entity being updated
 * @param parentTagEntity the tag update request
 */
public void validateParentTagEntity(TagEntity tagEntity, TagEntity parentTagEntity) {
    Integer maxAllowedTagNesting = configurationHelper.getProperty(ConfigurationValue.MAX_ALLOWED_TAG_NESTING, Integer.class);
    TagEntity localParentTagEntity = parentTagEntity;
    int level = 0;
    while (localParentTagEntity != null) {
        Assert.isTrue(!tagEntity.equals(localParentTagEntity), "Parent tag key cannot be the requested tag key or any of its children’s tag keys.");
        localParentTagEntity = localParentTagEntity.getParentTagEntity();
        if (level++ >= maxAllowedTagNesting) {
            throw new IllegalArgumentException("Exceeds maximum allowed tag nesting level of " + maxAllowedTagNesting);
        }
    }
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity)

Example 79 with TagEntity

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

the class SearchIndexHelperServiceTest method testIndexAllTags.

@Test
public void testIndexAllTags() {
    // Create a search index key.
    SearchIndexKey searchIndexKey = new SearchIndexKey(SEARCH_INDEX_NAME);
    // Create a list of tag entities.
    final List<TagEntity> tagEntities = Collections.unmodifiableList(Arrays.asList(tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE, TAG_DISPLAY_NAME, TAG_DESCRIPTION), tagDaoTestHelper.createTagEntity(TAG_TYPE_2, TAG_CODE_2, TAG_DISPLAY_NAME_2, TAG_DESCRIPTION_2)));
    // Mock the external calls. Please note that we mock index size is set to be equal to the tag entity list size.
    when(tagDao.getTags()).thenReturn(tagEntities);
    doNothing().when(indexFunctionsDao).createIndexDocument(any(), any(), any(), any());
    when(indexFunctionsDao.getNumberOfTypesInIndex(SEARCH_INDEX_NAME, SEARCH_INDEX_DOCUMENT_TYPE)).thenReturn(2L);
    // Index all tags defined in the system.
    Future<Void> response = searchIndexHelperService.indexAllTags(searchIndexKey, SEARCH_INDEX_DOCUMENT_TYPE);
    // Verify the external calls.
    verify(tagDao).getTags();
    // verify(indexFunctionsDao).createIndexDocument(any(), any(), any(), any());
    verify(tagHelper).executeFunctionForTagEntities(eq(SEARCH_INDEX_NAME), eq(SEARCH_INDEX_DOCUMENT_TYPE), eq(tagEntities), any());
    verify(indexFunctionsDao).getNumberOfTypesInIndex(SEARCH_INDEX_NAME, SEARCH_INDEX_DOCUMENT_TYPE);
    verify(searchIndexDaoHelper).updateSearchIndexStatus(searchIndexKey, SearchIndexStatusEntity.SearchIndexStatuses.READY.name());
    verifyNoMoreInteractions(businessObjectDefinitionDao, businessObjectDefinitionHelper, searchIndexDaoHelper, tagDao, tagHelper);
    // Validate the results.
    assertNotNull(response);
    assertThat(response, instanceOf(Future.class));
}
Also used : SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) TagEntity(org.finra.herd.model.jpa.TagEntity) Future(java.util.concurrent.Future) Test(org.junit.Test)

Example 80 with TagEntity

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

the class TagServiceTest method testUpdateTagParentTagMaxAllowedNestingExceeds.

@Test
public void testUpdateTagParentTagMaxAllowedNestingExceeds() throws Exception {
    // Create and persist a root tag entity.
    TagEntity rootTagEntity = tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE, TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION);
    // Create a child tag entity.
    TagEntity childTagEntity = tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE_2, TAG_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2, rootTagEntity);
    // Create a grandchild tag entity.
    TagEntity grandchildTagEntity = tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE_3, TAG_DISPLAY_NAME_3, TAG_SEARCH_SCORE_MULTIPLIER_3, TAG_DESCRIPTION_3, childTagEntity);
    // Override the configuration to set max allowed tag nesting to 1.
    Map<String, Object> overrideMap = new HashMap<>();
    overrideMap.put(ConfigurationValue.MAX_ALLOWED_TAG_NESTING.getKey(), 1);
    modifyPropertySourceInEnvironment(overrideMap);
    try {
        // Try to update the tag using it's child as a parent tag.
        try {
            tagService.updateTag(new TagKey(TAG_TYPE, TAG_CODE), new TagUpdateRequest(TAG_DISPLAY_NAME_4, TAG_SEARCH_SCORE_MULTIPLIER_4, TAG_DESCRIPTION_4, new TagKey(childTagEntity.getTagType().getCode(), childTagEntity.getTagCode())));
            fail();
        } catch (IllegalArgumentException e) {
            assertEquals("Parent tag key cannot be the requested tag key or any of its children’s tag keys.", e.getMessage());
        }
        // Try to update the tag using it's grandchild as a parent tag.
        try {
            tagService.updateTag(new TagKey(TAG_TYPE, TAG_CODE), new TagUpdateRequest(TAG_DISPLAY_NAME_4, TAG_SEARCH_SCORE_MULTIPLIER_4, TAG_DESCRIPTION_4, new TagKey(grandchildTagEntity.getTagType().getCode(), grandchildTagEntity.getTagCode())));
            fail();
        } catch (IllegalArgumentException e) {
            assertEquals("Exceeds maximum allowed tag nesting level of 1", e.getMessage());
        }
    } finally {
        // Restore the property sources so we don't affect other tests.
        restorePropertySourceInEnvironment();
    }
}
Also used : TagUpdateRequest(org.finra.herd.model.api.xml.TagUpdateRequest) HashMap(java.util.HashMap) TagEntity(org.finra.herd.model.jpa.TagEntity) TagKey(org.finra.herd.model.api.xml.TagKey) Test(org.junit.Test)

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