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));
}
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);
}
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));
}
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());
}
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();
}
}
Aggregations