Search in sources :

Example 1 with BusinessObjectDataAvailability

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

the class CheckBusinessObjectDataAvailability method executeImpl.

@Override
public void executeImpl(DelegateExecution execution) throws Exception {
    // Create the request.
    BusinessObjectDataAvailabilityRequest request = new BusinessObjectDataAvailabilityRequest();
    request.setNamespace(activitiHelper.getExpressionVariableAsString(namespace, execution));
    request.setBusinessObjectDefinitionName(activitiHelper.getExpressionVariableAsString(businessObjectDefinitionName, execution));
    request.setBusinessObjectFormatUsage(activitiHelper.getExpressionVariableAsString(businessObjectFormatUsage, execution));
    request.setBusinessObjectFormatFileType(activitiHelper.getExpressionVariableAsString(businessObjectFormatFileType, execution));
    request.setBusinessObjectFormatVersion(activitiHelper.getExpressionVariableAsInteger(businessObjectFormatVersion, execution, "BusinessObjectFormatVersion", false));
    // Build the partition value filter.
    PartitionValueFilter partitionValueFilter = new PartitionValueFilter();
    request.setPartitionValueFilter(partitionValueFilter);
    // Set the partition key if present.
    String partitionKeyString = activitiHelper.getExpressionVariableAsString(partitionKey, execution);
    if (partitionKeyString != null) {
        partitionValueFilter.setPartitionKey(partitionKeyString);
    }
    // Set the partition values if present.
    String partitionValuesString = activitiHelper.getExpressionVariableAsString(partitionValues, execution);
    List<String> partitionValueList = daoHelper.splitStringWithDefaultDelimiterEscaped(partitionValuesString);
    if (!CollectionUtils.isEmpty(partitionValueList)) {
        partitionValueFilter.setPartitionValues(partitionValueList);
    }
    // Build the partition value range and set it on the filter if present.
    PartitionValueRange partitionValueRange = new PartitionValueRange();
    partitionValueRange.setStartPartitionValue(activitiHelper.getExpressionVariableAsString(startPartitionValue, execution));
    partitionValueRange.setEndPartitionValue(activitiHelper.getExpressionVariableAsString(endPartitionValue, execution));
    if (StringUtils.isNotBlank(partitionValueRange.getStartPartitionValue()) || StringUtils.isNotBlank(partitionValueRange.getEndPartitionValue())) {
        partitionValueFilter.setPartitionValueRange(partitionValueRange);
    }
    // Set the business object data version if present.
    request.setBusinessObjectDataVersion(activitiHelper.getExpressionVariableAsInteger(businessObjectDataVersion, execution, "BusinessObjectDataVersion", false));
    // Set the storage.
    request.setStorageName(activitiHelper.getExpressionVariableAsString(storageName, execution));
    // Call the availability service.
    BusinessObjectDataAvailability businessObjectDataAvailability = businessObjectDataService.checkBusinessObjectDataAvailability(request);
    // Set the JSON response as a workflow variable.
    setJsonResponseAsWorkflowVariable(businessObjectDataAvailability, execution);
    // Set a workflow variable for whether all the data is available or not for easy access.
    boolean allAvailable = businessObjectDataAvailability.getNotAvailableStatuses().size() == 0;
    setTaskWorkflowVariable(execution, VARIABLE_IS_ALL_DATA_AVAILABLE, allAvailable);
}
Also used : PartitionValueRange(org.finra.herd.model.api.xml.PartitionValueRange) BusinessObjectDataAvailabilityRequest(org.finra.herd.model.api.xml.BusinessObjectDataAvailabilityRequest) BusinessObjectDataAvailability(org.finra.herd.model.api.xml.BusinessObjectDataAvailability) PartitionValueFilter(org.finra.herd.model.api.xml.PartitionValueFilter)

Example 2 with BusinessObjectDataAvailability

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

the class CheckBusinessObjectDataAvailabilityMultiplePartitions method executeImpl.

@Override
public void executeImpl(DelegateExecution execution) throws Exception {
    String contentTypeString = activitiHelper.getRequiredExpressionVariableAsString(contentType, execution, "ContentType").trim();
    String requestString = activitiHelper.getRequiredExpressionVariableAsString(businessObjectDataAvailabilityRequest, execution, "BusinessObjectDataAvailabilityRequest").trim();
    BusinessObjectDataAvailabilityRequest request = getRequestObject(contentTypeString, requestString, BusinessObjectDataAvailabilityRequest.class);
    // Call the business object data availability service.
    BusinessObjectDataAvailability businessObjectDataAvailability = businessObjectDataService.checkBusinessObjectDataAvailability(request);
    // Set the JSON response as a workflow variable.
    setJsonResponseAsWorkflowVariable(businessObjectDataAvailability, execution);
    // Set a workflow variable for whether all the data is available or not for easy access.
    boolean allAvailable = businessObjectDataAvailability.getNotAvailableStatuses().size() == 0;
    setTaskWorkflowVariable(execution, VARIABLE_IS_ALL_DATA_AVAILABLE, allAvailable);
}
Also used : BusinessObjectDataAvailabilityRequest(org.finra.herd.model.api.xml.BusinessObjectDataAvailabilityRequest) BusinessObjectDataAvailability(org.finra.herd.model.api.xml.BusinessObjectDataAvailability)

Example 3 with BusinessObjectDataAvailability

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

the class BusinessObjectDataServiceImpl method checkBusinessObjectDataAvailabilityImpl.

/**
 * Performs a search and returns a list of business object data key values and relative statuses for a range of requested business object data.
 *
 * @param request the business object data availability request
 * @param skipRequestValidation specifies whether to skip the request validation and trimming
 *
 * @return the business object data availability information
 */
protected BusinessObjectDataAvailability checkBusinessObjectDataAvailabilityImpl(BusinessObjectDataAvailabilityRequest request, boolean skipRequestValidation) {
    // Perform the validation.
    if (!skipRequestValidation) {
        validateBusinessObjectDataAvailabilityRequest(request);
    }
    // Get business object format key from the request.
    BusinessObjectFormatKey businessObjectFormatKey = getBusinessObjectFormatKey(request);
    // Make sure that specified business object format exists.
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatKey);
    // Get the list of storages from the request and validate that specified storages exist.
    List<String> storageNames = getStorageNames(request);
    storageDaoHelper.validateStorageExistence(storageNames);
    // Build partition filters based on the specified partition value filters.
    // Business object data availability works across all storage platform types, so the storage platform type is not specified in the call.
    List<List<String>> partitionFilters = businessObjectDataDaoHelper.buildPartitionFilters(request.getPartitionValueFilters(), request.getPartitionValueFilter(), businessObjectFormatKey, request.getBusinessObjectDataVersion(), storageNames, null, null, businessObjectFormatEntity);
    // Retrieve a list of storage unit entities for the specified partition values. The entities will be sorted by partition value that is identified
    // by partition column position. If a business object data version isn't specified, the latest VALID business object data version is returned.
    // Business object data availability works across all storage platform types, so the storage platform type is not specified in the herdDao call.
    // We want to select only "available" storage units, so we pass "true" for selectOnlyAvailableStorageUnits parameter.
    List<StorageUnitEntity> availableStorageUnitEntities = storageUnitDao.getStorageUnitsByPartitionFiltersAndStorages(businessObjectFormatKey, partitionFilters, request.getBusinessObjectDataVersion(), BusinessObjectDataStatusEntity.VALID, storageNames, null, null, true);
    // Create business object data availability object instance and initialise it with request field values.
    BusinessObjectDataAvailability businessObjectDataAvailability = createBusinessObjectDataAvailability(request);
    // Create "available" and "not available" business object data status lists.
    List<BusinessObjectDataStatus> availableStatuses = new ArrayList<>();
    businessObjectDataAvailability.setAvailableStatuses(availableStatuses);
    List<BusinessObjectDataStatus> notAvailableStatuses = new ArrayList<>();
    businessObjectDataAvailability.setNotAvailableStatuses(notAvailableStatuses);
    // Build a list of matched available partition filters and populate the available statuses list. Please note that each request partition filter
    // might result in multiple available business object data entities. If storage names are not specified, fail on "duplicate" business object data
    // (same business object data instance registered with multiple storages). Otherwise, remove possible "duplicates".
    List<List<String>> matchedAvailablePartitionFilters = new ArrayList<>();
    List<List<String>> availablePartitions = new ArrayList<>();
    Map<BusinessObjectDataEntity, StorageUnitEntity> businessObjectDataToStorageUnitMap = new HashMap<>();
    for (StorageUnitEntity storageUnitEntity : availableStorageUnitEntities) {
        BusinessObjectDataEntity businessObjectDataEntity = storageUnitEntity.getBusinessObjectData();
        if (businessObjectDataToStorageUnitMap.containsKey(businessObjectDataEntity)) {
            // If storage names are not specified, fail on a business object data registered in multiple storages. Otherwise, ignore that storage unit.
            if (CollectionUtils.isEmpty(storageNames)) {
                throw new IllegalArgumentException(String.format("Found business object data registered in more than one storage. " + "Please specify storage(s) in the request to resolve this. Business object data {%s}", businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)));
            }
        } else {
            BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataEntity);
            matchedAvailablePartitionFilters.add(businessObjectDataHelper.getPartitionFilter(businessObjectDataKey, partitionFilters.get(0)));
            availablePartitions.add(businessObjectDataHelper.getPrimaryAndSubPartitionValues(businessObjectDataKey));
            availableStatuses.add(createAvailableBusinessObjectDataStatus(businessObjectDataEntity));
            businessObjectDataToStorageUnitMap.put(businessObjectDataEntity, storageUnitEntity);
        }
    }
    // Check if request specifies to include all registered sub-partitions in the response.
    boolean includeAllRegisteredSubPartitions = request.getBusinessObjectDataVersion() == null && BooleanUtils.isTrue(request.isIncludeAllRegisteredSubPartitions());
    // matched partition filters one more time to discover any non-available registered sub-partitions.
    if (includeAllRegisteredSubPartitions && !CollectionUtils.isEmpty(matchedAvailablePartitionFilters)) {
        addNotAvailableBusinessObjectDataStatuses(notAvailableStatuses, businessObjectFormatKey, matchedAvailablePartitionFilters, availablePartitions, storageNames);
    }
    // Get a list of unmatched partition filters.
    List<List<String>> unmatchedPartitionFilters = new ArrayList<>(partitionFilters);
    unmatchedPartitionFilters.removeAll(matchedAvailablePartitionFilters);
    // We still need to try to retrieve business object data per list of unmatched filters regardless of business object data and/or storage unit statuses.
    // This is done to populate not-available statuses with legitimate reasons.
    // Business object data availability works across all storage platform types, so the storage platform type is not specified in the herdDao call.
    // We want to select any existing storage units regardless of their status, so we pass "false" for selectOnlyAvailableStorageUnits parameter.
    List<StorageUnitEntity> notAvailableStorageUnitEntities = storageUnitDao.getStorageUnitsByPartitionFiltersAndStorages(businessObjectFormatKey, unmatchedPartitionFilters, request.getBusinessObjectDataVersion(), null, storageNames, null, null, false);
    // Populate the not-available statuses list.
    addNotAvailableBusinessObjectDataStatuses(notAvailableStatuses, notAvailableStorageUnitEntities);
    // Build a list of matched "not-available" partition filters.
    // Please note that each request partition filter might result in multiple available business object data entities.
    List<List<String>> matchedNotAvailablePartitionFilters = getPartitionFilters(notAvailableStorageUnitEntities, partitionFilters.get(0));
    // Update the list of unmatched partition filters.
    unmatchedPartitionFilters.removeAll(matchedNotAvailablePartitionFilters);
    // Populate the "not available" statuses per remaining unmatched filters.
    for (List<String> unmatchedPartitionFilter : unmatchedPartitionFilters) {
        notAvailableStatuses.add(createNotAvailableBusinessObjectDataStatus(request, unmatchedPartitionFilter, REASON_NOT_REGISTERED));
    }
    return businessObjectDataAvailability;
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) HashMap(java.util.HashMap) BusinessObjectDataAvailability(org.finra.herd.model.api.xml.BusinessObjectDataAvailability) ArrayList(java.util.ArrayList) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) List(java.util.List) ArrayList(java.util.ArrayList) BusinessObjectDataStatus(org.finra.herd.model.api.xml.BusinessObjectDataStatus) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity)

Example 4 with BusinessObjectDataAvailability

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

the class BusinessObjectDataServiceImpl method checkBusinessObjectDataAvailabilityCollectionImpl.

/**
 * Performs an availability check for a collection of business object data.
 *
 * @param businessObjectDataAvailabilityCollectionRequest the business object data availability collection requests
 *
 * @return the business object data availability information
 */
protected BusinessObjectDataAvailabilityCollectionResponse checkBusinessObjectDataAvailabilityCollectionImpl(BusinessObjectDataAvailabilityCollectionRequest businessObjectDataAvailabilityCollectionRequest) {
    // Perform the validation of the entire request, before we start processing the individual requests that requires the database access.
    validateBusinessObjectDataAvailabilityCollectionRequest(businessObjectDataAvailabilityCollectionRequest);
    // Process the individual requests and build the response.
    BusinessObjectDataAvailabilityCollectionResponse businessObjectDataAvailabilityCollectionResponse = new BusinessObjectDataAvailabilityCollectionResponse();
    List<BusinessObjectDataAvailability> businessObjectDataAvailabilityResponses = new ArrayList<>();
    businessObjectDataAvailabilityCollectionResponse.setBusinessObjectDataAvailabilityResponses(businessObjectDataAvailabilityResponses);
    boolean isAllDataAvailable = true;
    boolean isAllDataNotAvailable = true;
    for (BusinessObjectDataAvailabilityRequest request : businessObjectDataAvailabilityCollectionRequest.getBusinessObjectDataAvailabilityRequests()) {
        // Please note that when calling to process individual availability requests, we ask to skip the request validation and trimming step.
        BusinessObjectDataAvailability businessObjectDataAvailability = checkBusinessObjectDataAvailabilityImpl(request, true);
        businessObjectDataAvailabilityResponses.add(businessObjectDataAvailability);
        isAllDataAvailable = isAllDataAvailable && businessObjectDataAvailability.getNotAvailableStatuses().isEmpty();
        isAllDataNotAvailable = isAllDataNotAvailable && businessObjectDataAvailability.getAvailableStatuses().isEmpty();
    }
    businessObjectDataAvailabilityCollectionResponse.setIsAllDataAvailable(isAllDataAvailable);
    businessObjectDataAvailabilityCollectionResponse.setIsAllDataNotAvailable(isAllDataNotAvailable);
    return businessObjectDataAvailabilityCollectionResponse;
}
Also used : BusinessObjectDataAvailabilityRequest(org.finra.herd.model.api.xml.BusinessObjectDataAvailabilityRequest) BusinessObjectDataAvailability(org.finra.herd.model.api.xml.BusinessObjectDataAvailability) ArrayList(java.util.ArrayList) BusinessObjectDataAvailabilityCollectionResponse(org.finra.herd.model.api.xml.BusinessObjectDataAvailabilityCollectionResponse)

Example 5 with BusinessObjectDataAvailability

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

the class BusinessObjectDataServiceCheckBusinessObjectDataAvailabilityTest method testCheckBusinessObjectDataAvailabilityLargePartitionValueListPrimaryPartitionOnly.

@Test
public void testCheckBusinessObjectDataAvailabilityLargePartitionValueListPrimaryPartitionOnly() {
    final int PRIMARY_PARTITION_VALUES_SIZE = 10000;
    // Prepare test data.
    businessObjectDataAvailabilityTestHelper.createDatabaseEntitiesForBusinessObjectDataAvailabilityTesting(null);
    // Build and execute a business object data availability request with a large list of partition values.
    List<String> partitionValues = new ArrayList<>();
    for (int i = 0; i < PRIMARY_PARTITION_VALUES_SIZE; i++) {
        partitionValues.add(String.format("%s-%s", PARTITION_VALUE, i));
    }
    partitionValues.addAll(UNSORTED_PARTITION_VALUES);
    BusinessObjectDataAvailabilityRequest request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataAvailabilityRequest(partitionValues);
    BusinessObjectDataAvailability resultAvailability = businessObjectDataService.checkBusinessObjectDataAvailability(request);
    // Validate the results.
    assertNotNull(resultAvailability);
    assertEquals(STORAGE_1_AVAILABLE_PARTITION_VALUES.size(), resultAvailability.getAvailableStatuses().size());
    assertEquals(partitionValues.size() - STORAGE_1_AVAILABLE_PARTITION_VALUES.size(), resultAvailability.getNotAvailableStatuses().size());
}
Also used : BusinessObjectDataAvailabilityRequest(org.finra.herd.model.api.xml.BusinessObjectDataAvailabilityRequest) ArrayList(java.util.ArrayList) BusinessObjectDataAvailability(org.finra.herd.model.api.xml.BusinessObjectDataAvailability) Test(org.junit.Test)

Aggregations

BusinessObjectDataAvailability (org.finra.herd.model.api.xml.BusinessObjectDataAvailability)51 BusinessObjectDataAvailabilityRequest (org.finra.herd.model.api.xml.BusinessObjectDataAvailabilityRequest)48 Test (org.junit.Test)44 BusinessObjectDataStatus (org.finra.herd.model.api.xml.BusinessObjectDataStatus)42 PartitionValueFilter (org.finra.herd.model.api.xml.PartitionValueFilter)30 ArrayList (java.util.ArrayList)20 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)3 LatestAfterPartitionValue (org.finra.herd.model.api.xml.LatestAfterPartitionValue)3 LatestBeforePartitionValue (org.finra.herd.model.api.xml.LatestBeforePartitionValue)3 SchemaColumn (org.finra.herd.model.api.xml.SchemaColumn)3 BusinessObjectDataAvailabilityCollectionResponse (org.finra.herd.model.api.xml.BusinessObjectDataAvailabilityCollectionResponse)2 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)2 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)2 HashMap (java.util.HashMap)1 List (java.util.List)1 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)1 PartitionValueRange (org.finra.herd.model.api.xml.PartitionValueRange)1 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)1 StorageEntity (org.finra.herd.model.jpa.StorageEntity)1