Search in sources :

Example 61 with TagEntity

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

the class TagDaoImpl method getTagsByIds.

@Override
public List<TagEntity> getTagsByIds(List<Integer> ids) {
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<TagEntity> criteria = builder.createQuery(TagEntity.class);
    // The criteria root is the tag entity.
    Root<TagEntity> tagEntityRoot = criteria.from(TagEntity.class);
    // Create the standard restrictions (i.e. the standard where clauses).
    Expression<Integer> expression = tagEntityRoot.get(TagEntity_.id);
    Predicate queryRestriction = expression.in(ids);
    criteria.select(tagEntityRoot).where(queryRestriction);
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) TagEntity(org.finra.herd.model.jpa.TagEntity) Predicate(javax.persistence.criteria.Predicate)

Example 62 with TagEntity

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

the class TagDaoImpl method getPercentageOfAllTags.

@Override
public List<TagEntity> getPercentageOfAllTags(double percentage) {
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Integer> criteria = builder.createQuery(Integer.class);
    // The criteria root is the tag.
    Root<TagEntity> tagEntityRoot = criteria.from(TagEntity.class);
    // Get the columns.
    Path<Integer> idColumn = tagEntityRoot.get(TagEntity_.id);
    criteria.select(idColumn);
    List<Integer> allTagIdsList = entityManager.createQuery(criteria).getResultList();
    List<Integer> percentageOfTagIdsList = new ArrayList<>();
    /*
        * Gets a percentage of all tag entities.
        * The percentage is randomly selected from all the tags.
        *
        * For each tag id in the list of all tag ids, get a random double value between 0 and 1.
        * If that value is below the percentage double value, also a number between 0 and 1 (inclusive),
        * then add the tag id to the list of tag ids that will be used to return a random percentage
        * of tag entities retrieved from the database.
        */
    allTagIdsList.forEach(id -> {
        if (ThreadLocalRandom.current().nextDouble() < percentage) {
            percentageOfTagIdsList.add(id);
        }
    });
    return getTagsByIds(percentageOfTagIdsList);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) TagEntity(org.finra.herd.model.jpa.TagEntity) ArrayList(java.util.ArrayList)

Example 63 with TagEntity

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

the class TagDaoTest method testGetPercentageOfAllTagsOneHundredPercent.

@Test
public void testGetPercentageOfAllTagsOneHundredPercent() {
    // 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));
    // Get the list of all tags aka. 100%
    assertEquals(rootTagEntities, tagDao.getPercentageOfAllTags(1.0));
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) Test(org.junit.Test)

Example 64 with TagEntity

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

the class TagDaoTest method testGetTagByTagTypeAndDisplayName.

@Test
public void testGetTagByTagTypeAndDisplayName() {
    // 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.getTagByTagTypeAndDisplayName(TAG_TYPE, TAG_DISPLAY_NAME));
    // Get tag entity by passing all case-insensitive parameters in uppercase.
    assertEquals(tagEntity, tagDao.getTagByTagTypeAndDisplayName(TAG_TYPE.toUpperCase(), TAG_DISPLAY_NAME.toUpperCase()));
    // Get tag entity by passing all case-insensitive parameters in lowercase.
    assertEquals(tagEntity, tagDao.getTagByTagTypeAndDisplayName(TAG_TYPE.toLowerCase(), TAG_DISPLAY_NAME.toLowerCase()));
    // Try invalid values for all input parameters.
    assertNull(tagDao.getTagByTagTypeAndDisplayName(I_DO_NOT_EXIST, TAG_DISPLAY_NAME));
    assertNull(tagDao.getTagByTagTypeAndDisplayName(TAG_TYPE, I_DO_NOT_EXIST));
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity) Test(org.junit.Test)

Example 65 with TagEntity

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

the class TagDaoTest method testGetCountOfAllTags.

@Test
public void testGetCountOfAllTags() {
    // 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));
    // Get the count of all tags
    assertEquals(rootTagEntities.size(), tagDao.getCountOfAllTags());
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) Test(org.junit.Test)

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