Search in sources :

Example 1 with NotificationActionEntity

use of org.finra.herd.model.jpa.NotificationActionEntity 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;
}
Also used : JobAction(org.finra.herd.model.api.xml.JobAction) ArrayList(java.util.ArrayList) StorageUnitNotificationRegistration(org.finra.herd.model.api.xml.StorageUnitNotificationRegistration) NotificationJobActionEntity(org.finra.herd.model.jpa.NotificationJobActionEntity) StorageUnitNotificationFilter(org.finra.herd.model.api.xml.StorageUnitNotificationFilter) NotificationRegistrationKey(org.finra.herd.model.api.xml.NotificationRegistrationKey) NotificationActionEntity(org.finra.herd.model.jpa.NotificationActionEntity)

Example 2 with NotificationActionEntity

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

the class NotificationEventServiceImpl method processBusinessObjectDataNotifications.

private List<Object> processBusinessObjectDataNotifications(String notificationEventType, List<BusinessObjectDataNotificationRegistrationEntity> businessObjectDataNotificationRegistrationEntities, BusinessObjectData businessObjectData, String newBusinessObjectDataStatus, String oldBusinessObjectDataStatus) {
    List<Object> notificationActions = new ArrayList<>();
    // Build a list of partition value that includes primary and sub-partition values, if any are specified in the business object data key.
    List<String> partitionValues = businessObjectDataHelper.getPrimaryAndSubPartitionValues(businessObjectData);
    // Get a list of partition columns from the associated business object format.
    List<String> partitionColumnNames = null;
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(new BusinessObjectFormatKey(businessObjectData.getNamespace(), businessObjectData.getBusinessObjectDefinitionName(), businessObjectData.getBusinessObjectFormatUsage(), businessObjectData.getBusinessObjectFormatFileType(), businessObjectData.getBusinessObjectFormatVersion()));
    if (businessObjectFormatEntity != null) {
        // Get business object format model object to directly access schema columns and partitions.
        BusinessObjectFormat businessObjectFormat = businessObjectFormatHelper.createBusinessObjectFormatFromEntity(businessObjectFormatEntity);
        // Proceed only if this format has schema with partition columns specified.
        if (businessObjectFormat.getSchema() != null && !CollectionUtils.isEmpty(businessObjectFormat.getSchema().getPartitions())) {
            // Do not provide more partition column names than there are primary and
            // sub-partition values that this business object data is registered with.
            partitionColumnNames = new ArrayList<>();
            List<SchemaColumn> partitionColumns = businessObjectFormat.getSchema().getPartitions();
            for (int i = 0; i < Math.min(partitionValues.size(), partitionColumns.size()); i++) {
                partitionColumnNames.add(partitionColumns.get(i).getName());
            }
        }
    }
    for (BusinessObjectDataNotificationRegistrationEntity businessObjectDataNotificationRegistration : businessObjectDataNotificationRegistrationEntities) {
        // Retrieve the job notification actions needed to be triggered.
        for (NotificationActionEntity notificationActionEntity : businessObjectDataNotificationRegistration.getNotificationActions()) {
            // Trigger the job action.
            if (notificationActionEntity instanceof NotificationJobActionEntity) {
                NotificationJobActionEntity notificationJobActionEntity = (NotificationJobActionEntity) notificationActionEntity;
                BusinessObjectDataNotificationEventParamsDto notificationEventParams = new BusinessObjectDataNotificationEventParamsDto();
                notificationEventParams.setBusinessObjectDataNotificationRegistration(businessObjectDataNotificationRegistration);
                notificationEventParams.setNotificationJobAction(notificationJobActionEntity);
                notificationEventParams.setEventType(notificationEventType);
                notificationEventParams.setBusinessObjectData(businessObjectData);
                notificationEventParams.setPartitionColumnNames(partitionColumnNames);
                notificationEventParams.setStorageName(businessObjectDataNotificationRegistration.getStorage() == null ? null : businessObjectDataNotificationRegistration.getStorage().getName());
                notificationEventParams.setPartitionValues(partitionValues);
                notificationEventParams.setNewBusinessObjectDataStatus(newBusinessObjectDataStatus);
                notificationEventParams.setOldBusinessObjectDataStatus(oldBusinessObjectDataStatus);
                notificationActions.add(triggerNotificationAction(NotificationTypeEntity.NOTIFICATION_TYPE_BDATA, notificationEventType, notificationEventParams));
            }
        }
    }
    return notificationActions;
}
Also used : ArrayList(java.util.ArrayList) SchemaColumn(org.finra.herd.model.api.xml.SchemaColumn) NotificationJobActionEntity(org.finra.herd.model.jpa.NotificationJobActionEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) BusinessObjectFormat(org.finra.herd.model.api.xml.BusinessObjectFormat) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectDataNotificationEventParamsDto(org.finra.herd.model.dto.BusinessObjectDataNotificationEventParamsDto) BusinessObjectDataNotificationRegistrationEntity(org.finra.herd.model.jpa.BusinessObjectDataNotificationRegistrationEntity) NotificationActionEntity(org.finra.herd.model.jpa.NotificationActionEntity)

Example 3 with NotificationActionEntity

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

the class BusinessObjectDataNotificationRegistrationServiceImpl method createBusinessObjectDataNotificationFromEntity.

/**
 * Creates the business object data notification registration from the persisted entity.
 *
 * @param businessObjectDataNotificationRegistrationEntity the business object data notification registration entity
 *
 * @return the business object data notification registration
 */
private BusinessObjectDataNotificationRegistration createBusinessObjectDataNotificationFromEntity(BusinessObjectDataNotificationRegistrationEntity businessObjectDataNotificationRegistrationEntity) {
    // Create the business object data notification.
    BusinessObjectDataNotificationRegistration businessObjectDataNotificationRegistration = new BusinessObjectDataNotificationRegistration();
    businessObjectDataNotificationRegistration.setId(businessObjectDataNotificationRegistrationEntity.getId());
    businessObjectDataNotificationRegistration.setBusinessObjectDataNotificationRegistrationKey(new NotificationRegistrationKey(businessObjectDataNotificationRegistrationEntity.getNamespace().getCode(), businessObjectDataNotificationRegistrationEntity.getName()));
    businessObjectDataNotificationRegistration.setBusinessObjectDataEventType(businessObjectDataNotificationRegistrationEntity.getNotificationEventType().getCode());
    BusinessObjectDataNotificationFilter filter = new BusinessObjectDataNotificationFilter();
    businessObjectDataNotificationRegistration.setBusinessObjectDataNotificationFilter(filter);
    // Business object definition entity cannot be null as per business object data notification registration create request validation.
    filter.setNamespace(businessObjectDataNotificationRegistrationEntity.getBusinessObjectDefinition().getNamespace().getCode());
    filter.setBusinessObjectDefinitionName(businessObjectDataNotificationRegistrationEntity.getBusinessObjectDefinition().getName());
    filter.setBusinessObjectFormatUsage(businessObjectDataNotificationRegistrationEntity.getUsage());
    filter.setBusinessObjectFormatFileType(businessObjectDataNotificationRegistrationEntity.getFileType() != null ? businessObjectDataNotificationRegistrationEntity.getFileType().getCode() : null);
    filter.setBusinessObjectFormatVersion(businessObjectDataNotificationRegistrationEntity.getBusinessObjectFormatVersion());
    filter.setStorageName(businessObjectDataNotificationRegistrationEntity.getStorage() != null ? businessObjectDataNotificationRegistrationEntity.getStorage().getName() : null);
    filter.setNewBusinessObjectDataStatus(businessObjectDataNotificationRegistrationEntity.getNewBusinessObjectDataStatus() != null ? businessObjectDataNotificationRegistrationEntity.getNewBusinessObjectDataStatus().getCode() : null);
    filter.setOldBusinessObjectDataStatus(businessObjectDataNotificationRegistrationEntity.getOldBusinessObjectDataStatus() != null ? businessObjectDataNotificationRegistrationEntity.getOldBusinessObjectDataStatus().getCode() : null);
    List<JobAction> jobActions = new ArrayList<>();
    businessObjectDataNotificationRegistration.setJobActions(jobActions);
    for (NotificationActionEntity notificationActionEntity : businessObjectDataNotificationRegistrationEntity.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());
        }
    }
    businessObjectDataNotificationRegistration.setNotificationRegistrationStatus(businessObjectDataNotificationRegistrationEntity.getNotificationRegistrationStatus().getCode());
    return businessObjectDataNotificationRegistration;
}
Also used : JobAction(org.finra.herd.model.api.xml.JobAction) BusinessObjectDataNotificationFilter(org.finra.herd.model.api.xml.BusinessObjectDataNotificationFilter) ArrayList(java.util.ArrayList) BusinessObjectDataNotificationRegistration(org.finra.herd.model.api.xml.BusinessObjectDataNotificationRegistration) NotificationJobActionEntity(org.finra.herd.model.jpa.NotificationJobActionEntity) NotificationRegistrationKey(org.finra.herd.model.api.xml.NotificationRegistrationKey) NotificationActionEntity(org.finra.herd.model.jpa.NotificationActionEntity)

Example 4 with NotificationActionEntity

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

the class NotificationRegistrationDaoTestHelper method createStorageUnitNotificationRegistrationEntity.

/**
 * Creates and persists a storage unit 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 newStorageUnitStatus the new storage unit status
 * @param oldStorageUnitStatus the old storage unit status
 * @param jobActions the list of job actions
 * @param notificationRegistrationStatus the notification registration status
 *
 * @return the newly created storage unit notification registration entity
 */
public StorageUnitNotificationRegistrationEntity createStorageUnitNotificationRegistrationEntity(NotificationRegistrationKey notificationRegistrationKey, String notificationEventTypeCode, String businessObjectDefinitionNamespace, String businessObjectDefinitionName, String businessObjectFormatUsage, String businessObjectFormatFileType, Integer businessObjectFormatVersion, String storageName, String newStorageUnitStatus, String oldStorageUnitStatus, 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.
    StorageEntity storageEntity = storageDao.getStorageByName(storageName);
    if (storageEntity == null) {
        storageEntity = storageDaoTestHelper.createStorageEntity(storageName, StoragePlatformEntity.S3);
    }
    // Create a business object status entity for new status if needed.
    StorageUnitStatusEntity newStorageUnitStatusEntity = null;
    if (StringUtils.isNotBlank(newStorageUnitStatus)) {
        newStorageUnitStatusEntity = storageUnitStatusDao.getStorageUnitStatusByCode(newStorageUnitStatus);
        if (newStorageUnitStatusEntity == null) {
            newStorageUnitStatusEntity = storageUnitStatusDaoTestHelper.createStorageUnitStatusEntity(newStorageUnitStatus);
        }
    }
    // Create a business object status entity for new status if needed.
    StorageUnitStatusEntity oldStorageUnitStatusEntity = null;
    if (StringUtils.isNotBlank(oldStorageUnitStatus)) {
        oldStorageUnitStatusEntity = storageUnitStatusDao.getStorageUnitStatusByCode(oldStorageUnitStatus);
        if (oldStorageUnitStatusEntity == null) {
            oldStorageUnitStatusEntity = storageUnitStatusDaoTestHelper.createStorageUnitStatusEntity(oldStorageUnitStatus);
        }
    }
    // 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.
    StorageUnitNotificationRegistrationEntity storageUnitNotificationRegistrationEntity = new StorageUnitNotificationRegistrationEntity();
    storageUnitNotificationRegistrationEntity.setNamespace(namespaceEntity);
    storageUnitNotificationRegistrationEntity.setName(notificationRegistrationKey.getNotificationName());
    storageUnitNotificationRegistrationEntity.setNotificationEventType(notificationEventTypeEntity);
    storageUnitNotificationRegistrationEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
    storageUnitNotificationRegistrationEntity.setUsage(businessObjectFormatUsage);
    storageUnitNotificationRegistrationEntity.setFileType(fileTypeEntity);
    storageUnitNotificationRegistrationEntity.setBusinessObjectFormatVersion(businessObjectFormatVersion);
    storageUnitNotificationRegistrationEntity.setStorage(storageEntity);
    storageUnitNotificationRegistrationEntity.setNewStorageUnitStatus(newStorageUnitStatusEntity);
    storageUnitNotificationRegistrationEntity.setOldStorageUnitStatus(oldStorageUnitStatusEntity);
    storageUnitNotificationRegistrationEntity.setNotificationRegistrationStatus(notificationRegistrationStatusEntity);
    if (!CollectionUtils.isEmpty(jobActions)) {
        List<NotificationActionEntity> notificationActionEntities = new ArrayList<>();
        storageUnitNotificationRegistrationEntity.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(storageUnitNotificationRegistrationEntity);
            notificationJobActionEntity.setJobDefinition(jobDefinitionEntity);
            notificationJobActionEntity.setCorrelationData(jobAction.getCorrelationData());
        }
    }
    return storageUnitNotificationRegistrationDao.saveAndRefresh(storageUnitNotificationRegistrationEntity);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) 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) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) NotificationRegistrationStatusEntity(org.finra.herd.model.jpa.NotificationRegistrationStatusEntity) StorageUnitNotificationRegistrationEntity(org.finra.herd.model.jpa.StorageUnitNotificationRegistrationEntity) NotificationActionEntity(org.finra.herd.model.jpa.NotificationActionEntity)

Example 5 with NotificationActionEntity

use of org.finra.herd.model.jpa.NotificationActionEntity 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)

Aggregations

ArrayList (java.util.ArrayList)8 NotificationActionEntity (org.finra.herd.model.jpa.NotificationActionEntity)8 NotificationJobActionEntity (org.finra.herd.model.jpa.NotificationJobActionEntity)8 JobAction (org.finra.herd.model.api.xml.JobAction)6 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)4 BusinessObjectDataNotificationRegistrationEntity (org.finra.herd.model.jpa.BusinessObjectDataNotificationRegistrationEntity)3 StorageUnitNotificationRegistrationEntity (org.finra.herd.model.jpa.StorageUnitNotificationRegistrationEntity)3 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)2 BusinessObjectFormat (org.finra.herd.model.api.xml.BusinessObjectFormat)2 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)2 NotificationRegistrationKey (org.finra.herd.model.api.xml.NotificationRegistrationKey)2 SchemaColumn (org.finra.herd.model.api.xml.SchemaColumn)2 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)2 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)2 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)2 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)2 NotificationEventTypeEntity (org.finra.herd.model.jpa.NotificationEventTypeEntity)2 NotificationRegistrationStatusEntity (org.finra.herd.model.jpa.NotificationRegistrationStatusEntity)2 StorageEntity (org.finra.herd.model.jpa.StorageEntity)2 BusinessObjectDataNotificationFilter (org.finra.herd.model.api.xml.BusinessObjectDataNotificationFilter)1