Search in sources :

Example 1 with BusinessObjectFormatDdl

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

the class BusinessObjectFormatServiceImpl method generateBusinessObjectFormatDdlCollectionImpl.

/**
 * Retrieves the DDL to initialize the specified type of the database system (e.g. Hive) by creating tables for a collection of business object formats.
 *
 * @param businessObjectFormatDdlCollectionRequest the business object format DDL collection request
 *
 * @return the business object format DDL information
 */
protected BusinessObjectFormatDdlCollectionResponse generateBusinessObjectFormatDdlCollectionImpl(BusinessObjectFormatDdlCollectionRequest businessObjectFormatDdlCollectionRequest) {
    // Perform the validation of the entire request, before we start processing the individual requests that requires the database access.
    validateBusinessObjectFormatDdlCollectionRequest(businessObjectFormatDdlCollectionRequest);
    // Process the individual requests and build the response.
    BusinessObjectFormatDdlCollectionResponse businessObjectFormatDdlCollectionResponse = new BusinessObjectFormatDdlCollectionResponse();
    List<BusinessObjectFormatDdl> businessObjectFormatDdlResponses = new ArrayList<>();
    businessObjectFormatDdlCollectionResponse.setBusinessObjectFormatDdlResponses(businessObjectFormatDdlResponses);
    List<String> ddls = new ArrayList<>();
    for (BusinessObjectFormatDdlRequest request : businessObjectFormatDdlCollectionRequest.getBusinessObjectFormatDdlRequests()) {
        // Please note that when calling to process individual ddl requests, we ask to skip the request validation and trimming step.
        BusinessObjectFormatDdl businessObjectFormatDdl = generateBusinessObjectFormatDdlImpl(request, true);
        businessObjectFormatDdlResponses.add(businessObjectFormatDdl);
        ddls.add(businessObjectFormatDdl.getDdl());
    }
    businessObjectFormatDdlCollectionResponse.setDdlCollection(StringUtils.join(ddls, "\n\n"));
    return businessObjectFormatDdlCollectionResponse;
}
Also used : BusinessObjectFormatDdlCollectionResponse(org.finra.herd.model.api.xml.BusinessObjectFormatDdlCollectionResponse) BusinessObjectFormatDdl(org.finra.herd.model.api.xml.BusinessObjectFormatDdl) ArrayList(java.util.ArrayList) BusinessObjectFormatDdlRequest(org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest)

Example 2 with BusinessObjectFormatDdl

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

the class BusinessObjectFormatServiceTest method testGenerateBusinessObjectFormatDdlNoCustomDdlEscapeBackslashInRowFormat.

@Test
public void testGenerateBusinessObjectFormatDdlNoCustomDdlEscapeBackslashInRowFormat() {
    // Prepare test data without custom ddl.
    List<SchemaColumn> partitionColumns = schemaColumnDaoTestHelper.getTestPartitionColumns();
    String partitionKey = partitionColumns.get(0).getName();
    businessObjectFormatServiceTestHelper.createDatabaseEntitiesForBusinessObjectFormatDdlTesting(FileTypeEntity.TXT_FILE_TYPE, partitionKey, BACKSLASH, BACKSLASH, BACKSLASH, schemaColumnDaoTestHelper.getTestSchemaColumns(), partitionColumns, null);
    // Retrieve business object format ddl.
    BusinessObjectFormatDdlRequest request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(null);
    BusinessObjectFormatDdl resultDdl = businessObjectFormatService.generateBusinessObjectFormatDdl(request);
    // Validate the results - please note that we do not escape single backslash in null value.
    String expectedRowFormat = "ROW FORMAT DELIMITED FIELDS TERMINATED BY '\\\\' ESCAPED BY '\\\\' NULL DEFINED AS '\\'";
    String expectedDdl = businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatDdl(PARTITION_COLUMNS.length, FIRST_COLUMN_NAME, FIRST_COLUMN_DATA_TYPE, expectedRowFormat, Hive13DdlGenerator.TEXT_HIVE_FILE_FORMAT, FileTypeEntity.TXT_FILE_TYPE, true, true);
    businessObjectFormatServiceTestHelper.validateBusinessObjectFormatDdl(null, expectedDdl, resultDdl);
}
Also used : BusinessObjectFormatDdl(org.finra.herd.model.api.xml.BusinessObjectFormatDdl) SchemaColumn(org.finra.herd.model.api.xml.SchemaColumn) BusinessObjectFormatDdlRequest(org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest) Test(org.junit.Test)

Example 3 with BusinessObjectFormatDdl

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

the class BusinessObjectFormatServiceTest method testGenerateBusinessObjectFormatDdlMissingOptionalParameters.

@Test
public void testGenerateBusinessObjectFormatDdlMissingOptionalParameters() {
    // Prepare test data without custom ddl.
    businessObjectFormatServiceTestHelper.createDatabaseEntitiesForBusinessObjectFormatDdlTesting(FileTypeEntity.TXT_FILE_TYPE, FIRST_PARTITION_COLUMN_NAME, SCHEMA_DELIMITER_PIPE, SCHEMA_ESCAPE_CHARACTER_BACKSLASH, SCHEMA_NULL_VALUE_BACKSLASH_N, schemaColumnDaoTestHelper.getTestSchemaColumns(), schemaColumnDaoTestHelper.getTestPartitionColumns(), CUSTOM_DDL_NAME);
    // Retrieve business object format ddl request without optional parameters.
    BusinessObjectFormatDdlRequest request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(BLANK_TEXT);
    request.setBusinessObjectFormatVersion(null);
    request.setIncludeDropTableStatement(null);
    request.setIncludeIfNotExistsOption(null);
    BusinessObjectFormatDdl resultDdl = businessObjectFormatService.generateBusinessObjectFormatDdl(request);
    // Validate the results.
    String expectedDdl = businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatDdl(PARTITION_COLUMNS.length, FIRST_COLUMN_NAME, FIRST_COLUMN_DATA_TYPE, ROW_FORMAT, Hive13DdlGenerator.TEXT_HIVE_FILE_FORMAT, FileTypeEntity.TXT_FILE_TYPE, false, false);
    businessObjectFormatServiceTestHelper.validateBusinessObjectFormatDdl("", expectedDdl, resultDdl);
}
Also used : BusinessObjectFormatDdl(org.finra.herd.model.api.xml.BusinessObjectFormatDdl) BusinessObjectFormatDdlRequest(org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest) Test(org.junit.Test)

Example 4 with BusinessObjectFormatDdl

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

the class BusinessObjectFormatServiceTest method testGenerateBusinessObjectFormatDdlNoCustomDdlEscapeSingleQuoteInRowFormat.

@Test
public void testGenerateBusinessObjectFormatDdlNoCustomDdlEscapeSingleQuoteInRowFormat() {
    // Prepare test data without custom ddl.
    List<SchemaColumn> partitionColumns = schemaColumnDaoTestHelper.getTestPartitionColumns();
    String partitionKey = partitionColumns.get(0).getName();
    businessObjectFormatServiceTestHelper.createDatabaseEntitiesForBusinessObjectFormatDdlTesting(FileTypeEntity.TXT_FILE_TYPE, partitionKey, SINGLE_QUOTE, SINGLE_QUOTE, SINGLE_QUOTE, schemaColumnDaoTestHelper.getTestSchemaColumns(), partitionColumns, null);
    // Retrieve business object format ddl.
    BusinessObjectFormatDdlRequest request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(null);
    BusinessObjectFormatDdl resultDdl = businessObjectFormatService.generateBusinessObjectFormatDdl(request);
    // Validate the results.
    String expectedRowFormat = "ROW FORMAT DELIMITED FIELDS TERMINATED BY '\\'' ESCAPED BY '\\'' NULL DEFINED AS '\\''";
    String expectedDdl = businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatDdl(PARTITION_COLUMNS.length, FIRST_COLUMN_NAME, FIRST_COLUMN_DATA_TYPE, expectedRowFormat, Hive13DdlGenerator.TEXT_HIVE_FILE_FORMAT, FileTypeEntity.TXT_FILE_TYPE, true, true);
    businessObjectFormatServiceTestHelper.validateBusinessObjectFormatDdl(null, expectedDdl, resultDdl);
}
Also used : BusinessObjectFormatDdl(org.finra.herd.model.api.xml.BusinessObjectFormatDdl) SchemaColumn(org.finra.herd.model.api.xml.SchemaColumn) BusinessObjectFormatDdlRequest(org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest) Test(org.junit.Test)

Example 5 with BusinessObjectFormatDdl

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

the class BusinessObjectFormatServiceTest method testGenerateBusinessObjectFormatDdlTrimParameters.

@Test
public void testGenerateBusinessObjectFormatDdlTrimParameters() {
    // Prepare test data.
    businessObjectFormatServiceTestHelper.createDatabaseEntitiesForBusinessObjectFormatDdlTesting();
    // Retrieve business object format ddl request with all string values requiring trimming.
    BusinessObjectFormatDdlRequest request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
    request.setBusinessObjectDefinitionName(addWhitespace(request.getBusinessObjectDefinitionName()));
    request.setBusinessObjectFormatUsage(addWhitespace(request.getBusinessObjectFormatUsage()));
    request.setBusinessObjectFormatFileType(addWhitespace(request.getBusinessObjectFormatFileType()));
    request.setTableName(addWhitespace(request.getTableName()));
    request.setCustomDdlName(addWhitespace(request.getCustomDdlName()));
    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)

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