Search in sources :

Example 1 with BusinessObjectDataSearchKey

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

the class BusinessObjectDataSearchHelper method validateBusinessObjectDataSearchRequest.

/**
 * Validates a business object data search request.
 *
 * @param businessObjectDataSearchRequest the business object data search request
 */
public void validateBusinessObjectDataSearchRequest(BusinessObjectDataSearchRequest businessObjectDataSearchRequest) {
    Assert.notNull(businessObjectDataSearchRequest, "A business object data search request must be specified.");
    List<BusinessObjectDataSearchFilter> businessObjectDataSearchFilters = businessObjectDataSearchRequest.getBusinessObjectDataSearchFilters();
    Assert.isTrue(CollectionUtils.isNotEmpty(businessObjectDataSearchFilters), "A business object data search filter must be specified.");
    Assert.isTrue(businessObjectDataSearchFilters.size() == 1, "A list of business object data search filters can only have one element.");
    BusinessObjectDataSearchFilter businessObjectDataSearchFilter = businessObjectDataSearchFilters.get(0);
    List<BusinessObjectDataSearchKey> businessObjectDataSearchKeys = businessObjectDataSearchFilter.getBusinessObjectDataSearchKeys();
    Assert.isTrue(CollectionUtils.isNotEmpty(businessObjectDataSearchKeys), "A business object data search key must be specified.");
    Assert.isTrue(businessObjectDataSearchKeys.size() == 1, "A list of business object data search keys can only have one element.");
    validateBusinessObjectDataSearchKey(businessObjectDataSearchKeys.get(0));
}
Also used : BusinessObjectDataSearchFilter(org.finra.herd.model.api.xml.BusinessObjectDataSearchFilter) BusinessObjectDataSearchKey(org.finra.herd.model.api.xml.BusinessObjectDataSearchKey)

Example 2 with BusinessObjectDataSearchKey

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

the class RetentionExpirationExporterController method performRetentionExpirationExport.

/**
 * Executes the retention expiration exporter workflow.
 *
 * @param namespace the namespace of business object data
 * @param businessObjectDefinitionName the business object definition name of business object data
 * @param localOutputFile the local output file
 * @param regServerAccessParamsDto the DTO for the parameters required to communicate with the registration server
 * @param udcServerHost the hostname of the UDC application server
 *
 * @throws Exception if any problems were encountered
 */
void performRetentionExpirationExport(String namespace, String businessObjectDefinitionName, File localOutputFile, RegServerAccessParamsDto regServerAccessParamsDto, String udcServerHost) throws Exception {
    // Fail if local output file already exists.
    if (localOutputFile.exists()) {
        throw new IllegalArgumentException(String.format("The specified local output file \"%s\" already exists.", localOutputFile.toString()));
    }
    // Initialize the web client.
    retentionExpirationExporterWebClient.setRegServerAccessParamsDto(regServerAccessParamsDto);
    // Validate that specified business object definition exists.
    BusinessObjectDefinition businessObjectDefinition = retentionExpirationExporterWebClient.getBusinessObjectDefinition(namespace, businessObjectDefinitionName);
    // Get business object display name.
    String businessObjectDefinitionDisplayName = getBusinessObjectDefinitionDisplayName(businessObjectDefinition);
    // Create a search request for business object data with the filter on retention expiration option.
    BusinessObjectDataSearchKey businessObjectDataSearchKey = new BusinessObjectDataSearchKey();
    businessObjectDataSearchKey.setNamespace(namespace);
    businessObjectDataSearchKey.setBusinessObjectDefinitionName(businessObjectDefinitionName);
    businessObjectDataSearchKey.setFilterOnRetentionExpiration(true);
    List<BusinessObjectDataSearchKey> businessObjectDataSearchKeys = new ArrayList<>();
    businessObjectDataSearchKeys.add(businessObjectDataSearchKey);
    BusinessObjectDataSearchFilter businessObjectDataSearchFilter = new BusinessObjectDataSearchFilter(businessObjectDataSearchKeys);
    BusinessObjectDataSearchRequest request = new BusinessObjectDataSearchRequest(Collections.singletonList(businessObjectDataSearchFilter));
    // Create a result list for business object data.
    List<BusinessObjectData> businessObjectDataList = new ArrayList<>();
    // Fetch business object data from server until no records found.
    int pageNumber = 1;
    BusinessObjectDataSearchResult businessObjectDataSearchResult = retentionExpirationExporterWebClient.searchBusinessObjectData(request, pageNumber);
    while (CollectionUtils.isNotEmpty(businessObjectDataSearchResult.getBusinessObjectDataElements())) {
        LOGGER.info("Fetched {} business object data records from the registration server.", CollectionUtils.size(businessObjectDataSearchResult.getBusinessObjectDataElements()));
        businessObjectDataList.addAll(businessObjectDataSearchResult.getBusinessObjectDataElements());
        pageNumber++;
        businessObjectDataSearchResult = retentionExpirationExporterWebClient.searchBusinessObjectData(request, pageNumber);
    }
    // Write business object data to the output CSV file.
    writeToCsvFile(localOutputFile, businessObjectDefinition.getNamespace(), businessObjectDefinition.getBusinessObjectDefinitionName(), businessObjectDefinitionDisplayName, udcServerHost, businessObjectDataList);
}
Also used : BusinessObjectDefinition(org.finra.herd.model.api.xml.BusinessObjectDefinition) BusinessObjectDataSearchFilter(org.finra.herd.model.api.xml.BusinessObjectDataSearchFilter) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) ArrayList(java.util.ArrayList) BusinessObjectDataSearchKey(org.finra.herd.model.api.xml.BusinessObjectDataSearchKey) BusinessObjectDataSearchRequest(org.finra.herd.model.api.xml.BusinessObjectDataSearchRequest) BusinessObjectDataSearchResult(org.finra.herd.model.api.xml.BusinessObjectDataSearchResult)

Example 3 with BusinessObjectDataSearchKey

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

the class BusinessObjectDataServiceImpl method searchBusinessObjectData.

@NamespacePermission(fields = "#businessObjectDataSearchRequest.businessObjectDataSearchFilters[0].BusinessObjectDataSearchKeys[0].namespace", permissions = NamespacePermissionEnum.READ)
@Override
public BusinessObjectDataSearchResultPagingInfoDto searchBusinessObjectData(Integer pageNum, Integer pageSize, BusinessObjectDataSearchRequest businessObjectDataSearchRequest) {
    // TODO: Check name space permission for all entries in the request.
    // Validate the business object data search request.
    businessObjectDataSearchHelper.validateBusinessObjectDataSearchRequest(businessObjectDataSearchRequest);
    // Get the maximum number of results that can be returned on any page of data. The "pageSize" query parameter should not be greater than
    // this value or an HTTP status of 400 (Bad Request) error would be returned.
    int maxResultsPerPage = configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DATA_SEARCH_MAX_PAGE_SIZE, Integer.class);
    // Validate the page number and page size
    // Set the defaults if pageNum and pageSize are null
    // Page number must be greater than 0
    // Page size must be greater than 0 and less than maximum page size
    pageNum = businessObjectDataSearchHelper.validatePagingParameter("pageNum", pageNum, 1, Integer.MAX_VALUE);
    pageSize = businessObjectDataSearchHelper.validatePagingParameter("pageSize", pageSize, maxResultsPerPage, maxResultsPerPage);
    // Get the maximum record count that is configured in the system.
    Integer businessObjectDataSearchMaxResultCount = configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DATA_SEARCH_MAX_RESULT_COUNT, Integer.class);
    // Get the business object data search key.
    // We assume that the input list contains only one filter with a single search key, since validation should be passed by now.
    BusinessObjectDataSearchKey businessObjectDataSearchKey = businessObjectDataSearchRequest.getBusinessObjectDataSearchFilters().get(0).getBusinessObjectDataSearchKeys().get(0);
    // Get the total record count.
    Long totalRecordCount = businessObjectDataDao.getBusinessObjectDataCountBySearchKey(businessObjectDataSearchKey);
    // Validate the total record count.
    if (totalRecordCount > businessObjectDataSearchMaxResultCount) {
        throw new IllegalArgumentException(String.format("Result limit of %d exceeded. Total result size %d. Modify filters to further limit results.", businessObjectDataSearchMaxResultCount, totalRecordCount));
    }
    // If total record count is zero, we return an empty result list. Otherwise, execute the search.
    List<BusinessObjectData> businessObjectDataList = totalRecordCount == 0 ? new ArrayList<>() : businessObjectDataDao.searchBusinessObjectData(businessObjectDataSearchKey, pageNum, pageSize);
    // Get the page count.
    Long pageCount = totalRecordCount / pageSize + (totalRecordCount % pageSize > 0 ? 1 : 0);
    // Build and return the business object data search result with the paging information.
    return new BusinessObjectDataSearchResultPagingInfoDto(pageNum.longValue(), pageSize.longValue(), pageCount, (long) businessObjectDataList.size(), totalRecordCount, (long) maxResultsPerPage, new BusinessObjectDataSearchResult(businessObjectDataList));
}
Also used : BusinessObjectDataSearchResultPagingInfoDto(org.finra.herd.model.dto.BusinessObjectDataSearchResultPagingInfoDto) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) BusinessObjectDataSearchKey(org.finra.herd.model.api.xml.BusinessObjectDataSearchKey) BusinessObjectDataSearchResult(org.finra.herd.model.api.xml.BusinessObjectDataSearchResult) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 4 with BusinessObjectDataSearchKey

use of org.finra.herd.model.api.xml.BusinessObjectDataSearchKey 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)

Example 5 with BusinessObjectDataSearchKey

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

the class BusinessObjectDataSearchServiceTest method testSearchBusinessObjectDataWithMaxRecordsExceeded.

@Test
public void testSearchBusinessObjectDataWithMaxRecordsExceeded() throws Exception {
    businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, null, DATA_VERSION, true, "VALID");
    businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, null, DATA_VERSION, true, "INVALID");
    businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION_2, PARTITION_VALUE, null, DATA_VERSION, true, "INVALID");
    businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION_2, PARTITION_VALUE, null, DATA_VERSION, true, "VALID");
    // Override configuration.
    int maxBusinessObjectDataSearchResultCount = 2;
    Map<String, Object> overrideMap = new HashMap<>();
    overrideMap.put(ConfigurationValue.BUSINESS_OBJECT_DATA_SEARCH_MAX_RESULT_COUNT.getKey(), maxBusinessObjectDataSearchResultCount);
    modifyPropertySourceInEnvironment(overrideMap);
    try {
        businessObjectDataService.searchBusinessObjectData(DEFAULT_PAGE_NUMBER, DEFAULT_PAGE_SIZE, new BusinessObjectDataSearchRequest(Collections.singletonList(new BusinessObjectDataSearchFilter(Collections.singletonList(new BusinessObjectDataSearchKey(NAMESPACE, BDEF_NAME, NO_FORMAT_USAGE_CODE, NO_FORMAT_FILE_TYPE_CODE, NO_FORMAT_VERSION, NO_PARTITION_VALUE_FILTERS, NO_ATTRIBUTE_VALUE_FILTERS, NO_FILTER_ON_LATEST_VALID_VERSION, NO_FILTER_ON_RETENTION_EXPIRATION))))));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Result limit of %d exceeded. Total result size %d. Modify filters to further limit results.", maxBusinessObjectDataSearchResultCount, 3), e.getMessage());
    } finally {
        // Restore the property sources so we don't affect other tests.
        restorePropertySourceInEnvironment();
    }
}
Also used : BusinessObjectDataSearchFilter(org.finra.herd.model.api.xml.BusinessObjectDataSearchFilter) HashMap(java.util.HashMap) BusinessObjectDataSearchKey(org.finra.herd.model.api.xml.BusinessObjectDataSearchKey) BusinessObjectDataSearchRequest(org.finra.herd.model.api.xml.BusinessObjectDataSearchRequest) Test(org.junit.Test)

Aggregations

BusinessObjectDataSearchKey (org.finra.herd.model.api.xml.BusinessObjectDataSearchKey)40 Test (org.junit.Test)35 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)28 ArrayList (java.util.ArrayList)21 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)15 BusinessObjectDataSearchFilter (org.finra.herd.model.api.xml.BusinessObjectDataSearchFilter)13 BusinessObjectDataSearchRequest (org.finra.herd.model.api.xml.BusinessObjectDataSearchRequest)12 AttributeValueFilter (org.finra.herd.model.api.xml.AttributeValueFilter)11 PartitionValueFilter (org.finra.herd.model.api.xml.PartitionValueFilter)8 BusinessObjectDataSearchResultPagingInfoDto (org.finra.herd.model.dto.BusinessObjectDataSearchResultPagingInfoDto)6 BusinessObjectDataAttributeEntity (org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity)6 PartitionValueRange (org.finra.herd.model.api.xml.PartitionValueRange)4 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)3 BusinessObjectDataSearchResult (org.finra.herd.model.api.xml.BusinessObjectDataSearchResult)2 RetentionTypeEntity (org.finra.herd.model.jpa.RetentionTypeEntity)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)1 BusinessObjectDefinition (org.finra.herd.model.api.xml.BusinessObjectDefinition)1 LatestBeforePartitionValue (org.finra.herd.model.api.xml.LatestBeforePartitionValue)1