use of org.finra.herd.model.jpa.BusinessObjectDataStatusEntity in project herd by FINRAOS.
the class BusinessObjectDataDaoHelper method updateBusinessObjectDataStatus.
/**
* Update the business object data status.
*
* @param businessObjectDataEntity the business object data entity
* @param status the status
*/
public void updateBusinessObjectDataStatus(BusinessObjectDataEntity businessObjectDataEntity, String status) {
// Retrieve and ensure the status is valid.
BusinessObjectDataStatusEntity businessObjectDataStatusEntity = businessObjectDataStatusDaoHelper.getBusinessObjectDataStatusEntity(status);
// Save the current status value.
String oldStatus = businessObjectDataEntity.getStatus().getCode();
// Update the entity with the new values.
businessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
// Add an entry to the business object data status history table
BusinessObjectDataStatusHistoryEntity businessObjectDataStatusHistoryEntity = new BusinessObjectDataStatusHistoryEntity();
businessObjectDataEntity.getHistoricalStatuses().add(businessObjectDataStatusHistoryEntity);
businessObjectDataStatusHistoryEntity.setBusinessObjectData(businessObjectDataEntity);
businessObjectDataStatusHistoryEntity.setStatus(businessObjectDataStatusEntity);
// Persist the entity.
businessObjectDataDao.saveAndRefresh(businessObjectDataEntity);
// Sent a business object data status change notification.
messageNotificationEventService.processBusinessObjectDataStatusChangeNotificationEvent(businessObjectDataHelper.getBusinessObjectDataKey(businessObjectDataEntity), businessObjectDataStatusEntity.getCode(), oldStatus);
}
use of org.finra.herd.model.jpa.BusinessObjectDataStatusEntity in project herd by FINRAOS.
the class BusinessObjectDataInitiateDestroyHelperServiceImplTest method testExecuteInitiateDestroyAfterStep.
@Test
public void testExecuteInitiateDestroyAfterStep() {
// Create a business object data key.
BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION);
// Create a business object data status entity.
BusinessObjectDataStatusEntity businessObjectDataStatusEntity = new BusinessObjectDataStatusEntity();
businessObjectDataStatusEntity.setCode(BusinessObjectDataStatusEntity.VALID);
// Create a business object data entity.
BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
businessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
// Create a storage unit status entity.
StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity();
storageUnitStatusEntity.setCode(StorageUnitStatusEntity.DISABLING);
// Create a storage unit entity.
StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
storageUnitEntity.setStatus(storageUnitStatusEntity);
// Create a business object data destroy parameters DTO.
BusinessObjectDataDestroyDto businessObjectDataDestroyDto = new BusinessObjectDataDestroyDto(businessObjectDataKey, STORAGE_NAME, BusinessObjectDataStatusEntity.DELETED, BusinessObjectDataStatusEntity.VALID, StorageUnitStatusEntity.DISABLING, StorageUnitStatusEntity.ENABLED, S3_ENDPOINT, S3_BUCKET_NAME, TEST_S3_KEY_PREFIX, S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE, S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME, BDATA_FINAL_DESTROY_DELAY_IN_DAYS);
// Create a business object data.
BusinessObjectData businessObjectData = new BusinessObjectData();
businessObjectData.setId(ID);
// Mock the external calls.
when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey)).thenReturn(businessObjectDataEntity);
when(storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity)).thenReturn(storageUnitEntity);
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) {
// Get the new storage unit status.
String storageUnitStatus = (String) invocation.getArguments()[1];
// Create a storage unit status entity for the new storage unit status.
StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity();
storageUnitStatusEntity.setCode(storageUnitStatus);
// Update the storage unit with the new status.
StorageUnitEntity storageUnitEntity = (StorageUnitEntity) invocation.getArguments()[0];
storageUnitEntity.setStatus(storageUnitStatusEntity);
return null;
}
}).when(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.DISABLED, StorageUnitStatusEntity.DISABLED);
when(businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity)).thenReturn(businessObjectData);
// Call the method under test.
BusinessObjectData result = businessObjectDataInitiateDestroyHelperServiceImpl.executeInitiateDestroyAfterStep(businessObjectDataDestroyDto);
// Verify the external calls.
verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey);
verify(storageUnitDaoHelper).getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
verify(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.DISABLED, StorageUnitStatusEntity.DISABLED);
verify(businessObjectDataHelper).createBusinessObjectDataFromEntity(businessObjectDataEntity);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(businessObjectData, result);
assertEquals(new BusinessObjectDataDestroyDto(businessObjectDataKey, STORAGE_NAME, BusinessObjectDataStatusEntity.DELETED, BusinessObjectDataStatusEntity.VALID, StorageUnitStatusEntity.DISABLED, StorageUnitStatusEntity.DISABLING, S3_ENDPOINT, S3_BUCKET_NAME, TEST_S3_KEY_PREFIX, S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE, S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME, BDATA_FINAL_DESTROY_DELAY_IN_DAYS), businessObjectDataDestroyDto);
}
use of org.finra.herd.model.jpa.BusinessObjectDataStatusEntity in project herd by FINRAOS.
the class UploadDownloadHelperServiceImplTest method testPrepareForFileMove.
@Test
public void testPrepareForFileMove() {
// Create an object key.
String objectKey = UUID_VALUE;
// Create a complete upload single parameters DTO.
CompleteUploadSingleParamsDto completeUploadSingleParamsDto = new CompleteUploadSingleParamsDto();
// Create a business object data status entity.
BusinessObjectDataStatusEntity businessObjectDataStatusEntity = new BusinessObjectDataStatusEntity();
businessObjectDataStatusEntity.setCode(BusinessObjectDataStatusEntity.UPLOADING);
// Create a source storage entity.
StorageEntity sourceStorageEntity = new StorageEntity();
// Create a source business object data key.
BusinessObjectDataKey sourceBusinessObjectDataKey = new BusinessObjectDataKey();
sourceBusinessObjectDataKey.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE);
// Create a source business object data entity.
BusinessObjectDataEntity sourceBusinessObjectDataEntity = new BusinessObjectDataEntity();
sourceBusinessObjectDataEntity.setId(ID);
sourceBusinessObjectDataEntity.setPartitionValue(objectKey);
sourceBusinessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
// Create a list of source storage files.
List<StorageFileEntity> sourceStorageFileEntities = new ArrayList<>();
// Create a source storage unit.
StorageUnitEntity sourceStorageUnitEntity = new StorageUnitEntity();
sourceStorageUnitEntity.setBusinessObjectData(sourceBusinessObjectDataEntity);
sourceStorageUnitEntity.setStorage(sourceStorageEntity);
sourceStorageUnitEntity.setStorageFiles(sourceStorageFileEntities);
// Create a source storage file entity.
StorageFileEntity sourceStorageFileEntity = new StorageFileEntity();
sourceStorageFileEntities.add(sourceStorageFileEntity);
sourceStorageFileEntity.setStorageUnit(sourceStorageUnitEntity);
sourceStorageFileEntity.setPath(S3_KEY);
sourceStorageFileEntity.setFileSizeBytes(FILE_SIZE);
// Create a target storage entity.
StorageEntity targetStorageEntity = new StorageEntity();
// Create a target business object data key.
BusinessObjectDataKey targetBusinessObjectDataKey = new BusinessObjectDataKey();
targetBusinessObjectDataKey.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE_2);
// Create a list of source storage files.
List<StorageFileEntity> targetStorageFileEntities = new ArrayList<>();
// Create a target storage unit.
StorageUnitEntity targetStorageUnitEntity = new StorageUnitEntity();
targetStorageUnitEntity.setStorage(targetStorageEntity);
targetStorageUnitEntity.setStorageFiles(targetStorageFileEntities);
// Create a source storage file entity.
StorageFileEntity targetStorageFileEntity = new StorageFileEntity();
targetStorageFileEntities.add(targetStorageFileEntity);
targetStorageFileEntity.setPath(S3_KEY_2);
// Create a target business object data entity.
BusinessObjectDataEntity targetBusinessObjectDataEntity = new BusinessObjectDataEntity();
targetBusinessObjectDataEntity.setId(ID_2);
targetBusinessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
targetBusinessObjectDataEntity.setStorageUnits(Collections.singletonList(targetStorageUnitEntity));
// Create an AWS parameters DTO.
AwsParamsDto awsParamsDto = new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT);
// Mock the external calls.
when(storageFileDaoHelper.getStorageFileEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, objectKey)).thenReturn(sourceStorageFileEntity);
when(businessObjectDataHelper.getBusinessObjectDataKey(sourceBusinessObjectDataEntity)).thenReturn(sourceBusinessObjectDataKey);
when(businessObjectDataDao.getBusinessObjectDataEntitiesByPartitionValue(objectKey)).thenReturn(Arrays.asList(sourceBusinessObjectDataEntity, targetBusinessObjectDataEntity));
when(businessObjectDataHelper.getBusinessObjectDataKey(targetBusinessObjectDataEntity)).thenReturn(targetBusinessObjectDataKey);
when(storageDaoHelper.getStorageEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE)).thenReturn(sourceStorageEntity);
when(storageHelper.getStorageBucketName(sourceStorageEntity)).thenReturn(S3_BUCKET_NAME);
when(storageUnitDaoHelper.getStorageUnitEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, sourceBusinessObjectDataEntity)).thenReturn(sourceStorageUnitEntity);
when(awsHelper.getAwsParamsDto()).thenReturn(awsParamsDto);
when(storageHelper.getStorageBucketName(targetStorageEntity)).thenReturn(S3_BUCKET_NAME_2);
when(storageHelper.getStorageKmsKeyId(targetStorageEntity)).thenReturn(AWS_KMS_KEY_ID);
// Call the method under test.
uploadDownloadHelperService.prepareForFileMoveImpl(objectKey, completeUploadSingleParamsDto);
// Verify the external calls.
verify(storageFileDaoHelper).getStorageFileEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, objectKey);
verify(storageFileDaoHelper).getStorageFileEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, objectKey);
verify(businessObjectDataHelper).getBusinessObjectDataKey(sourceBusinessObjectDataEntity);
verify(businessObjectDataDao).getBusinessObjectDataEntitiesByPartitionValue(objectKey);
verify(businessObjectDataHelper).getBusinessObjectDataKey(targetBusinessObjectDataEntity);
verify(storageDaoHelper).getStorageEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE);
verify(storageHelper).getStorageBucketName(sourceStorageEntity);
verify(storageUnitDaoHelper).getStorageUnitEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, sourceBusinessObjectDataEntity);
verify(awsHelper, times(2)).getAwsParamsDto();
verify(s3Dao).validateS3File(any(S3FileTransferRequestParamsDto.class), eq(FILE_SIZE));
verify(storageHelper).getStorageBucketName(targetStorageEntity);
verify(storageHelper).getStorageKmsKeyId(targetStorageEntity);
verify(s3Dao).s3FileExists(any(S3FileTransferRequestParamsDto.class));
verify(businessObjectDataDaoHelper).updateBusinessObjectDataStatus(sourceBusinessObjectDataEntity, BusinessObjectDataStatusEntity.RE_ENCRYPTING);
verify(businessObjectDataDaoHelper).updateBusinessObjectDataStatus(targetBusinessObjectDataEntity, BusinessObjectDataStatusEntity.RE_ENCRYPTING);
verify(notificationEventService).processBusinessObjectDataNotificationEventAsync(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_STTS_CHG, sourceBusinessObjectDataKey, BusinessObjectDataStatusEntity.RE_ENCRYPTING, BusinessObjectDataStatusEntity.UPLOADING);
verify(notificationEventService).processBusinessObjectDataNotificationEventAsync(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_STTS_CHG, targetBusinessObjectDataKey, BusinessObjectDataStatusEntity.RE_ENCRYPTING, BusinessObjectDataStatusEntity.UPLOADING);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(new CompleteUploadSingleParamsDto(sourceBusinessObjectDataKey, S3_BUCKET_NAME, S3_KEY, BusinessObjectDataStatusEntity.UPLOADING, BusinessObjectDataStatusEntity.RE_ENCRYPTING, targetBusinessObjectDataKey, S3_BUCKET_NAME_2, S3_KEY_2, BusinessObjectDataStatusEntity.UPLOADING, BusinessObjectDataStatusEntity.RE_ENCRYPTING, AWS_KMS_KEY_ID, awsParamsDto), completeUploadSingleParamsDto);
}
use of org.finra.herd.model.jpa.BusinessObjectDataStatusEntity in project herd by FINRAOS.
the class UploadDownloadHelperServiceImplTest method testPrepareForFileMoveImplOptimisticLockException.
@Test
public void testPrepareForFileMoveImplOptimisticLockException() {
// Create an object key.
String objectKey = UUID_VALUE;
// Create a complete upload single parameters DTO.
CompleteUploadSingleParamsDto completeUploadSingleParamsDto = new CompleteUploadSingleParamsDto();
// Create a business object data status entity.
BusinessObjectDataStatusEntity businessObjectDataStatusEntity = new BusinessObjectDataStatusEntity();
businessObjectDataStatusEntity.setCode(BusinessObjectDataStatusEntity.UPLOADING);
// Create a source storage entity.
StorageEntity sourceStorageEntity = new StorageEntity();
// Create a source business object data key.
BusinessObjectDataKey sourceBusinessObjectDataKey = new BusinessObjectDataKey();
sourceBusinessObjectDataKey.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE);
// Create a source business object data entity.
BusinessObjectDataEntity sourceBusinessObjectDataEntity = new BusinessObjectDataEntity();
sourceBusinessObjectDataEntity.setId(ID);
sourceBusinessObjectDataEntity.setPartitionValue(objectKey);
sourceBusinessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
// Create a list of source storage files.
List<StorageFileEntity> sourceStorageFileEntities = new ArrayList<>();
// Create a source storage unit.
StorageUnitEntity sourceStorageUnitEntity = new StorageUnitEntity();
sourceStorageUnitEntity.setBusinessObjectData(sourceBusinessObjectDataEntity);
sourceStorageUnitEntity.setStorage(sourceStorageEntity);
sourceStorageUnitEntity.setStorageFiles(sourceStorageFileEntities);
// Create a source storage file entity.
StorageFileEntity sourceStorageFileEntity = new StorageFileEntity();
sourceStorageFileEntities.add(sourceStorageFileEntity);
sourceStorageFileEntity.setStorageUnit(sourceStorageUnitEntity);
sourceStorageFileEntity.setPath(S3_KEY);
sourceStorageFileEntity.setFileSizeBytes(FILE_SIZE);
// Create a target storage entity.
StorageEntity targetStorageEntity = new StorageEntity();
// Create a target business object data key.
BusinessObjectDataKey targetBusinessObjectDataKey = new BusinessObjectDataKey();
targetBusinessObjectDataKey.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE_2);
// Create a list of source storage files.
List<StorageFileEntity> targetStorageFileEntities = new ArrayList<>();
// Create a target storage unit.
StorageUnitEntity targetStorageUnitEntity = new StorageUnitEntity();
targetStorageUnitEntity.setStorage(targetStorageEntity);
targetStorageUnitEntity.setStorageFiles(targetStorageFileEntities);
// Create a source storage file entity.
StorageFileEntity targetStorageFileEntity = new StorageFileEntity();
targetStorageFileEntities.add(targetStorageFileEntity);
targetStorageFileEntity.setPath(S3_KEY_2);
// Create a target business object data entity.
BusinessObjectDataEntity targetBusinessObjectDataEntity = new BusinessObjectDataEntity();
targetBusinessObjectDataEntity.setId(ID_2);
targetBusinessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
targetBusinessObjectDataEntity.setStorageUnits(Collections.singletonList(targetStorageUnitEntity));
// Create an AWS parameters DTO.
AwsParamsDto awsParamsDto = new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT);
// Mock the external calls.
when(storageFileDaoHelper.getStorageFileEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, objectKey)).thenReturn(sourceStorageFileEntity);
when(businessObjectDataHelper.getBusinessObjectDataKey(sourceBusinessObjectDataEntity)).thenReturn(sourceBusinessObjectDataKey);
when(businessObjectDataDao.getBusinessObjectDataEntitiesByPartitionValue(objectKey)).thenReturn(Arrays.asList(sourceBusinessObjectDataEntity, targetBusinessObjectDataEntity));
when(businessObjectDataHelper.getBusinessObjectDataKey(targetBusinessObjectDataEntity)).thenReturn(targetBusinessObjectDataKey);
when(storageDaoHelper.getStorageEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE)).thenReturn(sourceStorageEntity);
when(storageHelper.getStorageBucketName(sourceStorageEntity)).thenReturn(S3_BUCKET_NAME);
when(storageUnitDaoHelper.getStorageUnitEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, sourceBusinessObjectDataEntity)).thenReturn(sourceStorageUnitEntity);
when(awsHelper.getAwsParamsDto()).thenReturn(awsParamsDto);
when(storageHelper.getStorageBucketName(targetStorageEntity)).thenReturn(S3_BUCKET_NAME_2);
when(storageHelper.getStorageKmsKeyId(targetStorageEntity)).thenReturn(AWS_KMS_KEY_ID);
doThrow(new OptimisticLockException(ERROR_MESSAGE)).when(businessObjectDataDaoHelper).updateBusinessObjectDataStatus(sourceBusinessObjectDataEntity, BusinessObjectDataStatusEntity.RE_ENCRYPTING);
when(jsonHelper.objectToJson(sourceBusinessObjectDataKey)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING);
when(jsonHelper.objectToJson(targetBusinessObjectDataKey)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING_2);
// Try to call the method under test.
try {
uploadDownloadHelperService.prepareForFileMoveImpl(objectKey, completeUploadSingleParamsDto);
} catch (OptimisticLockException e) {
assertEquals(String.format("Ignoring S3 notification due to an optimistic lock exception caused by duplicate S3 event notifications. " + "sourceBusinessObjectDataKey=%s targetBusinessObjectDataKey=%s", BUSINESS_OBJECT_DATA_KEY_AS_STRING, BUSINESS_OBJECT_DATA_KEY_AS_STRING_2), e.getMessage());
}
// Verify the external calls.
verify(storageFileDaoHelper).getStorageFileEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, objectKey);
verify(storageFileDaoHelper).getStorageFileEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, objectKey);
verify(businessObjectDataHelper).getBusinessObjectDataKey(sourceBusinessObjectDataEntity);
verify(businessObjectDataDao).getBusinessObjectDataEntitiesByPartitionValue(objectKey);
verify(businessObjectDataHelper).getBusinessObjectDataKey(targetBusinessObjectDataEntity);
verify(storageDaoHelper).getStorageEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE);
verify(storageHelper).getStorageBucketName(sourceStorageEntity);
verify(storageUnitDaoHelper).getStorageUnitEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE, sourceBusinessObjectDataEntity);
verify(awsHelper, times(2)).getAwsParamsDto();
verify(s3Dao).validateS3File(any(S3FileTransferRequestParamsDto.class), eq(FILE_SIZE));
verify(storageHelper).getStorageBucketName(targetStorageEntity);
verify(storageHelper).getStorageKmsKeyId(targetStorageEntity);
verify(s3Dao).s3FileExists(any(S3FileTransferRequestParamsDto.class));
verify(businessObjectDataDaoHelper).updateBusinessObjectDataStatus(sourceBusinessObjectDataEntity, BusinessObjectDataStatusEntity.RE_ENCRYPTING);
verify(jsonHelper).objectToJson(sourceBusinessObjectDataKey);
verify(jsonHelper).objectToJson(targetBusinessObjectDataKey);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(new CompleteUploadSingleParamsDto(sourceBusinessObjectDataKey, S3_BUCKET_NAME, S3_KEY, BusinessObjectDataStatusEntity.UPLOADING, NO_BDATA_STATUS, targetBusinessObjectDataKey, S3_BUCKET_NAME_2, S3_KEY_2, BusinessObjectDataStatusEntity.UPLOADING, NO_BDATA_STATUS, AWS_KMS_KEY_ID, awsParamsDto), completeUploadSingleParamsDto);
}
use of org.finra.herd.model.jpa.BusinessObjectDataStatusEntity in project herd by FINRAOS.
the class BusinessObjectDataNotificationRegistrationServiceImpl method updateBusinessObjectDataNotificationRegistration.
@NamespacePermissions({ @NamespacePermission(fields = "#key?.namespace", permissions = NamespacePermissionEnum.WRITE), @NamespacePermission(fields = "#request?.businessObjectDataNotificationFilter?.namespace", permissions = NamespacePermissionEnum.READ), @NamespacePermission(fields = "#request?.jobActions?.![namespace]", permissions = NamespacePermissionEnum.EXECUTE) })
@Override
public BusinessObjectDataNotificationRegistration updateBusinessObjectDataNotificationRegistration(NotificationRegistrationKey key, BusinessObjectDataNotificationRegistrationUpdateRequest request) {
// Validate and trim the key.
validateBusinessObjectDataNotificationRegistrationKey(key);
// Validate and trim the request parameters.
validateBusinessObjectDataNotificationRegistrationUpdateRequest(request);
// Retrieve and ensure that a business object data notification exists with the specified key.
BusinessObjectDataNotificationRegistrationEntity oldBusinessObjectDataNotificationRegistrationEntity = businessObjectDataNotificationRegistrationDaoHelper.getBusinessObjectDataNotificationRegistrationEntity(key);
String oldBusinessObjectDataNotificationRegistrationName = oldBusinessObjectDataNotificationRegistrationEntity.getName();
// Retrieve the namespace with the specified namespace code.
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(key.getNamespace());
// Retrieve and validate the notification event type entity.
NotificationEventTypeEntity notificationEventTypeEntity = getAndValidateNotificationEventTypeEntity(request.getBusinessObjectDataEventType());
// Get the business object data notification filter.
BusinessObjectDataNotificationFilter filter = request.getBusinessObjectDataNotificationFilter();
// Retrieve and ensure that business object definition exists. Since namespace is specified, retrieve a business object definition by it's key.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(new BusinessObjectDefinitionKey(filter.getNamespace(), filter.getBusinessObjectDefinitionName()));
// If specified, retrieve and ensure that file type exists.
FileTypeEntity fileTypeEntity = null;
if (StringUtils.isNotBlank(filter.getBusinessObjectFormatFileType())) {
fileTypeEntity = fileTypeDaoHelper.getFileTypeEntity(filter.getBusinessObjectFormatFileType());
}
// If specified, retrieve and ensure that storage exists.
StorageEntity storageEntity = null;
if (StringUtils.isNotBlank(filter.getStorageName())) {
storageEntity = storageDaoHelper.getStorageEntity(filter.getStorageName());
}
// If specified, retrieve and ensure that new business object data status exists.
BusinessObjectDataStatusEntity newBusinessObjectDataStatus = null;
if (StringUtils.isNotBlank(filter.getNewBusinessObjectDataStatus())) {
newBusinessObjectDataStatus = businessObjectDataStatusDaoHelper.getBusinessObjectDataStatusEntity(filter.getNewBusinessObjectDataStatus());
}
// If specified, retrieve and ensure that old business object data status exists.
BusinessObjectDataStatusEntity oldBusinessObjectDataStatus = null;
if (StringUtils.isNotBlank(filter.getOldBusinessObjectDataStatus())) {
oldBusinessObjectDataStatus = businessObjectDataStatusDaoHelper.getBusinessObjectDataStatusEntity(filter.getOldBusinessObjectDataStatus());
}
// TODO: We need to add a null/empty list check here, if/when list of job actions will become optional (due to addition of other action types).
for (JobAction jobAction : request.getJobActions()) {
// Ensure that job definition exists.
jobDefinitionDaoHelper.getJobDefinitionEntity(jobAction.getNamespace(), jobAction.getJobName());
}
// Retrieve and validate the notification registration status entity.
NotificationRegistrationStatusEntity notificationRegistrationStatusEntity = notificationRegistrationStatusDaoHelper.getNotificationRegistrationStatusEntity(request.getNotificationRegistrationStatus());
// Delete the business object data notification.
businessObjectDataNotificationRegistrationDao.delete(oldBusinessObjectDataNotificationRegistrationEntity);
// Create a business object data notification registration entity from the request information.
BusinessObjectDataNotificationRegistrationEntity newBusinessObjectDataNotificationRegistrationEntity = createBusinessObjectDataNotificationEntity(namespaceEntity, notificationEventTypeEntity, businessObjectDefinitionEntity, fileTypeEntity, storageEntity, newBusinessObjectDataStatus, oldBusinessObjectDataStatus, new NotificationRegistrationKey(namespaceEntity.getCode(), oldBusinessObjectDataNotificationRegistrationName), request.getBusinessObjectDataNotificationFilter(), request.getJobActions(), notificationRegistrationStatusEntity);
// Persist the new entity.
newBusinessObjectDataNotificationRegistrationEntity = businessObjectDataNotificationRegistrationDao.saveAndRefresh(newBusinessObjectDataNotificationRegistrationEntity);
// Create and return the business object data notification object from the persisted entity.
return createBusinessObjectDataNotificationFromEntity(newBusinessObjectDataNotificationRegistrationEntity);
}
Aggregations