Search in sources :

Example 6 with TagEntity

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);
}
Also used : AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) TagEntity(org.finra.herd.model.jpa.TagEntity) BusinessObjectDefinitionTagEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity) BusinessObjectDefinitionTagEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 7 with TagEntity

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));
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity) BusinessObjectDefinitionTagEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity) BusinessObjectDefinitionTagKeys(org.finra.herd.model.api.xml.BusinessObjectDefinitionTagKeys) ArrayList(java.util.ArrayList)

Example 8 with TagEntity

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());
                    }
                });
            }
        }
    }
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity) TagKey(org.finra.herd.model.api.xml.TagKey) IndexSearchFilter(org.finra.herd.model.api.xml.IndexSearchFilter)

Example 9 with TagEntity

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);
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity)

Example 10 with TagEntity

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);
}
Also used : TagEntity(org.finra.herd.model.jpa.TagEntity) ArrayList(java.util.ArrayList)

Aggregations

TagEntity (org.finra.herd.model.jpa.TagEntity)111 Test (org.junit.Test)77 TagKey (org.finra.herd.model.api.xml.TagKey)55 ArrayList (java.util.ArrayList)44 TagTypeEntity (org.finra.herd.model.jpa.TagTypeEntity)33 Tag (org.finra.herd.model.api.xml.Tag)28 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)15 SearchIndexUpdateDto (org.finra.herd.model.dto.SearchIndexUpdateDto)14 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)13 TagUpdateRequest (org.finra.herd.model.api.xml.TagUpdateRequest)12 ElasticsearchResponseDto (org.finra.herd.model.dto.ElasticsearchResponseDto)11 BusinessObjectDefinitionTagEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity)11 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)10 Predicate (javax.persistence.criteria.Predicate)9 BusinessObjectDefinitionSearchKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchKey)9 TagCreateRequest (org.finra.herd.model.api.xml.TagCreateRequest)9 BusinessObjectDefinitionIndexSearchResponse (org.finra.herd.model.api.xml.BusinessObjectDefinitionIndexSearchResponse)8 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)8 BusinessObjectDefinitionSearchFilter (org.finra.herd.model.api.xml.BusinessObjectDefinitionSearchFilter)8 BusinessObjectDefinitionIndexSearchResponseDto (org.finra.herd.model.dto.BusinessObjectDefinitionIndexSearchResponseDto)8