Search in sources :

Example 1 with StoragePolicyRuleTypeEntity

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

the class StoragePolicyRuleTypeDaoTestHelper method createStoragePolicyRuleTypeEntity.

/**
 * Creates and persists a new storage policy rule type entity.
 *
 * @param code the storage policy rule type code
 *
 * @return the newly created storage policy rule type entity
 */
public StoragePolicyRuleTypeEntity createStoragePolicyRuleTypeEntity(String code, String description) {
    StoragePolicyRuleTypeEntity storagePolicyRuleTypeEntity = new StoragePolicyRuleTypeEntity();
    storagePolicyRuleTypeEntity.setCode(code);
    storagePolicyRuleTypeEntity.setDescription(description);
    return storagePolicyRuleTypeDao.saveAndRefresh(storagePolicyRuleTypeEntity);
}
Also used : StoragePolicyRuleTypeEntity(org.finra.herd.model.jpa.StoragePolicyRuleTypeEntity)

Example 2 with StoragePolicyRuleTypeEntity

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

the class StoragePolicyRuleTypeDaoImpl method getStoragePolicyRuleTypeByCode.

@Override
public StoragePolicyRuleTypeEntity getStoragePolicyRuleTypeByCode(String code) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<StoragePolicyRuleTypeEntity> criteria = builder.createQuery(StoragePolicyRuleTypeEntity.class);
    // The criteria root is the storage policy rule type.
    Root<StoragePolicyRuleTypeEntity> storagePolicyRuleTypeEntity = criteria.from(StoragePolicyRuleTypeEntity.class);
    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate queryRestriction = builder.equal(builder.upper(storagePolicyRuleTypeEntity.get(StoragePolicyRuleTypeEntity_.code)), code.toUpperCase());
    criteria.select(storagePolicyRuleTypeEntity).where(queryRestriction);
    return executeSingleResultQuery(criteria, String.format("Found more than one storage policy rule type with code \"%s\".", code));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) StoragePolicyRuleTypeEntity(org.finra.herd.model.jpa.StoragePolicyRuleTypeEntity) Predicate(javax.persistence.criteria.Predicate)

Example 3 with StoragePolicyRuleTypeEntity

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

the class StoragePolicyRuleTypeDaoTest method testGetStoragePolicyRuleTypeByCode.

@Test
public void testGetStoragePolicyRuleTypeByCode() {
    // Create and persist a storage policy rule type entity.
    StoragePolicyRuleTypeEntity storagePolicyRuleTypeEntity = storagePolicyRuleTypeDaoTestHelper.createStoragePolicyRuleTypeEntity(STORAGE_POLICY_RULE_TYPE, DESCRIPTION);
    // Retrieve this storage policy rule type entity by code.
    StoragePolicyRuleTypeEntity resultStoragePolicyRuleTypeEntity = storagePolicyRuleTypeDao.getStoragePolicyRuleTypeByCode(STORAGE_POLICY_RULE_TYPE);
    // Validate the returned object.
    assertNotNull(resultStoragePolicyRuleTypeEntity);
    assertEquals(storagePolicyRuleTypeEntity.getCode(), resultStoragePolicyRuleTypeEntity.getCode());
    // Retrieve this storage policy rule type entity by code in upper case.
    resultStoragePolicyRuleTypeEntity = storagePolicyRuleTypeDao.getStoragePolicyRuleTypeByCode(STORAGE_POLICY_RULE_TYPE.toUpperCase());
    // Validate the returned object.
    assertNotNull(resultStoragePolicyRuleTypeEntity);
    assertEquals(storagePolicyRuleTypeEntity.getCode(), resultStoragePolicyRuleTypeEntity.getCode());
    // Retrieve this storage policy rule type entity by code in lower case.
    resultStoragePolicyRuleTypeEntity = storagePolicyRuleTypeDao.getStoragePolicyRuleTypeByCode(STORAGE_POLICY_RULE_TYPE.toLowerCase());
    // Validate the returned object.
    assertNotNull(resultStoragePolicyRuleTypeEntity);
    assertEquals(storagePolicyRuleTypeEntity.getCode(), resultStoragePolicyRuleTypeEntity.getCode());
}
Also used : StoragePolicyRuleTypeEntity(org.finra.herd.model.jpa.StoragePolicyRuleTypeEntity) Test(org.junit.Test)

Example 4 with StoragePolicyRuleTypeEntity

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

the class StoragePolicyDaoTestHelper method createStoragePolicyEntity.

/**
 * Creates and persists a storage policy entity.
 *
 * @param storagePolicyKey the storage policy key
 * @param storagePolicyRuleType the storage policy rule type
 * @param storagePolicyRuleValue the storage policy rule value
 * @param businessObjectDefinitionNamespace the business object definition namespace
 * @param businessObjectDefinitionName the business object definition name
 * @param businessObjectFormatUsage the business object usage
 * @param businessObjectFormatFileType the business object format file type
 * @param storageName the storage name
 * @param storagePolicyTransitionType the transition type of the storage policy
 * @param storagePolicyStatus the storage policy status
 * @param storagePolicyVersion the storage policy version
 * @param storagePolicyLatestVersion specifies if this storage policy is flagged as latest version or not
 *
 * @return the newly created storage policy entity
 */
public StoragePolicyEntity createStoragePolicyEntity(StoragePolicyKey storagePolicyKey, String storagePolicyRuleType, Integer storagePolicyRuleValue, String businessObjectDefinitionNamespace, String businessObjectDefinitionName, String businessObjectFormatUsage, String businessObjectFormatFileType, String storageName, String storagePolicyTransitionType, String storagePolicyStatus, Integer storagePolicyVersion, Boolean storagePolicyLatestVersion) {
    // Create a storage policy namespace entity if needed.
    NamespaceEntity storagePolicyNamespaceEntity = namespaceDao.getNamespaceByCd(storagePolicyKey.getNamespace());
    if (storagePolicyNamespaceEntity == null) {
        storagePolicyNamespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(storagePolicyKey.getNamespace());
    }
    // Create a storage policy rule type type entity if needed.
    StoragePolicyRuleTypeEntity storagePolicyRuleTypeEntity = storagePolicyRuleTypeDao.getStoragePolicyRuleTypeByCode(storagePolicyRuleType);
    if (storagePolicyRuleTypeEntity == null) {
        storagePolicyRuleTypeEntity = storagePolicyRuleTypeDaoTestHelper.createStoragePolicyRuleTypeEntity(storagePolicyRuleType, AbstractDaoTest.DESCRIPTION);
    }
    // Create a business object definition entity if needed.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = null;
    if (StringUtils.isNotBlank(businessObjectDefinitionName)) {
        businessObjectDefinitionEntity = businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(new BusinessObjectDefinitionKey(businessObjectDefinitionNamespace, businessObjectDefinitionName));
        if (businessObjectDefinitionEntity == null) {
            // Create a business object definition.
            businessObjectDefinitionEntity = businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(businessObjectDefinitionNamespace, businessObjectDefinitionName, AbstractDaoTest.DATA_PROVIDER_NAME, AbstractDaoTest.BDEF_DESCRIPTION);
        }
    }
    // Create a business object format file type entity if needed.
    FileTypeEntity fileTypeEntity = null;
    if (StringUtils.isNotBlank(businessObjectFormatFileType)) {
        fileTypeEntity = fileTypeDao.getFileTypeByCode(businessObjectFormatFileType);
        if (fileTypeEntity == null) {
            fileTypeEntity = fileTypeDaoTestHelper.createFileTypeEntity(businessObjectFormatFileType);
        }
    }
    // Create a storage entity of S3 storage platform type if needed.
    StorageEntity storageEntity = storageDao.getStorageByName(storageName);
    if (storageEntity == null) {
        storageEntity = storageDaoTestHelper.createStorageEntity(storageName, StoragePlatformEntity.S3);
    }
    // Create a storage policy transition type entity, if not exists.
    StoragePolicyTransitionTypeEntity storagePolicyTransitionTypeEntity = storagePolicyTransitionTypeDao.getStoragePolicyTransitionTypeByCode(storagePolicyTransitionType);
    if (storagePolicyTransitionTypeEntity == null) {
        storagePolicyTransitionTypeEntity = createStoragePolicyTransitionTypeEntity(storagePolicyTransitionType);
    }
    // Create a storage policy status entity, if not exists.
    StoragePolicyStatusEntity storagePolicyStatusEntity = storagePolicyStatusDao.getStoragePolicyStatusByCode(storagePolicyStatus);
    if (storagePolicyStatusEntity == null) {
        storagePolicyStatusEntity = createStoragePolicyStatusEntity(storagePolicyStatus);
    }
    // Create a storage policy entity.
    StoragePolicyEntity storagePolicyEntity = new StoragePolicyEntity();
    storagePolicyEntity.setNamespace(storagePolicyNamespaceEntity);
    storagePolicyEntity.setName(storagePolicyKey.getStoragePolicyName());
    storagePolicyEntity.setStoragePolicyRuleType(storagePolicyRuleTypeEntity);
    storagePolicyEntity.setStoragePolicyRuleValue(storagePolicyRuleValue);
    storagePolicyEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
    storagePolicyEntity.setUsage(businessObjectFormatUsage);
    storagePolicyEntity.setFileType(fileTypeEntity);
    storagePolicyEntity.setStorage(storageEntity);
    storagePolicyEntity.setStoragePolicyTransitionType(storagePolicyTransitionTypeEntity);
    storagePolicyEntity.setStatus(storagePolicyStatusEntity);
    storagePolicyEntity.setVersion(storagePolicyVersion);
    storagePolicyEntity.setLatestVersion(storagePolicyLatestVersion);
    return storagePolicyDao.saveAndRefresh(storagePolicyEntity);
}
Also used : StoragePolicyRuleTypeEntity(org.finra.herd.model.jpa.StoragePolicyRuleTypeEntity) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) 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)

Example 5 with StoragePolicyRuleTypeEntity

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

the class StoragePolicyServiceImpl method updateStoragePolicy.

@NamespacePermissions({ @NamespacePermission(fields = "#storagePolicyKey?.namespace", permissions = NamespacePermissionEnum.WRITE), @NamespacePermission(fields = "#request?.storagePolicyFilter?.namespace", permissions = NamespacePermissionEnum.WRITE) })
@Override
public StoragePolicy updateStoragePolicy(StoragePolicyKey storagePolicyKey, StoragePolicyUpdateRequest request) {
    // Validate and trim the key.
    storagePolicyHelper.validateStoragePolicyKey(storagePolicyKey);
    // Retrieve and ensure that a storage policy exists with the specified key.
    StoragePolicyEntity storagePolicyEntity = storagePolicyDaoHelper.getStoragePolicyEntityByKey(storagePolicyKey);
    // Validate and trim the request parameters.
    validateStoragePolicyUpdateRequest(request);
    // Retrieve and ensure that storage policy 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.
    // Please note that simply adding 1 to the latest version without "DB locking" is sufficient here,
    // even for multi-threading, since we are relying on the DB having version as part of the alternate key.
    StoragePolicyEntity newVersionStoragePolicyEntity = createStoragePolicyEntity(storagePolicyEntity.getNamespace(), storagePolicyEntity.getName(), storageEntity, storagePolicyRuleTypeEntity, request.getStoragePolicyRule().getRuleValue(), businessObjectDefinitionEntity, request.getStoragePolicyFilter().getBusinessObjectFormatUsage(), fileTypeEntity, storagePolicyTransitionTypeEntity, storagePolicyStatusEntity, storagePolicyEntity.getVersion() + 1, true);
    // Update the existing latest version storage policy entity, so it would not be flagged as the latest version anymore.
    storagePolicyEntity.setLatestVersion(false);
    storagePolicyDao.saveAndRefresh(storagePolicyEntity);
    // Create and return the storage policy object from the new version entity.
    return createStoragePolicyFromEntity(newVersionStoragePolicyEntity);
}
Also used : StoragePolicyRuleTypeEntity(org.finra.herd.model.jpa.StoragePolicyRuleTypeEntity) 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) 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