use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class TagDaoImpl method getChildrenTags.
@Override
public List<TagEntity> getChildrenTags(List<TagEntity> parentTagEntities) {
// Create the criteria builder and the criteria.
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);
// Get the columns.
Path<String> tagDisplayNameColumn = tagEntityRoot.get(TagEntity_.displayName);
// Create the standard restrictions (i.e. the standard where clauses).
Predicate predicate = getPredicateForInClause(builder, tagEntityRoot.get(TagEntity_.parentTagEntity), parentTagEntities);
// Add all clauses to the query.
criteria.select(tagEntityRoot).where(predicate).orderBy(builder.asc(tagDisplayNameColumn));
// Run the query to get a list of tag children.
return entityManager.createQuery(criteria).getResultList();
}
use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class TagDaoImpl method getTagByKey.
@Override
public TagEntity getTagByKey(TagKey tagKey) {
// Create the criteria builder and the criteria.
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);
// Join on the other tables we can filter on.
Join<TagEntity, TagTypeEntity> tagTypeEntityJoin = tagEntityRoot.join(TagEntity_.tagType);
// Create the standard restrictions (i.e. the standard where clauses).
List<Predicate> predicates = new ArrayList<>();
predicates.add(builder.equal(builder.upper(tagTypeEntityJoin.get(TagTypeEntity_.code)), tagKey.getTagTypeCode().toUpperCase()));
predicates.add(builder.equal(builder.upper(tagEntityRoot.get(TagEntity_.tagCode)), tagKey.getTagCode().toUpperCase()));
// Add all clauses to the query.
criteria.select(tagEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()])));
return executeSingleResultQuery(criteria, String.format("Found more than one tag with parameters {tagType=\"%s\", tagCode=\"%s\"}.", tagKey.getTagTypeCode(), tagKey.getTagCode()));
}
use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class TagDaoImpl method getMostRecentTags.
@Override
public List<TagEntity> getMostRecentTags(int numberOfResults) {
// 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.
Root<TagEntity> tagEntityRoot = criteria.from(TagEntity.class);
// Get the columns.
Path<Timestamp> tagUpdatedOnColumn = tagEntityRoot.get(TagEntity_.updatedOn);
// Select the tags and order descending by the updated on column
criteria.select(tagEntityRoot).orderBy(builder.desc(tagUpdatedOnColumn));
return entityManager.createQuery(criteria).setMaxResults(numberOfResults).getResultList();
}
use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class TagDaoImpl method getTagByTagTypeAndDisplayName.
@Override
public TagEntity getTagByTagTypeAndDisplayName(String tagTypeCode, String displayName) {
// Create the criteria builder and the criteria.
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);
// Join on the other tables we can filter on.
Join<TagEntity, TagTypeEntity> tagTypeEntityJoin = tagEntityRoot.join(TagEntity_.tagType);
// Create the standard restrictions (i.e. the standard where clauses).
List<Predicate> predicates = new ArrayList<>();
predicates.add(builder.equal(builder.upper(tagTypeEntityJoin.get(TagTypeEntity_.code)), tagTypeCode.toUpperCase()));
predicates.add(builder.equal(builder.upper(tagEntityRoot.get(TagEntity_.displayName)), displayName.toUpperCase()));
// Add all clauses to the query.
criteria.select(tagEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()])));
return executeSingleResultQuery(criteria, String.format("Found more than one tag with parameters {tagType=\"%s\", displayName=\"%s\"}.", tagTypeCode, displayName));
}
use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionHelperTest method testProcessTagSearchScoreMultiplier.
@Test
public void testProcessTagSearchScoreMultiplier() {
// Create a business object definition entity
final BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, businessObjectDefinitionServiceTestHelper.getNewAttributes2());
// Create two tag entities
TagEntity tagEntity1 = tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE, TAG_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, null);
TagEntity tagEntity2 = tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE, TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER_NULL, TAG_DESCRIPTION, null);
// Assocaite tag entities with business object definition entity
List<BusinessObjectDefinitionTagEntity> businessObjectDefinitionTagEntities = Arrays.asList(businessObjectDefinitionTagDaoTestHelper.createBusinessObjectDefinitionTagEntity(businessObjectDefinitionEntity, tagEntity1), businessObjectDefinitionTagDaoTestHelper.createBusinessObjectDefinitionTagEntity(businessObjectDefinitionEntity, tagEntity2));
businessObjectDefinitionEntity.setBusinessObjectDefinitionTags(businessObjectDefinitionTagEntities);
// Call the method under test
businessObjectDefinitionHelper.processTagSearchScoreMultiplier(businessObjectDefinitionEntity);
// Validate the result
assertEquals(businessObjectDefinitionEntity.getTagSearchScoreMultiplier(), TAG_SEARCH_SCORE_MULTIPLIER.setScale(3, RoundingMode.HALF_UP));
}
Aggregations