Search in sources :

Example 26 with BusinessObjectFormatDdlRequest

use of org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest 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 27 with BusinessObjectFormatDdlRequest

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

the class BusinessObjectFormatServiceTest method testGenerateBusinessObjectFormatDdlNoCustomDdlForwardSlashInPartitionColumnName.

@Test
public void testGenerateBusinessObjectFormatDdlNoCustomDdlForwardSlashInPartitionColumnName() {
    // Prepare test data without custom ddl.
    String invalidPartitionColumnName = "INVALID_/_PRTN_CLMN";
    List<SchemaColumn> partitionColumns = schemaColumnDaoTestHelper.getTestPartitionColumns();
    partitionColumns.get(0).setName(invalidPartitionColumnName);
    businessObjectFormatServiceTestHelper.createDatabaseEntitiesForBusinessObjectFormatDdlTesting(FileTypeEntity.TXT_FILE_TYPE, PARTITION_KEY, SCHEMA_DELIMITER_PIPE, SCHEMA_ESCAPE_CHARACTER_BACKSLASH, SCHEMA_NULL_VALUE_BACKSLASH_N, schemaColumnDaoTestHelper.getTestSchemaColumns(), partitionColumns, null);
    // Try to retrieve business object format ddl for the format that uses unsupported schema column data type.
    BusinessObjectFormatDdlRequest request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(null);
    try {
        businessObjectFormatService.generateBusinessObjectFormatDdl(request);
        fail("Should throw an IllegalArgumentException when partition column name contains a '/' character.");
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Partition column name \"%s\" can not contain a '/' character. Business object format: " + "{namespace: \"%s\", businessObjectDefinitionName: \"%s\", businessObjectFormatUsage: \"%s\", " + "businessObjectFormatFileType: \"%s\", businessObjectFormatVersion: %d}", invalidPartitionColumnName, request.getNamespace(), request.getBusinessObjectDefinitionName(), request.getBusinessObjectFormatUsage(), request.getBusinessObjectFormatFileType(), request.getBusinessObjectFormatVersion()), e.getMessage());
    }
}
Also used : SchemaColumn(org.finra.herd.model.api.xml.SchemaColumn) BusinessObjectFormatDdlRequest(org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest) Test(org.junit.Test)

Example 28 with BusinessObjectFormatDdlRequest

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

the class BusinessObjectFormatServiceTest method testGenerateBusinessObjectFormatDdlMissingRequiredParameters.

@Test
public void testGenerateBusinessObjectFormatDdlMissingRequiredParameters() {
    BusinessObjectFormatDdlRequest request;
    // Try to retrieve business object format ddl when namespace parameter is not specified.
    request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
    request.setNamespace(BLANK_TEXT);
    try {
        businessObjectFormatService.generateBusinessObjectFormatDdl(request);
        fail("Should throw an IllegalArgumentException when namespace parameter is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A namespace must be specified.", e.getMessage());
    }
    // Try to retrieve business object format ddl when business object definition name parameter is not specified.
    request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
    request.setBusinessObjectDefinitionName(BLANK_TEXT);
    try {
        businessObjectFormatService.generateBusinessObjectFormatDdl(request);
        fail("Should throw an IllegalArgumentException when business object definition name parameter is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A business object definition name must be specified.", e.getMessage());
    }
    // Try to retrieve business object format ddl when business object format usage parameter is not specified.
    request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
    request.setBusinessObjectFormatUsage(BLANK_TEXT);
    try {
        businessObjectFormatService.generateBusinessObjectFormatDdl(request);
        fail("Should throw an IllegalArgumentException when business object format usage parameter is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A business object format usage must be specified.", e.getMessage());
    }
    // Try to retrieve business object format ddl when business object format file type parameter is not specified.
    request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
    request.setBusinessObjectFormatFileType(BLANK_TEXT);
    try {
        businessObjectFormatService.generateBusinessObjectFormatDdl(request);
        fail("Should throw an IllegalArgumentException when business object format file type parameter is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A business object format file type must be specified.", e.getMessage());
    }
    // Try to retrieve business object format ddl when output format parameter is not specified.
    request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
    request.setOutputFormat(null);
    try {
        businessObjectFormatService.generateBusinessObjectFormatDdl(request);
        fail("Should throw an IllegalArgumentException when output format parameter is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("An output format must be specified.", e.getMessage());
    }
    // Try to retrieve business object format ddl when table name parameter is not specified.
    request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
    request.setTableName(BLANK_TEXT);
    try {
        businessObjectFormatService.generateBusinessObjectFormatDdl(request);
        fail("Should throw an IllegalArgumentException when table name parameter is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A table name must be specified.", e.getMessage());
    }
}
Also used : BusinessObjectFormatDdlRequest(org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest) Test(org.junit.Test)

Example 29 with BusinessObjectFormatDdlRequest

use of org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest 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 30 with BusinessObjectFormatDdlRequest

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

BusinessObjectFormatDdlRequest (org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest)35 Test (org.junit.Test)30 BusinessObjectFormatDdl (org.finra.herd.model.api.xml.BusinessObjectFormatDdl)21 SchemaColumn (org.finra.herd.model.api.xml.SchemaColumn)11 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)3 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)3 ArrayList (java.util.ArrayList)2 BusinessObjectFormatDdlCollectionRequest (org.finra.herd.model.api.xml.BusinessObjectFormatDdlCollectionRequest)2 SchemaColumnEntity (org.finra.herd.model.jpa.SchemaColumnEntity)2 HashMap (java.util.HashMap)1 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)1 BusinessObjectDataDdlOutputFormatEnum (org.finra.herd.model.api.xml.BusinessObjectDataDdlOutputFormatEnum)1 BusinessObjectFormatDdlCollectionResponse (org.finra.herd.model.api.xml.BusinessObjectFormatDdlCollectionResponse)1 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)1 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)1 StorageEntity (org.finra.herd.model.jpa.StorageEntity)1 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)1