Search in sources :

Example 81 with BusinessObjectDataKey

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

the class BusinessObjectDataFinalizeRestoreHelperServiceImpl method prepareToFinalizeRestoreImpl.

/**
 * Prepares for the business object data finalize restore by validating the S3 storage unit along with other related database entities. The method also
 * creates and returns a business object data restore DTO.
 *
 * @param storageUnitKey the storage unit key
 *
 * @return the DTO that holds various parameters needed to perform a business object data restore
 */
protected BusinessObjectDataRestoreDto prepareToFinalizeRestoreImpl(BusinessObjectDataStorageUnitKey storageUnitKey) {
    // Get the storage name.
    String storageName = storageUnitKey.getStorageName();
    // Get a business object data key.
    BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.createBusinessObjectDataKeyFromStorageUnitKey(storageUnitKey);
    // Retrieve the business object data and ensure it exists.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey);
    // Retrieve the storage unit and validate it.
    StorageUnitEntity storageUnitEntity = getStorageUnit(storageUnitKey.getStorageName(), businessObjectDataEntity);
    // Validate that S3 storage has S3 bucket name configured. Please note that since S3 bucket name attribute value is required we pass a "true" flag.
    String s3BucketName = storageHelper.getStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), storageUnitEntity.getStorage(), true);
    // Get storage specific S3 key prefix for this business object data.
    String s3KeyPrefix = s3KeyPrefixHelper.buildS3KeyPrefix(storageUnitEntity.getStorage(), businessObjectDataEntity.getBusinessObjectFormat(), businessObjectDataKey);
    // Retrieve and validate storage files registered with the storage unit.
    List<StorageFile> storageFiles = storageFileHelper.getAndValidateStorageFiles(storageUnitEntity, s3KeyPrefix, storageName, businessObjectDataKey);
    // Validate that this storage does not have any other registered storage files that
    // start with the S3 key prefix, but belong to other business object data instances.
    storageFileDaoHelper.validateStorageFilesCount(storageName, businessObjectDataKey, s3KeyPrefix, storageFiles.size());
    // Build the business object data restore parameters DTO.
    BusinessObjectDataRestoreDto businessObjectDataRestoreDto = new BusinessObjectDataRestoreDto();
    businessObjectDataRestoreDto.setBusinessObjectDataKey(businessObjectDataKey);
    businessObjectDataRestoreDto.setStorageName(storageName);
    businessObjectDataRestoreDto.setS3Endpoint(configurationHelper.getProperty(ConfigurationValue.S3_ENDPOINT));
    businessObjectDataRestoreDto.setS3BucketName(s3BucketName);
    businessObjectDataRestoreDto.setS3KeyPrefix(s3KeyPrefix);
    businessObjectDataRestoreDto.setStorageFiles(storageFiles);
    // Return the business object data restore parameters DTO.
    return businessObjectDataRestoreDto;
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StorageFile(org.finra.herd.model.api.xml.StorageFile) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectDataRestoreDto(org.finra.herd.model.dto.BusinessObjectDataRestoreDto)

Example 82 with BusinessObjectDataKey

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

use of org.finra.herd.model.api.xml.BusinessObjectDataKey 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;
}
Also used : BusinessObjectDataVersion(org.finra.herd.model.api.xml.BusinessObjectDataVersion) BusinessObjectDataVersions(org.finra.herd.model.api.xml.BusinessObjectDataVersions) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 84 with BusinessObjectDataKey

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

the class BusinessObjectDataStorageUnitServiceImpl method createBusinessObjectDataStorageUnitCreateResponse.

/**
 * Creates and populates a business object data storage unit create response.
 *
 * @param storageUnitEntity the storage unit entity
 *
 * @return the business object data storage unit create response
 */
protected BusinessObjectDataStorageUnitCreateResponse createBusinessObjectDataStorageUnitCreateResponse(StorageUnitEntity storageUnitEntity) {
    // Get business object data key from the business object data entity.
    BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper.createBusinessObjectDataKeyFromEntity(storageUnitEntity.getBusinessObjectData());
    // Create a business object data storage unit create response.
    BusinessObjectDataStorageUnitCreateResponse response = new BusinessObjectDataStorageUnitCreateResponse();
    // Add business object data storage unit key.
    response.setBusinessObjectDataStorageUnitKey(storageUnitHelper.createBusinessObjectDataStorageUnitKey(businessObjectDataKey, storageUnitEntity.getStorage().getName()));
    // Add storage directory.
    if (storageUnitEntity.getDirectoryPath() != null) {
        response.setStorageDirectory(new StorageDirectory(storageUnitEntity.getDirectoryPath()));
    }
    // Add storage files.
    if (CollectionUtils.isNotEmpty(storageUnitEntity.getStorageFiles())) {
        response.setStorageFiles(storageFileHelper.createStorageFilesFromEntities(storageUnitEntity.getStorageFiles()));
    }
    // Return the response.
    return response;
}
Also used : BusinessObjectDataStorageUnitCreateResponse(org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitCreateResponse) StorageDirectory(org.finra.herd.model.api.xml.StorageDirectory) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey)

Example 85 with BusinessObjectDataKey

use of org.finra.herd.model.api.xml.BusinessObjectDataKey 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);
}
Also used : BusinessObjectDataAttributeEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey)

Aggregations

BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)444 Test (org.junit.Test)378 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)138 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)93 ArrayList (java.util.ArrayList)92 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)78 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)62 StoragePolicyKey (org.finra.herd.model.api.xml.StoragePolicyKey)50 HashMap (java.util.HashMap)43 StorageFile (org.finra.herd.model.api.xml.StorageFile)38 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)36 BusinessObjectDataStorageUnitKey (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey)33 Attribute (org.finra.herd.model.api.xml.Attribute)32 NotificationMessageDefinitions (org.finra.herd.model.api.xml.NotificationMessageDefinitions)32 StoragePolicySelection (org.finra.herd.model.dto.StoragePolicySelection)32 ConfigurationEntity (org.finra.herd.model.jpa.ConfigurationEntity)32 NotificationMessageDefinition (org.finra.herd.model.api.xml.NotificationMessageDefinition)30 Parameter (org.finra.herd.model.api.xml.Parameter)30 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)29 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)29