use of org.finra.herd.model.api.xml.TagSearchKey in project herd by FINRAOS.
the class TagServiceImpl method validateTagSearchRequest.
/**
* Validate the tag search request. This method also trims the request parameters.
*
* @param tagSearchRequest the tag search request
*/
private void validateTagSearchRequest(TagSearchRequest tagSearchRequest) {
Assert.notNull(tagSearchRequest, "A tag search request must be specified.");
// Continue validation if the list of tag search filters is not empty.
if (CollectionUtils.isNotEmpty(tagSearchRequest.getTagSearchFilters()) && tagSearchRequest.getTagSearchFilters().get(0) != null) {
// Validate that there is only one tag search filter.
Assert.isTrue(CollectionUtils.size(tagSearchRequest.getTagSearchFilters()) == 1, "At most one tag search filter must be specified.");
// Get the tag search filter.
TagSearchFilter tagSearchFilter = tagSearchRequest.getTagSearchFilters().get(0);
// Validate that exactly one tag search key is specified.
Assert.isTrue(CollectionUtils.size(tagSearchFilter.getTagSearchKeys()) == 1 && tagSearchFilter.getTagSearchKeys().get(0) != null, "Exactly one tag search key must be specified.");
// Get the tag search key.
TagSearchKey tagSearchKey = tagSearchFilter.getTagSearchKeys().get(0);
tagSearchKey.setTagTypeCode(alternateKeyHelper.validateStringParameter("tag type code", tagSearchKey.getTagTypeCode()));
if (tagSearchKey.getParentTagCode() != null) {
tagSearchKey.setParentTagCode(tagSearchKey.getParentTagCode().trim());
}
// Fail validation when parent tag code is specified along with the isParentTagNull flag set to true.
Assert.isTrue(StringUtils.isBlank(tagSearchKey.getParentTagCode()) || BooleanUtils.isNotTrue(tagSearchKey.isIsParentTagNull()), "A parent tag code can not be specified when isParentTagNull flag is set to true.");
}
}
use of org.finra.herd.model.api.xml.TagSearchKey in project herd by FINRAOS.
the class TagServiceImpl method searchTags.
@Override
public TagSearchResponse searchTags(TagSearchRequest request, Set<String> fields) {
// Validate and trim the request parameters.
validateTagSearchRequest(request);
// Validate and trim the search response fields.
validateSearchResponseFields(fields);
// Prepare the result list.
List<TagEntity> tagEntities = new ArrayList<>();
// If search key is specified, use it to retrieve the tags.
if (CollectionUtils.isNotEmpty(request.getTagSearchFilters()) && request.getTagSearchFilters().get(0) != null) {
// Get the tag search key.
TagSearchKey tagSearchKey = request.getTagSearchFilters().get(0).getTagSearchKeys().get(0);
// Retrieve and ensure that a tag type exists for the specified tag type code.
TagTypeEntity tagTypeEntity = tagTypeDaoHelper.getTagTypeEntity(new TagTypeKey(tagSearchKey.getTagTypeCode()));
// Retrieve the tags.
tagEntities.addAll(tagDao.getTagsByTagTypeEntityAndParentTagCode(tagTypeEntity, tagSearchKey.getParentTagCode(), tagSearchKey.isIsParentTagNull()));
} else // The search key is not specified, so select all tags registered in the system.
{
// Retrieve the tags.
tagEntities.addAll(tagDao.getTags());
}
// Build the list of tags.
List<Tag> tags = new ArrayList<>();
for (TagEntity tagEntity : tagEntities) {
tags.add(createTagFromEntity(tagEntity, false, fields.contains(DISPLAY_NAME_FIELD), fields.contains(SEARCH_SCORE_MULTIPLIER_FIELD), fields.contains(DESCRIPTION_FIELD), false, false, false, fields.contains(PARENT_TAG_KEY_FIELD), fields.contains(HAS_CHILDREN_FIELD)));
}
// Build and return the tag search response.
return new TagSearchResponse(tags);
}
use of org.finra.herd.model.api.xml.TagSearchKey in project herd by FINRAOS.
the class TagRestControllerTest method testSearchTags.
@Test
public void testSearchTags() {
TagSearchResponse tagSearchResponse = new TagSearchResponse(Arrays.asList(new Tag(NO_ID, new TagKey(TAG_TYPE, TAG_CODE_3), TAG_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER_3, TAG_DESCRIPTION_3, NO_USER_ID, NO_USER_ID, NO_UPDATED_TIME, new TagKey(TAG_TYPE, TAG_CODE), TAG_HAS_NO_CHILDREN), new Tag(NO_ID, new TagKey(TAG_TYPE, TAG_CODE_2), TAG_DISPLAY_NAME_3, TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2, NO_USER_ID, NO_USER_ID, NO_UPDATED_TIME, new TagKey(TAG_TYPE, TAG_CODE), TAG_HAS_NO_CHILDREN)));
Set<String> searchFields = Sets.newHashSet(TagServiceImpl.DISPLAY_NAME_FIELD, TagServiceImpl.DESCRIPTION_FIELD, TagServiceImpl.PARENT_TAG_KEY_FIELD, TagServiceImpl.HAS_CHILDREN_FIELD);
TagSearchRequest tagSearchRequest = new TagSearchRequest(Arrays.asList(new TagSearchFilter(Arrays.asList(new TagSearchKey(TAG_TYPE, TAG_CODE, NO_IS_PARENT_TAG_NULL_FLAG)))));
when(tagService.searchTags(tagSearchRequest, searchFields)).thenReturn(tagSearchResponse);
// Search the tags.
TagSearchResponse resultTagSearchResponse = tagRestController.searchTags(tagSearchRequest, searchFields);
// Verify the external calls.
verify(tagService).searchTags(tagSearchRequest, searchFields);
verifyNoMoreInteractions(tagService);
// Validate the returned object.
assertEquals(tagSearchResponse, resultTagSearchResponse);
}
use of org.finra.herd.model.api.xml.TagSearchKey in project herd by FINRAOS.
the class TagServiceTest method testSearchTagsWithIsParentTagNullFlag.
@Test
public void testSearchTagsWithIsParentTagNullFlag() {
// Create and persist database entities required for testing.
createDatabaseEntitiesForTagSearchTesting();
// Get root tag entities (parent tag must not be set).
assertEquals(new TagSearchResponse(Arrays.asList(new Tag(NO_ID, new TagKey(TAG_TYPE, TAG_CODE), NO_TAG_DISPLAY_NAME, NO_TAG_SEARCH_SCORE_MULTIPLIER, NO_TAG_DESCRIPTION, NO_USER_ID, NO_USER_ID, NO_UPDATED_TIME, NO_PARENT_TAG_KEY, NO_TAG_HAS_CHILDREN_FLAG))), tagService.searchTags(new TagSearchRequest(Arrays.asList(new TagSearchFilter(Arrays.asList(new TagSearchKey(TAG_TYPE, NO_PARENT_TAG_CODE, PARENT_TAG_IS_NULL))))), NO_SEARCH_RESPONSE_FIELDS));
// Get all non-root tag entities (parent tag must be set).
assertEquals(new TagSearchResponse(Arrays.asList(new Tag(NO_ID, new TagKey(TAG_TYPE, TAG_CODE_3), NO_TAG_DISPLAY_NAME, NO_TAG_SEARCH_SCORE_MULTIPLIER, NO_TAG_DESCRIPTION, NO_USER_ID, NO_USER_ID, NO_UPDATED_TIME, NO_PARENT_TAG_KEY, NO_TAG_HAS_CHILDREN_FLAG), new Tag(NO_ID, new TagKey(TAG_TYPE, TAG_CODE_2), NO_TAG_DISPLAY_NAME, NO_TAG_SEARCH_SCORE_MULTIPLIER, NO_TAG_DESCRIPTION, NO_USER_ID, NO_USER_ID, NO_UPDATED_TIME, NO_PARENT_TAG_KEY, NO_TAG_HAS_CHILDREN_FLAG))), tagService.searchTags(new TagSearchRequest(Arrays.asList(new TagSearchFilter(Arrays.asList(new TagSearchKey(TAG_TYPE, NO_PARENT_TAG_CODE, PARENT_TAG_IS_NOT_NULL))))), NO_SEARCH_RESPONSE_FIELDS));
}
use of org.finra.herd.model.api.xml.TagSearchKey in project herd by FINRAOS.
the class TagServiceTest method testSearchTags.
@Test
public void testSearchTags() {
// Create and persist database entities required for testing.
createDatabaseEntitiesForTagSearchTesting();
// Search the tags.
TagSearchResponse tagSearchResponse = tagService.searchTags(new TagSearchRequest(Arrays.asList(new TagSearchFilter(Arrays.asList(new TagSearchKey(TAG_TYPE, TAG_CODE, NO_IS_PARENT_TAG_NULL_FLAG))))), Sets.newHashSet(TagServiceImpl.DISPLAY_NAME_FIELD, TagServiceImpl.SEARCH_SCORE_MULTIPLIER_FIELD, TagServiceImpl.DESCRIPTION_FIELD, TagServiceImpl.PARENT_TAG_KEY_FIELD, TagServiceImpl.HAS_CHILDREN_FIELD));
// Validate the returned object.
assertEquals(new TagSearchResponse(Arrays.asList(new Tag(NO_ID, new TagKey(TAG_TYPE, TAG_CODE_3), TAG_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER_3, TAG_DESCRIPTION_3, NO_USER_ID, NO_USER_ID, NO_UPDATED_TIME, new TagKey(TAG_TYPE, TAG_CODE), TAG_HAS_NO_CHILDREN), new Tag(NO_ID, new TagKey(TAG_TYPE, TAG_CODE_2), TAG_DISPLAY_NAME_3, TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2, NO_USER_ID, NO_USER_ID, NO_UPDATED_TIME, new TagKey(TAG_TYPE, TAG_CODE), TAG_HAS_NO_CHILDREN))), tagSearchResponse);
}
Aggregations