use of org.finra.herd.model.jpa.StorageEntity in project herd by FINRAOS.
the class StorageHelperTest method testGetStorageAttributeIntegerValueByName_4.
/**
* Storage attribute: abcd Attribute required: false Attribute required if exists: false Assert throw
*/
@Test
public void testGetStorageAttributeIntegerValueByName_4() {
String attributeName = "test";
String attributeValue = "abcd";
StorageEntity storageEntity = storageDaoTestHelper.createStorageEntityWithAttributes(attributeName, attributeValue);
boolean attributeRequired = false;
boolean attributeValueRequiredIfExists = false;
try {
storageHelper.getStorageAttributeIntegerValueByName(attributeName, storageEntity, attributeRequired, attributeValueRequiredIfExists);
fail();
} catch (Exception e) {
assertEquals(IllegalStateException.class, e.getClass());
assertEquals("Storage attribute \"" + attributeName + "\" must be a valid integer. Actual value is \"" + attributeValue + "\"", e.getMessage());
}
}
use of org.finra.herd.model.jpa.StorageEntity in project herd by FINRAOS.
the class StorageHelperTest method testGetStorageAttributeIntegerValueByName_12.
/**
* Storage attribute: null Attribute required: true Attribute required if exists: false Assert throw
*/
@Test
public void testGetStorageAttributeIntegerValueByName_12() {
String attributeName = "test";
String attributeValue = null;
StorageEntity storageEntity = storageDaoTestHelper.createStorageEntityWithAttributes(attributeName, attributeValue);
boolean attributeRequired = true;
boolean attributeValueRequiredIfExists = false;
Integer value = storageHelper.getStorageAttributeIntegerValueByName(attributeName, storageEntity, attributeRequired, attributeValueRequiredIfExists);
assertEquals(attributeValue, value);
}
use of org.finra.herd.model.jpa.StorageEntity in project herd by FINRAOS.
the class ExpireRestoredBusinessObjectDataHelperServiceImplTest method testPrepareToExpireStorageUnit.
@Test
public void testPrepareToExpireStorageUnit() {
// Create a business object data key.
BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION);
// Create a storage unit key.
BusinessObjectDataStorageUnitKey storageUnitKey = new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME);
// Create a storage entity.
StorageEntity storageEntity = new StorageEntity();
storageEntity.setName(STORAGE_NAME);
// Create a business object format entity.
BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity();
// Create a business object data entity.
BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity);
// Create a new storage unit status entity.
StorageUnitStatusEntity newStorageUnitStatusEntity = new StorageUnitStatusEntity();
newStorageUnitStatusEntity.setCode(StorageUnitStatusEntity.EXPIRING);
// Create an old storage unit status entity.
StorageUnitStatusEntity oldStorageUnitStatusEntity = new StorageUnitStatusEntity();
oldStorageUnitStatusEntity.setCode(StorageUnitStatusEntity.RESTORED);
// Create a list of storage file entities.
List<StorageFileEntity> storageFileEntities = Arrays.asList(new StorageFileEntity());
// Create a storage unit entity.
StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
storageUnitEntity.setStorage(storageEntity);
storageUnitEntity.setBusinessObjectData(businessObjectDataEntity);
storageUnitEntity.setStatus(oldStorageUnitStatusEntity);
storageUnitEntity.setStorageFiles(storageFileEntities);
// Create a list of storage files.
List<StorageFile> storageFiles = Arrays.asList(new StorageFile(S3_KEY, FILE_SIZE, ROW_COUNT));
// Mock the external calls.
when(businessObjectDataHelper.createBusinessObjectDataKeyFromStorageUnitKey(storageUnitKey)).thenReturn(businessObjectDataKey);
when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey)).thenReturn(businessObjectDataEntity);
when(storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity)).thenReturn(storageUnitEntity);
when(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME)).thenReturn(S3_ATTRIBUTE_NAME_BUCKET_NAME);
when(storageHelper.getStorageAttributeValueByName(S3_ATTRIBUTE_NAME_BUCKET_NAME, storageEntity, true)).thenReturn(S3_BUCKET_NAME);
when(s3KeyPrefixHelper.buildS3KeyPrefix(storageEntity, businessObjectFormatEntity, businessObjectDataKey)).thenReturn(S3_KEY_PREFIX);
when(storageFileHelper.getAndValidateStorageFiles(storageUnitEntity, S3_KEY_PREFIX, STORAGE_NAME, businessObjectDataKey)).thenReturn(storageFiles);
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) {
// Get the storage unit entity.
StorageUnitEntity storageUnitEntity = (StorageUnitEntity) invocation.getArguments()[0];
// Update the storage unit status.
storageUnitEntity.setStatus(newStorageUnitStatusEntity);
return null;
}
}).when(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.EXPIRING, StorageUnitStatusEntity.EXPIRING);
when(configurationHelper.getProperty(ConfigurationValue.S3_ENDPOINT)).thenReturn(S3_ENDPOINT);
// Call the method under test.
BusinessObjectDataRestoreDto result = expireRestoredBusinessObjectDataHelperServiceImpl.prepareToExpireStorageUnit(storageUnitKey);
// Verify the external calls.
verify(businessObjectDataHelper).createBusinessObjectDataKeyFromStorageUnitKey(storageUnitKey);
verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey);
verify(storageUnitDaoHelper).getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
verify(configurationHelper).getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME);
verify(storageHelper).getStorageAttributeValueByName(S3_ATTRIBUTE_NAME_BUCKET_NAME, storageEntity, true);
verify(s3KeyPrefixHelper).buildS3KeyPrefix(storageEntity, businessObjectFormatEntity, businessObjectDataKey);
verify(storageFileHelper).getAndValidateStorageFiles(storageUnitEntity, S3_KEY_PREFIX, STORAGE_NAME, businessObjectDataKey);
verify(storageFileDaoHelper).validateStorageFilesCount(STORAGE_NAME, businessObjectDataKey, S3_KEY_PREFIX, storageFiles.size());
verify(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.EXPIRING, StorageUnitStatusEntity.EXPIRING);
verify(configurationHelper).getProperty(ConfigurationValue.S3_ENDPOINT);
verifyNoMoreInteractionsHelper();
// Validate the result.
assertEquals(new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, S3_KEY_PREFIX, StorageUnitStatusEntity.EXPIRING, StorageUnitStatusEntity.RESTORED, storageFiles, NO_EXCEPTION), result);
}
use of org.finra.herd.model.jpa.StorageEntity in project herd by FINRAOS.
the class BusinessObjectDataStorageFileServiceImpl method createBusinessObjectDataStorageFilesImpl.
/**
* Adds files to Business object data storage.
*
* @param businessObjectDataStorageFilesCreateRequest the business object data storage files create request
*
* @return BusinessObjectDataStorageFilesCreateResponse
*/
protected BusinessObjectDataStorageFilesCreateResponse createBusinessObjectDataStorageFilesImpl(BusinessObjectDataStorageFilesCreateRequest businessObjectDataStorageFilesCreateRequest) {
// validate request
validateBusinessObjectDataStorageFilesCreateRequest(businessObjectDataStorageFilesCreateRequest);
// retrieve and validate that the business object data exists
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(getBusinessObjectDataKey(businessObjectDataStorageFilesCreateRequest));
// Validate that business object data is in one of the pre-registered states.
Assert.isTrue(BooleanUtils.isTrue(businessObjectDataEntity.getStatus().getPreRegistrationStatus()), String.format("Business object data status must be one of the pre-registration statuses. Business object data status {%s}, business object data {%s}", businessObjectDataEntity.getStatus().getCode(), businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)));
// retrieve and validate that the storage unit exists
StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(businessObjectDataStorageFilesCreateRequest.getStorageName(), businessObjectDataEntity);
// Validate the storage unit has an acceptable status for adding new files.
Assert.isTrue(StorageUnitStatusEntity.ENABLED.equals(storageUnitEntity.getStatus().getCode()), String.format("Storage unit must be in the ENABLED status. Storage unit status {%s}, business object data {%s}", storageUnitEntity.getStatus().getCode(), businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)));
StorageEntity storageEntity = storageUnitEntity.getStorage();
// Get the S3 validation flags.
boolean validatePathPrefix = storageHelper.getBooleanStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX), storageEntity, false, true);
boolean validateFileExistence = storageHelper.getBooleanStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE), storageEntity, false, true);
boolean validateFileSize = storageHelper.getBooleanStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_FILE_SIZE), storageEntity, false, true);
// Ensure that file size validation is not enabled without file existence validation.
if (validateFileSize) {
Assert.isTrue(validateFileExistence, String.format("Storage \"%s\" has file size validation enabled without file existence validation.", storageEntity.getName()));
}
// Process the add storage files request based on the auto-discovery of storage files being enabled or not.
List<StorageFile> storageFiles;
if (BooleanUtils.isTrue(businessObjectDataStorageFilesCreateRequest.isDiscoverStorageFiles())) {
// Discover new storage files for this storage unit.
storageFiles = discoverStorageFiles(storageUnitEntity);
} else {
// Get the list of storage files from the request.
storageFiles = businessObjectDataStorageFilesCreateRequest.getStorageFiles();
// Validate storage files.
validateStorageFiles(storageFiles, storageUnitEntity, validatePathPrefix, validateFileExistence, validateFileSize);
}
// Add new storage files to the storage unit.
storageFileDaoHelper.createStorageFileEntitiesFromStorageFiles(storageUnitEntity, storageFiles);
// Construct and return the response.
return createBusinessObjectDataStorageFilesCreateResponse(storageEntity, businessObjectDataEntity, storageFiles);
}
use of org.finra.herd.model.jpa.StorageEntity in project herd by FINRAOS.
the class StorageUnitNotificationRegistrationServiceImpl method updateStorageUnitNotificationRegistration.
@NamespacePermissions({ @NamespacePermission(fields = "#notificationRegistrationKey?.namespace", permissions = NamespacePermissionEnum.WRITE), @NamespacePermission(fields = "#request?.storageUnitNotificationFilter?.namespace", permissions = NamespacePermissionEnum.READ), @NamespacePermission(fields = "#request?.jobActions?.![namespace]", permissions = NamespacePermissionEnum.EXECUTE) })
@Override
public StorageUnitNotificationRegistration updateStorageUnitNotificationRegistration(NotificationRegistrationKey notificationRegistrationKey, StorageUnitNotificationRegistrationUpdateRequest request) {
// Validate and trim the key.
validateStorageUnitNotificationRegistrationKey(notificationRegistrationKey);
// Validate and trim the request parameters.
validateStorageUnitNotificationRegistrationUpdateRequest(request);
// Retrieve and ensure that a storage unit notification exists with the specified key.
StorageUnitNotificationRegistrationEntity oldStorageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDaoHelper.getStorageUnitNotificationRegistrationEntity(notificationRegistrationKey);
String oldStorageUnitNotificationRegistrationName = oldStorageUnitNotificationRegistrationEntity.getName();
// Retrieve the namespace with the specified namespace code.
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(notificationRegistrationKey.getNamespace());
// Retrieve and validate the notification event type entity.
NotificationEventTypeEntity notificationEventTypeEntity = getAndValidateNotificationEventTypeEntity(request.getStorageUnitEventType());
// Get the storage unit notification filter.
StorageUnitNotificationFilter filter = request.getStorageUnitNotificationFilter();
// Retrieve and ensure that business object definition exists. Since namespace is specified, retrieve a business object definition by it's key.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(new BusinessObjectDefinitionKey(filter.getNamespace(), filter.getBusinessObjectDefinitionName()));
// If specified, retrieve and ensure that file type exists.
FileTypeEntity fileTypeEntity = null;
if (StringUtils.isNotBlank(filter.getBusinessObjectFormatFileType())) {
fileTypeEntity = fileTypeDaoHelper.getFileTypeEntity(filter.getBusinessObjectFormatFileType());
}
// Retrieve and ensure that storage exists.
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(filter.getStorageName());
// If specified, retrieve and ensure that new storage unit status exists.
StorageUnitStatusEntity newStorageUnitStatus = null;
if (StringUtils.isNotBlank(filter.getNewStorageUnitStatus())) {
newStorageUnitStatus = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(filter.getNewStorageUnitStatus());
}
// If specified, retrieve and ensure that old storage unit status exists.
StorageUnitStatusEntity oldStorageUnitStatus = null;
if (StringUtils.isNotBlank(filter.getOldStorageUnitStatus())) {
oldStorageUnitStatus = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(filter.getOldStorageUnitStatus());
}
// TODO: We need to add a null/empty list check here, if/when list of job actions will become optional (due to addition of other action types).
for (JobAction jobAction : request.getJobActions()) {
// Ensure that job definition exists.
jobDefinitionDaoHelper.getJobDefinitionEntity(jobAction.getNamespace(), jobAction.getJobName());
}
// Retrieve and validate the notification registration status entity.
NotificationRegistrationStatusEntity notificationRegistrationStatusEntity = notificationRegistrationStatusDaoHelper.getNotificationRegistrationStatusEntity(request.getNotificationRegistrationStatus());
// Delete the storage unit notification.
storageUnitNotificationRegistrationDao.delete(oldStorageUnitNotificationRegistrationEntity);
// Create a storage unit notification registration entity from the request information.
StorageUnitNotificationRegistrationEntity newStorageUnitNotificationRegistrationEntity = createStorageUnitNotificationEntity(namespaceEntity, notificationEventTypeEntity, businessObjectDefinitionEntity, fileTypeEntity, storageEntity, newStorageUnitStatus, oldStorageUnitStatus, new NotificationRegistrationKey(namespaceEntity.getCode(), oldStorageUnitNotificationRegistrationName), request.getStorageUnitNotificationFilter(), request.getJobActions(), notificationRegistrationStatusEntity);
// Persist the new entity.
newStorageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDao.saveAndRefresh(newStorageUnitNotificationRegistrationEntity);
// Create and return the storage unit notification object from the persisted entity.
return createStorageUnitNotificationFromEntity(newStorageUnitNotificationRegistrationEntity);
}
Aggregations