Search in sources :

Example 1 with TagEntity

use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.

the class TagDaoTest method testGetTagByKey.

@Test
public void testGetTagByKey() {
    // Create a tag entity.
    TagEntity tagEntity = tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE, TAG_DISPLAY_NAME, TAG_DESCRIPTION);
    // Get tag entity and validate.
    assertEquals(tagEntity, tagDao.getTagByKey(new TagKey(TAG_TYPE, TAG_CODE)));
    // Get tag entity by passing all case-insensitive parameters in uppercase.
    assertEquals(tagEntity, tagDao.getTagByKey(new TagKey(TAG_TYPE.toUpperCase(), TAG_CODE.toUpperCase())));
    // Get tag entity by passing all case-insensitive parameters in lowercase.
    assertEquals(tagEntity, tagDao.getTagByKey(new TagKey(TAG_TYPE.toLowerCase(), TAG_CODE.toLowerCase())));
    // Try invalid values for all input parameters.
    assertNull(tagDao.getTagByKey(new TagKey(I_DO_NOT_EXIST, TAG_CODE)));
    assertNull(tagDao.getTagByKey(new TagKey(TAG_TYPE, I_DO_NOT_EXIST)));
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity) TagKey(org.finra.herd.model.api.xml.TagKey) Test(org.junit.Test)

Example 2 with TagEntity

use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.

the class TagDaoTest method testGetPercentageOfAllTagsZeroPercent.

@Test
public void testGetPercentageOfAllTagsZeroPercent() {
    // 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_DESCRIPTION), tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_2, TAG_DISPLAY_NAME, TAG_DESCRIPTION_2));
    // Create an empty list
    List<TagEntity> emptyList = new ArrayList<>();
    // Get the list of all tags aka. 0%
    assertEquals(emptyList, tagDao.getPercentageOfAllTags(0.0));
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with TagEntity

use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.

the class TagDaoTest method testGetTagsByTagTypeEntityAndParentTagCode.

@Test
public void testGetTagsByTagTypeEntityAndParentTagCode() {
    // 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_DESCRIPTION), tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_2, TAG_DISPLAY_NAME, TAG_DESCRIPTION_2));
    // Create two children for the first root tag and one child for the second with tag display name in reverse order.
    List<TagEntity> childrenTagEntities = Arrays.asList(tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_3, TAG_DISPLAY_NAME_5, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION_3, rootTagEntities.get(0)), tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_4, TAG_DISPLAY_NAME_4, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION_4, rootTagEntities.get(0)), tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_5, TAG_DISPLAY_NAME_3, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION_5, rootTagEntities.get(1)));
    // Get all tag entities for the tag type regardless of their parent tag field.
    assertEquals(Arrays.asList(rootTagEntities.get(1), rootTagEntities.get(0), childrenTagEntities.get(2), childrenTagEntities.get(1), childrenTagEntities.get(0)), tagDao.getTagsByTagTypeEntityAndParentTagCode(tagTypeEntity, NO_PARENT_TAG_CODE, NO_IS_PARENT_TAG_NULL_FLAG));
    // Get root tag entities (parent tag must not be set).
    assertEquals(Arrays.asList(rootTagEntities.get(1), rootTagEntities.get(0)), tagDao.getTagsByTagTypeEntityAndParentTagCode(tagTypeEntity, NO_PARENT_TAG_CODE, PARENT_TAG_IS_NULL));
    // Get all non-root tag entities (parent tag must be set).
    assertEquals(Arrays.asList(childrenTagEntities.get(2), childrenTagEntities.get(1), childrenTagEntities.get(0)), tagDao.getTagsByTagTypeEntityAndParentTagCode(tagTypeEntity, NO_PARENT_TAG_CODE, PARENT_TAG_IS_NOT_NULL));
    // Get all immediate children of the root tag.
    assertEquals(Arrays.asList(childrenTagEntities.get(1), childrenTagEntities.get(0)), tagDao.getTagsByTagTypeEntityAndParentTagCode(tagTypeEntity, TAG_CODE, NO_IS_PARENT_TAG_NULL_FLAG));
    // Get all immediate children of the root tag when isParentTagNull flag is set to true (the flag value should get ignored).
    assertEquals(Arrays.asList(childrenTagEntities.get(1), childrenTagEntities.get(0)), tagDao.getTagsByTagTypeEntityAndParentTagCode(tagTypeEntity, TAG_CODE, PARENT_TAG_IS_NULL));
    // Get all immediate children of the root tag by passing all case-insensitive parameters in lowercase.
    assertEquals(Arrays.asList(childrenTagEntities.get(1), childrenTagEntities.get(0)), tagDao.getTagsByTagTypeEntityAndParentTagCode(tagTypeEntity, TAG_CODE.toUpperCase(), NO_IS_PARENT_TAG_NULL_FLAG));
    // Get all immediate children of the root tag by passing all case-insensitive parameters in lowercase.
    assertEquals(Arrays.asList(childrenTagEntities.get(1), childrenTagEntities.get(0)), tagDao.getTagsByTagTypeEntityAndParentTagCode(tagTypeEntity, TAG_CODE.toLowerCase(), NO_IS_PARENT_TAG_NULL_FLAG));
    // Create another tag type entity without any tag associated with it.
    TagTypeEntity invalidTagTypeEntity = tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE_2, TAG_TYPE_DISPLAY_NAME_2, TAG_TYPE_ORDER_2, TAG_TYPE_DESCRIPTION_2);
    // Try to get all immediate children of the root tag with invalid values for all input parameters.
    assertTrue(tagDao.getTagsByTagTypeEntityAndParentTagCode(invalidTagTypeEntity, TAG_CODE, NO_IS_PARENT_TAG_NULL_FLAG).isEmpty());
    assertTrue(tagDao.getTagsByTagTypeEntityAndParentTagCode(tagTypeEntity, I_DO_NOT_EXIST, NO_IS_PARENT_TAG_NULL_FLAG).isEmpty());
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) Test(org.junit.Test)

Example 4 with TagEntity

use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.

the class TagDaoTest method testGetMostRecentTags.

@Ignore
public void testGetMostRecentTags() {
    List<TagEntity> tagEntities = new ArrayList<>();
    // 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, TAG_DESCRIPTION), tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_2, TAG_DISPLAY_NAME_2, TAG_DESCRIPTION_2));
    // Only add the most recent 1 to the list
    tagEntities.add(rootTagEntities.get(1));
    // Get the list of most recent tags
    assertEquals(tagEntities, tagDao.getMostRecentTags(1));
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity) ArrayList(java.util.ArrayList) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) Ignore(org.junit.Ignore)

Example 5 with TagEntity

use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.

the class TagDaoTestHelper method createTagEntity.

/**
 * Creates and persists a new tag entity.
 *
 * @param tagTypeEntity the tag type entity
 * @param tagCode the tag code
 * @param tagDisplayName the tag display name
 * @param tagSearchScoreMultiplier the tag's search score multiplier
 * @param tagDescription the description of the tag
 * @param parentTagEntity the parent tag entity
 *
 * @return the newly created tag entity
 */
public TagEntity createTagEntity(TagTypeEntity tagTypeEntity, String tagCode, String tagDisplayName, BigDecimal tagSearchScoreMultiplier, String tagDescription, TagEntity parentTagEntity) {
    TagEntity tagEntity = new TagEntity();
    tagEntity.setTagType(tagTypeEntity);
    tagEntity.setTagCode(tagCode);
    tagEntity.setDisplayName(tagDisplayName);
    tagEntity.setSearchScoreMultiplier(tagSearchScoreMultiplier);
    tagEntity.setDescription(tagDescription);
    tagEntity.setParentTagEntity(parentTagEntity);
    return tagDao.saveAndRefresh(tagEntity);
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity)

Aggregations

TagEntity (org.finra.herd.model.jpa.TagEntity)111 Test (org.junit.Test)77 TagKey (org.finra.herd.model.api.xml.TagKey)55 ArrayList (java.util.ArrayList)44 TagTypeEntity (org.finra.herd.model.jpa.TagTypeEntity)33 Tag (org.finra.herd.model.api.xml.Tag)28 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)15 SearchIndexUpdateDto (org.finra.herd.model.dto.SearchIndexUpdateDto)14 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)13 TagUpdateRequest (org.finra.herd.model.api.xml.TagUpdateRequest)12 ElasticsearchResponseDto (org.finra.herd.model.dto.ElasticsearchResponseDto)11 BusinessObjectDefinitionTagEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity)11 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)10 Predicate (javax.persistence.criteria.Predicate)9 BusinessObjectDefinitionSearchKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchKey)9 TagCreateRequest (org.finra.herd.model.api.xml.TagCreateRequest)9 BusinessObjectDefinitionIndexSearchResponse (org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse)8 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)8 BusinessObjectDefinitionSearchFilter (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter)8 BusinessObjectDefinitionIndexSearchResponseDto (org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto)8