Search in sources :

Example 71 with StorageEntity

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) StorageFileEntity(org.finra.herd.model.jpa.StorageFileEntity) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) StorageEntity(org.finra.herd.model.jpa.StorageEntity) Predicate(javax.persistence.criteria.Predicate)

Example 72 with StorageEntity

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;
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) ArrayList(java.util.ArrayList) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity)

Example 73 with StorageEntity

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));
}
Also used : BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) StorageEntity(org.finra.herd.model.jpa.StorageEntity) Test(org.junit.Test)

Example 74 with StorageEntity

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));
}
Also used : BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) StorageEntity(org.finra.herd.model.jpa.StorageEntity) Test(org.junit.Test)

Example 75 with StorageEntity

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));
}
Also used : BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) Test(org.junit.Test)

Aggregations

StorageEntity (org.finra.herd.model.jpa.StorageEntity)141 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)67 Test (org.junit.Test)63 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)57 ArrayList (java.util.ArrayList)42 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)38 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)34 StorageUnitStatusEntity (org.finra.herd.model.jpa.StorageUnitStatusEntity)24 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)23 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)23 Predicate (javax.persistence.criteria.Predicate)18 Attribute (org.finra.herd.model.api.xml.Attribute)18 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)18 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)17 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)17 StorageFileEntity (org.finra.herd.model.jpa.StorageFileEntity)16 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)15 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)14 StoragePlatformEntity (org.finra.herd.model.jpa.StoragePlatformEntity)14 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)13