use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionServiceIndexTest method testIndexSearchBusinessObjectDefinitionsIncludeTagHierarchy.
@Test
public void testIndexSearchBusinessObjectDefinitionsIncludeTagHierarchy() {
// 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(NO_EXCLUSION_SEARCH_FILTER, businessObjectDefinitionSearchKeyList));
// Create a new business object definition search request that will be used when testing the index search business object definitions method
BusinessObjectDefinitionIndexSearchRequest businessObjectDefinitionIndexSearchRequest = new BusinessObjectDefinitionIndexSearchRequest(businessObjectDefinitionSearchFilterList, new ArrayList<>());
// 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 tag entity to return from the tag dao helper get tag entity method
TagEntity tagEntity = new TagEntity();
tagEntity.setTagCode(TAG_CODE);
// Create a tag child entity to enter into the tag children entities list
TagEntity tagChildEntity = new TagEntity();
tagChildEntity.setTagCode(TAG_CODE_2);
// Create a tag children entity list to return from the tag dao helper tag children entities method
List<TagEntity> tagChildrenEntityList = new ArrayList<>();
tagChildrenEntityList.add(tagChildEntity);
List<BusinessObjectDefinitionIndexSearchResponseDto> businessObjectDefinitionIndexSearchResponseDtoList = new ArrayList<>();
BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto1 = new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME), BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, BDEF_NAME, new Namespace(NAMESPACE));
BusinessObjectDefinitionIndexSearchResponseDto businessObjectDefinitionIndexSearchResponseDto2 = new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider(DATA_PROVIDER_NAME_2), BDEF_DESCRIPTION_2, BDEF_DISPLAY_NAME_2, BDEF_NAME_2, new Namespace(NAMESPACE));
businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto1);
businessObjectDefinitionIndexSearchResponseDtoList.add(businessObjectDefinitionIndexSearchResponseDto2);
ElasticsearchResponseDto elasticsearchResponseDto = new ElasticsearchResponseDto();
elasticsearchResponseDto.setBusinessObjectDefinitionIndexSearchResponseDtos(businessObjectDefinitionIndexSearchResponseDtoList);
// Mock the call to external methods
when(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class)).thenReturn(SHORT_DESCRIPTION_LENGTH);
when(searchIndexDaoHelper.getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF)).thenReturn(SEARCH_INDEX_NAME);
when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE);
when(tagDaoHelper.getTagEntity(businessObjectDefinitionSearchKey.getTagKey())).thenReturn(tagEntity);
when(tagDaoHelper.getTagChildrenEntities(tagEntity)).thenReturn(tagChildrenEntityList);
when(businessObjectDefinitionIndexSearchDao.searchBusinessObjectDefinitionsByTags(any(), any(), any(), any())).thenReturn(elasticsearchResponseDto);
// Call the method under test
BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponse = businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionIndexSearchRequest, fields);
assertThat("Business object definition service index search business object definitions method response is null, but it should not be.", businessObjectDefinitionSearchResponse, not(nullValue()));
assertThat("The first business object definition name in the search response is not correct.", businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(0).getBusinessObjectDefinitionName(), is(BDEF_NAME));
assertThat("The second business object definition name in the search response is not correct.", businessObjectDefinitionSearchResponse.getBusinessObjectDefinitions().get(1).getBusinessObjectDefinitionName(), is(BDEF_NAME_2));
// Verify the calls to external methods
verify(configurationHelper, times(2)).getProperty(ConfigurationValue.BUSINESS_OBJECT_DEFINITION_SHORT_DESCRIPTION_LENGTH, Integer.class);
verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
verify(searchIndexDaoHelper).getActiveSearchIndex(SEARCH_INDEX_TYPE_BDEF);
verify(tagHelper).validateTagKey(tagKey);
verify(tagDaoHelper).getTagEntity(businessObjectDefinitionSearchKey.getTagKey());
verify(tagDaoHelper).getTagChildrenEntities(tagEntity);
verify(businessObjectDefinitionIndexSearchDao).searchBusinessObjectDefinitionsByTags(any(), any(), any(), any());
verifyNoMoreInteractionsHelper();
}
use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionDaoTest method testGetBusinessObjectDefinitions.
@Test
public void testGetBusinessObjectDefinitions() {
// Create and persist two business object definition entities.
List<BusinessObjectDefinitionEntity> businessObjectDefinitionEntities = businessObjectDefinitionDaoTestHelper.createExpectedBusinessObjectDefinitionEntities();
// Get the list of business object definitions when tag entities is empty.
assertEquals(ImmutableSet.copyOf(businessObjectDefinitionEntities), ImmutableSet.copyOf(businessObjectDefinitionDao.getBusinessObjectDefinitions(new ArrayList<>())));
// Create and persist root tag entity.
TagEntity parentTagEntity = tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE, TAG_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, null);
// Create two children for the root tag.
List<TagEntity> tagEntities = Arrays.asList(parentTagEntity, tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE_3, TAG_DISPLAY_NAME_4, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, parentTagEntity), tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE_4, TAG_DISPLAY_NAME_3, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, parentTagEntity));
// Create and persist two business object definition tag entities for the child tag entities.
for (BusinessObjectDefinitionEntity businessObjectDefinitionEntity : businessObjectDefinitionEntities) {
for (TagEntity tagEntity : tagEntities) {
businessObjectDefinitionTagDaoTestHelper.createBusinessObjectDefinitionTagEntity(businessObjectDefinitionEntity, tagEntity);
}
}
// Filter duplicates and validate the result.
assertEquals(ImmutableSet.copyOf(businessObjectDefinitionEntities), ImmutableSet.copyOf(businessObjectDefinitionDao.getBusinessObjectDefinitions(tagEntities)));
}
use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionIndexSearchDaoTest method testSearchBusinessObjectDefinitionByTagsFunction.
@Test
public void testSearchBusinessObjectDefinitionByTagsFunction() throws Exception {
SearchResult searchResult = mock(SearchResult.class);
JestResult jestResult = mock(JestResult.class);
Terms.Bucket tagTypeCodeBucket = mock(Terms.Bucket.class);
List<Terms.Bucket> tagTypeCodeBucketList = new ArrayList<>();
tagTypeCodeBucketList.add(tagTypeCodeBucket);
// Mock the call to external methods
when(jestClientHelper.searchExecute(any(Search.class))).thenReturn(searchResult);
List<TagTypeIndexSearchResponseDto> tagTypeIndexSearchResponseDtoList = new ArrayList<>();
when(elasticsearchHelper.getNestedTagTagIndexSearchResponseDto(any(SearchResult.class))).thenReturn(tagTypeIndexSearchResponseDtoList);
List<BusinessObjectDefinitionIndexSearchResponseDto> businessObjectDefinitionIndexSearchResponseDtoList = Arrays.asList(new BusinessObjectDefinitionIndexSearchResponseDto(new DataProvider("data provider"), "description 1", "display name", "bdefname", new Namespace("namespace")));
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("_scroll_id", "100");
when(searchResult.getSourceAsObjectList(BusinessObjectDefinitionIndexSearchResponseDto.class)).thenReturn(businessObjectDefinitionIndexSearchResponseDtoList);
when(jestClientHelper.searchScrollExecute(any())).thenReturn(jestResult);
when(searchResult.getJsonObject()).thenReturn(jsonObject);
// Get test tag entity
TagEntity tagEntity = new TagEntity();
tagEntity.setTagCode("TAG_CODE");
TagTypeEntity tagTypeEntity = new TagTypeEntity();
tagTypeEntity.setCode("TAG_TYPE_CODE");
tagTypeEntity.setDisplayName("DISPLAY_NAME");
tagTypeEntity.setOrderNumber(1);
tagEntity.setTagType(tagTypeEntity);
List<TagEntity> tagEntities = new ArrayList<>();
tagEntities.add(tagEntity);
// List<Map<SearchFilterType, List<TagEntity>>>
Map<SearchFilterType, List<TagEntity>> searchFilterTypeListMap = new HashMap<>();
searchFilterTypeListMap.put(SearchFilterType.INCLUSION_SEARCH_FILTER, tagEntities);
List<Map<SearchFilterType, List<TagEntity>>> tagEnLists = Collections.singletonList(searchFilterTypeListMap);
// Call the method under test.
ElasticsearchResponseDto result = businessObjectDefinitionIndexSearchDao.searchBusinessObjectDefinitionsByTags("INDEX_NAME", "DOCUMENT_TYPE", tagEnLists, new HashSet<>());
// Verify the external calls.
verify(jestClientHelper).searchExecute(any());
// Validate the results.
assertEquals(new ElasticsearchResponseDto(businessObjectDefinitionIndexSearchResponseDtoList, null, null, null), result);
}
use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionTagDaoTest method testGetBusinessObjectDefinitionTagsByTagEntities.
@Test
public void testGetBusinessObjectDefinitionTagsByTagEntities() {
// Create and persist two business object definition entities with display names in reverse order.
List<BusinessObjectDefinitionEntity> businessObjectDefinitionEntities = Arrays.asList(businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, BDEF_DISPLAY_NAME_2, NO_ATTRIBUTES), businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE_2, BDEF_NAME_2, DATA_PROVIDER_NAME, BDEF_DESCRIPTION_2, BDEF_DISPLAY_NAME, NO_ATTRIBUTES));
// Create and persist three tag entities with display names in reverse order.
List<TagEntity> tagEntities = Arrays.asList(tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE, TAG_DISPLAY_NAME_2, TAG_DESCRIPTION), tagDaoTestHelper.createTagEntity(TAG_TYPE_2, TAG_CODE_2, TAG_DISPLAY_NAME, TAG_DESCRIPTION), tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE_2, TAG_DISPLAY_NAME, TAG_DESCRIPTION));
// Create and persist two business object definition tag entities for the first two tag entities.
for (BusinessObjectDefinitionEntity businessObjectDefinitionEntity : businessObjectDefinitionEntities) {
for (TagEntity tagEntity : tagEntities.subList(0, 2)) {
businessObjectDefinitionTagDaoTestHelper.createBusinessObjectDefinitionTagEntity(businessObjectDefinitionEntity, tagEntity);
}
}
// Get business object definition tags by the list of tag entities.
// Validate that the keys are ordered by business object definition display name and tag display name.
assertEquals(Arrays.asList(new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE_2, BDEF_NAME_2), new TagKey(TAG_TYPE_2, TAG_CODE_2)), new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE_2, BDEF_NAME_2), new TagKey(TAG_TYPE, TAG_CODE)), new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME), new TagKey(TAG_TYPE_2, TAG_CODE_2)), new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME), new TagKey(TAG_TYPE, TAG_CODE))), businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagsByTagEntities(tagEntities));
// Try invalid values for all input parameters.
assertTrue(businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagsByTagEntities(Arrays.asList(tagEntities.get(2))).isEmpty());
}
use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class TagDaoImpl method getTagsByTagTypeAndParentTagCode.
@Override
public List<TagChild> getTagsByTagTypeAndParentTagCode(String tagType, String parentTagCode) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<TagEntity> criteria = builder.createQuery(TagEntity.class);
// The criteria root is the tag entity.
Root<TagEntity> tagEntityRoot = criteria.from(TagEntity.class);
// Join to the other tables we can filter on.
Join<TagEntity, TagTypeEntity> tagTypeEntityJoin = tagEntityRoot.join(TagEntity_.tagType);
// Get the columns.
Path<String> displayNameColumn = tagEntityRoot.get(TagEntity_.displayName);
// Create the standard restrictions (i.e. the standard where clauses).
List<Predicate> predicates = new ArrayList<>();
predicates.add(builder.equal(builder.upper(tagTypeEntityJoin.get(TagTypeEntity_.code)), tagType.toUpperCase()));
if (parentTagCode == null) {
// Parent tag code is not specified, then return all tags with no parents, i.e. root tags.
predicates.add(builder.isNull(tagEntityRoot.get(TagEntity_.parentTagEntity)));
} else {
// Add a restriction for the parent tag code.
predicates.add(builder.equal(builder.upper(tagEntityRoot.get(TagEntity_.parentTagEntity).get(TagEntity_.tagCode)), parentTagCode.toUpperCase()));
}
// Add all clauses to the query.
criteria.select(tagEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(builder.asc(displayNameColumn));
// Run the query to get a list of tag entities back.
List<TagEntity> tagEntities = entityManager.createQuery(criteria).getResultList();
// Populate tag child objects from the returned tag entities.
List<TagChild> tagChildren = new ArrayList<>();
for (TagEntity tagEntity : tagEntities) {
boolean hasChildren = !tagEntity.getChildrenTagEntities().isEmpty();
tagChildren.add(new TagChild(new TagKey(tagEntity.getTagType().getCode(), tagEntity.getTagCode()), hasChildren));
}
return tagChildren;
}
Aggregations