Search in sources :

Example 16 with BusinessObjectFormatDdl

use of org.finra.herd.model.api.xml.BusinessObjectFormatDdl in project herd by FINRAOS.

the class BusinessObjectFormatServiceTestHelper method getExpectedBusinessObjectFormatDdlCollectionResponse.

/**
 * Creates an expected generate business object format ddl collection response using hard coded test values.
 *
 * @return the business object format ddl collection response
 */
public BusinessObjectFormatDdlCollectionResponse getExpectedBusinessObjectFormatDdlCollectionResponse() {
    // Prepare a generate business object data collection response using hard coded test values.
    BusinessObjectFormatDdlCollectionResponse businessObjectFormatDdlCollectionResponse = new BusinessObjectFormatDdlCollectionResponse();
    // Create a list of business object data ddl responses.
    List<BusinessObjectFormatDdl> businessObjectFormatDdlResponses = new ArrayList<>();
    businessObjectFormatDdlCollectionResponse.setBusinessObjectFormatDdlResponses(businessObjectFormatDdlResponses);
    // Get the actual HIVE DDL expected to be generated.
    String expectedDdl = getExpectedBusinessObjectFormatDdl();
    // Create a business object data ddl response.
    BusinessObjectFormatDdl expectedBusinessObjectFormatDdl = new BusinessObjectFormatDdl(AbstractServiceTest.NAMESPACE, AbstractServiceTest.BDEF_NAME, AbstractServiceTest.FORMAT_USAGE_CODE, FileTypeEntity.TXT_FILE_TYPE, AbstractServiceTest.FORMAT_VERSION, BusinessObjectDataDdlOutputFormatEnum.HIVE_13_DDL, AbstractServiceTest.TABLE_NAME, AbstractServiceTest.NO_CUSTOM_DDL_NAME, expectedDdl);
    // Add two business object ddl responses to the collection response.
    businessObjectFormatDdlResponses.add(expectedBusinessObjectFormatDdl);
    businessObjectFormatDdlResponses.add(expectedBusinessObjectFormatDdl);
    // Set the expected DDL collection value.
    businessObjectFormatDdlCollectionResponse.setDdlCollection(String.format("%s\n\n%s", expectedDdl, expectedDdl));
    return businessObjectFormatDdlCollectionResponse;
}
Also used : BusinessObjectFormatDdlCollectionResponse(org.finra.herd.model.api.xml.BusinessObjectFormatDdlCollectionResponse) BusinessObjectFormatDdl(org.finra.herd.model.api.xml.BusinessObjectFormatDdl) ArrayList(java.util.ArrayList)

Example 17 with BusinessObjectFormatDdl

use of org.finra.herd.model.api.xml.BusinessObjectFormatDdl 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)

Example 18 with BusinessObjectFormatDdl

use of org.finra.herd.model.api.xml.BusinessObjectFormatDdl in project herd by FINRAOS.

the class GenerateBusinessObjectFormatDdl method executeImpl.

@Override
public void executeImpl(DelegateExecution execution) throws Exception {
    String namespace = activitiHelper.getExpressionVariableAsString(this.namespace, execution);
    String businessObjectDefinitionName = activitiHelper.getExpressionVariableAsString(this.businessObjectDefinitionName, execution);
    String businessObjectFormatUsage = activitiHelper.getExpressionVariableAsString(this.businessObjectFormatUsage, execution);
    String businessObjectFormatFileType = activitiHelper.getExpressionVariableAsString(this.businessObjectFormatFileType, execution);
    Integer businessObjectFormatVersion = activitiHelper.getExpressionVariableAsInteger(this.businessObjectFormatVersion, execution, "businessObjectFormatVersion", false);
    String outputFormat = activitiHelper.getRequiredExpressionVariableAsString(this.outputFormat, execution, "outputFormat");
    BusinessObjectDataDdlOutputFormatEnum outputFormatEnum = BusinessObjectDataDdlOutputFormatEnum.fromValue(outputFormat);
    String tableName = activitiHelper.getExpressionVariableAsString(this.tableName, execution);
    String customDdlName = activitiHelper.getExpressionVariableAsString(this.customDdlName, execution);
    Boolean includeDropTableStatement = activitiHelper.getExpressionVariableAsBoolean(this.includeDropTableStatement, execution, "includeDropTableStatement", false, false);
    Boolean includeIfNotExistsOption = activitiHelper.getExpressionVariableAsBoolean(this.includeIfNotExistsOption, execution, "includeIfNotExistsOption", false, false);
    Boolean replaceColumns = activitiHelper.getExpressionVariableAsBoolean(this.replaceColumns, execution, "replaceColumns", false, false);
    BusinessObjectFormatDdlRequest businessObjectFormatDdlRequest = new BusinessObjectFormatDdlRequest();
    businessObjectFormatDdlRequest.setNamespace(namespace);
    businessObjectFormatDdlRequest.setBusinessObjectDefinitionName(businessObjectDefinitionName);
    businessObjectFormatDdlRequest.setBusinessObjectFormatUsage(businessObjectFormatUsage);
    businessObjectFormatDdlRequest.setBusinessObjectFormatFileType(businessObjectFormatFileType);
    businessObjectFormatDdlRequest.setBusinessObjectFormatVersion(businessObjectFormatVersion);
    businessObjectFormatDdlRequest.setOutputFormat(outputFormatEnum);
    businessObjectFormatDdlRequest.setTableName(tableName);
    businessObjectFormatDdlRequest.setCustomDdlName(customDdlName);
    businessObjectFormatDdlRequest.setIncludeDropTableStatement(includeDropTableStatement);
    businessObjectFormatDdlRequest.setIncludeIfNotExistsOption(includeIfNotExistsOption);
    businessObjectFormatDdlRequest.setReplaceColumns(replaceColumns);
    BusinessObjectFormatDdl businessObjectFormatDdl = businessObjectFormatService.generateBusinessObjectFormatDdl(businessObjectFormatDdlRequest);
    setTaskWorkflowVariable(execution, VARIABLE_DDL, businessObjectFormatDdl.getDdl());
}
Also used : BusinessObjectFormatDdl(org.finra.herd.model.api.xml.BusinessObjectFormatDdl) BusinessObjectDataDdlOutputFormatEnum(org.finra.herd.model.api.xml.BusinessObjectDataDdlOutputFormatEnum) BusinessObjectFormatDdlRequest(org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest)

Example 19 with BusinessObjectFormatDdl

use of org.finra.herd.model.api.xml.BusinessObjectFormatDdl in project herd by FINRAOS.

the class BusinessObjectFormatServiceTest method testGenerateBusinessObjectFormatDdlLowerCaseParameters.

@Test
public void testGenerateBusinessObjectFormatDdlLowerCaseParameters() {
    // Prepare test data.
    businessObjectFormatServiceTestHelper.createDatabaseEntitiesForBusinessObjectFormatDdlTesting();
    // Retrieve business object format ddl request with all string values in lower case.
    BusinessObjectFormatDdlRequest request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
    request.setNamespace(request.getNamespace().toLowerCase());
    request.setBusinessObjectDefinitionName(request.getBusinessObjectDefinitionName().toLowerCase());
    request.setBusinessObjectFormatUsage(request.getBusinessObjectFormatUsage().toLowerCase());
    request.setBusinessObjectFormatFileType(request.getBusinessObjectFormatFileType().toLowerCase());
    request.setCustomDdlName(request.getCustomDdlName().toLowerCase());
    BusinessObjectFormatDdl resultDdl = businessObjectFormatService.generateBusinessObjectFormatDdl(request);
    // Validate the results.
    businessObjectFormatServiceTestHelper.validateBusinessObjectFormatDdl(CUSTOM_DDL_NAME, businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatDdl(AbstractServiceTest.PARTITION_COLUMNS.length, AbstractServiceTest.FIRST_COLUMN_NAME, AbstractServiceTest.FIRST_COLUMN_DATA_TYPE, AbstractServiceTest.ROW_FORMAT, Hive13DdlGenerator.TEXT_HIVE_FILE_FORMAT, FileTypeEntity.TXT_FILE_TYPE, true, true), resultDdl);
}
Also used : BusinessObjectFormatDdl(org.finra.herd.model.api.xml.BusinessObjectFormatDdl) BusinessObjectFormatDdlRequest(org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest) Test(org.junit.Test)

Example 20 with BusinessObjectFormatDdl

use of org.finra.herd.model.api.xml.BusinessObjectFormatDdl in project herd by FINRAOS.

the class BusinessObjectFormatServiceTest method testGenerateBusinessObjectFormatDdlWhenReplaceColumnsMissingOptionalParameters.

/**
 * Asserts that when replace columns is TRUE and other optional parameters are not specified.
 */
@Test
public void testGenerateBusinessObjectFormatDdlWhenReplaceColumnsMissingOptionalParameters() {
    businessObjectFormatServiceTestHelper.createDatabaseEntitiesForBusinessObjectFormatDdlTesting();
    BusinessObjectFormatDdlRequest businessObjectFormatDdlRequest = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(null);
    businessObjectFormatDdlRequest.setReplaceColumns(true);
    businessObjectFormatDdlRequest.setIncludeDropTableStatement(null);
    businessObjectFormatDdlRequest.setIncludeIfNotExistsOption(null);
    BusinessObjectFormatDdl result = businessObjectFormatService.generateBusinessObjectFormatDdl(businessObjectFormatDdlRequest);
    Assert.assertEquals("result DDL", result.getDdl(), "ALTER TABLE `" + businessObjectFormatDdlRequest.getTableName() + "` REPLACE COLUMNS (\n" + "    `COLUMN001` TINYINT,\n" + "    `COLUMN002` SMALLINT COMMENT 'This is \\'COLUMN002\\' column. Here are \\'single\\' and \"double\" quotes along with a backslash \\.',\n" + "    `COLUMN003` INT,\n" + "    `COLUMN004` BIGINT,\n" + "    `COLUMN005` FLOAT,\n" + "    `COLUMN006` DOUBLE,\n" + "    `COLUMN007` DECIMAL,\n" + "    `COLUMN008` DECIMAL(p,s),\n" + "    `COLUMN009` DECIMAL,\n" + "    `COLUMN010` DECIMAL(p),\n" + "    `COLUMN011` DECIMAL(p,s),\n" + "    `COLUMN012` TIMESTAMP,\n" + "    `COLUMN013` DATE,\n" + "    `COLUMN014` STRING,\n" + "    `COLUMN015` VARCHAR(n),\n" + "    `COLUMN016` VARCHAR(n),\n" + "    `COLUMN017` CHAR(n),\n" + "    `COLUMN018` BOOLEAN,\n" + "    `COLUMN019` BINARY);");
}
Also used : BusinessObjectFormatDdl(org.finra.herd.model.api.xml.BusinessObjectFormatDdl) BusinessObjectFormatDdlRequest(org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest) Test(org.junit.Test)

Aggregations

BusinessObjectFormatDdl (org.finra.herd.model.api.xml.BusinessObjectFormatDdl)24 BusinessObjectFormatDdlRequest (org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest)21 Test (org.junit.Test)20 SchemaColumn (org.finra.herd.model.api.xml.SchemaColumn)9 ArrayList (java.util.ArrayList)2 BusinessObjectFormatDdlCollectionResponse (org.finra.herd.model.api.xml.BusinessObjectFormatDdlCollectionResponse)2 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)2 HashMap (java.util.HashMap)1 BusinessObjectDataDdlOutputFormatEnum (org.finra.herd.model.api.xml.BusinessObjectDataDdlOutputFormatEnum)1 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)1 CustomDdlKey (org.finra.herd.model.api.xml.CustomDdlKey)1 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)1 CustomDdlEntity (org.finra.herd.model.jpa.CustomDdlEntity)1 StorageEntity (org.finra.herd.model.jpa.StorageEntity)1 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)1 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)1 DdlGenerator (org.finra.herd.service.helper.DdlGenerator)1