Search in sources :

Example 11 with TagEntity

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

Example 12 with TagEntity

use of org.finra.herd.model.jpa.TagEntity 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;
}
Also used : SEARCH_INDEX_UPDATE_TYPE_CREATE(org.finra.herd.model.dto.SearchIndexUpdateDto.SEARCH_INDEX_UPDATE_TYPE_CREATE) LoggerFactory(org.slf4j.LoggerFactory) TagTypeDaoHelper(org.finra.herd.service.helper.TagTypeDaoHelper) Autowired(org.springframework.beans.factory.annotation.Autowired) TagCreateRequest(org.finra.herd.model.api.xml.TagCreateRequest) StringUtils(org.apache.commons.lang3.StringUtils) SearchIndexUpdateDto(org.finra.herd.model.dto.SearchIndexUpdateDto) Tag(org.finra.herd.model.api.xml.Tag) BigDecimal(java.math.BigDecimal) Future(java.util.concurrent.Future) TagSearchKey(org.finra.herd.model.api.xml.TagSearchKey) Map(java.util.Map) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) AsyncResult(org.springframework.scheduling.annotation.AsyncResult) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) ConfigurationValue(org.finra.herd.model.dto.ConfigurationValue) ImmutableSet(com.google.common.collect.ImmutableSet) Predicate(java.util.function.Predicate) TagUpdateRequest(org.finra.herd.model.api.xml.TagUpdateRequest) Set(java.util.Set) List(java.util.List) ConfigurationHelper(org.finra.herd.core.helper.ConfigurationHelper) TagListResponse(org.finra.herd.model.api.xml.TagListResponse) TagTypeKey(org.finra.herd.model.api.xml.TagTypeKey) IndexFunctionsDao(org.finra.herd.dao.IndexFunctionsDao) Async(org.springframework.scheduling.annotation.Async) TagSearchFilter(org.finra.herd.model.api.xml.TagSearchFilter) TagHelper(org.finra.herd.service.helper.TagHelper) TagSearchRequest(org.finra.herd.model.api.xml.TagSearchRequest) HashMap(java.util.HashMap) BooleanUtils(org.apache.commons.lang3.BooleanUtils) DaoSpringModuleConfig(org.finra.herd.dao.config.DaoSpringModuleConfig) CollectionUtils(org.apache.commons.collections4.CollectionUtils) SearchIndexUpdateHelper(org.finra.herd.service.helper.SearchIndexUpdateHelper) ArrayList(java.util.ArrayList) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) TagSearchResponse(org.finra.herd.model.api.xml.TagSearchResponse) SEARCH_INDEX_UPDATE_TYPE_UPDATE(org.finra.herd.model.dto.SearchIndexUpdateDto.SEARCH_INDEX_UPDATE_TYPE_UPDATE) Service(org.springframework.stereotype.Service) TagChild(org.finra.herd.model.api.xml.TagChild) TagKey(org.finra.herd.model.api.xml.TagKey) TagDao(org.finra.herd.dao.TagDao) Logger(org.slf4j.Logger) AlternateKeyHelper(org.finra.herd.service.helper.AlternateKeyHelper) SearchableService(org.finra.herd.service.SearchableService) HerdDateUtils(org.finra.herd.core.HerdDateUtils) TagEntity(org.finra.herd.model.jpa.TagEntity) BusinessObjectDefinitionDao(org.finra.herd.dao.BusinessObjectDefinitionDao) TagService(org.finra.herd.service.TagService) SEARCH_INDEX_UPDATE_TYPE_DELETE(org.finra.herd.model.dto.SearchIndexUpdateDto.SEARCH_INDEX_UPDATE_TYPE_DELETE) TagDaoHelper(org.finra.herd.service.helper.TagDaoHelper) Collections(java.util.Collections) SearchIndexTypeEntity(org.finra.herd.model.jpa.SearchIndexTypeEntity) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) TagEntity(org.finra.herd.model.jpa.TagEntity)

Example 13 with TagEntity

use of org.finra.herd.model.jpa.TagEntity 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);
}
Also used : TagSearchKey(org.finra.herd.model.api.xml.TagSearchKey) TagSearchResponse(org.finra.herd.model.api.xml.TagSearchResponse) TagTypeKey(org.finra.herd.model.api.xml.TagTypeKey) TagEntity(org.finra.herd.model.jpa.TagEntity) ArrayList(java.util.ArrayList) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) Tag(org.finra.herd.model.api.xml.Tag)

Example 14 with TagEntity

use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.

the class BusinessObjectDefinitionTagDaoImpl method getBusinessObjectDefinitionTagsByBusinessObjectDefinitionEntity.

@Override
public List<BusinessObjectDefinitionTagKey> getBusinessObjectDefinitionTagsByBusinessObjectDefinitionEntity(BusinessObjectDefinitionEntity businessObjectDefinitionEntity) {
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> criteria = builder.createTupleQuery();
    // The criteria root is the business object definition.
    Root<TagEntity> tagEntityRoot = criteria.from(TagEntity.class);
    // Join to the other tables we can filter on.
    Join<TagEntity, TagTypeEntity> tagTypeEntityJoin = tagEntityRoot.join(TagEntity_.tagType);
    Join<TagEntity, BusinessObjectDefinitionTagEntity> businessObjectDefinitionTagEntityJoin = tagEntityRoot.join(TagEntity_.businessObjectDefinitionTags);
    Join<BusinessObjectDefinitionTagEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntityJoin = businessObjectDefinitionTagEntityJoin.join(BusinessObjectDefinitionTagEntity_.businessObjectDefinition);
    // Get the columns.
    Path<String> tagTypeCodeColumn = tagTypeEntityJoin.get(TagTypeEntity_.code);
    Path<String> tagCodeColumn = tagEntityRoot.get(TagEntity_.tagCode);
    Path<String> tagDisplayNameColumn = tagEntityRoot.get(TagEntity_.displayName);
    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(businessObjectDefinitionEntityJoin, businessObjectDefinitionEntity));
    // Add the clauses for the query.
    criteria.multiselect(tagTypeCodeColumn, tagCodeColumn).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(builder.asc(tagDisplayNameColumn));
    // Run the query to get a list of tuples back.
    List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();
    // Get the business object definition key.
    BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(businessObjectDefinitionEntity.getNamespace().getCode(), businessObjectDefinitionEntity.getName());
    // Populate the "keys" objects from the returned tuples (i.e. 1 tuple for each row).
    List<BusinessObjectDefinitionTagKey> businessObjectDefinitionTagKeys = new ArrayList<>();
    for (Tuple tuple : tuples) {
        businessObjectDefinitionTagKeys.add(new BusinessObjectDefinitionTagKey(businessObjectDefinitionKey, new TagKey(tuple.get(tagTypeCodeColumn), tuple.get(tagCodeColumn))));
    }
    return businessObjectDefinitionTagKeys;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) ArrayList(java.util.ArrayList) BusinessObjectDefinitionTagKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionTagKey) BusinessObjectDefinitionTagEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity) Predicate(javax.persistence.criteria.Predicate) TagEntity(org.finra.herd.model.jpa.TagEntity) BusinessObjectDefinitionTagEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) BusinessObjectDefinitionTagKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionTagKey) TagKey(org.finra.herd.model.api.xml.TagKey) Tuple(javax.persistence.Tuple)

Example 15 with TagEntity

use of org.finra.herd.model.jpa.TagEntity in project herd by FINRAOS.

the class BusinessObjectDefinitionTagDaoImpl method getBusinessObjectDefinitionTagByKey.

@Override
public BusinessObjectDefinitionTagEntity getBusinessObjectDefinitionTagByKey(BusinessObjectDefinitionTagKey businessObjectDefinitionTagKey) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<BusinessObjectDefinitionTagEntity> criteria = builder.createQuery(BusinessObjectDefinitionTagEntity.class);
    // The criteria root is the business object definition tag.
    Root<BusinessObjectDefinitionTagEntity> businessObjectDefinitionTagEntityRoot = criteria.from(BusinessObjectDefinitionTagEntity.class);
    // Join to the other tables we can filter on.
    Join<BusinessObjectDefinitionTagEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntityJoin = businessObjectDefinitionTagEntityRoot.join(BusinessObjectDefinitionTagEntity_.businessObjectDefinition);
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntityJoin = businessObjectDefinitionEntityJoin.join(BusinessObjectDefinitionEntity_.namespace);
    Join<BusinessObjectDefinitionTagEntity, TagEntity> tagEntityJoin = businessObjectDefinitionTagEntityRoot.join(BusinessObjectDefinitionTagEntity_.tag);
    Join<TagEntity, TagTypeEntity> tagTypeEntityJoin = tagEntityJoin.join(TagEntity_.tagType);
    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(builder.upper(namespaceEntityJoin.get(NamespaceEntity_.code)), businessObjectDefinitionTagKey.getBusinessObjectDefinitionKey().getNamespace().toUpperCase()));
    predicates.add(builder.equal(builder.upper(businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.name)), businessObjectDefinitionTagKey.getBusinessObjectDefinitionKey().getBusinessObjectDefinitionName().toUpperCase()));
    predicates.add(builder.equal(builder.upper(tagTypeEntityJoin.get(TagTypeEntity_.code)), businessObjectDefinitionTagKey.getTagKey().getTagTypeCode().toUpperCase()));
    predicates.add(builder.equal(builder.upper(tagEntityJoin.get(TagEntity_.tagCode)), businessObjectDefinitionTagKey.getTagKey().getTagCode().toUpperCase()));
    // Add the clauses for the query.
    criteria.select(businessObjectDefinitionTagEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()])));
    return executeSingleResultQuery(criteria, String.format("Found more than one business object definition tag instance with parameters {namespace=\"%s\", businessObjectDefinitionName=\"%s\"," + " tagType=\"%s\", tagCode=\"%s\"}.", businessObjectDefinitionTagKey.getBusinessObjectDefinitionKey().getNamespace(), businessObjectDefinitionTagKey.getBusinessObjectDefinitionKey().getBusinessObjectDefinitionName(), businessObjectDefinitionTagKey.getTagKey().getTagTypeCode(), businessObjectDefinitionTagKey.getTagKey().getTagCode()));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) ArrayList(java.util.ArrayList) BusinessObjectDefinitionTagEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity) Predicate(javax.persistence.criteria.Predicate) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) TagEntity(org.finra.herd.model.jpa.TagEntity) BusinessObjectDefinitionTagEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity)

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