Search in sources :

Example 1 with BusinessObjectFormatDdlRequest

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

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

the class BusinessObjectFormatServiceImpl method validateBusinessObjectFormatDdlCollectionRequest.

/**
 * Validates a business object format DDL collection request. This method also trims appropriate request parameters.
 *
 * @param businessObjectFormatDdlCollectionRequest the request
 *
 * @throws IllegalArgumentException if any validation errors were found
 */
private void validateBusinessObjectFormatDdlCollectionRequest(BusinessObjectFormatDdlCollectionRequest businessObjectFormatDdlCollectionRequest) {
    Assert.notNull(businessObjectFormatDdlCollectionRequest, "A business object format DDL collection request must be specified.");
    Assert.isTrue(!CollectionUtils.isEmpty(businessObjectFormatDdlCollectionRequest.getBusinessObjectFormatDdlRequests()), "At least one business object format DDL request must be specified.");
    for (BusinessObjectFormatDdlRequest request : businessObjectFormatDdlCollectionRequest.getBusinessObjectFormatDdlRequests()) {
        validateBusinessObjectFormatDdlRequest(request);
    }
}
Also used : BusinessObjectFormatDdlRequest(org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest)

Example 3 with BusinessObjectFormatDdlRequest

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

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

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

the class BusinessObjectFormatServiceTest method testGenerateBusinessObjectFormatDdlInvalidParameters.

@Test
public void testGenerateBusinessObjectFormatDdlInvalidParameters() {
    // Prepare test data.
    businessObjectFormatServiceTestHelper.createDatabaseEntitiesForBusinessObjectFormatDdlTesting();
    BusinessObjectFormatDdlRequest request;
    // Try to retrieve business object format ddl using non-existing format.
    request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
    request.setBusinessObjectDefinitionName("I_DO_NOT_EXIST");
    try {
        businessObjectFormatService.generateBusinessObjectFormatDdl(request);
        fail("Should throw an ObjectNotFoundException when non-existing business object format is used.");
    } catch (ObjectNotFoundException e) {
        assertEquals(businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatNotFoundErrorMessage(request.getNamespace(), request.getBusinessObjectDefinitionName(), request.getBusinessObjectFormatUsage(), request.getBusinessObjectFormatFileType(), request.getBusinessObjectFormatVersion()), e.getMessage());
    }
    // Try to retrieve business object format ddl using non-existing custom ddl.
    request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
    request.setCustomDdlName("I_DO_NOT_EXIST");
    try {
        businessObjectFormatService.generateBusinessObjectFormatDdl(request);
        fail("Should throw an ObjectNotFoundException when non-existing custom ddl is used.");
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Custom DDL with name \"%s\" does not exist for business object format with namespace \"%s\", " + "business object definition name \"%s\", format usage \"%s\", format file type \"%s\", and format version \"%d\".", request.getCustomDdlName(), request.getNamespace(), request.getBusinessObjectDefinitionName(), request.getBusinessObjectFormatUsage(), request.getBusinessObjectFormatFileType(), request.getBusinessObjectFormatVersion()), e.getMessage());
    }
}
Also used : ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) 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