Search in sources :

Example 1 with DownloadSingleInitiationResponse

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;
}
Also used : DownloadSingleInitiationResponse(org.finra.herd.model.api.xml.DownloadSingleInitiationResponse) S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Credentials(com.amazonaws.services.securitytoken.model.Credentials) Date(java.util.Date) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 2 with DownloadSingleInitiationResponse

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);
}
Also used : DownloadSingleInitiationResponse(org.finra.herd.model.api.xml.DownloadSingleInitiationResponse) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) Test(org.junit.Test)

Example 3 with DownloadSingleInitiationResponse

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);
}
Also used : DownloadSingleInitiationResponse(org.finra.herd.model.api.xml.DownloadSingleInitiationResponse) UploadSingleInitiationResponse(org.finra.herd.model.api.xml.UploadSingleInitiationResponse) Test(org.junit.Test)

Aggregations

DownloadSingleInitiationResponse (org.finra.herd.model.api.xml.DownloadSingleInitiationResponse)3 Test (org.junit.Test)2 Credentials (com.amazonaws.services.securitytoken.model.Credentials)1 Date (java.util.Date)1 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)1 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)1 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)1 UploadSingleInitiationResponse (org.finra.herd.model.api.xml.UploadSingleInitiationResponse)1 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)1 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)1 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)1