use of org.finra.herd.model.api.xml.TagKey in project herd by FINRAOS.
the class ElasticSearchHelperTest method testAddIndexSearchFilterBooleanClause.
@Test
public void testAddIndexSearchFilterBooleanClause() {
TagKey tagKey = new TagKey();
tagKey.setTagCode(TAG_CODE);
tagKey.setTagTypeCode(TAG_TYPE_CODE);
IndexSearchResultTypeKey indexSearchResultTypeKey = new IndexSearchResultTypeKey();
indexSearchResultTypeKey.setIndexSearchResultType(INDEX_SEARCH_RESULT_TYPE);
List<IndexSearchKey> indexSearchKeys = new ArrayList<>();
IndexSearchKey indexSearchKey = new IndexSearchKey();
indexSearchKey.setTagKey(tagKey);
indexSearchKey.setIndexSearchResultTypeKey(indexSearchResultTypeKey);
indexSearchKeys.add(indexSearchKey);
List<IndexSearchFilter> indexSearchFilters = new ArrayList<>();
IndexSearchFilter indexSearchFilter1 = new IndexSearchFilter();
indexSearchFilter1.setIsExclusionSearchFilter(true);
indexSearchFilter1.setIndexSearchKeys(indexSearchKeys);
IndexSearchFilter indexSearchFilter2 = new IndexSearchFilter();
indexSearchFilter2.setIsExclusionSearchFilter(false);
indexSearchFilter2.setIndexSearchKeys(indexSearchKeys);
indexSearchFilters.add(indexSearchFilter1);
indexSearchFilters.add(indexSearchFilter2);
BoolQueryBuilder result = elasticsearchHelper.addIndexSearchFilterBooleanClause(indexSearchFilters, "bdefIndex", "tagIndex");
assertThat("Result is null.", result, is(notNullValue()));
}
use of org.finra.herd.model.api.xml.TagKey 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)));
}
use of org.finra.herd.model.api.xml.TagKey in project herd by FINRAOS.
the class IndexSearchServiceImpl method validateIndexSearchFilters.
/**
* Validates the specified index search filters.
*
* @param indexSearchFilters the index search filters
*/
private void validateIndexSearchFilters(List<IndexSearchFilter> indexSearchFilters) {
// Validate that the search filters list is not empty
Assert.notEmpty(indexSearchFilters, "At least one index search filter must be specified.");
for (IndexSearchFilter searchFilter : indexSearchFilters) {
// Silently skip a search filter which is null
if (searchFilter != null) {
// Validate that each search filter has at least one index search key
Assert.notEmpty(searchFilter.getIndexSearchKeys(), "At least one index search key must be specified.");
// Guard against a single null element in the index search keys list
if (searchFilter.getIndexSearchKeys().get(0) != null) {
// Get the instance type of the key in the search filter, match all other keys with this
Class<?> expectedInstanceType = searchFilter.getIndexSearchKeys().get(0).getIndexSearchResultTypeKey() != null ? IndexSearchResultTypeKey.class : TagKey.class;
searchFilter.getIndexSearchKeys().forEach(indexSearchKey -> {
// Validate that each search key has either an index search result type key or a tag key
Assert.isTrue((indexSearchKey.getIndexSearchResultTypeKey() != null) ^ (indexSearchKey.getTagKey() != null), "Exactly one instance of index search result type key or tag key must be specified.");
Class<?> actualInstanceType = indexSearchKey.getIndexSearchResultTypeKey() != null ? IndexSearchResultTypeKey.class : TagKey.class;
// Validate that search keys within the same filter have either index search result type keys or tag keys
Assert.isTrue(expectedInstanceType.equals(actualInstanceType), "Index search keys should be a homogeneous list of either index search result type keys or tag keys.");
// Validate tag key if present
if (indexSearchKey.getTagKey() != null) {
tagHelper.validateTagKey(indexSearchKey.getTagKey());
// Validates that a tag entity exists for the specified tag key and gets the actual key from the database
// We then modify the index search filter key to use the actual values because it eventually becomes a filter query and it will not
// automatically be case-sensitivity and whitespace resilient.
TagEntity actualTagEntity = tagDaoHelper.getTagEntity(indexSearchKey.getTagKey());
TagKey tagKey = new TagKey(actualTagEntity.getTagType().getCode(), actualTagEntity.getTagCode());
indexSearchKey.setTagKey(tagKey);
}
// Validate search result type key if present
if (indexSearchKey.getIndexSearchResultTypeKey() != null) {
validateIndexSearchResultTypeKey(indexSearchKey.getIndexSearchResultTypeKey());
// Ensure that specified search index type exists.
searchIndexTypeDaoHelper.getSearchIndexTypeEntity(indexSearchKey.getIndexSearchResultTypeKey().getIndexSearchResultType());
}
});
}
}
}
}
use of org.finra.herd.model.api.xml.TagKey in project herd by FINRAOS.
the class TagServiceImpl method getTags.
@Override
public TagListResponse getTags(String tagTypeCode, String tagCode) {
// Validate and trim the tag type code.
String tagTypeCodeLocal = alternateKeyHelper.validateStringParameter("tag type code", tagTypeCode);
String cleanTagCode = tagCode;
// Retrieve and ensure that a tag type exists for the specified tag type code.
tagTypeDaoHelper.getTagTypeEntity(new TagTypeKey(tagTypeCodeLocal));
// Get the list of tag keys.
TagListResponse response = new TagListResponse();
// getTag method will validate the requested tag exists
if (tagCode != null) {
cleanTagCode = alternateKeyHelper.validateStringParameter("tag code", tagCode);
TagKey tagKey = new TagKey(tagTypeCodeLocal, cleanTagCode);
Tag tag = getTag(tagKey);
response.setTagKey(tag.getTagKey());
response.setParentTagKey(tag.getParentTagKey());
}
List<TagChild> tagChildren = tagDao.getTagsByTagTypeAndParentTagCode(tagTypeCodeLocal, cleanTagCode);
response.setTagChildren(tagChildren);
return response;
}
use of org.finra.herd.model.api.xml.TagKey in project herd by FINRAOS.
the class TagServiceImpl method createTagFromEntity.
/**
* Creates the tag from the persisted entity.
*
* @param tagEntity the tag entity
* @param includeId specifies to include the display name field
* @param includeDisplayName specifies to include the display name field
* @param includeSearchScoreMultiplier specifies to include the search score multiplier
* @param includeDescription specifies to include the description field
* @param includeUserId specifies to include the user id of the user who created this tag
* @param includeLastUpdatedByUserId specifies to include the user id of the user who last updated this tag
* @param includeUpdatedTime specifies to include the timestamp of when this tag is last updated
* @param includeParentTagKey specifies to include the parent tag key field
* @param includeHasChildren specifies to include the hasChildren field
*
* @return the tag
*/
private Tag createTagFromEntity(TagEntity tagEntity, boolean includeId, boolean includeDisplayName, boolean includeSearchScoreMultiplier, boolean includeDescription, boolean includeUserId, boolean includeLastUpdatedByUserId, boolean includeUpdatedTime, boolean includeParentTagKey, boolean includeHasChildren) {
Tag tag = new Tag();
if (includeId) {
tag.setId(tagEntity.getId());
}
tag.setTagKey(new TagKey(tagEntity.getTagType().getCode(), tagEntity.getTagCode()));
if (includeDisplayName) {
tag.setDisplayName(tagEntity.getDisplayName());
}
if (includeSearchScoreMultiplier) {
tag.setSearchScoreMultiplier(tagEntity.getSearchScoreMultiplier());
}
if (includeDescription) {
tag.setDescription(tagEntity.getDescription());
}
if (includeUserId) {
tag.setUserId(tagEntity.getCreatedBy());
}
if (includeLastUpdatedByUserId) {
tag.setLastUpdatedByUserId(tagEntity.getUpdatedBy());
}
if (includeUpdatedTime) {
tag.setUpdatedTime(HerdDateUtils.getXMLGregorianCalendarValue(tagEntity.getUpdatedOn()));
}
if (includeParentTagKey) {
TagEntity parentTagEntity = tagEntity.getParentTagEntity();
if (parentTagEntity != null) {
tag.setParentTagKey(new TagKey(parentTagEntity.getTagType().getCode(), parentTagEntity.getTagCode()));
}
}
if (includeHasChildren) {
tag.setHasChildren(!tagEntity.getChildrenTagEntities().isEmpty());
}
return tag;
}
Aggregations