use of org.finra.herd.model.jpa.StorageEntity 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.StorageEntity 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.StorageEntity in project herd by FINRAOS.
the class StorageFileDaoTest method testGetStorageFileByStorageNameAndFilePathDuplicateFiles.
@Test
public void testGetStorageFileByStorageNameAndFilePathDuplicateFiles() throws Exception {
// Create relative database entities.
BusinessObjectDataEntity businessObjectDataEntity1 = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, INITIAL_DATA_VERSION, Boolean.TRUE, BDATA_STATUS);
BusinessObjectDataEntity businessObjectDataEntity2 = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, INITIAL_DATA_VERSION + 1, Boolean.TRUE, BDATA_STATUS);
StorageEntity storageEntity = storageDao.getStorageByName(StorageEntity.MANAGED_STORAGE);
StorageUnitEntity storageUnitEntity1 = storageUnitDaoTestHelper.createStorageUnitEntity(storageEntity, businessObjectDataEntity1, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
StorageUnitEntity storageUnitEntity2 = storageUnitDaoTestHelper.createStorageUnitEntity(storageEntity, businessObjectDataEntity2, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
storageFileDaoTestHelper.createStorageFileEntity(storageUnitEntity1, LOCAL_FILE, FILE_SIZE_1_KB, ROW_COUNT_1000);
storageFileDaoTestHelper.createStorageFileEntity(storageUnitEntity2, LOCAL_FILE, FILE_SIZE_1_KB, ROW_COUNT_1000);
try {
// Try to retrieve storage file.
storageFileDao.getStorageFileByStorageNameAndFilePath(StorageEntity.MANAGED_STORAGE, LOCAL_FILE);
fail("Should throw an IllegalArgumentException.");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().startsWith("Found more than one storage file with parameters"));
}
}
use of org.finra.herd.model.jpa.StorageEntity 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.StorageEntity in project herd by FINRAOS.
the class StorageDaoTestHelper method getBucketNameFromStorage.
/**
* Returns the bucket name of the specified storage name.
* <p/>
* Gets the storage with specified name and finds and returns the value of the attribute for the bucket name.
*
* @param storageName the name of the storage to get the bucket name for.
*
* @return S3 bucket name
* @throws IllegalStateException when either the storage or attribute is not found.
*/
private String getBucketNameFromStorage(String storageName) {
String s3BucketName = null;
StorageEntity storageEntity = storageDao.getStorageByName(storageName);
if (storageEntity == null) {
throw new IllegalStateException("storageEntity \"" + storageName + "\" not found");
}
for (StorageAttributeEntity storageAttributeEntity : storageEntity.getAttributes()) {
if (configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME).equals(storageAttributeEntity.getName())) {
s3BucketName = storageAttributeEntity.getValue();
break;
}
}
if (s3BucketName == null) {
throw new IllegalStateException("storageAttributeEntity with name " + configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME) + " not found for storage \"" + storageName + "\".");
}
return s3BucketName;
}
Aggregations