use of org.finra.herd.model.jpa.BusinessObjectDefinitionSampleDataFileEntity 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;
}
use of org.finra.herd.model.jpa.BusinessObjectDefinitionSampleDataFileEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionDaoTestHelper method createBusinessObjectDefinitionEntity.
/**
* Creates and persists a new business object definition entity.
*
* @return the newly created business object definition entity
*/
public BusinessObjectDefinitionEntity createBusinessObjectDefinitionEntity(NamespaceEntity namespaceEntity, String businessObjectDefinitionName, DataProviderEntity dataProviderEntity, String businessObjectDefinitionDescription, String displayName, List<Attribute> attributes, List<SampleDataFile> sampleDataFiles) {
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = new BusinessObjectDefinitionEntity();
businessObjectDefinitionEntity.setNamespace(namespaceEntity);
businessObjectDefinitionEntity.setDataProvider(dataProviderEntity);
businessObjectDefinitionEntity.setName(businessObjectDefinitionName);
businessObjectDefinitionEntity.setDescription(businessObjectDefinitionDescription);
businessObjectDefinitionEntity.setDisplayName(displayName);
// Create business object definition attribute entities if they are specified.
if (!CollectionUtils.isEmpty(attributes)) {
List<BusinessObjectDefinitionAttributeEntity> attributeEntities = new ArrayList<>();
businessObjectDefinitionEntity.setAttributes(attributeEntities);
for (Attribute attribute : attributes) {
BusinessObjectDefinitionAttributeEntity attributeEntity = new BusinessObjectDefinitionAttributeEntity();
attributeEntities.add(attributeEntity);
attributeEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
attributeEntity.setName(attribute.getName());
attributeEntity.setValue(attribute.getValue());
}
}
// Create business object definition sample data file entities if they are specified.
if (!CollectionUtils.isEmpty(sampleDataFiles)) {
// Create a storage entity if needed.
StorageEntity storageEntity = storageDao.getStorageByName(AbstractDaoTest.STORAGE_NAME);
if (storageEntity == null) {
storageEntity = storageDaoTestHelper.createStorageEntity(AbstractDaoTest.STORAGE_NAME);
}
// Create sample data file entities.
List<BusinessObjectDefinitionSampleDataFileEntity> sampleDataFileEntities = new ArrayList<>();
businessObjectDefinitionEntity.setSampleDataFiles(sampleDataFileEntities);
for (SampleDataFile sampleDataFile : sampleDataFiles) {
BusinessObjectDefinitionSampleDataFileEntity sampleDataFileEntity = new BusinessObjectDefinitionSampleDataFileEntity();
sampleDataFileEntities.add(sampleDataFileEntity);
sampleDataFileEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
sampleDataFileEntity.setDirectoryPath(sampleDataFile.getDirectoryPath());
sampleDataFileEntity.setFileName(sampleDataFile.getFileName());
sampleDataFileEntity.setFileSizeBytes(AbstractDaoTest.FILE_SIZE_1_KB);
sampleDataFileEntity.setStorage(storageEntity);
}
}
return businessObjectDefinitionDao.saveAndRefresh(businessObjectDefinitionEntity);
}
use of org.finra.herd.model.jpa.BusinessObjectDefinitionSampleDataFileEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionServiceImpl method updateBusinessObjectDefinitionEntitySampleFile.
@Override
public void updateBusinessObjectDefinitionEntitySampleFile(BusinessObjectDefinitionKey businessObjectDefinitionKey, BusinessObjectDefinitionSampleFileUpdateDto businessObjectDefinitionSampleFileUpdateDto) {
String path = businessObjectDefinitionSampleFileUpdateDto.getPath();
String fileName = businessObjectDefinitionSampleFileUpdateDto.getFileName();
long fileSize = businessObjectDefinitionSampleFileUpdateDto.getFileSize();
// Validate business object key
businessObjectDefinitionHelper.validateBusinessObjectDefinitionKey(businessObjectDefinitionKey);
// Validate file name
Assert.hasText(fileName, "A file name must be specified.");
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(businessObjectDefinitionKey);
Collection<BusinessObjectDefinitionSampleDataFileEntity> sampleFiles = businessObjectDefinitionEntity.getSampleDataFiles();
boolean found = false;
for (BusinessObjectDefinitionSampleDataFileEntity sampleDataFieEntity : sampleFiles) {
// Assume the path is the same for this business object definition
if (sampleDataFieEntity.getFileName().equals(fileName)) {
found = true;
sampleDataFieEntity.setFileSizeBytes(fileSize);
businessObjectDefinitionDao.saveAndRefresh(businessObjectDefinitionEntity);
break;
}
}
// Create a new entity when not found
if (!found) {
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(StorageEntity.SAMPLE_DATA_FILE_STORAGE);
BusinessObjectDefinitionSampleDataFileEntity sampleDataFileEntity = new BusinessObjectDefinitionSampleDataFileEntity();
sampleDataFileEntity.setStorage(storageEntity);
sampleDataFileEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
sampleDataFileEntity.setDirectoryPath(path);
sampleDataFileEntity.setFileName(fileName);
sampleDataFileEntity.setFileSizeBytes(fileSize);
businessObjectDefinitionEntity.getSampleDataFiles().add(sampleDataFileEntity);
businessObjectDefinitionDao.saveAndRefresh(businessObjectDefinitionEntity);
}
// Notify the search index that a business object definition must be updated.
searchIndexUpdateHelper.modifyBusinessObjectDefinitionInSearchIndex(businessObjectDefinitionEntity, SEARCH_INDEX_UPDATE_TYPE_UPDATE);
}
use of org.finra.herd.model.jpa.BusinessObjectDefinitionSampleDataFileEntity 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