Search in sources :

Example 1 with BusinessObjectDataSearchResultPagingInfoDto

use of org.finra.herd.model.dto.BusinessObjectDataSearchResultPagingInfoDto in project herd by FINRAOS.

the class SearchBusinessObjectData method executeImpl.

@Override
public void executeImpl(DelegateExecution execution) throws Exception {
    String contentTypeString = activitiHelper.getRequiredExpressionVariableAsString(contentType, execution, "ContentType").trim();
    String requestString = activitiHelper.getRequiredExpressionVariableAsString(businessObjectDataSearchRequest, execution, "BusinessObjectDataSearchRequest").trim();
    Integer pageNum = activitiHelper.getExpressionVariableAsInteger(this.pageNum, execution, "pageNum", false);
    Integer pageSize = activitiHelper.getExpressionVariableAsInteger(this.pageSize, execution, "pageSize", false);
    BusinessObjectDataSearchRequest request = getRequestObject(contentTypeString, requestString, BusinessObjectDataSearchRequest.class);
    // Call the business object data search service.
    BusinessObjectDataSearchResultPagingInfoDto businessObjectDataSearchResultPagingInfoDto = businessObjectDataService.searchBusinessObjectData(pageNum, pageSize, request);
    // Set the JSON response as a workflow variable.
    setJsonResponseAsWorkflowVariable(businessObjectDataSearchResultPagingInfoDto.getBusinessObjectDataSearchResult(), execution);
}
Also used : BusinessObjectDataSearchResultPagingInfoDto(org.finra.herd.model.dto.BusinessObjectDataSearchResultPagingInfoDto) BusinessObjectDataSearchRequest(org.finra.herd.model.api.xml.BusinessObjectDataSearchRequest)

Example 2 with BusinessObjectDataSearchResultPagingInfoDto

use of org.finra.herd.model.dto.BusinessObjectDataSearchResultPagingInfoDto 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 3 with BusinessObjectDataSearchResultPagingInfoDto

use of org.finra.herd.model.dto.BusinessObjectDataSearchResultPagingInfoDto 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 4 with BusinessObjectDataSearchResultPagingInfoDto

use of org.finra.herd.model.dto.BusinessObjectDataSearchResultPagingInfoDto in project herd by FINRAOS.

the class BusinessObjectDataSearchServiceTest method testSearchBusinessObjectData.

@Test
public void testSearchBusinessObjectData() {
    businessObjectDataServiceTestHelper.createDatabaseEntitiesForBusinessObjectDataSearchTesting();
    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);
    businessObjectDataSearchKeys.add(key);
    BusinessObjectDataSearchFilter filter = new BusinessObjectDataSearchFilter(businessObjectDataSearchKeys);
    filters.add(filter);
    request.setBusinessObjectDataSearchFilters(filters);
    BusinessObjectDataSearchResultPagingInfoDto result = businessObjectDataService.searchBusinessObjectData(DEFAULT_PAGE_NUMBER, PAGE_SIZE, request);
    assertTrue(result.getBusinessObjectDataSearchResult().getBusinessObjectDataElements().size() == 2);
    for (BusinessObjectData data : result.getBusinessObjectDataSearchResult().getBusinessObjectDataElements()) {
        assertEquals(NAMESPACE, data.getNamespace());
        assertEquals(BDEF_NAME, data.getBusinessObjectDefinitionName());
    }
    // 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(2), result.getTotalRecordsOnPage());
    assertEquals(Long.valueOf(2), result.getTotalRecordCount());
    assertEquals(Long.valueOf(DEFAULT_PAGE_SIZE), result.getMaxResultsPerPage());
}
Also used : BusinessObjectDataSearchResultPagingInfoDto(org.finra.herd.model.dto.BusinessObjectDataSearchResultPagingInfoDto) 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) Test(org.junit.Test)

Example 5 with BusinessObjectDataSearchResultPagingInfoDto

use of org.finra.herd.model.dto.BusinessObjectDataSearchResultPagingInfoDto in project herd by FINRAOS.

the class BusinessObjectDataSearchServiceTest method testSearchBusinessObjectDataWithPageNumPageSize.

@Test
public void testSearchBusinessObjectDataWithPageNumPageSize() {
    businessObjectDataServiceTestHelper.createDatabaseEntitiesForBusinessObjectDataSearchTesting();
    BusinessObjectDataSearchRequest request = businessObjectDataServiceTestHelper.createSimpleBusinessObjectDataSearchRequest(NAMESPACE, BDEF_NAME);
    // Test getting the first page.
    BusinessObjectDataSearchResultPagingInfoDto result = businessObjectDataService.searchBusinessObjectData(1, 1, request);
    assertEquals(1, result.getBusinessObjectDataSearchResult().getBusinessObjectDataElements().size());
    for (BusinessObjectData data : result.getBusinessObjectDataSearchResult().getBusinessObjectDataElements()) {
        assertEquals(NAMESPACE, data.getNamespace());
        assertEquals(BDEF_NAME, data.getBusinessObjectDefinitionName());
        assertEquals(FORMAT_FILE_TYPE_CODE, data.getBusinessObjectFormatFileType());
        assertEquals(FORMAT_USAGE_CODE, data.getBusinessObjectFormatUsage());
    }
    // Validate the paging information.
    assertEquals(Long.valueOf(1), result.getPageNum());
    assertEquals(Long.valueOf(1), result.getPageSize());
    assertEquals(Long.valueOf(2), result.getPageCount());
    assertEquals(Long.valueOf(1), result.getTotalRecordsOnPage());
    assertEquals(Long.valueOf(2), result.getTotalRecordCount());
    assertEquals(Long.valueOf(DEFAULT_PAGE_SIZE), result.getMaxResultsPerPage());
    // Test getting the second page.
    result = businessObjectDataService.searchBusinessObjectData(2, 1, request);
    assertEquals(1, result.getBusinessObjectDataSearchResult().getBusinessObjectDataElements().size());
    for (BusinessObjectData data : result.getBusinessObjectDataSearchResult().getBusinessObjectDataElements()) {
        assertEquals(NAMESPACE, data.getNamespace());
        assertEquals(BDEF_NAME, data.getBusinessObjectDefinitionName());
        assertEquals(FORMAT_FILE_TYPE_CODE, data.getBusinessObjectFormatFileType());
        assertEquals(FORMAT_USAGE_CODE_2, data.getBusinessObjectFormatUsage());
    }
    // Validate the paging information.
    assertEquals(Long.valueOf(2), result.getPageNum());
    assertEquals(Long.valueOf(1), result.getPageSize());
    assertEquals(Long.valueOf(2), result.getPageCount());
    assertEquals(Long.valueOf(1), result.getTotalRecordsOnPage());
    assertEquals(Long.valueOf(2), result.getTotalRecordCount());
    assertEquals(Long.valueOf(DEFAULT_PAGE_SIZE), result.getMaxResultsPerPage());
    // Test getting a larger page than there are results remaining
    result = businessObjectDataService.searchBusinessObjectData(1, 3, request);
    assertEquals(2, result.getBusinessObjectDataSearchResult().getBusinessObjectDataElements().size());
    // Validate the paging information.
    assertEquals(Long.valueOf(1), result.getPageNum());
    assertEquals(Long.valueOf(3), result.getPageSize());
    assertEquals(Long.valueOf(1), result.getPageCount());
    assertEquals(Long.valueOf(2), result.getTotalRecordsOnPage());
    assertEquals(Long.valueOf(2), result.getTotalRecordCount());
    assertEquals(Long.valueOf(DEFAULT_PAGE_SIZE), result.getMaxResultsPerPage());
    // Test getting a page that does not exist.
    result = businessObjectDataService.searchBusinessObjectData(3, 1, request);
    assertEquals(0, result.getBusinessObjectDataSearchResult().getBusinessObjectDataElements().size());
    // Validate the paging information.
    assertEquals(Long.valueOf(3), result.getPageNum());
    assertEquals(Long.valueOf(1), result.getPageSize());
    assertEquals(Long.valueOf(2), result.getPageCount());
    assertEquals(Long.valueOf(0), result.getTotalRecordsOnPage());
    assertEquals(Long.valueOf(2), 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) BusinessObjectDataSearchRequest(org.finra.herd.model.api.xml.BusinessObjectDataSearchRequest) Test(org.junit.Test)

Aggregations

BusinessObjectDataSearchResultPagingInfoDto (org.finra.herd.model.dto.BusinessObjectDataSearchResultPagingInfoDto)12 BusinessObjectDataSearchRequest (org.finra.herd.model.api.xml.BusinessObjectDataSearchRequest)10 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)7 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)6 BusinessObjectDataSearchKey (org.finra.herd.model.api.xml.BusinessObjectDataSearchKey)6 BusinessObjectDataSearchFilter (org.finra.herd.model.api.xml.BusinessObjectDataSearchFilter)5 AttributeValueFilter (org.finra.herd.model.api.xml.AttributeValueFilter)3 HashMap (java.util.HashMap)2 FieldExtension (org.activiti.bpmn.model.FieldExtension)2 BusinessObjectDataSearchResult (org.finra.herd.model.api.xml.BusinessObjectDataSearchResult)2 Parameter (org.finra.herd.model.api.xml.Parameter)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)1 PartitionValueFilter (org.finra.herd.model.api.xml.PartitionValueFilter)1 Secured (org.springframework.security.access.annotation.Secured)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1