use of org.finra.herd.model.jpa.CustomDdlEntity in project herd by FINRAOS.
the class CustomDdlDaoImpl method getCustomDdlByKey.
@Override
public CustomDdlEntity getCustomDdlByKey(CustomDdlKey customDdlKey) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<CustomDdlEntity> criteria = builder.createQuery(CustomDdlEntity.class);
// The criteria root is the custom DDL.
Root<CustomDdlEntity> customDdlEntity = criteria.from(CustomDdlEntity.class);
// Join to the other tables we can filter on.
Join<CustomDdlEntity, BusinessObjectFormatEntity> businessObjectFormatEntity = customDdlEntity.join(CustomDdlEntity_.businessObjectFormat);
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)), customDdlKey.getNamespace().toUpperCase());
queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)), customDdlKey.getBusinessObjectDefinitionName().toUpperCase()));
queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage)), customDdlKey.getBusinessObjectFormatUsage().toUpperCase()));
queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(fileTypeEntity.get(FileTypeEntity_.code)), customDdlKey.getBusinessObjectFormatFileType().toUpperCase()));
queryRestriction = builder.and(queryRestriction, builder.equal(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion), customDdlKey.getBusinessObjectFormatVersion()));
queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(customDdlEntity.get(CustomDdlEntity_.customDdlName)), customDdlKey.getCustomDdlName().toUpperCase()));
// Add select and where clauses.
criteria.select(customDdlEntity).where(queryRestriction);
return executeSingleResultQuery(criteria, String.format("Found more than one custom DDL instance with parameters {businessObjectDefinitionName=\"%s\"," + " businessObjectFormatUsage=\"%s\", businessObjectFormatFileType=\"%s\", businessObjectFormatVersion=\"%d\", customDdlName=\"%s\"}.", customDdlKey.getBusinessObjectDefinitionName(), customDdlKey.getBusinessObjectFormatUsage(), customDdlKey.getBusinessObjectFormatFileType(), customDdlKey.getBusinessObjectFormatVersion(), customDdlKey.getCustomDdlName()));
}
use of org.finra.herd.model.jpa.CustomDdlEntity in project herd by FINRAOS.
the class CustomDdlDaoImpl method getCustomDdls.
@Override
public List<CustomDdlKey> getCustomDdls(BusinessObjectFormatKey businessObjectFormatKey) {
// Create the criteria builder and a tuple style criteria query.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Tuple> criteria = builder.createTupleQuery();
// The criteria root is the business object format.
Root<CustomDdlEntity> customDdlEntity = criteria.from(CustomDdlEntity.class);
// Join to the other tables we can filter on.
Join<CustomDdlEntity, BusinessObjectFormatEntity> businessObjectFormatEntity = customDdlEntity.join(CustomDdlEntity_.businessObjectFormat);
Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.businessObjectDefinition);
Join<BusinessObjectFormatEntity, FileTypeEntity> fileTypeEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.fileType);
Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntity = businessObjectDefinitionEntity.join(BusinessObjectDefinitionEntity_.namespace);
// Get the columns.
Path<String> namespaceCodeColumn = namespaceEntity.get(NamespaceEntity_.code);
Path<String> businessObjectDefinitionNameColumn = businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name);
Path<String> businessObjectFormatUsageColumn = businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage);
Path<String> fileTypeCodeColumn = fileTypeEntity.get(FileTypeEntity_.code);
Path<Integer> businessObjectFormatVersionColumn = businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion);
Path<String> customDdlNameColumn = customDdlEntity.get(CustomDdlEntity_.customDdlName);
// Create the standard restrictions (i.e. the standard where clauses).
Predicate queryRestriction = builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), businessObjectFormatKey.getNamespace().toUpperCase());
queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)), businessObjectFormatKey.getBusinessObjectDefinitionName().toUpperCase()));
queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage)), businessObjectFormatKey.getBusinessObjectFormatUsage().toUpperCase()));
queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(fileTypeEntity.get(FileTypeEntity_.code)), businessObjectFormatKey.getBusinessObjectFormatFileType().toUpperCase()));
queryRestriction = builder.and(queryRestriction, builder.equal(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion), businessObjectFormatKey.getBusinessObjectFormatVersion()));
// Add the select clause.
criteria.multiselect(namespaceCodeColumn, businessObjectDefinitionNameColumn, businessObjectFormatUsageColumn, fileTypeCodeColumn, businessObjectFormatVersionColumn, customDdlNameColumn);
// Add the where clause.
criteria.where(queryRestriction);
// Add the order by clause.
criteria.orderBy(builder.asc(customDdlNameColumn));
// Run the query to get a list of tuples back.
List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();
// Populate the "keys" objects from the returned tuples (i.e. 1 tuple for each row).
List<CustomDdlKey> customDdlKeys = new ArrayList<>();
for (Tuple tuple : tuples) {
CustomDdlKey customDdlKey = new CustomDdlKey();
customDdlKeys.add(customDdlKey);
customDdlKey.setNamespace(tuple.get(namespaceCodeColumn));
customDdlKey.setBusinessObjectDefinitionName(tuple.get(businessObjectDefinitionNameColumn));
customDdlKey.setBusinessObjectFormatUsage(tuple.get(businessObjectFormatUsageColumn));
customDdlKey.setBusinessObjectFormatFileType(tuple.get(fileTypeCodeColumn));
customDdlKey.setBusinessObjectFormatVersion(tuple.get(businessObjectFormatVersionColumn));
customDdlKey.setCustomDdlName(tuple.get(customDdlNameColumn));
}
return customDdlKeys;
}
use of org.finra.herd.model.jpa.CustomDdlEntity in project herd by FINRAOS.
the class BusinessObjectFormatServiceImpl method generateBusinessObjectFormatDdlImpl.
/**
* Retrieves the DDL to initialize the specified type of the database system (e.g. Hive) by creating a table for the requested business object format.
*
* @param request the business object format DDL request
* @param skipRequestValidation specifies whether to skip the request validation and trimming
*
* @return the business object format DDL information
*/
protected BusinessObjectFormatDdl generateBusinessObjectFormatDdlImpl(BusinessObjectFormatDdlRequest request, boolean skipRequestValidation) {
// Perform the validation.
if (!skipRequestValidation) {
validateBusinessObjectFormatDdlRequest(request);
}
// Get the business object format entity for the specified parameters and make sure it exists.
// Please note that when format version is not specified, we should get back the latest format version.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(new BusinessObjectFormatKey(request.getNamespace(), request.getBusinessObjectDefinitionName(), request.getBusinessObjectFormatUsage(), request.getBusinessObjectFormatFileType(), request.getBusinessObjectFormatVersion()));
// Get business object format key.
BusinessObjectFormatKey businessObjectFormatKey = businessObjectFormatHelper.getBusinessObjectFormatKey(businessObjectFormatEntity);
// Validate that format has schema information.
Assert.notEmpty(businessObjectFormatEntity.getSchemaColumns(), String.format("Business object format with namespace \"%s\", business object definition name \"%s\", format usage \"%s\", format file type \"%s\"," + " and format version \"%s\" doesn't have schema information.", businessObjectFormatKey.getNamespace(), businessObjectFormatKey.getBusinessObjectDefinitionName(), businessObjectFormatKey.getBusinessObjectFormatUsage(), businessObjectFormatKey.getBusinessObjectFormatFileType(), businessObjectFormatKey.getBusinessObjectFormatVersion()));
// If it was specified, retrieve the custom DDL and ensure it exists.
CustomDdlEntity customDdlEntity = null;
if (StringUtils.isNotBlank(request.getCustomDdlName())) {
customDdlEntity = customDdlDaoHelper.getCustomDdlEntity(new CustomDdlKey(businessObjectFormatKey.getNamespace(), businessObjectFormatKey.getBusinessObjectDefinitionName(), businessObjectFormatKey.getBusinessObjectFormatUsage(), businessObjectFormatKey.getBusinessObjectFormatFileType(), businessObjectFormatKey.getBusinessObjectFormatVersion(), request.getCustomDdlName()));
}
// Create business object format DDL object instance.
BusinessObjectFormatDdl businessObjectFormatDdl = new BusinessObjectFormatDdl();
businessObjectFormatDdl.setNamespace(businessObjectFormatKey.getNamespace());
businessObjectFormatDdl.setBusinessObjectDefinitionName(businessObjectFormatKey.getBusinessObjectDefinitionName());
businessObjectFormatDdl.setBusinessObjectFormatUsage(businessObjectFormatKey.getBusinessObjectFormatUsage());
businessObjectFormatDdl.setBusinessObjectFormatFileType(businessObjectFormatKey.getBusinessObjectFormatFileType());
businessObjectFormatDdl.setBusinessObjectFormatVersion(businessObjectFormatKey.getBusinessObjectFormatVersion());
businessObjectFormatDdl.setOutputFormat(request.getOutputFormat());
businessObjectFormatDdl.setTableName(request.getTableName());
businessObjectFormatDdl.setCustomDdlName(customDdlEntity != null ? customDdlEntity.getCustomDdlName() : request.getCustomDdlName());
DdlGenerator ddlGenerator = ddlGeneratorFactory.getDdlGenerator(request.getOutputFormat());
String ddl;
if (Boolean.TRUE.equals(request.isReplaceColumns())) {
ddl = ddlGenerator.generateReplaceColumnsStatement(request, businessObjectFormatEntity);
} else {
ddl = ddlGenerator.generateCreateTableDdl(request, businessObjectFormatEntity, customDdlEntity);
}
businessObjectFormatDdl.setDdl(ddl);
// Return business object format DDL.
return businessObjectFormatDdl;
}
use of org.finra.herd.model.jpa.CustomDdlEntity in project herd by FINRAOS.
the class BusinessObjectDataServiceImpl method generateBusinessObjectDataDdlImpl.
/**
* Retrieves the DDL to initialize the specified type of the database system to perform queries for a range of requested business object data in the
* specified storage.
*
* @param request the business object data DDL request
* @param skipRequestValidation specifies whether to skip the request validation and trimming
*
* @return the business object data DDL information
*/
protected BusinessObjectDataDdl generateBusinessObjectDataDdlImpl(BusinessObjectDataDdlRequest request, boolean skipRequestValidation) {
// Perform the validation.
if (!skipRequestValidation) {
validateBusinessObjectDataDdlRequest(request);
}
// Get the business object format entity for the specified parameters and make sure it exists.
// Please note that when format version is not specified, we should get back the latest format version.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(new BusinessObjectFormatKey(request.getNamespace(), request.getBusinessObjectDefinitionName(), request.getBusinessObjectFormatUsage(), request.getBusinessObjectFormatFileType(), request.getBusinessObjectFormatVersion()));
// Validate that format has schema information.
Assert.notEmpty(businessObjectFormatEntity.getSchemaColumns(), String.format("Business object format with namespace \"%s\", business object definition name \"%s\", format usage \"%s\", format file type \"%s\"," + " and format version \"%s\" doesn't have schema information.", businessObjectFormatEntity.getBusinessObjectDefinition().getNamespace().getCode(), businessObjectFormatEntity.getBusinessObjectDefinition().getName(), businessObjectFormatEntity.getUsage(), businessObjectFormatEntity.getFileType().getCode(), businessObjectFormatEntity.getBusinessObjectFormatVersion()));
// If it was specified, retrieve the custom DDL and ensure it exists.
CustomDdlEntity customDdlEntity = null;
if (StringUtils.isNotBlank(request.getCustomDdlName())) {
CustomDdlKey customDdlKey = new CustomDdlKey(businessObjectFormatEntity.getBusinessObjectDefinition().getNamespace().getCode(), businessObjectFormatEntity.getBusinessObjectDefinition().getName(), businessObjectFormatEntity.getUsage(), businessObjectFormatEntity.getFileType().getCode(), businessObjectFormatEntity.getBusinessObjectFormatVersion(), request.getCustomDdlName());
customDdlEntity = customDdlDaoHelper.getCustomDdlEntity(customDdlKey);
}
// Validate that specified storages exist and of a proper storage platform type.
List<String> storageNames = new ArrayList<>();
if (StringUtils.isNotBlank(request.getStorageName())) {
storageNames.add(request.getStorageName());
}
if (!CollectionUtils.isEmpty(request.getStorageNames())) {
storageNames.addAll(request.getStorageNames());
}
List<StorageEntity> storageEntities = new ArrayList<>();
for (String storageName : storageNames) {
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(storageName);
// Only S3 storage platform is currently supported.
Assert.isTrue(storageEntity.getStoragePlatform().getName().equals(StoragePlatformEntity.S3), String.format("Cannot generate DDL for \"%s\" storage platform.", storageEntity.getStoragePlatform().getName()));
storageEntities.add(storageEntity);
}
// Validate that all storages have S3 bucket name configured.
Map<StorageEntity, String> s3BucketNames = new HashMap<>();
for (StorageEntity storageEntity : storageEntities) {
// Please note that since S3 bucket name attribute value is required we pass a "true" flag.
String s3BucketName = storageHelper.getStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), storageEntity, true);
s3BucketNames.put(storageEntity, s3BucketName);
}
// Create and initialize a business object data DDL object instance.
BusinessObjectDataDdl businessObjectDataDdl = createBusinessObjectDataDdl(request);
businessObjectDataDdl.setDdl(ddlGeneratorFactory.getDdlGenerator(request.getOutputFormat()).generateCreateTableDdl(request, businessObjectFormatEntity, customDdlEntity, storageNames, storageEntities, s3BucketNames));
return businessObjectDataDdl;
}
use of org.finra.herd.model.jpa.CustomDdlEntity in project herd by FINRAOS.
the class CustomDdlServiceImpl method deleteCustomDdl.
/**
* Deletes an existing custom DDL by key.
*
* @param customDdlKey the custom DDL key
*
* @return the custom DDL that got deleted
*/
@NamespacePermission(fields = "#customDdlKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public CustomDdl deleteCustomDdl(CustomDdlKey customDdlKey) {
// Validate and trim the key.
customDdlHelper.validateCustomDdlKey(customDdlKey);
// Retrieve and ensure that a custom DDL already exists with the specified key.
CustomDdlEntity customDdlEntity = customDdlDaoHelper.getCustomDdlEntity(customDdlKey);
// Delete the custom DDL.
customDdlDao.delete(customDdlEntity);
// Create and return the custom DDL object from the deleted entity.
return createCustomDdlFromEntity(customDdlEntity);
}
Aggregations