use of org.finra.herd.service.helper.DdlGenerator 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;
}
Aggregations