use of org.finra.herd.model.jpa.BusinessObjectDefinitionEntity in project herd by FINRAOS.
the class StorageUnitDaoImpl method getStorageUnitsByPartitionFiltersAndStorages.
/**
* Retrieves a list of storage unit entities per specified parameters. This method processes a sublist of partition filters specified by
* partitionFilterSubListFromIndex and partitionFilterSubListSize parameters.
*
* @param businessObjectFormatKey the business object format key (case-insensitive). If a business object format version isn't specified, the latest
* available format version for each partition value will be used
* @param partitionFilters the list of partition filter to be used to select business object data instances. Each partition filter contains a list of
* primary and sub-partition values in the right order up to the maximum partition levels allowed by business object data registration - with partition
* values for the relative partitions not to be used for selection passed as nulls
* @param businessObjectDataVersion the business object data version. If a business object data version isn't specified, the latest data version based on
* the specified business object data status is returned
* @param businessObjectDataStatus the business object data status. This parameter is ignored when the business object data version is specified. When
* business object data version and business object data status both are not specified, the latest data version for each set of partition values will be
* used regardless of the status
* @param storageNames the list of storage names where the business object data storage units should be looked for (case-insensitive)
* @param storagePlatformType the optional storage platform type, e.g. S3 for Hive DDL. It is ignored when the list of storages is not empty
* @param excludedStoragePlatformType the optional storage platform type to be excluded from search. It is ignored when the list of storages is not empty or
* the storage platform type is specified
* @param partitionFilterSubListFromIndex the index of the first element in the partition filter sublist
* @param partitionFilterSubListSize the size of the partition filter sublist
* @param selectOnlyAvailableStorageUnits specifies if only available storage units will be selected or any storage units regardless of their status
*
* @return the list of storage unit entities sorted by partition values
*/
private List<StorageUnitEntity> getStorageUnitsByPartitionFiltersAndStorages(BusinessObjectFormatKey businessObjectFormatKey, List<List<String>> partitionFilters, Integer businessObjectDataVersion, String businessObjectDataStatus, List<String> storageNames, String storagePlatformType, String excludedStoragePlatformType, boolean selectOnlyAvailableStorageUnits, int partitionFilterSubListFromIndex, int partitionFilterSubListSize) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Tuple> criteria = builder.createTupleQuery();
// The criteria root is the storage unit.
Root<StorageUnitEntity> storageUnitEntity = criteria.from(StorageUnitEntity.class);
// Join to the other tables we can filter on.
Join<StorageUnitEntity, BusinessObjectDataEntity> businessObjectDataEntity = storageUnitEntity.join(StorageUnitEntity_.businessObjectData);
Join<StorageUnitEntity, StorageEntity> storageEntity = storageUnitEntity.join(StorageUnitEntity_.storage);
Join<StorageEntity, StoragePlatformEntity> storagePlatformEntity = storageEntity.join(StorageEntity_.storagePlatform);
Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> businessObjectFormatEntity = businessObjectDataEntity.join(BusinessObjectDataEntity_.businessObjectFormat);
Join<BusinessObjectFormatEntity, FileTypeEntity> fileTypeEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.fileType);
Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.businessObjectDefinition);
Join<StorageUnitEntity, StorageUnitStatusEntity> storageUnitStatusEntity = storageUnitEntity.join(StorageUnitEntity_.status);
// Create the standard restrictions (i.e. the standard where clauses).
// Create a standard restriction based on the business object format key values.
// Please note that we specify not to ignore the business object format version.
Predicate mainQueryRestriction = getQueryRestriction(builder, businessObjectFormatEntity, fileTypeEntity, businessObjectDefinitionEntity, businessObjectFormatKey, false);
// If a format version was not specified, use the latest available for this set of partition values.
if (businessObjectFormatKey.getBusinessObjectFormatVersion() == null) {
// Get the latest available format version for this set of partition values and per other restrictions.
Subquery<Integer> subQuery = getMaximumBusinessObjectFormatVersionSubQuery(builder, criteria, businessObjectDefinitionEntity, businessObjectFormatEntity, fileTypeEntity, businessObjectDataEntity, businessObjectDataVersion, businessObjectDataStatus, storageNames, storagePlatformType, excludedStoragePlatformType, selectOnlyAvailableStorageUnits);
mainQueryRestriction = builder.and(mainQueryRestriction, builder.in(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion)).value(subQuery));
}
// Add restriction as per specified primary and/or sub-partition values.
mainQueryRestriction = builder.and(mainQueryRestriction, getQueryRestrictionOnPartitionValues(builder, businessObjectDataEntity, partitionFilters.subList(partitionFilterSubListFromIndex, partitionFilterSubListFromIndex + partitionFilterSubListSize)));
// If a data version was specified, use it. Otherwise, use the latest one as per specified business object data status.
if (businessObjectDataVersion != null) {
mainQueryRestriction = builder.and(mainQueryRestriction, builder.equal(businessObjectDataEntity.get(BusinessObjectDataEntity_.version), businessObjectDataVersion));
} else {
// Business object data version is not specified, so get the latest one as per specified business object data status, if any.
// Meaning, when both business object data version and business object data status are not specified, we just return
// the latest business object data version in the specified storage.
Subquery<Integer> subQuery = getMaximumBusinessObjectDataVersionSubQuery(builder, criteria, businessObjectDataEntity, businessObjectFormatEntity, businessObjectDataStatus, storageNames, storagePlatformType, excludedStoragePlatformType, selectOnlyAvailableStorageUnits);
mainQueryRestriction = builder.and(mainQueryRestriction, builder.in(businessObjectDataEntity.get(BusinessObjectDataEntity_.version)).value(subQuery));
}
// If specified, add restriction on storage.
mainQueryRestriction = builder.and(mainQueryRestriction, getQueryRestrictionOnStorage(builder, storageEntity, storagePlatformEntity, storageNames, storagePlatformType, excludedStoragePlatformType));
// If specified, add a restriction on storage unit status availability flag.
if (selectOnlyAvailableStorageUnits) {
mainQueryRestriction = builder.and(mainQueryRestriction, builder.isTrue(storageUnitStatusEntity.get(StorageUnitStatusEntity_.available)));
}
// Order by partitions and storage names.
List<Order> orderBy = new ArrayList<>();
for (SingularAttribute<BusinessObjectDataEntity, String> businessObjectDataPartition : BUSINESS_OBJECT_DATA_PARTITIONS) {
orderBy.add(builder.asc(businessObjectDataEntity.get(businessObjectDataPartition)));
}
orderBy.add(builder.asc(storageEntity.get(StorageEntity_.name)));
// Add the clauses for the query.
// Please note that we use multiselect here in order to eliminate the Hibernate N+1 SELECT's problem,
// happening when we select storage unit entities and access their relative business object data entities.
// This is an alternative approach, since adding @Fetch(FetchMode.JOIN) failed to address the issue.
criteria.multiselect(storageUnitEntity, storageUnitStatusEntity, storageEntity, storagePlatformEntity, businessObjectDataEntity, businessObjectFormatEntity).where(mainQueryRestriction).orderBy(orderBy);
// Run the query to get a list of tuples back.
List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();
// Build a list of storage unit entities to return.
List<StorageUnitEntity> storageUnitEntities = new ArrayList<>();
for (Tuple tuple : tuples) {
storageUnitEntities.add(tuple.get(storageUnitEntity));
}
return storageUnitEntities;
}
use of org.finra.herd.model.jpa.BusinessObjectDefinitionEntity in project herd by FINRAOS.
the class StorageUnitNotificationRegistrationDaoImpl method getStorageUnitNotificationRegistrationKeysByNotificationFilter.
@Override
public List<NotificationRegistrationKey> getStorageUnitNotificationRegistrationKeysByNotificationFilter(StorageUnitNotificationFilter businessObjectDataNotificationFilter) {
// Create the criteria builder and a tuple style criteria query.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Tuple> criteria = builder.createTupleQuery();
// The criteria root is the storage unit notification registration.
Root<StorageUnitNotificationRegistrationEntity> notificationRegistrationEntityRoot = criteria.from(StorageUnitNotificationRegistrationEntity.class);
// Join to the other tables we can filter on.
Join<StorageUnitNotificationRegistrationEntity, NamespaceEntity> notificationRegistrationNamespaceEntityJoin = notificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.namespace);
Join<StorageUnitNotificationRegistrationEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = notificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.businessObjectDefinition);
Join<BusinessObjectDefinitionEntity, NamespaceEntity> businessObjectDefinitionNamespaceEntity = businessObjectDefinitionEntity.join(BusinessObjectDefinitionEntity_.namespace);
Join<StorageUnitNotificationRegistrationEntity, FileTypeEntity> fileTypeEntity = notificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.fileType, JoinType.LEFT);
// Get the columns.
Path<String> notificationRegistrationNamespaceColumn = notificationRegistrationNamespaceEntityJoin.get(NamespaceEntity_.code);
Path<String> notificationRegistrationNameColumn = notificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.name);
// Create the standard restrictions (i.e. the standard where clauses).
List<Predicate> predicates = new ArrayList<>();
predicates.add(builder.equal(builder.upper(businessObjectDefinitionNamespaceEntity.get(NamespaceEntity_.code)), businessObjectDataNotificationFilter.getNamespace().toUpperCase()));
predicates.add(builder.equal(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)), businessObjectDataNotificationFilter.getBusinessObjectDefinitionName().toUpperCase()));
if (StringUtils.isNotBlank(businessObjectDataNotificationFilter.getBusinessObjectFormatUsage())) {
predicates.add(builder.or(builder.isNull(notificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.usage)), builder.equal(builder.upper(notificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.usage)), businessObjectDataNotificationFilter.getBusinessObjectFormatUsage().toUpperCase())));
}
if (StringUtils.isNotBlank(businessObjectDataNotificationFilter.getBusinessObjectFormatFileType())) {
predicates.add(builder.or(builder.isNull(notificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.fileType)), builder.equal(builder.upper(fileTypeEntity.get(FileTypeEntity_.code)), businessObjectDataNotificationFilter.getBusinessObjectFormatFileType().toUpperCase())));
}
// Add the select and where clauses to the query.
criteria.multiselect(notificationRegistrationNamespaceColumn, notificationRegistrationNameColumn).where(builder.and(predicates.toArray(new Predicate[predicates.size()])));
// Add the order by clause to the query.
criteria.orderBy(builder.asc(notificationRegistrationNamespaceColumn), builder.asc(notificationRegistrationNameColumn));
// Run the query to get a list of tuples back.
List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();
// Populate the list of keys from the returned tuples.
return getNotificationRegistrationKeys(tuples, notificationRegistrationNamespaceColumn, notificationRegistrationNameColumn);
}
use of org.finra.herd.model.jpa.BusinessObjectDefinitionEntity in project herd by FINRAOS.
the class SchemaColumnDaoTest method testGetSchemaColumns.
@Test
public void testGetSchemaColumns() {
// Create a business object definition column key.
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME);
// Create a business object definition entity.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(businessObjectDefinitionKey, DATA_PROVIDER_NAME, BDEF_DESCRIPTION);
// Create a file type entity.
FileTypeEntity fileTypeEntity = fileTypeDaoTestHelper.createFileTypeEntity(FORMAT_FILE_TYPE_CODE);
// Create and persist database entities required for testing.
for (Integer formatVersion : Arrays.asList(INITIAL_FORMAT_VERSION, SECOND_FORMAT_VERSION)) {
businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(businessObjectDefinitionEntity, FORMAT_USAGE_CODE, fileTypeEntity, formatVersion, FORMAT_DESCRIPTION, LATEST_VERSION_FLAG_SET, PARTITION_KEY, null, NO_ATTRIBUTES, SCHEMA_DELIMITER_PIPE, SCHEMA_ESCAPE_CHARACTER_BACKSLASH, SCHEMA_NULL_VALUE_BACKSLASH_N, schemaColumnDaoTestHelper.getTestSchemaColumns(), NO_PARTITION_COLUMNS);
}
// Get a list of schema columns from the business object definition matching to the first column name.
assertEquals(2, schemaColumnDao.getSchemaColumns(businessObjectDefinitionEntity, FIRST_COLUMN_NAME).size());
// Get a list of schema columns by passing all case-insensitive parameters in uppercase.
assertEquals(2, schemaColumnDao.getSchemaColumns(businessObjectDefinitionEntity, FIRST_COLUMN_NAME.toUpperCase()).size());
// Get business object definition column by passing all case-insensitive parameters in lowercase.
assertEquals(2, schemaColumnDao.getSchemaColumns(businessObjectDefinitionEntity, FIRST_COLUMN_NAME.toLowerCase()).size());
// Try invalid values for all input parameters.
assertEquals(0, schemaColumnDao.getSchemaColumns(businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE, BDEF_NAME_2, DATA_PROVIDER_NAME, DESCRIPTION), FIRST_COLUMN_NAME).size());
assertEquals(0, schemaColumnDao.getSchemaColumns(businessObjectDefinitionEntity, "I_DO_NOT_EXIST").size());
}
use of org.finra.herd.model.jpa.BusinessObjectDefinitionEntity in project herd by FINRAOS.
the class NotificationRegistrationDaoTestHelper method createBusinessObjectDataNotificationRegistrationEntity.
/**
* Creates and persists a business object data notification registration entity.
*
* @param notificationRegistrationKey the business object data notification registration key
* @param notificationEventTypeCode the notification event type
* @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 businessObjectFormatVersion the business object format version
* @param storageName the storage name
* @param newBusinessObjectDataStatus the new business object data status
* @param oldBusinessObjectDataStatus the old business object data status
* @param jobActions the list of job actions
* @param notificationRegistrationStatus the notification registration status
*
* @return the newly created business object data notification registration entity
*/
public BusinessObjectDataNotificationRegistrationEntity createBusinessObjectDataNotificationRegistrationEntity(NotificationRegistrationKey notificationRegistrationKey, String notificationEventTypeCode, String businessObjectDefinitionNamespace, String businessObjectDefinitionName, String businessObjectFormatUsage, String businessObjectFormatFileType, Integer businessObjectFormatVersion, String storageName, String newBusinessObjectDataStatus, String oldBusinessObjectDataStatus, List<JobAction> jobActions, String notificationRegistrationStatus) {
// Create a namespace entity if needed.
NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByCd(notificationRegistrationKey.getNamespace());
if (namespaceEntity == null) {
namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(notificationRegistrationKey.getNamespace());
}
// Create a notification event type entity if needed.
NotificationEventTypeEntity notificationEventTypeEntity = notificationEventTypeDao.getNotificationEventTypeByCode(notificationEventTypeCode);
if (notificationEventTypeEntity == null) {
notificationEventTypeEntity = createNotificationEventTypeEntity(notificationEventTypeCode);
}
// Create a business object definition entity if needed.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(new BusinessObjectDefinitionKey(businessObjectDefinitionNamespace, businessObjectDefinitionName));
if (businessObjectDefinitionEntity == null) {
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 if needed.
StorageEntity storageEntity = null;
if (StringUtils.isNotBlank(storageName)) {
storageEntity = storageDao.getStorageByName(storageName);
if (storageEntity == null) {
storageEntity = storageDaoTestHelper.createStorageEntity(storageName, StoragePlatformEntity.S3);
}
}
// Create a business object status entity for new status if needed.
BusinessObjectDataStatusEntity newBusinessObjectDataStatusEntity = null;
if (StringUtils.isNotBlank(newBusinessObjectDataStatus)) {
newBusinessObjectDataStatusEntity = businessObjectDataStatusDao.getBusinessObjectDataStatusByCode(newBusinessObjectDataStatus);
if (newBusinessObjectDataStatusEntity == null) {
newBusinessObjectDataStatusEntity = businessObjectDataStatusDaoTestHelper.createBusinessObjectDataStatusEntity(newBusinessObjectDataStatus);
}
}
// Create a business object status entity for new status if needed.
BusinessObjectDataStatusEntity oldBusinessObjectDataStatusEntity = null;
if (StringUtils.isNotBlank(oldBusinessObjectDataStatus)) {
oldBusinessObjectDataStatusEntity = businessObjectDataStatusDao.getBusinessObjectDataStatusByCode(oldBusinessObjectDataStatus);
if (oldBusinessObjectDataStatusEntity == null) {
oldBusinessObjectDataStatusEntity = businessObjectDataStatusDaoTestHelper.createBusinessObjectDataStatusEntity(oldBusinessObjectDataStatus);
}
}
// Create a notification registration status entity if needed.
NotificationRegistrationStatusEntity notificationRegistrationStatusEntity = notificationRegistrationStatusDao.getNotificationRegistrationStatus(notificationRegistrationStatus);
if (notificationRegistrationStatusEntity == null) {
notificationRegistrationStatusEntity = createNotificationRegistrationStatusEntity(notificationRegistrationStatus);
}
// Create a business object data notification registration entity.
BusinessObjectDataNotificationRegistrationEntity businessObjectDataNotificationRegistrationEntity = new BusinessObjectDataNotificationRegistrationEntity();
businessObjectDataNotificationRegistrationEntity.setNamespace(namespaceEntity);
businessObjectDataNotificationRegistrationEntity.setName(notificationRegistrationKey.getNotificationName());
businessObjectDataNotificationRegistrationEntity.setNotificationEventType(notificationEventTypeEntity);
businessObjectDataNotificationRegistrationEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
businessObjectDataNotificationRegistrationEntity.setUsage(businessObjectFormatUsage);
businessObjectDataNotificationRegistrationEntity.setFileType(fileTypeEntity);
businessObjectDataNotificationRegistrationEntity.setBusinessObjectFormatVersion(businessObjectFormatVersion);
businessObjectDataNotificationRegistrationEntity.setStorage(storageEntity);
businessObjectDataNotificationRegistrationEntity.setNewBusinessObjectDataStatus(newBusinessObjectDataStatusEntity);
businessObjectDataNotificationRegistrationEntity.setOldBusinessObjectDataStatus(oldBusinessObjectDataStatusEntity);
businessObjectDataNotificationRegistrationEntity.setNotificationRegistrationStatus(notificationRegistrationStatusEntity);
if (!CollectionUtils.isEmpty(jobActions)) {
List<NotificationActionEntity> notificationActionEntities = new ArrayList<>();
businessObjectDataNotificationRegistrationEntity.setNotificationActions(notificationActionEntities);
for (JobAction jobAction : jobActions) {
// Create a job definition entity if needed.
JobDefinitionEntity jobDefinitionEntity = jobDefinitionDao.getJobDefinitionByAltKey(jobAction.getNamespace(), jobAction.getJobName());
if (jobDefinitionEntity == null) {
jobDefinitionEntity = jobDefinitionDaoTestHelper.createJobDefinitionEntity(jobAction.getNamespace(), jobAction.getJobName(), String.format("Description of \"%s.%s\" job definition.", jobAction.getNamespace(), jobAction.getJobName()), String.format("%s.%s.%s", jobAction.getNamespace(), jobAction.getJobName(), AbstractDaoTest.ACTIVITI_ID));
}
NotificationJobActionEntity notificationJobActionEntity = new NotificationJobActionEntity();
notificationActionEntities.add(notificationJobActionEntity);
notificationJobActionEntity.setNotificationRegistration(businessObjectDataNotificationRegistrationEntity);
notificationJobActionEntity.setJobDefinition(jobDefinitionEntity);
notificationJobActionEntity.setCorrelationData(jobAction.getCorrelationData());
}
}
return businessObjectDataNotificationRegistrationDao.saveAndRefresh(businessObjectDataNotificationRegistrationEntity);
}
use of org.finra.herd.model.jpa.BusinessObjectDefinitionEntity 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);
}
Aggregations