use of org.finra.herd.model.jpa.StorageEntity in project herd by FINRAOS.
the class StorageFileDaoImpl method getStorageFileCount.
@Override
public Long getStorageFileCount(String storageName, String filePathPrefix) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
// The criteria root is the storage files.
Root<StorageFileEntity> storageFileEntity = criteria.from(StorageFileEntity.class);
// Join to the other tables we can filter on.
Join<StorageFileEntity, StorageUnitEntity> storageUnitEntity = storageFileEntity.join(StorageFileEntity_.storageUnit);
Join<StorageUnitEntity, StorageEntity> storageEntity = storageUnitEntity.join(StorageUnitEntity_.storage);
// Create path.
Expression<Long> storageFileCount = builder.count(storageFileEntity.get(StorageFileEntity_.id));
// Create the standard restrictions (i.e. the standard where clauses).
Predicate storageNameRestriction = builder.equal(builder.upper(storageEntity.get(StorageEntity_.name)), storageName.toUpperCase());
Predicate filePathRestriction = builder.like(storageFileEntity.get(StorageFileEntity_.path), String.format("%s%%", filePathPrefix));
// Add the clauses for the query.
criteria.select(storageFileCount).where(builder.and(storageNameRestriction, filePathRestriction));
return entityManager.createQuery(criteria).getSingleResult();
}
use of org.finra.herd.model.jpa.StorageEntity in project herd by FINRAOS.
the class BusinessObjectDataAvailabilityTestHelper method createDatabaseEntitiesForBusinessObjectDataAvailabilityTesting.
/**
* Creates relative database entities required for the business object data availability service unit tests.
*
* @param partitionKeyGroupName the partition key group name
* @param columns the list of schema columns
* @param partitionColumns the list of schema partition columns
* @param partitionColumnPosition the position of the partition column (1-based numbering) that will be changing
* @param subPartitionValues the list of sub-partition values to be used in test business object data generation
* @param allowDuplicateBusinessObjectData specifies if business object data is allowed to be registered in multiple storages
* @param expectedRequestStorageNames the list of storage names expected to be listed in the relative unit test availability requests when queering business
* object data availability. This list will be used to produce the ordered list of expected available storage units.
*
* @return the ordered list of storage unit entities expected to be available across the specified list of storages
*/
public List<StorageUnitEntity> createDatabaseEntitiesForBusinessObjectDataAvailabilityTesting(String partitionKeyGroupName, List<SchemaColumn> columns, List<SchemaColumn> partitionColumns, int partitionColumnPosition, List<String> subPartitionValues, boolean allowDuplicateBusinessObjectData, List<String> expectedRequestStorageNames) {
List<StorageUnitEntity> availableStorageUnits = new ArrayList<>();
// Create relative database entities.
String partitionKey = partitionColumns.isEmpty() ? AbstractDaoTest.PARTITION_KEY : partitionColumns.get(0).getName();
// Create a business object format entity if it does not exist.
if (businessObjectFormatDao.getBusinessObjectFormatByAltKey(new BusinessObjectFormatKey(AbstractDaoTest.NAMESPACE, AbstractDaoTest.BDEF_NAME, AbstractDaoTest.FORMAT_USAGE_CODE, AbstractDaoTest.FORMAT_FILE_TYPE_CODE, AbstractDaoTest.FORMAT_VERSION)) == null) {
businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(AbstractDaoTest.NAMESPACE, AbstractDaoTest.BDEF_NAME, AbstractDaoTest.FORMAT_USAGE_CODE, AbstractDaoTest.FORMAT_FILE_TYPE_CODE, AbstractDaoTest.FORMAT_VERSION, AbstractDaoTest.FORMAT_DESCRIPTION, AbstractDaoTest.LATEST_VERSION_FLAG_SET, partitionKey, partitionKeyGroupName, AbstractDaoTest.NO_ATTRIBUTES, AbstractDaoTest.SCHEMA_DELIMITER_PIPE, AbstractDaoTest.SCHEMA_ESCAPE_CHARACTER_BACKSLASH, AbstractDaoTest.SCHEMA_NULL_VALUE_BACKSLASH_N, columns, partitionColumns);
}
// Create storage entities if they do not exist.
StorageEntity storageEntity1 = storageDao.getStorageByName(AbstractDaoTest.STORAGE_NAME);
if (storageEntity1 == null) {
storageEntity1 = storageDaoTestHelper.createStorageEntity(AbstractDaoTest.STORAGE_NAME);
}
StorageEntity storageEntity2 = storageDao.getStorageByName(AbstractDaoTest.STORAGE_NAME_2);
if (storageEntity2 == null) {
storageEntity2 = storageDaoTestHelper.createStorageEntity(AbstractDaoTest.STORAGE_NAME_2);
}
// Get storage status unit status entity.
StorageUnitStatusEntity storageUnitStatusEntity = storageUnitStatusDao.getStorageUnitStatusByCode(StorageUnitStatusEntity.ENABLED);
// Create business object data instances and relative storage units.
for (String partitionValue : AbstractDaoTest.SORTED_PARTITION_VALUES) {
BusinessObjectDataEntity businessObjectDataEntity;
// Create a business object data instance for the specified partition value.
if (partitionColumnPosition == BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION) {
businessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(AbstractDaoTest.NAMESPACE, AbstractDaoTest.BDEF_NAME, AbstractDaoTest.FORMAT_USAGE_CODE, AbstractDaoTest.FORMAT_FILE_TYPE_CODE, AbstractDaoTest.FORMAT_VERSION, partitionValue, subPartitionValues, AbstractDaoTest.DATA_VERSION, AbstractDaoTest.LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.VALID);
} else {
List<String> testSubPartitionValues = new ArrayList<>(subPartitionValues);
// Please note that the second partition column is located at index 0.
testSubPartitionValues.set(partitionColumnPosition - 2, partitionValue);
businessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(AbstractDaoTest.NAMESPACE, AbstractDaoTest.BDEF_NAME, AbstractDaoTest.FORMAT_USAGE_CODE, AbstractDaoTest.FORMAT_FILE_TYPE_CODE, AbstractDaoTest.FORMAT_VERSION, AbstractDaoTest.PARTITION_VALUE, testSubPartitionValues, AbstractDaoTest.DATA_VERSION, AbstractDaoTest.LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.VALID);
}
// Check if we need to create the relative storage units.
if (AbstractDaoTest.STORAGE_1_AVAILABLE_PARTITION_VALUES.contains(partitionValue)) {
StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(storageEntity1, businessObjectDataEntity, storageUnitStatusEntity, AbstractDaoTest.NO_STORAGE_DIRECTORY_PATH);
if (expectedRequestStorageNames.contains(AbstractDaoTest.STORAGE_NAME)) {
availableStorageUnits.add(storageUnitEntity);
}
}
if (AbstractDaoTest.STORAGE_2_AVAILABLE_PARTITION_VALUES.contains(partitionValue) && (allowDuplicateBusinessObjectData || !AbstractDaoTest.STORAGE_1_AVAILABLE_PARTITION_VALUES.contains(partitionValue))) {
StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(storageEntity2, businessObjectDataEntity, storageUnitStatusEntity, AbstractDaoTest.NO_STORAGE_DIRECTORY_PATH);
if (expectedRequestStorageNames.contains(AbstractDaoTest.STORAGE_NAME_2)) {
availableStorageUnits.add(storageUnitEntity);
}
}
}
return availableStorageUnits;
}
use of org.finra.herd.model.jpa.StorageEntity in project herd by FINRAOS.
the class BusinessObjectDataDaoTest method testGetBusinessObjectDataPartitionValueExcludedStoragePlatformTypeSpecified.
@Test
public void testGetBusinessObjectDataPartitionValueExcludedStoragePlatformTypeSpecified() {
// Create database entities required for testing.
StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(STORAGE_NAME, STORAGE_PLATFORM_CODE);
storageUnitDaoTestHelper.createStorageUnitEntity(storageEntity.getName(), NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.VALID, STORAGE_UNIT_STATUS, NO_STORAGE_DIRECTORY_PATH);
// Create a business object format key.
BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION);
// Validate that we can retrieve maximum and minimum partition values without specifying storage, storage platform, or excluded storage platform type.
assertEquals(PARTITION_VALUE, businessObjectDataDao.getBusinessObjectDataMaxPartitionValue(BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, businessObjectFormatKey, NO_DATA_VERSION, NO_BDATA_STATUS, NO_STORAGE_NAMES, null, null, null, null));
assertEquals(PARTITION_VALUE, businessObjectDataDao.getBusinessObjectDataMinPartitionValue(BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, businessObjectFormatKey, NO_DATA_VERSION, NO_BDATA_STATUS, NO_STORAGE_NAMES, null, null));
// Validate that we can still retrieve maximum and minimum partition values when we specify an invalid excluded storage platform type.
assertEquals(PARTITION_VALUE, businessObjectDataDao.getBusinessObjectDataMaxPartitionValue(BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, businessObjectFormatKey, NO_DATA_VERSION, NO_BDATA_STATUS, NO_STORAGE_NAMES, null, STORAGE_PLATFORM_CODE_2, null, null));
assertEquals(PARTITION_VALUE, businessObjectDataDao.getBusinessObjectDataMinPartitionValue(BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, businessObjectFormatKey, NO_DATA_VERSION, NO_BDATA_STATUS, NO_STORAGE_NAMES, null, STORAGE_PLATFORM_CODE_2));
// Validate that we fail to retrieve maximum and minimum partition values when we specify correct excluded storage platform type.
assertNull(businessObjectDataDao.getBusinessObjectDataMaxPartitionValue(BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, businessObjectFormatKey, NO_DATA_VERSION, NO_BDATA_STATUS, NO_STORAGE_NAMES, null, STORAGE_PLATFORM_CODE, null, null));
assertNull(businessObjectDataDao.getBusinessObjectDataMinPartitionValue(BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, businessObjectFormatKey, NO_DATA_VERSION, NO_BDATA_STATUS, NO_STORAGE_NAMES, null, STORAGE_PLATFORM_CODE));
// Validate that specifying storage forces to ignore the excluded storage platform type.
assertEquals(PARTITION_VALUE, businessObjectDataDao.getBusinessObjectDataMaxPartitionValue(BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, businessObjectFormatKey, NO_DATA_VERSION, NO_BDATA_STATUS, Collections.singletonList(STORAGE_NAME), null, STORAGE_PLATFORM_CODE, null, null));
assertEquals(PARTITION_VALUE, businessObjectDataDao.getBusinessObjectDataMinPartitionValue(BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, businessObjectFormatKey, NO_DATA_VERSION, NO_BDATA_STATUS, Collections.singletonList(STORAGE_NAME), null, STORAGE_PLATFORM_CODE));
// Validate that specifying storage platform type forces to ignore the excluded storage platform type.
assertEquals(PARTITION_VALUE, businessObjectDataDao.getBusinessObjectDataMaxPartitionValue(BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, businessObjectFormatKey, NO_DATA_VERSION, NO_BDATA_STATUS, NO_STORAGE_NAMES, STORAGE_PLATFORM_CODE, STORAGE_PLATFORM_CODE, null, null));
assertEquals(PARTITION_VALUE, businessObjectDataDao.getBusinessObjectDataMinPartitionValue(BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, businessObjectFormatKey, NO_DATA_VERSION, NO_BDATA_STATUS, NO_STORAGE_NAMES, STORAGE_PLATFORM_CODE, STORAGE_PLATFORM_CODE));
}
use of org.finra.herd.model.jpa.StorageEntity in project herd by FINRAOS.
the class BusinessObjectDataDaoTest method testGetBusinessObjectDataPartitionValueNoStorageSpecified.
@Test
public void testGetBusinessObjectDataPartitionValueNoStorageSpecified() {
// Create database entities required for testing.
StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(STORAGE_NAME, STORAGE_PLATFORM_CODE);
storageUnitDaoTestHelper.createStorageUnitEntity(storageEntity.getName(), NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.VALID, STORAGE_UNIT_STATUS, NO_STORAGE_DIRECTORY_PATH);
// Create a business object format key.
BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION);
// Validate that we can retrieve maximum and minimum partition values without specifying storage.
assertEquals(PARTITION_VALUE, businessObjectDataDao.getBusinessObjectDataMaxPartitionValue(BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, businessObjectFormatKey, NO_DATA_VERSION, NO_BDATA_STATUS, NO_STORAGE_NAMES, null, null, null, null));
assertEquals(PARTITION_VALUE, businessObjectDataDao.getBusinessObjectDataMinPartitionValue(BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, businessObjectFormatKey, NO_DATA_VERSION, NO_BDATA_STATUS, NO_STORAGE_NAMES, null, null));
}
use of org.finra.herd.model.jpa.StorageEntity in project herd by FINRAOS.
the class BusinessObjectDataDaoTest method testGetBusinessObjectDataPartitionValueLatestDataVersionNotInStorage.
/**
* This unit test validates that we do not rely on the business object data latest version flag when selecting an aggregate on the business object data
* partition value.
*/
@Test
public void testGetBusinessObjectDataPartitionValueLatestDataVersionNotInStorage() {
// Create a business object format entity.
BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION);
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(businessObjectFormatKey, FORMAT_DESCRIPTION, true, PARTITION_KEY);
// Create two versions of business object data instances with the latest version not located in the test storage.
List<BusinessObjectDataEntity> businessObjectDataEntities = Arrays.asList(businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectFormatEntity, PARTITION_VALUE, SUBPARTITION_VALUES, INITIAL_DATA_VERSION, false, BDATA_STATUS), businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectFormatEntity, PARTITION_VALUE, SUBPARTITION_VALUES, SECOND_DATA_VERSION, true, BDATA_STATUS));
// Create a storage instance and a storage unit for the initial business object data version only.
StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(STORAGE_NAME);
StorageUnitStatusEntity storageUnitStatusEntity = storageUnitStatusDaoTestHelper.createStorageUnitStatusEntity(STORAGE_UNIT_STATUS);
storageUnitDaoTestHelper.createStorageUnitEntity(storageEntity, businessObjectDataEntities.get(0), storageUnitStatusEntity, NO_STORAGE_DIRECTORY_PATH);
// Get the maximum available partition value in the test storage without specifying business object data version.
assertEquals(PARTITION_VALUE, businessObjectDataDao.getBusinessObjectDataMaxPartitionValue(BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, businessObjectFormatKey, null, BDATA_STATUS, Collections.singletonList(STORAGE_NAME), null, null, null, null));
// Get the minimum available partition value in the test storage without specifying business object data version.
assertEquals(PARTITION_VALUE, businessObjectDataDao.getBusinessObjectDataMinPartitionValue(BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, businessObjectFormatKey, null, BDATA_STATUS, Collections.singletonList(STORAGE_NAME), null, null));
}
Aggregations