use of org.finra.herd.model.api.xml.SampleDataFile 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.SampleDataFile in project herd by FINRAOS.
the class UploadDownloadServiceTest method testDownloadBusinessObjectDefinitionInvalidParameters.
@Test
public void testDownloadBusinessObjectDefinitionInvalidParameters() {
// Create a test storage.
storageDaoTestHelper.createStorageEntity(STORAGE_NAME, Arrays.asList(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), S3_BUCKET_NAME), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_DOWNLOAD_ROLE_ARN), DOWNLOADER_ROLE_ARN)));
// 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(), Arrays.asList(new SampleDataFile(DIRECTORY_PATH, FILE_NAME)));
// Try to initiate a download using an invalid namespace.
try {
uploadDownloadService.initiateDownloadSingleSampleFile(new DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest(new BusinessObjectDefinitionSampleDataFileKey("I_DO_NOT_EXIST", BDEF_NAME, DIRECTORY_PATH, FILE_NAME)));
fail();
} catch (ObjectNotFoundException e) {
assertEquals(businessObjectDefinitionServiceTestHelper.getExpectedBusinessObjectDefinitionNotFoundErrorMessage("I_DO_NOT_EXIST", BDEF_NAME), e.getMessage());
}
// Try to initiate a download using an invalid business object definition name.
try {
uploadDownloadService.initiateDownloadSingleSampleFile(new DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest(new BusinessObjectDefinitionSampleDataFileKey(NAMESPACE, "I_DO_NOT_EXIST", DIRECTORY_PATH, FILE_NAME)));
fail();
} catch (ObjectNotFoundException e) {
assertEquals(businessObjectDefinitionServiceTestHelper.getExpectedBusinessObjectDefinitionNotFoundErrorMessage(NAMESPACE, "I_DO_NOT_EXIST"), e.getMessage());
}
// Try to initiate a download using an invalid directory path.
try {
uploadDownloadService.initiateDownloadSingleSampleFile(new DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest(new BusinessObjectDefinitionSampleDataFileKey(NAMESPACE, BDEF_NAME, "I_DO_NOT_EXIST", FILE_NAME)));
fail();
} catch (ObjectNotFoundException e) {
assertEquals(String.format("Business object definition with name \"%s\" and namespace \"%s\" does not have the specified sample file registered with file name \"%s\" in" + " directory path \"%s\"", BDEF_NAME, NAMESPACE, FILE_NAME, "I_DO_NOT_EXIST"), e.getMessage());
}
// Try to initiate a download using an invalid file name.
try {
uploadDownloadService.initiateDownloadSingleSampleFile(new DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest(new BusinessObjectDefinitionSampleDataFileKey(NAMESPACE, BDEF_NAME, DIRECTORY_PATH, "I_DO_NOT_EXIST")));
fail();
} catch (ObjectNotFoundException e) {
assertEquals(String.format("Business object definition with name \"%s\" and namespace \"%s\" does not have the specified sample file registered with file name \"%s\" in" + " directory path \"%s\"", BDEF_NAME, NAMESPACE, "I_DO_NOT_EXIST", DIRECTORY_PATH), e.getMessage());
}
}
use of org.finra.herd.model.api.xml.SampleDataFile 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());
}
use of org.finra.herd.model.api.xml.SampleDataFile in project herd by FINRAOS.
the class UploadDownloadServiceTest method testDownloadBusinessObjectDefinitionSampleFile.
@Test
public void testDownloadBusinessObjectDefinitionSampleFile() {
// Create a test storage.
storageDaoTestHelper.createStorageEntity(STORAGE_NAME, Arrays.asList(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), S3_BUCKET_NAME), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_DOWNLOAD_ROLE_ARN), DOWNLOADER_ROLE_ARN)));
// 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(), Arrays.asList(new SampleDataFile(DIRECTORY_PATH, FILE_NAME)));
// Initiate download of a sample data file.
DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest downloadRequest = new DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationRequest();
BusinessObjectDefinitionSampleDataFileKey sampleDataFileKey = new BusinessObjectDefinitionSampleDataFileKey();
sampleDataFileKey.setNamespace(NAMESPACE);
sampleDataFileKey.setBusinessObjectDefinitionName(BDEF_NAME);
sampleDataFileKey.setDirectoryPath(DIRECTORY_PATH);
sampleDataFileKey.setFileName(FILE_NAME);
downloadRequest.setBusinessObjectDefinitionSampleDataFileKey(sampleDataFileKey);
DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse downloadResponse = uploadDownloadService.initiateDownloadSingleSampleFile(downloadRequest);
// Validate the response.
assertNotNull(downloadResponse.getAwsSessionExpirationTime());
assertNotNull(downloadResponse.getPreSignedUrl());
assertEquals(new DownloadBusinessObjectDefinitionSampleDataFileSingleInitiationResponse(new BusinessObjectDefinitionSampleDataFileKey(NAMESPACE, BDEF_NAME, DIRECTORY_PATH, FILE_NAME), S3_BUCKET_NAME, MockStsOperationsImpl.MOCK_AWS_ASSUMED_ROLE_ACCESS_KEY, MockStsOperationsImpl.MOCK_AWS_ASSUMED_ROLE_SECRET_KEY, MockStsOperationsImpl.MOCK_AWS_ASSUMED_ROLE_SESSION_TOKEN, downloadResponse.getAwsSessionExpirationTime(), downloadResponse.getPreSignedUrl()), downloadResponse);
}
use of org.finra.herd.model.api.xml.SampleDataFile in project herd by FINRAOS.
the class BusinessObjectDefinitionServiceImpl method createBusinessObjectDefinitionFromEntity.
/**
* Creates a business object definition from the persisted entity.
*
* @param businessObjectDefinitionEntity the business object definition entity
*
* @return the business object definition
*/
private BusinessObjectDefinition createBusinessObjectDefinitionFromEntity(BusinessObjectDefinitionEntity businessObjectDefinitionEntity, Boolean includeBusinessObjectDefinitionUpdateHistory) {
// Create a business object definition.
BusinessObjectDefinition businessObjectDefinition = new BusinessObjectDefinition();
businessObjectDefinition.setId(businessObjectDefinitionEntity.getId());
businessObjectDefinition.setNamespace(businessObjectDefinitionEntity.getNamespace().getCode());
businessObjectDefinition.setBusinessObjectDefinitionName(businessObjectDefinitionEntity.getName());
businessObjectDefinition.setDescription(businessObjectDefinitionEntity.getDescription());
businessObjectDefinition.setDataProviderName(businessObjectDefinitionEntity.getDataProvider().getName());
businessObjectDefinition.setDisplayName(businessObjectDefinitionEntity.getDisplayName());
// Add attributes.
List<Attribute> attributes = new ArrayList<>();
businessObjectDefinition.setAttributes(attributes);
for (BusinessObjectDefinitionAttributeEntity attributeEntity : businessObjectDefinitionEntity.getAttributes()) {
attributes.add(new Attribute(attributeEntity.getName(), attributeEntity.getValue()));
}
if (businessObjectDefinitionEntity.getDescriptiveBusinessObjectFormat() != null) {
BusinessObjectFormatEntity descriptiveFormatEntity = businessObjectDefinitionEntity.getDescriptiveBusinessObjectFormat();
DescriptiveBusinessObjectFormat descriptiveBusinessObjectFormat = new DescriptiveBusinessObjectFormat();
businessObjectDefinition.setDescriptiveBusinessObjectFormat(descriptiveBusinessObjectFormat);
descriptiveBusinessObjectFormat.setBusinessObjectFormatUsage(descriptiveFormatEntity.getUsage());
descriptiveBusinessObjectFormat.setBusinessObjectFormatFileType(descriptiveFormatEntity.getFileType().getCode());
descriptiveBusinessObjectFormat.setBusinessObjectFormatVersion(descriptiveFormatEntity.getBusinessObjectFormatVersion());
}
// Add sample data files.
List<SampleDataFile> sampleDataFiles = new ArrayList<>();
businessObjectDefinition.setSampleDataFiles(sampleDataFiles);
for (BusinessObjectDefinitionSampleDataFileEntity sampleDataFileEntity : businessObjectDefinitionEntity.getSampleDataFiles()) {
sampleDataFiles.add(new SampleDataFile(sampleDataFileEntity.getDirectoryPath(), sampleDataFileEntity.getFileName()));
}
// Add auditable fields.
businessObjectDefinition.setCreatedByUserId(businessObjectDefinitionEntity.getCreatedBy());
businessObjectDefinition.setLastUpdatedByUserId(businessObjectDefinitionEntity.getUpdatedBy());
businessObjectDefinition.setLastUpdatedOn(HerdDateUtils.getXMLGregorianCalendarValue(businessObjectDefinitionEntity.getUpdatedOn()));
// Add change events.
final List<BusinessObjectDefinitionChangeEvent> businessObjectDefinitionChangeEvents = new ArrayList<>();
if (BooleanUtils.isTrue(includeBusinessObjectDefinitionUpdateHistory)) {
businessObjectDefinitionEntity.getChangeEvents().forEach(businessObjectDefinitionChangeEventEntity -> {
DescriptiveBusinessObjectFormatUpdateRequest descriptiveBusinessObjectFormatUpdateRequest = null;
if (businessObjectDefinitionChangeEventEntity.getFileType() != null) {
descriptiveBusinessObjectFormatUpdateRequest = new DescriptiveBusinessObjectFormatUpdateRequest(businessObjectDefinitionChangeEventEntity.getUsage(), businessObjectDefinitionChangeEventEntity.getFileType());
}
businessObjectDefinitionChangeEvents.add(new BusinessObjectDefinitionChangeEvent(businessObjectDefinitionChangeEventEntity.getDisplayName(), businessObjectDefinitionChangeEventEntity.getDescription(), descriptiveBusinessObjectFormatUpdateRequest, HerdDateUtils.getXMLGregorianCalendarValue(businessObjectDefinitionChangeEventEntity.getCreatedOn()), businessObjectDefinitionChangeEventEntity.getCreatedBy()));
});
}
businessObjectDefinition.setBusinessObjectDefinitionChangeEvents(businessObjectDefinitionChangeEvents);
return businessObjectDefinition;
}
Aggregations