Search in sources :

Example 1 with StoragePolicyTransitionTypeEntity

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

the class StoragePolicyTransitionTypeDaoTestHelper method createStoragePolicyTransitionTypeEntity.

/**
 * 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 StoragePolicyTransitionTypeEntity createStoragePolicyTransitionTypeEntity(String code) {
    StoragePolicyTransitionTypeEntity storagePolicyTransitionTypeEntity = new StoragePolicyTransitionTypeEntity();
    storagePolicyTransitionTypeEntity.setCode(code);
    return storagePolicyTransitionTypeDao.saveAndRefresh(storagePolicyTransitionTypeEntity);
}
Also used : StoragePolicyTransitionTypeEntity(org.finra.herd.model.jpa.StoragePolicyTransitionTypeEntity)

Example 2 with StoragePolicyTransitionTypeEntity

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

the class StoragePolicyTransitionTypeDaoImpl method getStoragePolicyTransitionTypeByCode.

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

Example 3 with StoragePolicyTransitionTypeEntity

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

the class StoragePolicyTransitionTypeDaoTest method testGetStoragePolicyTransitionTypeByCode.

@Test
public void testGetStoragePolicyTransitionTypeByCode() {
    // Create and persist a storage policy rule type entity.
    StoragePolicyTransitionTypeEntity storagePolicyTransitionTypeEntity = storagePolicyTransitionTypeDaoTestHelper.createStoragePolicyTransitionTypeEntity(STORAGE_POLICY_TRANSITION_TYPE);
    // Retrieve this storage policy rule type entity by code.
    StoragePolicyTransitionTypeEntity resultStoragePolicyTransitionTypeEntity = storagePolicyTransitionTypeDao.getStoragePolicyTransitionTypeByCode(STORAGE_POLICY_TRANSITION_TYPE);
    // Validate the returned object.
    assertNotNull(resultStoragePolicyTransitionTypeEntity);
    assertEquals(storagePolicyTransitionTypeEntity.getCode(), resultStoragePolicyTransitionTypeEntity.getCode());
    // Retrieve this storage policy rule type entity by code in upper case.
    resultStoragePolicyTransitionTypeEntity = storagePolicyTransitionTypeDao.getStoragePolicyTransitionTypeByCode(STORAGE_POLICY_TRANSITION_TYPE.toUpperCase());
    // Validate the returned object.
    assertNotNull(resultStoragePolicyTransitionTypeEntity);
    assertEquals(storagePolicyTransitionTypeEntity.getCode(), resultStoragePolicyTransitionTypeEntity.getCode());
    // Retrieve this storage policy rule type entity by code in lower case.
    resultStoragePolicyTransitionTypeEntity = storagePolicyTransitionTypeDao.getStoragePolicyTransitionTypeByCode(STORAGE_POLICY_TRANSITION_TYPE.toLowerCase());
    // Validate the returned object.
    assertNotNull(resultStoragePolicyTransitionTypeEntity);
    assertEquals(storagePolicyTransitionTypeEntity.getCode(), resultStoragePolicyTransitionTypeEntity.getCode());
}
Also used : StoragePolicyTransitionTypeEntity(org.finra.herd.model.jpa.StoragePolicyTransitionTypeEntity) Test(org.junit.Test)

Example 4 with StoragePolicyTransitionTypeEntity

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

the class StoragePolicyDaoTestHelper method createStoragePolicyTransitionTypeEntity.

/**
 * Creates and persists a new storage policy transition type entity.
 *
 * @param storagePolicyTransitionType the transition type of the storage policy
 *
 * @return the newly created storage policy transition type entity
 */
public StoragePolicyTransitionTypeEntity createStoragePolicyTransitionTypeEntity(String storagePolicyTransitionType) {
    StoragePolicyTransitionTypeEntity storagePolicyTransitionTypeEntity = new StoragePolicyTransitionTypeEntity();
    storagePolicyTransitionTypeEntity.setCode(storagePolicyTransitionType);
    return storagePolicyTransitionTypeDao.saveAndRefresh(storagePolicyTransitionTypeEntity);
}
Also used : StoragePolicyTransitionTypeEntity(org.finra.herd.model.jpa.StoragePolicyTransitionTypeEntity)

Example 5 with StoragePolicyTransitionTypeEntity

use of org.finra.herd.model.jpa.StoragePolicyTransitionTypeEntity 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)

Aggregations

StoragePolicyTransitionTypeEntity (org.finra.herd.model.jpa.StoragePolicyTransitionTypeEntity)9 StoragePolicyEntity (org.finra.herd.model.jpa.StoragePolicyEntity)5 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)4 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)4 StorageEntity (org.finra.herd.model.jpa.StorageEntity)4 StoragePolicyStatusEntity (org.finra.herd.model.jpa.StoragePolicyStatusEntity)4 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)3 StoragePolicyRuleTypeEntity (org.finra.herd.model.jpa.StoragePolicyRuleTypeEntity)3 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Predicate (javax.persistence.criteria.Predicate)2 NamespacePermissions (org.finra.herd.model.annotation.NamespacePermissions)2 StoragePolicyFilter (org.finra.herd.model.api.xml.StoragePolicyFilter)2 StoragePolicyKey (org.finra.herd.model.api.xml.StoragePolicyKey)2 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)2 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)2 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)2 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)2 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)2 StorageUnitStatusEntity (org.finra.herd.model.jpa.StorageUnitStatusEntity)2 Test (org.junit.Test)2