use of org.finra.herd.model.api.xml.BusinessObjectFormat in project herd by FINRAOS.
the class RelationalTableRegistrationHelperServiceImpl method registerRelationalTableImpl.
/**
* Creates a new relational table registration. The relation table registration includes creation of the following entities: <ul> <li>a business object
* definition</li> <li>a business object format with the specified schema columns</li> <li>a business object data</li> <li>a storage unit that links
* together the business object data with the storage specified in the create request</li> </ul>
*
* @param relationalTableRegistrationCreateRequest the relational table registration create request
* @param schemaColumns the list of schema columns
* @param appendToExistingBusinessObjectDefinition boolean flag that determines if the format should be appended to an existing business object definition
*
* @return the information for the newly created business object data
*/
BusinessObjectData registerRelationalTableImpl(RelationalTableRegistrationCreateRequest relationalTableRegistrationCreateRequest, List<SchemaColumn> schemaColumns, Boolean appendToExistingBusinessObjectDefinition) {
BusinessObjectDefinitionEntity businessObjectDefinitionEntity;
// else create a new business object definition with the information in the relational table registration create request.
if (BooleanUtils.isTrue(appendToExistingBusinessObjectDefinition)) {
// Get the existing business object definition
businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(new BusinessObjectDefinitionKey(relationalTableRegistrationCreateRequest.getNamespace(), relationalTableRegistrationCreateRequest.getBusinessObjectDefinitionName()));
} else {
// Create a business object definition.
businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.createBusinessObjectDefinitionEntity(new BusinessObjectDefinitionCreateRequest(relationalTableRegistrationCreateRequest.getNamespace(), relationalTableRegistrationCreateRequest.getBusinessObjectDefinitionName(), relationalTableRegistrationCreateRequest.getDataProviderName(), null, relationalTableRegistrationCreateRequest.getBusinessObjectDefinitionDisplayName(), null));
}
// Notify the search index that a business object definition is created.
searchIndexUpdateHelper.modifyBusinessObjectDefinitionInSearchIndex(businessObjectDefinitionEntity, SEARCH_INDEX_UPDATE_TYPE_CREATE);
// Create a business object format. Store the relational table name as a business object format attribute per attribute name configured in the system.
BusinessObjectFormatCreateRequest businessObjectFormatCreateRequest = new BusinessObjectFormatCreateRequest();
businessObjectFormatCreateRequest.setNamespace(relationalTableRegistrationCreateRequest.getNamespace());
businessObjectFormatCreateRequest.setBusinessObjectDefinitionName(relationalTableRegistrationCreateRequest.getBusinessObjectDefinitionName());
businessObjectFormatCreateRequest.setBusinessObjectFormatUsage(relationalTableRegistrationCreateRequest.getBusinessObjectFormatUsage());
businessObjectFormatCreateRequest.setBusinessObjectFormatFileType(FileTypeEntity.RELATIONAL_TABLE_FILE_TYPE);
businessObjectFormatCreateRequest.setPartitionKey(BusinessObjectDataServiceImpl.NO_PARTITIONING_PARTITION_KEY);
businessObjectFormatCreateRequest.setAttributes(Arrays.asList(new Attribute(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_FORMAT_ATTRIBUTE_NAME_RELATIONAL_SCHEMA_NAME), relationalTableRegistrationCreateRequest.getRelationalSchemaName()), new Attribute(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_FORMAT_ATTRIBUTE_NAME_RELATIONAL_TABLE_NAME), relationalTableRegistrationCreateRequest.getRelationalTableName())));
businessObjectFormatCreateRequest.setSchema(new Schema(schemaColumns, null, "", null, null, null));
BusinessObjectFormat businessObjectFormat = businessObjectFormatService.createBusinessObjectFormat(businessObjectFormatCreateRequest);
// Retrieve the newly created business object format entity.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatHelper.getBusinessObjectFormatKey(businessObjectFormat));
// Get a business object data status entity for the VALID status.
BusinessObjectDataStatusEntity businessObjectDataStatusEntity = businessObjectDataStatusDaoHelper.getBusinessObjectDataStatusEntity(BusinessObjectDataStatusEntity.VALID);
// Create a business object data entity.
BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity);
businessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
businessObjectDataEntity.setVersion(0);
businessObjectDataEntity.setLatestVersion(true);
businessObjectDataEntity.setPartitionValue(BusinessObjectDataServiceImpl.NO_PARTITIONING_PARTITION_VALUE);
// Get a storage unit status entity for the ENABLED status.
StorageUnitStatusEntity storageUnitStatusEntity = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(StorageUnitStatusEntity.ENABLED);
// Get the storage.
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(relationalTableRegistrationCreateRequest.getStorageName());
// Create a storage unit entity.
StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
storageUnitEntity.setStorage(storageEntity);
storageUnitEntity.setBusinessObjectData(businessObjectDataEntity);
storageUnitDaoHelper.setStorageUnitStatus(storageUnitEntity, storageUnitStatusEntity);
businessObjectDataEntity.setStorageUnits(Collections.singletonList(storageUnitEntity));
// Persist the newly created business object data entity.
businessObjectDataEntity = businessObjectDataDao.saveAndRefresh(businessObjectDataEntity);
// Create a status change notification to be sent on create business object data event.
messageNotificationEventService.processBusinessObjectDataStatusChangeNotificationEvent(businessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataEntity), businessObjectDataStatusEntity.getCode(), null);
// Create and return business object data information from the newly created business object data entity.
return businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity);
}
use of org.finra.herd.model.api.xml.BusinessObjectFormat in project herd by FINRAOS.
the class Hive13DdlGenerator method generateCreateTableDdlHelper.
/**
* Generates and append to the string builder the create table Hive 13 DDL as per specified parameters.
*/
private String generateCreateTableDdlHelper(GenerateDdlRequest generateDdlRequest) {
// TODO: We might want to consider using a template engine such as Velocity to generate this DDL so we don't wind up just doing string manipulation.
StringBuilder sb = new StringBuilder();
// For custom DDL, we would need to substitute the custom DDL tokens with their relative values.
HashMap<String, String> replacements = new HashMap<>();
// Validate that partition values passed in the list of partition filters do not contain '/' character.
if (generateDdlRequest.isPartitioned && !CollectionUtils.isEmpty(generateDdlRequest.partitionFilters)) {
// Validate that partition values do not contain '/' characters.
for (List<String> partitionFilter : generateDdlRequest.partitionFilters) {
for (String partitionValue : partitionFilter) {
Assert.doesNotContain(partitionValue, "/", String.format("Partition value \"%s\" can not contain a '/' character.", partitionValue));
}
}
}
// Get business object format model object to directly access schema columns and partitions.
BusinessObjectFormat businessObjectFormat = businessObjectFormatHelper.createBusinessObjectFormatFromEntity(generateDdlRequest.businessObjectFormatEntity);
// Validate that we have at least one column specified in the business object format schema.
assertSchemaColumnsNotEmpty(businessObjectFormat, generateDdlRequest.businessObjectFormatEntity);
if (generateDdlRequest.isPartitioned) {
// Validate that we have at least one partition column specified in the business object format schema.
Assert.notEmpty(businessObjectFormat.getSchema().getPartitions(), String.format("No schema partitions specified for business object format {%s}.", businessObjectFormatHelper.businessObjectFormatEntityAltKeyToString(generateDdlRequest.businessObjectFormatEntity)));
// Validate that partition column names do not contain '/' characters.
for (SchemaColumn partitionColumn : businessObjectFormat.getSchema().getPartitions()) {
Assert.doesNotContain(partitionColumn.getName(), "/", String.format("Partition column name \"%s\" can not contain a '/' character. Business object format: {%s}", partitionColumn.getName(), businessObjectFormatHelper.businessObjectFormatEntityAltKeyToString(generateDdlRequest.businessObjectFormatEntity)));
}
}
// Add drop table if requested.
if (BooleanUtils.isTrue(generateDdlRequest.includeDropTableStatement)) {
sb.append(String.format("DROP TABLE IF EXISTS `%s`;\n\n", generateDdlRequest.tableName));
}
// Depending on the flag, prepare "if not exists" option text or leave it an empty string.
String ifNotExistsOption = BooleanUtils.isTrue(generateDdlRequest.includeIfNotExistsOption) ? "IF NOT EXISTS " : "";
// Only generate the create table DDL statement, if custom DDL was not specified.
if (generateDdlRequest.customDdlEntity == null) {
generateStandardBaseDdl(generateDdlRequest, sb, businessObjectFormat, ifNotExistsOption);
} else {
// Use the custom DDL in place of the create table statement.
sb.append(String.format("%s\n\n", generateDdlRequest.customDdlEntity.getDdl()));
// We need to substitute the relative custom DDL token with an actual table name.
replacements.put(TABLE_NAME_CUSTOM_DDL_TOKEN, generateDdlRequest.tableName);
}
// Add alter table statements only if the list of partition filters is not empty - this is applicable to generating DDL for business object data only.
if (!CollectionUtils.isEmpty(generateDdlRequest.partitionFilters)) {
processPartitionFiltersForGenerateDdl(generateDdlRequest, sb, replacements, generateDdlRequest.businessObjectFormatEntity, businessObjectFormat, ifNotExistsOption);
} else // Add a location statement with a token if this is format dll that does not use custom ddl.
if (!generateDdlRequest.isPartitioned && generateDdlRequest.customDdlEntity == null) {
// Since custom DDL is not specified, there are no partition values, and this table is not partitioned, add a LOCATION clause with a token.
sb.append(String.format("LOCATION '%s';", NON_PARTITIONED_TABLE_LOCATION_CUSTOM_DDL_TOKEN));
}
// Trim to remove unnecessary end-of-line characters, if any, from the end of the generated DDL.
String resultDdl = sb.toString().trim();
// For custom DDL, substitute the relative custom DDL tokens with their values.
if (generateDdlRequest.customDdlEntity != null) {
for (Map.Entry<String, String> entry : replacements.entrySet()) {
String token = entry.getKey();
String value = entry.getValue();
resultDdl = resultDdl.replaceAll(Pattern.quote(token), value);
}
}
return resultDdl;
}
use of org.finra.herd.model.api.xml.BusinessObjectFormat in project herd by FINRAOS.
the class GetBusinessObjectFormat 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);
BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey();
businessObjectFormatKey.setNamespace(namespace);
businessObjectFormatKey.setBusinessObjectDefinitionName(businessObjectDefinitionName);
businessObjectFormatKey.setBusinessObjectFormatUsage(businessObjectFormatUsage);
businessObjectFormatKey.setBusinessObjectFormatFileType(businessObjectFormatFileType);
businessObjectFormatKey.setBusinessObjectFormatVersion(businessObjectFormatVersion);
BusinessObjectFormat businessObjectFormat = businessObjectFormatService.getBusinessObjectFormat(businessObjectFormatKey);
setJsonResponseAsWorkflowVariable(businessObjectFormat, execution);
}
use of org.finra.herd.model.api.xml.BusinessObjectFormat in project herd by FINRAOS.
the class BusinessObjectFormatServiceTest method testGetBusinessObjectFormatUpperCaseParameters.
@Test
public void testGetBusinessObjectFormatUpperCaseParameters() {
// Create and persist a valid business object format.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE.toLowerCase(), BDEF_NAME.toLowerCase(), FORMAT_USAGE_CODE.toLowerCase(), FORMAT_FILE_TYPE_CODE.toLowerCase(), INITIAL_FORMAT_VERSION, FORMAT_DESCRIPTION.toLowerCase(), LATEST_VERSION_FLAG_SET, PARTITION_KEY.toLowerCase());
// Call GET Business Object Format.
BusinessObjectFormat resultBusinessObjectFormat = businessObjectFormatService.getBusinessObjectFormat(new BusinessObjectFormatKey(NAMESPACE.toUpperCase(), BDEF_NAME.toUpperCase(), FORMAT_USAGE_CODE.toUpperCase(), FORMAT_FILE_TYPE_CODE.toUpperCase(), INITIAL_FORMAT_VERSION));
// Validate the returned object.
businessObjectFormatServiceTestHelper.validateBusinessObjectFormat(businessObjectFormatEntity.getId(), NAMESPACE.toLowerCase(), BDEF_NAME.toLowerCase(), FORMAT_USAGE_CODE.toLowerCase(), FORMAT_FILE_TYPE_CODE.toLowerCase(), INITIAL_FORMAT_VERSION, LATEST_VERSION_FLAG_SET, PARTITION_KEY.toLowerCase(), FORMAT_DESCRIPTION.toLowerCase(), NO_ATTRIBUTES, NO_ATTRIBUTE_DEFINITIONS, NO_SCHEMA, resultBusinessObjectFormat);
}
use of org.finra.herd.model.api.xml.BusinessObjectFormat in project herd by FINRAOS.
the class BusinessObjectFormatServiceTest method testDeleteBusinessObjectFormatInvalidParameters.
@Test
public void testDeleteBusinessObjectFormatInvalidParameters() {
// Create and persist a valid business object format.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, FORMAT_DESCRIPTION, true, PARTITION_KEY);
// Validate that we can perform a get on our business object format.
BusinessObjectFormat resultBusinessObjectFormat = businessObjectFormatService.getBusinessObjectFormat(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION));
// Validate the returned object.
businessObjectFormatServiceTestHelper.validateBusinessObjectFormat(businessObjectFormatEntity.getId(), NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, LATEST_VERSION_FLAG_SET, PARTITION_KEY, FORMAT_DESCRIPTION, NO_ATTRIBUTES, NO_ATTRIBUTE_DEFINITIONS, NO_SCHEMA, resultBusinessObjectFormat);
// Try to perform a delete using invalid namespace code.
try {
businessObjectFormatService.deleteBusinessObjectFormat(new BusinessObjectFormatKey("I_DO_NOT_EXIST", BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION));
fail("Should throw an ObjectNotFoundException when not able to find business object format.");
} catch (ObjectNotFoundException e) {
assertEquals(businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatNotFoundErrorMessage("I_DO_NOT_EXIST", BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION), e.getMessage());
}
// Try to perform a delete using invalid business object definition name.
try {
businessObjectFormatService.deleteBusinessObjectFormat(new BusinessObjectFormatKey(NAMESPACE, "I_DO_NOT_EXIST", FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION));
fail("Should throw an ObjectNotFoundException when not able to find business object format.");
} catch (ObjectNotFoundException e) {
assertEquals(businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatNotFoundErrorMessage(NAMESPACE, "I_DO_NOT_EXIST", FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION), e.getMessage());
}
// Try to perform a delete using invalid format usage.
try {
businessObjectFormatService.deleteBusinessObjectFormat(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, "I_DO_NOT_EXIST", FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION));
fail("Should throw an ObjectNotFoundException when not able to find business object format.");
} catch (ObjectNotFoundException e) {
assertEquals(businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatNotFoundErrorMessage(NAMESPACE, BDEF_NAME, "I_DO_NOT_EXIST", FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION), e.getMessage());
}
// Try to perform a delete using invalid format file type.
try {
businessObjectFormatService.deleteBusinessObjectFormat(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, "I_DO_NOT_EXIST", INITIAL_FORMAT_VERSION));
fail("Should throw an ObjectNotFoundException when not able to find business object format.");
} catch (ObjectNotFoundException e) {
assertEquals(businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatNotFoundErrorMessage(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, "I_DO_NOT_EXIST", INITIAL_FORMAT_VERSION), e.getMessage());
}
// Try to perform a delete using invalid format version.
try {
businessObjectFormatService.deleteBusinessObjectFormat(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, 999));
fail("Should throw an ObjectNotFoundException when not able to find business object format.");
} catch (ObjectNotFoundException e) {
assertEquals(businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatNotFoundErrorMessage(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, 999), e.getMessage());
}
}
Aggregations