use of org.finra.herd.model.api.xml.Tag 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.Tag 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;
}
use of org.finra.herd.model.api.xml.Tag in project herd by FINRAOS.
the class TagServiceImpl method indexValidateTagsList.
/**
* A helper method that will validate a list of tags
*
* @param tagEntityList the list of tags that will be validated
*
* @return true all of the tags are valid in the index
*/
private boolean indexValidateTagsList(final List<TagEntity> tagEntityList) {
final String indexName = SearchIndexTypeEntity.SearchIndexTypes.TAG.name().toLowerCase();
final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
Predicate<TagEntity> validInIndexPredicate = tagEntity -> {
// Fetch Join with .size()
tagEntity.getChildrenTagEntities().size();
// Convert the tag entity to a JSON string
final String jsonString = tagHelper.safeObjectMapperWriteValueAsString(tagEntity);
return this.indexFunctionsDao.isValidDocumentIndex(indexName, documentType, tagEntity.getId().toString(), jsonString);
// searchFunctions.getIsValidFunction().test(indexName, documentType, tagEntity.getId().toString(), jsonString);
};
boolean isValid = true;
for (TagEntity tagEntity : tagEntityList) {
if (!validInIndexPredicate.test(tagEntity)) {
isValid = false;
}
}
return isValid;
}
use of org.finra.herd.model.api.xml.Tag in project herd by FINRAOS.
the class TagServiceImpl method searchTags.
@Override
public TagSearchResponse searchTags(TagSearchRequest request, Set<String> fields) {
// Validate and trim the request parameters.
validateTagSearchRequest(request);
// Validate and trim the search response fields.
validateSearchResponseFields(fields);
// Prepare the result list.
List<TagEntity> tagEntities = new ArrayList<>();
// If search key is specified, use it to retrieve the tags.
if (CollectionUtils.isNotEmpty(request.getTagSearchFilters()) && request.getTagSearchFilters().get(0) != null) {
// Get the tag search key.
TagSearchKey tagSearchKey = request.getTagSearchFilters().get(0).getTagSearchKeys().get(0);
// Retrieve and ensure that a tag type exists for the specified tag type code.
TagTypeEntity tagTypeEntity = tagTypeDaoHelper.getTagTypeEntity(new TagTypeKey(tagSearchKey.getTagTypeCode()));
// Retrieve the tags.
tagEntities.addAll(tagDao.getTagsByTagTypeEntityAndParentTagCode(tagTypeEntity, tagSearchKey.getParentTagCode(), tagSearchKey.isIsParentTagNull()));
} else // The search key is not specified, so select all tags registered in the system.
{
// Retrieve the tags.
tagEntities.addAll(tagDao.getTags());
}
// Build the list of tags.
List<Tag> tags = new ArrayList<>();
for (TagEntity tagEntity : tagEntities) {
tags.add(createTagFromEntity(tagEntity, false, fields.contains(DISPLAY_NAME_FIELD), fields.contains(SEARCH_SCORE_MULTIPLIER_FIELD), fields.contains(DESCRIPTION_FIELD), false, false, false, fields.contains(PARENT_TAG_KEY_FIELD), fields.contains(HAS_CHILDREN_FIELD)));
}
// Build and return the tag search response.
return new TagSearchResponse(tags);
}
use of org.finra.herd.model.api.xml.Tag in project herd by FINRAOS.
the class TagRestControllerTest method getNewTag.
private Tag getNewTag(TagKey tagKey) {
Calendar cal = Calendar.getInstance();
Date createdTime = cal.getTime();
String createdBy = "some test";
String updatedBy = "some test 2";
Tag tag = new Tag(ID, tagKey, TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, createdBy, updatedBy, HerdDateUtils.getXMLGregorianCalendarValue(createdTime), NO_PARENT_TAG_KEY, NO_TAG_HAS_CHILDREN_FLAG);
return tag;
}
Aggregations