use of org.finra.herd.model.jpa.FileTypeEntity in project herd by FINRAOS.
the class BusinessObjectDataStorageFileServiceTest method createDataWithSubPartitions.
private void createDataWithSubPartitions() {
NamespaceEntity namespaceEntity = super.namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
DataProviderEntity dataProviderEntity = super.dataProviderDaoTestHelper.createDataProviderEntity(DATA_PROVIDER_NAME);
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = super.businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(namespaceEntity, BDEF_NAME, dataProviderEntity, NO_BDEF_DESCRIPTION, NO_BDEF_DISPLAY_NAME, NO_ATTRIBUTES, NO_SAMPLE_DATA_FILES);
FileTypeEntity fileTypeEntity = super.fileTypeDaoTestHelper.createFileTypeEntity(FORMAT_FILE_TYPE_CODE, FORMAT_DESCRIPTION);
List<SchemaColumn> schemaColumns = new ArrayList<>();
{
SchemaColumn schemaColumn = new SchemaColumn();
schemaColumn.setName(PARTITION_KEY);
schemaColumn.setType("STRING");
schemaColumns.add(schemaColumn);
}
{
SchemaColumn schemaColumn = new SchemaColumn();
schemaColumn.setName(PARTITION_KEY_2);
schemaColumn.setType("STRING");
schemaColumns.add(schemaColumn);
}
{
SchemaColumn schemaColumn = new SchemaColumn();
schemaColumn.setName(PARTITION_KEY_3);
schemaColumn.setType("STRING");
schemaColumns.add(schemaColumn);
}
{
SchemaColumn schemaColumn = new SchemaColumn();
schemaColumn.setName(PARTITION_KEY_4);
schemaColumn.setType("STRING");
schemaColumns.add(schemaColumn);
}
{
SchemaColumn schemaColumn = new SchemaColumn();
schemaColumn.setName(PARTITION_KEY_5);
schemaColumn.setType("STRING");
schemaColumns.add(schemaColumn);
}
BusinessObjectFormatEntity businessObjectFormatEntity = super.businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(businessObjectDefinitionEntity, FORMAT_USAGE_CODE, fileTypeEntity, FORMAT_VERSION, null, true, PARTITION_KEY, null, NO_ATTRIBUTES, null, null, null, schemaColumns, null);
BusinessObjectDataStatusEntity businessObjectDataStatusEntity = businessObjectDataStatusDaoTestHelper.createBusinessObjectDataStatusEntity(BDATA_STATUS, DESCRIPTION, BDATA_STATUS_PRE_REGISTRATION_FLAG_SET);
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectFormatEntity, PARTITION_VALUE, SUB_PARTITION_VALUES, DATA_VERSION, true, businessObjectDataStatusEntity.getCode());
StorageEntity storageEntity = super.storageDaoTestHelper.createStorageEntity(STORAGE_NAME);
StorageUnitEntity storageUnitEntity = super.storageUnitDaoTestHelper.createStorageUnitEntity(storageEntity, businessObjectDataEntity, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
super.storageFileDaoTestHelper.createStorageFileEntity(storageUnitEntity, FILE_PATH_1, FILE_SIZE_1_KB, null);
}
use of org.finra.herd.model.jpa.FileTypeEntity in project herd by FINRAOS.
the class GetBusinessObjectDataTest method setupDatabase.
/**
* Inserts a business object data and their FK relationships into the database.
*
* @param dataProviderName the data provider name.
* @param businessObjectDefinitionName the business object definition name.
* @param fileTypeCode the file type code.
* @param businessObjectFormatUsage the business object format usage.
* @param businessObjectFormatVersion the business object format version.
* @param businessObjectDataVersion the business object data version.
* @param partitionKey the partition key.
* @param partitionValues the partition values.
*/
private void setupDatabase(String namespace, String dataProviderName, String businessObjectDefinitionName, String fileTypeCode, String businessObjectFormatUsage, Integer businessObjectFormatVersion, Integer businessObjectDataVersion, String partitionKey, String[] partitionValues) {
DataProviderEntity dataProviderEntity = new DataProviderEntity();
dataProviderEntity.setName(dataProviderName);
herdDao.saveAndRefresh(dataProviderEntity);
NamespaceEntity namespaceEntity = new NamespaceEntity();
namespaceEntity.setCode(namespace);
herdDao.saveAndRefresh(namespaceEntity);
BusinessObjectDefinitionEntity businessObjectDefinition = new BusinessObjectDefinitionEntity();
businessObjectDefinition.setDataProvider(dataProviderEntity);
businessObjectDefinition.setName(businessObjectDefinitionName);
businessObjectDefinition.setNamespace(namespaceEntity);
herdDao.saveAndRefresh(businessObjectDefinition);
FileTypeEntity fileTypeEntity = new FileTypeEntity();
fileTypeEntity.setCode(fileTypeCode);
herdDao.saveAndRefresh(fileTypeEntity);
BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity();
businessObjectFormatEntity.setBusinessObjectDefinition(businessObjectDefinition);
businessObjectFormatEntity.setBusinessObjectFormatVersion(businessObjectFormatVersion);
businessObjectFormatEntity.setFileType(fileTypeEntity);
businessObjectFormatEntity.setLatestVersion(true);
businessObjectFormatEntity.setNullValue("#");
businessObjectFormatEntity.setPartitionKey(partitionKey);
businessObjectFormatEntity.setUsage(businessObjectFormatUsage);
herdDao.saveAndRefresh(businessObjectFormatEntity);
StoragePlatformEntity storagePlatformEntity = new StoragePlatformEntity();
storagePlatformEntity.setName(randomString());
herdDao.saveAndRefresh(storagePlatformEntity);
StorageEntity storageEntity = new StorageEntity();
storageEntity.setName(randomString());
storageEntity.setStoragePlatform(storagePlatformEntity);
herdDao.saveAndRefresh(storageEntity);
BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity);
businessObjectDataEntity.setLatestVersion(true);
businessObjectDataEntity.setPartitionValue(partitionValues[0]);
businessObjectDataEntity.setPartitionValue2(partitionValues[1]);
businessObjectDataEntity.setPartitionValue3(partitionValues[2]);
businessObjectDataEntity.setPartitionValue4(partitionValues[3]);
businessObjectDataEntity.setPartitionValue5(partitionValues[4]);
businessObjectDataEntity.setStatus(businessObjectDataStatusDao.getBusinessObjectDataStatusByCode(BusinessObjectDataStatusEntity.VALID));
Collection<StorageUnitEntity> storageUnits = new ArrayList<>();
StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
storageUnitEntity.setStorage(storageEntity);
Collection<StorageFileEntity> storageFiles = new ArrayList<>();
StorageFileEntity storageFileEntity = new StorageFileEntity();
storageFileEntity.setPath(randomString());
storageFileEntity.setFileSizeBytes(1000l);
storageFileEntity.setStorageUnit(storageUnitEntity);
storageFiles.add(storageFileEntity);
storageUnitEntity.setStorageFiles(storageFiles);
storageUnitEntity.setBusinessObjectData(businessObjectDataEntity);
storageUnitEntity.setStatus(storageUnitStatusDao.getStorageUnitStatusByCode(StorageUnitStatusEntity.ENABLED));
storageUnits.add(storageUnitEntity);
businessObjectDataEntity.setStorageUnits(storageUnits);
businessObjectDataEntity.setVersion(businessObjectDataVersion);
herdDao.saveAndRefresh(businessObjectDataEntity);
}
use of org.finra.herd.model.jpa.FileTypeEntity 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);
}
use of org.finra.herd.model.jpa.FileTypeEntity 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);
}
use of org.finra.herd.model.jpa.FileTypeEntity in project herd by FINRAOS.
the class BusinessObjectDataNotificationRegistrationServiceImpl method createBusinessObjectDataNotificationRegistration.
@NamespacePermissions({ @NamespacePermission(fields = "#request?.businessObjectDataNotificationRegistrationKey?.namespace", permissions = NamespacePermissionEnum.WRITE), @NamespacePermission(fields = "#request?.businessObjectDataNotificationFilter?.namespace", permissions = NamespacePermissionEnum.READ), @NamespacePermission(fields = "#request?.jobActions?.![namespace]", permissions = NamespacePermissionEnum.EXECUTE) })
@Override
public BusinessObjectDataNotificationRegistration createBusinessObjectDataNotificationRegistration(BusinessObjectDataNotificationRegistrationCreateRequest request) {
// Validate and trim the request parameters.
validateBusinessObjectDataNotificationRegistrationCreateRequest(request);
// Get the business object notification key.
NotificationRegistrationKey key = request.getBusinessObjectDataNotificationRegistrationKey();
// Retrieve and ensure that namespace exists with the specified namespace code.
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(key.getNamespace());
// Retrieve and validate the notification event type entity.
NotificationEventTypeEntity notificationEventTypeEntity = getAndValidateNotificationEventTypeEntity(request.getBusinessObjectDataEventType());
// Get the business object data notification filter.
BusinessObjectDataNotificationFilter filter = request.getBusinessObjectDataNotificationFilter();
// Retrieve and ensure that business object definition exists.
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());
}
// If specified, retrieve and ensure that storage exists.
StorageEntity storageEntity = null;
if (StringUtils.isNotBlank(filter.getStorageName())) {
storageEntity = storageDaoHelper.getStorageEntity(filter.getStorageName());
}
// If specified, retrieve and ensure that new business object data status exists.
BusinessObjectDataStatusEntity newBusinessObjectDataStatus = null;
if (StringUtils.isNotBlank(filter.getNewBusinessObjectDataStatus())) {
newBusinessObjectDataStatus = businessObjectDataStatusDaoHelper.getBusinessObjectDataStatusEntity(filter.getNewBusinessObjectDataStatus());
}
// If specified, retrieve and ensure that old business object data status exists.
BusinessObjectDataStatusEntity oldBusinessObjectDataStatus = null;
if (StringUtils.isNotBlank(filter.getOldBusinessObjectDataStatus())) {
oldBusinessObjectDataStatus = businessObjectDataStatusDaoHelper.getBusinessObjectDataStatusEntity(filter.getOldBusinessObjectDataStatus());
}
// 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());
}
// If specified, retrieve and validate the notification registration status entity. Otherwise, default it to ENABLED.
NotificationRegistrationStatusEntity notificationRegistrationStatusEntity = notificationRegistrationStatusDaoHelper.getNotificationRegistrationStatusEntity(StringUtils.isNotBlank(request.getNotificationRegistrationStatus()) ? request.getNotificationRegistrationStatus() : NotificationRegistrationStatusEntity.ENABLED);
// Ensure a business object data notification with the specified name doesn't already exist for the specified namespace.
BusinessObjectDataNotificationRegistrationEntity businessObjectDataNotificationRegistrationEntity = businessObjectDataNotificationRegistrationDao.getBusinessObjectDataNotificationRegistrationByAltKey(key);
if (businessObjectDataNotificationRegistrationEntity != null) {
throw new AlreadyExistsException(String.format("Unable to create business object data notification with name \"%s\" because it already exists for namespace \"%s\".", key.getNotificationName(), key.getNamespace()));
}
// Create a business object data notification registration entity from the request information.
businessObjectDataNotificationRegistrationEntity = createBusinessObjectDataNotificationEntity(namespaceEntity, notificationEventTypeEntity, businessObjectDefinitionEntity, fileTypeEntity, storageEntity, newBusinessObjectDataStatus, oldBusinessObjectDataStatus, request.getBusinessObjectDataNotificationRegistrationKey(), request.getBusinessObjectDataNotificationFilter(), request.getJobActions(), notificationRegistrationStatusEntity);
// Persist the new entity.
businessObjectDataNotificationRegistrationEntity = businessObjectDataNotificationRegistrationDao.saveAndRefresh(businessObjectDataNotificationRegistrationEntity);
// Create and return the business object data notification object from the persisted entity.
return createBusinessObjectDataNotificationFromEntity(businessObjectDataNotificationRegistrationEntity);
}
Aggregations