Search in sources :

Example 1 with BusinessObjectDataStatus

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

the class BusinessObjectDataServiceImpl method createNotAvailableBusinessObjectDataStatus.

/**
 * Creates a business object data status instance from the storage unit entity.
 *
 * @param storageUnitEntity the storage unit entity
 *
 * @return the business object data status instance
 */
private BusinessObjectDataStatus createNotAvailableBusinessObjectDataStatus(StorageUnitEntity storageUnitEntity) {
    // Get the business object entity.
    BusinessObjectDataEntity businessObjectDataEntity = storageUnitEntity.getBusinessObjectData();
    // Create and populate the business object data status instance.
    BusinessObjectDataStatus businessObjectDataStatus = new BusinessObjectDataStatus();
    businessObjectDataStatus.setBusinessObjectFormatVersion(businessObjectDataEntity.getBusinessObjectFormat().getBusinessObjectFormatVersion());
    businessObjectDataStatus.setPartitionValue(businessObjectDataEntity.getPartitionValue());
    businessObjectDataStatus.setSubPartitionValues(businessObjectDataHelper.getSubPartitionValues(businessObjectDataEntity));
    businessObjectDataStatus.setBusinessObjectDataVersion(businessObjectDataEntity.getVersion());
    // If storage unit is "available", the business object data is selected as "non-available" due to its business object data status.
    if (storageUnitEntity.getStatus().getAvailable()) {
        businessObjectDataStatus.setReason(businessObjectDataEntity.getStatus().getCode());
    } else // Otherwise, report the storage unit status as a reason for the business object data not being available.
    {
        businessObjectDataStatus.setReason(storageUnitEntity.getStatus().getCode());
    }
    return businessObjectDataStatus;
}
Also used : BusinessObjectDataStatus(org.finra.herd.model.api.xml.BusinessObjectDataStatus) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity)

Example 2 with BusinessObjectDataStatus

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

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

the class BusinessObjectDataServiceImpl method createNotAvailableBusinessObjectDataStatus.

/**
 * Creates the business object data status.
 *
 * @param businessObjectDataAvailabilityRequest the business object data availability request
 * @param unmatchedPartitionFilter the partition filter that got no matched business object data instances
 * @param reason the reason for the business object data not being available
 *
 * @return the business object data status
 */
private BusinessObjectDataStatus createNotAvailableBusinessObjectDataStatus(BusinessObjectDataAvailabilityRequest businessObjectDataAvailabilityRequest, List<String> unmatchedPartitionFilter, String reason) {
    BusinessObjectDataStatus businessObjectDataStatus = new BusinessObjectDataStatus();
    // Populate business object data status values using the business object data availability request.
    businessObjectDataStatus.setBusinessObjectFormatVersion(businessObjectDataAvailabilityRequest.getBusinessObjectFormatVersion());
    // When list of partition value filters is used, we populate primary and/or sub-partition values.
    if (businessObjectDataAvailabilityRequest.getPartitionValueFilters() != null) {
        // Replace all null partition values with an empty string.
        replaceAllNullsWithEmptyString(unmatchedPartitionFilter);
        // Populate primary and sub-partition values from the unmatched partition filter.
        businessObjectDataStatus.setPartitionValue(unmatchedPartitionFilter.get(0));
        businessObjectDataStatus.setSubPartitionValues(unmatchedPartitionFilter.subList(1, unmatchedPartitionFilter.size()));
    } else // Otherwise, for backwards compatibility, populate primary partition value only per expected single partition value from the unmatched filter.
    {
        // the unmatched partition filter is expected to contain only a single partition value.
        for (String partitionValue : unmatchedPartitionFilter) {
            if (partitionValue != null) {
                businessObjectDataStatus.setPartitionValue(partitionValue);
                break;
            }
        }
    }
    businessObjectDataStatus.setBusinessObjectDataVersion(businessObjectDataAvailabilityRequest.getBusinessObjectDataVersion());
    businessObjectDataStatus.setReason(reason);
    return businessObjectDataStatus;
}
Also used : BusinessObjectDataStatus(org.finra.herd.model.api.xml.BusinessObjectDataStatus)

Example 4 with BusinessObjectDataStatus

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

the class BusinessObjectDataServiceCheckBusinessObjectDataAvailabilityTest method testCheckBusinessObjectDataAvailabilityIncludeAllRegisteredSubPartitionsSecondSubPartitionValidNonAvailableStorageUnit.

@Test
public void testCheckBusinessObjectDataAvailabilityIncludeAllRegisteredSubPartitionsSecondSubPartitionValidNonAvailableStorageUnit() {
    // Create two VALID sub-partitions - the first with an "available" storage unit and the second with a "non-available" storage unit.
    storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, Arrays.asList(SUB_PARTITION_VALUE_1), DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.VALID, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
    storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, Arrays.asList(SUB_PARTITION_VALUE_2), DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.VALID, StorageUnitStatusEntity.DISABLED, NO_STORAGE_DIRECTORY_PATH);
    // Check this business object data availability with "IncludeAllRegisteredSubPartitions" option enabled.
    BusinessObjectDataAvailability result = businessObjectDataService.checkBusinessObjectDataAvailability(new BusinessObjectDataAvailabilityRequest(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, Arrays.asList(new PartitionValueFilter(PARTITION_KEY, Arrays.asList(PARTITION_VALUE), NO_PARTITION_VALUE_RANGE, NO_LATEST_BEFORE_PARTITION_VALUE, NO_LATEST_AFTER_PARTITION_VALUE)), NO_STANDALONE_PARTITION_VALUE_FILTER, NO_DATA_VERSION, NO_STORAGE_NAMES, STORAGE_NAME, INCLUDE_ALL_REGISTERED_SUBPARTITIONS));
    // Validate the response object.
    // Both sub-partitions should be listed - the first as VALID "available" and the second as NO_ENABLED_STORAGE_UNIT "non-available".
    assertEquals(new BusinessObjectDataAvailability(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, Arrays.asList(new PartitionValueFilter(PARTITION_KEY, Arrays.asList(PARTITION_VALUE), NO_PARTITION_VALUE_RANGE, NO_LATEST_BEFORE_PARTITION_VALUE, NO_LATEST_AFTER_PARTITION_VALUE)), NO_STANDALONE_PARTITION_VALUE_FILTER, NO_DATA_VERSION, NO_STORAGE_NAMES, STORAGE_NAME, Arrays.asList(new BusinessObjectDataStatus(FORMAT_VERSION, PARTITION_VALUE, Arrays.asList(SUB_PARTITION_VALUE_1), DATA_VERSION, BusinessObjectDataStatusEntity.VALID)), Arrays.asList(new BusinessObjectDataStatus(FORMAT_VERSION, PARTITION_VALUE, Arrays.asList(SUB_PARTITION_VALUE_2), DATA_VERSION, StorageUnitStatusEntity.DISABLED))), result);
}
Also used : BusinessObjectDataAvailabilityRequest(org.finra.herd.model.api.xml.BusinessObjectDataAvailabilityRequest) BusinessObjectDataAvailability(org.finra.herd.model.api.xml.BusinessObjectDataAvailability) BusinessObjectDataStatus(org.finra.herd.model.api.xml.BusinessObjectDataStatus) PartitionValueFilter(org.finra.herd.model.api.xml.PartitionValueFilter) Test(org.junit.Test)

Example 5 with BusinessObjectDataStatus

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

the class BusinessObjectDataServiceCheckBusinessObjectDataAvailabilityTest method runCheckBusinessObjectDataAvailabilityPartitionValueListPartitionValueTokenCaseSensitivityTest.

private void runCheckBusinessObjectDataAvailabilityPartitionValueListPartitionValueTokenCaseSensitivityTest(boolean useMaxPartitionValueToken, boolean isUpperCase) {
    // Prepare test data.
    businessObjectDataAvailabilityTestHelper.createDatabaseEntitiesForBusinessObjectDataAvailabilityTesting(null);
    // Check business object data availability using maximum or minimum partition value token with business
    // object format alternate key parameters in upper or lower case as per specified input parameters.
    BusinessObjectDataAvailabilityRequest request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataAvailabilityRequest(null);
    List<PartitionValueFilter> partitionValueFilters = new ArrayList<>();
    request.setPartitionValueFilters(partitionValueFilters);
    partitionValueFilters.add(new PartitionValueFilter(FIRST_PARTITION_COLUMN_NAME, Arrays.asList(useMaxPartitionValueToken ? BusinessObjectDataService.MAX_PARTITION_VALUE_TOKEN : BusinessObjectDataService.MIN_PARTITION_VALUE_TOKEN), NO_PARTITION_VALUE_RANGE, NO_LATEST_BEFORE_PARTITION_VALUE, NO_LATEST_AFTER_PARTITION_VALUE));
    request.setNamespace(isUpperCase ? NAMESPACE.toUpperCase() : NAMESPACE.toLowerCase());
    request.setBusinessObjectDefinitionName(isUpperCase ? BDEF_NAME.toUpperCase() : BDEF_NAME.toLowerCase());
    request.setBusinessObjectFormatUsage(isUpperCase ? FORMAT_USAGE_CODE.toUpperCase() : FORMAT_USAGE_CODE.toLowerCase());
    request.setBusinessObjectFormatFileType(isUpperCase ? FORMAT_FILE_TYPE_CODE.toUpperCase() : FORMAT_FILE_TYPE_CODE.toLowerCase());
    BusinessObjectDataAvailability resultAvailability = businessObjectDataService.checkBusinessObjectDataAvailability(request);
    // Validate the results.
    List<BusinessObjectDataStatus> expectedAvailableStatuses = businessObjectDataServiceTestHelper.getTestBusinessObjectDataStatuses(FORMAT_VERSION, BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, Arrays.asList(useMaxPartitionValueToken ? STORAGE_1_GREATEST_PARTITION_VALUE : STORAGE_1_LEAST_PARTITION_VALUE), NO_SUBPARTITION_VALUES, DATA_VERSION, BusinessObjectDataStatusEntity.VALID, false);
    List<BusinessObjectDataStatus> expectedNotAvailableStatuses = new ArrayList<>();
    businessObjectDataServiceTestHelper.validateBusinessObjectDataAvailability(request, expectedAvailableStatuses, expectedNotAvailableStatuses, resultAvailability);
}
Also used : BusinessObjectDataAvailabilityRequest(org.finra.herd.model.api.xml.BusinessObjectDataAvailabilityRequest) ArrayList(java.util.ArrayList) BusinessObjectDataAvailability(org.finra.herd.model.api.xml.BusinessObjectDataAvailability) BusinessObjectDataStatus(org.finra.herd.model.api.xml.BusinessObjectDataStatus) PartitionValueFilter(org.finra.herd.model.api.xml.PartitionValueFilter)

Aggregations

BusinessObjectDataStatus (org.finra.herd.model.api.xml.BusinessObjectDataStatus)46 BusinessObjectDataAvailability (org.finra.herd.model.api.xml.BusinessObjectDataAvailability)42 BusinessObjectDataAvailabilityRequest (org.finra.herd.model.api.xml.BusinessObjectDataAvailabilityRequest)40 Test (org.junit.Test)39 PartitionValueFilter (org.finra.herd.model.api.xml.PartitionValueFilter)27 ArrayList (java.util.ArrayList)18 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 List (java.util.List)2 SchemaColumn (org.finra.herd.model.api.xml.SchemaColumn)2 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)2 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)2 HashMap (java.util.HashMap)1 BusinessObjectDataAvailabilityCollectionResponse (org.finra.herd.model.api.xml.BusinessObjectDataAvailabilityCollectionResponse)1 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)1 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)1