use of org.finra.herd.model.api.xml.StorageUnitNotificationFilter in project herd by FINRAOS.
the class StorageUnitNotificationRegistrationServiceImpl method updateStorageUnitNotificationRegistration.
@NamespacePermissions({ @NamespacePermission(fields = "#notificationRegistrationKey?.namespace", permissions = NamespacePermissionEnum.WRITE), @NamespacePermission(fields = "#request?.storageUnitNotificationFilter?.namespace", permissions = NamespacePermissionEnum.READ), @NamespacePermission(fields = "#request?.jobActions?.![namespace]", permissions = NamespacePermissionEnum.EXECUTE) })
@Override
public StorageUnitNotificationRegistration updateStorageUnitNotificationRegistration(NotificationRegistrationKey notificationRegistrationKey, StorageUnitNotificationRegistrationUpdateRequest request) {
// Validate and trim the key.
validateStorageUnitNotificationRegistrationKey(notificationRegistrationKey);
// Validate and trim the request parameters.
validateStorageUnitNotificationRegistrationUpdateRequest(request);
// Retrieve and ensure that a storage unit notification exists with the specified key.
StorageUnitNotificationRegistrationEntity oldStorageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDaoHelper.getStorageUnitNotificationRegistrationEntity(notificationRegistrationKey);
String oldStorageUnitNotificationRegistrationName = oldStorageUnitNotificationRegistrationEntity.getName();
// Retrieve the namespace with the specified namespace code.
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(notificationRegistrationKey.getNamespace());
// Retrieve and validate the notification event type entity.
NotificationEventTypeEntity notificationEventTypeEntity = getAndValidateNotificationEventTypeEntity(request.getStorageUnitEventType());
// Get the storage unit notification filter.
StorageUnitNotificationFilter filter = request.getStorageUnitNotificationFilter();
// 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());
}
// Retrieve and ensure that storage exists.
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(filter.getStorageName());
// If specified, retrieve and ensure that new storage unit status exists.
StorageUnitStatusEntity newStorageUnitStatus = null;
if (StringUtils.isNotBlank(filter.getNewStorageUnitStatus())) {
newStorageUnitStatus = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(filter.getNewStorageUnitStatus());
}
// If specified, retrieve and ensure that old storage unit status exists.
StorageUnitStatusEntity oldStorageUnitStatus = null;
if (StringUtils.isNotBlank(filter.getOldStorageUnitStatus())) {
oldStorageUnitStatus = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(filter.getOldStorageUnitStatus());
}
// 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 storage unit notification.
storageUnitNotificationRegistrationDao.delete(oldStorageUnitNotificationRegistrationEntity);
// Create a storage unit notification registration entity from the request information.
StorageUnitNotificationRegistrationEntity newStorageUnitNotificationRegistrationEntity = createStorageUnitNotificationEntity(namespaceEntity, notificationEventTypeEntity, businessObjectDefinitionEntity, fileTypeEntity, storageEntity, newStorageUnitStatus, oldStorageUnitStatus, new NotificationRegistrationKey(namespaceEntity.getCode(), oldStorageUnitNotificationRegistrationName), request.getStorageUnitNotificationFilter(), request.getJobActions(), notificationRegistrationStatusEntity);
// Persist the new entity.
newStorageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDao.saveAndRefresh(newStorageUnitNotificationRegistrationEntity);
// Create and return the storage unit notification object from the persisted entity.
return createStorageUnitNotificationFromEntity(newStorageUnitNotificationRegistrationEntity);
}
use of org.finra.herd.model.api.xml.StorageUnitNotificationFilter in project herd by FINRAOS.
the class StorageUnitNotificationRegistrationServiceImpl method createStorageUnitNotificationFromEntity.
/**
* Creates the storage unit notification registration from the persisted entity.
*
* @param storageUnitNotificationRegistrationEntity the storage unit notification registration entity
*
* @return the storage unit notification registration
*/
private StorageUnitNotificationRegistration createStorageUnitNotificationFromEntity(StorageUnitNotificationRegistrationEntity storageUnitNotificationRegistrationEntity) {
// Create the storage unit notification.
StorageUnitNotificationRegistration storageUnitNotificationRegistration = new StorageUnitNotificationRegistration();
storageUnitNotificationRegistration.setId(storageUnitNotificationRegistrationEntity.getId());
storageUnitNotificationRegistration.setStorageUnitNotificationRegistrationKey(new NotificationRegistrationKey(storageUnitNotificationRegistrationEntity.getNamespace().getCode(), storageUnitNotificationRegistrationEntity.getName()));
storageUnitNotificationRegistration.setStorageUnitEventType(storageUnitNotificationRegistrationEntity.getNotificationEventType().getCode());
StorageUnitNotificationFilter filter = new StorageUnitNotificationFilter();
storageUnitNotificationRegistration.setStorageUnitNotificationFilter(filter);
// Business object definition entity cannot be null as per storage unit notification registration create request validation.
filter.setNamespace(storageUnitNotificationRegistrationEntity.getBusinessObjectDefinition().getNamespace().getCode());
filter.setBusinessObjectDefinitionName(storageUnitNotificationRegistrationEntity.getBusinessObjectDefinition().getName());
filter.setBusinessObjectFormatUsage(storageUnitNotificationRegistrationEntity.getUsage());
filter.setBusinessObjectFormatFileType(storageUnitNotificationRegistrationEntity.getFileType() != null ? storageUnitNotificationRegistrationEntity.getFileType().getCode() : null);
filter.setBusinessObjectFormatVersion(storageUnitNotificationRegistrationEntity.getBusinessObjectFormatVersion());
filter.setStorageName(storageUnitNotificationRegistrationEntity.getStorage() != null ? storageUnitNotificationRegistrationEntity.getStorage().getName() : null);
filter.setNewStorageUnitStatus(storageUnitNotificationRegistrationEntity.getNewStorageUnitStatus() != null ? storageUnitNotificationRegistrationEntity.getNewStorageUnitStatus().getCode() : null);
filter.setOldStorageUnitStatus(storageUnitNotificationRegistrationEntity.getOldStorageUnitStatus() != null ? storageUnitNotificationRegistrationEntity.getOldStorageUnitStatus().getCode() : null);
List<JobAction> jobActions = new ArrayList<>();
storageUnitNotificationRegistration.setJobActions(jobActions);
for (NotificationActionEntity notificationActionEntity : storageUnitNotificationRegistrationEntity.getNotificationActions()) {
if (notificationActionEntity instanceof NotificationJobActionEntity) {
NotificationJobActionEntity notificationJobActionEntity = (NotificationJobActionEntity) notificationActionEntity;
JobAction jobAction = new JobAction();
jobActions.add(jobAction);
jobAction.setNamespace(notificationJobActionEntity.getJobDefinition().getNamespace().getCode());
jobAction.setJobName(notificationJobActionEntity.getJobDefinition().getName());
jobAction.setCorrelationData(notificationJobActionEntity.getCorrelationData());
}
}
storageUnitNotificationRegistration.setNotificationRegistrationStatus(storageUnitNotificationRegistrationEntity.getNotificationRegistrationStatus().getCode());
return storageUnitNotificationRegistration;
}
use of org.finra.herd.model.api.xml.StorageUnitNotificationFilter in project herd by FINRAOS.
the class StorageUnitNotificationRegistrationServiceImpl method createStorageUnitNotificationRegistration.
@NamespacePermissions({ @NamespacePermission(fields = "#request?.storageUnitNotificationRegistrationKey?.namespace", permissions = NamespacePermissionEnum.WRITE), @NamespacePermission(fields = "#request?.storageUnitNotificationFilter?.namespace", permissions = NamespacePermissionEnum.READ), @NamespacePermission(fields = "#request?.jobActions?.![namespace]", permissions = NamespacePermissionEnum.EXECUTE) })
@Override
public StorageUnitNotificationRegistration createStorageUnitNotificationRegistration(StorageUnitNotificationRegistrationCreateRequest request) {
// Validate and trim the request parameters.
validateStorageUnitNotificationRegistrationCreateRequest(request);
// Get the notification registration key.
NotificationRegistrationKey notificationRegistrationKey = request.getStorageUnitNotificationRegistrationKey();
// Retrieve and ensure that notification registration namespace exists.
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(notificationRegistrationKey.getNamespace());
// Retrieve and validate the notification event type entity.
NotificationEventTypeEntity notificationEventTypeEntity = getAndValidateNotificationEventTypeEntity(request.getStorageUnitEventType());
// Validate the notification event type.
Assert.isTrue(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG.name().equalsIgnoreCase(request.getStorageUnitEventType()), String.format("Notification event type \"%s\" is not supported for storage unit notification registration.", request.getStorageUnitEventType()));
// Get the storage unit notification filter.
StorageUnitNotificationFilter filter = request.getStorageUnitNotificationFilter();
// Retrieve and ensure that business object definition exists.
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());
}
// Retrieve and ensure that storage exists.
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(filter.getStorageName());
// If specified, retrieve and ensure that new storage unit status exists.
StorageUnitStatusEntity newStorageUnitStatus = null;
if (StringUtils.isNotBlank(filter.getNewStorageUnitStatus())) {
newStorageUnitStatus = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(filter.getNewStorageUnitStatus());
}
// If specified, retrieve and ensure that old storage unit status exists.
StorageUnitStatusEntity oldStorageUnitStatus = null;
if (StringUtils.isNotBlank(filter.getOldStorageUnitStatus())) {
oldStorageUnitStatus = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(filter.getOldStorageUnitStatus());
}
// 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());
}
// If specified, retrieve and validate the notification registration status entity. Otherwise, default it to ENABLED.
NotificationRegistrationStatusEntity notificationRegistrationStatusEntity = notificationRegistrationStatusDaoHelper.getNotificationRegistrationStatusEntity(StringUtils.isNotBlank(request.getNotificationRegistrationStatus()) ? request.getNotificationRegistrationStatus() : NotificationRegistrationStatusEntity.ENABLED);
// Ensure a storage unit notification with the specified name doesn't already exist for the specified namespace.
StorageUnitNotificationRegistrationEntity storageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDao.getStorageUnitNotificationRegistrationByAltKey(notificationRegistrationKey);
if (storageUnitNotificationRegistrationEntity != null) {
throw new AlreadyExistsException(String.format("Unable to create storage unit notification with name \"%s\" because it already exists for namespace \"%s\".", notificationRegistrationKey.getNotificationName(), notificationRegistrationKey.getNamespace()));
}
// Create a storage unit notification registration entity from the request information.
storageUnitNotificationRegistrationEntity = createStorageUnitNotificationEntity(namespaceEntity, notificationEventTypeEntity, businessObjectDefinitionEntity, fileTypeEntity, storageEntity, newStorageUnitStatus, oldStorageUnitStatus, request.getStorageUnitNotificationRegistrationKey(), request.getStorageUnitNotificationFilter(), request.getJobActions(), notificationRegistrationStatusEntity);
// Persist the new entity.
storageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDao.saveAndRefresh(storageUnitNotificationRegistrationEntity);
// Create and return the storage unit notification object from the persisted entity.
return createStorageUnitNotificationFromEntity(storageUnitNotificationRegistrationEntity);
}
use of org.finra.herd.model.api.xml.StorageUnitNotificationFilter in project herd by FINRAOS.
the class StorageUnitNotificationRegistrationRestControllerTest method testDeleteStorageUnitNotificationRegistration.
@Test
public void testDeleteStorageUnitNotificationRegistration() {
NotificationRegistrationKey storageUnitNotificationRegistrationKey = new NotificationRegistrationKey(NAMESPACE, NOTIFICATION_NAME);
StorageUnitNotificationRegistration storageUnitNotificationRegistration = new StorageUnitNotificationRegistration(ID, storageUnitNotificationRegistrationKey, NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG.name(), new StorageUnitNotificationFilter(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, STORAGE_NAME, STORAGE_UNIT_STATUS, STORAGE_UNIT_STATUS_2), notificationRegistrationDaoTestHelper.getTestJobActions(), NotificationRegistrationStatusEntity.ENABLED);
when(storageUnitNotificationRegistrationService.deleteStorageUnitNotificationRegistration(storageUnitNotificationRegistrationKey)).thenReturn(storageUnitNotificationRegistration);
// Delete this business object data notification.
StorageUnitNotificationRegistration deletedStorageUnitNotificationRegistration = storageUnitNotificationRegistrationRestController.deleteStorageUnitNotification(NAMESPACE, NOTIFICATION_NAME);
// Verify the external calls.
verify(storageUnitNotificationRegistrationService).deleteStorageUnitNotificationRegistration(storageUnitNotificationRegistrationKey);
verifyNoMoreInteractions(storageUnitNotificationRegistrationService);
// Validate the returned object.
assertEquals(storageUnitNotificationRegistration, deletedStorageUnitNotificationRegistration);
}
use of org.finra.herd.model.api.xml.StorageUnitNotificationFilter in project herd by FINRAOS.
the class StorageUnitNotificationRegistrationServiceTest method testDeleteStorageUnitNotificationRegistrationTrimParameters.
@Test
public void testDeleteStorageUnitNotificationRegistrationTrimParameters() {
NotificationRegistrationKey notificationRegistrationKey = new NotificationRegistrationKey(NAMESPACE, NOTIFICATION_NAME);
// Create and persist a storage unit notification registration entity.
StorageUnitNotificationRegistrationEntity storageUnitNotificationRegistrationEntity = notificationRegistrationDaoTestHelper.createStorageUnitNotificationRegistrationEntity(notificationRegistrationKey, NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG.name(), BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, STORAGE_NAME, STORAGE_UNIT_STATUS, STORAGE_UNIT_STATUS_2, notificationRegistrationDaoTestHelper.getTestJobActions(), NotificationRegistrationStatusEntity.ENABLED);
// Validate that this storage unit notification exists.
assertNotNull(storageUnitNotificationRegistrationDao.getStorageUnitNotificationRegistrationByAltKey(notificationRegistrationKey));
// Delete this storage unit notification using input parameters with leading and trailing empty spaces.
StorageUnitNotificationRegistration deletedStorageUnitNotificationRegistration = storageUnitNotificationRegistrationService.deleteStorageUnitNotificationRegistration(new NotificationRegistrationKey(addWhitespace(NAMESPACE), addWhitespace(NOTIFICATION_NAME)));
// Validate the returned object.
assertEquals(new StorageUnitNotificationRegistration(storageUnitNotificationRegistrationEntity.getId(), notificationRegistrationKey, NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG.name(), new StorageUnitNotificationFilter(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, STORAGE_NAME, STORAGE_UNIT_STATUS, STORAGE_UNIT_STATUS_2), notificationRegistrationDaoTestHelper.getTestJobActions(), NotificationRegistrationStatusEntity.ENABLED), deletedStorageUnitNotificationRegistration);
// Ensure that this storage unit notification is no longer there.
assertNull(storageUnitNotificationRegistrationDao.getStorageUnitNotificationRegistrationByAltKey(notificationRegistrationKey));
}
Aggregations