use of org.finra.herd.model.api.xml.DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse in project herd by FINRAOS.
the class UploadDownloadServiceImpl method initiateDownloadSingleSampleFile.
@Override
public DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse initiateDownloadSingleSampleFile(DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest request) {
// Validate and trim the request parameters.
validateDownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest(request);
// Get the business object definition sample data file key.
BusinessObjectDefinitionSampleDataFileKey businessObjectDefinitionSampleDataFileKey = request.getBusinessObjectDefinitionSampleDataFileKey();
// Get the business object definition key.
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(businessObjectDefinitionSampleDataFileKey.getNamespace(), businessObjectDefinitionSampleDataFileKey.getBusinessObjectDefinitionName());
// Get the business object definition entity and ensure it exists.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(businessObjectDefinitionKey);
// Get the sample data file exists for the business object definition and ensure it exists.
BusinessObjectDefinitionSampleDataFileEntity businessObjectDefinitionSampleDataFileEntity = getBusinessObjectDefinitionSampleDataFileEntity(businessObjectDefinitionEntity, businessObjectDefinitionSampleDataFileKey);
// Retrieve the storage related information.
StorageEntity storageEntity = businessObjectDefinitionSampleDataFileEntity.getStorage();
String s3BucketName = storageHelper.getStorageBucketName(storageEntity);
String s3ObjectKey = businessObjectDefinitionSampleDataFileKey.getDirectoryPath() + businessObjectDefinitionSampleDataFileKey.getFileName();
String sessionID = UUID.randomUUID().toString();
// Get the temporary credentials.
Credentials downloaderCredentials = getDownloaderCredentialsNoKmsKey(storageEntity, sessionID, s3ObjectKey);
// Generate a pre-signed URL.
Date expiration = downloaderCredentials.getExpiration();
S3FileTransferRequestParamsDto s3BucketAccessParams = storageHelper.getS3BucketAccessParams(storageEntity);
String presignedUrl = s3Dao.generateGetObjectPresignedUrl(s3BucketName, s3ObjectKey, expiration, s3BucketAccessParams);
// Create the download business object definition sample data file single initiation response.
DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse response = new DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse();
response.setBusinessObjectDefinitionSampleDataFileKey(new BusinessObjectDefinitionSampleDataFileKey(businessObjectDefinitionEntity.getNamespace().getCode(), businessObjectDefinitionEntity.getName(), businessObjectDefinitionSampleDataFileEntity.getDirectoryPath(), businessObjectDefinitionSampleDataFileEntity.getFileName()));
response.setAwsS3BucketName(s3BucketName);
response.setAwsAccessKey(downloaderCredentials.getAccessKeyId());
response.setAwsSecretKey(downloaderCredentials.getSecretAccessKey());
response.setAwsSessionToken(downloaderCredentials.getSessionToken());
response.setAwsSessionExpirationTime(HerdDateUtils.getXMLGregorianCalendarValue(expiration));
response.setPreSignedUrl(presignedUrl);
// Return the response.
return response;
}
use of org.finra.herd.model.api.xml.DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse in project herd by FINRAOS.
the class UploadDownloadServiceTest method testDownloadBusinessObjectDefinitionSampleFileUpperCaseParameters.
@Test
public void testDownloadBusinessObjectDefinitionSampleFileUpperCaseParameters() {
// Create and persist a business object definition entity.
businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, businessObjectDefinitionServiceTestHelper.getNewAttributes(), businessObjectDefinitionServiceTestHelper.getTestSampleDataFiles());
List<SampleDataFile> sampleFileList = businessObjectDefinitionServiceTestHelper.getTestSampleDataFiles();
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(STORAGE_NAME);
storageEntity.getAttributes().add(storageDaoTestHelper.createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), "testBucketName"));
storageEntity.getAttributes().add(storageDaoTestHelper.createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_DOWNLOAD_ROLE_ARN), "downloadRole"));
DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest downloadRequest = new DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest();
BusinessObjectDefinitionSampleDataFileKey sampleDataFileKey = new BusinessObjectDefinitionSampleDataFileKey();
sampleDataFileKey.setBusinessObjectDefinitionName(BDEF_NAME);
sampleDataFileKey.setNamespace(NAMESPACE);
sampleDataFileKey.setDirectoryPath(sampleFileList.get(0).getDirectoryPath());
sampleDataFileKey.setFileName(sampleFileList.get(0).getFileName());
// use the lower case name space and business definition still return the same response
BusinessObjectDefinitionSampleDataFileKey sampleDataFileKeyUpperCase = new BusinessObjectDefinitionSampleDataFileKey();
sampleDataFileKeyUpperCase.setBusinessObjectDefinitionName(BDEF_NAME.toUpperCase());
sampleDataFileKeyUpperCase.setNamespace(NAMESPACE.toUpperCase());
sampleDataFileKeyUpperCase.setDirectoryPath(sampleFileList.get(0).getDirectoryPath());
sampleDataFileKeyUpperCase.setFileName(sampleFileList.get(0).getFileName());
downloadRequest.setBusinessObjectDefinitionSampleDataFileKey(sampleDataFileKeyUpperCase);
DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse downloadResponse = uploadDownloadService.initiateDownloadSingleSampleFile(downloadRequest);
assertEquals(downloadResponse.getBusinessObjectDefinitionSampleDataFileKey(), sampleDataFileKey);
assertNotNull(downloadResponse.getAwsS3BucketName());
assertNotNull(downloadResponse.getAwsAccessKey());
assertNotNull(downloadResponse.getAwsSecretKey());
assertNotNull(downloadResponse.getAwsSessionExpirationTime());
assertNotNull(downloadResponse.getAwsSessionToken());
assertNotNull(downloadResponse.getPreSignedUrl());
}
use of org.finra.herd.model.api.xml.DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse in project herd by FINRAOS.
the class UploadDownloadRestControllerTest method testInitiateDownloadSingleSampleFile.
@Test
public void testInitiateDownloadSingleSampleFile() {
// Create a business object definition sample data file key.
BusinessObjectDefinitionSampleDataFileKey businessObjectDefinitionSampleDataFileKey = new BusinessObjectDefinitionSampleDataFileKey(BDEF_NAMESPACE, BDEF_NAME, DIRECTORY_PATH, FILE_NAME);
// Create a request.
DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest request = new DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest(businessObjectDefinitionSampleDataFileKey);
// Create a response.
DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse response = new DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse(businessObjectDefinitionSampleDataFileKey, S3_BUCKET_NAME, AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, AWS_ASSUMED_ROLE_SESSION_EXPIRATION_TIME, AWS_PRE_SIGNED_URL);
// Mock the external calls.
when(uploadDownloadService.initiateDownloadSingleSampleFile(request)).thenReturn(response);
// Call the method under test.
DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse result = uploadDownloadRestController.initiateDownloadSingleSampleFile(request);
// Verify the external calls.
verify(uploadDownloadService).initiateDownloadSingleSampleFile(request);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(response, result);
}
use of org.finra.herd.model.api.xml.DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse in project herd by FINRAOS.
the class UploadDownloadServiceTest method testDownloadBusinessObjectDefinitionSampleFileTrimmedParameters.
@Test
public void testDownloadBusinessObjectDefinitionSampleFileTrimmedParameters() {
// Create and persist a business object definition entity.
businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, businessObjectDefinitionServiceTestHelper.getNewAttributes(), businessObjectDefinitionServiceTestHelper.getTestSampleDataFiles());
List<SampleDataFile> sampleFileList = businessObjectDefinitionServiceTestHelper.getTestSampleDataFiles();
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(STORAGE_NAME);
storageEntity.getAttributes().add(storageDaoTestHelper.createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), "testBucketName"));
storageEntity.getAttributes().add(storageDaoTestHelper.createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_DOWNLOAD_ROLE_ARN), "downloadRole"));
DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest downloadRequest = new DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest();
BusinessObjectDefinitionSampleDataFileKey sampleDataFileKey = new BusinessObjectDefinitionSampleDataFileKey();
sampleDataFileKey.setBusinessObjectDefinitionName(BDEF_NAME);
sampleDataFileKey.setNamespace(NAMESPACE);
sampleDataFileKey.setDirectoryPath(sampleFileList.get(0).getDirectoryPath());
sampleDataFileKey.setFileName(sampleFileList.get(0).getFileName());
// use the lower case name space and business definition still return the same response
BusinessObjectDefinitionSampleDataFileKey sampleDataFileKeyPadded = new BusinessObjectDefinitionSampleDataFileKey();
sampleDataFileKeyPadded.setBusinessObjectDefinitionName(" " + BDEF_NAME + " ");
sampleDataFileKeyPadded.setNamespace(" " + NAMESPACE + " ");
sampleDataFileKeyPadded.setDirectoryPath(sampleFileList.get(0).getDirectoryPath());
sampleDataFileKeyPadded.setFileName(sampleFileList.get(0).getFileName());
downloadRequest.setBusinessObjectDefinitionSampleDataFileKey(sampleDataFileKeyPadded);
DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse downloadResponse = uploadDownloadService.initiateDownloadSingleSampleFile(downloadRequest);
assertEquals(downloadResponse.getBusinessObjectDefinitionSampleDataFileKey(), sampleDataFileKey);
assertNotNull(downloadResponse.getAwsS3BucketName());
assertNotNull(downloadResponse.getAwsAccessKey());
assertNotNull(downloadResponse.getAwsSecretKey());
assertNotNull(downloadResponse.getAwsSessionExpirationTime());
assertNotNull(downloadResponse.getAwsSessionToken());
assertNotNull(downloadResponse.getPreSignedUrl());
}
use of org.finra.herd.model.api.xml.DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse in project herd by FINRAOS.
the class UploadDownloadServiceTest method testDownloadBusinessObjectDefinitionSampleFileLowerCaseParameters.
@Test
public void testDownloadBusinessObjectDefinitionSampleFileLowerCaseParameters() {
// Create and persist a business object definition entity.
businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, businessObjectDefinitionServiceTestHelper.getNewAttributes(), businessObjectDefinitionServiceTestHelper.getTestSampleDataFiles());
List<SampleDataFile> sampleFileList = businessObjectDefinitionServiceTestHelper.getTestSampleDataFiles();
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(STORAGE_NAME);
storageEntity.getAttributes().add(storageDaoTestHelper.createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), "testBucketName"));
storageEntity.getAttributes().add(storageDaoTestHelper.createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_DOWNLOAD_ROLE_ARN), "downloadRole"));
DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest downloadRequest = new DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest();
BusinessObjectDefinitionSampleDataFileKey sampleDataFileKey = new BusinessObjectDefinitionSampleDataFileKey();
sampleDataFileKey.setBusinessObjectDefinitionName(BDEF_NAME);
sampleDataFileKey.setNamespace(NAMESPACE);
sampleDataFileKey.setDirectoryPath(sampleFileList.get(0).getDirectoryPath());
sampleDataFileKey.setFileName(sampleFileList.get(0).getFileName());
// use the lower case name space and business definition still return the same response
BusinessObjectDefinitionSampleDataFileKey sampleDataFileKeyLowerCase = new BusinessObjectDefinitionSampleDataFileKey();
sampleDataFileKeyLowerCase.setBusinessObjectDefinitionName(BDEF_NAME.toLowerCase());
sampleDataFileKeyLowerCase.setNamespace(NAMESPACE.toLowerCase());
sampleDataFileKeyLowerCase.setDirectoryPath(sampleFileList.get(0).getDirectoryPath());
sampleDataFileKeyLowerCase.setFileName(sampleFileList.get(0).getFileName());
downloadRequest.setBusinessObjectDefinitionSampleDataFileKey(sampleDataFileKeyLowerCase);
DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse downloadResponse = uploadDownloadService.initiateDownloadSingleSampleFile(downloadRequest);
assertEquals(downloadResponse.getBusinessObjectDefinitionSampleDataFileKey(), sampleDataFileKey);
assertNotNull(downloadResponse.getAwsS3BucketName());
assertNotNull(downloadResponse.getAwsAccessKey());
assertNotNull(downloadResponse.getAwsSecretKey());
assertNotNull(downloadResponse.getAwsSessionExpirationTime());
assertNotNull(downloadResponse.getAwsSessionToken());
assertNotNull(downloadResponse.getPreSignedUrl());
}
Aggregations