Search in sources :

Example 1 with NamespacePermission

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);
}
Also used : AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) TagEntity(org.finra.herd.model.jpa.TagEntity) BusinessObjectDefinitionTagEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity) BusinessObjectDefinitionTagEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 2 with NamespacePermission

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);
}
Also used : StorageUnitNotificationRegistrationEntity(org.finra.herd.model.jpa.StorageUnitNotificationRegistrationEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 3 with NamespacePermission

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;
}
Also used : StorageUnitNotificationRegistrationKeys(org.finra.herd.model.api.xml.StorageUnitNotificationRegistrationKeys) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 4 with NamespacePermission

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;
}
Also used : DownloadSingleInitiationResponse(org.finra.herd.model.api.xml.DownloadSingleInitiationResponse) S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Credentials(com.amazonaws.services.securitytoken.model.Credentials) Date(java.util.Date) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 5 with NamespacePermission

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;
}
Also used : StorageFileEntity(org.finra.herd.model.jpa.StorageFileEntity) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) UploadSingleCredentialExtensionResponse(org.finra.herd.model.api.xml.UploadSingleCredentialExtensionResponse) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Credentials(com.amazonaws.services.securitytoken.model.Credentials) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Aggregations

NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)63 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)10 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)10 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)10 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)9 AttributeValueListEntity (org.finra.herd.model.jpa.AttributeValueListEntity)6 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)5 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)5 CustomDdlEntity (org.finra.herd.model.jpa.CustomDdlEntity)5 Credentials (com.amazonaws.services.securitytoken.model.Credentials)4 ArrayList (java.util.ArrayList)4 PublishNotificationMessages (org.finra.herd.model.annotation.PublishNotificationMessages)4 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)4 IamRole (org.finra.herd.model.api.xml.IamRole)4 NamespaceIamRoleAuthorization (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization)4 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)4 NamespaceIamRoleAuthorizationEntity (org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity)4 UserNamespaceAuthorizationEntity (org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity)4 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)3 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)3