use of org.finra.herd.model.api.xml.DownloadSingleInitiationResponse in project herd by FINRAOS.
the class UploadDownloadServiceImpl method initiateDownloadSingle.
@NamespacePermission(fields = "#namespace", permissions = NamespacePermissionEnum.READ)
@Override
public DownloadSingleInitiationResponse initiateDownloadSingle(String namespace, String businessObjectDefinitionName, String businessObjectFormatUsage, String businessObjectFormatFileType, Integer businessObjectFormatVersion, String partitionValue, Integer businessObjectDataVersion) {
// Create the business object data key.
BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(namespace, businessObjectDefinitionName, businessObjectFormatUsage, businessObjectFormatFileType, businessObjectFormatVersion, partitionValue, null, businessObjectDataVersion);
// Validate the parameters
businessObjectDataHelper.validateBusinessObjectDataKey(businessObjectDataKey, true, true);
// Retrieve the persisted business object data
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey);
// Make sure the status of the business object data is VALID
businessObjectDataHelper.assertBusinessObjectDataStatusEquals(BusinessObjectDataStatusEntity.VALID, businessObjectDataEntity);
// Get the external storage registered against this data
// Validate that the storage unit exists
StorageUnitEntity storageUnitEntity = IterableUtils.get(businessObjectDataEntity.getStorageUnits(), 0);
// Validate that the storage unit contains only 1 file
assertHasOneStorageFile(storageUnitEntity);
String s3BucketName = storageHelper.getStorageBucketName(storageUnitEntity.getStorage());
String s3ObjectKey = IterableUtils.get(storageUnitEntity.getStorageFiles(), 0).getPath();
// Get the temporary credentials
Credentials downloaderCredentials = getExternalDownloaderCredentials(storageUnitEntity.getStorage(), String.valueOf(businessObjectDataEntity.getId()), s3ObjectKey);
// Generate a pre-signed URL
Date expiration = downloaderCredentials.getExpiration();
S3FileTransferRequestParamsDto s3BucketAccessParams = storageHelper.getS3BucketAccessParams(storageUnitEntity.getStorage());
String presignedUrl = s3Dao.generateGetObjectPresignedUrl(s3BucketName, s3ObjectKey, expiration, s3BucketAccessParams);
// Construct and return the response
DownloadSingleInitiationResponse response = new DownloadSingleInitiationResponse();
response.setBusinessObjectData(businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity));
response.setAwsAccessKey(downloaderCredentials.getAccessKeyId());
response.setAwsSecretKey(downloaderCredentials.getSecretAccessKey());
response.setAwsSessionToken(downloaderCredentials.getSessionToken());
response.setAwsSessionExpirationTime(HerdDateUtils.getXMLGregorianCalendarValue(expiration));
response.setPreSignedUrl(presignedUrl);
return response;
}
use of org.finra.herd.model.api.xml.DownloadSingleInitiationResponse in project herd by FINRAOS.
the class UploadDownloadRestControllerTest method testInitiateDownloadSingle.
@Test
public void testInitiateDownloadSingle() {
// Create a business object data.
BusinessObjectData businessObjectData = new BusinessObjectData();
businessObjectData.setId(ID);
// Create a response.
DownloadSingleInitiationResponse response = new DownloadSingleInitiationResponse(businessObjectData, 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.initiateDownloadSingle(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, DATA_VERSION)).thenReturn(response);
// Call the method under test.
DownloadSingleInitiationResponse result = uploadDownloadRestController.initiateDownloadSingle(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, DATA_VERSION);
// Verify the external calls.
verify(uploadDownloadService).initiateDownloadSingle(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, DATA_VERSION);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(response, result);
}
use of org.finra.herd.model.api.xml.DownloadSingleInitiationResponse in project herd by FINRAOS.
the class UploadDownloadServiceTest method testInitiateDownloadSingle.
@Test
public void testInitiateDownloadSingle() {
// Create the upload data.
UploadSingleInitiationResponse uploadSingleInitiationResponse = uploadDownloadServiceTestHelper.createUploadedFileData(BusinessObjectDataStatusEntity.VALID);
// Initiate the download against the uploaded data (i.e. the target business object data).
DownloadSingleInitiationResponse downloadSingleInitiationResponse = initiateDownload(uploadSingleInitiationResponse.getTargetBusinessObjectData());
// Validate the download initiation response.
uploadDownloadServiceTestHelper.validateDownloadSingleInitiationResponse(uploadSingleInitiationResponse, downloadSingleInitiationResponse);
}
Aggregations