use of org.finra.herd.model.jpa.BusinessObjectDataEntity 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.jpa.BusinessObjectDataEntity in project herd by FINRAOS.
the class BusinessObjectDataServiceImpl method getBusinessObjectDataVersions.
@NamespacePermission(fields = "#businessObjectDataKey.namespace", permissions = NamespacePermissionEnum.READ)
@Override
public BusinessObjectDataVersions getBusinessObjectDataVersions(BusinessObjectDataKey businessObjectDataKey) {
// Validate and trim the business object data key.
businessObjectDataHelper.validateBusinessObjectDataKey(businessObjectDataKey, false, false);
// Get the business object data versions based on the specified parameters.
List<BusinessObjectDataEntity> businessObjectDataEntities = businessObjectDataDao.getBusinessObjectDataEntities(businessObjectDataKey);
// Create the response.
BusinessObjectDataVersions businessObjectDataVersions = new BusinessObjectDataVersions();
for (BusinessObjectDataEntity businessObjectDataEntity : businessObjectDataEntities) {
BusinessObjectDataVersion businessObjectDataVersion = new BusinessObjectDataVersion();
BusinessObjectDataKey businessObjectDataVersionKey = businessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataEntity);
businessObjectDataVersion.setBusinessObjectDataKey(businessObjectDataVersionKey);
businessObjectDataVersion.setStatus(businessObjectDataEntity.getStatus().getCode());
businessObjectDataVersions.getBusinessObjectDataVersions().add(businessObjectDataVersion);
}
return businessObjectDataVersions;
}
use of org.finra.herd.model.jpa.BusinessObjectDataEntity in project herd by FINRAOS.
the class BusinessObjectDataServiceImpl method updateBusinessObjectDataAttributes.
@NamespacePermission(fields = "#businessObjectDataKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public BusinessObjectData updateBusinessObjectDataAttributes(BusinessObjectDataKey businessObjectDataKey, BusinessObjectDataAttributesUpdateRequest businessObjectDataAttributesUpdateRequest) {
// Validate and trim the business object data key.
businessObjectDataHelper.validateBusinessObjectDataKey(businessObjectDataKey, true, true);
// Validate the update request.
Assert.notNull(businessObjectDataAttributesUpdateRequest, "A business object data attributes update request must be specified.");
Assert.notNull(businessObjectDataAttributesUpdateRequest.getAttributes(), "A list of business object data attributes must be specified.");
List<Attribute> attributes = businessObjectDataAttributesUpdateRequest.getAttributes();
// Validate attributes. This is also going to trim the attribute names.
attributeHelper.validateAttributes(attributes);
// Retrieve the business object data and ensure it exists.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey);
// Validate attributes against attribute definitions.
attributeDaoHelper.validateAttributesAgainstBusinessObjectDataAttributeDefinitions(attributes, businessObjectDataEntity.getBusinessObjectFormat().getAttributeDefinitions());
// Update the attributes.
attributeDaoHelper.updateBusinessObjectDataAttributes(businessObjectDataEntity, attributes);
// Persist and refresh the entity.
businessObjectDataEntity = businessObjectDataDao.saveAndRefresh(businessObjectDataEntity);
// Create and return the business object data object from the persisted entity.
return businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity);
}
use of org.finra.herd.model.jpa.BusinessObjectDataEntity in project herd by FINRAOS.
the class BusinessObjectDataStorageUnitServiceImpl method createBusinessObjectDataStorageUnitImpl.
/**
* Creates new storage unit for a given business object data and storage.
*
* @param request the create business object data storage unit create request
*
* @return the create business object data storage unit create response
*/
protected BusinessObjectDataStorageUnitCreateResponse createBusinessObjectDataStorageUnitImpl(BusinessObjectDataStorageUnitCreateRequest request) {
// Validate the request.
validateBusinessObjectDataStorageUnitCreateRequest(request);
// Retrieve and validate that business object data exists.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(storageUnitHelper.getBusinessObjectDataKey(request.getBusinessObjectDataStorageUnitKey()));
// Retrieve and validate that storage exists.
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(request.getBusinessObjectDataStorageUnitKey().getStorageName());
// Create a storage unit entity.
StorageUnitEntity storageUnitEntity = businessObjectDataDaoHelper.createStorageUnitEntity(businessObjectDataEntity, storageEntity, request.getStorageDirectory(), request.getStorageFiles(), request.isDiscoverStorageFiles());
// Persist the newly created storage unit entity.
storageUnitDao.saveAndRefresh(storageUnitEntity);
// Construct and return the response.
return createBusinessObjectDataStorageUnitCreateResponse(storageUnitEntity);
}
use of org.finra.herd.model.jpa.BusinessObjectDataEntity 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);
}
Aggregations