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);
}
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;
}
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;
}
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);
}
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);
}
Aggregations