Search in sources :

Example 1 with DdlGenerator

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;
}
Also used : CustomDdlEntity(org.finra.herd.model.jpa.CustomDdlEntity) BusinessObjectFormatDdl(org.finra.herd.model.api.xml.BusinessObjectFormatDdl) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) DdlGenerator(org.finra.herd.service.helper.DdlGenerator) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) CustomDdlKey(org.finra.herd.model.api.xml.CustomDdlKey)

Aggregations

BusinessObjectFormatDdl (org.finra.herd.model.api.xml.BusinessObjectFormatDdl)1 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)1 CustomDdlKey (org.finra.herd.model.api.xml.CustomDdlKey)1 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)1 CustomDdlEntity (org.finra.herd.model.jpa.CustomDdlEntity)1 DdlGenerator (org.finra.herd.service.helper.DdlGenerator)1