Search in sources :

Example 16 with StorageUnitNotificationRegistrationEntity

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

the class NotificationEventServiceImpl method processStorageUnitNotificationEventSync.

@Override
public List<Object> processStorageUnitNotificationEventSync(NotificationEventTypeEntity.EventTypesStorageUnit notificationEventType, BusinessObjectDataKey businessObjectDataKey, String storageName, String newStorageUnitStatus, String oldStorageUnitStatus) {
    // Retrieve all matching storage unit notification registrations with enabled status.
    List<StorageUnitNotificationRegistrationEntity> storageUnitNotificationRegistrationEntities = storageUnitNotificationRegistrationDao.getStorageUnitNotificationRegistrations(notificationEventType.name(), businessObjectDataKey, storageName, newStorageUnitStatus, oldStorageUnitStatus, NotificationRegistrationStatusEntity.ENABLED);
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDao.getBusinessObjectDataByAltKey(businessObjectDataKey);
    return processStorageUnitNotifications(notificationEventType.name(), storageUnitNotificationRegistrationEntities, businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity), storageName, newStorageUnitStatus, oldStorageUnitStatus);
}
Also used : StorageUnitNotificationRegistrationEntity(org.finra.herd.model.jpa.StorageUnitNotificationRegistrationEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity)

Example 17 with StorageUnitNotificationRegistrationEntity

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

the class NotificationEventServiceImpl method processStorageUnitNotifications.

private List<Object> processStorageUnitNotifications(String notificationEventType, List<StorageUnitNotificationRegistrationEntity> storageUnitNotificationRegistrationEntities, BusinessObjectData businessObjectData, String storageName, String newStorageUnitStatus, String oldStorageUnitStatus) {
    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 (StorageUnitNotificationRegistrationEntity storageUnitNotificationRegistration : storageUnitNotificationRegistrationEntities) {
        // Retrieve the job notification actions needed to be triggered.
        for (NotificationActionEntity notificationActionEntity : storageUnitNotificationRegistration.getNotificationActions()) {
            // Trigger the job action.
            if (notificationActionEntity instanceof NotificationJobActionEntity) {
                NotificationJobActionEntity notificationJobActionEntity = (NotificationJobActionEntity) notificationActionEntity;
                StorageUnitNotificationEventParamsDto notificationEventParams = new StorageUnitNotificationEventParamsDto();
                notificationEventParams.setStorageUnitNotificationRegistration(storageUnitNotificationRegistration);
                notificationEventParams.setNotificationJobAction(notificationJobActionEntity);
                notificationEventParams.setEventType(notificationEventType);
                notificationEventParams.setBusinessObjectData(businessObjectData);
                notificationEventParams.setPartitionColumnNames(partitionColumnNames);
                notificationEventParams.setStorageName(storageName);
                notificationEventParams.setPartitionValues(partitionValues);
                notificationEventParams.setNewStorageUnitStatus(newStorageUnitStatus);
                notificationEventParams.setOldStorageUnitStatus(oldStorageUnitStatus);
                notificationActions.add(triggerNotificationAction(NotificationTypeEntity.NOTIFICATION_TYPE_STORAGE_UNIT, notificationEventType, notificationEventParams));
            }
        }
    }
    return notificationActions;
}
Also used : ArrayList(java.util.ArrayList) SchemaColumn(org.finra.herd.model.api.xml.SchemaColumn) StorageUnitNotificationEventParamsDto(org.finra.herd.model.dto.StorageUnitNotificationEventParamsDto) 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) StorageUnitNotificationRegistrationEntity(org.finra.herd.model.jpa.StorageUnitNotificationRegistrationEntity) NotificationActionEntity(org.finra.herd.model.jpa.NotificationActionEntity)

Example 18 with StorageUnitNotificationRegistrationEntity

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

the class StorageUnitNotificationRegistrationServiceImpl method deleteStorageUnitNotificationRegistration.

@NamespacePermission(fields = "#notificationRegistrationKey?.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public StorageUnitNotificationRegistration deleteStorageUnitNotificationRegistration(NotificationRegistrationKey notificationRegistrationKey) {
    // Validate and trim the key.
    validateStorageUnitNotificationRegistrationKey(notificationRegistrationKey);
    // Retrieve and ensure that a storage unit notification exists with the specified key.
    StorageUnitNotificationRegistrationEntity storageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDaoHelper.getStorageUnitNotificationRegistrationEntity(notificationRegistrationKey);
    // Delete the storage unit notification.
    storageUnitNotificationRegistrationDao.delete(storageUnitNotificationRegistrationEntity);
    // Create and return the storage unit notification object from the deleted entity.
    return createStorageUnitNotificationFromEntity(storageUnitNotificationRegistrationEntity);
}
Also used : StorageUnitNotificationRegistrationEntity(org.finra.herd.model.jpa.StorageUnitNotificationRegistrationEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 19 with StorageUnitNotificationRegistrationEntity

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

the class StorageUnitNotificationRegistrationServiceImpl method createStorageUnitNotificationEntity.

/**
 * Creates a new storage unit notification registration entity from the request information.
 *
 * @param namespaceEntity the namespace entity
 * @param notificationEventTypeEntity the notification event type entity
 * @param businessObjectDefinitionEntity the business object definition entity
 * @param fileTypeEntity the file type entity
 * @param storageEntity the storage entity
 * @param newStorageUnitStatusEntity the new storage unit status entity
 * @param oldStorageUnitStatusEntity the old storage unit status entity
 * @param key the storage unit notification registration key
 * @param storageUnitNotificationFilter the storage unit notification filter
 * @param jobActions the list of notification job actions
 * @param notificationRegistrationStatusEntity the notification registration status entity
 *
 * @return the newly created storage unit notification registration entity
 */
private StorageUnitNotificationRegistrationEntity createStorageUnitNotificationEntity(NamespaceEntity namespaceEntity, NotificationEventTypeEntity notificationEventTypeEntity, BusinessObjectDefinitionEntity businessObjectDefinitionEntity, FileTypeEntity fileTypeEntity, StorageEntity storageEntity, StorageUnitStatusEntity newStorageUnitStatusEntity, StorageUnitStatusEntity oldStorageUnitStatusEntity, NotificationRegistrationKey key, StorageUnitNotificationFilter storageUnitNotificationFilter, List<JobAction> jobActions, NotificationRegistrationStatusEntity notificationRegistrationStatusEntity) {
    // Create a new entity.
    StorageUnitNotificationRegistrationEntity storageUnitNotificationRegistrationEntity = new StorageUnitNotificationRegistrationEntity();
    storageUnitNotificationRegistrationEntity.setNamespace(namespaceEntity);
    storageUnitNotificationRegistrationEntity.setName(key.getNotificationName());
    storageUnitNotificationRegistrationEntity.setNotificationEventType(notificationEventTypeEntity);
    storageUnitNotificationRegistrationEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
    if (StringUtils.isNotBlank(storageUnitNotificationFilter.getBusinessObjectFormatUsage())) {
        storageUnitNotificationRegistrationEntity.setUsage(storageUnitNotificationFilter.getBusinessObjectFormatUsage());
    }
    storageUnitNotificationRegistrationEntity.setFileType(fileTypeEntity);
    storageUnitNotificationRegistrationEntity.setBusinessObjectFormatVersion(storageUnitNotificationFilter.getBusinessObjectFormatVersion());
    storageUnitNotificationRegistrationEntity.setStorage(storageEntity);
    storageUnitNotificationRegistrationEntity.setNewStorageUnitStatus(newStorageUnitStatusEntity);
    storageUnitNotificationRegistrationEntity.setOldStorageUnitStatus(oldStorageUnitStatusEntity);
    storageUnitNotificationRegistrationEntity.setNotificationRegistrationStatus(notificationRegistrationStatusEntity);
    // Create the relative entities for job actions.
    // 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).
    List<NotificationActionEntity> notificationActionEntities = new ArrayList<>();
    storageUnitNotificationRegistrationEntity.setNotificationActions(notificationActionEntities);
    for (JobAction jobAction : jobActions) {
        // Retrieve and ensure that job definition exists.
        JobDefinitionEntity jobDefinitionEntity = jobDefinitionDaoHelper.getJobDefinitionEntity(jobAction.getNamespace(), jobAction.getJobName());
        // Create a new entity.
        NotificationJobActionEntity notificationJobActionEntity = new NotificationJobActionEntity();
        notificationActionEntities.add(notificationJobActionEntity);
        notificationJobActionEntity.setJobDefinition(jobDefinitionEntity);
        notificationJobActionEntity.setCorrelationData(jobAction.getCorrelationData());
        notificationJobActionEntity.setNotificationRegistration(storageUnitNotificationRegistrationEntity);
    }
    return storageUnitNotificationRegistrationEntity;
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) JobAction(org.finra.herd.model.api.xml.JobAction) ArrayList(java.util.ArrayList) NotificationJobActionEntity(org.finra.herd.model.jpa.NotificationJobActionEntity) StorageUnitNotificationRegistrationEntity(org.finra.herd.model.jpa.StorageUnitNotificationRegistrationEntity) NotificationActionEntity(org.finra.herd.model.jpa.NotificationActionEntity)

Example 20 with StorageUnitNotificationRegistrationEntity

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

the class StorageUnitStatusChangeNotificationJobActionServiceImpl method performNotificationAction.

@Override
public Object performNotificationAction(NotificationEventParamsDto notificationEventParams) throws Exception {
    if (notificationEventParams instanceof StorageUnitNotificationEventParamsDto) {
        StorageUnitNotificationEventParamsDto storageUnitNotificationEventParams = (StorageUnitNotificationEventParamsDto) notificationEventParams;
        JobCreateRequest request = new JobCreateRequest();
        JobDefinitionEntity jobDefinitionEntity = storageUnitNotificationEventParams.getNotificationJobAction().getJobDefinition();
        request.setNamespace(jobDefinitionEntity.getNamespace().getCode());
        request.setJobName(jobDefinitionEntity.getName());
        request.setParameters(buildJobParameters(storageUnitNotificationEventParams));
        /*
             * Log enough information so we can trace back what notification registration triggered what workflow.
             * This also allows us to reproduce the workflow execution if needed by logging the entire jobCreateRequest in JSON format.
             */
        if (LOGGER.isInfoEnabled()) {
            StorageUnitNotificationRegistrationEntity storageUnitNotificationRegistration = storageUnitNotificationEventParams.getStorageUnitNotificationRegistration();
            LOGGER.info("Starting a job due to a notification. notificationRegistrationKey={} jobCreateRequest={}", jsonHelper.objectToJson(notificationRegistrationHelper.getNotificationRegistrationKey(storageUnitNotificationRegistration)), jsonHelper.objectToJson(request));
        }
        return jobService.createAndStartJob(request);
    } else {
        throw new IllegalStateException("Notification event parameters DTO passed to the method must be an instance of StorageUnitNotificationEventParamsDto.");
    }
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) StorageUnitNotificationEventParamsDto(org.finra.herd.model.dto.StorageUnitNotificationEventParamsDto) StorageUnitNotificationRegistrationEntity(org.finra.herd.model.jpa.StorageUnitNotificationRegistrationEntity) JobCreateRequest(org.finra.herd.model.api.xml.JobCreateRequest)

Aggregations

StorageUnitNotificationRegistrationEntity (org.finra.herd.model.jpa.StorageUnitNotificationRegistrationEntity)25 NotificationRegistrationKey (org.finra.herd.model.api.xml.NotificationRegistrationKey)14 Test (org.junit.Test)12 StorageUnitNotificationFilter (org.finra.herd.model.api.xml.StorageUnitNotificationFilter)9 StorageUnitNotificationRegistration (org.finra.herd.model.api.xml.StorageUnitNotificationRegistration)7 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)7 ArrayList (java.util.ArrayList)6 JobAction (org.finra.herd.model.api.xml.JobAction)5 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)5 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 Predicate (javax.persistence.criteria.Predicate)4 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)4 NotificationEventTypeEntity (org.finra.herd.model.jpa.NotificationEventTypeEntity)4 NotificationRegistrationStatusEntity (org.finra.herd.model.jpa.NotificationRegistrationStatusEntity)4 StorageEntity (org.finra.herd.model.jpa.StorageEntity)4 StorageUnitStatusEntity (org.finra.herd.model.jpa.StorageUnitStatusEntity)4 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)3 StorageUnitNotificationEventParamsDto (org.finra.herd.model.dto.StorageUnitNotificationEventParamsDto)3 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)3