Search in sources :

Example 6 with BusinessObjectFormatKey

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

the class BusinessObjectDefinitionServiceImpl method updateBusinessObjectDefinitionDescriptiveInformationImpl.

/**
 * Updates a business object definition descriptive information.
 *
 * @param businessObjectDefinitionKey the business object definition key
 * @param request the business object definition descriptive information update request
 *
 * @return the updated business object definition
 */
protected BusinessObjectDefinition updateBusinessObjectDefinitionDescriptiveInformationImpl(BusinessObjectDefinitionKey businessObjectDefinitionKey, BusinessObjectDefinitionDescriptiveInformationUpdateRequest request) {
    // Perform validation and trim.
    businessObjectDefinitionHelper.validateBusinessObjectDefinitionKey(businessObjectDefinitionKey);
    validateBusinessObjectDefinitionDescriptiveInformationUpdateRequest(request);
    // Retrieve and ensure that a business object definition already exists with the specified key.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(businessObjectDefinitionKey);
    BusinessObjectFormatEntity businessObjectFormatEntity = null;
    DescriptiveBusinessObjectFormatUpdateRequest descriptiveFormat = request.getDescriptiveBusinessObjectFormat();
    if (descriptiveFormat != null) {
        BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey();
        businessObjectFormatKey.setBusinessObjectDefinitionName(businessObjectDefinitionEntity.getName());
        businessObjectFormatKey.setNamespace(businessObjectDefinitionEntity.getNamespace().getCode());
        businessObjectFormatKey.setBusinessObjectFormatFileType(descriptiveFormat.getBusinessObjectFormatFileType());
        businessObjectFormatKey.setBusinessObjectFormatUsage(descriptiveFormat.getBusinessObjectFormatUsage());
        businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatKey);
    }
    businessObjectDefinitionEntity.setDescriptiveBusinessObjectFormat(businessObjectFormatEntity);
    // Update and persist the entity.
    updateBusinessObjectDefinitionEntityDescriptiveInformation(businessObjectDefinitionEntity, request);
    // Notify the search index that a business object definition must be updated.
    searchIndexUpdateHelper.modifyBusinessObjectDefinitionInSearchIndex(businessObjectDefinitionEntity, SEARCH_INDEX_UPDATE_TYPE_UPDATE);
    // Create and return the business object definition object from the persisted entity.
    return createBusinessObjectDefinitionFromEntity(businessObjectDefinitionEntity, false);
}
Also used : BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) DescriptiveBusinessObjectFormatUpdateRequest(org.finra.herd.model.api.xml.DescriptiveBusinessObjectFormatUpdateRequest) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity)

Example 7 with BusinessObjectFormatKey

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

the class StorageUnitServiceImpl method getS3KeyPrefixImpl.

/**
 * Gets the S3 key prefix.
 *
 * @param businessObjectDataKey the business object data key
 * @param businessObjectFormatPartitionKey the business object format partition key
 * @param storageName the storage name
 * @param createNewVersion specifies if it is OK to return an S3 key prefix for a new business object data version that is not an initial version. This
 * parameter is ignored, when the business object data version is specified.
 *
 * @return the S3 key prefix
 */
protected S3KeyPrefixInformation getS3KeyPrefixImpl(BusinessObjectDataKey businessObjectDataKey, String businessObjectFormatPartitionKey, String storageName, Boolean createNewVersion) {
    // Validate and trim the business object data key.
    businessObjectDataHelper.validateBusinessObjectDataKey(businessObjectDataKey, true, false);
    // If specified, trim the partition key parameter.
    String businessObjectFormatPartitionKeyLocal = businessObjectFormatPartitionKey;
    if (businessObjectFormatPartitionKeyLocal != null) {
        businessObjectFormatPartitionKeyLocal = businessObjectFormatPartitionKeyLocal.trim();
    }
    // If specified, trim the storage name. Otherwise, default to the configuration option.
    String storageNameLocal = storageName;
    if (StringUtils.isNotBlank(storageNameLocal)) {
        storageNameLocal = storageNameLocal.trim();
    } else {
        storageNameLocal = configurationHelper.getProperty(ConfigurationValue.S3_STORAGE_NAME_DEFAULT);
    }
    // Get the business object format for the specified parameters and make sure it exists.
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(new BusinessObjectFormatKey(businessObjectDataKey.getNamespace(), businessObjectDataKey.getBusinessObjectDefinitionName(), businessObjectDataKey.getBusinessObjectFormatUsage(), businessObjectDataKey.getBusinessObjectFormatFileType(), businessObjectDataKey.getBusinessObjectFormatVersion()));
    // If specified, ensure that partition key matches what's configured within the business object format.
    if (StringUtils.isNotBlank(businessObjectFormatPartitionKeyLocal)) {
        Assert.isTrue(businessObjectFormatEntity.getPartitionKey().equalsIgnoreCase(businessObjectFormatPartitionKeyLocal), "Partition key \"" + businessObjectFormatPartitionKeyLocal + "\" doesn't match configured business object format partition key \"" + businessObjectFormatEntity.getPartitionKey() + "\".");
    }
    // Get and validate the storage along with the relative attributes.
    StorageEntity storageEntity = storageDaoHelper.getStorageEntity(storageNameLocal);
    // If the business object data version is not specified, get the next business object data version value.
    if (businessObjectDataKey.getBusinessObjectDataVersion() == null) {
        // Get the latest data version for this business object data, if it exists.
        BusinessObjectDataEntity latestVersionBusinessObjectDataEntity = businessObjectDataDao.getBusinessObjectDataByAltKey(new BusinessObjectDataKey(businessObjectDataKey.getNamespace(), businessObjectDataKey.getBusinessObjectDefinitionName(), businessObjectDataKey.getBusinessObjectFormatUsage(), businessObjectDataKey.getBusinessObjectFormatFileType(), businessObjectDataKey.getBusinessObjectFormatVersion(), businessObjectDataKey.getPartitionValue(), businessObjectDataKey.getSubPartitionValues(), null));
        // Throw an error if this business object data already exists and createNewVersion flag is not set.
        if (latestVersionBusinessObjectDataEntity != null && !createNewVersion) {
            throw new AlreadyExistsException("Initial version of the business object data already exists.");
        }
        businessObjectDataKey.setBusinessObjectDataVersion(latestVersionBusinessObjectDataEntity == null ? BusinessObjectDataEntity.BUSINESS_OBJECT_DATA_INITIAL_VERSION : latestVersionBusinessObjectDataEntity.getVersion() + 1);
    }
    // Build the S3 key prefix string.
    String s3KeyPrefix = s3KeyPrefixHelper.buildS3KeyPrefix(storageEntity, businessObjectFormatEntity, businessObjectDataKey);
    // Create and return the S3 key prefix.
    S3KeyPrefixInformation s3KeyPrefixInformation = new S3KeyPrefixInformation();
    s3KeyPrefixInformation.setS3KeyPrefix(s3KeyPrefix);
    return s3KeyPrefixInformation;
}
Also used : AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) S3KeyPrefixInformation(org.finra.herd.model.api.xml.S3KeyPrefixInformation) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey)

Example 8 with BusinessObjectFormatKey

use of org.finra.herd.model.api.xml.BusinessObjectFormatKey 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);
}
Also used : CustomDdlEntity(org.finra.herd.model.jpa.CustomDdlEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 9 with BusinessObjectFormatKey

use of org.finra.herd.model.api.xml.BusinessObjectFormatKey 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;
}
Also used : ArrayList(java.util.ArrayList) SchemaColumn(org.finra.herd.model.api.xml.SchemaColumn) NotificationJobActionEntity(org.finra.herd.model.jpa.NotificationJobActionEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) BusinessObjectFormat(org.finra.herd.model.api.xml.BusinessObjectFormat) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectDataNotificationEventParamsDto(org.finra.herd.model.dto.BusinessObjectDataNotificationEventParamsDto) BusinessObjectDataNotificationRegistrationEntity(org.finra.herd.model.jpa.BusinessObjectDataNotificationRegistrationEntity) NotificationActionEntity(org.finra.herd.model.jpa.NotificationActionEntity)

Example 10 with BusinessObjectFormatKey

use of org.finra.herd.model.api.xml.BusinessObjectFormatKey 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;
}
Also used : AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) RelationalStorageAttributesDto(org.finra.herd.model.dto.RelationalStorageAttributesDto) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity)

Aggregations

BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)166 Test (org.junit.Test)126 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)71 BusinessObjectFormat (org.finra.herd.model.api.xml.BusinessObjectFormat)62 DescriptiveBusinessObjectFormat (org.finra.herd.model.api.xml.DescriptiveBusinessObjectFormat)47 Attribute (org.finra.herd.model.api.xml.Attribute)24 ArrayList (java.util.ArrayList)23 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)20 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)17 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)15 BusinessObjectFormatUpdateRequest (org.finra.herd.model.api.xml.BusinessObjectFormatUpdateRequest)15 DescriptiveBusinessObjectFormatUpdateRequest (org.finra.herd.model.api.xml.DescriptiveBusinessObjectFormatUpdateRequest)15 StorageEntity (org.finra.herd.model.jpa.StorageEntity)14 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)13 NotificationMessageDefinitions (org.finra.herd.model.api.xml.NotificationMessageDefinitions)10 ConfigurationEntity (org.finra.herd.model.jpa.ConfigurationEntity)10 AttributeDefinition (org.finra.herd.model.api.xml.AttributeDefinition)9 BusinessObjectFormatAttributeDefinitionsUpdateRequest (org.finra.herd.model.api.xml.BusinessObjectFormatAttributeDefinitionsUpdateRequest)9 BusinessObjectFormatCreateRequest (org.finra.herd.model.api.xml.BusinessObjectFormatCreateRequest)9 NotificationMessageDefinition (org.finra.herd.model.api.xml.NotificationMessageDefinition)9