Search in sources :

Example 36 with NamespacePermission

use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.

the class AllowedAttributeValueServiceImpl method getAllowedAttributeValues.

/**
 * Retrieves existing allowed attribute values based on the specified key
 *
 * @param attributeValueListKey the attribute value list key
 *
 * @return the allowed attribute values information
 */
@NamespacePermission(fields = "#attributeValueListKey.namespace", permissions = NamespacePermissionEnum.READ)
@Override
public AllowedAttributeValuesInformation getAllowedAttributeValues(AttributeValueListKey attributeValueListKey) {
    // Perform validation and trim of the input parameters.
    attributeValueListHelper.validateAttributeValueListKey(attributeValueListKey);
    // Retrieve and ensure that a attribute value list exists with the specified name.
    AttributeValueListEntity attributeValueListEntity = attributeValueListDaoHelper.getAttributeValueListEntity(attributeValueListKey);
    // Retrieve a list of allowed attribute values.
    List<AllowedAttributeValueEntity> allowedAttributeValueEntities = allowedAttributeValueDao.getAllowedAttributeValuesByAttributeValueListKey(attributeValueListKey);
    return createAllowedAttributeValuesInformationFromEntities(attributeValueListEntity, allowedAttributeValueEntities);
}
Also used : AttributeValueListEntity(org.finra.herd.model.jpa.AttributeValueListEntity) AllowedAttributeValueEntity(org.finra.herd.model.jpa.AllowedAttributeValueEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 37 with NamespacePermission

use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.

the class NotificationRegistrationStatusServiceImpl method updateNotificationRegistrationStatus.

@NamespacePermission(fields = "#namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public NotificationRegistrationStatusUpdateResponse updateNotificationRegistrationStatus(String namespace, String notificationName, NotificationRegistrationStatusUpdateRequest notificationRegistrationStatusUpdateRequest) {
    Assert.hasText(namespace, "The namespace must be specified");
    Assert.hasText(notificationName, "The notification name must be specified");
    String notificationRegistrationStatus = notificationRegistrationStatusUpdateRequest.getNotificationRegistrationStatus();
    Assert.hasText(notificationRegistrationStatus, "The notification registration status must be specified");
    NotificationRegistrationEntity notificationRegistration = notificationRegistrationDaoHelper.getNotificationRegistration(namespace.trim(), notificationName.trim());
    NotificationRegistrationStatusEntity notificationRegistrationStatusEntity = notificationRegistrationStatusDaoHelper.getNotificationRegistrationStatusEntity(notificationRegistrationStatus.trim());
    notificationRegistration.setNotificationRegistrationStatus(notificationRegistrationStatusEntity);
    NotificationRegistrationStatusUpdateResponse notificationRegistrationStatusUpdateResponse = new NotificationRegistrationStatusUpdateResponse();
    notificationRegistrationStatusUpdateResponse.setNotificationRegistrationKey(new NotificationRegistrationKey(notificationRegistration.getNamespace().getCode(), notificationRegistration.getName()));
    notificationRegistrationStatusUpdateResponse.setNotificationRegistrationStatus(notificationRegistrationStatusEntity.getCode());
    return notificationRegistrationStatusUpdateResponse;
}
Also used : NotificationRegistrationStatusEntity(org.finra.herd.model.jpa.NotificationRegistrationStatusEntity) NotificationRegistrationStatusUpdateResponse(org.finra.herd.model.api.xml.NotificationRegistrationStatusUpdateResponse) NotificationRegistrationEntity(org.finra.herd.model.jpa.NotificationRegistrationEntity) NotificationRegistrationKey(org.finra.herd.model.api.xml.NotificationRegistrationKey) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 38 with NamespacePermission

use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.

the class BusinessObjectDataServiceImpl method deleteBusinessObjectData.

@NamespacePermission(fields = "#businessObjectDataKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public BusinessObjectData deleteBusinessObjectData(BusinessObjectDataKey businessObjectDataKey, Boolean deleteFiles) {
    // Validate and trim the business object data key.
    businessObjectDataHelper.validateBusinessObjectDataKey(businessObjectDataKey, true, true);
    // Validate the mandatory deleteFiles flag.
    Assert.notNull(deleteFiles, "A delete files flag must be specified.");
    // Retrieve the business object data and ensure it exists.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey);
    // If the business object data has children, remove the parent children relationship.
    if (!businessObjectDataEntity.getBusinessObjectDataChildren().isEmpty()) {
        for (BusinessObjectDataEntity childBusinessObjectEntity : businessObjectDataEntity.getBusinessObjectDataChildren()) {
            childBusinessObjectEntity.getBusinessObjectDataParents().remove(businessObjectDataEntity);
        }
        String businessObjectDataChildren = businessObjectDataEntity.getBusinessObjectDataChildren().stream().map(bData -> String.format("{%s}", businessObjectDataHelper.businessObjectDataEntityAltKeyToString(bData))).collect(Collectors.joining(", "));
        businessObjectDataEntity.setBusinessObjectDataChildren(new ArrayList<BusinessObjectDataEntity>());
        businessObjectDataDao.save(businessObjectDataEntity);
        LOGGER.warn(String.format("Deleting business object data {%s} that has children associated with it. The parent relationship has been removed from: %s.", businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity), businessObjectDataChildren));
    }
    // If the flag is set, clean up the data files from all storages of S3 storage platform type.
    LOGGER.info("deleteFiles={}", deleteFiles);
    if (deleteFiles) {
        // Loop over all storage units for this business object data.
        for (StorageUnitEntity storageUnitEntity : businessObjectDataEntity.getStorageUnits()) {
            StorageEntity storageEntity = storageUnitEntity.getStorage();
            // Currently, we only support data file deletion from S3 platform type.
            if (storageEntity.getStoragePlatform().getName().equals(StoragePlatformEntity.S3)) {
                LOGGER.info("Deleting business object data files from the storage... storageName=\"{}\" businessObjectDataKey={}", storageEntity.getName(), jsonHelper.objectToJson(businessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataEntity)));
                // Get the S3 validation flags.
                boolean validatePathPrefix = storageHelper.getBooleanStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_PATH_PREFIX), storageEntity, false, true);
                // If this storage conforms to the path prefix validation, then delete all keys found under the S3 key prefix.
                if (validatePathPrefix) {
                    // Retrieve S3 key prefix velocity template storage attribute value and store it in memory.
                    // Please note that it is not required, so we pass in a "false" flag.
                    String s3KeyPrefixVelocityTemplate = storageHelper.getStorageAttributeValueByName(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), storageEntity, false);
                    // Validate that S3 key prefix velocity template is configured.
                    Assert.isTrue(StringUtils.isNotBlank(s3KeyPrefixVelocityTemplate), String.format("Storage \"%s\" has enabled path validation without S3 key prefix velocity template configured.", storageEntity.getName()));
                    // Build the S3 key prefix as per S3 Naming Convention Wiki page.
                    String s3KeyPrefix = s3KeyPrefixHelper.buildS3KeyPrefix(s3KeyPrefixVelocityTemplate, businessObjectDataEntity.getBusinessObjectFormat(), businessObjectDataKey, storageEntity.getName());
                    // Get S3 bucket access parameters, such as bucket name, AWS access key ID, AWS secret access key, etc...
                    S3FileTransferRequestParamsDto params = storageHelper.getS3BucketAccessParams(storageEntity);
                    // Since the S3 key prefix represents a directory, we add a trailing '/' character to it.
                    params.setS3KeyPrefix(s3KeyPrefix + "/");
                    // Delete a list of all keys/objects from S3 managed bucket matching the expected S3 key prefix.
                    // Please note that when deleting S3 files, we also delete all 0 byte objects that represent S3 directories.
                    s3Service.deleteDirectory(params);
                } else // For a non S3 prefixed paths, delete the files explicitly or if only directory is registered, delete all files/subfolders found under it.
                {
                    // Get S3 bucket access parameters, such as bucket name, AWS access key ID, AWS secret access key, etc...
                    S3FileTransferRequestParamsDto params = storageHelper.getS3BucketAccessParams(storageEntity);
                    // If only directory is registered delete all files/sub-folders found under it.
                    if (StringUtils.isNotBlank(storageUnitEntity.getDirectoryPath()) && storageUnitEntity.getStorageFiles().isEmpty()) {
                        // Since the directory path represents a directory, we add a trailing '/' character to it.
                        params.setS3KeyPrefix(storageUnitEntity.getDirectoryPath() + "/");
                        // Delete a list of all keys/objects from S3 bucket matching the directory path.
                        // Please note that when deleting S3 files, we also delete all 0 byte objects that represent S3 directories.
                        s3Service.deleteDirectory(params);
                    } else // Delete the files explicitly.
                    {
                        // Create a list of files to delete.
                        List<File> files = new ArrayList<>();
                        for (StorageFileEntity storageFileEntity : storageUnitEntity.getStorageFiles()) {
                            files.add(new File(storageFileEntity.getPath()));
                        }
                        params.setFiles(files);
                        s3Service.deleteFileList(params);
                    }
                }
            } else {
                LOGGER.info("Skipping business object data file removal for a storage unit from the storage since it is not an S3 storage platform. " + " storageName=\"{}\" businessObjectDataKey={}", storageEntity.getName(), jsonHelper.objectToJson(businessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataEntity)));
            }
        }
    }
    // Create the business object data object from the entity.
    BusinessObjectData deletedBusinessObjectData = businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity);
    // Delete this business object data.
    businessObjectDataDao.delete(businessObjectDataEntity);
    // If this business object data version is the latest, set the latest flag on the previous version of this object data, if it exists.
    if (businessObjectDataEntity.getLatestVersion()) {
        // Get the maximum version for this business object data, if it exists.
        Integer maxBusinessObjectDataVersion = businessObjectDataDao.getBusinessObjectDataMaxVersion(businessObjectDataKey);
        if (maxBusinessObjectDataVersion != null) {
            // Retrieve the previous version business object data entity. Since we successfully got the maximum
            // version for this business object data, the retrieved entity is not expected to be null.
            BusinessObjectDataEntity previousVersionBusinessObjectDataEntity = businessObjectDataDao.getBusinessObjectDataByAltKey(new BusinessObjectDataKey(businessObjectDataKey.getNamespace(), businessObjectDataKey.getBusinessObjectDefinitionName(), businessObjectDataKey.getBusinessObjectFormatUsage(), businessObjectDataKey.getBusinessObjectFormatFileType(), businessObjectDataKey.getBusinessObjectFormatVersion(), businessObjectDataKey.getPartitionValue(), businessObjectDataKey.getSubPartitionValues(), maxBusinessObjectDataVersion));
            // Update the previous version business object data entity.
            previousVersionBusinessObjectDataEntity.setLatestVersion(true);
            businessObjectDataDao.saveAndRefresh(previousVersionBusinessObjectDataEntity);
        }
    }
    // Return the deleted business object data.
    return deletedBusinessObjectData;
}
Also used : S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) CustomDdlKey(org.finra.herd.model.api.xml.CustomDdlKey) StorageDaoHelper(org.finra.herd.service.helper.StorageDaoHelper) NotificationEventTypeEntity(org.finra.herd.model.jpa.NotificationEventTypeEntity) BusinessObjectDataSearchKey(org.finra.herd.model.api.xml.BusinessObjectDataSearchKey) StorageUnitDao(org.finra.herd.dao.StorageUnitDao) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) BusinessObjectDataDdlCollectionRequest(org.finra.herd.model.api.xml.BusinessObjectDataDdlCollectionRequest) BusinessObjectDataRetryStoragePolicyTransitionRequest(org.finra.herd.model.api.xml.BusinessObjectDataRetryStoragePolicyTransitionRequest) StringUtils(org.apache.commons.lang3.StringUtils) BusinessObjectDataAttributesUpdateRequest(org.finra.herd.model.api.xml.BusinessObjectDataAttributesUpdateRequest) BusinessObjectDataKeys(org.finra.herd.model.api.xml.BusinessObjectDataKeys) BusinessObjectDataSearchRequest(org.finra.herd.model.api.xml.BusinessObjectDataSearchRequest) AttributeDaoHelper(org.finra.herd.service.helper.AttributeDaoHelper) Attribute(org.finra.herd.model.api.xml.Attribute) Map(java.util.Map) BusinessObjectDataAvailabilityCollectionRequest(org.finra.herd.model.api.xml.BusinessObjectDataAvailabilityCollectionRequest) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) BusinessObjectDataInvalidateUnregisteredResponse(org.finra.herd.model.api.xml.BusinessObjectDataInvalidateUnregisteredResponse) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) BusinessObjectDataVersions(org.finra.herd.model.api.xml.BusinessObjectDataVersions) BusinessObjectDataVersion(org.finra.herd.model.api.xml.BusinessObjectDataVersion) ConfigurationValue(org.finra.herd.model.dto.ConfigurationValue) BusinessObjectFormatHelper(org.finra.herd.service.helper.BusinessObjectFormatHelper) BusinessObjectDataInvalidateUnregisteredHelper(org.finra.herd.service.helper.BusinessObjectDataInvalidateUnregisteredHelper) BusinessObjectDataService(org.finra.herd.service.BusinessObjectDataService) BusinessObjectFormatDaoHelper(org.finra.herd.service.helper.BusinessObjectFormatDaoHelper) Collectors(java.util.stream.Collectors) BusinessObjectDataSearchResultPagingInfoDto(org.finra.herd.model.dto.BusinessObjectDataSearchResultPagingInfoDto) BusinessObjectDataCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest) List(java.util.List) ConfigurationHelper(org.finra.herd.core.helper.ConfigurationHelper) NotificationEventService(org.finra.herd.service.NotificationEventService) StoragePlatformEntity(org.finra.herd.model.jpa.StoragePlatformEntity) CollectionUtils(org.springframework.util.CollectionUtils) BusinessObjectDataAvailabilityCollectionResponse(org.finra.herd.model.api.xml.BusinessObjectDataAvailabilityCollectionResponse) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) JsonHelper(org.finra.herd.dao.helper.JsonHelper) StorageEntity(org.finra.herd.model.jpa.StorageEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission) BusinessObjectDefinitionHelper(org.finra.herd.service.helper.BusinessObjectDefinitionHelper) NamespacePermissionEnum(org.finra.herd.model.api.xml.NamespacePermissionEnum) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) BusinessObjectDataDdl(org.finra.herd.model.api.xml.BusinessObjectDataDdl) BusinessObjectDataInitiateRestoreHelperService(org.finra.herd.service.BusinessObjectDataInitiateRestoreHelperService) BusinessObjectDataAvailability(org.finra.herd.model.api.xml.BusinessObjectDataAvailability) BusinessObjectDataInitiateDestroyHelperService(org.finra.herd.service.BusinessObjectDataInitiateDestroyHelperService) HashMap(java.util.HashMap) BooleanUtils(org.apache.commons.lang3.BooleanUtils) BusinessObjectDataHelper(org.finra.herd.service.helper.BusinessObjectDataHelper) DaoSpringModuleConfig(org.finra.herd.dao.config.DaoSpringModuleConfig) ArrayList(java.util.ArrayList) S3Service(org.finra.herd.service.S3Service) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectDataRetryStoragePolicyTransitionHelper(org.finra.herd.service.helper.BusinessObjectDataRetryStoragePolicyTransitionHelper) Propagation(org.springframework.transaction.annotation.Propagation) DdlGeneratorFactory(org.finra.herd.service.helper.DdlGeneratorFactory) Service(org.springframework.stereotype.Service) BusinessObjectDataDdlCollectionResponse(org.finra.herd.model.api.xml.BusinessObjectDataDdlCollectionResponse) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) CustomDdlDaoHelper(org.finra.herd.service.helper.CustomDdlDaoHelper) S3KeyPrefixHelper(org.finra.herd.service.helper.S3KeyPrefixHelper) BusinessObjectDataAvailabilityRequest(org.finra.herd.model.api.xml.BusinessObjectDataAvailabilityRequest) BusinessObjectDataStatusDaoHelper(org.finra.herd.service.helper.BusinessObjectDataStatusDaoHelper) StorageUnitHelper(org.finra.herd.service.helper.StorageUnitHelper) BusinessObjectDefinitionDaoHelper(org.finra.herd.service.helper.BusinessObjectDefinitionDaoHelper) Logger(org.slf4j.Logger) StorageFileEntity(org.finra.herd.model.jpa.StorageFileEntity) StorageHelper(org.finra.herd.service.helper.StorageHelper) BusinessObjectDataInvalidateUnregisteredRequest(org.finra.herd.model.api.xml.BusinessObjectDataInvalidateUnregisteredRequest) BusinessObjectDataDao(org.finra.herd.dao.BusinessObjectDataDao) BusinessObjectDataRestoreDto(org.finra.herd.model.dto.BusinessObjectDataRestoreDto) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) File(java.io.File) PublishNotificationMessages(org.finra.herd.model.annotation.PublishNotificationMessages) BusinessObjectDataDaoHelper(org.finra.herd.service.helper.BusinessObjectDataDaoHelper) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectDataStatus(org.finra.herd.model.api.xml.BusinessObjectDataStatus) BusinessObjectDataSearchHelper(org.finra.herd.service.helper.BusinessObjectDataSearchHelper) BusinessObjectDataSearchResult(org.finra.herd.model.api.xml.BusinessObjectDataSearchResult) BusinessObjectDataDestroyDto(org.finra.herd.model.dto.BusinessObjectDataDestroyDto) AttributeHelper(org.finra.herd.service.helper.AttributeHelper) BusinessObjectDataDdlRequest(org.finra.herd.model.api.xml.BusinessObjectDataDdlRequest) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) BusinessObjectDataStatusEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusEntity) CustomDdlEntity(org.finra.herd.model.jpa.CustomDdlEntity) S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) ArrayList(java.util.ArrayList) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) StorageFileEntity(org.finra.herd.model.jpa.StorageFileEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) File(java.io.File) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 39 with NamespacePermission

use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.

the class BusinessObjectDefinitionColumnServiceImpl method deleteBusinessObjectDefinitionColumn.

@NamespacePermission(fields = "#businessObjectDefinitionColumnKey.namespace", permissions = { NamespacePermissionEnum.WRITE_DESCRIPTIVE_CONTENT, NamespacePermissionEnum.WRITE })
@Override
public BusinessObjectDefinitionColumn deleteBusinessObjectDefinitionColumn(BusinessObjectDefinitionColumnKey businessObjectDefinitionColumnKey) {
    // Validate and trim the business object definition column key.
    validateBusinessObjectDefinitionColumnKey(businessObjectDefinitionColumnKey);
    // Retrieve and ensure that a business object definition column exists with the business object definition.
    BusinessObjectDefinitionColumnEntity businessObjectDefinitionColumnEntity = businessObjectDefinitionColumnDaoHelper.getBusinessObjectDefinitionColumnEntity(businessObjectDefinitionColumnKey);
    // Unlink schema columns from the business object definition column.
    for (SchemaColumnEntity schemaColumnEntity : businessObjectDefinitionColumnEntity.getSchemaColumns()) {
        schemaColumnEntity.setBusinessObjectDefinitionColumn(null);
    }
    // Delete the business object definition column.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionColumnEntity.getBusinessObjectDefinition();
    businessObjectDefinitionEntity.getColumns().remove(businessObjectDefinitionColumnEntity);
    businessObjectDefinitionDao.saveAndRefresh(businessObjectDefinitionEntity);
    // 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 column object from the deleted entity.
    return createBusinessObjectDefinitionColumnFromEntity(businessObjectDefinitionColumnEntity, true, getValidSearchResponseFields(), false);
}
Also used : SchemaColumnEntity(org.finra.herd.model.jpa.SchemaColumnEntity) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) BusinessObjectDefinitionColumnEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionColumnEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 40 with NamespacePermission

use of org.finra.herd.model.annotation.NamespacePermission in project herd by FINRAOS.

the class BusinessObjectDefinitionColumnServiceImpl method createBusinessObjectDefinitionColumn.

@NamespacePermission(fields = "#request.businessObjectDefinitionColumnKey.namespace", permissions = { NamespacePermissionEnum.WRITE_DESCRIPTIVE_CONTENT, NamespacePermissionEnum.WRITE })
@Override
public BusinessObjectDefinitionColumn createBusinessObjectDefinitionColumn(BusinessObjectDefinitionColumnCreateRequest request) {
    // Validate and trim the business object definition column create request.
    validateBusinessObjectDefinitionColumnCreateRequest(request);
    // Get the business object definition key.
    BusinessObjectDefinitionKey businessObjectDefinitionKey = businessObjectDefinitionHelper.getBusinessObjectDefinitionKey(request.getBusinessObjectDefinitionColumnKey());
    // Get the business object definition and ensure it exists.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(businessObjectDefinitionKey);
    // Ensure a business object definition column with the specified name doesn't already exist for the business object definition.
    if (businessObjectDefinitionColumnDao.getBusinessObjectDefinitionColumnByBusinessObjectDefinitionColumnName(businessObjectDefinitionEntity, request.getBusinessObjectDefinitionColumnKey().getBusinessObjectDefinitionColumnName()) != null) {
        throw new AlreadyExistsException(String.format("Unable to create business object definition column with name \"%s\" because it already exists for the business object definition {%s}.", request.getBusinessObjectDefinitionColumnKey().getBusinessObjectDefinitionColumnName(), businessObjectDefinitionHelper.businessObjectDefinitionKeyToString(businessObjectDefinitionKey)));
    }
    // Retrieve schema column entities from all format instances for the business object definition that match the specified schema column name.
    Collection<SchemaColumnEntity> schemaColumnEntities = schemaColumnDao.getSchemaColumns(businessObjectDefinitionEntity, request.getSchemaColumnName());
    // Ensure that exists at least one schema column that matches the specified schema column name.
    if (CollectionUtils.isEmpty(schemaColumnEntities)) {
        if (businessObjectDefinitionEntity.getDescriptiveBusinessObjectFormat() == null) {
            throw new ObjectNotFoundException(String.format("Unable to create business object definition column because there are no format schema " + "columns with name \"%s\" for the business object definition {%s}.", request.getSchemaColumnName(), businessObjectDefinitionHelper.businessObjectDefinitionKeyToString(businessObjectDefinitionKey)));
        } else {
            throw new ObjectNotFoundException(String.format("Unable to create business object definition column because there are no format schema " + "columns with name \"%s\" in the descriptive business object format for the business object definition {%s}.", request.getSchemaColumnName(), businessObjectDefinitionHelper.businessObjectDefinitionKeyToString(businessObjectDefinitionKey)));
        }
    }
    // Ensure a business object definition column with the specified schema column name doesn't already exist for this business object definition.
    for (SchemaColumnEntity schemaColumnEntity : schemaColumnEntities) {
        if (schemaColumnEntity.getBusinessObjectDefinitionColumn() != null) {
            throw new AlreadyExistsException(String.format("Unable to create business object definition column because a business object definition column " + "with schema column name \"%s\" already exists for the business object definition {%s}.", request.getSchemaColumnName(), businessObjectDefinitionHelper.businessObjectDefinitionKeyToString(businessObjectDefinitionKey)));
        }
    }
    // Create a business object definition column entity from the request information.
    BusinessObjectDefinitionColumnEntity businessObjectDefinitionColumnEntity = createBusinessObjectDefinitionColumnEntity(businessObjectDefinitionEntity, request);
    // Link schema columns with the business object definition column.
    for (SchemaColumnEntity schemaColumnEntity : schemaColumnEntities) {
        schemaColumnEntity.setBusinessObjectDefinitionColumn(businessObjectDefinitionColumnEntity);
    }
    // Persist the change event entity
    businessObjectDefinitionColumnDaoHelper.saveBusinessObjectDefinitionColumnChangeEvents(businessObjectDefinitionColumnEntity);
    // Persist the new entity.
    businessObjectDefinitionColumnEntity = businessObjectDefinitionColumnDao.saveAndRefresh(businessObjectDefinitionColumnEntity);
    // 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 column object from the persisted entity.
    return createBusinessObjectDefinitionColumnFromEntity(businessObjectDefinitionColumnEntity, true, getValidSearchResponseFields(), false);
}
Also used : AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) SchemaColumnEntity(org.finra.herd.model.jpa.SchemaColumnEntity) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) BusinessObjectDefinitionColumnEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionColumnEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Aggregations

NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)63 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)10 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)10 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)10 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)9 AttributeValueListEntity (org.finra.herd.model.jpa.AttributeValueListEntity)6 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)5 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)5 CustomDdlEntity (org.finra.herd.model.jpa.CustomDdlEntity)5 Credentials (com.amazonaws.services.securitytoken.model.Credentials)4 ArrayList (java.util.ArrayList)4 PublishNotificationMessages (org.finra.herd.model.annotation.PublishNotificationMessages)4 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)4 IamRole (org.finra.herd.model.api.xml.IamRole)4 NamespaceIamRoleAuthorization (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization)4 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)4 NamespaceIamRoleAuthorizationEntity (org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity)4 UserNamespaceAuthorizationEntity (org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity)4 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)3 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)3