use of org.finra.herd.model.api.xml.StorageUnitCreateRequest in project herd by FINRAOS.
the class BusinessObjectDataDaoHelper method validateBusinessObjectDataCreateRequest.
/**
* Validates the business object data create request. This method also trims appropriate request parameters.
*
* @param request the request
* @param fileSizeRequired specifies if fileSizeBytes value is required or not
* @param businessObjectDataStatusEntity The status entity in the request
*
* @throws IllegalArgumentException if any validation errors were found.
*/
private void validateBusinessObjectDataCreateRequest(BusinessObjectDataCreateRequest request, boolean fileSizeRequired, BusinessObjectDataStatusEntity businessObjectDataStatusEntity) {
// Validate and trim the request parameters.
request.setNamespace(alternateKeyHelper.validateStringParameter("namespace", request.getNamespace()));
request.setBusinessObjectDefinitionName(alternateKeyHelper.validateStringParameter("business object definition name", request.getBusinessObjectDefinitionName()));
request.setBusinessObjectFormatUsage(alternateKeyHelper.validateStringParameter("business object format usage", request.getBusinessObjectFormatUsage()));
request.setBusinessObjectFormatFileType(alternateKeyHelper.validateStringParameter("business object format file type", request.getBusinessObjectFormatFileType()));
Assert.notNull(request.getBusinessObjectFormatVersion(), "A business object format version must be specified.");
request.setPartitionKey(alternateKeyHelper.validateStringParameter("partition key", request.getPartitionKey()));
request.setPartitionValue(alternateKeyHelper.validateStringParameter("partition value", request.getPartitionValue()));
businessObjectDataHelper.validateSubPartitionValues(request.getSubPartitionValues());
Assert.isTrue(CollectionUtils.isNotEmpty(request.getStorageUnits()), "At least one storage unit must be specified.");
for (StorageUnitCreateRequest storageUnit : request.getStorageUnits()) {
Assert.notNull(storageUnit, "A storage unit can't be null.");
// Validate and trim the storage name.
Assert.hasText(storageUnit.getStorageName(), "A storage name is required for each storage unit.");
storageUnit.setStorageName(storageUnit.getStorageName().trim());
if (BooleanUtils.isTrue(storageUnit.isDiscoverStorageFiles())) {
// The auto-discovery of storage files is enabled, thus a storage directory is required and storage files cannot be specified.
Assert.isTrue(storageUnit.getStorageDirectory() != null, "A storage directory must be specified when discovery of storage files is enabled.");
Assert.isTrue(CollectionUtils.isEmpty(storageUnit.getStorageFiles()), "Storage files cannot be specified when discovery of storage files is enabled.");
} else if (!Boolean.TRUE.equals(businessObjectDataStatusEntity.getPreRegistrationStatus())) {
// Since auto-discovery is disabled, a storage directory or at least one storage file are required for each storage unit.
Assert.isTrue(storageUnit.getStorageDirectory() != null || CollectionUtils.isNotEmpty(storageUnit.getStorageFiles()), "A storage directory or at least one storage file must be specified for each storage unit.");
}
// If storageDirectory element is present in the request, we require it to contain a non-empty directoryPath element.
if (storageUnit.getStorageDirectory() != null) {
Assert.hasText(storageUnit.getStorageDirectory().getDirectoryPath(), "A storage directory path must be specified.");
storageUnit.getStorageDirectory().setDirectoryPath(storageUnit.getStorageDirectory().getDirectoryPath().trim());
}
if (CollectionUtils.isNotEmpty(storageUnit.getStorageFiles())) {
for (StorageFile storageFile : storageUnit.getStorageFiles()) {
Assert.hasText(storageFile.getFilePath(), "A file path must be specified.");
storageFile.setFilePath(storageFile.getFilePath().trim());
if (fileSizeRequired) {
Assert.notNull(storageFile.getFileSizeBytes(), "A file size must be specified.");
}
// Ensure row count is not negative.
if (storageFile.getRowCount() != null) {
Assert.isTrue(storageFile.getRowCount() >= 0, "File \"" + storageFile.getFilePath() + "\" has a row count which is < 0.");
}
}
}
}
// Validate and trim the parents' keys.
validateBusinessObjectDataKeys(request.getBusinessObjectDataParents());
// Validate attributes.
attributeHelper.validateAttributes(request.getAttributes());
}
use of org.finra.herd.model.api.xml.StorageUnitCreateRequest in project herd by FINRAOS.
the class BusinessObjectDataDaoHelper method createStorageUnitEntitiesFromStorageUnits.
/**
* Creates a list of storage unit entities from a list of storage unit create requests.
*
* @param storageUnitCreateRequests the storage unit create requests
* @param businessObjectDataEntity the business object data entity
*
* @return the list of storage unit entities.
*/
private List<StorageUnitEntity> createStorageUnitEntitiesFromStorageUnits(List<StorageUnitCreateRequest> storageUnitCreateRequests, BusinessObjectDataEntity businessObjectDataEntity) {
// Create the storage units for the data.
List<StorageUnitEntity> storageUnitEntities = new ArrayList<>();
for (StorageUnitCreateRequest storageUnit : storageUnitCreateRequests) {
// Get the storage entity per request and verify that it exists.
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(storageUnit.getStorageName());
// Create storage unit and add it to the result list.
storageUnitEntities.add(createStorageUnitEntity(businessObjectDataEntity, storageEntity, storageUnit.getStorageDirectory(), storageUnit.getStorageFiles(), storageUnit.isDiscoverStorageFiles()));
}
return storageUnitEntities;
}
use of org.finra.herd.model.api.xml.StorageUnitCreateRequest in project herd by FINRAOS.
the class BusinessObjectDataServiceCreateBusinessObjectDataTest method testCreateBusinessObjectDataDiscoverStorageFilesStorageFilesSpecified.
@Test
public void testCreateBusinessObjectDataDiscoverStorageFilesStorageFilesSpecified() {
// Try to create an initial version of the business object data when discovery of storage files is enabled and storage files are specified.
try {
businessObjectDataService.createBusinessObjectData(new BusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, NO_SUBPARTITION_VALUES, BusinessObjectDataStatusEntity.VALID, Arrays.asList(new StorageUnitCreateRequest(STORAGE_NAME, new StorageDirectory(STORAGE_DIRECTORY_PATH), Arrays.asList(new StorageFile(LOCAL_FILE, FILE_SIZE_1_KB, ROW_COUNT_1000)), DISCOVER_STORAGE_FILES)), NO_ATTRIBUTES, NO_BUSINESS_OBJECT_DATA_PARENTS, NO_CREATE_NEW_VERSION));
fail("Should throw an IllegalArgumentException when discovery of storage files is enabled and storage files are specified.");
} catch (IllegalArgumentException e) {
assertEquals("Storage files cannot be specified when discovery of storage files is enabled.", e.getMessage());
}
}
use of org.finra.herd.model.api.xml.StorageUnitCreateRequest in project herd by FINRAOS.
the class BusinessObjectDataServiceCreateBusinessObjectDataTest method testCreateBusinessObjectDataDiscoverStorageFilesInvalidStoragePlatform.
@Test
public void testCreateBusinessObjectDataDiscoverStorageFilesInvalidStoragePlatform() {
// Create a business object format entity.
businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, FORMAT_DESCRIPTION, LATEST_VERSION_FLAG_SET, PARTITION_KEY);
// Create a business object data status entity.
businessObjectDataStatusDaoTestHelper.createBusinessObjectDataStatusEntity(BDATA_STATUS);
// Create a non-S3 storage entity with a bucket name attribute.
storageDaoTestHelper.createStorageEntity(STORAGE_NAME, STORAGE_PLATFORM_CODE, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), S3_BUCKET_NAME);
// Try to create an initial version of the business object data when storage platform is not supported for discovery of storage files.
try {
businessObjectDataService.createBusinessObjectData(new BusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, NO_SUBPARTITION_VALUES, BDATA_STATUS, Arrays.asList(new StorageUnitCreateRequest(STORAGE_NAME, new StorageDirectory(testS3KeyPrefix), NO_STORAGE_FILES, DISCOVER_STORAGE_FILES)), NO_ATTRIBUTES, NO_BUSINESS_OBJECT_DATA_PARENTS, NO_CREATE_NEW_VERSION));
fail("Should throw an IllegalArgumentException when storage platform is not supported for discovery of storage files.");
} catch (IllegalArgumentException e) {
assertEquals(String.format("Cannot discover storage files at \"%s\" storage platform.", STORAGE_PLATFORM_CODE), e.getMessage());
}
}
use of org.finra.herd.model.api.xml.StorageUnitCreateRequest in project herd by FINRAOS.
the class BusinessObjectDataServiceCreateBusinessObjectDataTest method testCreateBusinessObjectDataDiscoverStorageFilesNoS3FilesExist.
@Test
public void testCreateBusinessObjectDataDiscoverStorageFilesNoS3FilesExist() {
// Create a business object format entity.
businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, FORMAT_DESCRIPTION, LATEST_VERSION_FLAG_SET, PARTITION_KEY);
// Create a business object data status entity.
businessObjectDataStatusDaoTestHelper.createBusinessObjectDataStatusEntity(BDATA_STATUS);
// Try to create an initial version of the business object data when there are no files in S3 to discover.
try {
businessObjectDataService.createBusinessObjectData(new BusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, NO_SUBPARTITION_VALUES, BDATA_STATUS, Arrays.asList(new StorageUnitCreateRequest(StorageEntity.MANAGED_STORAGE, new StorageDirectory(testS3KeyPrefix), NO_STORAGE_FILES, DISCOVER_STORAGE_FILES)), NO_ATTRIBUTES, NO_BUSINESS_OBJECT_DATA_PARENTS, NO_CREATE_NEW_VERSION));
fail("Should throw an ObjectNotFoundException when there are no files in S3 to discover.");
} catch (ObjectNotFoundException e) {
assertTrue(e.getMessage().startsWith(String.format("Found no files at \"s3://%s", storageDaoTestHelper.getS3ManagedBucketName())));
}
}
Aggregations