Search in sources :

Example 11 with NotificationEventTypeEntity

use of org.finra.herd.model.jpa.NotificationEventTypeEntity in project herd by FINRAOS.

the class NotificationRegistrationDaoTestHelper method createBusinessObjectDataNotificationRegistrationEntity.

/**
 * Creates and persists a business object data notification registration entity.
 *
 * @param notificationRegistrationKey the business object data notification registration key
 * @param notificationEventTypeCode the notification event type
 * @param businessObjectDefinitionNamespace the business object definition namespace
 * @param businessObjectDefinitionName the business object definition name
 * @param businessObjectFormatUsage the business object usage
 * @param businessObjectFormatFileType the business object format file type
 * @param businessObjectFormatVersion the business object format version
 * @param storageName the storage name
 * @param newBusinessObjectDataStatus the new business object data status
 * @param oldBusinessObjectDataStatus the old business object data status
 * @param jobActions the list of job actions
 * @param notificationRegistrationStatus the notification registration status
 *
 * @return the newly created business object data notification registration entity
 */
public BusinessObjectDataNotificationRegistrationEntity createBusinessObjectDataNotificationRegistrationEntity(NotificationRegistrationKey notificationRegistrationKey, String notificationEventTypeCode, String businessObjectDefinitionNamespace, String businessObjectDefinitionName, String businessObjectFormatUsage, String businessObjectFormatFileType, Integer businessObjectFormatVersion, String storageName, String newBusinessObjectDataStatus, String oldBusinessObjectDataStatus, List<JobAction> jobActions, String notificationRegistrationStatus) {
    // Create a namespace entity if needed.
    NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByCd(notificationRegistrationKey.getNamespace());
    if (namespaceEntity == null) {
        namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(notificationRegistrationKey.getNamespace());
    }
    // Create a notification event type entity if needed.
    NotificationEventTypeEntity notificationEventTypeEntity = notificationEventTypeDao.getNotificationEventTypeByCode(notificationEventTypeCode);
    if (notificationEventTypeEntity == null) {
        notificationEventTypeEntity = createNotificationEventTypeEntity(notificationEventTypeCode);
    }
    // Create a business object definition entity if needed.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(new BusinessObjectDefinitionKey(businessObjectDefinitionNamespace, businessObjectDefinitionName));
    if (businessObjectDefinitionEntity == null) {
        businessObjectDefinitionEntity = businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(businessObjectDefinitionNamespace, businessObjectDefinitionName, AbstractDaoTest.DATA_PROVIDER_NAME, AbstractDaoTest.BDEF_DESCRIPTION);
    }
    // Create a business object format file type entity if needed.
    FileTypeEntity fileTypeEntity = null;
    if (StringUtils.isNotBlank(businessObjectFormatFileType)) {
        fileTypeEntity = fileTypeDao.getFileTypeByCode(businessObjectFormatFileType);
        if (fileTypeEntity == null) {
            fileTypeEntity = fileTypeDaoTestHelper.createFileTypeEntity(businessObjectFormatFileType);
        }
    }
    // Create a storage entity if needed.
    StorageEntity storageEntity = null;
    if (StringUtils.isNotBlank(storageName)) {
        storageEntity = storageDao.getStorageByName(storageName);
        if (storageEntity == null) {
            storageEntity = storageDaoTestHelper.createStorageEntity(storageName, StoragePlatformEntity.S3);
        }
    }
    // Create a business object status entity for new status if needed.
    BusinessObjectDataStatusEntity newBusinessObjectDataStatusEntity = null;
    if (StringUtils.isNotBlank(newBusinessObjectDataStatus)) {
        newBusinessObjectDataStatusEntity = businessObjectDataStatusDao.getBusinessObjectDataStatusByCode(newBusinessObjectDataStatus);
        if (newBusinessObjectDataStatusEntity == null) {
            newBusinessObjectDataStatusEntity = businessObjectDataStatusDaoTestHelper.createBusinessObjectDataStatusEntity(newBusinessObjectDataStatus);
        }
    }
    // Create a business object status entity for new status if needed.
    BusinessObjectDataStatusEntity oldBusinessObjectDataStatusEntity = null;
    if (StringUtils.isNotBlank(oldBusinessObjectDataStatus)) {
        oldBusinessObjectDataStatusEntity = businessObjectDataStatusDao.getBusinessObjectDataStatusByCode(oldBusinessObjectDataStatus);
        if (oldBusinessObjectDataStatusEntity == null) {
            oldBusinessObjectDataStatusEntity = businessObjectDataStatusDaoTestHelper.createBusinessObjectDataStatusEntity(oldBusinessObjectDataStatus);
        }
    }
    // Create a notification registration status entity if needed.
    NotificationRegistrationStatusEntity notificationRegistrationStatusEntity = notificationRegistrationStatusDao.getNotificationRegistrationStatus(notificationRegistrationStatus);
    if (notificationRegistrationStatusEntity == null) {
        notificationRegistrationStatusEntity = createNotificationRegistrationStatusEntity(notificationRegistrationStatus);
    }
    // Create a business object data notification registration entity.
    BusinessObjectDataNotificationRegistrationEntity businessObjectDataNotificationRegistrationEntity = new BusinessObjectDataNotificationRegistrationEntity();
    businessObjectDataNotificationRegistrationEntity.setNamespace(namespaceEntity);
    businessObjectDataNotificationRegistrationEntity.setName(notificationRegistrationKey.getNotificationName());
    businessObjectDataNotificationRegistrationEntity.setNotificationEventType(notificationEventTypeEntity);
    businessObjectDataNotificationRegistrationEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
    businessObjectDataNotificationRegistrationEntity.setUsage(businessObjectFormatUsage);
    businessObjectDataNotificationRegistrationEntity.setFileType(fileTypeEntity);
    businessObjectDataNotificationRegistrationEntity.setBusinessObjectFormatVersion(businessObjectFormatVersion);
    businessObjectDataNotificationRegistrationEntity.setStorage(storageEntity);
    businessObjectDataNotificationRegistrationEntity.setNewBusinessObjectDataStatus(newBusinessObjectDataStatusEntity);
    businessObjectDataNotificationRegistrationEntity.setOldBusinessObjectDataStatus(oldBusinessObjectDataStatusEntity);
    businessObjectDataNotificationRegistrationEntity.setNotificationRegistrationStatus(notificationRegistrationStatusEntity);
    if (!CollectionUtils.isEmpty(jobActions)) {
        List<NotificationActionEntity> notificationActionEntities = new ArrayList<>();
        businessObjectDataNotificationRegistrationEntity.setNotificationActions(notificationActionEntities);
        for (JobAction jobAction : jobActions) {
            // Create a job definition entity if needed.
            JobDefinitionEntity jobDefinitionEntity = jobDefinitionDao.getJobDefinitionByAltKey(jobAction.getNamespace(), jobAction.getJobName());
            if (jobDefinitionEntity == null) {
                jobDefinitionEntity = jobDefinitionDaoTestHelper.createJobDefinitionEntity(jobAction.getNamespace(), jobAction.getJobName(), String.format("Description of \"%s.%s\" job definition.", jobAction.getNamespace(), jobAction.getJobName()), String.format("%s.%s.%s", jobAction.getNamespace(), jobAction.getJobName(), AbstractDaoTest.ACTIVITI_ID));
            }
            NotificationJobActionEntity notificationJobActionEntity = new NotificationJobActionEntity();
            notificationActionEntities.add(notificationJobActionEntity);
            notificationJobActionEntity.setNotificationRegistration(businessObjectDataNotificationRegistrationEntity);
            notificationJobActionEntity.setJobDefinition(jobDefinitionEntity);
            notificationJobActionEntity.setCorrelationData(jobAction.getCorrelationData());
        }
    }
    return businessObjectDataNotificationRegistrationDao.saveAndRefresh(businessObjectDataNotificationRegistrationEntity);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) BusinessObjectDataStatusEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusEntity) ArrayList(java.util.ArrayList) StorageEntity(org.finra.herd.model.jpa.StorageEntity) NotificationJobActionEntity(org.finra.herd.model.jpa.NotificationJobActionEntity) NotificationEventTypeEntity(org.finra.herd.model.jpa.NotificationEventTypeEntity) JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) JobAction(org.finra.herd.model.api.xml.JobAction) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) NotificationRegistrationStatusEntity(org.finra.herd.model.jpa.NotificationRegistrationStatusEntity) BusinessObjectDataNotificationRegistrationEntity(org.finra.herd.model.jpa.BusinessObjectDataNotificationRegistrationEntity) NotificationActionEntity(org.finra.herd.model.jpa.NotificationActionEntity)

Example 12 with NotificationEventTypeEntity

use of org.finra.herd.model.jpa.NotificationEventTypeEntity in project herd by FINRAOS.

the class StorageUnitNotificationRegistrationServiceImpl method getAndValidateNotificationEventTypeEntity.

/**
 * Retrieves and validate notification event type entity.
 *
 * @param notificationEventType the notification event type
 */
private NotificationEventTypeEntity getAndValidateNotificationEventTypeEntity(String notificationEventType) {
    // Retrieve and ensure that notification event type exists.
    NotificationEventTypeEntity notificationEventTypeEntity = notificationEventTypeDaoHelper.getNotificationEventTypeEntity(notificationEventType);
    // Validate the notification event type.
    Assert.isTrue(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG.name().equalsIgnoreCase(notificationEventType), String.format("Notification event type \"%s\" is not supported for storage unit notification registration.", notificationEventType));
    return notificationEventTypeEntity;
}
Also used : NotificationEventTypeEntity(org.finra.herd.model.jpa.NotificationEventTypeEntity)

Example 13 with NotificationEventTypeEntity

use of org.finra.herd.model.jpa.NotificationEventTypeEntity in project herd by FINRAOS.

the class BusinessObjectDataNotificationRegistrationServiceImpl method getAndValidateNotificationEventTypeEntity.

/**
 * Retrieves and validate notification event type entity.
 *
 * @param notificationEventType the notification event type
 */
private NotificationEventTypeEntity getAndValidateNotificationEventTypeEntity(String notificationEventType) {
    // Retrieve and ensure that notification event type exists.
    NotificationEventTypeEntity notificationEventTypeEntity = notificationEventTypeDaoHelper.getNotificationEventTypeEntity(notificationEventType);
    // Validate the notification event type.
    Assert.isTrue(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_RGSTN.name().equalsIgnoreCase(notificationEventType) || NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_STTS_CHG.name().equalsIgnoreCase(notificationEventType), String.format("Notification event type \"%s\" is not supported for business object data notification registration.", notificationEventType));
    return notificationEventTypeEntity;
}
Also used : NotificationEventTypeEntity(org.finra.herd.model.jpa.NotificationEventTypeEntity)

Example 14 with NotificationEventTypeEntity

use of org.finra.herd.model.jpa.NotificationEventTypeEntity in project herd by FINRAOS.

the class BusinessObjectDataNotificationRegistrationServiceImpl method createBusinessObjectDataNotificationRegistration.

@NamespacePermissions({ @NamespacePermission(fields = "#request?.businessObjectDataNotificationRegistrationKey?.namespace", permissions = NamespacePermissionEnum.WRITE), @NamespacePermission(fields = "#request?.businessObjectDataNotificationFilter?.namespace", permissions = NamespacePermissionEnum.READ), @NamespacePermission(fields = "#request?.jobActions?.![namespace]", permissions = NamespacePermissionEnum.EXECUTE) })
@Override
public BusinessObjectDataNotificationRegistration createBusinessObjectDataNotificationRegistration(BusinessObjectDataNotificationRegistrationCreateRequest request) {
    // Validate and trim the request parameters.
    validateBusinessObjectDataNotificationRegistrationCreateRequest(request);
    // Get the business object notification key.
    NotificationRegistrationKey key = request.getBusinessObjectDataNotificationRegistrationKey();
    // Retrieve and ensure that namespace exists 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.
    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());
    }
    // 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 business object data notification with the specified name doesn't already exist for the specified namespace.
    BusinessObjectDataNotificationRegistrationEntity businessObjectDataNotificationRegistrationEntity = businessObjectDataNotificationRegistrationDao.getBusinessObjectDataNotificationRegistrationByAltKey(key);
    if (businessObjectDataNotificationRegistrationEntity != null) {
        throw new AlreadyExistsException(String.format("Unable to create business object data notification with name \"%s\" because it already exists for namespace \"%s\".", key.getNotificationName(), key.getNamespace()));
    }
    // Create a business object data notification registration entity from the request information.
    businessObjectDataNotificationRegistrationEntity = createBusinessObjectDataNotificationEntity(namespaceEntity, notificationEventTypeEntity, businessObjectDefinitionEntity, fileTypeEntity, storageEntity, newBusinessObjectDataStatus, oldBusinessObjectDataStatus, request.getBusinessObjectDataNotificationRegistrationKey(), request.getBusinessObjectDataNotificationFilter(), request.getJobActions(), notificationRegistrationStatusEntity);
    // Persist the new entity.
    businessObjectDataNotificationRegistrationEntity = businessObjectDataNotificationRegistrationDao.saveAndRefresh(businessObjectDataNotificationRegistrationEntity);
    // Create and return the business object data notification object from the persisted entity.
    return createBusinessObjectDataNotificationFromEntity(businessObjectDataNotificationRegistrationEntity);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) BusinessObjectDataNotificationFilter(org.finra.herd.model.api.xml.BusinessObjectDataNotificationFilter) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) BusinessObjectDataStatusEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusEntity) StorageEntity(org.finra.herd.model.jpa.StorageEntity) NotificationEventTypeEntity(org.finra.herd.model.jpa.NotificationEventTypeEntity) JobAction(org.finra.herd.model.api.xml.JobAction) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) NotificationRegistrationStatusEntity(org.finra.herd.model.jpa.NotificationRegistrationStatusEntity) BusinessObjectDataNotificationRegistrationEntity(org.finra.herd.model.jpa.BusinessObjectDataNotificationRegistrationEntity) NotificationRegistrationKey(org.finra.herd.model.api.xml.NotificationRegistrationKey) NamespacePermissions(org.finra.herd.model.annotation.NamespacePermissions)

Aggregations

NotificationEventTypeEntity (org.finra.herd.model.jpa.NotificationEventTypeEntity)14 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)10 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)10 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)8 JobAction (org.finra.herd.model.api.xml.JobAction)8 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)8 NotificationRegistrationStatusEntity (org.finra.herd.model.jpa.NotificationRegistrationStatusEntity)8 StorageEntity (org.finra.herd.model.jpa.StorageEntity)7 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)5 StorageUnitStatusEntity (org.finra.herd.model.jpa.StorageUnitStatusEntity)5 ArrayList (java.util.ArrayList)4 NamespacePermissions (org.finra.herd.model.annotation.NamespacePermissions)4 NotificationRegistrationKey (org.finra.herd.model.api.xml.NotificationRegistrationKey)4 BusinessObjectDataNotificationRegistrationEntity (org.finra.herd.model.jpa.BusinessObjectDataNotificationRegistrationEntity)4 StorageUnitNotificationRegistrationEntity (org.finra.herd.model.jpa.StorageUnitNotificationRegistrationEntity)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 Predicate (javax.persistence.criteria.Predicate)3 Order (javax.persistence.criteria.Order)2 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)2 BusinessObjectDataNotificationFilter (org.finra.herd.model.api.xml.BusinessObjectDataNotificationFilter)2