use of org.finra.herd.model.api.xml.UploadBusinessObjectDefinitionSampleDataFileInitiationResponse in project herd by FINRAOS.
the class UploadDownloadServiceTest method testUploadBusinessObjectDefinitionSampleFile.
@Test
public void testUploadBusinessObjectDefinitionSampleFile() {
String s3_velocity_template = "$namespace/$businessObjectDefinitionName";
String expectedS3Keyprefix = NAMESPACE.toLowerCase() + "/" + BDEF_NAME.toLowerCase() + "/";
expectedS3Keyprefix = expectedS3Keyprefix.replace("_", "-");
// Create a test storage.
storageDaoTestHelper.createStorageEntity(StorageEntity.SAMPLE_DATA_FILE_STORAGE, Arrays.asList(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), S3_BUCKET_NAME), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_UPLOAD_ROLE_ARN), UPLOADER_ROLE_ARN), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), s3_velocity_template)));
// Create and persist a business object definition entity with sample data files.
businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, businessObjectDefinitionServiceTestHelper.getNewAttributes());
UploadBusinessObjectDefinitionSampleDataFileInitiationRequest request = new UploadBusinessObjectDefinitionSampleDataFileInitiationRequest();
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME);
request.setBusinessObjectDefinitionKey(businessObjectDefinitionKey);
UploadBusinessObjectDefinitionSampleDataFileInitiationResponse response = uploadDownloadService.initiateUploadSampleFile(request);
assertEquals(response.getBusinessObjectDefinitionKey(), businessObjectDefinitionKey);
assertEquals(response.getAwsS3BucketName(), S3_BUCKET_NAME);
assertEquals(response.getS3KeyPrefix(), expectedS3Keyprefix);
assertEquals(response.getAwsAccessKey(), MockStsOperationsImpl.MOCK_AWS_ASSUMED_ROLE_ACCESS_KEY);
assertEquals(response.getAwsSecretKey(), MockStsOperationsImpl.MOCK_AWS_ASSUMED_ROLE_SECRET_KEY);
assertEquals(response.getAwsSessionToken(), MockStsOperationsImpl.MOCK_AWS_ASSUMED_ROLE_SESSION_TOKEN);
}
use of org.finra.herd.model.api.xml.UploadBusinessObjectDefinitionSampleDataFileInitiationResponse in project herd by FINRAOS.
the class UploadDownloadServiceTest method testUploadBusinessObjectDefinitionSampleFileLowerCase.
@Test
public void testUploadBusinessObjectDefinitionSampleFileLowerCase() {
String s3_velocity_template = "$namespace/$businessObjectDefinitionName";
// Create a test storage.
storageDaoTestHelper.createStorageEntity(StorageEntity.SAMPLE_DATA_FILE_STORAGE, Arrays.asList(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), S3_BUCKET_NAME), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_UPLOAD_ROLE_ARN), UPLOADER_ROLE_ARN), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), s3_velocity_template)));
// Create and persist a business object definition entity with sample data files.
businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, businessObjectDefinitionServiceTestHelper.getNewAttributes());
UploadBusinessObjectDefinitionSampleDataFileInitiationRequest request = new UploadBusinessObjectDefinitionSampleDataFileInitiationRequest();
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME);
BusinessObjectDefinitionKey businessObjectDefinitionKeyLowerCase = new BusinessObjectDefinitionKey(NAMESPACE.toLowerCase(), BDEF_NAME.toLowerCase());
request.setBusinessObjectDefinitionKey(businessObjectDefinitionKeyLowerCase);
UploadBusinessObjectDefinitionSampleDataFileInitiationResponse response = uploadDownloadService.initiateUploadSampleFile(request);
assertEquals(response.getBusinessObjectDefinitionKey(), businessObjectDefinitionKey);
assertEquals(response.getAwsS3BucketName(), S3_BUCKET_NAME);
assertEquals(response.getAwsAccessKey(), MockStsOperationsImpl.MOCK_AWS_ASSUMED_ROLE_ACCESS_KEY);
assertEquals(response.getAwsSecretKey(), MockStsOperationsImpl.MOCK_AWS_ASSUMED_ROLE_SECRET_KEY);
assertEquals(response.getAwsSessionToken(), MockStsOperationsImpl.MOCK_AWS_ASSUMED_ROLE_SESSION_TOKEN);
}
use of org.finra.herd.model.api.xml.UploadBusinessObjectDefinitionSampleDataFileInitiationResponse in project herd by FINRAOS.
the class UploadDownloadServiceImpl method initiateUploadSampleFile.
@NamespacePermission(fields = "#request.businessObjectDefinitionKey.namespace", permissions = { NamespacePermissionEnum.WRITE_DESCRIPTIVE_CONTENT, NamespacePermissionEnum.WRITE })
@Override
public UploadBusinessObjectDefinitionSampleDataFileInitiationResponse initiateUploadSampleFile(UploadBusinessObjectDefinitionSampleDataFileInitiationRequest request) {
validateUploadBusinessObjectDefinitionSampleDataFileInitiationRequest(request);
BusinessObjectDefinitionKey businessObjectDefinitionKey = request.getBusinessObjectDefinitionKey();
// Get the business object definition entity and ensure it exists.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(businessObjectDefinitionKey);
businessObjectDefinitionKey.setNamespace(businessObjectDefinitionEntity.getNamespace().getCode());
businessObjectDefinitionKey.setBusinessObjectDefinitionName(businessObjectDefinitionEntity.getName());
UploadBusinessObjectDefinitionSampleDataFileInitiationResponse response = new UploadBusinessObjectDefinitionSampleDataFileInitiationResponse();
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(StorageEntity.SAMPLE_DATA_FILE_STORAGE);
String s3BucketName = storageHelper.getStorageBucketName(storageEntity);
String s3EndPoint = storageHelper.getS3BucketAccessParams(storageEntity).getS3Endpoint();
String awsRoleArn = getStorageUploadRoleArn(storageEntity);
String sessionID = UUID.randomUUID().toString();
String s3KeyPrefix = s3KeyPrefixHelper.buildS3KeyPrefix(storageEntity, businessObjectDefinitionKey);
s3KeyPrefix = StringUtils.appendIfMissing(s3KeyPrefix, "/");
// need to add star for aws authorization
String s3Path = s3KeyPrefix + "*";
Integer awsRoleDurationSeconds = getStorageUploadSessionDuration(storageEntity);
Credentials assumedSessionCredentials = stsDao.getTemporarySecurityCredentials(awsHelper.getAwsParamsDto(), sessionID, awsRoleArn, awsRoleDurationSeconds, createUploaderPolicyNoKmsKey(s3BucketName, s3Path));
response.setAwsAccessKey(assumedSessionCredentials.getAccessKeyId());
response.setAwsSecretKey(assumedSessionCredentials.getSecretAccessKey());
response.setAwsSessionToken(assumedSessionCredentials.getSessionToken());
response.setAwsSessionExpirationTime(HerdDateUtils.getXMLGregorianCalendarValue(assumedSessionCredentials.getExpiration()));
response.setAwsS3BucketName(s3BucketName);
response.setBusinessObjectDefinitionKey(businessObjectDefinitionKey);
response.setS3Endpoint(s3EndPoint);
response.setS3KeyPrefix(s3KeyPrefix);
return response;
}
use of org.finra.herd.model.api.xml.UploadBusinessObjectDefinitionSampleDataFileInitiationResponse in project herd by FINRAOS.
the class UploadDownloadRestControllerTest method testInitiateUploadSampleFile.
@Test
public void testInitiateUploadSampleFile() {
// Create a business object data key.
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME);
// Create a request.
UploadBusinessObjectDefinitionSampleDataFileInitiationRequest request = new UploadBusinessObjectDefinitionSampleDataFileInitiationRequest(businessObjectDefinitionKey);
// Create a response.
UploadBusinessObjectDefinitionSampleDataFileInitiationResponse response = new UploadBusinessObjectDefinitionSampleDataFileInitiationResponse(businessObjectDefinitionKey, S3_BUCKET_NAME, S3_ENDPOINT, S3_KEY_PREFIX, AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, AWS_ASSUMED_ROLE_SESSION_EXPIRATION_TIME);
// Mock the external calls.
when(uploadDownloadService.initiateUploadSampleFile(request)).thenReturn(response);
// Call the method under test.
UploadBusinessObjectDefinitionSampleDataFileInitiationResponse result = uploadDownloadRestController.initiateUploadSampleFile(request);
// Verify the external calls.
verify(uploadDownloadService).initiateUploadSampleFile(request);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(response, result);
}
use of org.finra.herd.model.api.xml.UploadBusinessObjectDefinitionSampleDataFileInitiationResponse in project herd by FINRAOS.
the class UploadDownloadServiceTest method testUploadBusinessObjectDefinitionSampleFileUpperCase.
@Test
public void testUploadBusinessObjectDefinitionSampleFileUpperCase() {
String s3_velocity_template = "$namespace/$businessObjectDefinitionName";
// Create a test storage.
storageDaoTestHelper.createStorageEntity(StorageEntity.SAMPLE_DATA_FILE_STORAGE, Arrays.asList(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), S3_BUCKET_NAME), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_UPLOAD_ROLE_ARN), UPLOADER_ROLE_ARN), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), s3_velocity_template)));
// Create and persist a business object definition entity with sample data files.
businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, businessObjectDefinitionServiceTestHelper.getNewAttributes());
UploadBusinessObjectDefinitionSampleDataFileInitiationRequest request = new UploadBusinessObjectDefinitionSampleDataFileInitiationRequest();
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME);
BusinessObjectDefinitionKey businessObjectDefinitionKeyUpperCase = new BusinessObjectDefinitionKey(NAMESPACE.toUpperCase(), BDEF_NAME.toUpperCase());
request.setBusinessObjectDefinitionKey(businessObjectDefinitionKeyUpperCase);
UploadBusinessObjectDefinitionSampleDataFileInitiationResponse response = uploadDownloadService.initiateUploadSampleFile(request);
assertEquals(response.getBusinessObjectDefinitionKey(), businessObjectDefinitionKey);
assertEquals(response.getAwsS3BucketName(), S3_BUCKET_NAME);
assertEquals(response.getAwsAccessKey(), MockStsOperationsImpl.MOCK_AWS_ASSUMED_ROLE_ACCESS_KEY);
assertEquals(response.getAwsSecretKey(), MockStsOperationsImpl.MOCK_AWS_ASSUMED_ROLE_SECRET_KEY);
assertEquals(response.getAwsSessionToken(), MockStsOperationsImpl.MOCK_AWS_ASSUMED_ROLE_SESSION_TOKEN);
}
Aggregations