Search in sources :

Example 6 with StoragePolicyRuleTypeEntity

use of org.finra.herd.model.jpa.StoragePolicyRuleTypeEntity in project herd by FINRAOS.

the class StoragePolicyServiceImpl method createStoragePolicy.

@NamespacePermissions({ @NamespacePermission(fields = "#request?.storagePolicyKey?.namespace", permissions = NamespacePermissionEnum.WRITE), @NamespacePermission(fields = "#request?.storagePolicyFilter?.namespace", permissions = NamespacePermissionEnum.WRITE) })
@Override
public StoragePolicy createStoragePolicy(StoragePolicyCreateRequest request) {
    // Validate and trim the request parameters.
    validateStoragePolicyCreateRequest(request);
    // Get the storage policy key.
    StoragePolicyKey storagePolicyKey = request.getStoragePolicyKey();
    // Ensure a storage policy with the specified name doesn't already exist for the specified namespace.
    StoragePolicyEntity storagePolicyEntity = storagePolicyDao.getStoragePolicyByAltKey(storagePolicyKey);
    if (storagePolicyEntity != null) {
        throw new AlreadyExistsException(String.format("Unable to create storage policy with name \"%s\" because it already exists for namespace \"%s\".", storagePolicyKey.getStoragePolicyName(), storagePolicyKey.getNamespace()));
    }
    // Retrieve and ensure that namespace exists with the specified storage policy namespace code.
    NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(storagePolicyKey.getNamespace());
    // Retrieve and ensure that storage policy rule type exists.
    StoragePolicyRuleTypeEntity storagePolicyRuleTypeEntity = storagePolicyRuleTypeDaoHelper.getStoragePolicyRuleTypeEntity(request.getStoragePolicyRule().getRuleType());
    // Get the storage policy filter.
    StoragePolicyFilter storagePolicyFilter = request.getStoragePolicyFilter();
    // If specified, retrieve and ensure that the business object definition exists.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = null;
    if (StringUtils.isNotBlank(storagePolicyFilter.getBusinessObjectDefinitionName())) {
        businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(new BusinessObjectDefinitionKey(storagePolicyFilter.getNamespace(), storagePolicyFilter.getBusinessObjectDefinitionName()));
    }
    // If specified, retrieve and ensure that file type exists.
    FileTypeEntity fileTypeEntity = null;
    if (StringUtils.isNotBlank(storagePolicyFilter.getBusinessObjectFormatFileType())) {
        fileTypeEntity = fileTypeDaoHelper.getFileTypeEntity(storagePolicyFilter.getBusinessObjectFormatFileType());
    }
    // Retrieve and ensure that storage policy filter storage exists.
    StorageEntity storageEntity = storageDaoHelper.getStorageEntity(storagePolicyFilter.getStorageName());
    // Validate the source storage.
    storagePolicyDaoHelper.validateStoragePolicyFilterStorage(storageEntity);
    // Retrieve and ensure that storage policy transition type exists.
    StoragePolicyTransitionTypeEntity storagePolicyTransitionTypeEntity = storagePolicyTransitionTypeDaoHelper.getStoragePolicyTransitionTypeEntity(request.getStoragePolicyTransition().getTransitionType());
    // Retrieve and ensure that specified storage policy status exists.
    StoragePolicyStatusEntity storagePolicyStatusEntity = storagePolicyStatusDaoHelper.getStoragePolicyStatusEntity(request.getStatus());
    // Create and persist a new storage policy entity from the request information.
    storagePolicyEntity = createStoragePolicyEntity(namespaceEntity, storagePolicyKey.getStoragePolicyName(), storageEntity, storagePolicyRuleTypeEntity, request.getStoragePolicyRule().getRuleValue(), businessObjectDefinitionEntity, request.getStoragePolicyFilter().getBusinessObjectFormatUsage(), fileTypeEntity, storagePolicyTransitionTypeEntity, storagePolicyStatusEntity, StoragePolicyEntity.STORAGE_POLICY_INITIAL_VERSION, true);
    // Create and return the storage policy object from the persisted entity.
    return createStoragePolicyFromEntity(storagePolicyEntity);
}
Also used : StoragePolicyRuleTypeEntity(org.finra.herd.model.jpa.StoragePolicyRuleTypeEntity) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) StoragePolicyFilter(org.finra.herd.model.api.xml.StoragePolicyFilter) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) StoragePolicyKey(org.finra.herd.model.api.xml.StoragePolicyKey) StoragePolicyEntity(org.finra.herd.model.jpa.StoragePolicyEntity) StorageEntity(org.finra.herd.model.jpa.StorageEntity) StoragePolicyTransitionTypeEntity(org.finra.herd.model.jpa.StoragePolicyTransitionTypeEntity) StoragePolicyStatusEntity(org.finra.herd.model.jpa.StoragePolicyStatusEntity) NamespacePermissions(org.finra.herd.model.annotation.NamespacePermissions)

Aggregations

StoragePolicyRuleTypeEntity (org.finra.herd.model.jpa.StoragePolicyRuleTypeEntity)6 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)3 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)3 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)3 StorageEntity (org.finra.herd.model.jpa.StorageEntity)3 StoragePolicyEntity (org.finra.herd.model.jpa.StoragePolicyEntity)3 StoragePolicyStatusEntity (org.finra.herd.model.jpa.StoragePolicyStatusEntity)3 StoragePolicyTransitionTypeEntity (org.finra.herd.model.jpa.StoragePolicyTransitionTypeEntity)3 NamespacePermissions (org.finra.herd.model.annotation.NamespacePermissions)2 StoragePolicyFilter (org.finra.herd.model.api.xml.StoragePolicyFilter)2 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Predicate (javax.persistence.criteria.Predicate)1 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)1 StoragePolicyKey (org.finra.herd.model.api.xml.StoragePolicyKey)1 Test (org.junit.Test)1