use of org.finra.herd.model.api.xml.TagKey in project herd by FINRAOS.
the class BusinessObjectDefinitionTagDaoTest method testGetBusinessObjectDefinitionTagByKey.
@Test
public void testGetBusinessObjectDefinitionTagByKey() {
// Create a business object definition tag key.
BusinessObjectDefinitionTagKey businessObjectDefinitionTagKey = new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME), new TagKey(TAG_TYPE, TAG_CODE));
// Create and persist a business object definition tag entity.
BusinessObjectDefinitionTagEntity businessObjectDefinitionTagEntity = businessObjectDefinitionTagDaoTestHelper.createBusinessObjectDefinitionTagEntity(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME), new TagKey(TAG_TYPE, TAG_CODE));
// Get the business object definition tag.
assertEquals(businessObjectDefinitionTagEntity, businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagByKey(businessObjectDefinitionTagKey));
// Get business object definition tag by passing all case-insensitive parameters in uppercase.
assertEquals(businessObjectDefinitionTagEntity, businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagByKey(new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE.toUpperCase(), BDEF_NAME.toUpperCase()), new TagKey(TAG_TYPE.toUpperCase(), TAG_CODE.toUpperCase()))));
// Get business object definition tag by passing all case-insensitive parameters in lowercase.
assertEquals(businessObjectDefinitionTagEntity, businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagByKey(new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE.toLowerCase(), BDEF_NAME.toLowerCase()), new TagKey(TAG_TYPE.toLowerCase(), TAG_CODE.toLowerCase()))));
// Try invalid values for all input parameters.
assertNull(businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagByKey(new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey("I_DO_NOT_EXIST", BDEF_NAME), new TagKey(TAG_TYPE, TAG_CODE))));
assertNull(businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagByKey(new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, "I_DO_NOT_EXIST"), new TagKey(TAG_TYPE, TAG_CODE))));
assertNull(businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagByKey(new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME), new TagKey("I_DO_NOT_EXIST", TAG_CODE))));
assertNull(businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagByKey(new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME), new TagKey(TAG_TYPE, "I_DO_NOT_EXIST"))));
}
use of org.finra.herd.model.api.xml.TagKey in project herd by FINRAOS.
the class TagDaoImpl method getTagsByTagTypeAndParentTagCode.
@Override
public List<TagChild> getTagsByTagTypeAndParentTagCode(String tagType, String parentTagCode) {
// 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 to the other tables we can filter on.
Join<TagEntity, TagTypeEntity> tagTypeEntityJoin = tagEntityRoot.join(TagEntity_.tagType);
// Get the columns.
Path<String> displayNameColumn = tagEntityRoot.get(TagEntity_.displayName);
// 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)), tagType.toUpperCase()));
if (parentTagCode == null) {
// Parent tag code is not specified, then return all tags with no parents, i.e. root tags.
predicates.add(builder.isNull(tagEntityRoot.get(TagEntity_.parentTagEntity)));
} else {
// Add a restriction for the parent tag code.
predicates.add(builder.equal(builder.upper(tagEntityRoot.get(TagEntity_.parentTagEntity).get(TagEntity_.tagCode)), parentTagCode.toUpperCase()));
}
// Add all clauses to the query.
criteria.select(tagEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(builder.asc(displayNameColumn));
// Run the query to get a list of tag entities back.
List<TagEntity> tagEntities = entityManager.createQuery(criteria).getResultList();
// Populate tag child objects from the returned tag entities.
List<TagChild> tagChildren = new ArrayList<>();
for (TagEntity tagEntity : tagEntities) {
boolean hasChildren = !tagEntity.getChildrenTagEntities().isEmpty();
tagChildren.add(new TagChild(new TagKey(tagEntity.getTagType().getCode(), tagEntity.getTagCode()), hasChildren));
}
return tagChildren;
}
use of org.finra.herd.model.api.xml.TagKey in project herd by FINRAOS.
the class BusinessObjectDefinitionTagDaoTest method testGetBusinessObjectDefinitionTagsByBusinessObjectDefinitionEntity.
@Test
public void testGetBusinessObjectDefinitionTagsByBusinessObjectDefinitionEntity() {
// Create and persist two business object definition entities.
List<BusinessObjectDefinitionEntity> businessObjectDefinitionEntities = Arrays.asList(businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME), DATA_PROVIDER_NAME, DESCRIPTION), businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(new BusinessObjectDefinitionKey(BDEF_NAMESPACE_2, BDEF_NAME_2), DATA_PROVIDER_NAME, DESCRIPTION));
// Create and persist two tag entities with display names in reverse order.
List<TagEntity> tagEntities = Arrays.asList(tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE, TAG_DISPLAY_NAME_2, TAG_DESCRIPTION), tagDaoTestHelper.createTagEntity(TAG_TYPE_2, TAG_CODE_2, TAG_DISPLAY_NAME, TAG_DESCRIPTION));
// Create and persist two business object definition tag entities for the first business object definition entity.
for (TagEntity tagEntity : tagEntities) {
businessObjectDefinitionTagDaoTestHelper.createBusinessObjectDefinitionTagEntity(businessObjectDefinitionEntities.get(0), tagEntity);
}
// Get business object definition tags by business object definition entity.
assertEquals(Arrays.asList(new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME), new TagKey(TAG_TYPE_2, TAG_CODE_2)), new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME), new TagKey(TAG_TYPE, TAG_CODE))), businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagsByBusinessObjectDefinitionEntity(businessObjectDefinitionEntities.get(0)));
// Try invalid values for all input parameters.
assertTrue(businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagsByBusinessObjectDefinitionEntity(businessObjectDefinitionEntities.get(1)).isEmpty());
}
use of org.finra.herd.model.api.xml.TagKey in project herd by FINRAOS.
the class BusinessObjectDefinitionTagDaoTest method testGetBusinessObjectDefinitionTagByKeyDuplicateTags.
@Test
public void testGetBusinessObjectDefinitionTagByKeyDuplicateTags() throws Exception {
// Create a business object definition entity.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION);
// Create duplicate business object definition tags.
businessObjectDefinitionTagDaoTestHelper.createBusinessObjectDefinitionTagEntity(businessObjectDefinitionEntity, tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE.toUpperCase(), TAG_DISPLAY_NAME, DESCRIPTION));
businessObjectDefinitionTagDaoTestHelper.createBusinessObjectDefinitionTagEntity(businessObjectDefinitionEntity, tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE.toLowerCase(), TAG_DISPLAY_NAME, DESCRIPTION));
// Try to get business object definition tag when business object definition tags are duplicate.
try {
businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagByKey(new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME), new TagKey(TAG_TYPE, TAG_CODE)));
fail();
} catch (IllegalArgumentException e) {
assertEquals(String.format("Found more than one business object definition tag instance with parameters {namespace=\"%s\", " + "businessObjectDefinitionName=\"%s\", tagType=\"%s\", tagCode=\"%s\"}.", BDEF_NAMESPACE, BDEF_NAME, TAG_TYPE, TAG_CODE), e.getMessage());
}
}
use of org.finra.herd.model.api.xml.TagKey in project herd by FINRAOS.
the class IndexSearchDaoTest method indexSearchTestWithTagKeyFilterAndExcludeFlagSet.
@Test
public void indexSearchTestWithTagKeyFilterAndExcludeFlagSet() throws IOException {
// Create a new fields set that will be used when testing the index search method
final Set<String> fields = new HashSet<>();
// Create an index search key
final IndexSearchKey indexSearchKey = new IndexSearchKey();
// Create a tag key
final TagKey tagKey = new TagKey(TAG_TYPE_CODE, TAG_CODE);
indexSearchKey.setTagKey(tagKey);
// Create an index search keys list and add the previously defined key to it
final List<IndexSearchKey> indexSearchKeys = Collections.singletonList(indexSearchKey);
// Create an index search filter with the keys previously defined
final IndexSearchFilter indexSearchFilter = new IndexSearchFilter(NO_EXCLUSION_SEARCH_FILTER, indexSearchKeys);
// Set exclude filter flag to true
indexSearchFilter.setIsExclusionSearchFilter(true);
List<IndexSearchFilter> indexSearchFilters = Collections.singletonList(indexSearchFilter);
// result type facet only
testIndexSearch(fields, indexSearchFilters, null, NO_ENABLE_HIT_HIGHLIGHTING);
}
Aggregations