use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class UploadDownloadServiceImpl method initiateUploadSingle.
@PublishNotificationMessages
@NamespacePermission(fields = { "#uploadSingleInitiationRequest?.sourceBusinessObjectFormatKey?.namespace", "#uploadSingleInitiationRequest?.targetBusinessObjectFormatKey?.namespace" }, permissions = NamespacePermissionEnum.WRITE)
@Override
public UploadSingleInitiationResponse initiateUploadSingle(UploadSingleInitiationRequest uploadSingleInitiationRequest) {
// Validate and trim the request parameters.
validateUploadSingleInitiationRequest(uploadSingleInitiationRequest);
// Get the business object format for the specified parameters and make sure it exists.
BusinessObjectFormatEntity sourceBusinessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(uploadSingleInitiationRequest.getSourceBusinessObjectFormatKey());
// Get the target business object format entity for the specified parameters and make sure it exists.
BusinessObjectFormatEntity targetBusinessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(uploadSingleInitiationRequest.getTargetBusinessObjectFormatKey());
// Get the S3 managed "loading dock" storage entity and make sure it exists.
StorageEntity sourceStorageEntity = storageDaoHelper.getStorageEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE);
// Get S3 bucket name for the storage. Please note that since those values are required we pass a "true" flag.
String s3BucketName = storageHelper.getStorageBucketName(sourceStorageEntity);
// Get the S3 managed "external" storage entity and make sure it exists.
String targetStorageName;
if (uploadSingleInitiationRequest.getTargetStorageName() != null) {
targetStorageName = uploadSingleInitiationRequest.getTargetStorageName();
} else {
targetStorageName = configurationHelper.getProperty(ConfigurationValue.S3_EXTERNAL_STORAGE_NAME_DEFAULT);
}
StorageEntity targetStorageEntity = storageDaoHelper.getStorageEntity(targetStorageName);
assertTargetStorageEntityValid(targetStorageEntity);
// Generate a random UUID value.
String uuid = UUID.randomUUID().toString();
// Create business object data key with partition value set to the generated UUID.
BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(uploadSingleInitiationRequest.getSourceBusinessObjectFormatKey().getNamespace(), uploadSingleInitiationRequest.getSourceBusinessObjectFormatKey().getBusinessObjectDefinitionName(), uploadSingleInitiationRequest.getSourceBusinessObjectFormatKey().getBusinessObjectFormatUsage(), uploadSingleInitiationRequest.getSourceBusinessObjectFormatKey().getBusinessObjectFormatFileType(), uploadSingleInitiationRequest.getSourceBusinessObjectFormatKey().getBusinessObjectFormatVersion(), uuid, null, BusinessObjectDataEntity.BUSINESS_OBJECT_DATA_INITIAL_VERSION);
// Get a file upload specific S3 key prefix for the source storage based on the generated UUID.
String sourceStorageDirectoryPath = s3KeyPrefixHelper.buildS3KeyPrefix(sourceStorageEntity, sourceBusinessObjectFormatEntity, businessObjectDataKey);
String sourceStorageFilePath = String.format("%s/%s", sourceStorageDirectoryPath, uploadSingleInitiationRequest.getFile().getFileName());
// Create a business object data create request.
BusinessObjectDataCreateRequest sourceBusinessObjectDataCreateRequest = businessObjectDataHelper.createBusinessObjectDataCreateRequest(sourceBusinessObjectFormatEntity, uuid, BusinessObjectDataStatusEntity.UPLOADING, uploadSingleInitiationRequest.getBusinessObjectDataAttributes(), sourceStorageEntity, sourceStorageDirectoryPath, sourceStorageFilePath, uploadSingleInitiationRequest.getFile().getFileSizeBytes(), null);
// Create a new business object data instance. Set the flag to false, since for the file upload service the file size value is optional.
BusinessObjectData sourceBusinessObjectData = businessObjectDataDaoHelper.createBusinessObjectData(sourceBusinessObjectDataCreateRequest, false);
// Get a file upload specific S3 key prefix for the target storage based on the generated UUID.
String targetStorageDirectoryPath = s3KeyPrefixHelper.buildS3KeyPrefix(targetStorageEntity, targetBusinessObjectFormatEntity, businessObjectDataKey);
String targetStorageFilePath = String.format("%s/%s", targetStorageDirectoryPath, uploadSingleInitiationRequest.getFile().getFileName());
uploadDownloadHelperService.assertS3ObjectKeyDoesNotExist(storageHelper.getStorageBucketName(targetStorageEntity), targetStorageFilePath);
// Create a target business object data based on the source business object data and target business object format.
BusinessObjectDataCreateRequest targetBusinessObjectDataCreateRequest = businessObjectDataHelper.createBusinessObjectDataCreateRequest(targetBusinessObjectFormatEntity, uuid, BusinessObjectDataStatusEntity.UPLOADING, uploadSingleInitiationRequest.getBusinessObjectDataAttributes(), targetStorageEntity, targetStorageDirectoryPath, targetStorageFilePath, uploadSingleInitiationRequest.getFile().getFileSizeBytes(), null);
// Create a target business object data instance. Set the flag to false, since for the file upload service the file size value is optional.
BusinessObjectData targetBusinessObjectData = businessObjectDataDaoHelper.createBusinessObjectData(targetBusinessObjectDataCreateRequest, false);
// Get decrypted AWS ARN of the role that is required to provide access to S3_MANAGED_LOADING_DOCK storage.
String awsRoleArn = getStorageUploadRoleArn(sourceStorageEntity);
// Get expiration interval for the pre-signed URL to be generated.
Integer awsRoleDurationSeconds = getStorageUploadSessionDuration(sourceStorageEntity);
String awsKmsKeyId = storageHelper.getStorageKmsKeyId(sourceStorageEntity);
// Get the temporary security credentials to access S3_MANAGED_STORAGE.
Credentials assumedSessionCredentials = stsDao.getTemporarySecurityCredentials(awsHelper.getAwsParamsDto(), String.valueOf(sourceBusinessObjectData.getId()), awsRoleArn, awsRoleDurationSeconds, createUploaderPolicy(s3BucketName, sourceStorageFilePath, awsKmsKeyId));
// Create the response.
UploadSingleInitiationResponse response = new UploadSingleInitiationResponse();
response.setSourceBusinessObjectData(sourceBusinessObjectData);
response.setTargetBusinessObjectData(targetBusinessObjectData);
response.setFile(uploadSingleInitiationRequest.getFile());
response.setUuid(uuid);
response.setAwsAccessKey(assumedSessionCredentials.getAccessKeyId());
response.setAwsSecretKey(assumedSessionCredentials.getSecretAccessKey());
response.setAwsSessionToken(assumedSessionCredentials.getSessionToken());
response.setAwsSessionExpirationTime(HerdDateUtils.getXMLGregorianCalendarValue(assumedSessionCredentials.getExpiration()));
response.setAwsKmsKeyId(awsKmsKeyId);
response.setTargetStorageName(targetStorageName);
return response;
}
use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class BusinessObjectDataNotificationRegistrationServiceImpl method getBusinessObjectDataNotificationRegistration.
@NamespacePermission(fields = "#key?.namespace", permissions = NamespacePermissionEnum.READ)
@Override
public BusinessObjectDataNotificationRegistration getBusinessObjectDataNotificationRegistration(NotificationRegistrationKey key) {
// Validate and trim the key.
validateBusinessObjectDataNotificationRegistrationKey(key);
// Retrieve and ensure that a business object data notification exists with the specified key.
BusinessObjectDataNotificationRegistrationEntity businessObjectDataNotificationRegistrationEntity = businessObjectDataNotificationRegistrationDaoHelper.getBusinessObjectDataNotificationRegistrationEntity(key);
// Create and return the business object data notification object from the persisted entity.
return createBusinessObjectDataNotificationFromEntity(businessObjectDataNotificationRegistrationEntity);
}
use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class BusinessObjectDataNotificationRegistrationServiceImpl method deleteBusinessObjectDataNotificationRegistration.
@NamespacePermission(fields = "#key?.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public BusinessObjectDataNotificationRegistration deleteBusinessObjectDataNotificationRegistration(NotificationRegistrationKey key) {
// Validate and trim the key.
validateBusinessObjectDataNotificationRegistrationKey(key);
// Retrieve and ensure that a business object data notification exists with the specified key.
BusinessObjectDataNotificationRegistrationEntity businessObjectDataNotificationRegistrationEntity = businessObjectDataNotificationRegistrationDaoHelper.getBusinessObjectDataNotificationRegistrationEntity(key);
// Delete the business object data notification.
businessObjectDataNotificationRegistrationDao.delete(businessObjectDataNotificationRegistrationEntity);
// Create and return the business object data notification object from the deleted entity.
return createBusinessObjectDataNotificationFromEntity(businessObjectDataNotificationRegistrationEntity);
}
use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class BusinessObjectDataServiceImpl method getAllBusinessObjectDataByBusinessObjectDefinition.
@NamespacePermission(fields = "#businessObjectDefinitionKey.namespace", permissions = NamespacePermissionEnum.READ)
@Override
public BusinessObjectDataKeys getAllBusinessObjectDataByBusinessObjectDefinition(BusinessObjectDefinitionKey businessObjectDefinitionKey) {
// Perform validation and trim.
businessObjectDefinitionHelper.validateBusinessObjectDefinitionKey(businessObjectDefinitionKey);
// Ensure that a business object definition already exists with the specified name.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(businessObjectDefinitionKey);
// Get the maximum number of records to return.
Integer maxResults = configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_DATA_SEARCH_MAX_RESULTS, Integer.class);
// Gets the list of keys and return them.
BusinessObjectDataKeys businessObjectDataKeys = new BusinessObjectDataKeys();
businessObjectDataKeys.getBusinessObjectDataKeys().addAll(businessObjectDataDao.getBusinessObjectDataByBusinessObjectDefinition(businessObjectDefinitionEntity, maxResults));
return businessObjectDataKeys;
}
use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class CustomDdlServiceImpl method deleteCustomDdl.
/**
* Deletes an existing custom DDL by key.
*
* @param customDdlKey the custom DDL key
*
* @return the custom DDL that got deleted
*/
@NamespacePermission(fields = "#customDdlKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public CustomDdl deleteCustomDdl(CustomDdlKey customDdlKey) {
// Validate and trim the key.
customDdlHelper.validateCustomDdlKey(customDdlKey);
// Retrieve and ensure that a custom DDL already exists with the specified key.
CustomDdlEntity customDdlEntity = customDdlDaoHelper.getCustomDdlEntity(customDdlKey);
// Delete the custom DDL.
customDdlDao.delete(customDdlEntity);
// Create and return the custom DDL object from the deleted entity.
return createCustomDdlFromEntity(customDdlEntity);
}
Aggregations