use of org.finra.herd.model.api.xml.TagListResponse in project herd by FINRAOS.
the class TagServiceImpl method getTags.
@Override
public TagListResponse getTags(String tagTypeCode, String tagCode) {
// Validate and trim the tag type code.
String tagTypeCodeLocal = alternateKeyHelper.validateStringParameter("tag type code", tagTypeCode);
String cleanTagCode = tagCode;
// Retrieve and ensure that a tag type exists for the specified tag type code.
tagTypeDaoHelper.getTagTypeEntity(new TagTypeKey(tagTypeCodeLocal));
// Get the list of tag keys.
TagListResponse response = new TagListResponse();
// getTag method will validate the requested tag exists
if (tagCode != null) {
cleanTagCode = alternateKeyHelper.validateStringParameter("tag code", tagCode);
TagKey tagKey = new TagKey(tagTypeCodeLocal, cleanTagCode);
Tag tag = getTag(tagKey);
response.setTagKey(tag.getTagKey());
response.setParentTagKey(tag.getParentTagKey());
}
List<TagChild> tagChildren = tagDao.getTagsByTagTypeAndParentTagCode(tagTypeCodeLocal, cleanTagCode);
response.setTagChildren(tagChildren);
return response;
}
use of org.finra.herd.model.api.xml.TagListResponse in project herd by FINRAOS.
the class TagServiceTest method testGetTags.
@Test
public void testGetTags() {
// Create and persist a tag type entity.
TagTypeEntity tagTypeEntity = tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION);
// Create and persist two tag entities for the same tag type.
tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE, TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION);
tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_2, TAG_TYPE_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2);
// Retrieve a list of tag keys.
TagListResponse resultTagKeys = tagService.getTags(TAG_TYPE, NO_PARENT_TAG_CODE);
// Validate the returned object.
assertNotNull(resultTagKeys);
assertEquals(Arrays.asList(new TagChild(new TagKey(TAG_TYPE, TAG_CODE), TAG_HAS_NO_CHILDREN), new TagChild(new TagKey(TAG_TYPE, TAG_CODE_2), TAG_HAS_NO_CHILDREN)), resultTagKeys.getTagChildren());
}
use of org.finra.herd.model.api.xml.TagListResponse in project herd by FINRAOS.
the class TagServiceTest method testGetTagsTagsNoExist.
@Test
public void testGetTagsTagsNoExist() {
// Create and persist a tag type entity.
tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION);
// Retrieve a list of tag keys, when none of the tags exist for the tag type.
TagListResponse resultTagKeys = tagService.getTags(TAG_TYPE, NO_PARENT_TAG_CODE);
// Validate the returned object.
assertNotNull(resultTagKeys);
assertEquals(0, resultTagKeys.getTagChildren().size());
}
use of org.finra.herd.model.api.xml.TagListResponse in project herd by FINRAOS.
the class TagRestControllerTest method testGetTags.
@Test
public void testGetTags() {
List<TagChild> tagChildren = new ArrayList<>();
tagChildren.add(new TagChild(new TagKey(TAG_TYPE, TAG_CODE), false));
tagChildren.add(new TagChild(new TagKey(TAG_TYPE, TAG_CODE_2), false));
TagListResponse tagListResponse = new TagListResponse();
tagListResponse.setTagChildren(tagChildren);
when(tagService.getTags(TAG_TYPE, TAG_CODE)).thenReturn(tagListResponse);
// Retrieve the tag.
TagListResponse resultTagKeys = tagRestController.getTags(TAG_TYPE, TAG_CODE);
// Verify the external calls.
verify(tagService).getTags(TAG_TYPE, TAG_CODE);
verifyNoMoreInteractions(tagService);
// Validate the returned object.
assertEquals(tagListResponse, resultTagKeys);
;
}
use of org.finra.herd.model.api.xml.TagListResponse in project herd by FINRAOS.
the class TagServiceTest method testGetTagsWithParent.
@Test
public void testGetTagsWithParent() {
// Create and persist a tag entity.
TagEntity root = tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE, TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION);
TagEntity child = tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE_2, TAG_DISPLAY_NAME + "x", TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2 + "x", root);
tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE_2 + "y", TAG_DISPLAY_NAME_2 + "y", TAG_SEARCH_SCORE_MULTIPLIER_3, TAG_DESCRIPTION_2 + "y", child);
// only the root
TagListResponse resultTagKeys = tagService.getTags(TAG_TYPE, NO_PARENT_TAG_CODE);
assertNull(resultTagKeys.getParentTagKey());
assertNull(resultTagKeys.getTagKey());
assertEquals(resultTagKeys.getTagChildren().size(), 1);
resultTagKeys = tagService.getTags(TAG_TYPE, TAG_CODE);
assertNull(resultTagKeys.getParentTagKey());
assertEquals(resultTagKeys.getTagChildren().size(), 1);
assertEquals(resultTagKeys.getTagKey(), new TagKey(TAG_TYPE, TAG_CODE));
// the lower case should be the same
resultTagKeys = tagService.getTags(TAG_TYPE, TAG_CODE.toLowerCase() + " ");
assertNull(resultTagKeys.getParentTagKey());
assertEquals(resultTagKeys.getTagChildren().size(), 1);
assertEquals(resultTagKeys.getTagKey(), new TagKey(TAG_TYPE, TAG_CODE));
resultTagKeys = tagService.getTags(TAG_TYPE, TAG_CODE_2.toLowerCase() + " ");
assertNotNull(resultTagKeys.getParentTagKey());
assertEquals(resultTagKeys.getParentTagKey(), new TagKey(TAG_TYPE, TAG_CODE));
assertEquals(resultTagKeys.getTagChildren().size(), 1);
assertEquals(resultTagKeys.getTagKey(), new TagKey(TAG_TYPE, TAG_CODE_2));
}
Aggregations