use of org.finra.herd.model.api.xml.BusinessObjectFormatKey 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;
}
use of org.finra.herd.model.api.xml.BusinessObjectFormatKey in project herd by FINRAOS.
the class BusinessObjectDataAttributeServiceImpl method updateBusinessObjectDataAttributeImpl.
/**
* Updates an existing business object data attribute by key.
*
* @param businessObjectDataAttributeKey the business object data attribute key
* @param request the information needed to update a business object data attribute
*
* @return the business object data attribute information
*/
protected BusinessObjectDataAttribute updateBusinessObjectDataAttributeImpl(BusinessObjectDataAttributeKey businessObjectDataAttributeKey, BusinessObjectDataAttributeUpdateRequest request) {
// Validate and trim the key.
businessObjectDataAttributeHelper.validateBusinessObjectDataAttributeKey(businessObjectDataAttributeKey);
// Get the business object format and ensure it exists.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(new BusinessObjectFormatKey(businessObjectDataAttributeKey.getNamespace(), businessObjectDataAttributeKey.getBusinessObjectDefinitionName(), businessObjectDataAttributeKey.getBusinessObjectFormatUsage(), businessObjectDataAttributeKey.getBusinessObjectFormatFileType(), businessObjectDataAttributeKey.getBusinessObjectFormatVersion()));
// Validate the attribute value.
if (businessObjectDataAttributeHelper.isBusinessObjectDataAttributeRequired(businessObjectDataAttributeKey.getBusinessObjectDataAttributeName(), businessObjectFormatEntity)) {
Assert.hasText(request.getBusinessObjectDataAttributeValue(), String.format("A business object data attribute value must be specified since \"%s\" is a required attribute for business object format {%s}.", businessObjectDataAttributeKey.getBusinessObjectDataAttributeName(), businessObjectFormatHelper.businessObjectFormatEntityAltKeyToString(businessObjectFormatEntity)));
}
// Retrieve and ensure that a business object data attribute exists with the specified key.
BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = businessObjectDataAttributeDaoHelper.getBusinessObjectDataAttributeEntity(businessObjectDataAttributeKey);
// Update the entity with the new values.
businessObjectDataAttributeEntity.setValue(request.getBusinessObjectDataAttributeValue());
// Persist the entity.
businessObjectDataAttributeEntity = businessObjectDataAttributeDao.saveAndRefresh(businessObjectDataAttributeEntity);
// Create and return the business object data attribute object from the persisted entity.
return createBusinessObjectDataAttributeFromEntity(businessObjectDataAttributeEntity);
}
use of org.finra.herd.model.api.xml.BusinessObjectFormatKey in project herd by FINRAOS.
the class BusinessObjectDataAttributeServiceImpl method deleteBusinessObjectDataAttributeImpl.
/**
* Deletes an existing business object data attribute by key.
*
* @param businessObjectDataAttributeKey the business object data attribute key
*
* @return the business object data attribute information for the attribute that got deleted
*/
protected BusinessObjectDataAttribute deleteBusinessObjectDataAttributeImpl(BusinessObjectDataAttributeKey businessObjectDataAttributeKey) {
// Validate and trim the key.
businessObjectDataAttributeHelper.validateBusinessObjectDataAttributeKey(businessObjectDataAttributeKey);
// Get the business object format and ensure it exists.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(new BusinessObjectFormatKey(businessObjectDataAttributeKey.getNamespace(), businessObjectDataAttributeKey.getBusinessObjectDefinitionName(), businessObjectDataAttributeKey.getBusinessObjectFormatUsage(), businessObjectDataAttributeKey.getBusinessObjectFormatFileType(), businessObjectDataAttributeKey.getBusinessObjectFormatVersion()));
// Make sure we are not trying to delete a required attribute.
if (businessObjectDataAttributeHelper.isBusinessObjectDataAttributeRequired(businessObjectDataAttributeKey.getBusinessObjectDataAttributeName(), businessObjectFormatEntity)) {
throw new IllegalArgumentException(String.format("Cannot delete \"%s\" attribute since it is a required attribute for business object format {%s}.", businessObjectDataAttributeKey.getBusinessObjectDataAttributeName(), businessObjectFormatHelper.businessObjectFormatEntityAltKeyToString(businessObjectFormatEntity)));
}
// Retrieve and ensure that a business object data attribute exists with the specified key.
BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = businessObjectDataAttributeDaoHelper.getBusinessObjectDataAttributeEntity(businessObjectDataAttributeKey);
// Delete the business object data attribute.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataAttributeEntity.getBusinessObjectData();
businessObjectDataEntity.getAttributes().remove(businessObjectDataAttributeEntity);
businessObjectDataDao.saveAndRefresh(businessObjectDataEntity);
// Create and return the business object data attribute object from the deleted entity.
return createBusinessObjectDataAttributeFromEntity(businessObjectDataAttributeEntity);
}
use of org.finra.herd.model.api.xml.BusinessObjectFormatKey in project herd by FINRAOS.
the class BusinessObjectDataAttributeServiceImpl method createBusinessObjectDataAttributeImpl.
/**
* Creates a new business object data attribute.
*
* @param request the information needed to create a business object data attribute
*
* @return the newly created business object data attribute
*/
protected BusinessObjectDataAttribute createBusinessObjectDataAttributeImpl(BusinessObjectDataAttributeCreateRequest request) {
// Validate and trim the key.
businessObjectDataAttributeHelper.validateBusinessObjectDataAttributeKey(request.getBusinessObjectDataAttributeKey());
// Get the business object format and ensure it exists.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(new BusinessObjectFormatKey(request.getBusinessObjectDataAttributeKey().getNamespace(), request.getBusinessObjectDataAttributeKey().getBusinessObjectDefinitionName(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatUsage(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatFileType(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatVersion()));
// Validate the attribute value.
if (businessObjectDataAttributeHelper.isBusinessObjectDataAttributeRequired(request.getBusinessObjectDataAttributeKey().getBusinessObjectDataAttributeName(), businessObjectFormatEntity)) {
Assert.hasText(request.getBusinessObjectDataAttributeValue(), String.format("A business object data attribute value must be specified since \"%s\" is a required attribute for business object format {%s}.", request.getBusinessObjectDataAttributeKey().getBusinessObjectDataAttributeName(), businessObjectFormatHelper.businessObjectFormatEntityAltKeyToString(businessObjectFormatEntity)));
}
// Get the business object data and ensure it exists.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(new BusinessObjectDataKey(request.getBusinessObjectDataAttributeKey().getNamespace(), request.getBusinessObjectDataAttributeKey().getBusinessObjectDefinitionName(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatUsage(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatFileType(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatVersion(), request.getBusinessObjectDataAttributeKey().getPartitionValue(), request.getBusinessObjectDataAttributeKey().getSubPartitionValues(), request.getBusinessObjectDataAttributeKey().getBusinessObjectDataVersion()));
// Load all existing business object data attribute entities into a map for quick access using lowercase attribute names.
Map<String, BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntityMap = businessObjectDataAttributeDaoHelper.getBusinessObjectDataAttributeEntityMap(businessObjectDataEntity.getAttributes());
// Ensure a business object data attribute with the specified name doesn't already exist for the specified business object data.
if (businessObjectDataAttributeEntityMap.containsKey(request.getBusinessObjectDataAttributeKey().getBusinessObjectDataAttributeName().toLowerCase())) {
throw new AlreadyExistsException(String.format("Unable to create business object data attribute with name \"%s\" because it already exists for the business object data {%s}.", request.getBusinessObjectDataAttributeKey().getBusinessObjectDataAttributeName(), businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)));
}
// Create a business object data attribute entity from the request information.
BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = createBusinessObjectDataAttributeEntity(businessObjectDataEntity, request);
// Persist the new entity.
businessObjectDataAttributeEntity = businessObjectDataAttributeDao.saveAndRefresh(businessObjectDataAttributeEntity);
// Create and return the business object data attribute object from the persisted entity.
return createBusinessObjectDataAttributeFromEntity(businessObjectDataAttributeEntity);
}
use of org.finra.herd.model.api.xml.BusinessObjectFormatKey in project herd by FINRAOS.
the class StorageUnitDaoTest method testGetStorageUnitsByPartitionFiltersAndStoragesNotEnabledStorageUnitStatus.
@Test
public void testGetStorageUnitsByPartitionFiltersAndStoragesNotEnabledStorageUnitStatus() {
// Create enabled and disabled storage units for different partition values.
StorageUnitEntity enabledStorageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BDATA_STATUS, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
StorageUnitEntity disabledStorageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE_2, NO_SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BDATA_STATUS, StorageUnitStatusEntity.DISABLED, NO_STORAGE_DIRECTORY_PATH);
// Build a list of partition filters to select business object data.
List<List<String>> partitionFilters = new ArrayList<>();
for (String partitionValue : Arrays.asList(PARTITION_VALUE, PARTITION_VALUE_2)) {
partitionFilters.add(Arrays.asList(partitionValue, null, null, null, null));
}
// Retrieve "available" storage units per specified parameters.
List<StorageUnitEntity> resultStorageUnitEntities = storageUnitDao.getStorageUnitsByPartitionFiltersAndStorages(new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION), partitionFilters, DATA_VERSION, null, Collections.singletonList(STORAGE_NAME), null, null, SELECT_ONLY_AVAILABLE_STORAGE_UNITS);
// Validate the results.
assertEquals(Collections.singletonList(enabledStorageUnitEntity), resultStorageUnitEntities);
// Retrieve "available" storage units without specifying
// a business object format version, which is an optional parameter.
resultStorageUnitEntities = storageUnitDao.getStorageUnitsByPartitionFiltersAndStorages(new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, null), partitionFilters, DATA_VERSION, null, Collections.singletonList(STORAGE_NAME), null, null, SELECT_ONLY_AVAILABLE_STORAGE_UNITS);
// Validate the results.
assertEquals(Collections.singletonList(enabledStorageUnitEntity), resultStorageUnitEntities);
// Retrieve storage units regardless of storage unit status per specified parameters.
resultStorageUnitEntities = storageUnitDao.getStorageUnitsByPartitionFiltersAndStorages(new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION), partitionFilters, DATA_VERSION, null, Collections.singletonList(STORAGE_NAME), null, null, NO_SELECT_ONLY_AVAILABLE_STORAGE_UNITS);
// Validate the results.
assertEquals(Arrays.asList(enabledStorageUnitEntity, disabledStorageUnitEntity), resultStorageUnitEntities);
// Retrieve storage units regardless of storage unit status without specifying
// a business object format version, which is an optional parameter.
resultStorageUnitEntities = storageUnitDao.getStorageUnitsByPartitionFiltersAndStorages(new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, null), partitionFilters, DATA_VERSION, null, Collections.singletonList(STORAGE_NAME), null, null, NO_SELECT_ONLY_AVAILABLE_STORAGE_UNITS);
// Validate the results.
assertEquals(Arrays.asList(enabledStorageUnitEntity, disabledStorageUnitEntity), resultStorageUnitEntities);
}
Aggregations