use of org.finra.herd.model.api.xml.TagKey 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.api.xml.TagKey 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.api.xml.TagKey in project herd by FINRAOS.
the class BusinessObjectDefinitionRestControllerIndexTest method testIndexSearchBusinessObjectDefinitions.
@Test
public void testIndexSearchBusinessObjectDefinitions() {
// 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(false, businessObjectDefinitionSearchKeyList));
// Create a list of facet fields
List<String> facetFields = new ArrayList<>();
facetFields.add("Invalid");
// Create a new business object definition search request that will be used when testing the index search business object definitions method
BusinessObjectDefinitionIndexSearchRequest businessObjectDefinitionSearchRequest = new BusinessObjectDefinitionIndexSearchRequest(businessObjectDefinitionSearchFilterList, facetFields);
// 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 business object definition entity list to return from the search business object definitions by tags function
List<BusinessObjectDefinitionEntity> businessObjectDefinitionEntityList = new ArrayList<>();
businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, businessObjectDefinitionServiceTestHelper.getNewAttributes()));
businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME_2, DATA_PROVIDER_NAME_2, BDEF_DESCRIPTION_2, businessObjectDefinitionServiceTestHelper.getNewAttributes()));
// Create a list to hold the business object definitions that will be returned as part of the search response
List<BusinessObjectDefinition> businessObjectDefinitions = new ArrayList<>();
// Retrieve all unique business object definition entities and construct a list of business object definitions based on the requested fields.
for (BusinessObjectDefinitionEntity businessObjectDefinitionEntity : ImmutableSet.copyOf(businessObjectDefinitionEntityList)) {
// Convert the business object definition entity to a business object definition and add it to the list of business object definitions that will be
// returned as a part of the search response
BusinessObjectDefinition businessObjectDefinition = new BusinessObjectDefinition();
// Populate the business object definition
businessObjectDefinition.setNamespace(businessObjectDefinitionEntity.getNamespace().getCode());
businessObjectDefinition.setBusinessObjectDefinitionName(businessObjectDefinitionEntity.getName());
businessObjectDefinition.setDataProviderName(businessObjectDefinitionEntity.getDataProvider().getName());
businessObjectDefinition.setShortDescription(StringUtils.left(businessObjectDefinitionEntity.getDescription(), SHORT_DESCRIPTION_LENGTH));
businessObjectDefinition.setDisplayName(businessObjectDefinitionEntity.getDisplayName());
businessObjectDefinitions.add(businessObjectDefinition);
}
List<TagTypeIndexSearchResponseDto> tagTypeIndexSearchResponseDtos = new ArrayList<>();
List<TagIndexSearchResponseDto> tagIndexSearchResponseDtos = new ArrayList<>();
tagIndexSearchResponseDtos.add(new TagIndexSearchResponseDto(TAG_CODE, TAG_COUNT, TAG_DISPLAY_NAME));
tagIndexSearchResponseDtos.add(new TagIndexSearchResponseDto(TAG_CODE_2, TAG_COUNT, TAG_DISPLAY_NAME_2));
TagTypeIndexSearchResponseDto tagTypeIndexSearchResponseDto = new TagTypeIndexSearchResponseDto(TAG_TYPE, tagIndexSearchResponseDtos, TAG_TYPE_DISPLAY_NAME);
tagTypeIndexSearchResponseDtos.add(tagTypeIndexSearchResponseDto);
List<Facet> tagTypeFacets = new ArrayList<>();
for (TagTypeIndexSearchResponseDto tagTypeIndexSearchResponse : ImmutableSet.copyOf(tagTypeIndexSearchResponseDtos)) {
List<Facet> tagFacets = new ArrayList<>();
for (TagIndexSearchResponseDto tagIndexSearchResponseDto : tagTypeIndexSearchResponse.getTagIndexSearchResponseDtos()) {
Facet tagFacet = new Facet(tagIndexSearchResponseDto.getTagDisplayName(), tagIndexSearchResponseDto.getCount(), FacetTypeEnum.TAG.value(), tagIndexSearchResponseDto.getTagCode(), null);
tagFacets.add(tagFacet);
}
tagTypeFacets.add(new Facet(tagTypeIndexSearchResponse.getDisplayName(), null, FacetTypeEnum.TAG_TYPE.value(), tagTypeIndexSearchResponse.getCode(), tagFacets));
}
// Construct business object search response.
BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponse = new BusinessObjectDefinitionIndexSearchResponse();
businessObjectDefinitionSearchResponse.setBusinessObjectDefinitions(businessObjectDefinitions);
businessObjectDefinitionSearchResponse.setFacets(tagTypeFacets);
// Mock the call to the business object definition service
when(businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionSearchRequest, fields)).thenReturn(businessObjectDefinitionSearchResponse);
// Create a business object definition.
BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponseFromRestCall = businessObjectDefinitionRestController.indexSearchBusinessObjectDefinitions(fields, businessObjectDefinitionSearchRequest);
// Verify the method call to businessObjectDefinitionService.indexAllBusinessObjectDefinitions()
verify(businessObjectDefinitionService, times(1)).indexSearchBusinessObjectDefinitions(businessObjectDefinitionSearchRequest, fields);
// Validate the returned object.
assertThat("Business object definition index search response was null.", businessObjectDefinitionSearchResponseFromRestCall, not(nullValue()));
assertThat("Business object definition index search response was not correct.", businessObjectDefinitionSearchResponseFromRestCall, is(businessObjectDefinitionSearchResponse));
assertThat("Business object definition index search response was not an instance of BusinessObjectDefinitionSearchResponse.class.", businessObjectDefinitionSearchResponseFromRestCall, instanceOf(BusinessObjectDefinitionIndexSearchResponse.class));
}
use of org.finra.herd.model.api.xml.TagKey in project herd by FINRAOS.
the class BusinessObjectDefinitionServiceTest method testSearchBusinessObjectDefinitionsOnlyShortDescriptionAndDisplayName.
@Test
public void testSearchBusinessObjectDefinitionsOnlyShortDescriptionAndDisplayName() {
// 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.setDataProviderName(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_SHORT_DESCRIPTION, FIELD_DISPLAY_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 BusinessObjectDefinitionServiceTest method testSearchBusinessObjectDefinitionsMissingOptionalParams.
@Test
public void testSearchBusinessObjectDefinitionsMissingOptionalParams() {
// 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);
businessObjectDefinition.setDataProviderName(null);
}
// Retrieve the actual business object definition objects from the search response.
// Fields are required to have a blank text value because that is set by default in the controller.
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(BLANK_TEXT));
Set<BusinessObjectDefinition> actualBusinessObjectDefinitions = new HashSet<>(searchResponse.getBusinessObjectDefinitions());
assertEquals(actualBusinessObjectDefinitions, expectedBusinessObjectDefinitions);
}
Aggregations