use of org.finra.herd.model.api.xml.BusinessObjectFormat in project herd by FINRAOS.
the class BusinessObjectDataDaoHelper method getPartitionColumnPosition.
/**
* Returns the partition key column position (one-based numbering).
*
* @param partitionKey the partition key
* @param businessObjectFormatEntity, the business object format entity
*
* @return the partition key column position
* @throws IllegalArgumentException if partition key is not found in schema
*/
private int getPartitionColumnPosition(String partitionKey, BusinessObjectFormatEntity businessObjectFormatEntity) {
int partitionColumnPosition = 0;
if (partitionKey.equalsIgnoreCase(businessObjectFormatEntity.getPartitionKey())) {
partitionColumnPosition = BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION;
} else {
// Get business object format model object to directly access schema columns and partitions.
BusinessObjectFormat businessObjectFormat = businessObjectFormatHelper.createBusinessObjectFormatFromEntity(businessObjectFormatEntity);
Assert.notNull(businessObjectFormat.getSchema(), String.format("Partition key \"%s\" doesn't match configured business object format partition key \"%s\" and " + "there is no schema defined to check subpartition columns for business object format {%s}.", partitionKey, businessObjectFormatEntity.getPartitionKey(), businessObjectFormatHelper.businessObjectFormatEntityAltKeyToString(businessObjectFormatEntity)));
for (int i = 0; i < Math.min(BusinessObjectDataEntity.MAX_SUBPARTITIONS + 1, businessObjectFormat.getSchema().getPartitions().size()); i++) {
if (partitionKey.equalsIgnoreCase(businessObjectFormat.getSchema().getPartitions().get(i).getName())) {
// Partition key found in schema.
partitionColumnPosition = i + 1;
break;
}
}
Assert.isTrue(partitionColumnPosition > 0, String.format("The partition key \"%s\" does not exist in first %d partition columns in the schema for business object format {%s}.", partitionKey, BusinessObjectDataEntity.MAX_SUBPARTITIONS + 1, businessObjectFormatHelper.businessObjectFormatEntityAltKeyToString(businessObjectFormatEntity)));
}
return partitionColumnPosition;
}
use of org.finra.herd.model.api.xml.BusinessObjectFormat in project herd by FINRAOS.
the class BusinessObjectFormatHelper method createBusinessObjectFormatFromEntity.
/**
* Creates the business object format from the persisted entity.
*
* @param businessObjectFormatEntity the newly persisted business object format entity.
*
* @param checkLatestVersion need to check latest version
*
* @return the business object format.
*/
public BusinessObjectFormat createBusinessObjectFormatFromEntity(BusinessObjectFormatEntity businessObjectFormatEntity, Boolean checkLatestVersion) {
BusinessObjectFormat businessObjectFormat = new BusinessObjectFormat();
businessObjectFormat.setId(businessObjectFormatEntity.getId());
businessObjectFormat.setNamespace(businessObjectFormatEntity.getBusinessObjectDefinition().getNamespace().getCode());
businessObjectFormat.setBusinessObjectDefinitionName(businessObjectFormatEntity.getBusinessObjectDefinition().getName());
businessObjectFormat.setBusinessObjectFormatUsage(businessObjectFormatEntity.getUsage());
businessObjectFormat.setBusinessObjectFormatFileType(businessObjectFormatEntity.getFileType().getCode());
businessObjectFormat.setBusinessObjectFormatVersion(businessObjectFormatEntity.getBusinessObjectFormatVersion());
businessObjectFormat.setLatestVersion(businessObjectFormatEntity.getLatestVersion());
businessObjectFormat.setPartitionKey(businessObjectFormatEntity.getPartitionKey());
businessObjectFormat.setDescription(businessObjectFormatEntity.getDescription());
// Add in the attributes.
List<Attribute> attributes = new ArrayList<>();
businessObjectFormat.setAttributes(attributes);
for (BusinessObjectFormatAttributeEntity attributeEntity : businessObjectFormatEntity.getAttributes()) {
Attribute attribute = new Attribute();
attributes.add(attribute);
attribute.setName(attributeEntity.getName());
attribute.setValue(attributeEntity.getValue());
}
// Add in the attribute definitions.
List<AttributeDefinition> attributeDefinitions = new ArrayList<>();
businessObjectFormat.setAttributeDefinitions(attributeDefinitions);
for (BusinessObjectDataAttributeDefinitionEntity attributeDefinitionEntity : businessObjectFormatEntity.getAttributeDefinitions()) {
AttributeDefinition attributeDefinition = new AttributeDefinition();
attributeDefinitions.add(attributeDefinition);
attributeDefinition.setName(attributeDefinitionEntity.getName());
attributeDefinition.setPublish(attributeDefinitionEntity.getPublish());
}
// Only add schema information if this format has any schema columns defined.
if (!businessObjectFormatEntity.getSchemaColumns().isEmpty()) {
Schema schema = new Schema();
businessObjectFormat.setSchema(schema);
schema.setNullValue(businessObjectFormatEntity.getNullValue());
schema.setDelimiter(businessObjectFormatEntity.getDelimiter());
schema.setEscapeCharacter(businessObjectFormatEntity.getEscapeCharacter());
schema.setPartitionKeyGroup(businessObjectFormatEntity.getPartitionKeyGroup() != null ? businessObjectFormatEntity.getPartitionKeyGroup().getPartitionKeyGroupName() : null);
// Create two lists of schema column entities: one for the data columns and one for the partition columns.
List<SchemaColumnEntity> dataSchemaColumns = new ArrayList<>();
List<SchemaColumnEntity> partitionSchemaColumns = new ArrayList<>();
for (SchemaColumnEntity schemaColumnEntity : businessObjectFormatEntity.getSchemaColumns()) {
// We can determine which list (or both) a column entity belongs to depending on whether it has a position and/or partition level set.
if (schemaColumnEntity.getPosition() != null) {
dataSchemaColumns.add(schemaColumnEntity);
}
if (schemaColumnEntity.getPartitionLevel() != null) {
partitionSchemaColumns.add(schemaColumnEntity);
}
}
// Sort the data schema columns on the position.
Collections.sort(dataSchemaColumns, new SchemaColumnPositionComparator());
// Sort the partition schema columns on the partition level.
Collections.sort(partitionSchemaColumns, new SchemaColumnPartitionLevelComparator());
// Add in the data schema columns.
List<SchemaColumn> schemaColumns = new ArrayList<>();
schema.setColumns(schemaColumns);
for (SchemaColumnEntity schemaColumnEntity : dataSchemaColumns) {
schemaColumns.add(createSchemaColumn(schemaColumnEntity));
}
// columns which isn't valid from an XSD standpoint.
if (partitionSchemaColumns.size() > 0) {
schemaColumns = new ArrayList<>();
schema.setPartitions(schemaColumns);
for (SchemaColumnEntity schemaColumnEntity : partitionSchemaColumns) {
schemaColumns.add(createSchemaColumn(schemaColumnEntity));
}
}
}
BusinessObjectFormatEntity latestVersionBusinessObjectFormatEntity = businessObjectFormatEntity;
// use the latest version if it is not
if (checkLatestVersion) {
BusinessObjectFormatKey businessObjectFormatKey = getBusinessObjectFormatKey(businessObjectFormatEntity);
businessObjectFormatKey.setBusinessObjectFormatVersion(null);
latestVersionBusinessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey);
}
// add business object format parent
List<BusinessObjectFormatKey> businessObjectFormatParents = new ArrayList();
businessObjectFormat.setBusinessObjectFormatParents(businessObjectFormatParents);
for (BusinessObjectFormatEntity businessObjectFormatEntityParent : latestVersionBusinessObjectFormatEntity.getBusinessObjectFormatParents()) {
BusinessObjectFormatKey businessObjectFormatParent = getBusinessObjectFormatKey(businessObjectFormatEntityParent);
businessObjectFormatParent.setBusinessObjectFormatVersion(null);
businessObjectFormatParents.add(businessObjectFormatParent);
}
// add business object format children
List<BusinessObjectFormatKey> businessObjectFormatChildren = new ArrayList();
businessObjectFormat.setBusinessObjectFormatChildren(businessObjectFormatChildren);
for (BusinessObjectFormatEntity businessObjectFormatEntityChild : latestVersionBusinessObjectFormatEntity.getBusinessObjectFormatChildren()) {
BusinessObjectFormatKey businessObjectFormatChild = getBusinessObjectFormatKey(businessObjectFormatEntityChild);
businessObjectFormatChild.setBusinessObjectFormatVersion(null);
businessObjectFormatChildren.add(businessObjectFormatChild);
}
// add retention information
businessObjectFormat.setRecordFlag(latestVersionBusinessObjectFormatEntity.isRecordFlag());
businessObjectFormat.setRetentionPeriodInDays(latestVersionBusinessObjectFormatEntity.getRetentionPeriodInDays());
if (latestVersionBusinessObjectFormatEntity.getRetentionType() != null) {
businessObjectFormat.setRetentionType(latestVersionBusinessObjectFormatEntity.getRetentionType().getCode());
}
return businessObjectFormat;
}
use of org.finra.herd.model.api.xml.BusinessObjectFormat in project herd by FINRAOS.
the class Hive13DdlGenerator method generateReplaceColumnsStatement.
@Override
public String generateReplaceColumnsStatement(BusinessObjectFormatDdlRequest request, BusinessObjectFormatEntity businessObjectFormatEntity) {
BusinessObjectFormat businessObjectFormat = businessObjectFormatHelper.createBusinessObjectFormatFromEntity(businessObjectFormatEntity);
assertSchemaColumnsNotEmpty(businessObjectFormat, businessObjectFormatEntity);
StringBuilder builder = new StringBuilder(34);
builder.append("ALTER TABLE `");
builder.append(request.getTableName());
builder.append("` REPLACE COLUMNS (\n");
builder.append(generateDdlColumns(businessObjectFormatEntity, businessObjectFormat));
return builder.toString().trim() + ';';
}
use of org.finra.herd.model.api.xml.BusinessObjectFormat in project herd by FINRAOS.
the class NotificationEventServiceImpl method processBusinessObjectDataNotifications.
private List<Object> processBusinessObjectDataNotifications(String notificationEventType, List<BusinessObjectDataNotificationRegistrationEntity> businessObjectDataNotificationRegistrationEntities, BusinessObjectData businessObjectData, String newBusinessObjectDataStatus, String oldBusinessObjectDataStatus) {
List<Object> notificationActions = new ArrayList<>();
// Build a list of partition value that includes primary and sub-partition values, if any are specified in the business object data key.
List<String> partitionValues = businessObjectDataHelper.getPrimaryAndSubPartitionValues(businessObjectData);
// Get a list of partition columns from the associated business object format.
List<String> partitionColumnNames = null;
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(new BusinessObjectFormatKey(businessObjectData.getNamespace(), businessObjectData.getBusinessObjectDefinitionName(), businessObjectData.getBusinessObjectFormatUsage(), businessObjectData.getBusinessObjectFormatFileType(), businessObjectData.getBusinessObjectFormatVersion()));
if (businessObjectFormatEntity != null) {
// Get business object format model object to directly access schema columns and partitions.
BusinessObjectFormat businessObjectFormat = businessObjectFormatHelper.createBusinessObjectFormatFromEntity(businessObjectFormatEntity);
// Proceed only if this format has schema with partition columns specified.
if (businessObjectFormat.getSchema() != null && !CollectionUtils.isEmpty(businessObjectFormat.getSchema().getPartitions())) {
// Do not provide more partition column names than there are primary and
// sub-partition values that this business object data is registered with.
partitionColumnNames = new ArrayList<>();
List<SchemaColumn> partitionColumns = businessObjectFormat.getSchema().getPartitions();
for (int i = 0; i < Math.min(partitionValues.size(), partitionColumns.size()); i++) {
partitionColumnNames.add(partitionColumns.get(i).getName());
}
}
}
for (BusinessObjectDataNotificationRegistrationEntity businessObjectDataNotificationRegistration : businessObjectDataNotificationRegistrationEntities) {
// Retrieve the job notification actions needed to be triggered.
for (NotificationActionEntity notificationActionEntity : businessObjectDataNotificationRegistration.getNotificationActions()) {
// Trigger the job action.
if (notificationActionEntity instanceof NotificationJobActionEntity) {
NotificationJobActionEntity notificationJobActionEntity = (NotificationJobActionEntity) notificationActionEntity;
BusinessObjectDataNotificationEventParamsDto notificationEventParams = new BusinessObjectDataNotificationEventParamsDto();
notificationEventParams.setBusinessObjectDataNotificationRegistration(businessObjectDataNotificationRegistration);
notificationEventParams.setNotificationJobAction(notificationJobActionEntity);
notificationEventParams.setEventType(notificationEventType);
notificationEventParams.setBusinessObjectData(businessObjectData);
notificationEventParams.setPartitionColumnNames(partitionColumnNames);
notificationEventParams.setStorageName(businessObjectDataNotificationRegistration.getStorage() == null ? null : businessObjectDataNotificationRegistration.getStorage().getName());
notificationEventParams.setPartitionValues(partitionValues);
notificationEventParams.setNewBusinessObjectDataStatus(newBusinessObjectDataStatus);
notificationEventParams.setOldBusinessObjectDataStatus(oldBusinessObjectDataStatus);
notificationActions.add(triggerNotificationAction(NotificationTypeEntity.NOTIFICATION_TYPE_BDATA, notificationEventType, notificationEventParams));
}
}
}
return notificationActions;
}
use of org.finra.herd.model.api.xml.BusinessObjectFormat in project herd by FINRAOS.
the class BusinessObjectFormatServiceImpl method createBusinessObjectFormat.
@PublishNotificationMessages
@NamespacePermission(fields = "#request.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public BusinessObjectFormat createBusinessObjectFormat(BusinessObjectFormatCreateRequest request) {
// Perform the validation of the request parameters, except for the alternate key.
validateBusinessObjectFormatCreateRequest(request);
// Get business object format key from the request.
BusinessObjectFormatKey businessObjectFormatKey = getBusinessObjectFormatKey(request);
// Get the business object definition and ensure it exists.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(new BusinessObjectDefinitionKey(businessObjectFormatKey.getNamespace(), businessObjectFormatKey.getBusinessObjectDefinitionName()));
// Get business object format file type and ensure it exists.
FileTypeEntity fileTypeEntity = fileTypeDaoHelper.getFileTypeEntity(request.getBusinessObjectFormatFileType());
// Get the latest format version for this business format, if it exists.
BusinessObjectFormatEntity latestVersionBusinessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey);
// If the latest version exists, perform the additive schema validation and update the latest entity.
if (latestVersionBusinessObjectFormatEntity != null) {
// Get the latest version business object format model object.
BusinessObjectFormat latestVersionBusinessObjectFormat = businessObjectFormatHelper.createBusinessObjectFormatFromEntity(latestVersionBusinessObjectFormatEntity);
// If the latest version format has schema, check the new format version schema is "additive" to the previous format version.
if (latestVersionBusinessObjectFormat.getSchema() != null) {
validateNewSchemaIsAdditiveToOldSchema(request.getSchema(), latestVersionBusinessObjectFormat.getSchema());
}
// Update the latest entity.
latestVersionBusinessObjectFormatEntity.setLatestVersion(false);
businessObjectFormatDao.saveAndRefresh(latestVersionBusinessObjectFormatEntity);
}
// Create a business object format entity from the request information.
Integer businessObjectFormatVersion = latestVersionBusinessObjectFormatEntity == null ? 0 : latestVersionBusinessObjectFormatEntity.getBusinessObjectFormatVersion() + 1;
BusinessObjectFormatEntity newBusinessObjectFormatEntity = createBusinessObjectFormatEntity(request, businessObjectDefinitionEntity, fileTypeEntity, businessObjectFormatVersion, null);
// latest version format is the descriptive format for the bdef, update the bdef descriptive format to the newly created one
if (latestVersionBusinessObjectFormatEntity != null && latestVersionBusinessObjectFormatEntity.equals(businessObjectDefinitionEntity.getDescriptiveBusinessObjectFormat())) {
businessObjectDefinitionEntity.setDescriptiveBusinessObjectFormat(newBusinessObjectFormatEntity);
businessObjectDefinitionDao.saveAndRefresh(businessObjectDefinitionEntity);
}
// latest version business object exists, carry the retention information to the new entity
if (latestVersionBusinessObjectFormatEntity != null) {
// for each of the previous version's child, remove the parent link to the previous version and set the parent to the new version
for (BusinessObjectFormatEntity childFormatEntity : latestVersionBusinessObjectFormatEntity.getBusinessObjectFormatChildren()) {
childFormatEntity.getBusinessObjectFormatParents().remove(latestVersionBusinessObjectFormatEntity);
childFormatEntity.getBusinessObjectFormatParents().add(newBusinessObjectFormatEntity);
newBusinessObjectFormatEntity.getBusinessObjectFormatChildren().add(childFormatEntity);
businessObjectFormatDao.saveAndRefresh(childFormatEntity);
}
// for each of the previous version's parent, remove the child link to the previous version and set the child link to the new version
for (BusinessObjectFormatEntity parentFormatEntity : latestVersionBusinessObjectFormatEntity.getBusinessObjectFormatParents()) {
parentFormatEntity.getBusinessObjectFormatChildren().remove(latestVersionBusinessObjectFormatEntity);
parentFormatEntity.getBusinessObjectFormatChildren().add(newBusinessObjectFormatEntity);
newBusinessObjectFormatEntity.getBusinessObjectFormatParents().add(parentFormatEntity);
businessObjectFormatDao.saveAndRefresh(parentFormatEntity);
}
// mark the latest version business object format
latestVersionBusinessObjectFormatEntity.setBusinessObjectFormatParents(null);
latestVersionBusinessObjectFormatEntity.setBusinessObjectFormatChildren(null);
// carry the retention information from the latest entity to the new entity
newBusinessObjectFormatEntity.setRetentionPeriodInDays(latestVersionBusinessObjectFormatEntity.getRetentionPeriodInDays());
newBusinessObjectFormatEntity.setRecordFlag(latestVersionBusinessObjectFormatEntity.isRecordFlag());
newBusinessObjectFormatEntity.setRetentionType(latestVersionBusinessObjectFormatEntity.getRetentionType());
businessObjectFormatDao.saveAndRefresh(newBusinessObjectFormatEntity);
// reset the retention information of the latest version business object format
latestVersionBusinessObjectFormatEntity.setRetentionType(null);
latestVersionBusinessObjectFormatEntity.setRecordFlag(null);
latestVersionBusinessObjectFormatEntity.setRetentionPeriodInDays(null);
businessObjectFormatDao.saveAndRefresh(latestVersionBusinessObjectFormatEntity);
}
// Notify the search index that a business object definition must be updated.
searchIndexUpdateHelper.modifyBusinessObjectDefinitionInSearchIndex(businessObjectDefinitionEntity, SEARCH_INDEX_UPDATE_TYPE_UPDATE);
// Create a version change notification to be sent on create business object format event.
messageNotificationEventService.processBusinessObjectFormatVersionChangeNotificationEvent(businessObjectFormatHelper.getBusinessObjectFormatKey(newBusinessObjectFormatEntity), latestVersionBusinessObjectFormatEntity != null ? latestVersionBusinessObjectFormatEntity.getBusinessObjectFormatVersion().toString() : "");
// Create and return the business object format object from the persisted entity.
return businessObjectFormatHelper.createBusinessObjectFormatFromEntity(newBusinessObjectFormatEntity);
}
Aggregations