Search in sources :

Example 1 with AttributeValueFilter

use of org.finra.herd.model.api.xml.AttributeValueFilter in project herd by FINRAOS.

the class BusinessObjectDataSearchHelper method validateBusinessObjectDataSearchKey.

/**
 * Validates a business object data search key.
 *
 * @param businessObjectDataSearchKey the business object data search key
 */
void validateBusinessObjectDataSearchKey(BusinessObjectDataSearchKey businessObjectDataSearchKey) {
    Assert.notNull(businessObjectDataSearchKey, "A business object data search key must be specified.");
    businessObjectDataSearchKey.setNamespace(alternateKeyHelper.validateStringParameter("namespace", businessObjectDataSearchKey.getNamespace()));
    businessObjectDataSearchKey.setBusinessObjectDefinitionName(alternateKeyHelper.validateStringParameter("business object definition name", businessObjectDataSearchKey.getBusinessObjectDefinitionName()));
    if (businessObjectDataSearchKey.getBusinessObjectFormatUsage() != null) {
        businessObjectDataSearchKey.setBusinessObjectFormatUsage(alternateKeyHelper.validateStringParameter("business object format usage", businessObjectDataSearchKey.getBusinessObjectFormatUsage()));
    }
    if (businessObjectDataSearchKey.getBusinessObjectFormatFileType() != null) {
        businessObjectDataSearchKey.setBusinessObjectFormatFileType(alternateKeyHelper.validateStringParameter("business object format file type", businessObjectDataSearchKey.getBusinessObjectFormatFileType()));
    }
    // Validate partition value filters, if specified.
    if (CollectionUtils.isNotEmpty(businessObjectDataSearchKey.getPartitionValueFilters())) {
        businessObjectDataHelper.validatePartitionValueFilters(businessObjectDataSearchKey.getPartitionValueFilters(), null, false);
        // TODO: For now, we only support partition values or partition range in the filter.
        for (PartitionValueFilter partitionValueFilter : businessObjectDataSearchKey.getPartitionValueFilters()) {
            List<String> partitionValues = partitionValueFilter.getPartitionValues();
            PartitionValueRange partitionValueRange = partitionValueFilter.getPartitionValueRange();
            // as it is done above at businessObjectDataHelper.validatePartitionValueFilters().
            if (CollectionUtils.isEmpty(partitionValues) && partitionValueRange == null) {
                throw new IllegalArgumentException("Only partition values or partition range are supported in partition value filter.");
            }
        }
    }
    // Validate attribute value filters, if specified.
    if (CollectionUtils.isNotEmpty(businessObjectDataSearchKey.getAttributeValueFilters())) {
        for (AttributeValueFilter attributeValueFilter : businessObjectDataSearchKey.getAttributeValueFilters()) {
            if (attributeValueFilter.getAttributeName() != null) {
                attributeValueFilter.setAttributeName(attributeValueFilter.getAttributeName().trim());
            }
            if (StringUtils.isBlank(attributeValueFilter.getAttributeName()) && StringUtils.isEmpty(attributeValueFilter.getAttributeValue())) {
                throw new IllegalArgumentException("Either attribute name or attribute value filter must be specified.");
            }
        }
    }
}
Also used : PartitionValueRange(org.finra.herd.model.api.xml.PartitionValueRange) PartitionValueFilter(org.finra.herd.model.api.xml.PartitionValueFilter) AttributeValueFilter(org.finra.herd.model.api.xml.AttributeValueFilter)

Example 2 with AttributeValueFilter

use of org.finra.herd.model.api.xml.AttributeValueFilter in project herd by FINRAOS.

the class BusinessObjectDataDaoImpl method getPredict.

/**
 * Create search restrictions
 *
 * @param builder criteria builder
 * @param criteria criteria
 * @param businessObjectDataEntity root business object data entity
 * @param businessDataSearchKey business object data search key
 * @param isCountQuery is the query a count query
 *
 * @return search restrictions
 */
private Predicate getPredict(CriteriaBuilder builder, CriteriaQuery<?> criteria, Root<BusinessObjectDataEntity> businessObjectDataEntity, BusinessObjectDataSearchKey businessDataSearchKey, boolean isCountQuery) {
    // Join to the other tables we can filter on.
    Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> businessObjectFormatEntity = businessObjectDataEntity.join(BusinessObjectDataEntity_.businessObjectFormat);
    Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.businessObjectDefinition);
    if (!isCountQuery) {
        List<Order> orderList = new ArrayList<>();
        orderList.add(builder.asc(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.namespace)));
        orderList.add(builder.asc(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)));
        orderList.add(builder.asc(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage)));
        orderList.add(builder.asc(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.fileType)));
        orderList.add(builder.desc(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion)));
        orderList.add(builder.desc(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue)));
        orderList.add(builder.desc(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue2)));
        orderList.add(builder.desc(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue3)));
        orderList.add(builder.desc(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue4)));
        orderList.add(builder.desc(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue5)));
        orderList.add(builder.desc(businessObjectDataEntity.get(BusinessObjectDataEntity_.version)));
        criteria.orderBy(orderList);
    }
    // Create the standard restrictions based on the business object search key values (i.e. the standard where clauses).
    // Create a restriction on namespace code.
    Predicate predicate = builder.equal(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.namespace).get(NamespaceEntity_.code)), businessDataSearchKey.getNamespace().toUpperCase());
    // Create and append a restriction on business object definition name.
    predicate = builder.and(predicate, builder.equal(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)), businessDataSearchKey.getBusinessObjectDefinitionName().toUpperCase()));
    // Create and append a restriction on business object format usage.
    if (!StringUtils.isEmpty(businessDataSearchKey.getBusinessObjectFormatUsage())) {
        predicate = builder.and(predicate, builder.equal(builder.upper(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage)), businessDataSearchKey.getBusinessObjectFormatUsage().toUpperCase()));
    }
    if (!StringUtils.isEmpty(businessDataSearchKey.getBusinessObjectFormatFileType())) {
        // Create and append a restriction on business object format file type.
        predicate = builder.and(predicate, builder.equal(builder.upper(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.fileType).get(FileTypeEntity_.code)), businessDataSearchKey.getBusinessObjectFormatFileType().toUpperCase()));
    }
    // If specified, create and append a restriction on business object format version.
    if (businessDataSearchKey.getBusinessObjectFormatVersion() != null) {
        predicate = builder.and(predicate, builder.equal(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion), businessDataSearchKey.getBusinessObjectFormatVersion()));
    }
    predicate = createPartitionValueFilters(businessDataSearchKey, businessObjectDataEntity, businessObjectFormatEntity, builder, predicate);
    List<AttributeValueFilter> attributeValueFilters = businessDataSearchKey.getAttributeValueFilters();
    if (attributeValueFilters != null && !attributeValueFilters.isEmpty()) {
        predicate = createAttributeValueFilters(businessDataSearchKey, businessObjectDataEntity, builder, predicate);
    }
    if (BooleanUtils.isTrue(businessDataSearchKey.isFilterOnLatestValidVersion())) {
        String validStatus = BusinessObjectDataStatusEntity.VALID;
        Subquery<Integer> subQuery = getMaximumBusinessObjectDataVersionSubQuery(builder, criteria, businessObjectDataEntity, businessObjectFormatEntity, validStatus);
        predicate = builder.and(predicate, builder.in(businessObjectDataEntity.get(BusinessObjectDataEntity_.version)).value(subQuery));
    }
    if (BooleanUtils.isTrue(businessDataSearchKey.isFilterOnRetentionExpiration())) {
        predicate = createRetentionExpirationFilter(businessDataSearchKey, businessObjectDataEntity, businessObjectFormatEntity, builder, predicate);
    }
    return predicate;
}
Also used : Order(javax.persistence.criteria.Order) ArrayList(java.util.ArrayList) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) AttributeValueFilter(org.finra.herd.model.api.xml.AttributeValueFilter) Predicate(javax.persistence.criteria.Predicate) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity)

Example 3 with AttributeValueFilter

use of org.finra.herd.model.api.xml.AttributeValueFilter in project herd by FINRAOS.

the class BusinessObjectDataDaoImpl method shouldIncludeAttributeInResponse.

/**
 * Checks if the attribute should be returned based on the attribute value query list if attribute name supplied, match attribute name case in sensitive if
 * attribute value supplied, match attribute value case sensitive with contain logic if both attribute name and value supplied, match both.
 *
 * @param attributeEntity the database attribute entity
 * @param attributeQueryList the attribute query list
 *
 * @return true for returning in response; false for not
 */
private boolean shouldIncludeAttributeInResponse(BusinessObjectDataAttributeEntity attributeEntity, List<AttributeValueFilter> attributeQueryList) {
    String attributeName = attributeEntity.getName();
    String attributeValue = attributeEntity.getValue();
    for (AttributeValueFilter valueFiler : attributeQueryList) {
        String queryAttributeName = valueFiler.getAttributeName();
        String queryAttributeValue = valueFiler.getAttributeValue();
        Boolean matchAttributeName = false;
        Boolean matchAttributeValue = false;
        if (attributeName != null && attributeName.equalsIgnoreCase(queryAttributeName)) {
            matchAttributeName = true;
        }
        if (attributeValue != null && queryAttributeValue != null && attributeValue.contains(queryAttributeValue)) {
            matchAttributeValue = true;
        }
        if (!StringUtils.isEmpty(queryAttributeName) && !StringUtils.isEmpty(queryAttributeValue)) {
            if (matchAttributeName && matchAttributeValue) {
                return true;
            }
        } else if (!StringUtils.isEmpty(queryAttributeName) && matchAttributeName) {
            return true;
        } else if (!StringUtils.isEmpty(queryAttributeValue) && matchAttributeValue) {
            return true;
        }
    }
    return false;
}
Also used : AttributeValueFilter(org.finra.herd.model.api.xml.AttributeValueFilter)

Example 4 with AttributeValueFilter

use of org.finra.herd.model.api.xml.AttributeValueFilter in project herd by FINRAOS.

the class BusinessObjectDataDaoImpl method createAttributeValueFilters.

/**
 * Creates a predicate for attribute value filters.
 *
 * @param businessDataSearchKey business object search key
 * @param businessObjectDataEntity business object data entity
 * @param builder query build
 * @param predicatePram predicate
 *
 * @return the predicate with added attribute value filters
 */
private Predicate createAttributeValueFilters(BusinessObjectDataSearchKey businessDataSearchKey, Root<BusinessObjectDataEntity> businessObjectDataEntity, CriteriaBuilder builder, Predicate predicatePram) {
    Predicate predicate = predicatePram;
    if (businessDataSearchKey.getAttributeValueFilters() != null && !businessDataSearchKey.getAttributeValueFilters().isEmpty()) {
        for (AttributeValueFilter attributeValueFilter : businessDataSearchKey.getAttributeValueFilters()) {
            Join<BusinessObjectDataEntity, BusinessObjectDataAttributeEntity> dataAttributeEntity = businessObjectDataEntity.join(BusinessObjectDataEntity_.attributes);
            String attributeName = attributeValueFilter.getAttributeName();
            String attributeValue = attributeValueFilter.getAttributeValue();
            if (!StringUtils.isEmpty(attributeName)) {
                predicate = builder.and(predicate, builder.equal(builder.upper(dataAttributeEntity.get(BusinessObjectDataAttributeEntity_.name)), attributeName.toUpperCase()));
            }
            if (!StringUtils.isEmpty(attributeValue)) {
                predicate = builder.and(predicate, builder.like(dataAttributeEntity.get(BusinessObjectDataAttributeEntity_.value), "%" + attributeValue + "%"));
            }
        }
    }
    return predicate;
}
Also used : BusinessObjectDataAttributeEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) AttributeValueFilter(org.finra.herd.model.api.xml.AttributeValueFilter) Predicate(javax.persistence.criteria.Predicate)

Example 5 with AttributeValueFilter

use of org.finra.herd.model.api.xml.AttributeValueFilter in project herd by FINRAOS.

the class BusinessObjectDataSearchServiceTest method testSearchBusinessObjectDataWithAttributeFilterValuesWithMultipleFilters.

@Test
public void testSearchBusinessObjectDataWithAttributeFilterValuesWithMultipleFilters() {
    businessObjectDataServiceTestHelper.createDatabaseEntitiesForBusinessObjectDataSearchTesting();
    businessObjectDataAttributeDaoTestHelper.createBusinessObjectDataAttributeEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, null, DATA_VERSION, ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_1);
    businessObjectDataAttributeDaoTestHelper.createBusinessObjectDataAttributeEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, null, DATA_VERSION, ATTRIBUTE_NAME_2_MIXED_CASE, ATTRIBUTE_VALUE_2);
    businessObjectDataAttributeDaoTestHelper.createBusinessObjectDataAttributeEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, null, DATA_VERSION, ATTRIBUTE_NAME_3_MIXED_CASE, ATTRIBUTE_VALUE_3);
    businessObjectDataAttributeDaoTestHelper.createBusinessObjectDataAttributeEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, null, DATA_VERSION, ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_1);
    BusinessObjectDataSearchRequest request = new BusinessObjectDataSearchRequest();
    List<BusinessObjectDataSearchFilter> filters = new ArrayList<>();
    List<BusinessObjectDataSearchKey> businessObjectDataSearchKeys = new ArrayList<>();
    BusinessObjectDataSearchKey key = new BusinessObjectDataSearchKey();
    key.setNamespace(NAMESPACE);
    key.setBusinessObjectDefinitionName(BDEF_NAME);
    List<AttributeValueFilter> attributeValueFilters = new ArrayList<>();
    attributeValueFilters.add(new AttributeValueFilter(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_1));
    attributeValueFilters.add(new AttributeValueFilter(ATTRIBUTE_NAME_2_MIXED_CASE, null));
    key.setAttributeValueFilters(attributeValueFilters);
    businessObjectDataSearchKeys.add(key);
    BusinessObjectDataSearchFilter filter = new BusinessObjectDataSearchFilter(businessObjectDataSearchKeys);
    filters.add(filter);
    request.setBusinessObjectDataSearchFilters(filters);
    BusinessObjectDataSearchResultPagingInfoDto result = businessObjectDataService.searchBusinessObjectData(DEFAULT_PAGE_NUMBER, PAGE_SIZE, request);
    List<BusinessObjectData> resultList = result.getBusinessObjectDataSearchResult().getBusinessObjectDataElements();
    assertEquals(1, resultList.size());
    for (BusinessObjectData data : resultList) {
        assertEquals(NAMESPACE, data.getNamespace());
        assertEquals(BDEF_NAME, data.getBusinessObjectDefinitionName());
        assertEquals(2, data.getAttributes().size());
        boolean foundCase1 = false, foundCase2 = false;
        for (int i = 0; i < data.getAttributes().size(); i++) {
            if (ATTRIBUTE_NAME_1_MIXED_CASE.equals(data.getAttributes().get(i).getName())) {
                assertEquals(ATTRIBUTE_VALUE_1, data.getAttributes().get(i).getValue());
                foundCase1 = true;
            }
            if (ATTRIBUTE_NAME_2_MIXED_CASE.equals(data.getAttributes().get(i).getName())) {
                assertEquals(ATTRIBUTE_VALUE_2, data.getAttributes().get(i).getValue());
                foundCase2 = true;
            }
        }
        assertTrue(foundCase1 && foundCase2);
    }
    // Validate the paging information.
    assertEquals(Long.valueOf(DEFAULT_PAGE_NUMBER), result.getPageNum());
    assertEquals(Long.valueOf(PAGE_SIZE), result.getPageSize());
    assertEquals(Long.valueOf(1), result.getPageCount());
    assertEquals(Long.valueOf(1), result.getTotalRecordsOnPage());
    assertEquals(Long.valueOf(1), result.getTotalRecordCount());
    assertEquals(Long.valueOf(DEFAULT_PAGE_SIZE), result.getMaxResultsPerPage());
}
Also used : BusinessObjectDataSearchResultPagingInfoDto(org.finra.herd.model.dto.BusinessObjectDataSearchResultPagingInfoDto) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) ArrayList(java.util.ArrayList) BusinessObjectDataSearchRequest(org.finra.herd.model.api.xml.BusinessObjectDataSearchRequest) AttributeValueFilter(org.finra.herd.model.api.xml.AttributeValueFilter) BusinessObjectDataSearchFilter(org.finra.herd.model.api.xml.BusinessObjectDataSearchFilter) BusinessObjectDataSearchKey(org.finra.herd.model.api.xml.BusinessObjectDataSearchKey) Test(org.junit.Test)

Aggregations

AttributeValueFilter (org.finra.herd.model.api.xml.AttributeValueFilter)15 BusinessObjectDataSearchKey (org.finra.herd.model.api.xml.BusinessObjectDataSearchKey)11 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)8 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)7 BusinessObjectDataAttributeEntity (org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity)6 BusinessObjectDataSearchFilter (org.finra.herd.model.api.xml.BusinessObjectDataSearchFilter)4 BusinessObjectDataSearchRequest (org.finra.herd.model.api.xml.BusinessObjectDataSearchRequest)4 BusinessObjectDataSearchResultPagingInfoDto (org.finra.herd.model.dto.BusinessObjectDataSearchResultPagingInfoDto)3 Predicate (javax.persistence.criteria.Predicate)2 PartitionValueFilter (org.finra.herd.model.api.xml.PartitionValueFilter)2 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)2 HashSet (java.util.HashSet)1 Order (javax.persistence.criteria.Order)1 LatestBeforePartitionValue (org.finra.herd.model.api.xml.LatestBeforePartitionValue)1 PartitionValueRange (org.finra.herd.model.api.xml.PartitionValueRange)1 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)1 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)1