Search in sources :

Example 1 with TagListResponse

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;
}
Also used : TagChild(org.finra.herd.model.api.xml.TagChild) TagListResponse(org.finra.herd.model.api.xml.TagListResponse) TagTypeKey(org.finra.herd.model.api.xml.TagTypeKey) TagKey(org.finra.herd.model.api.xml.TagKey) Tag(org.finra.herd.model.api.xml.Tag)

Example 2 with TagListResponse

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());
}
Also used : TagChild(org.finra.herd.model.api.xml.TagChild) TagListResponse(org.finra.herd.model.api.xml.TagListResponse) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) TagKey(org.finra.herd.model.api.xml.TagKey) Test(org.junit.Test)

Example 3 with TagListResponse

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());
}
Also used : TagListResponse(org.finra.herd.model.api.xml.TagListResponse) Test(org.junit.Test)

Example 4 with TagListResponse

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);
    ;
}
Also used : TagChild(org.finra.herd.model.api.xml.TagChild) TagListResponse(org.finra.herd.model.api.xml.TagListResponse) ArrayList(java.util.ArrayList) TagKey(org.finra.herd.model.api.xml.TagKey) Test(org.junit.Test)

Example 5 with TagListResponse

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));
}
Also used : TagListResponse(org.finra.herd.model.api.xml.TagListResponse) TagEntity(org.finra.herd.model.jpa.TagEntity) TagKey(org.finra.herd.model.api.xml.TagKey) Test(org.junit.Test)

Aggregations

TagListResponse (org.finra.herd.model.api.xml.TagListResponse)8 TagKey (org.finra.herd.model.api.xml.TagKey)7 Test (org.junit.Test)7 TagChild (org.finra.herd.model.api.xml.TagChild)6 TagTypeEntity (org.finra.herd.model.jpa.TagTypeEntity)4 ArrayList (java.util.ArrayList)1 Tag (org.finra.herd.model.api.xml.Tag)1 TagTypeKey (org.finra.herd.model.api.xml.TagTypeKey)1 TagEntity (org.finra.herd.model.jpa.TagEntity)1