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();
}
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);
}
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));
}
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));
}
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());
}
Aggregations