use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class BusinessObjectDefinitionTagServiceImpl method createBusinessObjectDefinitionTag.
@NamespacePermission(fields = "#request.businessObjectDefinitionTagKey.businessObjectDefinitionKey.namespace", permissions = { NamespacePermissionEnum.WRITE_DESCRIPTIVE_CONTENT, NamespacePermissionEnum.WRITE })
@Override
public BusinessObjectDefinitionTag createBusinessObjectDefinitionTag(BusinessObjectDefinitionTagCreateRequest request) {
// Validate and trim the business object definition tag create request.
validateBusinessObjectDefinitionTagCreateRequest(request);
// Get the business object definition entity and ensure it exists.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(request.getBusinessObjectDefinitionTagKey().getBusinessObjectDefinitionKey());
// Get the tag entity and ensure it exists.
TagEntity tagEntity = tagDaoHelper.getTagEntity(request.getBusinessObjectDefinitionTagKey().getTagKey());
// Ensure a business object definition tag for the specified business object definition and tag doesn't already exist.
if (businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagByParentEntities(businessObjectDefinitionEntity, tagEntity) != null) {
throw new AlreadyExistsException(String.format("Tag with tag type \"%s\" and code \"%s\" already exists for business object definition {%s}.", request.getBusinessObjectDefinitionTagKey().getTagKey().getTagTypeCode(), request.getBusinessObjectDefinitionTagKey().getTagKey().getTagCode(), businessObjectDefinitionHelper.businessObjectDefinitionKeyToString(request.getBusinessObjectDefinitionTagKey().getBusinessObjectDefinitionKey())));
}
// Create and persist a business object definition tag entity.
BusinessObjectDefinitionTagEntity businessObjectDefinitionTagEntity = createBusinessObjectDefinitionTagEntity(businessObjectDefinitionEntity, tagEntity);
// Notify the search index that a business object definition must be updated.
searchIndexUpdateHelper.modifyBusinessObjectDefinitionInSearchIndex(businessObjectDefinitionEntity, SEARCH_INDEX_UPDATE_TYPE_UPDATE);
// Create and return the business object definition tag object from the persisted entity.
return createBusinessObjectDefinitionTagFromEntity(businessObjectDefinitionTagEntity);
}
use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class StorageUnitNotificationRegistrationServiceImpl method getStorageUnitNotificationRegistration.
@NamespacePermission(fields = "#notificationRegistrationKey?.namespace", permissions = NamespacePermissionEnum.READ)
@Override
public StorageUnitNotificationRegistration getStorageUnitNotificationRegistration(NotificationRegistrationKey notificationRegistrationKey) {
// Validate and trim the key.
validateStorageUnitNotificationRegistrationKey(notificationRegistrationKey);
// Retrieve and ensure that a storage unit notification exists with the specified key.
StorageUnitNotificationRegistrationEntity storageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDaoHelper.getStorageUnitNotificationRegistrationEntity(notificationRegistrationKey);
// Create and return the storage unit notification object from the persisted entity.
return createStorageUnitNotificationFromEntity(storageUnitNotificationRegistrationEntity);
}
use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class StorageUnitNotificationRegistrationServiceImpl method getStorageUnitNotificationRegistrationsByNotificationFilter.
@NamespacePermission(fields = "#storageUnitNotificationFilter?.namespace", permissions = NamespacePermissionEnum.READ)
@Override
public StorageUnitNotificationRegistrationKeys getStorageUnitNotificationRegistrationsByNotificationFilter(StorageUnitNotificationFilter storageUnitNotificationFilter) {
// Validate and trim the storage unit notification filter parameters.
validateStorageUnitNotificationFilterBusinessObjectDefinitionFields(storageUnitNotificationFilter);
trimStorageUnitNotificationFilterBusinessObjectFormatFields(storageUnitNotificationFilter);
// Create and populate a list of storage unit notification registration keys.
StorageUnitNotificationRegistrationKeys storageUnitNotificationKeys = new StorageUnitNotificationRegistrationKeys();
storageUnitNotificationKeys.getStorageUnitNotificationRegistrationKeys().addAll(storageUnitNotificationRegistrationDao.getStorageUnitNotificationRegistrationKeysByNotificationFilter(storageUnitNotificationFilter));
return storageUnitNotificationKeys;
}
use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class UploadDownloadServiceImpl method initiateDownloadSingle.
@NamespacePermission(fields = "#namespace", permissions = NamespacePermissionEnum.READ)
@Override
public DownloadSingleInitiationResponse initiateDownloadSingle(String namespace, String businessObjectDefinitionName, String businessObjectFormatUsage, String businessObjectFormatFileType, Integer businessObjectFormatVersion, String partitionValue, Integer businessObjectDataVersion) {
// Create the business object data key.
BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(namespace, businessObjectDefinitionName, businessObjectFormatUsage, businessObjectFormatFileType, businessObjectFormatVersion, partitionValue, null, businessObjectDataVersion);
// Validate the parameters
businessObjectDataHelper.validateBusinessObjectDataKey(businessObjectDataKey, true, true);
// Retrieve the persisted business object data
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey);
// Make sure the status of the business object data is VALID
businessObjectDataHelper.assertBusinessObjectDataStatusEquals(BusinessObjectDataStatusEntity.VALID, businessObjectDataEntity);
// Get the external storage registered against this data
// Validate that the storage unit exists
StorageUnitEntity storageUnitEntity = IterableUtils.get(businessObjectDataEntity.getStorageUnits(), 0);
// Validate that the storage unit contains only 1 file
assertHasOneStorageFile(storageUnitEntity);
String s3BucketName = storageHelper.getStorageBucketName(storageUnitEntity.getStorage());
String s3ObjectKey = IterableUtils.get(storageUnitEntity.getStorageFiles(), 0).getPath();
// Get the temporary credentials
Credentials downloaderCredentials = getExternalDownloaderCredentials(storageUnitEntity.getStorage(), String.valueOf(businessObjectDataEntity.getId()), s3ObjectKey);
// Generate a pre-signed URL
Date expiration = downloaderCredentials.getExpiration();
S3FileTransferRequestParamsDto s3BucketAccessParams = storageHelper.getS3BucketAccessParams(storageUnitEntity.getStorage());
String presignedUrl = s3Dao.generateGetObjectPresignedUrl(s3BucketName, s3ObjectKey, expiration, s3BucketAccessParams);
// Construct and return the response
DownloadSingleInitiationResponse response = new DownloadSingleInitiationResponse();
response.setBusinessObjectData(businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity));
response.setAwsAccessKey(downloaderCredentials.getAccessKeyId());
response.setAwsSecretKey(downloaderCredentials.getSecretAccessKey());
response.setAwsSessionToken(downloaderCredentials.getSessionToken());
response.setAwsSessionExpirationTime(HerdDateUtils.getXMLGregorianCalendarValue(expiration));
response.setPreSignedUrl(presignedUrl);
return response;
}
use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.
the class UploadDownloadServiceImpl method extendUploadSingleCredentials.
@NamespacePermission(fields = "#namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public UploadSingleCredentialExtensionResponse extendUploadSingleCredentials(String namespace, String businessObjectDefinitionName, String businessObjectFormatUsage, String businessObjectFormatFileType, Integer businessObjectFormatVersion, String partitionValue, Integer businessObjectDataVersion) {
// Create the business object data key.
BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(namespace, businessObjectDefinitionName, businessObjectFormatUsage, businessObjectFormatFileType, businessObjectFormatVersion, partitionValue, null, businessObjectDataVersion);
// Validate and trim the business object data key.
businessObjectDataHelper.validateBusinessObjectDataKey(businessObjectDataKey, true, true);
// Get the business object data for the key.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey);
// Ensure the status of the business object data is "uploading" in order to extend credentials.
if (!(businessObjectDataEntity.getStatus().getCode().equals(BusinessObjectDataStatusEntity.UPLOADING))) {
throw new IllegalArgumentException(String.format(String.format("Business object data {%s} has a status of \"%s\" and must be \"%s\" to extend " + "credentials.", businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey), businessObjectDataEntity.getStatus().getCode(), BusinessObjectDataStatusEntity.UPLOADING)));
}
// Get the S3 managed "loading dock" storage entity and make sure it exists.
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE);
String s3BucketName = storageHelper.getStorageBucketName(storageEntity);
// Get the storage unit entity for this business object data in the S3 managed "loading dock" storage and make sure it exists.
StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, businessObjectDataEntity);
// Validate that the storage unit contains exactly one storage file.
assertHasOneStorageFile(storageUnitEntity);
// Get the storage file entity.
StorageFileEntity storageFileEntity = IterableUtils.get(storageUnitEntity.getStorageFiles(), 0);
// Get the storage file path.
String storageFilePath = storageFileEntity.getPath();
String awsRoleArn = getStorageUploadRoleArn(storageEntity);
Integer awsRoleDurationSeconds = getStorageUploadSessionDuration(storageEntity);
String awsKmsKeyId = storageHelper.getStorageKmsKeyId(storageEntity);
// Get the temporary security credentials to access S3_MANAGED_STORAGE.
Credentials assumedSessionCredentials = stsDao.getTemporarySecurityCredentials(awsHelper.getAwsParamsDto(), String.valueOf(businessObjectDataEntity.getId()), awsRoleArn, awsRoleDurationSeconds, createUploaderPolicy(s3BucketName, storageFilePath, awsKmsKeyId));
// Create the response.
UploadSingleCredentialExtensionResponse response = new UploadSingleCredentialExtensionResponse();
response.setAwsAccessKey(assumedSessionCredentials.getAccessKeyId());
response.setAwsSecretKey(assumedSessionCredentials.getSecretAccessKey());
response.setAwsSessionToken(assumedSessionCredentials.getSessionToken());
response.setAwsSessionExpirationTime(HerdDateUtils.getXMLGregorianCalendarValue(assumedSessionCredentials.getExpiration()));
return response;
}
Aggregations