use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionTagServiceImpl method createBusinessObjectDefinitionTag.
@NamespacePermission(fields = "#request.businessObjectDefinitionTagKey.businessObjectDefinitionKey.namespace", permissions = { NamespacePermissionEnum.WRITE_DESCRIPTIVE_CONTENT, NamespacePermissionEnum.WRITE })
@Override
public BusinessObjectDefinitionTag createBusinessObjectDefinitionTag(BusinessObjectDefinitionTagCreateRequest request) {
// Validate and trim the business object definition tag create request.
validateBusinessObjectDefinitionTagCreateRequest(request);
// Get the business object definition entity and ensure it exists.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(request.getBusinessObjectDefinitionTagKey().getBusinessObjectDefinitionKey());
// Get the tag entity and ensure it exists.
TagEntity tagEntity = tagDaoHelper.getTagEntity(request.getBusinessObjectDefinitionTagKey().getTagKey());
// Ensure a business object definition tag for the specified business object definition and tag doesn't already exist.
if (businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagByParentEntities(businessObjectDefinitionEntity, tagEntity) != null) {
throw new AlreadyExistsException(String.format("Tag with tag type \"%s\" and code \"%s\" already exists for business object definition {%s}.", request.getBusinessObjectDefinitionTagKey().getTagKey().getTagTypeCode(), request.getBusinessObjectDefinitionTagKey().getTagKey().getTagCode(), businessObjectDefinitionHelper.businessObjectDefinitionKeyToString(request.getBusinessObjectDefinitionTagKey().getBusinessObjectDefinitionKey())));
}
// Create and persist a business object definition tag entity.
BusinessObjectDefinitionTagEntity businessObjectDefinitionTagEntity = createBusinessObjectDefinitionTagEntity(businessObjectDefinitionEntity, tagEntity);
// Notify the search index that a business object definition must be updated.
searchIndexUpdateHelper.modifyBusinessObjectDefinitionInSearchIndex(businessObjectDefinitionEntity, SEARCH_INDEX_UPDATE_TYPE_UPDATE);
// Create and return the business object definition tag object from the persisted entity.
return createBusinessObjectDefinitionTagFromEntity(businessObjectDefinitionTagEntity);
}
use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionTagServiceImpl method getBusinessObjectDefinitionTagsByTag.
@Override
public BusinessObjectDefinitionTagKeys getBusinessObjectDefinitionTagsByTag(TagKey tagKey) {
// Validate the tag key.
tagHelper.validateTagKey(tagKey);
// Get the tag entity and ensure it exists.
TagEntity tagEntity = tagDaoHelper.getTagEntity(tagKey);
// Create a list of tag entities along with all its children tags down the hierarchy up to maximum allowed tag nesting level.
List<TagEntity> tagEntities = new ArrayList<>();
tagEntities.add(tagEntity);
tagEntities.addAll(tagDaoHelper.getTagChildrenEntities(tagEntity));
// Retrieve and return a list of business object definition tag keys.
return new BusinessObjectDefinitionTagKeys(businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagsByTagEntities(tagEntities));
}
use of org.finra.herd.model.jpa.TagEntity 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.jpa.TagEntity in project herd by FINRAOS.
the class TagTypeServiceImpl method updateTagType.
@Override
public TagType updateTagType(TagTypeKey tagTypeKey, TagTypeUpdateRequest request) {
// Perform validation and trim.
tagTypeHelper.validateTagTypeKey(tagTypeKey);
// Perform validation and trim the alternate key parameters.
validateTagTypeUpdateRequest(request);
// Retrieve and ensure that a tag type already exists with the specified key.
TagTypeEntity tagTypeEntity = tagTypeDaoHelper.getTagTypeEntity(tagTypeKey);
// Validate the display name does not already exist for another tag type.
if (!StringUtils.equalsIgnoreCase(tagTypeEntity.getDisplayName(), request.getDisplayName())) {
// Validate that the description is different.
tagTypeDaoHelper.assertTagTypeDisplayNameDoesNotExist(request.getDisplayName());
}
// Update and persist the tag type entity.
updateTagTypeEntity(tagTypeEntity, request);
// Notify the search index that a business object definition must be updated.
List<TagEntity> tagEntities = tagDao.getTagsByTagTypeEntityAndParentTagCode(tagTypeEntity, null, null);
searchIndexUpdateHelper.modifyBusinessObjectDefinitionsInSearchIndex(businessObjectDefinitionDao.getBusinessObjectDefinitions(tagEntities), SEARCH_INDEX_UPDATE_TYPE_UPDATE);
// Notify the tag search index that tags must be updated.
searchIndexUpdateHelper.modifyTagsInSearchIndex(tagEntities, SEARCH_INDEX_UPDATE_TYPE_UPDATE);
// Create and return the tag type from the persisted entity.
return createTagTypeFromEntity(tagTypeEntity);
}
use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.
the class TagServiceImpl method updateTag.
@Override
public Tag updateTag(TagKey tagKey, TagUpdateRequest tagUpdateRequest) {
// Perform validation and trim
tagHelper.validateTagKey(tagKey);
// Perform validation and trim.
validateTagUpdateRequest(tagKey, tagUpdateRequest);
// Retrieve and ensure that a tag already exists with the specified key.
TagEntity tagEntity = tagDaoHelper.getTagEntity(tagKey);
// Validate the display name does not already exist for another tag for this tag type in the database.
if (!StringUtils.equalsIgnoreCase(tagEntity.getDisplayName(), tagUpdateRequest.getDisplayName())) {
// Validate that the description is different.
tagDaoHelper.assertDisplayNameDoesNotExistForTag(tagKey.getTagTypeCode(), tagUpdateRequest.getDisplayName());
}
// List of tag entities to update in the search index
List<TagEntity> tagEntities = new ArrayList<>();
tagEntities.add(tagEntity);
// If there is an original tag entity parent, then update
if (tagEntity.getParentTagEntity() != null) {
tagEntities.add(tagEntity.getParentTagEntity());
}
// Validate the parent tag if one specified.
TagEntity parentTagEntity = null;
if (tagUpdateRequest.getParentTagKey() != null) {
// Get parent tag entity and ensure it exists.
parentTagEntity = tagDaoHelper.getTagEntity(tagUpdateRequest.getParentTagKey());
// Validate the parent tag entity.
tagDaoHelper.validateParentTagEntity(tagEntity, parentTagEntity);
// Add the parent tag entity to the tag entities list
tagEntities.add(parentTagEntity);
}
// Update and persist the tag entity.
updateTagEntity(tagEntity, tagUpdateRequest, parentTagEntity);
// Notify the search index that a business object definition must be updated.
searchIndexUpdateHelper.modifyBusinessObjectDefinitionsInSearchIndex(businessObjectDefinitionDao.getBusinessObjectDefinitions(tagEntities), SEARCH_INDEX_UPDATE_TYPE_UPDATE);
// Notify the tag search index that tags must be updated.
searchIndexUpdateHelper.modifyTagsInSearchIndex(tagEntities, SEARCH_INDEX_UPDATE_TYPE_UPDATE);
// Create and return the tag object from the tag entity.
return createTagFromEntity(tagEntity);
}
Aggregations