Search in sources :

Example 1 with TagTypeKey

use of org.finra.herd.model.api.xml.TagTypeKey in project herd by FINRAOS.

the class TagTypeServiceImpl method createTagTypeFromEntity.

/**
 * Creates the tag type registration from the persisted entity.
 *
 * @param tagTypeEntity the tag type registration entity
 * @param includeDisplayName specifies to include the display name field
 * @param includeTagTypeOrder specifies to include the tag type order field
 * @param includeDescription specifies to include the description field
 *
 * @return the tag type registration
 */
private TagType createTagTypeFromEntity(TagTypeEntity tagTypeEntity, boolean includeDisplayName, boolean includeTagTypeOrder, boolean includeDescription) {
    TagType tagType = new TagType();
    TagTypeKey tagTypeKey = new TagTypeKey();
    tagType.setTagTypeKey(tagTypeKey);
    tagTypeKey.setTagTypeCode(tagTypeEntity.getCode());
    if (includeDisplayName) {
        tagType.setDisplayName(tagTypeEntity.getDisplayName());
    }
    if (includeTagTypeOrder) {
        tagType.setTagTypeOrder(tagTypeEntity.getOrderNumber());
    }
    if (includeDescription) {
        tagType.setDescription(tagTypeEntity.getDescription());
    }
    return tagType;
}
Also used : TagType(org.finra.herd.model.api.xml.TagType) TagTypeKey(org.finra.herd.model.api.xml.TagTypeKey)

Example 2 with TagTypeKey

use of org.finra.herd.model.api.xml.TagTypeKey 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 3 with TagTypeKey

use of org.finra.herd.model.api.xml.TagTypeKey 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);
}
Also used : TagSearchKey(org.finra.herd.model.api.xml.TagSearchKey) TagSearchResponse(org.finra.herd.model.api.xml.TagSearchResponse) TagTypeKey(org.finra.herd.model.api.xml.TagTypeKey) TagEntity(org.finra.herd.model.jpa.TagEntity) ArrayList(java.util.ArrayList) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) Tag(org.finra.herd.model.api.xml.Tag)

Example 4 with TagTypeKey

use of org.finra.herd.model.api.xml.TagTypeKey in project herd by FINRAOS.

the class TagTypeRestControllerTest method testDeleteTagType.

@Test
public void testDeleteTagType() throws Exception {
    TagTypeKey tagTypeKey = new TagTypeKey(TAG_TYPE);
    TagType tagType = new TagType(new TagTypeKey(TAG_TYPE), TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION);
    when(tagTypeService.deleteTagType(tagTypeKey)).thenReturn(tagType);
    // Delete this tag type.
    TagType deletedTagType = tagTypeRestController.deleteTagType(TAG_TYPE);
    // Verify the external calls.
    verify(tagTypeService).deleteTagType(tagTypeKey);
    verifyNoMoreInteractions(tagTypeService);
    // Validate the returned object.
    assertEquals(tagType, deletedTagType);
}
Also used : TagType(org.finra.herd.model.api.xml.TagType) TagTypeKey(org.finra.herd.model.api.xml.TagTypeKey) Test(org.junit.Test)

Example 5 with TagTypeKey

use of org.finra.herd.model.api.xml.TagTypeKey in project herd by FINRAOS.

the class TagTypeRestControllerTest method testGetTagType.

@Test
public void testGetTagType() throws Exception {
    TagTypeKey tagTypeKey = new TagTypeKey(TAG_TYPE);
    TagType tagType = new TagType(new TagTypeKey(TAG_TYPE), TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION);
    when(tagTypeService.getTagType(tagTypeKey)).thenReturn(tagType);
    // Retrieve the tag type.
    TagType resultTagType = tagTypeRestController.getTagType(TAG_TYPE);
    // Verify the external calls.
    verify(tagTypeService).getTagType(tagTypeKey);
    verifyNoMoreInteractions(tagTypeService);
    // Validate the returned object.
    assertEquals(tagType, resultTagType);
}
Also used : TagType(org.finra.herd.model.api.xml.TagType) TagTypeKey(org.finra.herd.model.api.xml.TagTypeKey) Test(org.junit.Test)

Aggregations

TagTypeKey (org.finra.herd.model.api.xml.TagTypeKey)44 Test (org.junit.Test)40 TagType (org.finra.herd.model.api.xml.TagType)27 TagTypeUpdateRequest (org.finra.herd.model.api.xml.TagTypeUpdateRequest)10 TagTypeCreateRequest (org.finra.herd.model.api.xml.TagTypeCreateRequest)7 TagTypeSearchRequest (org.finra.herd.model.api.xml.TagTypeSearchRequest)6 TagTypeSearchResponse (org.finra.herd.model.api.xml.TagTypeSearchResponse)6 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)4 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)3 TagTypeEntity (org.finra.herd.model.jpa.TagTypeEntity)3 ArrayList (java.util.ArrayList)2 Tag (org.finra.herd.model.api.xml.Tag)2 TagTypeKeys (org.finra.herd.model.api.xml.TagTypeKeys)2 TagEntity (org.finra.herd.model.jpa.TagEntity)2 TagChild (org.finra.herd.model.api.xml.TagChild)1 TagKey (org.finra.herd.model.api.xml.TagKey)1 TagListResponse (org.finra.herd.model.api.xml.TagListResponse)1 TagSearchKey (org.finra.herd.model.api.xml.TagSearchKey)1 TagSearchResponse (org.finra.herd.model.api.xml.TagSearchResponse)1