use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionTagDaoTestHelper method createBusinessObjectDefinitionTagEntity.
/**
* Creates and persists a new business object definition tag entity.
*
* @param businessObjectDefinitionKey the business object definition key
* @param tagKey the tag key
*
* @return the newly created business object definition tag entity
*/
public BusinessObjectDefinitionTagEntity createBusinessObjectDefinitionTagEntity(BusinessObjectDefinitionKey businessObjectDefinitionKey, TagKey tagKey) {
// Create a business object definition entity if needed.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(businessObjectDefinitionKey);
if (businessObjectDefinitionEntity == null) {
businessObjectDefinitionEntity = businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(businessObjectDefinitionKey, AbstractDaoTest.DATA_PROVIDER_NAME, AbstractDaoTest.DESCRIPTION);
}
// Create a tag entity if needed.
TagEntity tagEntity = tagDao.getTagByKey(tagKey);
if (tagEntity == null) {
tagEntity = tagDaoTestHelper.createTagEntity(tagKey.getTagTypeCode(), tagKey.getTagCode(), AbstractDaoTest.TAG_DISPLAY_NAME, AbstractDaoTest.TAG_DESCRIPTION);
}
return createBusinessObjectDefinitionTagEntity(businessObjectDefinitionEntity, tagEntity);
}
use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionIndexSearchDaoTest method testSearchBusinessObjectDefinitionByTagsFunctionExclusionAndTag.
@Test
public void testSearchBusinessObjectDefinitionByTagsFunctionExclusionAndTag() 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.EXCLUSION_SEARCH_FILTER, tagEntities);
List<Map<SearchFilterType, List<TagEntity>>> tagEnLists = Collections.singletonList(searchFilterTypeListMap);
// Mock the external calls.
when(elasticsearchHelper.getNestedTagTagIndexSearchResponseDto(searchResult)).thenReturn(tagTypeIndexSearchResponseDtoList);
// Call the method under test.
ElasticsearchResponseDto result = businessObjectDefinitionIndexSearchDao.searchBusinessObjectDefinitionsByTags("INDEX_NAME", "DOCUMENT_TYPE", tagEnLists, new HashSet<>(Arrays.asList("tag")));
// Verify the external calls.
verify(jestClientHelper, times(2)).searchExecute(any());
verify(jestClientHelper).searchScrollExecute(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 TagDaoImpl method getCountOfAllTags.
@Override
public long getCountOfAllTags() {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
Root<TagEntity> tagEntityRoot = criteria.from(TagEntity.class);
criteria.select(builder.count(tagEntityRoot));
return entityManager.createQuery(criteria).getSingleResult();
}
use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class TagDaoImpl method getTagsByTagTypeEntityAndParentTagCode.
@Override
public List<TagEntity> getTagsByTagTypeEntityAndParentTagCode(TagTypeEntity tagTypeEntity, String parentTagCode, Boolean isParentTagNull) {
// 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);
// 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(tagEntityRoot.get(TagEntity_.tagType), tagTypeEntity));
if (StringUtils.isNotBlank(parentTagCode)) {
// Return all tags that are immediate children of the specified parent tag.
predicates.add(builder.equal(builder.upper(tagEntityRoot.get(TagEntity_.parentTagEntity).get(TagEntity_.tagCode)), parentTagCode.toUpperCase()));
} else if (BooleanUtils.isTrue(isParentTagNull)) {
// The flag is non-null and true, return all tags with no parents, i.e. root tags.
predicates.add(builder.isNull(tagEntityRoot.get(TagEntity_.parentTagEntity)));
} else if (BooleanUtils.isFalse(isParentTagNull)) {
// The flag is non-null and false, return all tags with parents.
predicates.add(builder.isNotNull(tagEntityRoot.get(TagEntity_.parentTagEntity)));
}
// 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 the results.
return entityManager.createQuery(criteria).getResultList();
}
use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class TagDaoImpl method getTags.
@Override
public List<TagEntity> getTags() {
// 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 on 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);
Path<Integer> tagTypeOrderNumberColumn = tagTypeEntityJoin.get(TagTypeEntity_.orderNumber);
Path<String> tagTypeCodeColumn = tagTypeEntityJoin.get(TagTypeEntity_.code);
// Add all clauses to the query.
criteria.select(tagEntityRoot).orderBy(builder.asc(tagTypeOrderNumberColumn), builder.asc(tagTypeCodeColumn), builder.asc(displayNameColumn));
// Run the query to get the results.
return entityManager.createQuery(criteria).getResultList();
}
Aggregations