Search in sources :

Example 1 with BusinessObjectDataSearchResult

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

the class RetentionExpirationExporterWebClient method searchBusinessObjectData.

/**
 * Retrieves business object definition from the herd registration server.
 *
 * @param businessObjectDataSearchRequest the business object definition search request
 * @param pageNum the page number for the result to contain
 *
 * @return the business object definition
 * @throws JAXBException if a JAXB error was encountered
 * @throws IOException if an I/O error was encountered
 * @throws URISyntaxException if a URI syntax error was encountered
 */
BusinessObjectDataSearchResult searchBusinessObjectData(BusinessObjectDataSearchRequest businessObjectDataSearchRequest, Integer pageNum) throws IOException, JAXBException, URISyntaxException {
    LOGGER.info("Sending business object data search request to the registration server...");
    URIBuilder uriBuilder = new URIBuilder().setScheme(getUriScheme()).setHost(regServerAccessParamsDto.getRegServerHost()).setPort(regServerAccessParamsDto.getRegServerPort()).setPath(HERD_APP_REST_URI_PREFIX + "/businessObjectData/search").setParameter("pageNum", pageNum.toString());
    URI uri = uriBuilder.build();
    // Create a JAXB context and marshaller
    JAXBContext requestContext = JAXBContext.newInstance(BusinessObjectDataSearchRequest.class);
    Marshaller requestMarshaller = requestContext.createMarshaller();
    requestMarshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.name());
    requestMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    StringWriter stringWriter = new StringWriter();
    requestMarshaller.marshal(businessObjectDataSearchRequest, stringWriter);
    try (CloseableHttpClient client = httpClientOperations.createHttpClient()) {
        HttpPost request = new HttpPost(uri);
        request.addHeader("Content-Type", DEFAULT_CONTENT_TYPE);
        request.addHeader("Accepts", DEFAULT_ACCEPT);
        // If SSL is enabled, set the client authentication header.
        if (regServerAccessParamsDto.isUseSsl()) {
            request.addHeader(getAuthorizationHeader());
        }
        request.setEntity(new StringEntity(stringWriter.toString()));
        LOGGER.info(String.format("    HTTP POST URI: %s", request.getURI().toString()));
        LOGGER.info(String.format("    HTTP POST Headers: %s", Arrays.toString(request.getAllHeaders())));
        LOGGER.info(String.format("    HTTP POST Entity Content:%n%s", stringWriter.toString()));
        BusinessObjectDataSearchResult businessObjectDataSearchResult = getBusinessObjectDataSearchResult(httpClientOperations.execute(client, request));
        LOGGER.info("Successfully received search business object data response from the registration server.");
        return businessObjectDataSearchResult;
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) JAXBContext(javax.xml.bind.JAXBContext) URI(java.net.URI) BusinessObjectDataSearchResult(org.finra.herd.model.api.xml.BusinessObjectDataSearchResult) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 2 with BusinessObjectDataSearchResult

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

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

the class MockHttpClientOperationsImpl method buildSearchBusinessObjectDataResponse.

/**
 * Builds a business object definition response.
 *
 * @param response the response
 * @param uri the URI of the incoming request
 *
 * @throws JAXBException if a JAXB error occurred
 */
private void buildSearchBusinessObjectDataResponse(MockCloseableHttpResponse response, URI uri) throws JAXBException {
    BusinessObjectDataSearchResult businessObjectDataSearchResult = new BusinessObjectDataSearchResult();
    // Build the response based on the pageNum.
    if (uri.getRawQuery().equals("pageNum=1")) {
        List<BusinessObjectData> businessObjectDataElements = new ArrayList<>();
        // Add business object data with sub-partitions.
        BusinessObjectData businessObjectDataWithSubPartitions = new BusinessObjectData();
        businessObjectDataWithSubPartitions.setNamespace("testNamespace");
        businessObjectDataWithSubPartitions.setBusinessObjectDefinitionName("testBusinessObjectDefinitionName");
        businessObjectDataWithSubPartitions.setBusinessObjectFormatUsage("testBusinessObjectFormatUsage");
        businessObjectDataWithSubPartitions.setBusinessObjectFormatFileType("testBusinessObjectFormatFileType");
        businessObjectDataWithSubPartitions.setBusinessObjectFormatVersion(9);
        businessObjectDataWithSubPartitions.setPartitionValue("primaryPartitionValue");
        businessObjectDataWithSubPartitions.setSubPartitionValues(Arrays.asList("subPartitionValue1", "subPartitionValue2", "subPartitionValue3", "subPartitionValue4"));
        businessObjectDataWithSubPartitions.setVersion(5);
        businessObjectDataElements.add(businessObjectDataWithSubPartitions);
        // Add business object data without sub-partitions.
        BusinessObjectData businessObjectDataWithoutSubPartitions = new BusinessObjectData();
        businessObjectDataWithoutSubPartitions.setNamespace("testNamespace");
        businessObjectDataWithoutSubPartitions.setBusinessObjectDefinitionName("testBusinessObjectDefinitionName");
        businessObjectDataWithoutSubPartitions.setBusinessObjectFormatUsage("testBusinessObjectFormatUsage");
        businessObjectDataWithoutSubPartitions.setBusinessObjectFormatFileType("testBusinessObjectFormatFileType");
        businessObjectDataWithoutSubPartitions.setBusinessObjectFormatVersion(9);
        businessObjectDataWithoutSubPartitions.setPartitionValue("primaryPartitionValue");
        businessObjectDataWithoutSubPartitions.setSubPartitionValues(null);
        businessObjectDataWithoutSubPartitions.setVersion(5);
        businessObjectDataElements.add(businessObjectDataWithoutSubPartitions);
        businessObjectDataSearchResult.setBusinessObjectDataElements(businessObjectDataElements);
    }
    response.setEntity(getHttpEntity(businessObjectDataSearchResult));
}
Also used : BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) ArrayList(java.util.ArrayList) BusinessObjectDataSearchResult(org.finra.herd.model.api.xml.BusinessObjectDataSearchResult)

Example 4 with BusinessObjectDataSearchResult

use of org.finra.herd.model.api.xml.BusinessObjectDataSearchResult 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 5 with BusinessObjectDataSearchResult

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

the class BusinessObjectDataRestControllerTest method testSearchBusinessObjectData.

@Test
public void testSearchBusinessObjectData() {
    // Create a business object data search request.
    BusinessObjectDataSearchRequest businessObjectDataSearchRequest = new BusinessObjectDataSearchRequest();
    // Create a business object data search response with paging information.
    BusinessObjectDataSearchResultPagingInfoDto businessObjectDataSearchResultPagingInfoDto = new BusinessObjectDataSearchResultPagingInfoDto(Long.valueOf(PAGE_NUMBER_ONE), Long.valueOf(PAGE_SIZE_ONE_THOUSAND), PAGE_COUNT, TOTAL_RECORDS_ON_PAGE, TOTAL_RECORD_COUNT, MAX_RESULTS_PER_PAGE, new BusinessObjectDataSearchResult());
    // Create a mocked HTTP servlet response.
    HttpServletResponse httpServletResponse = mock(HttpServletResponse.class);
    // Mock the external calls.
    when(businessObjectDataService.searchBusinessObjectData(PAGE_NUMBER_ONE, PAGE_SIZE_ONE_THOUSAND, businessObjectDataSearchRequest)).thenReturn(businessObjectDataSearchResultPagingInfoDto);
    // Call the method under test.
    BusinessObjectDataSearchResult result = businessObjectDataRestController.searchBusinessObjectData(PAGE_NUMBER_ONE, PAGE_SIZE_ONE_THOUSAND, businessObjectDataSearchRequest, httpServletResponse);
    // Verify the external calls.
    verify(businessObjectDataService).searchBusinessObjectData(PAGE_NUMBER_ONE, PAGE_SIZE_ONE_THOUSAND, businessObjectDataSearchRequest);
    verifyNoMoreInteractionsHelper();
    // Verify interactions with the mocked objects.
    verify(httpServletResponse).setHeader(HerdBaseController.HTTP_HEADER_PAGING_PAGE_NUM, String.valueOf(PAGE_NUMBER_ONE));
    verify(httpServletResponse).setHeader(HerdBaseController.HTTP_HEADER_PAGING_PAGE_SIZE, String.valueOf(PAGE_SIZE_ONE_THOUSAND));
    verify(httpServletResponse).setHeader(HerdBaseController.HTTP_HEADER_PAGING_PAGE_COUNT, String.valueOf(PAGE_COUNT));
    verify(httpServletResponse).setHeader(HerdBaseController.HTTP_HEADER_PAGING_TOTAL_RECORDS_ON_PAGE, String.valueOf(TOTAL_RECORDS_ON_PAGE));
    verify(httpServletResponse).setHeader(HerdBaseController.HTTP_HEADER_PAGING_TOTAL_RECORD_COUNT, String.valueOf(TOTAL_RECORD_COUNT));
    verify(httpServletResponse).setHeader(HerdBaseController.HTTP_HEADER_PAGING_MAX_RESULTS_PER_PAGE, String.valueOf(MAX_RESULTS_PER_PAGE));
    verifyNoMoreInteractions(httpServletResponse);
    // Validate the results.
    assertEquals(businessObjectDataSearchResultPagingInfoDto.getBusinessObjectDataSearchResult(), result);
}
Also used : BusinessObjectDataSearchResultPagingInfoDto(org.finra.herd.model.dto.BusinessObjectDataSearchResultPagingInfoDto) HttpServletResponse(javax.servlet.http.HttpServletResponse) BusinessObjectDataSearchRequest(org.finra.herd.model.api.xml.BusinessObjectDataSearchRequest) BusinessObjectDataSearchResult(org.finra.herd.model.api.xml.BusinessObjectDataSearchResult) Test(org.junit.Test)

Aggregations

BusinessObjectDataSearchResult (org.finra.herd.model.api.xml.BusinessObjectDataSearchResult)8 BusinessObjectDataSearchRequest (org.finra.herd.model.api.xml.BusinessObjectDataSearchRequest)5 Test (org.junit.Test)4 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)3 ArrayList (java.util.ArrayList)2 BusinessObjectDataSearchKey (org.finra.herd.model.api.xml.BusinessObjectDataSearchKey)2 BusinessObjectDataSearchResultPagingInfoDto (org.finra.herd.model.dto.BusinessObjectDataSearchResultPagingInfoDto)2 StringWriter (java.io.StringWriter)1 URI (java.net.URI)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 HttpPost (org.apache.http.client.methods.HttpPost)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1 StringEntity (org.apache.http.entity.StringEntity)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)1 BusinessObjectDataSearchFilter (org.finra.herd.model.api.xml.BusinessObjectDataSearchFilter)1 BusinessObjectDefinition (org.finra.herd.model.api.xml.BusinessObjectDefinition)1