Search in sources :

Example 1 with DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse

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;
}
Also used : BusinessObjectDefinitionSampleDataFileKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionSampleDataFileKey) DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse(org.finra.herd.model.api.xml.DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse) S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectDefinitionSampleDataFileEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionSampleDataFileEntity) Credentials(com.amazonaws.services.securitytoken.model.Credentials) Date(java.util.Date)

Example 2 with DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse

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());
}
Also used : SampleDataFile(org.finra.herd.model.api.xml.SampleDataFile) BusinessObjectDefinitionSampleDataFileKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionSampleDataFileKey) DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse(org.finra.herd.model.api.xml.DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse) DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest(org.finra.herd.model.api.xml.DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest) StorageEntity(org.finra.herd.model.jpa.StorageEntity) Test(org.junit.Test)

Example 3 with DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse

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

Example 4 with DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse

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());
}
Also used : SampleDataFile(org.finra.herd.model.api.xml.SampleDataFile) BusinessObjectDefinitionSampleDataFileKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionSampleDataFileKey) DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse(org.finra.herd.model.api.xml.DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse) DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest(org.finra.herd.model.api.xml.DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest) StorageEntity(org.finra.herd.model.jpa.StorageEntity) Test(org.junit.Test)

Example 5 with DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse

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());
}
Also used : SampleDataFile(org.finra.herd.model.api.xml.SampleDataFile) BusinessObjectDefinitionSampleDataFileKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionSampleDataFileKey) DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse(org.finra.herd.model.api.xml.DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse) DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest(org.finra.herd.model.api.xml.DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest) StorageEntity(org.finra.herd.model.jpa.StorageEntity) Test(org.junit.Test)

Aggregations

BusinessObjectDefinitionSampleDataFileKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionSampleDataFileKey)6 DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse (org.finra.herd.model.api.xml.DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse)6 DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest (org.finra.herd.model.api.xml.DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest)5 Test (org.junit.Test)5 SampleDataFile (org.finra.herd.model.api.xml.SampleDataFile)4 StorageEntity (org.finra.herd.model.jpa.StorageEntity)4 Credentials (com.amazonaws.services.securitytoken.model.Credentials)1 Date (java.util.Date)1 Attribute (org.finra.herd.model.api.xml.Attribute)1 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)1 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)1 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)1 BusinessObjectDefinitionSampleDataFileEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionSampleDataFileEntity)1