use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class CustomDdlServiceImpl method createCustomDdl.
/**
* Creates a new custom DDL.
*
* @param request the information needed to create a custom DDL
*
* @return the newly created custom DDL information
*/
@NamespacePermission(fields = "#request.customDdlKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public CustomDdl createCustomDdl(CustomDdlCreateRequest request) {
// Validate and trim the key.
customDdlHelper.validateCustomDdlKey(request.getCustomDdlKey());
// Validate and trim the DDL.
Assert.hasText(request.getDdl(), "DDL must be specified.");
request.setDdl(request.getDdl().trim());
// Get the business object format and ensure it exists.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(new BusinessObjectFormatKey(request.getCustomDdlKey().getNamespace(), request.getCustomDdlKey().getBusinessObjectDefinitionName(), request.getCustomDdlKey().getBusinessObjectFormatUsage(), request.getCustomDdlKey().getBusinessObjectFormatFileType(), request.getCustomDdlKey().getBusinessObjectFormatVersion()));
// Ensure a custom DDL with the specified name doesn't already exist for the specified business object format.
CustomDdlEntity customDdlEntity = customDdlDao.getCustomDdlByKey(request.getCustomDdlKey());
if (customDdlEntity != null) {
throw new AlreadyExistsException(String.format("Unable to create custom DDL with name \"%s\" because it already exists for the business object format {%s}.", request.getCustomDdlKey().getCustomDdlName(), businessObjectFormatHelper.businessObjectFormatEntityAltKeyToString(businessObjectFormatEntity)));
}
// Create a custom DDL entity from the request information.
customDdlEntity = createCustomDdlEntity(businessObjectFormatEntity, request);
// Persist the new entity.
customDdlEntity = customDdlDao.saveAndRefresh(customDdlEntity);
// Create and return the custom DDL object from the persisted entity.
return createCustomDdlFromEntity(customDdlEntity);
}
use of org.finra.herd.model.jpa.BusinessObjectFormatEntity 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.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class RelationalTableRegistrationHelperServiceImpl method getRelationalStorageAttributesImpl.
/**
* Gets storage attributes required to perform relation table registration. This method also validates database entities per specified relational table
* registration create request.
*
* @param relationalTableRegistrationCreateRequest the relational table registration create request
* @param appendToExistingBusinessObjectDefinition boolean flag that determines if the format should be appended to an existing business object definition
*
* @return the relational storage attributes DtO
*/
RelationalStorageAttributesDto getRelationalStorageAttributesImpl(RelationalTableRegistrationCreateRequest relationalTableRegistrationCreateRequest, Boolean appendToExistingBusinessObjectDefinition) {
// Validate that specified namespace exists.
namespaceDaoHelper.getNamespaceEntity(relationalTableRegistrationCreateRequest.getNamespace());
// Create a business object definition key.
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(relationalTableRegistrationCreateRequest.getNamespace(), relationalTableRegistrationCreateRequest.getBusinessObjectDefinitionName());
// Ensure that a business object definition with the specified key doesn't already exist.
if (BooleanUtils.isNotTrue(appendToExistingBusinessObjectDefinition) && businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(businessObjectDefinitionKey) != null) {
throw new AlreadyExistsException(String.format("Business object definition with name \"%s\" already exists for namespace \"%s\".", businessObjectDefinitionKey.getBusinessObjectDefinitionName(), businessObjectDefinitionKey.getNamespace()));
}
// Get the latest format version for this business format, if it exists.
BusinessObjectFormatEntity latestVersionBusinessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(new BusinessObjectFormatKey(relationalTableRegistrationCreateRequest.getNamespace(), relationalTableRegistrationCreateRequest.getBusinessObjectDefinitionName(), relationalTableRegistrationCreateRequest.getBusinessObjectFormatUsage(), FileTypeEntity.RELATIONAL_TABLE_FILE_TYPE, null));
// If the latest version exists, fail with an already exists exception.
if (latestVersionBusinessObjectFormatEntity != null) {
throw new AlreadyExistsException(String.format("Format with file type \"%s\" and usage \"%s\" already exists for business object definition \"%s\".", latestVersionBusinessObjectFormatEntity.getFileType().getCode(), latestVersionBusinessObjectFormatEntity.getUsage(), latestVersionBusinessObjectFormatEntity.getBusinessObjectDefinition().getName()));
}
// Validate that specified data provider exists.
dataProviderDaoHelper.getDataProviderEntity(relationalTableRegistrationCreateRequest.getDataProviderName());
// Get the storage.
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(relationalTableRegistrationCreateRequest.getStorageName());
// Only RELATIONAL storage platform is supported for the relational table registration feature.
Assert.isTrue(storageEntity.getStoragePlatform().getName().equals(StoragePlatformEntity.RELATIONAL), String.format("Cannot register relational table in \"%s\" storage of %s storage platform type. Only %s storage platform type is supported by this feature.", storageEntity.getName(), storageEntity.getStoragePlatform().getName(), StoragePlatformEntity.RELATIONAL));
// Get JDBC URL for this storage. This storage attribute is required and must have a non-blank value.
String jdbcUrl = storageHelper.getStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.STORAGE_ATTRIBUTE_NAME_JDBC_URL), storageEntity, true, true);
// Get JDBC username for this storage. This storage attribute is not required and it is allowed to have a blank value.
String jdbcUsername = storageHelper.getStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.STORAGE_ATTRIBUTE_NAME_JDBC_USERNAME), storageEntity, false, false);
// Get JDBC user credential name for this storage. This storage attribute is not required and it is allowed to have a blank value.
String jdbcUserCredentialName = storageHelper.getStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.STORAGE_ATTRIBUTE_NAME_JDBC_USER_CREDENTIAL_NAME), storageEntity, false, false);
// Create and initialize a relational storage attributes DTO.
RelationalStorageAttributesDto relationalStorageAttributesDto = new RelationalStorageAttributesDto();
relationalStorageAttributesDto.setJdbcUrl(jdbcUrl);
relationalStorageAttributesDto.setJdbcUsername(jdbcUsername);
relationalStorageAttributesDto.setJdbcUserCredentialName(jdbcUserCredentialName);
return relationalStorageAttributesDto;
}
use of org.finra.herd.model.jpa.BusinessObjectFormatEntity 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);
}
use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class BusinessObjectFormatServiceImpl method updateBusinessObjectFormatParents.
@NamespacePermissions({ @NamespacePermission(fields = "#businessObjectFormatKey.namespace", permissions = NamespacePermissionEnum.WRITE), @NamespacePermission(fields = "#businessObjectFormatParentsUpdateRequest?.businessObjectFormatParents?.![namespace]", permissions = NamespacePermissionEnum.READ) })
@Override
public BusinessObjectFormat updateBusinessObjectFormatParents(BusinessObjectFormatKey businessObjectFormatKey, BusinessObjectFormatParentsUpdateRequest businessObjectFormatParentsUpdateRequest) {
Assert.notNull(businessObjectFormatParentsUpdateRequest, "A Business Object Format Parents Update Request is required.");
// Perform validation and trim the alternate key parameters.
businessObjectFormatHelper.validateBusinessObjectFormatKey(businessObjectFormatKey, false);
Assert.isNull(businessObjectFormatKey.getBusinessObjectFormatVersion(), "Business object format version must not be specified.");
// Perform validation and trim for the business object format parents
validateBusinessObjectFormatParents(businessObjectFormatParentsUpdateRequest.getBusinessObjectFormatParents());
// Retrieve and ensure that a business object format exists.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatKey);
// Retrieve and ensure that business object format parents exist. A set is used to ignore duplicate business object format parents.
Set<BusinessObjectFormatEntity> businessObjectFormatParents = new HashSet<>();
for (BusinessObjectFormatKey businessObjectFormatParent : businessObjectFormatParentsUpdateRequest.getBusinessObjectFormatParents()) {
// Retrieve and ensure that a business object format exists.
BusinessObjectFormatEntity businessObjectFormatEntityParent = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatParent);
businessObjectFormatParents.add(businessObjectFormatEntityParent);
}
// Set the business object format parents.
businessObjectFormatEntity.setBusinessObjectFormatParents(new ArrayList<>(businessObjectFormatParents));
// Persist and refresh the entity.
businessObjectFormatEntity = businessObjectFormatDao.saveAndRefresh(businessObjectFormatEntity);
// Notify the search index that a business object definition must be updated.
searchIndexUpdateHelper.modifyBusinessObjectDefinitionInSearchIndex(businessObjectFormatEntity.getBusinessObjectDefinition(), SEARCH_INDEX_UPDATE_TYPE_UPDATE);
// Create and return the business object format object from the persisted entity.
return businessObjectFormatHelper.createBusinessObjectFormatFromEntity(businessObjectFormatEntity);
}
Aggregations