use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class AbstractHerdDao method getMaximumBusinessObjectDataVersionSubQuery.
/**
* TODO This method may be bdata specific. Consider creating new abstract class to group all bdata related DAO. Builds a sub-query to select the maximum
* business object data version.
*
* @param builder the criteria builder
* @param criteria the criteria query
* @param businessObjectDataEntity the business object data entity that appears in the from clause of the main query
* @param businessObjectFormatEntity the business object format entity that appears in the from clause of the main query
* @param businessObjectDataStatus the business object data 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 selectOnlyAvailableStorageUnits specifies if only available storage units will be selected or any storage units regardless of their status
*
* @return the sub-query to select the maximum business object data version
*/
protected Subquery<Integer> getMaximumBusinessObjectDataVersionSubQuery(CriteriaBuilder builder, CriteriaQuery<?> criteria, From<?, BusinessObjectDataEntity> businessObjectDataEntity, From<?, BusinessObjectFormatEntity> businessObjectFormatEntity, String businessObjectDataStatus, List<String> storageNames, String storagePlatformType, String excludedStoragePlatformType, boolean selectOnlyAvailableStorageUnits) {
// Business object data version is not specified, so get the latest one in the specified storage.
Subquery<Integer> subQuery = criteria.subquery(Integer.class);
// The criteria root is the business object data.
Root<BusinessObjectDataEntity> subBusinessObjectDataEntity = subQuery.from(BusinessObjectDataEntity.class);
// Join to the other tables we can filter on.
Join<BusinessObjectDataEntity, StorageUnitEntity> subStorageUnitEntity = subBusinessObjectDataEntity.join(BusinessObjectDataEntity_.storageUnits);
Join<StorageUnitEntity, StorageEntity> subStorageEntity = subStorageUnitEntity.join(StorageUnitEntity_.storage);
Join<StorageEntity, StoragePlatformEntity> subStoragePlatformEntity = subStorageEntity.join(StorageEntity_.storagePlatform);
Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> subBusinessObjectFormatEntity = subBusinessObjectDataEntity.join(BusinessObjectDataEntity_.businessObjectFormat);
Join<StorageUnitEntity, StorageUnitStatusEntity> subStorageUnitStatusEntity = subStorageUnitEntity.join(StorageUnitEntity_.status);
// Add a standard restriction on business object format.
Predicate subQueryRestriction = builder.equal(subBusinessObjectFormatEntity, businessObjectFormatEntity);
// Create and add standard restrictions on primary and sub-partition values.
subQueryRestriction = builder.and(subQueryRestriction, getQueryRestrictionOnPartitionValues(builder, subBusinessObjectDataEntity, businessObjectDataEntity));
// If specified, create and add a standard restriction on business object data status.
if (businessObjectDataStatus != null) {
Join<BusinessObjectDataEntity, BusinessObjectDataStatusEntity> subBusinessObjectDataStatusEntity = subBusinessObjectDataEntity.join(BusinessObjectDataEntity_.status);
subQueryRestriction = builder.and(subQueryRestriction, builder.equal(builder.upper(subBusinessObjectDataStatusEntity.get(BusinessObjectDataStatusEntity_.code)), businessObjectDataStatus.toUpperCase()));
}
// Create and add a standard restriction on storage.
subQueryRestriction = builder.and(subQueryRestriction, getQueryRestrictionOnStorage(builder, subStorageEntity, subStoragePlatformEntity, storageNames, storagePlatformType, excludedStoragePlatformType));
// If specified, add a restriction on storage unit status availability flag.
if (selectOnlyAvailableStorageUnits) {
subQueryRestriction = builder.and(subQueryRestriction, builder.isTrue(subStorageUnitStatusEntity.get(StorageUnitStatusEntity_.available)));
}
subQuery.select(builder.max(subBusinessObjectDataEntity.get(BusinessObjectDataEntity_.version))).where(subQueryRestriction);
return subQuery;
}
use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class BusinessObjectFormatDaoImpl method getBusinessObjectFormatByAltKey.
@Override
public BusinessObjectFormatEntity getBusinessObjectFormatByAltKey(BusinessObjectFormatKey businessObjectFormatKey) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<BusinessObjectFormatEntity> criteria = builder.createQuery(BusinessObjectFormatEntity.class);
// The criteria root is the business object format.
Root<BusinessObjectFormatEntity> businessObjectFormatEntity = criteria.from(BusinessObjectFormatEntity.class);
// Join to the other tables we can filter on.
Join<BusinessObjectFormatEntity, FileTypeEntity> fileTypeEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.fileType);
Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.businessObjectDefinition);
// Create the standard restrictions (i.e. the standard where clauses).
// Please note that we specify not to ignore the business object format version.
Predicate queryRestriction = getQueryRestriction(builder, businessObjectFormatEntity, fileTypeEntity, businessObjectDefinitionEntity, businessObjectFormatKey, false);
// If a business format version was not specified, use the latest one.
if (businessObjectFormatKey.getBusinessObjectFormatVersion() == null) {
queryRestriction = builder.and(queryRestriction, builder.isTrue(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.latestVersion)));
}
criteria.select(businessObjectFormatEntity).where(queryRestriction);
return executeSingleResultQuery(criteria, String.format("Found more than one business object format instance with parameters " + "{namespace=\"%s\", businessObjectDefinitionName=\"%s\", businessObjectFormatUsage=\"%s\", businessObjectFormatFileType=\"%s\", " + "businessObjectFormatVersion=\"%d\"}.", businessObjectFormatKey.getNamespace(), businessObjectFormatKey.getBusinessObjectDefinitionName(), businessObjectFormatKey.getBusinessObjectFormatUsage(), businessObjectFormatKey.getBusinessObjectFormatFileType(), businessObjectFormatKey.getBusinessObjectFormatVersion()));
}
use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class BusinessObjectFormatDaoImpl method getLatestVersionBusinessObjectFormatsByBusinessObjectDefinition.
@Override
public List<BusinessObjectFormatEntity> getLatestVersionBusinessObjectFormatsByBusinessObjectDefinition(BusinessObjectDefinitionKey businessObjectDefinitionKey) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<BusinessObjectFormatEntity> criteria = builder.createQuery(BusinessObjectFormatEntity.class);
// The criteria root is the business object format.
Root<BusinessObjectFormatEntity> businessObjectFormatEntity = criteria.from(BusinessObjectFormatEntity.class);
// Join to the other tables we can filter on.
Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.businessObjectDefinition);
Join<BusinessObjectFormatEntity, FileTypeEntity> fileTypeEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.fileType);
Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntity = businessObjectDefinitionEntity.join(BusinessObjectDefinitionEntity_.namespace);
// Create the standard restrictions (i.e. the standard where clauses).
Predicate queryRestriction = builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), businessObjectDefinitionKey.getNamespace().toUpperCase());
queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)), businessObjectDefinitionKey.getBusinessObjectDefinitionName().toUpperCase()));
// Add the order by clause.
List<Order> orderBy = new ArrayList<>();
orderBy.add(builder.asc(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage)));
orderBy.add(builder.asc(fileTypeEntity.get(FileTypeEntity_.code)));
queryRestriction = builder.and(queryRestriction, builder.equal(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.latestVersion), true));
criteria.orderBy(orderBy);
// Add the where clause.
criteria.where(queryRestriction);
return entityManager.createQuery(criteria).getResultList();
}
use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class StorageUnitServiceGetS3KeyPrefixTest method testGetS3PrefixWhenSchemaWithoutPartitionColumns.
@Test
public void testGetS3PrefixWhenSchemaWithoutPartitionColumns() {
// Get a list of test schema partition columns and use the first column name as the partition key.
List<SchemaColumn> partitionColumns = schemaColumnDaoTestHelper.getTestPartitionColumns();
String partitionKey = partitionColumns.get(0).getName();
// Create and persist a business object format entity without partitions
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, FORMAT_DESCRIPTION, LATEST_VERSION_FLAG_SET, partitionKey, NO_PARTITION_KEY_GROUP, NO_ATTRIBUTES, SCHEMA_DELIMITER_PIPE, SCHEMA_ESCAPE_CHARACTER_BACKSLASH, SCHEMA_NULL_VALUE_BACKSLASH_N, schemaColumnDaoTestHelper.getTestSchemaColumns(), null);
// Create and persist an S3 storage with the S3 key prefix velocity template attribute.
storageDaoTestHelper.createStorageEntity(STORAGE_NAME, StoragePlatformEntity.S3, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), S3_KEY_PREFIX_VELOCITY_TEMPLATE);
// getS3Prefix request should fail with an appropriate message.
try {
storageUnitService.getS3KeyPrefix(new BusinessObjectDataKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, null), partitionKey, STORAGE_NAME, false);
} catch (IllegalArgumentException e) {
assertEquals(String.format("Schema partition(s) must be defined when using subpartition values for business object format {%s}.", businessObjectFormatHelper.businessObjectFormatKeyToString(businessObjectFormatHelper.getBusinessObjectFormatKey(businessObjectFormatHelper.createBusinessObjectFormatFromEntity(businessObjectFormatEntity)))), e.getMessage());
}
}
use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class MessageNotificationEventServiceTest method testProcessBusinessObjectFormatVersionChangeNotificationEventHerdSqsNotificationNotEnabled.
@Test
public void testProcessBusinessObjectFormatVersionChangeNotificationEventHerdSqsNotificationNotEnabled() throws Exception {
// Create a business object format entity.
BusinessObjectDataInvalidateUnregisteredRequest request = new BusinessObjectDataInvalidateUnregisteredRequest(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, StorageEntity.MANAGED_STORAGE);
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatServiceTestHelper.createBusinessObjectFormat(request);
// Get a business object data key.
BusinessObjectFormatKey businessObjectFormatKey = businessObjectFormatHelper.getBusinessObjectFormatKey(businessObjectFormatEntity);
// Override configuration.
Map<String, Object> overrideMap = new HashMap<>();
overrideMap.put(ConfigurationValue.HERD_NOTIFICATION_SQS_ENABLED.getKey(), false);
modifyPropertySourceInEnvironment(overrideMap);
try {
// Trigger the notification.
List<NotificationMessage> result = messageNotificationEventService.processBusinessObjectFormatVersionChangeNotificationEvent(businessObjectFormatKey, NO_OLD_BUSINESS_OBJECT_FORMAT_VERSION);
// Validate the results.
assertTrue(CollectionUtils.isEmpty(result));
} finally {
// Restore the property sources so we don't affect other tests.
restorePropertySourceInEnvironment();
}
}
Aggregations