use of org.finra.herd.model.jpa.StorageFileEntity in project herd by FINRAOS.
the class StorageFileDaoImpl method getStorageFileByStorageNameAndFilePath.
@Override
public StorageFileEntity getStorageFileByStorageNameAndFilePath(String storageName, String filePath) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<StorageFileEntity> criteria = builder.createQuery(StorageFileEntity.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 the standard restrictions (i.e. the standard where clauses).
Predicate filePathRestriction = builder.equal(storageFileEntity.get(StorageFileEntity_.path), filePath);
Predicate storageNameRestriction = builder.equal(builder.upper(storageEntity.get(StorageEntity_.name)), storageName.toUpperCase());
criteria.select(storageFileEntity).where(builder.and(filePathRestriction, storageNameRestriction));
return executeSingleResultQuery(criteria, String.format("Found more than one storage file with parameters {storageName=\"%s\"," + " filePath=\"%s\"}.", storageName, filePath));
}
use of org.finra.herd.model.jpa.StorageFileEntity in project herd by FINRAOS.
the class StorageFileDaoImpl method getStorageFilesByStorageAndFilePathPrefix.
@Override
public List<String> getStorageFilesByStorageAndFilePathPrefix(String storageName, String filePathPrefix) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<StorageFileEntity> criteria = builder.createQuery(StorageFileEntity.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 the standard restrictions (i.e. the standard where clauses).
Predicate filePathRestriction = builder.like(storageFileEntity.get(StorageFileEntity_.path), String.format("%s%%", filePathPrefix));
Predicate storageNameRestriction = builder.equal(builder.upper(storageEntity.get(StorageEntity_.name)), storageName.toUpperCase());
// Order the results by file path.
Order orderByFilePath = builder.asc(storageFileEntity.get(StorageFileEntity_.path));
criteria.select(storageFileEntity).where(builder.and(filePathRestriction, storageNameRestriction)).orderBy(orderByFilePath);
// Retrieve the storage files.
List<StorageFileEntity> storageFileEntities = entityManager.createQuery(criteria).getResultList();
// Build the result list.
List<String> storageFilePaths = new ArrayList<>();
for (StorageFileEntity storageFile : storageFileEntities) {
storageFilePaths.add(storageFile.getPath());
}
return storageFilePaths;
}
use of org.finra.herd.model.jpa.StorageFileEntity in project herd by FINRAOS.
the class StorageFileDaoTest method testGetStorageFileByStorageNameAndFilePath.
@Test
public void testGetStorageFileByStorageNameAndFilePath() {
// Create relative database entities.
StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(StorageEntity.MANAGED_STORAGE, NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, INITIAL_DATA_VERSION, true, BDATA_STATUS, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
for (String file : LOCAL_FILES) {
storageFileDaoTestHelper.createStorageFileEntity(storageUnitEntity, file, FILE_SIZE_1_KB, ROW_COUNT_1000);
}
// Retrieve the relative storage file entities and validate the results.
for (String file : LOCAL_FILES) {
StorageFileEntity storageFileEntity = storageFileDao.getStorageFileByStorageNameAndFilePath(StorageEntity.MANAGED_STORAGE, file);
assertTrue(storageFileEntity.getPath().compareTo(file) == 0);
assertTrue(storageFileEntity.getFileSizeBytes().compareTo(FILE_SIZE_1_KB) == 0);
assertTrue(storageFileEntity.getRowCount().compareTo(ROW_COUNT_1000) == 0);
}
// Confirm negative results when using wrong input parameters.
assertNull(storageFileDao.getStorageFileByStorageNameAndFilePath("I_DO_NOT_EXIST", LOCAL_FILES.get(0)));
assertNull(storageFileDao.getStorageFileByStorageNameAndFilePath(StorageEntity.MANAGED_STORAGE, "I_DO_NOT_EXIST"));
}
use of org.finra.herd.model.jpa.StorageFileEntity in project herd by FINRAOS.
the class StorageFileDaoTestHelper method createStorageFileEntity.
/**
* Creates and persists a new storage file entity.
*
* @param storageUnitEntity the storage unit entity
* @param filePath the file path
* @param fileSizeInBytes the size of the file in bytes
* @param rowCount the count of rows in the file
*
* @return the newly created storage file entity.
*/
public StorageFileEntity createStorageFileEntity(StorageUnitEntity storageUnitEntity, String filePath, Long fileSizeInBytes, Long rowCount) {
StorageFileEntity storageFileEntity = new StorageFileEntity();
storageFileEntity.setStorageUnit(storageUnitEntity);
storageFileEntity.setPath(filePath);
storageFileEntity.setFileSizeBytes(fileSizeInBytes);
storageFileEntity.setRowCount(rowCount);
return storageFileDao.saveAndRefresh(storageFileEntity);
}
use of org.finra.herd.model.jpa.StorageFileEntity in project herd by FINRAOS.
the class BusinessObjectDataStorageFileServiceTest method testCreateBusinessObjectDataStorageFilesS3ManagedPreviouslyRegisteredS3FileSizeIsNull.
@Test
public void testCreateBusinessObjectDataStorageFilesS3ManagedPreviouslyRegisteredS3FileSizeIsNull() throws Exception {
// Create and persist a storage unit entity.
StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(StorageEntity.MANAGED_STORAGE, NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BusinessObjectDataStatusEntity.UPLOADING, StorageUnitStatusEntity.ENABLED, testS3KeyPrefix);
// Create and persist a storage file with a null file size.
StorageFileEntity storageFileEntity = storageFileDaoTestHelper.createStorageFileEntity(storageUnitEntity, testS3KeyPrefix + "/" + FILE_PATH_1, NO_FILE_SIZE, NO_ROW_COUNT);
storageUnitEntity.getStorageFiles().add(storageFileEntity);
// Create and upload to S3 managed storage two test files with 1 KB file size.
businessObjectDataServiceTestHelper.prepareTestS3Files(testS3KeyPrefix, localTempPath, Arrays.asList(FILE_PATH_1, FILE_PATH_2));
// Try to add storage file to the business object data when an already registered storage file has a null file size.
try {
businessObjectDataStorageFileService.createBusinessObjectDataStorageFiles(new BusinessObjectDataStorageFilesCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, null, DATA_VERSION, StorageEntity.MANAGED_STORAGE, Arrays.asList(createFile(testS3KeyPrefix + "/" + FILE_PATH_2, FILE_SIZE_1_KB, ROW_COUNT_1000)), NO_DISCOVER_STORAGE_FILES));
fail("Should throw an IllegalArgumentException when an already registered storage file has a null file size");
} catch (IllegalArgumentException e) {
assertEquals(String.format("Previously registered storage file \"%s/%s\" has no file size specified.", testS3KeyPrefix, FILE_PATH_1, FILE_SIZE_2_KB, FILE_SIZE_1_KB), e.getMessage());
}
}
Aggregations