Search in sources :

Example 16 with StoragePolicyFilter

use of org.finra.herd.model.api.xml.StoragePolicyFilter in project herd by FINRAOS.

the class StoragePolicyServiceTest method testUpdateStoragePolicy.

// Unit tests for updateStoragePolicy().
@Test
public void testUpdateStoragePolicy() {
    // Create a storage policy key.
    StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME);
    // Create and persist the relative database entities.
    storagePolicyServiceTestHelper.createDatabaseEntitiesForStoragePolicyTesting();
    // Create and persist a storage policy entity.
    StoragePolicyEntity storagePolicyEntity = storagePolicyDaoTestHelper.createStoragePolicyEntity(storagePolicyKey, STORAGE_POLICY_RULE_TYPE_2, STORAGE_POLICY_RULE_VALUE_2, BDEF_NAMESPACE_2, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, STORAGE_NAME_2, STORAGE_POLICY_TRANSITION_TYPE_2, StoragePolicyStatusEntity.ENABLED, INITIAL_VERSION, LATEST_VERSION_FLAG_SET);
    // Update a storage policy.
    StoragePolicy resultStoragePolicy = storagePolicyService.updateStoragePolicy(storagePolicyKey, storagePolicyServiceTestHelper.createStoragePolicyUpdateRequest(STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.DISABLED));
    // Validate the returned object.
    assertEquals(new StoragePolicy(resultStoragePolicy.getId(), storagePolicyKey, new StoragePolicyRule(STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE), new StoragePolicyFilter(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME), new StoragePolicyTransition(STORAGE_POLICY_TRANSITION_TYPE), StoragePolicyStatusEntity.DISABLED), resultStoragePolicy);
    assertTrue(resultStoragePolicy.getId() > storagePolicyEntity.getId());
}
Also used : StoragePolicyRule(org.finra.herd.model.api.xml.StoragePolicyRule) StoragePolicyTransition(org.finra.herd.model.api.xml.StoragePolicyTransition) StoragePolicyFilter(org.finra.herd.model.api.xml.StoragePolicyFilter) StoragePolicyKey(org.finra.herd.model.api.xml.StoragePolicyKey) StoragePolicyEntity(org.finra.herd.model.jpa.StoragePolicyEntity) StoragePolicy(org.finra.herd.model.api.xml.StoragePolicy) Test(org.junit.Test)

Example 17 with StoragePolicyFilter

use of org.finra.herd.model.api.xml.StoragePolicyFilter in project herd by FINRAOS.

the class StoragePolicyRestControllerTest method testCreateStoragePolicy.

@Test
public void testCreateStoragePolicy() {
    // Create a storage policy key.
    StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME);
    StoragePolicy storagePolicy = new StoragePolicy(ID, storagePolicyKey, new StoragePolicyRule(STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE), new StoragePolicyFilter(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME), new StoragePolicyTransition(STORAGE_POLICY_TRANSITION_TYPE), StoragePolicyStatusEntity.ENABLED);
    StoragePolicyCreateRequest request = storagePolicyServiceTestHelper.createStoragePolicyCreateRequest(storagePolicyKey, STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE, BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, STORAGE_NAME, STORAGE_POLICY_TRANSITION_TYPE, StoragePolicyStatusEntity.ENABLED);
    when(storagePolicyService.createStoragePolicy(request)).thenReturn(storagePolicy);
    // Create a storage policy.
    StoragePolicy resultStoragePolicy = storagePolicyRestController.createStoragePolicy(request);
    // Verify the external calls.
    verify(storagePolicyService).createStoragePolicy(request);
    verifyNoMoreInteractions(storagePolicyService);
    // Validate the returned object.
    assertEquals(storagePolicy, resultStoragePolicy);
}
Also used : StoragePolicyRule(org.finra.herd.model.api.xml.StoragePolicyRule) StoragePolicyTransition(org.finra.herd.model.api.xml.StoragePolicyTransition) StoragePolicyFilter(org.finra.herd.model.api.xml.StoragePolicyFilter) StoragePolicyKey(org.finra.herd.model.api.xml.StoragePolicyKey) StoragePolicy(org.finra.herd.model.api.xml.StoragePolicy) StoragePolicyCreateRequest(org.finra.herd.model.api.xml.StoragePolicyCreateRequest) Test(org.junit.Test)

Example 18 with StoragePolicyFilter

use of org.finra.herd.model.api.xml.StoragePolicyFilter 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)

Example 19 with StoragePolicyFilter

use of org.finra.herd.model.api.xml.StoragePolicyFilter 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)

Example 20 with StoragePolicyFilter

use of org.finra.herd.model.api.xml.StoragePolicyFilter in project herd by FINRAOS.

the class StoragePolicyServiceTest method testUpdateStoragePolicyUpperCaseParameters.

@Test
public void testUpdateStoragePolicyUpperCaseParameters() {
    // Create a storage policy key.
    StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME);
    // Create and persist the relative database entities.
    storagePolicyServiceTestHelper.createDatabaseEntitiesForStoragePolicyTesting();
    // Create and persist a storage policy entity.
    StoragePolicyEntity storagePolicyEntity = storagePolicyDaoTestHelper.createStoragePolicyEntity(storagePolicyKey, STORAGE_POLICY_RULE_TYPE_2, STORAGE_POLICY_RULE_VALUE_2, BDEF_NAMESPACE_2, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, STORAGE_NAME_2, STORAGE_POLICY_TRANSITION_TYPE_2, StoragePolicyStatusEntity.ENABLED, INITIAL_VERSION, LATEST_VERSION_FLAG_SET);
    // Update a storage policy using upper case input parameters.
    StoragePolicy resultStoragePolicy = storagePolicyService.updateStoragePolicy(new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD.toUpperCase(), STORAGE_POLICY_NAME.toUpperCase()), storagePolicyServiceTestHelper.createStoragePolicyUpdateRequest(STORAGE_POLICY_RULE_TYPE.toUpperCase(), STORAGE_POLICY_RULE_VALUE, BDEF_NAMESPACE.toUpperCase(), BDEF_NAME.toUpperCase(), FORMAT_USAGE_CODE.toUpperCase(), FORMAT_FILE_TYPE_CODE.toUpperCase(), STORAGE_NAME.toUpperCase(), STORAGE_POLICY_TRANSITION_TYPE.toUpperCase(), StoragePolicyStatusEntity.DISABLED.toUpperCase()));
    // Validate the returned object.
    assertEquals(new StoragePolicy(resultStoragePolicy.getId(), new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME), new StoragePolicyRule(STORAGE_POLICY_RULE_TYPE, STORAGE_POLICY_RULE_VALUE), new StoragePolicyFilter(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE.toUpperCase(), FORMAT_FILE_TYPE_CODE, STORAGE_NAME), new StoragePolicyTransition(STORAGE_POLICY_TRANSITION_TYPE), StoragePolicyStatusEntity.DISABLED), resultStoragePolicy);
    assertTrue(resultStoragePolicy.getId() > storagePolicyEntity.getId());
}
Also used : StoragePolicyRule(org.finra.herd.model.api.xml.StoragePolicyRule) StoragePolicyTransition(org.finra.herd.model.api.xml.StoragePolicyTransition) StoragePolicyFilter(org.finra.herd.model.api.xml.StoragePolicyFilter) StoragePolicyKey(org.finra.herd.model.api.xml.StoragePolicyKey) StoragePolicyEntity(org.finra.herd.model.jpa.StoragePolicyEntity) StoragePolicy(org.finra.herd.model.api.xml.StoragePolicy) Test(org.junit.Test)

Aggregations

StoragePolicyFilter (org.finra.herd.model.api.xml.StoragePolicyFilter)24 StoragePolicyRule (org.finra.herd.model.api.xml.StoragePolicyRule)22 StoragePolicyTransition (org.finra.herd.model.api.xml.StoragePolicyTransition)22 StoragePolicyKey (org.finra.herd.model.api.xml.StoragePolicyKey)21 StoragePolicy (org.finra.herd.model.api.xml.StoragePolicy)20 Test (org.junit.Test)19 StoragePolicyEntity (org.finra.herd.model.jpa.StoragePolicyEntity)12 NamespacePermissions (org.finra.herd.model.annotation.NamespacePermissions)2 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)2 StoragePolicyCreateRequest (org.finra.herd.model.api.xml.StoragePolicyCreateRequest)2 StoragePolicyUpdateRequest (org.finra.herd.model.api.xml.StoragePolicyUpdateRequest)2 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)2 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)2 StorageEntity (org.finra.herd.model.jpa.StorageEntity)2 StoragePolicyRuleTypeEntity (org.finra.herd.model.jpa.StoragePolicyRuleTypeEntity)2 StoragePolicyStatusEntity (org.finra.herd.model.jpa.StoragePolicyStatusEntity)2 StoragePolicyTransitionTypeEntity (org.finra.herd.model.jpa.StoragePolicyTransitionTypeEntity)2 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)1 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)1