use of org.finra.herd.model.api.xml.CustomDdlKey in project herd by FINRAOS.
the class CustomDdlServiceTestHelper method createCustomDdlCreateRequest.
/**
* Creates a custom DDL create request.
*
* @return the newly created custom DDL create request
*/
public CustomDdlCreateRequest createCustomDdlCreateRequest(String namespaceCode, String businessObjectDefinitionName, String businessObjectFormatUsage, String businessObjectFormatFileType, Integer businessObjectFormatVersion, String customDdlName, String ddl) {
CustomDdlCreateRequest request = new CustomDdlCreateRequest();
request.setCustomDdlKey(new CustomDdlKey(namespaceCode, businessObjectDefinitionName, businessObjectFormatUsage, businessObjectFormatFileType, businessObjectFormatVersion, customDdlName));
request.setDdl(ddl);
return request;
}
use of org.finra.herd.model.api.xml.CustomDdlKey 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;
}
use of org.finra.herd.model.api.xml.CustomDdlKey in project herd by FINRAOS.
the class BusinessObjectDataServiceImpl method generateBusinessObjectDataDdlImpl.
/**
* Retrieves the DDL to initialize the specified type of the database system to perform queries for a range of requested business object data in the
* specified storage.
*
* @param request the business object data DDL request
* @param skipRequestValidation specifies whether to skip the request validation and trimming
*
* @return the business object data DDL information
*/
protected BusinessObjectDataDdl generateBusinessObjectDataDdlImpl(BusinessObjectDataDdlRequest request, boolean skipRequestValidation) {
// Perform the validation.
if (!skipRequestValidation) {
validateBusinessObjectDataDdlRequest(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()));
// 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.", businessObjectFormatEntity.getBusinessObjectDefinition().getNamespace().getCode(), businessObjectFormatEntity.getBusinessObjectDefinition().getName(), businessObjectFormatEntity.getUsage(), businessObjectFormatEntity.getFileType().getCode(), businessObjectFormatEntity.getBusinessObjectFormatVersion()));
// If it was specified, retrieve the custom DDL and ensure it exists.
CustomDdlEntity customDdlEntity = null;
if (StringUtils.isNotBlank(request.getCustomDdlName())) {
CustomDdlKey customDdlKey = new CustomDdlKey(businessObjectFormatEntity.getBusinessObjectDefinition().getNamespace().getCode(), businessObjectFormatEntity.getBusinessObjectDefinition().getName(), businessObjectFormatEntity.getUsage(), businessObjectFormatEntity.getFileType().getCode(), businessObjectFormatEntity.getBusinessObjectFormatVersion(), request.getCustomDdlName());
customDdlEntity = customDdlDaoHelper.getCustomDdlEntity(customDdlKey);
}
// Validate that specified storages exist and of a proper storage platform type.
List<String> storageNames = new ArrayList<>();
if (StringUtils.isNotBlank(request.getStorageName())) {
storageNames.add(request.getStorageName());
}
if (!CollectionUtils.isEmpty(request.getStorageNames())) {
storageNames.addAll(request.getStorageNames());
}
List<StorageEntity> storageEntities = new ArrayList<>();
for (String storageName : storageNames) {
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(storageName);
// Only S3 storage platform is currently supported.
Assert.isTrue(storageEntity.getStoragePlatform().getName().equals(StoragePlatformEntity.S3), String.format("Cannot generate DDL for \"%s\" storage platform.", storageEntity.getStoragePlatform().getName()));
storageEntities.add(storageEntity);
}
// Validate that all storages have S3 bucket name configured.
Map<StorageEntity, String> s3BucketNames = new HashMap<>();
for (StorageEntity storageEntity : storageEntities) {
// Please note that since S3 bucket name attribute value is required we pass a "true" flag.
String s3BucketName = storageHelper.getStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), storageEntity, true);
s3BucketNames.put(storageEntity, s3BucketName);
}
// Create and initialize a business object data DDL object instance.
BusinessObjectDataDdl businessObjectDataDdl = createBusinessObjectDataDdl(request);
businessObjectDataDdl.setDdl(ddlGeneratorFactory.getDdlGenerator(request.getOutputFormat()).generateCreateTableDdl(request, businessObjectFormatEntity, customDdlEntity, storageNames, storageEntities, s3BucketNames));
return businessObjectDataDdl;
}
use of org.finra.herd.model.api.xml.CustomDdlKey in project herd by FINRAOS.
the class CustomDdlServiceImpl method createCustomDdlFromEntity.
/**
* Creates the custom DDL from the persisted entity.
*
* @param customDdlEntity the custom DDL entity
*
* @return the custom DDL
*/
private CustomDdl createCustomDdlFromEntity(CustomDdlEntity customDdlEntity) {
// Create the custom DDL.
CustomDdl customDdl = new CustomDdl();
customDdl.setId(customDdlEntity.getId());
customDdl.setCustomDdlKey(new CustomDdlKey(customDdlEntity.getBusinessObjectFormat().getBusinessObjectDefinition().getNamespace().getCode(), customDdlEntity.getBusinessObjectFormat().getBusinessObjectDefinition().getName(), customDdlEntity.getBusinessObjectFormat().getUsage(), customDdlEntity.getBusinessObjectFormat().getFileType().getCode(), customDdlEntity.getBusinessObjectFormat().getBusinessObjectFormatVersion(), customDdlEntity.getCustomDdlName()));
customDdl.setDdl(customDdlEntity.getDdl());
return customDdl;
}
use of org.finra.herd.model.api.xml.CustomDdlKey in project herd by FINRAOS.
the class CustomDdlServiceTest method testUpdateCustomDdlLowerCaseParameters.
@Test
public void testUpdateCustomDdlLowerCaseParameters() {
// Create and persist a custom DDL entity using upper case values.
CustomDdlEntity customDdlEntity = customDdlDaoTestHelper.createCustomDdlEntity(NAMESPACE.toUpperCase(), BDEF_NAME.toUpperCase(), FORMAT_USAGE_CODE.toUpperCase(), FORMAT_FILE_TYPE_CODE.toUpperCase(), FORMAT_VERSION, CUSTOM_DDL_NAME.toUpperCase(), TEST_DDL.toUpperCase());
// Update the custom DDL using lower case input parameters.
CustomDdl updatedCustomDdl = customDdlService.updateCustomDdl(new CustomDdlKey(NAMESPACE.toLowerCase(), BDEF_NAME.toLowerCase(), FORMAT_USAGE_CODE.toLowerCase(), FORMAT_FILE_TYPE_CODE.toLowerCase(), FORMAT_VERSION, CUSTOM_DDL_NAME.toLowerCase()), customDdlServiceTestHelper.createCustomDdlUpdateRequest(TEST_DDL_2.toLowerCase()));
// Validate the returned object.
customDdlServiceTestHelper.validateCustomDdl(customDdlEntity.getId(), NAMESPACE.toUpperCase(), BDEF_NAME.toUpperCase(), FORMAT_USAGE_CODE.toUpperCase(), FORMAT_FILE_TYPE_CODE.toUpperCase(), FORMAT_VERSION, CUSTOM_DDL_NAME.toUpperCase(), TEST_DDL_2.toLowerCase(), updatedCustomDdl);
}
Aggregations