Search in sources :

Example 26 with JobDefinitionEntity

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

the class BusinessObjectDataNotificationJobActionServiceImpl method performNotificationAction.

@Override
public Object performNotificationAction(NotificationEventParamsDto notificationEventParams) throws Exception {
    if (notificationEventParams instanceof BusinessObjectDataNotificationEventParamsDto) {
        BusinessObjectDataNotificationEventParamsDto businessObjectDataNotificationEventParams = (BusinessObjectDataNotificationEventParamsDto) notificationEventParams;
        JobCreateRequest request = new JobCreateRequest();
        JobDefinitionEntity jobDefinitionEntity = businessObjectDataNotificationEventParams.getNotificationJobAction().getJobDefinition();
        request.setNamespace(jobDefinitionEntity.getNamespace().getCode());
        request.setJobName(jobDefinitionEntity.getName());
        request.setParameters(buildJobParameters(businessObjectDataNotificationEventParams));
        /*
             * 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()) {
            BusinessObjectDataNotificationRegistrationEntity businessObjectDataNotificationRegistration = businessObjectDataNotificationEventParams.getBusinessObjectDataNotificationRegistration();
            LOGGER.info("Starting a job due to a notification. notificationRegistrationKey={} jobCreateRequest={}", jsonHelper.objectToJson(notificationRegistrationHelper.getNotificationRegistrationKey(businessObjectDataNotificationRegistration)), jsonHelper.objectToJson(request));
        }
        return jobService.createAndStartJob(request);
    } else {
        throw new IllegalStateException("Notification event parameters DTO passed to the method must be an instance of BusinessObjectDataNotificationEventParamsDto.");
    }
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) BusinessObjectDataNotificationEventParamsDto(org.finra.herd.model.dto.BusinessObjectDataNotificationEventParamsDto) BusinessObjectDataNotificationRegistrationEntity(org.finra.herd.model.jpa.BusinessObjectDataNotificationRegistrationEntity) JobCreateRequest(org.finra.herd.model.api.xml.JobCreateRequest)

Example 27 with JobDefinitionEntity

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

the class ExecuteJdbcTestHelper method cleanUpHerdDatabaseAfterExecuteJdbcWithReceiveTaskTest.

/**
 * Cleans up Herd database after ExecuteJdbcWithReceiveTask test by deleting the test job definition related entities.\
 *
 * @param jobDefinitionNamespace the namespace for the job definition
 * @param jobDefinitionName the name of the job definition
 */
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void cleanUpHerdDatabaseAfterExecuteJdbcWithReceiveTaskTest(String jobDefinitionNamespace, String jobDefinitionName) {
    // Retrieve the test job definition entity.
    JobDefinitionEntity jobDefinitionEntity = jobDefinitionDao.getJobDefinitionByAltKey(jobDefinitionNamespace, jobDefinitionName);
    // Delete the test job definition entity.
    if (jobDefinitionEntity != null) {
        jobDefinitionDao.delete(jobDefinitionEntity);
    }
    // Retrieve the test namespace entity.
    NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByCd(jobDefinitionNamespace);
    // Delete the test namespace entity.
    if (namespaceEntity != null) {
        namespaceDao.delete(namespaceEntity);
    }
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 28 with JobDefinitionEntity

use of org.finra.herd.model.jpa.JobDefinitionEntity 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 29 with JobDefinitionEntity

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

Example 30 with JobDefinitionEntity

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

the class BusinessObjectDataNotificationRegistrationServiceImpl method createBusinessObjectDataNotificationEntity.

/**
 * Creates a new business object data 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 newBusinessObjectDataStatusEntity the new business object data status entity
 * @param oldBusinessObjectDataStatusEntity the old business object data status entity
 * @param key the business object data notification registration key
 * @param businessObjectDataNotificationFilter the business object data notification filter
 * @param jobActions the list of notification job actions
 * @param notificationRegistrationStatusEntity the notification registration status entity
 *
 * @return the newly created business object data notification registration entity
 */
private BusinessObjectDataNotificationRegistrationEntity createBusinessObjectDataNotificationEntity(NamespaceEntity namespaceEntity, NotificationEventTypeEntity notificationEventTypeEntity, BusinessObjectDefinitionEntity businessObjectDefinitionEntity, FileTypeEntity fileTypeEntity, StorageEntity storageEntity, BusinessObjectDataStatusEntity newBusinessObjectDataStatusEntity, BusinessObjectDataStatusEntity oldBusinessObjectDataStatusEntity, NotificationRegistrationKey key, BusinessObjectDataNotificationFilter businessObjectDataNotificationFilter, List<JobAction> jobActions, NotificationRegistrationStatusEntity notificationRegistrationStatusEntity) {
    // Create a new entity.
    BusinessObjectDataNotificationRegistrationEntity businessObjectDataNotificationRegistrationEntity = new BusinessObjectDataNotificationRegistrationEntity();
    businessObjectDataNotificationRegistrationEntity.setNamespace(namespaceEntity);
    businessObjectDataNotificationRegistrationEntity.setName(key.getNotificationName());
    businessObjectDataNotificationRegistrationEntity.setNotificationEventType(notificationEventTypeEntity);
    businessObjectDataNotificationRegistrationEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
    if (StringUtils.isNotBlank(businessObjectDataNotificationFilter.getBusinessObjectFormatUsage())) {
        businessObjectDataNotificationRegistrationEntity.setUsage(businessObjectDataNotificationFilter.getBusinessObjectFormatUsage());
    }
    businessObjectDataNotificationRegistrationEntity.setFileType(fileTypeEntity);
    businessObjectDataNotificationRegistrationEntity.setBusinessObjectFormatVersion(businessObjectDataNotificationFilter.getBusinessObjectFormatVersion());
    businessObjectDataNotificationRegistrationEntity.setStorage(storageEntity);
    businessObjectDataNotificationRegistrationEntity.setNewBusinessObjectDataStatus(newBusinessObjectDataStatusEntity);
    businessObjectDataNotificationRegistrationEntity.setOldBusinessObjectDataStatus(oldBusinessObjectDataStatusEntity);
    businessObjectDataNotificationRegistrationEntity.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<>();
    businessObjectDataNotificationRegistrationEntity.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(businessObjectDataNotificationRegistrationEntity);
    }
    return businessObjectDataNotificationRegistrationEntity;
}
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) BusinessObjectDataNotificationRegistrationEntity(org.finra.herd.model.jpa.BusinessObjectDataNotificationRegistrationEntity) NotificationActionEntity(org.finra.herd.model.jpa.NotificationActionEntity)

Aggregations

JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)36 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)18 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)12 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)11 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)7 Collection (java.util.Collection)6 HashSet (java.util.HashSet)6 JobDefinition (org.finra.herd.model.api.xml.JobDefinition)5 JobStatusEnum (org.finra.herd.model.api.xml.JobStatusEnum)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 Predicate (javax.persistence.criteria.Predicate)4 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)4 JobAction (org.finra.herd.model.api.xml.JobAction)4 JobDefinitionCreateRequest (org.finra.herd.model.api.xml.JobDefinitionCreateRequest)4 JobSummaries (org.finra.herd.model.api.xml.JobSummaries)4 JobSummary (org.finra.herd.model.api.xml.JobSummary)4 NotificationActionEntity (org.finra.herd.model.jpa.NotificationActionEntity)4 NotificationJobActionEntity (org.finra.herd.model.jpa.NotificationJobActionEntity)4 Date (java.util.Date)3