use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class TagDaoTest method testGetTagsByTagTypeAndParentTagCode.
@Test
public void testGetTagsByTagTypeAndParentTagCode() {
// Create a tag type entity.
TagTypeEntity tagTypeEntity = tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION);
// Create two root tag entities for the tag type with tag display name in reverse order.
List<TagEntity> rootTagEntities = Arrays.asList(tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE, TAG_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION), tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_2, TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION));
// Create two children for the first root tag with tag display name in reverse order.
List<TagEntity> childrenTagEntities = Arrays.asList(tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_3, TAG_DISPLAY_NAME_4, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, rootTagEntities.get(0)), tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_4, TAG_DISPLAY_NAME_3, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, rootTagEntities.get(0)));
// Create one grand child of the first root tag.
tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_5, TAG_DISPLAY_NAME_5, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, childrenTagEntities.get(0));
// Get root tag entities (by not specifying parent tag code).
assertEquals(Arrays.asList(new TagChild(new TagKey(TAG_TYPE, TAG_CODE_2), TAG_HAS_NO_CHILDREN), new TagChild(new TagKey(TAG_TYPE, TAG_CODE), TAG_HAS_CHILDREN)), tagDao.getTagsByTagTypeAndParentTagCode(TAG_TYPE, null));
// Get root tag entities by passing all case-insensitive parameters in uppercase.
assertEquals(Arrays.asList(new TagChild(new TagKey(TAG_TYPE, TAG_CODE_2), TAG_HAS_NO_CHILDREN), new TagChild(new TagKey(TAG_TYPE, TAG_CODE), TAG_HAS_CHILDREN)), tagDao.getTagsByTagTypeAndParentTagCode(TAG_TYPE.toUpperCase(), null));
// Get root tag entities by passing all case-insensitive parameters in lowercase.
assertEquals(Arrays.asList(new TagChild(new TagKey(TAG_TYPE, TAG_CODE_2), TAG_HAS_NO_CHILDREN), new TagChild(new TagKey(TAG_TYPE, TAG_CODE), TAG_HAS_CHILDREN)), tagDao.getTagsByTagTypeAndParentTagCode(TAG_TYPE.toLowerCase(), null));
// Try to get root tags with invalid values for all input parameters.
assertTrue(tagDao.getTagsByTagTypeAndParentTagCode(I_DO_NOT_EXIST, null).isEmpty());
// Get children tags (by specifying both tag type and parent tag type code).
assertEquals(Arrays.asList(new TagChild(new TagKey(TAG_TYPE, TAG_CODE_4), TAG_HAS_NO_CHILDREN), new TagChild(new TagKey(TAG_TYPE, TAG_CODE_3), TAG_HAS_CHILDREN)), tagDao.getTagsByTagTypeAndParentTagCode(TAG_TYPE, TAG_CODE));
// Get children tags by passing all case-insensitive parameters in uppercase.
assertEquals(Arrays.asList(new TagChild(new TagKey(TAG_TYPE, TAG_CODE_4), TAG_HAS_NO_CHILDREN), new TagChild(new TagKey(TAG_TYPE, TAG_CODE_3), TAG_HAS_CHILDREN)), tagDao.getTagsByTagTypeAndParentTagCode(TAG_TYPE.toUpperCase(), TAG_CODE.toUpperCase()));
// Get children tags by passing all case-insensitive parameters in lowercase.
assertEquals(Arrays.asList(new TagChild(new TagKey(TAG_TYPE, TAG_CODE_4), TAG_HAS_NO_CHILDREN), new TagChild(new TagKey(TAG_TYPE, TAG_CODE_3), TAG_HAS_CHILDREN)), tagDao.getTagsByTagTypeAndParentTagCode(TAG_TYPE.toLowerCase(), TAG_CODE.toLowerCase()));
// Try to get children tags with invalid values for all input parameters.
assertTrue(tagDao.getTagsByTagTypeAndParentTagCode(I_DO_NOT_EXIST, TAG_CODE).isEmpty());
assertTrue(tagDao.getTagsByTagTypeAndParentTagCode(TAG_TYPE, I_DO_NOT_EXIST).isEmpty());
}
use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class TagDaoTest method testGetChildrenTags.
@Test
public void testGetChildrenTags() {
// Create a tag type entity.
TagTypeEntity tagTypeEntity = tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION);
// Create two root tag entities for the tag type.
List<TagEntity> rootTagEntities = Arrays.asList(tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE, TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION), tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_2, TAG_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION));
// Create two children for the first root tag with tag display name in reverse order.
List<TagEntity> childrenTagEntities = Arrays.asList(tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_3, TAG_DISPLAY_NAME_4, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, rootTagEntities.get(0)), tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_4, TAG_DISPLAY_NAME_3, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, rootTagEntities.get(0)));
// Create one grand child of the first root tag.
tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_5, TAG_DISPLAY_NAME_5, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, childrenTagEntities.get(0));
// Get children tags for the first root tag.
assertEquals(Arrays.asList(childrenTagEntities.get(1), childrenTagEntities.get(0)), tagDao.getChildrenTags(Arrays.asList(rootTagEntities.get(0))));
// Get children tags for the list of root tags.
assertEquals(Arrays.asList(childrenTagEntities.get(1), childrenTagEntities.get(0)), tagDao.getChildrenTags(rootTagEntities));
// Try to get children tags with invalid values for all input parameters (by specifying only the second root tag entity).
assertTrue(tagDao.getChildrenTags(Arrays.asList(rootTagEntities.get(1))).isEmpty());
}
use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionIndexSearchDaoImpl method searchBusinessObjectDefinitionsByTags.
@Override
public ElasticsearchResponseDto searchBusinessObjectDefinitionsByTags(String indexName, String documentType, List<Map<SearchFilterType, List<TagEntity>>> nestedTagEntityMaps, Set<String> facetFieldsList) {
ElasticsearchResponseDto elasticsearchResponseDto = new ElasticsearchResponseDto();
List<List<TagEntity>> nestedInclusionTagEntityLists = new ArrayList<>();
List<List<TagEntity>> nestedExclusionTagEntityLists = new ArrayList<>();
for (Map<SearchFilterType, List<TagEntity>> tagEntityMap : nestedTagEntityMaps) {
if (tagEntityMap.containsKey(SearchFilterType.INCLUSION_SEARCH_FILTER)) {
nestedInclusionTagEntityLists.add(tagEntityMap.get(SearchFilterType.INCLUSION_SEARCH_FILTER));
} else if (tagEntityMap.containsKey(SearchFilterType.EXCLUSION_SEARCH_FILTER)) {
nestedExclusionTagEntityLists.add(tagEntityMap.get(SearchFilterType.EXCLUSION_SEARCH_FILTER));
}
}
LOGGER.info("Searching Elasticsearch business object definition documents from index, indexName={} and documentType={}, by tagEntityList={}", indexName, documentType, tagEntityListToString(flattenTagEntitiesList(nestedInclusionTagEntityLists)));
LOGGER.info("Excluding the following tagEntityList={}", indexName, documentType, tagEntityListToString(flattenTagEntitiesList(nestedExclusionTagEntityLists)));
BoolQueryBuilder compoundSearchFiltersQueryBuilder = new BoolQueryBuilder();
// If there are only exclusion tag entities then, get everything else, but the exclusion tags.
if (CollectionUtils.isEmpty(flattenTagEntitiesList(nestedInclusionTagEntityLists))) {
WildcardQueryBuilder wildcardQueryBuilder = QueryBuilders.wildcardQuery(NAME_FIELD, "*");
compoundSearchFiltersQueryBuilder.must(wildcardQueryBuilder);
}
// Inclusion
for (List<TagEntity> tagEntities : nestedInclusionTagEntityLists) {
BoolQueryBuilder searchFilterQueryBuilder = new BoolQueryBuilder();
for (TagEntity tagEntity : tagEntities) {
// Add constant-score term queries for tagType-code and tag-code from the tag-key.
ConstantScoreQueryBuilder searchKeyQueryBuilder = QueryBuilders.constantScoreQuery(QueryBuilders.boolQuery().must(QueryBuilders.termQuery(TAGTYPE_CODE_FIELD, tagEntity.getTagType().getCode())).must(QueryBuilders.termQuery(TAG_CODE_FIELD, tagEntity.getTagCode())));
// Individual tag-keys are OR-ed
searchFilterQueryBuilder.should(searchKeyQueryBuilder);
}
// Individual search-filters are AND-ed
compoundSearchFiltersQueryBuilder.must(searchFilterQueryBuilder);
}
// Exclusion
for (List<TagEntity> tagEntities : nestedExclusionTagEntityLists) {
for (TagEntity tagEntity : tagEntities) {
// Add constant-score term queries for tagType-code and tag-code from the tag-key.
QueryBuilder searchKeyQueryBuilder = QueryBuilders.boolQuery().must(QueryBuilders.termQuery(TAGTYPE_CODE_FIELD, tagEntity.getTagType().getCode())).must(QueryBuilders.termQuery(TAG_CODE_FIELD, tagEntity.getTagCode()));
// Exclusion: individual tag-keys are added as a must not query
compoundSearchFiltersQueryBuilder.mustNot(searchKeyQueryBuilder);
}
}
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
// Fetch only the required fields
searchSourceBuilder.fetchSource(new String[] { DATA_PROVIDER_NAME_SOURCE, DESCRIPTION_SOURCE, DISPLAY_NAME_SOURCE, NAME_SOURCE, NAMESPACE_CODE_SOURCE }, null);
searchSourceBuilder.query(compoundSearchFiltersQueryBuilder);
// Create a search request and set the scroll time and scroll size
SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(new ElasticsearchClientImpl(), SearchAction.INSTANCE);
searchRequestBuilder.setIndices(indexName);
// Construct scroll query
searchRequestBuilder.setTypes(documentType).setScroll(new TimeValue(ELASTIC_SEARCH_SCROLL_KEEP_ALIVE_TIME)).setSize(ELASTIC_SEARCH_SCROLL_PAGE_SIZE).setSource(searchSourceBuilder).addSort(SortBuilders.fieldSort(BUSINESS_OBJECT_DEFINITION_SORT_FIELD).order(SortOrder.ASC)).addSort(SortBuilders.fieldSort(NAMESPACE_CODE_SORT_FIELD).order(SortOrder.ASC));
// Add aggregation builder if facet fields are present
if (CollectionUtils.isNotEmpty(facetFieldsList)) {
addFacetFieldAggregations(facetFieldsList, elasticsearchResponseDto, searchRequestBuilder, indexName);
}
// Log the actual search query
LOGGER.info("bdefIndexSearchQuery={}", searchRequestBuilder.toString());
elasticsearchResponseDto.setBusinessObjectDefinitionIndexSearchResponseDtos(scrollSearchResultsIntoBusinessObjectDefinitionDto(searchRequestBuilder, indexName));
return elasticsearchResponseDto;
}
use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionTagDaoImpl method getBusinessObjectDefinitionTagsByTagEntities.
@Override
public List<BusinessObjectDefinitionTagKey> getBusinessObjectDefinitionTagsByTagEntities(List<TagEntity> tagEntities) {
// Create the criteria builder and a tuple style criteria query.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Tuple> criteria = builder.createTupleQuery();
// The criteria root is the business object definition tag entity.
Root<BusinessObjectDefinitionTagEntity> businessObjectDefinitionTagEntityRoot = criteria.from(BusinessObjectDefinitionTagEntity.class);
// Join to the other tables we can filter on.
Join<BusinessObjectDefinitionTagEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntityJoin = businessObjectDefinitionTagEntityRoot.join(BusinessObjectDefinitionTagEntity_.businessObjectDefinition);
Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntityJoin = businessObjectDefinitionEntityJoin.join(BusinessObjectDefinitionEntity_.namespace);
Join<BusinessObjectDefinitionTagEntity, TagEntity> tagEntityJoin = businessObjectDefinitionTagEntityRoot.join(BusinessObjectDefinitionTagEntity_.tag);
Join<TagEntity, TagTypeEntity> tagTypeEntityJoin = tagEntityJoin.join(TagEntity_.tagType);
// Get the columns.
Path<String> namespaceCodeColumn = namespaceEntityJoin.get(NamespaceEntity_.code);
Path<String> businessObjectDefinitionNameColumn = businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.name);
Path<String> businessObjectDefinitionDisplayNameColumn = businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.displayName);
Path<String> tagTypeCodeColumn = tagTypeEntityJoin.get(TagTypeEntity_.code);
Path<String> tagCodeColumn = tagEntityJoin.get(TagEntity_.tagCode);
Path<String> tagDisplayNameColumn = tagEntityJoin.get(TagEntity_.displayName);
// Create the standard restrictions (i.e. the standard where clauses).
Predicate predicate = getPredicateForInClause(builder, businessObjectDefinitionTagEntityRoot.get(BusinessObjectDefinitionTagEntity_.tag), tagEntities);
// Order the results by business object definition display name (an optional column),
// business object definition namespace, business object definition name, tag display name,
// and tag type code (since tag display name is unique across a tag type).
List<Order> orderBy = new ArrayList<>();
orderBy.add(builder.asc(businessObjectDefinitionDisplayNameColumn));
orderBy.add(builder.asc(namespaceCodeColumn));
orderBy.add(builder.asc(businessObjectDefinitionNameColumn));
orderBy.add(builder.asc(tagDisplayNameColumn));
orderBy.add(builder.asc(tagTypeCodeColumn));
// Add the clauses for the query.
criteria.multiselect(namespaceCodeColumn, businessObjectDefinitionNameColumn, tagTypeCodeColumn, tagCodeColumn).where(predicate).orderBy(orderBy);
// Run the query to get a list of tuples back.
List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();
// Populate the "keys" objects from the returned tuples (i.e. 1 tuple for each row).
List<BusinessObjectDefinitionTagKey> businessObjectDefinitionTagKeys = new ArrayList<>();
for (Tuple tuple : tuples) {
businessObjectDefinitionTagKeys.add(new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(tuple.get(namespaceCodeColumn), tuple.get(businessObjectDefinitionNameColumn)), new TagKey(tuple.get(tagTypeCodeColumn), tuple.get(tagCodeColumn))));
}
return businessObjectDefinitionTagKeys;
}
use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionServiceTest method setUpTestEntitiesForSearchTesting.
private Set<BusinessObjectDefinition> setUpTestEntitiesForSearchTesting() {
// Create and retrieve a list of business object definition entities.
List<BusinessObjectDefinitionEntity> businessObjectDefinitionEntities = businessObjectDefinitionDaoTestHelper.createExpectedBusinessObjectDefinitionEntities();
// Create and persist a tag type entity.
TagTypeEntity tagTypeEntity = tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION);
// Create a root tag entity for the tag type.
TagEntity rootTagEntity = tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE, TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION);
// Create three children for the root tag.
TagEntity childTagEntity1 = tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_2, TAG_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2, rootTagEntity);
TagEntity childTagEntity2 = tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_3, TAG_DISPLAY_NAME_3, TAG_SEARCH_SCORE_MULTIPLIER_3, TAG_DESCRIPTION_3, rootTagEntity);
TagEntity childTagEntity3 = tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_4, TAG_DISPLAY_NAME_4, TAG_SEARCH_SCORE_MULTIPLIER_4, TAG_DESCRIPTION_4, rootTagEntity);
// Create association between business object definition and tag.
businessObjectDefinitionTagDaoTestHelper.createBusinessObjectDefinitionTagEntity(businessObjectDefinitionEntities.get(0), childTagEntity1);
businessObjectDefinitionTagDaoTestHelper.createBusinessObjectDefinitionTagEntity(businessObjectDefinitionEntities.get(1), childTagEntity2);
businessObjectDefinitionTagDaoTestHelper.createBusinessObjectDefinitionTagEntity(businessObjectDefinitionEntities.get(2), childTagEntity3);
// Convert the entities into business object definition objects for easy comparison later.
return businessObjectDefinitionEntities.stream().map(businessObjectDefinitionServiceTestHelper::createBusinessObjectDefinitionFromEntityForSearchTesting).collect(Collectors.toSet());
}
Aggregations